Skip to content

Commit 1cde375

Browse files
committed
fix(types): preserve emitted ts-ignore comments
1 parent 5f075a8 commit 1cde375

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

scripts/utils/postprocess-files.cjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ 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+
if (/\.d\.[cm]?ts$/.test(file)) {
33+
transformed = transformed.replace(/\/\*\* @ts-ignore ([^*]+?) \*\/ type /g, '// @ts-ignore $1\ntype ');
34+
}
35+
3236
if (transformed !== code) {
3337
console.error(`wrote ${path.relative(process.cwd(), file)}`);
3438
await fs.promises.writeFile(file, transformed, 'utf8');

0 commit comments

Comments
 (0)