diff options
author | Chris Swithinbank | 2024-09-08 11:00:43 +0200 |
---|---|---|
committer | GitHub | 2024-09-08 11:00:43 +0200 |
commit | f92791aa1d1ec3d5498e445a078f7143fef60553 (patch) | |
tree | b2f7347ca53f2d49b12bb97a88a66ccbc0feb330 | |
parent | 367af7e219ccaefa951444a9edb125007bf95943 (diff) | |
download | IT.starlight-f92791aa1d1ec3d5498e445a078f7143fef60553.tar.gz IT.starlight-f92791aa1d1ec3d5498e445a078f7143fef60553.tar.bz2 IT.starlight-f92791aa1d1ec3d5498e445a078f7143fef60553.zip |
Convert URL to file path correctly for Git virtual module (#2303)
Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com>
-rw-r--r-- | .changeset/strange-clouds-lay.md | 5 | ||||
-rw-r--r-- | packages/starlight/integrations/virtual-user-config.ts | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/.changeset/strange-clouds-lay.md b/.changeset/strange-clouds-lay.md new file mode 100644 index 00000000..1405b2c7 --- /dev/null +++ b/.changeset/strange-clouds-lay.md @@ -0,0 +1,5 @@ +--- +"@astrojs/starlight": patch +--- + +Fixes resolution for the internal module Git virtual module in projects with special characters in the file path diff --git a/packages/starlight/integrations/virtual-user-config.ts b/packages/starlight/integrations/virtual-user-config.ts index c0bd6089..92207e0c 100644 --- a/packages/starlight/integrations/virtual-user-config.ts +++ b/packages/starlight/integrations/virtual-user-config.ts @@ -31,6 +31,15 @@ export function vitePluginStarlightUserConfig( const resolveId = (id: string, base = root) => JSON.stringify(id.startsWith('.') ? resolve(fileURLToPath(base), id) : id); + /** + * Resolves a path to a Starlight file relative to this file. + * @example + * resolveLocalPath('../utils/git.ts'); + * // => '"/users/houston/docs/node_modules/@astrojs/starlight/utils/git.ts"' + */ + const resolveLocalPath = (path: string) => + JSON.stringify(fileURLToPath(new URL(path, import.meta.url))); + const docsPath = resolve(fileURLToPath(srcDir), 'content/docs'); const virtualComponentModules = Object.fromEntries( @@ -51,9 +60,9 @@ export function vitePluginStarlightUserConfig( })}`, 'virtual:starlight/git-info': (command !== 'build' - ? `import { makeAPI } from '${new URL('../utils/git.ts', import.meta.url)}';` + + ? `import { makeAPI } from ${resolveLocalPath('../utils/git.ts')};` + `const api = makeAPI(${JSON.stringify(docsPath)});` - : `import { makeAPI } from '${new URL('../utils/gitInlined.ts', import.meta.url)}';` + + : `import { makeAPI } from ${resolveLocalPath('../utils/gitInlined.ts')};` + `const api = makeAPI(${JSON.stringify(getAllNewestCommitDate(docsPath))});`) + 'export const getNewestCommitDate = api.getNewestCommitDate;', 'virtual:starlight/user-css': opts.customCss.map((id) => `import ${resolveId(id)};`).join(''), |