|
1 | 1 | import typescript from '@rollup/plugin-typescript'
|
2 | 2 | import * as ts from 'typescript'
|
3 | 3 |
|
| 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 | + |
4 | 24 | /**
|
5 | 25 | * Strip out TS relative import path rewrite helper from dynamic import() calls
|
6 | 26 | *
|
@@ -42,15 +62,22 @@ export default [
|
42 | 62 | esModule: false,
|
43 | 63 | preserveModules: true
|
44 | 64 | },
|
45 |
| - plugins: [typescript()], |
| 65 | + plugins: [ |
| 66 | + typescript({ |
| 67 | + transformers: { afterDeclarations: [fixDeclarationImportPaths] } |
| 68 | + }) |
| 69 | + ], |
46 | 70 | treeshake: { moduleSideEffects: false, propertyReadSideEffects: false }
|
47 | 71 | },
|
48 | 72 | {
|
49 | 73 | input: 'src/cli.ts',
|
50 | 74 | output: { file: 'dist/cli.mjs' },
|
51 | 75 | external: () => true,
|
52 | 76 | plugins: [
|
53 |
| - typescript({ transformers: { after: [fixDynamicImportRewrite] } }) |
| 77 | + typescript({ |
| 78 | + declaration: false, |
| 79 | + transformers: { after: [fixDynamicImportRewrite] } |
| 80 | + }) |
54 | 81 | ]
|
55 | 82 | }
|
56 | 83 | ]
|
0 commit comments