Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/angular_devkit/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
28 changes: 6 additions & 22 deletions packages/angular_devkit/core/src/virtual-fs/host/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) {
Expand Down