Skip to content

Commit a1e50dc

Browse files
DevRohit06claude
andcommitted
fix: wrap astro-llms-txt plugin to fix Windows path handling
The @4hse/astro-llms-txt plugin uses dir.pathname which returns /C:/Users/... on Windows, causing doubled drive letters and file not found errors. Inject a wrapper that uses fileURLToPath() to normalize the path before passing it to the plugin. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 795a2f7 commit a1e50dc

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

package-lock.json

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/config.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,43 @@ export async function generateConfig(projectDir, options, frameworkConfig = null
108108
if (await pathExists(astroConfigPath)) {
109109
let content = await readFile(astroConfigPath, "utf-8");
110110

111-
// Add import after the last existing import line
112-
const importLine = `import astroLlmsTxt from '@4hse/astro-llms-txt';`;
113-
if (!content.includes(importLine)) {
111+
// Add imports after the last existing import line
112+
const importLines = [
113+
`import _astroLlmsTxt from '@4hse/astro-llms-txt';`,
114+
`import { fileURLToPath as _llmsFileURLToPath } from 'url';`,
115+
];
116+
// Wrapper: fix Windows dir.pathname (/C:/... → C:/...) before passing to plugin
117+
const wrapperFn = `function astroLlmsTxt(opts) {
118+
const inner = _astroLlmsTxt(opts);
119+
const origHook = inner.hooks['astro:build:done'];
120+
inner.hooks['astro:build:done'] = async (args) => {
121+
if (args.dir && args.dir.pathname) {
122+
const fixed = _llmsFileURLToPath(args.dir);
123+
args = { ...args, dir: { ...args.dir, pathname: fixed } };
124+
}
125+
return origHook(args);
126+
};
127+
return inner;
128+
}`;
129+
for (const importLine of importLines) {
130+
if (!content.includes(importLine)) {
131+
const lines = content.split('\n');
132+
let lastImportIdx = 0;
133+
for (let i = 0; i < lines.length; i++) {
134+
if (lines[i].startsWith('import ')) lastImportIdx = i;
135+
}
136+
lines.splice(lastImportIdx + 1, 0, importLine);
137+
content = lines.join('\n');
138+
}
139+
}
140+
// Inject wrapper function after imports
141+
if (!content.includes('function astroLlmsTxt(')) {
114142
const lines = content.split('\n');
115143
let lastImportIdx = 0;
116144
for (let i = 0; i < lines.length; i++) {
117145
if (lines[i].startsWith('import ')) lastImportIdx = i;
118146
}
119-
lines.splice(lastImportIdx + 1, 0, importLine);
147+
lines.splice(lastImportIdx + 1, 0, '', wrapperFn);
120148
content = lines.join('\n');
121149
}
122150

0 commit comments

Comments
 (0)