mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +08:00
refactor(@angular-devkit/core): use picomatch for PatternMatchingHost glob support
The glob support in the `PatternMatchingHost` class now uses the capabilities of the `picomatch` package to convert glob strings into regular expressions. This removes custom string replacement code that previously was used. The `picomatch` package is already used by `@angular-devkit/build-angular` and is present in the repository but is a new dependency for the `@angular-devkit/core` package specifically.
This commit is contained in:
parent
683f84dc13
commit
f9372acb1a
@ -34,9 +34,11 @@ ts_library(
|
||||
module_root = "src/index.d.ts",
|
||||
deps = [
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/picomatch",
|
||||
"@npm//ajv",
|
||||
"@npm//ajv-formats",
|
||||
"@npm//jsonc-parser",
|
||||
"@npm//picomatch",
|
||||
"@npm//rxjs",
|
||||
"@npm//source-map",
|
||||
# @node_module: typescript:es2015.proxy
|
||||
|
@ -28,6 +28,7 @@
|
||||
"ajv-formats": "2.1.1",
|
||||
"ajv": "8.12.0",
|
||||
"jsonc-parser": "3.2.0",
|
||||
"picomatch": "2.3.1",
|
||||
"rxjs": "7.8.1",
|
||||
"source-map": "0.7.4"
|
||||
},
|
||||
|
@ -6,6 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import { parse as parseGlob } from 'picomatch';
|
||||
import { Path } from '../path';
|
||||
import { ResolverHost } from './resolver';
|
||||
|
||||
@ -17,28 +18,11 @@ export class PatternMatchingHost<StatsT extends object = {}> extends ResolverHos
|
||||
protected _patterns = new Map<RegExp, ReplacementFunction>();
|
||||
|
||||
addPattern(pattern: string | string[], replacementFn: ReplacementFunction) {
|
||||
// Simple GLOB pattern replacement.
|
||||
const reString =
|
||||
'^(' +
|
||||
(Array.isArray(pattern) ? pattern : [pattern])
|
||||
.map(
|
||||
(ex) =>
|
||||
'(' +
|
||||
ex
|
||||
.split(/[/\\]/g)
|
||||
.map((f) =>
|
||||
f
|
||||
.replace(/[-[\]{}()+?.^$|]/g, '\\$&')
|
||||
.replace(/^\*\*/g, '(.+?)?')
|
||||
.replace(/\*/g, '[^/\\\\]*'),
|
||||
)
|
||||
.join('[/\\\\]') +
|
||||
')',
|
||||
)
|
||||
.join('|') +
|
||||
')($|/|\\\\)';
|
||||
|
||||
this._patterns.set(new RegExp(reString), replacementFn);
|
||||
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
||||
for (const glob of patterns) {
|
||||
const { output } = parseGlob(glob);
|
||||
this._patterns.set(new RegExp(`^${output}$`), replacementFn);
|
||||
}
|
||||
}
|
||||
|
||||
protected _resolve(path: Path) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user