Skip to content

Commit

Permalink
fix(core): fix(core): abide by .nxignore when hashing files
Browse files Browse the repository at this point in the history
ISSUES CLOSED: nrwl#3897
  • Loading branch information
yharaskrik committed Oct 19, 2020
1 parent cf7d779 commit a927722
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/workspace/src/core/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ export function allFilesInDir(
return res;
}

function getIgnoredGlobs() {
function readFileIfExisting(path: string) {
return fs.existsSync(path) ? fs.readFileSync(path, 'UTF-8').toString() : '';
}

export function getIgnoredGlobs() {
const ig = ignore();
ig.add(readFileIfExisting(`${appRootPath}/.gitignore`));
ig.add(readFileIfExisting(`${appRootPath}/.nxignore`));
return ig;
}

function readFileIfExisting(path: string) {
return fs.existsSync(path) ? fs.readFileSync(path, 'UTF-8').toString() : '';
}

export function readWorkspaceJson(): any {
return readJsonFile(`${appRootPath}/${workspaceFileName()}`);
}
Expand Down
10 changes: 7 additions & 3 deletions packages/workspace/src/core/hasher/hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { ProjectGraph } from '../project-graph';
import { NxJson } from '../shared-interfaces';
import { Task } from '../../tasks-runner/tasks-runner';
import { readFileSync } from 'fs';
import { rootWorkspaceFileNames } from '../file-utils';
import { getIgnoredGlobs, rootWorkspaceFileNames } from '../file-utils';
import { execSync } from 'child_process';
import {
defaultFileHasher,
extractNameAndVersion,
FileHasher,
} from './file-hasher';
import { defaultHashing, HashingImp } from './hashing-impl';
import { Ignore } from 'ignore';

const resolve = require('resolve');

Expand Down Expand Up @@ -50,12 +51,14 @@ export class Hasher {
private fileHasher: FileHasher;
private projectHashes: ProjectHasher;
private hashing: HashingImp;
private ignore: Ignore;

constructor(
private readonly projectGraph: ProjectGraph,
private readonly nxJson: NxJson,
private readonly options: any,
hashing: HashingImp = undefined
hashing: HashingImp = undefined,
ignore: Ignore = getIgnoredGlobs()
) {
if (!hashing) {
this.hashing = defaultHashing;
Expand All @@ -69,6 +72,7 @@ export class Hasher {
this.fileHasher,
this.hashing
);
this.ignore = ignore;
}

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

const fileNames = [
...Object.keys(this.nxJson.implicitDependencies || {}),
...rootWorkspaceFileNames(),
...rootWorkspaceFileNames().filter((name) => !this.ignore.ignores(name)),
'package-lock.json',
'yarn.lock',
];
Expand Down

0 comments on commit a927722

Please sign in to comment.