summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Swithinbank2024-07-29 15:22:08 +0200
committerGitHub2024-07-29 15:22:08 +0200
commit904ad47ea9588c0b1d8c583f3f04e4ae199474d9 (patch)
tree31ba8b074a90f65235548c7d0fb57c12865e346f
parent6757d97b0ae789e0c61a776ad9af742858c663b0 (diff)
downloadIT.starlight-904ad47ea9588c0b1d8c583f3f04e4ae199474d9.tar.gz
IT.starlight-904ad47ea9588c0b1d8c583f3f04e4ae199474d9.tar.bz2
IT.starlight-904ad47ea9588c0b1d8c583f3f04e4ae199474d9.zip
Fix bug for projects with spaces in their pathname (#2156)
-rw-r--r--.changeset/thirty-planes-divide.md5
-rw-r--r--packages/starlight/__e2e__/collection-config.test.ts4
-rw-r--r--packages/starlight/__e2e__/fixtures/custom src-dir/astro.config.mjs (renamed from packages/starlight/__e2e__/fixtures/custom-src-dir/astro.config.mjs)0
-rw-r--r--packages/starlight/__e2e__/fixtures/custom src-dir/package.json (renamed from packages/starlight/__e2e__/fixtures/custom-src-dir/package.json)0
-rw-r--r--packages/starlight/__e2e__/fixtures/custom src-dir/www/content/config.ts (renamed from packages/starlight/__e2e__/fixtures/custom-src-dir/www/content/config.ts)0
-rw-r--r--packages/starlight/__e2e__/fixtures/custom src-dir/www/env.d.ts (renamed from packages/starlight/__e2e__/fixtures/custom-src-dir/www/env.d.ts)0
-rw-r--r--packages/starlight/__e2e__/fixtures/custom src-dir/www/pages/custom.astro (renamed from packages/starlight/__e2e__/fixtures/custom-src-dir/www/pages/custom.astro)0
-rw-r--r--packages/starlight/integrations/virtual-user-config.ts13
-rw-r--r--pnpm-lock.yaml2
9 files changed, 19 insertions, 5 deletions
diff --git a/.changeset/thirty-planes-divide.md b/.changeset/thirty-planes-divide.md
new file mode 100644
index 00000000..bf74f696
--- /dev/null
+++ b/.changeset/thirty-planes-divide.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/starlight": patch
+---
+
+Fixes builds for projects with a space in their pathname
diff --git a/packages/starlight/__e2e__/collection-config.test.ts b/packages/starlight/__e2e__/collection-config.test.ts
index 5b26f9dc..7e9d6d06 100644
--- a/packages/starlight/__e2e__/collection-config.test.ts
+++ b/packages/starlight/__e2e__/collection-config.test.ts
@@ -1,6 +1,8 @@
import { expect, testFactory } from './test-utils';
-const test = await testFactory('./fixtures/custom-src-dir/');
+// This fixture contains a space in the directory so that we have a smoke test for building
+// Starlight projects with pathnames like this, which are a common source of bugs.
+const test = await testFactory('./fixtures/custom src-dir/');
test('builds a custom page using the `<StarlightPage>` component and a custom `srcDir`', async ({
page,
diff --git a/packages/starlight/__e2e__/fixtures/custom-src-dir/astro.config.mjs b/packages/starlight/__e2e__/fixtures/custom src-dir/astro.config.mjs
index 9e759d9e..9e759d9e 100644
--- a/packages/starlight/__e2e__/fixtures/custom-src-dir/astro.config.mjs
+++ b/packages/starlight/__e2e__/fixtures/custom src-dir/astro.config.mjs
diff --git a/packages/starlight/__e2e__/fixtures/custom-src-dir/package.json b/packages/starlight/__e2e__/fixtures/custom src-dir/package.json
index b6d71aca..b6d71aca 100644
--- a/packages/starlight/__e2e__/fixtures/custom-src-dir/package.json
+++ b/packages/starlight/__e2e__/fixtures/custom src-dir/package.json
diff --git a/packages/starlight/__e2e__/fixtures/custom-src-dir/www/content/config.ts b/packages/starlight/__e2e__/fixtures/custom src-dir/www/content/config.ts
index 45f60b01..45f60b01 100644
--- a/packages/starlight/__e2e__/fixtures/custom-src-dir/www/content/config.ts
+++ b/packages/starlight/__e2e__/fixtures/custom src-dir/www/content/config.ts
diff --git a/packages/starlight/__e2e__/fixtures/custom-src-dir/www/env.d.ts b/packages/starlight/__e2e__/fixtures/custom src-dir/www/env.d.ts
index acef35f1..acef35f1 100644
--- a/packages/starlight/__e2e__/fixtures/custom-src-dir/www/env.d.ts
+++ b/packages/starlight/__e2e__/fixtures/custom src-dir/www/env.d.ts
diff --git a/packages/starlight/__e2e__/fixtures/custom-src-dir/www/pages/custom.astro b/packages/starlight/__e2e__/fixtures/custom src-dir/www/pages/custom.astro
index 680eaaef..680eaaef 100644
--- a/packages/starlight/__e2e__/fixtures/custom-src-dir/www/pages/custom.astro
+++ b/packages/starlight/__e2e__/fixtures/custom src-dir/www/pages/custom.astro
diff --git a/packages/starlight/integrations/virtual-user-config.ts b/packages/starlight/integrations/virtual-user-config.ts
index d955ad50..75bdd0d0 100644
--- a/packages/starlight/integrations/virtual-user-config.ts
+++ b/packages/starlight/integrations/virtual-user-config.ts
@@ -19,8 +19,15 @@ export function vitePluginStarlightUserConfig(
build: Pick<AstroConfig['build'], 'format'>;
}
): NonNullable<ViteUserConfig['plugins']>[number] {
- const resolveId = (id: string) =>
- JSON.stringify(id.startsWith('.') ? resolve(fileURLToPath(root), id) : id);
+ /**
+ * Resolves module IDs to a usable format:
+ * - Relative paths (e.g. `'./module.js'`) are resolved against `base` and formatted as an absolute path.
+ * - Package identifiers (e.g. `'module'`) are returned unchanged.
+ *
+ * By default, `base` is the project root directory.
+ */
+ const resolveId = (id: string, base = root) =>
+ JSON.stringify(id.startsWith('.') ? resolve(fileURLToPath(base), id) : id);
const virtualComponentModules = Object.fromEntries(
Object.entries(opts.components).map(([name, path]) => [
@@ -50,7 +57,7 @@ export function vitePluginStarlightUserConfig(
: 'export const logos = {};',
'virtual:starlight/collection-config': `let userCollections;
try {
- userCollections = (await import('${new URL('./content/config.ts', srcDir).pathname}')).collections;
+ userCollections = (await import(${resolveId('./content/config.ts', srcDir)})).collections;
} catch {}
export const collections = userCollections;`,
...virtualComponentModules,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index da143b36..36f068d4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -222,7 +222,7 @@ importers:
specifier: ^4.10.2
version: 4.10.2(@types/node@18.16.19)(typescript@5.4.5)
- packages/starlight/__e2e__/fixtures/custom-src-dir:
+ packages/starlight/__e2e__/fixtures/custom src-dir:
dependencies:
'@astrojs/starlight':
specifier: workspace:*