From dd52f3cdcaed0967b5910a7c962180efb927f679 Mon Sep 17 00:00:00 2001 From: ZachJW34 Date: Tue, 19 Feb 2019 11:40:57 -0600 Subject: [PATCH] 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. --- packages/schematics/src/command-line/format.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/schematics/src/command-line/format.ts b/packages/schematics/src/command-line/format.ts index 79cdbd1460..e5c4c75370 100644 --- a/packages/schematics/src/command-line/format.ts +++ b/packages/schematics/src/command-line/format.ts @@ -4,6 +4,7 @@ import * as resolve from 'resolve'; import { getProjectRoots, parseFiles } from './shared'; import { YargsAffectedOptions } from './affected'; import { getTouchedProjects } from './touched'; +import { fileExists } from '../utils/fileutils'; export interface YargsFormatOptions extends YargsAffectedOptions { libsAndApps?: boolean; @@ -41,9 +42,11 @@ function getPatterns(args: YargsAffectedOptions) { } const p = parseFiles(args); - let patterns = p.files.filter(f => - PRETTIER_EXTENSIONS.map(ext => '.' + ext).includes(path.extname(f)) - ); + let patterns = p.files + .filter(f => fileExists(f)) + .filter(f => + PRETTIER_EXTENSIONS.map(ext => '.' + ext).includes(path.extname(f)) + ); const libsAndApp = args.libsAndApps; return libsAndApp ? getPatternsFromApps(patterns) : patterns;