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:
parent
4a95159746
commit
7d70ba3178
2 changed files with 20 additions and 0 deletions
5
.changeset/nasty-dogs-sort.md
Normal file
5
.changeset/nasty-dogs-sort.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'create-astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Updates the default Astro config with `// @ts-check` if the Typescript preset is `strict` or `strictest`
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue