fix(nx-plugin): ignoring Additional Files from Affected Commands (#2519)

* fix(nx-plugin): ignoring Additional Files from Affected Commands

ISSUES CLOSED: #2517
This commit is contained in:
Jimmy 2020-02-23 06:06:10 +08:00 committed by GitHub
parent 74716df4fc
commit 06b0e7fe6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import { calculateFileChanges, WholeFileChange } from './file-utils';
import { DiffType, JsonChange, jsonDiff } from '../utils/json-diff';
const ignore = require('ignore');
describe('calculateFileChanges', () => {
it('should return a whole file change by default', () => {
const changes = calculateFileChanges(
@ -63,4 +65,18 @@ describe('calculateFileChanges', () => {
}
});
});
it('should ignore *.md changes', () => {
const ig = ignore();
ig.add('*.md');
const changes = calculateFileChanges(
['proj/readme.md'],
undefined,
(path, revision) => {
return revision === 'sha1' ? '' : 'const a = 0;';
},
ig
);
expect(changes.length).toEqual(0);
});
});

View File

@ -41,8 +41,12 @@ export function calculateFileChanges(
readFileAtRevision: (
f: string,
r: void | string
) => string = defaultReadFileAtRevision
) => string = defaultReadFileAtRevision,
ignore = getIgnoredGlobs()
): FileChange[] {
if (ignore) {
files = files.filter(f => !ignore.ignores(f));
}
return files.map(f => {
const ext = extname(f);
const _mtime = mtime(`${appRootPath}/${f}`);