summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiDeoo2024-06-28 17:19:08 +0200
committerGitHub2024-06-28 17:19:08 +0200
commitdbfd3eeccacb5f5b77d75213dac3b30dc0be6deb (patch)
tree0676ad72e78ae23f9142f1fa629e213dfbc0e10a
parent0bcf93ba7bf7ed0b269a093c01af8aa83517ab2a (diff)
downloadIT.starlight-dbfd3eeccacb5f5b77d75213dac3b30dc0be6deb.tar.gz
IT.starlight-dbfd3eeccacb5f5b77d75213dac3b30dc0be6deb.tar.bz2
IT.starlight-dbfd3eeccacb5f5b77d75213dac3b30dc0be6deb.zip
Fix usage of `<StarlightPage>` with a custom `srcDir` configuration (#2054)
-rw-r--r--.changeset/tidy-brooms-complain.md5
-rw-r--r--packages/starlight/__e2e__/collection-config.test.ts12
-rw-r--r--packages/starlight/__e2e__/fixtures/custom-src-dir/astro.config.mjs11
-rw-r--r--packages/starlight/__e2e__/fixtures/custom-src-dir/package.json9
-rw-r--r--packages/starlight/__e2e__/fixtures/custom-src-dir/www/content/config.ts6
-rw-r--r--packages/starlight/__e2e__/fixtures/custom-src-dir/www/env.d.ts2
-rw-r--r--packages/starlight/__e2e__/fixtures/custom-src-dir/www/pages/custom.astro7
-rw-r--r--packages/starlight/integrations/virtual-user-config.ts2
-rw-r--r--packages/starlight/playwright.config.ts1
-rw-r--r--pnpm-lock.yaml9
10 files changed, 63 insertions, 1 deletions
diff --git a/.changeset/tidy-brooms-complain.md b/.changeset/tidy-brooms-complain.md
new file mode 100644
index 00000000..b501ba49
--- /dev/null
+++ b/.changeset/tidy-brooms-complain.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/starlight': patch
+---
+
+Fixes an issue when using the `<StarlightPage>` component in a custom page with a user-defined `srcDir` configuration.
diff --git a/packages/starlight/__e2e__/collection-config.test.ts b/packages/starlight/__e2e__/collection-config.test.ts
new file mode 100644
index 00000000..5b26f9dc
--- /dev/null
+++ b/packages/starlight/__e2e__/collection-config.test.ts
@@ -0,0 +1,12 @@
+import { expect, testFactory } from './test-utils';
+
+const test = await testFactory('./fixtures/custom-src-dir/');
+
+test('builds a custom page using the `<StarlightPage>` component and a custom `srcDir`', async ({
+ page,
+ starlight,
+}) => {
+ await starlight.goto('/custom');
+
+ await expect(page.getByText('Hello')).toBeVisible();
+});
diff --git a/packages/starlight/__e2e__/fixtures/custom-src-dir/astro.config.mjs b/packages/starlight/__e2e__/fixtures/custom-src-dir/astro.config.mjs
new file mode 100644
index 00000000..de22ac39
--- /dev/null
+++ b/packages/starlight/__e2e__/fixtures/custom-src-dir/astro.config.mjs
@@ -0,0 +1,11 @@
+import starlight from '@astrojs/starlight';
+import { defineConfig } from 'astro/config';
+
+export default defineConfig({
+ srcDir: './www',
+ integrations: [
+ starlight({
+ title: 'Custom src directory',
+ }),
+ ],
+});
diff --git a/packages/starlight/__e2e__/fixtures/custom-src-dir/package.json b/packages/starlight/__e2e__/fixtures/custom-src-dir/package.json
new file mode 100644
index 00000000..b6d71aca
--- /dev/null
+++ b/packages/starlight/__e2e__/fixtures/custom-src-dir/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@e2e/custom-src-dir",
+ "version": "0.0.0",
+ "private": true,
+ "dependencies": {
+ "@astrojs/starlight": "workspace:*",
+ "astro": "^4.10.2"
+ }
+}
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
new file mode 100644
index 00000000..45f60b01
--- /dev/null
+++ b/packages/starlight/__e2e__/fixtures/custom-src-dir/www/content/config.ts
@@ -0,0 +1,6 @@
+import { defineCollection } from 'astro:content';
+import { docsSchema } from '@astrojs/starlight/schema';
+
+export const collections = {
+ docs: defineCollection({ schema: docsSchema() }),
+};
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
new file mode 100644
index 00000000..acef35f1
--- /dev/null
+++ b/packages/starlight/__e2e__/fixtures/custom-src-dir/www/env.d.ts
@@ -0,0 +1,2 @@
+/// <reference path="../.astro/types.d.ts" />
+/// <reference types="astro/client" />
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
new file mode 100644
index 00000000..680eaaef
--- /dev/null
+++ b/packages/starlight/__e2e__/fixtures/custom-src-dir/www/pages/custom.astro
@@ -0,0 +1,7 @@
+---
+import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
+---
+
+<StarlightPage frontmatter={{ title: 'A custom page' }}>
+ <p>Hello</p>
+</StarlightPage>
diff --git a/packages/starlight/integrations/virtual-user-config.ts b/packages/starlight/integrations/virtual-user-config.ts
index b51f8e38..d955ad50 100644
--- a/packages/starlight/integrations/virtual-user-config.ts
+++ b/packages/starlight/integrations/virtual-user-config.ts
@@ -50,7 +50,7 @@ export function vitePluginStarlightUserConfig(
: 'export const logos = {};',
'virtual:starlight/collection-config': `let userCollections;
try {
- userCollections = (await import('/src/content/config.ts')).collections;
+ userCollections = (await import('${new URL('./content/config.ts', srcDir).pathname}')).collections;
} catch {}
export const collections = userCollections;`,
...virtualComponentModules,
diff --git a/packages/starlight/playwright.config.ts b/packages/starlight/playwright.config.ts
index 01098ea8..e16c146c 100644
--- a/packages/starlight/playwright.config.ts
+++ b/packages/starlight/playwright.config.ts
@@ -12,4 +12,5 @@ export default defineConfig({
},
],
testMatch: '__e2e__/*.test.ts',
+ workers: 1,
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 516d3ae4..eecee635 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -219,6 +219,15 @@ 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:
+ dependencies:
+ '@astrojs/starlight':
+ specifier: workspace:*
+ version: link:../../..
+ astro:
+ specifier: ^4.10.2
+ version: 4.10.2(@types/node@18.16.19)(typescript@5.4.5)
+
packages/tailwind:
dependencies:
'@astrojs/starlight':