diff --git a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts index 6c15d555de4ec..653fb1960b32b 100644 --- a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts +++ b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts @@ -17,6 +17,7 @@ import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets'; import { serverLogger } from './logger'; import { Workspaces } from '../../config/workspaces'; import { workspaceRoot } from '../../utils/workspace-root'; +import { execSync } from 'child_process'; let cachedSerializedProjectGraphPromise: Promise<{ error: Error | null; @@ -104,12 +105,29 @@ function computeWorkspaceConfigHash(projectsConfigurations: any) { return new HashingImpl().hashArray([JSON.stringify(projectsConfigurations)]); } +/** + * Temporary work around to handle nested gitignores. The parcel file watcher doesn't handle them well, + * so we need to filter them out here. + */ +function filterUpdatedFiles(files: string[]) { + try { + const quoted = files.map((f) => '"' + f + '"'); + const ignored = execSync(`git check-ignore ${quoted.join(' ')}`) + .toString() + .split('\n'); + return files.filter((f) => ignored.indexOf(f) === -1); + } catch (e) { + // none of the files were ignored + return files; + } +} + async function processCollectedUpdatedAndDeletedFiles() { try { performance.mark('hash-watched-changes-start'); - const updatedFiles = await defaultFileHasher.hashFiles([ - ...collectedUpdatedFiles.values(), - ]); + const updatedFiles = await defaultFileHasher.hashFiles( + filterUpdatedFiles([...collectedUpdatedFiles.values()]) + ); const deletedFiles = [...collectedDeletedFiles.values()]; performance.mark('hash-watched-changes-end'); performance.measure( diff --git a/packages/nx/src/daemon/server/watcher.ts b/packages/nx/src/daemon/server/watcher.ts index c60d55996664d..7ba9bf1abe3f4 100644 --- a/packages/nx/src/daemon/server/watcher.ts +++ b/packages/nx/src/daemon/server/watcher.ts @@ -81,7 +81,7 @@ export async function subscribeToWorkspaceChanges( path: normalizePath(relative(workspaceRoot, event.path)), }; if ( - workspaceRelativeEvent.path === '.gitignore' || + workspaceRelativeEvent.path.endsWith('.gitignore') || workspaceRelativeEvent.path === '.nxignore' ) { hasIgnoreFileUpdate = true;