Skip to content

Commit f17ba61

Browse files
chore(internal): codegen related update
1 parent 759b9c9 commit f17ba61

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

scripts/utils/postprocess-files.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ async function postprocess() {
2323

2424
// strip out lib="dom", types="node", and types="react" references; these
2525
// are needed at build time, but would pollute the user's TS environment
26-
const transformed = code.replace(
26+
let transformed = code.replace(
2727
/^ *\/\/\/ *<reference +(lib="dom"|types="(node|react)").*?\n/gm,
2828
// replace with same number of characters to avoid breaking source maps
2929
(match) => ' '.repeat(match.length - 1) + '\n',
3030
);
3131

32+
// TypeScript's declaration emitter collapses /** @ts-ignore */ onto the same
33+
// line as the type declaration, which doesn't work. So we convert to // @ts-ignore
34+
// on its own line to properly suppresses errors.
35+
if (file.endsWith('.d.ts') || file.endsWith('.d.mts') || file.endsWith('.d.cts')) {
36+
transformed = transformed.replace(/\/\*\* @ts-ignore\b[^*]*\*\/ /gm, '// @ts-ignore\n');
37+
}
38+
3239
if (transformed !== code) {
3340
console.error(`wrote ${path.relative(process.cwd(), file)}`);
3441
await fs.promises.writeFile(file, transformed, 'utf8');

0 commit comments

Comments
 (0)