Commit 18e6112 1 parent 4cbf694 commit 18e6112 Copy full SHA for 18e6112
File tree 3 files changed +44
-1
lines changed
3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1
1
import typescript from '@rollup/plugin-typescript'
2
+ import * as ts from 'typescript'
3
+
4
+ /**
5
+ * Strip out TS relative import path rewrite helper from dynamic import() calls
6
+ *
7
+ * Required due to
8
+ * https://github.com/rollup/plugins/issues/1820
9
+ *
10
+ * @param {ts.TransformationContext } context
11
+ */
12
+ function fixDynamicImportRewrite ( context ) {
13
+ /** @param {ts.SourceFile } source */
14
+ return function fixDynamicImport ( source ) {
15
+ /** @param {ts.Node } node */
16
+ function visitor ( node ) {
17
+ if (
18
+ ts . isCallExpression ( node ) &&
19
+ ts . isIdentifier ( node . expression ) &&
20
+ String ( node . expression . escapedText ) ===
21
+ '___rewriteRelativeImportExtension' &&
22
+ node . arguments . length === 1
23
+ ) {
24
+ return node . arguments [ 0 ]
25
+ }
26
+ return ts . visitEachChild ( node , visitor , context )
27
+ }
28
+ return ts . visitNode ( source , visitor )
29
+ }
30
+ }
2
31
3
32
export default [
4
33
{
@@ -20,6 +49,8 @@ export default [
20
49
input : 'src/cli.ts' ,
21
50
output : { file : 'dist/cli.mjs' } ,
22
51
external : ( ) => true ,
23
- plugins : [ typescript ( ) ]
52
+ plugins : [
53
+ typescript ( { transformers : { after : [ fixDynamicImportRewrite ] } } )
54
+ ]
24
55
}
25
56
]
Original file line number Diff line number Diff line change @@ -38,6 +38,17 @@ export default [
38
38
'no-control-regex' : 'off' ,
39
39
'no-fallthrough' : [ 'error' , { commentPattern : 'fallthrough' } ] ,
40
40
'no-implicit-globals' : 'error' ,
41
+ 'no-restricted-imports' : [
42
+ 'error' ,
43
+ {
44
+ patterns : [
45
+ {
46
+ regex : '^\\..*(?<!\\.ts)$' ,
47
+ message : 'Relative imports must use .ts extension.'
48
+ }
49
+ ]
50
+ }
51
+ ] ,
41
52
'no-template-curly-in-string' : 'warn' ,
42
53
'no-var' : 'error' ,
43
54
'prefer-const' : [ 'warn' , { destructuring : 'all' } ] ,
Original file line number Diff line number Diff line change 6
6
"noUnusedLocals" : true ,
7
7
"noUnusedParameters" : true ,
8
8
"outDir" : "dist" ,
9
+ "rewriteRelativeImportExtensions" : true ,
9
10
"rootDir" : "src" ,
10
11
"strict" : true ,
11
12
"target" : "ES2020" ,
You can’t perform that action at this time.
0 commit comments