fix(nx): filter non-existing files during format (#1087)

Formatting of uncommitted files errors when the only change is the deletion of files. Checking if
the file exists before writing solves this issue.
This commit is contained in:
ZachJW34 2019-02-19 11:40:57 -06:00 committed by Jason Jean
parent 36b8ff9c94
commit dd52f3cdca

View File

@ -4,6 +4,7 @@ import * as resolve from 'resolve';
import { getProjectRoots, parseFiles } from './shared'; import { getProjectRoots, parseFiles } from './shared';
import { YargsAffectedOptions } from './affected'; import { YargsAffectedOptions } from './affected';
import { getTouchedProjects } from './touched'; import { getTouchedProjects } from './touched';
import { fileExists } from '../utils/fileutils';
export interface YargsFormatOptions extends YargsAffectedOptions { export interface YargsFormatOptions extends YargsAffectedOptions {
libsAndApps?: boolean; libsAndApps?: boolean;
@ -41,9 +42,11 @@ function getPatterns(args: YargsAffectedOptions) {
} }
const p = parseFiles(args); const p = parseFiles(args);
let patterns = p.files.filter(f => let patterns = p.files
PRETTIER_EXTENSIONS.map(ext => '.' + ext).includes(path.extname(f)) .filter(f => fileExists(f))
); .filter(f =>
PRETTIER_EXTENSIONS.map(ext => '.' + ext).includes(path.extname(f))
);
const libsAndApp = args.libsAndApps; const libsAndApp = args.libsAndApps;
return libsAndApp ? getPatternsFromApps(patterns) : patterns; return libsAndApp ? getPatternsFromApps(patterns) : patterns;