Skip to content

Commit 029273f

Browse files
committed
feat: introduce escapeSpecialChars
1 parent 393cb1e commit 029273f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/core/options.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join, resolve } from 'node:path'
33
import { slash, toArray } from '@antfu/utils'
44
import { getPackageInfoSync, isPackageExists } from 'local-pkg'
55
import { detectTypeImports } from './type-imports/detect'
6+
import { escapeSpecialChars } from './utils'
67

78
export const defaultOptions: Omit<Required<Options>, 'include' | 'exclude' | 'excludeNames' | 'transformer' | 'globs' | 'globsExclude' | 'directives' | 'types' | 'version'> = {
89
dirs: 'src/components',
@@ -63,8 +64,8 @@ export function resolveOptions(options: Options, root: string): ResolvedOptions
6364
i = i.slice(1)
6465
}
6566
return resolved.deep
66-
? prefix + slash(join((i), `**/*.${extsGlob}`))
67-
: prefix + slash(join((i), `*.${extsGlob}`))
67+
? prefix + escapeSpecialChars((join(i, `**/*.${extsGlob}`)))
68+
: prefix + escapeSpecialChars((join(i, `*.${extsGlob}`)))
6869
})
6970

7071
if (!resolved.extensions.length)

src/core/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,9 @@ export function isExclude(name: string, exclude?: FilterPattern): boolean {
242242
}
243243
return false
244244
}
245+
246+
const ESCAPE_PARENTHESES_REGEX = /[(?:)]/g
247+
248+
export function escapeSpecialChars(str: string): string {
249+
return str.replace(ESCAPE_PARENTHESES_REGEX, '\\$&')
250+
}

0 commit comments

Comments
 (0)