Skip to content

Commit

Permalink
feat(create-astro): ts-check comment (#11924)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre committed Sep 6, 2024
1 parent 4a95159 commit 7d70ba3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-dogs-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Updates the default Astro config with `// @ts-check` if the Typescript preset is `strict` or `strictest`
15 changes: 15 additions & 0 deletions packages/create-astro/src/actions/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7d70ba3

Please sign in to comment.