Skip to content

Commit 0e236e7

Browse files
authored
Fix pattern matching when upgrading packages (#1347)
* refactor(ng-fs): spawn visitor for subdirs if an ignore pattern is provided * refactor(ngfs): pattern match with minimatch * refactor(ngfs): allow multiple ignore patterns - update - ignore dist and node_modules by default - upgrade-packages - set default framework & project type --------- Co-authored-by: Nikolay Alipiev <[email protected]>
2 parents 2fedb28 + b714285 commit 0e236e7

File tree

6 files changed

+70
-22
lines changed

6 files changed

+70
-22
lines changed

packages/core/types/FileSystem.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export interface IFileSystem {
88
* Returns a list of file paths under a directory based on a match pattern
99
* @param dirPath Root dir to search in
1010
* @param pattern Pattern to match
11+
* @param ignorePatterns Optional pattern to ignore for each subdirectory
1112
*/
12-
glob(dirPath: string, pattern: string, ignorePattern?: string): string[];
13+
glob(dirPath: string, pattern: string, ignorePatterns?: string[]): string[];
1314
}
1415

1516
export const FS_TOKEN: string = "fs";

packages/core/update/Update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
6161
const logicFiles = [];
6262
const styleFiles = [];
6363
const pkgJsonFiles = [];
64-
pkgJsonFiles.push(...fs.glob(rootPath, `package.json`, "node_modules"));
64+
pkgJsonFiles.push(...fs.glob(rootPath, `package.json`, ['node_modules', 'dist']));
6565

6666
let workspaceConfig = null;
6767
switch (framework.toLowerCase()) {

packages/ng-schematics/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
"@igniteui/angular-templates": "~19.0.1431",
2424
"@igniteui/cli-core": "~14.3.1",
2525
"@schematics/angular": "~19.0.0",
26-
"rxjs": "^7.8.1"
26+
"rxjs": "^7.8.1",
27+
"minimatch": "^10.0.1"
2728
},
2829
"devDependencies": {
2930
"@types/jasmine": "^5.1.4",
3031
"@types/node": "^22.5.5",
32+
"@types/minimatch": "^5.1.2",
3133
"jasmine": "^5.3.0",
3234
"typescript": "~5.6.2"
3335
},

packages/ng-schematics/src/upgrade-packages/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export default function(options: UpgradeOptions): Rule {
1818
});
1919
const templateManager = new SchematicsTemplateManager();
2020
const config = ProjectConfig.getConfig();
21-
const library = templateManager.getProjectLibrary(config.project.framework, config.project.projectType);
21+
const library = templateManager.getProjectLibrary('angular', config.project?.projectType || 'igx-ts');
2222
let project: ProjectTemplate;
23-
if (!config.project.projectTemplate || !library.hasProject(config.project.projectTemplate)) {
23+
if (!config.project?.projectTemplate || !library.hasProject(config.project?.projectTemplate)) {
2424
// in case project template is missing from the config we provide backward.
2525
project = library.getProject(library.projectIds[0]);
2626
} else {

packages/ng-schematics/src/utils/NgFileSystem.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { Tree } from "@angular-devkit/schematics";
1+
import { DirEntry, FileEntry, Tree } from "@angular-devkit/schematics";
22
import { App, FS_TOKEN, FS_TYPE_TOKEN, FsTypes, IFileSystem } from "@igniteui/cli-core";
3+
import { minimatch } from 'minimatch';
4+
import * as path from "path";
35

46
export class NgTreeFileSystem implements IFileSystem {
57
constructor(private tree: Tree) { }
68
public fileExists(filePath: string): boolean {
79
return this.tree.exists(filePath);
810
}
911

10-
public readFile(filePath: string, encoding?: string): string {
12+
public readFile(filePath: string, _encoding?: string): string {
1113
return (this.tree.read(filePath) || "").toString();
1214
}
1315

@@ -23,24 +25,42 @@ export class NgTreeFileSystem implements IFileSystem {
2325
/**
2426
* Returns a list of file paths under a directory based on a match pattern
2527
* @param dirPath Root dir to search in
26-
* @param pattern Supports only recursive wildcard '\*\*\/\*'
27-
* @param ignorePattern Optional pattern to ignore
28+
* @param pattern Supports only recursive wildcard `\*\*\/\*`
29+
* @param ignorePatterns Optional patterns to ignore for each subdirectory
2830
*/
29-
public glob(dirPath: string, pattern: string, ignorePattern?: string): string[] {
31+
public glob(dirPath: string, pattern: string, ignorePatterns?: string[]): string[] {
3032
const dir = this.tree.getDir(dirPath);
3133
const entries: string[] = [];
32-
pattern = pattern.split("**/*").pop() || pattern;
3334

34-
dir.visit((_fullPath, entry) => {
35-
if (ignorePattern && entry?.path.includes(ignorePattern)) {
36-
return;
37-
}
38-
39-
if (entry?.path.endsWith(pattern)) {
35+
const visitor = (_fullPath: string, entry?: Readonly<FileEntry>): void => {
36+
if (entry && minimatch(entry.path, pattern)) {
4037
entries.push(entry.path);
4138
}
42-
});
39+
};
40+
41+
if (ignorePatterns?.length) {
42+
const recurse = (dir: DirEntry): void => {
43+
for (const subdirPath of dir.subdirs) {
44+
if (ignorePatterns.every(p => !minimatch(subdirPath, p))) {
45+
const subDir = dir.dir(subdirPath);
46+
if (subDir.subdirs.length) {
47+
recurse(subDir);
48+
continue;
49+
}
50+
for (const file of dir.subfiles) {
51+
if (minimatch(file, pattern) && ignorePatterns.every(p => !minimatch(file, p))) {
52+
entries.push(path.posix.normalize(`${dir.path}/${file}`));
53+
}
54+
}
55+
}
56+
}
57+
};
58+
59+
recurse(dir);
60+
return entries;
61+
}
4362

63+
dir.visit(visitor);
4464
return entries;
4565
}
4666
}

yarn.lock

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,7 +4915,7 @@ [email protected]:
49154915
dependencies:
49164916
brace-expansion "^2.0.1"
49174917

4918-
minimatch@^10.0.0:
4918+
minimatch@^10.0.0, minimatch@^10.0.1:
49194919
version "10.0.1"
49204920
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-10.0.1.tgz#ce0521856b453c86e25f2c4c0d03e6ff7ddc440b"
49214921
integrity sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==
@@ -6701,7 +6701,16 @@ stream-throttle@^0.1.3:
67016701
commander "^2.2.0"
67026702
limiter "^1.0.5"
67036703

6704-
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
6704+
"string-width-cjs@npm:string-width@^4.2.0":
6705+
version "4.2.3"
6706+
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
6707+
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
6708+
dependencies:
6709+
emoji-regex "^8.0.0"
6710+
is-fullwidth-code-point "^3.0.0"
6711+
strip-ansi "^6.0.1"
6712+
6713+
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
67056714
version "4.2.3"
67066715
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
67076716
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -6761,7 +6770,14 @@ string_decoder@~1.1.1:
67616770
dependencies:
67626771
safe-buffer "~5.1.0"
67636772

6764-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6773+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
6774+
version "6.0.1"
6775+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
6776+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
6777+
dependencies:
6778+
ansi-regex "^5.0.1"
6779+
6780+
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
67656781
version "6.0.1"
67666782
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
67676783
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -7408,7 +7424,7 @@ wordwrap@^1.0.0:
74087424
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
74097425
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
74107426

7411-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
7427+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
74127428
version "7.0.0"
74137429
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
74147430
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -7426,6 +7442,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
74267442
string-width "^4.1.0"
74277443
strip-ansi "^6.0.0"
74287444

7445+
wrap-ansi@^7.0.0:
7446+
version "7.0.0"
7447+
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
7448+
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
7449+
dependencies:
7450+
ansi-styles "^4.0.0"
7451+
string-width "^4.1.0"
7452+
strip-ansi "^6.0.0"
7453+
74297454
wrap-ansi@^8.1.0:
74307455
version "8.1.0"
74317456
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)