Skip to content

Commit a927722

Browse files
committed
fix(core): fix(core): abide by .nxignore when hashing files
ISSUES CLOSED: #3897
1 parent cf7d779 commit a927722

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/workspace/src/core/file-utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ export function allFilesInDir(
151151
return res;
152152
}
153153

154-
function getIgnoredGlobs() {
154+
function readFileIfExisting(path: string) {
155+
return fs.existsSync(path) ? fs.readFileSync(path, 'UTF-8').toString() : '';
156+
}
157+
158+
export function getIgnoredGlobs() {
155159
const ig = ignore();
156160
ig.add(readFileIfExisting(`${appRootPath}/.gitignore`));
157161
ig.add(readFileIfExisting(`${appRootPath}/.nxignore`));
158162
return ig;
159163
}
160164

161-
function readFileIfExisting(path: string) {
162-
return fs.existsSync(path) ? fs.readFileSync(path, 'UTF-8').toString() : '';
163-
}
164-
165165
export function readWorkspaceJson(): any {
166166
return readJsonFile(`${appRootPath}/${workspaceFileName()}`);
167167
}

packages/workspace/src/core/hasher/hasher.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { ProjectGraph } from '../project-graph';
22
import { NxJson } from '../shared-interfaces';
33
import { Task } from '../../tasks-runner/tasks-runner';
44
import { readFileSync } from 'fs';
5-
import { rootWorkspaceFileNames } from '../file-utils';
5+
import { getIgnoredGlobs, rootWorkspaceFileNames } from '../file-utils';
66
import { execSync } from 'child_process';
77
import {
88
defaultFileHasher,
99
extractNameAndVersion,
1010
FileHasher,
1111
} from './file-hasher';
1212
import { defaultHashing, HashingImp } from './hashing-impl';
13+
import { Ignore } from 'ignore';
1314

1415
const resolve = require('resolve');
1516

@@ -50,12 +51,14 @@ export class Hasher {
5051
private fileHasher: FileHasher;
5152
private projectHashes: ProjectHasher;
5253
private hashing: HashingImp;
54+
private ignore: Ignore;
5355

5456
constructor(
5557
private readonly projectGraph: ProjectGraph,
5658
private readonly nxJson: NxJson,
5759
private readonly options: any,
58-
hashing: HashingImp = undefined
60+
hashing: HashingImp = undefined,
61+
ignore: Ignore = getIgnoredGlobs()
5962
) {
6063
if (!hashing) {
6164
this.hashing = defaultHashing;
@@ -69,6 +72,7 @@ export class Hasher {
6972
this.fileHasher,
7073
this.hashing
7174
);
75+
this.ignore = ignore;
7276
}
7377

7478
async hashTasks(tasks: Task[]): Promise<Hash[]> {
@@ -153,7 +157,7 @@ export class Hasher {
153157

154158
const fileNames = [
155159
...Object.keys(this.nxJson.implicitDependencies || {}),
156-
...rootWorkspaceFileNames(),
160+
...rootWorkspaceFileNames().filter((name) => !this.ignore.ignores(name)),
157161
'package-lock.json',
158162
'yarn.lock',
159163
];

0 commit comments

Comments
 (0)