0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

feat(create-astro): ts-check comment (#11924)

This commit is contained in:
Florian Lefebvre 2024-09-06 14:23:02 +02:00 committed by GitHub
parent 4a95159746
commit 7d70ba3178
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'create-astro': patch
---
Updates the default Astro config with `// @ts-check` if the Typescript preset is `strict` or `strictest`

View file

@ -140,6 +140,21 @@ const FILES_TO_UPDATE = {
} }
} }
}, },
'astro.config.mjs': async (file: string, options: { value: string }) => {
if (!(options.value === 'strict' || options.value === 'strictest')) {
return;
}
try {
let data = await readFile(file, { encoding: 'utf-8' });
data = `// @ts-check\n${data}`;
await writeFile(file, data, { encoding: 'utf-8' });
} catch (err) {
// if there's no astro.config.mjs (which is very unlikely), then do nothing
if (err && (err as any).code === 'ENOENT') return;
if (err instanceof Error) throw new Error(err.message);
}
},
}; };
export async function setupTypeScript(value: string, ctx: PickedTypeScriptContext) { export async function setupTypeScript(value: string, ctx: PickedTypeScriptContext) {