Bug: Incorrect Path Generation for Hoisted Scripts (._astro vs _astro)
Hello,
I've encountered an issue with the @kindspells/astro-shield integration where it generates incorrect paths for hoisted scripts during the build process. Specifically, the integration adds a . prefix to the _astro directory, resulting in paths like ./._astro/hoisted.*.js, causing the following errors during build:
- With custom
assetsdirectory defined inastro.config.mjs:build: { assets: 'nameOfFolder', },ENOENT: no such file or directory, open 'C:\path\to\project\dist\.nameOfFolder\hoisted.[hash].js' - Without custom directory:
ENOENT: no such file or directory, open 'C:\path\to\project\dist\._astro\hoisted.[hash].js'
The issue persists even with the default settings. I tested it on a static Astro project, and the same error occurred. It seems like the integration mishandles asset paths when creating integrity hashes for hoisted scripts.
Steps to Reproduce:
- Set up an Astro project with
@kindspells/astro-shieldintegration. - Add any inline or hoisted JavaScript, or React components that include JavaScript.
- Run
astro build.
Expected Behavior:
Hoisted scripts should be placed in the correct _astro directory without the extra . prefix.
Actual Behavior:
The build fails due to incorrect paths like ._astro being used.
Possible Solution:
The issue seems to be caused by an unnecessary . prefix being added when generating paths for hoisted assets. Upon testing, removing this prefix resolves the issue in my project setup. I recommend reviewing the logic responsible for path handling and conditionally applying the . prefix only when necessary, as it may not be universally required for all builds.
This should help maintain compatibility across different configurations.
Thank you for your assistance!