summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/pretty-planes-promise.md5
-rw-r--r--packages/astro/src/vite-plugin-utils/index.ts4
-rw-r--r--packages/astro/test/fixtures/space in folder name/app/package.json8
-rw-r--r--packages/astro/test/fixtures/space in folder name/app/src/pages/index.astro11
-rw-r--r--packages/astro/test/space-in-folder-name.test.js33
-rw-r--r--pnpm-lock.yaml6
6 files changed, 66 insertions, 1 deletions
diff --git a/.changeset/pretty-planes-promise.md b/.changeset/pretty-planes-promise.md
new file mode 100644
index 000000000..668be49b2
--- /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 17882e602..557c7bb7b 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 000000000..daf3a1963
--- /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 000000000..ada8acc28
--- /dev/null
+++ b/packages/astro/test/fixtures/space in folder name/app/src/pages/index.astro
@@ -0,0 +1,11 @@
+<html>
+<head>
+<title>Project with spaces in the folder name</title>
+</head>
+<body>
+ <h1>Testing</h1>
+ <script>
+ console.log('hi');
+ </script>
+</body>
+</html>
diff --git a/packages/astro/test/space-in-folder-name.test.js b/packages/astro/test/space-in-folder-name.test.js
new file mode 100644
index 000000000..3920e1957
--- /dev/null
+++ b/packages/astro/test/space-in-folder-name.test.js
@@ -0,0 +1,33 @@
+import { expect } from 'chai';
+import * as cheerio from 'cheerio';
+import { loadFixture } from './test-utils.js';
+
+describe('Projects with a space in the folder name', () => {
+ let fixture;
+
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/space in folder name/app/',
+ });
+ });
+
+ describe('dev', () => {
+ /** @type {import('./test-utils').Fixture} */
+ let devServer;
+
+ before(async () => {
+ devServer = await fixture.startDevServer();
+ });
+
+ after(async () => {
+ await devServer.stop();
+ });
+
+ it('Work with hoisted scripts', async () => {
+ const html = await fixture.fetch('/').then(r => r.text());
+ const $ = cheerio.load(html);
+
+ expect($('script[src*="space in folder name"]')).to.have.a.lengthOf(1);
+ });
+ });
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 126fc2a6a..57c885655 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2275,6 +2275,12 @@ importers:
react: 18.2.0
react-dom: 18.2.0_react@18.2.0
+ packages/astro/test/fixtures/space in folder name/app:
+ specifiers:
+ astro: workspace:*
+ dependencies:
+ astro: link:../../../..
+
packages/astro/test/fixtures/special-chars-in-component-imports:
specifiers:
'@astrojs/mdx': workspace:*