Skip to content

Commit 5523213

Browse files
committed
feat(4.1): patcher: ignore precompiled
1 parent 0a626be commit 5523213

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "@hackbg/ubik",
44
"type": "module",
55
"main": "ubik.mjs",
6-
"version": "4.0.0",
6+
"version": "4.1.0",
77
"license": "AGPL-3.0-only",
88
"keywords": [ "typescript" ],
99
"homepage": "https://github.com/hackbg/ubik",

src/Patcher.mjs

+14-5
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ export default class Patcher extends Logged {
2323
dryRun = true,
2424
matchExt = Error.required('matchExt'),
2525
patchExt = Error.required('patchExt'),
26+
ignored
2627
}) {
2728
super()
2829
this.cwd = cwd
2930
this.dryRun = dryRun
3031
this.matchExt = matchExt
3132
this.patchExt = patchExt
33+
this.ignored = ignored
3234
}
3335
patched = {}
3436
async patchAll (ext) {
@@ -76,6 +78,7 @@ export class MJSPatcher extends Patcher {
7678
constructor (options) {
7779
options.matchExt ??= '.mjs'
7880
options.patchExt ??= '.dist.mjs'
81+
options.ignored ??= /\.m?js/
7982
super(options)
8083
}
8184
patch ({
@@ -92,13 +95,18 @@ export class MJSPatcher extends Patcher {
9295
//@ts-ignore
9396
const { type, source } = node
9497
if (source?.value) {
95-
const isRelative = source.value.startsWith('./') || source.value.startsWith('../')
98+
const isRelative = source.value.startsWith('./') || source.value.startsWith('../')
9699
const isNotPatched = !source.value.endsWith(patchExt)
100+
const isIgnored = this.ignored && this.ignored.test(source.value)
97101
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+
}
102110
}
103111
}
104112
}
@@ -140,6 +148,7 @@ export class CJSPatcher extends Patcher {
140148
constructor (options) {
141149
options.matchExt ??= '.cjs'
142150
options.patchExt ??= '.dist.cjs'
151+
options.ignored ??= /\.c?js/ // FIXME: don't ignore the ignore
143152
super(options)
144153
}
145154
patch ({

0 commit comments

Comments
 (0)