Skip to content

Commit 63403c3

Browse files
authored
build: minor build script improvements (google#944)
1 parent 3b6c120 commit 63403c3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

scripts/build-js.mjs

+9-3
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ const {
5757
} = argv
5858

5959
const formats = format.split(',')
60-
const cwd = Array.isArray(_cwd) ? _cwd[_cwd.length - 1] : _cwd
60+
const cwd = [_cwd].flat().pop()
6161
const entries = entry.split(/:\s?/)
6262
const entryPoints = entry.includes('*')
6363
? await glob(entries, { absolute: false, onlyFiles: true, cwd, root: cwd })
6464
: entries.map((p) => path.relative(cwd, path.resolve(cwd, p)))
6565

66-
const _bundle = bundle !== 'none' && !process.argv.includes('--no-bundle')
66+
const _bundle = bundle && bundle !== 'none'
6767
const _external = _bundle ? external.split(',') : undefined // https://github.com/evanw/esbuild/issues/1466
6868

6969
const plugins = [
@@ -159,10 +159,16 @@ plugins.push(
159159

160160
function entryPointsToRegexp(entryPoints) {
161161
return new RegExp(
162-
'(' + entryPoints.map((e) => path.parse(e).name).join('|') + ')\\.cjs$'
162+
'(' +
163+
entryPoints.map((e) => escapeRegExp(path.parse(e).name)).join('|') +
164+
')\\.cjs$'
163165
)
164166
}
165167

168+
function escapeRegExp(str) {
169+
return str.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
170+
}
171+
166172
const esmConfig = {
167173
absWorkingDir: cwd,
168174
entryPoints,

0 commit comments

Comments
 (0)