• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-cli / 12051387210

27 Nov 2024 01:33PM UTC coverage: 70.301% (-0.08%) from 70.38%
12051387210

push

github

web-flow
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 <nikolay.alipiev@gmail.com>

929 of 1359 branches covered (68.36%)

Branch coverage included in aggregate %.

5 of 21 new or added lines in 3 files covered. (23.81%)

2 existing lines in 1 file now uncovered.

4738 of 6702 relevant lines covered (70.7%)

86.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.08
/packages/ng-schematics/src/utils/NgFileSystem.ts
1
import { DirEntry, FileEntry, Tree } from "@angular-devkit/schematics";
2
import { App, FS_TOKEN, FS_TYPE_TOKEN, FsTypes, IFileSystem } from "@igniteui/cli-core";
1✔
3
import { minimatch } from 'minimatch';
1✔
4
import * as path from "path";
1✔
5

6
export class NgTreeFileSystem implements IFileSystem {
1✔
7
        constructor(private tree: Tree) { }
20✔
8
        public fileExists(filePath: string): boolean {
9
                return this.tree.exists(filePath);
45✔
10
        }
11

12
        public readFile(filePath: string, _encoding?: string): string {
13
                return (this.tree.read(filePath) || "").toString();
43!
14
        }
15

16
        public writeFile(filePath: string, text: string): void {
17
                return this.tree.overwrite(filePath, text);
5✔
18
        }
19

20
        public directoryExists(dirPath: string): boolean {
21
                const dir = this.tree.getDir(dirPath);
×
22
                return dir.subdirs.length || dir.subfiles.length ? true : false;
×
23
        }
24

25
        /**
26
         * Returns a list of file paths under a directory based on a match pattern
27
         * @param dirPath Root dir to search in
28
         * @param pattern Supports only recursive wildcard `\*\*\/\*`
29
         * @param ignorePatterns Optional patterns to ignore for each subdirectory
30
         */
31
        public glob(dirPath: string, pattern: string, ignorePatterns?: string[]): string[] {
32
                const dir = this.tree.getDir(dirPath);
×
33
                const entries: string[] = [];
×
34

NEW
35
                const visitor = (_fullPath: string, entry?: Readonly<FileEntry>): void => {
×
NEW
36
                        if (entry && minimatch(entry.path, pattern)) {
×
UNCOV
37
                                entries.push(entry.path);
×
38
                        }
39
                };
40

NEW
41
                if (ignorePatterns?.length) {
×
NEW
42
                        const recurse = (dir: DirEntry): void => {
×
NEW
43
                                for (const subdirPath of dir.subdirs) {
×
NEW
44
                                        if (ignorePatterns.every(p => !minimatch(subdirPath, p))) {
×
NEW
45
                                                const subDir = dir.dir(subdirPath);
×
NEW
46
                                                if (subDir.subdirs.length) {
×
NEW
47
                                                        recurse(subDir);
×
NEW
48
                                                        continue;
×
49
                                                }
NEW
50
                                                for (const file of dir.subfiles) {
×
NEW
51
                                                        if (minimatch(file, pattern) && ignorePatterns.every(p => !minimatch(file, p))) {
×
NEW
52
                                                                entries.push(path.posix.normalize(`${dir.path}/${file}`));
×
53
                                                        }
54
                                                }
55
                                        }
56
                                }
57
                        };
58

NEW
59
                        recurse(dir);
×
NEW
60
                        return entries;
×
61
                }
62

NEW
63
                dir.visit(visitor);
×
UNCOV
64
                return entries;
×
65
        }
66
}
67

68
export function setVirtual(tree: Tree) {
1✔
69
        App.container.set(FS_TOKEN, new NgTreeFileSystem(tree));
20✔
70
        App.container.set(FS_TYPE_TOKEN, FsTypes.virtual);
20✔
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc