Skip to content

Commit 0ccd1b5

Browse files
committed
Invert ignore check
1 parent 8333a45 commit 0ccd1b5

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

apps/rush-lib/src/logic/ProjectChangeAnalyzer.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class ProjectChangeAnalyzer {
3434
* undefined === data isn't available (i.e. - git isn't present)
3535
*/
3636
private _data: Map<string, Map<string, string>> | undefined | UNINITIALIZED = UNINITIALIZED;
37+
private _filteredData: Map<string, Map<string, string>> = new Map<string, Map<string, string>>();
3738
private _projectStateCache: Map<string, string> = new Map<string, string>();
3839
private _rushConfiguration: RushConfiguration;
3940
private readonly _git: Git;
@@ -55,6 +56,12 @@ export class ProjectChangeAnalyzer {
5556
projectName: string,
5657
terminal: Terminal
5758
): Promise<Map<string, string> | undefined> {
59+
// Check the cache for any existing data
60+
const existingData: Map<string, string> | undefined = this._filteredData.get(projectName);
61+
if (existingData) {
62+
return existingData;
63+
}
64+
5865
if (this._data === UNINITIALIZED) {
5966
this._data = await this._getDataAsync(terminal);
6067
}
@@ -70,22 +77,26 @@ export class ProjectChangeAnalyzer {
7077
}
7178

7279
const unfilteredProjectData: Map<string, string> = this._data.get(projectName)!;
73-
const filteredProjectData: Map<string, string> = new Map(unfilteredProjectData);
80+
let filteredProjectData: Map<string, string> | undefined;
7481

7582
const ignoreMatcher: Ignore | undefined = await this._getIgnoreMatcherForProjectAsync(project, terminal);
7683
if (ignoreMatcher) {
7784
// At this point, `filePath` is guaranteed to start with `projectRelativeFolder`, so
7885
// we can safely slice off the first N characters to get the file path relative to the
7986
// root of the project.
80-
for (const [filePath] of unfilteredProjectData) {
87+
filteredProjectData = new Map<string, string>();
88+
for (const [filePath, fileHash] of unfilteredProjectData) {
8189
const relativePath: string = filePath.slice(project.projectRelativeFolder.length + 1);
82-
if (ignoreMatcher.ignores(relativePath)) {
83-
// Remove from the filtered data as we encounter the ignored files
84-
filteredProjectData.delete(filePath);
90+
if (!ignoreMatcher.ignores(relativePath)) {
91+
// Add the file path to the filtered data if it is not ignored
92+
filteredProjectData.set(filePath, fileHash);
8593
}
8694
}
95+
} else {
96+
filteredProjectData = unfilteredProjectData;
8797
}
8898

99+
this._filteredData.set(projectName, filteredProjectData);
89100
return filteredProjectData;
90101
}
91102

@@ -189,7 +200,7 @@ export class ProjectChangeAnalyzer {
189200
owningProjectHashDeps = new Map<string, string>();
190201
projectHashDeps.set(owningProject.packageName, owningProjectHashDeps);
191202
}
192-
owningProjectHashDeps!.set(filePath, fileHash);
203+
owningProjectHashDeps.set(filePath, fileHash);
193204
}
194205
}
195206

0 commit comments

Comments
 (0)