@@ -23,12 +23,14 @@ export default class Patcher extends Logged {
23
23
dryRun = true ,
24
24
matchExt = Error . required ( 'matchExt' ) ,
25
25
patchExt = Error . required ( 'patchExt' ) ,
26
+ ignored
26
27
} ) {
27
28
super ( )
28
29
this . cwd = cwd
29
30
this . dryRun = dryRun
30
31
this . matchExt = matchExt
31
32
this . patchExt = patchExt
33
+ this . ignored = ignored
32
34
}
33
35
patched = { }
34
36
async patchAll ( ext ) {
@@ -76,6 +78,7 @@ export class MJSPatcher extends Patcher {
76
78
constructor ( options ) {
77
79
options . matchExt ??= '.mjs'
78
80
options . patchExt ??= '.dist.mjs'
81
+ options . ignored ??= / \. m ? j s /
79
82
super ( options )
80
83
}
81
84
patch ( {
@@ -92,13 +95,18 @@ export class MJSPatcher extends Patcher {
92
95
//@ts -ignore
93
96
const { type, source } = node
94
97
if ( source ?. value ) {
95
- const isRelative = source . value . startsWith ( './' ) || source . value . startsWith ( '../' )
98
+ const isRelative = source . value . startsWith ( './' ) || source . value . startsWith ( '../' )
96
99
const isNotPatched = ! source . value . endsWith ( patchExt )
100
+ const isIgnored = this . ignored && this . ignored . test ( source . value )
97
101
if ( isRelative && isNotPatched ) {
98
- const newValue = `${ source . value } ${ patchExt } `
99
- log . debug ( ' ' , source . value , '->' , newValue )
100
- Object . assign ( source , { value : newValue , raw : JSON . stringify ( newValue ) } )
101
- modified = true
102
+ if ( isIgnored ) {
103
+ log . debug ( ' ' , source . value , '-> leaving as is' )
104
+ } else {
105
+ const newValue = `${ source . value } ${ patchExt } `
106
+ log . debug ( ' ' , source . value , '->' , newValue )
107
+ Object . assign ( source , { value : newValue , raw : JSON . stringify ( newValue ) } )
108
+ modified = true
109
+ }
102
110
}
103
111
}
104
112
}
@@ -140,6 +148,7 @@ export class CJSPatcher extends Patcher {
140
148
constructor ( options ) {
141
149
options . matchExt ??= '.cjs'
142
150
options . patchExt ??= '.dist.cjs'
151
+ options . ignored ??= / \. c ? j s / // FIXME: don't ignore the ignore
143
152
super ( options )
144
153
}
145
154
patch ( {
0 commit comments