Skip to content

Commit ab240c1

Browse files
committed
fix: Drop .ts extension from import & export paths in .d.ts files
1 parent c4c49f9 commit ab240c1

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

config/rollup.node-config.mjs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import typescript from '@rollup/plugin-typescript'
22
import * as ts from 'typescript'
33

4+
/**
5+
* Drop .ts extension from import & export paths in .d.ts files
6+
* to support older TS versions.
7+
*
8+
* @param {ts.TransformationContext} context
9+
*/
10+
function fixDeclarationImportPaths(context) {
11+
/** @param {ts.SourceFile} source */
12+
return function fixPaths(source) {
13+
/** @param {ts.Node} node */
14+
function visitor(node) {
15+
if (ts.isStringLiteral(node) && /^\.+\/.*\.ts$/.test(node.text)) {
16+
return ts.factory.createStringLiteral(node.text.slice(0, -3), true)
17+
}
18+
return ts.visitEachChild(node, visitor, context)
19+
}
20+
return ts.visitNode(source, visitor)
21+
}
22+
}
23+
424
/**
525
* Strip out TS relative import path rewrite helper from dynamic import() calls
626
*
@@ -42,15 +62,22 @@ export default [
4262
esModule: false,
4363
preserveModules: true
4464
},
45-
plugins: [typescript()],
65+
plugins: [
66+
typescript({
67+
transformers: { afterDeclarations: [fixDeclarationImportPaths] }
68+
})
69+
],
4670
treeshake: { moduleSideEffects: false, propertyReadSideEffects: false }
4771
},
4872
{
4973
input: 'src/cli.ts',
5074
output: { file: 'dist/cli.mjs' },
5175
external: () => true,
5276
plugins: [
53-
typescript({ transformers: { after: [fixDynamicImportRewrite] } })
77+
typescript({
78+
declaration: false,
79+
transformers: { after: [fixDynamicImportRewrite] }
80+
})
5481
]
5582
}
5683
]

0 commit comments

Comments
 (0)