diff --git a/.changeset/pretty-planes-promise.md b/.changeset/pretty-planes-promise.md new file mode 100644 index 000000000000..668be49b294d --- /dev/null +++ b/.changeset/pretty-planes-promise.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix for hoisted scripts in project with spaces in the file path diff --git a/packages/astro/src/vite-plugin-utils/index.ts b/packages/astro/src/vite-plugin-utils/index.ts index 17882e602095..557c7bb7b3d6 100644 --- a/packages/astro/src/vite-plugin-utils/index.ts +++ b/packages/astro/src/vite-plugin-utils/index.ts @@ -5,6 +5,7 @@ import { appendForwardSlash, removeLeadingForwardSlashWindows, } from '../core/path.js'; +import { viteID } from '../core/util.js'; /** * Converts the first dot in `import.meta.env` to its Unicode escape sequence, @@ -47,7 +48,8 @@ export function normalizeFilename(filename: string, config: AstroConfig) { if (filename.startsWith('/@fs')) { filename = filename.slice('/@fs'.length); } else if (filename.startsWith('/') && !ancestor(filename, config.root.pathname)) { - filename = new URL('.' + filename, config.root).pathname; + const url = new URL('.' + filename, config.root); + filename = viteID(url); } return removeLeadingForwardSlashWindows(filename); } diff --git a/packages/astro/test/fixtures/space in folder name/app/package.json b/packages/astro/test/fixtures/space in folder name/app/package.json new file mode 100644 index 000000000000..daf3a1963d7a --- /dev/null +++ b/packages/astro/test/fixtures/space in folder name/app/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/space-in-folder-name", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/space in folder name/app/src/pages/index.astro b/packages/astro/test/fixtures/space in folder name/app/src/pages/index.astro new file mode 100644 index 000000000000..ada8acc288a6 --- /dev/null +++ b/packages/astro/test/fixtures/space in folder name/app/src/pages/index.astro @@ -0,0 +1,11 @@ + +
+