Skip to content

Commit a9f6586

Browse files
committed
feat: support regex on cli
closes #245
1 parent 1f5f02d commit a9f6586

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/options/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { resolveClean } from '../features/clean'
77
import { resolveEntry } from '../features/entry'
88
import { resolveTarget } from '../features/target'
99
import { resolveTsconfig } from '../features/tsconfig'
10+
import { resolveRegex } from '../utils/general'
1011
import { logger } from '../utils/logger'
1112
import { normalizeFormat, readPackageJson } from '../utils/package'
1213
import type { Awaitable } from '../utils/types'
@@ -201,6 +202,8 @@ async function resolveConfig(
201202
cwd = process.cwd(),
202203
name,
203204
workspace,
205+
external,
206+
noExternal,
204207
} = userConfig
205208

206209
outDir = path.resolve(cwd, outDir)
@@ -216,6 +219,12 @@ async function resolveConfig(
216219
}
217220
target = resolveTarget(target, pkg, name)
218221
tsconfig = await resolveTsconfig(tsconfig, cwd, name)
222+
if (typeof external === 'string') {
223+
external = resolveRegex(external)
224+
}
225+
if (typeof noExternal === 'string') {
226+
noExternal = resolveRegex(noExternal)
227+
}
219228

220229
if (publint === true) publint = {}
221230

@@ -286,6 +295,8 @@ async function resolveConfig(
286295
copy: publicDir || copy,
287296
hash: hash ?? true,
288297
name,
298+
external,
299+
noExternal,
289300
}
290301

291302
return config

src/utils/general.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export function resolveComma<T extends string>(arr: T[]): T[] {
1616
return arr.flatMap((format) => format.split(',') as T[])
1717
}
1818

19+
export function resolveRegex(str: string): string | RegExp {
20+
if (str.length > 2 && str[0] === '/' && str.at(-1) === '/') {
21+
return new RegExp(str.slice(1, -1))
22+
}
23+
return str
24+
}
25+
1926
export function debounce<T extends (...args: any[]) => any>(
2027
fn: T,
2128
wait: number,

0 commit comments

Comments
 (0)