Skip to content

Commit 9753acb

Browse files
committedApr 27, 2023
fix(core): handle nested gitignores in the filewatcher
1 parent 2be25eb commit 9753acb

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed
 

‎packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets';
1717
import { serverLogger } from './logger';
1818
import { Workspaces } from '../../config/workspaces';
1919
import { workspaceRoot } from '../../utils/workspace-root';
20+
import { execSync } from 'child_process';
2021

2122
let cachedSerializedProjectGraphPromise: Promise<{
2223
error: Error | null;
@@ -104,12 +105,29 @@ function computeWorkspaceConfigHash(projectsConfigurations: any) {
104105
return new HashingImpl().hashArray([JSON.stringify(projectsConfigurations)]);
105106
}
106107

108+
/**
109+
* Temporary work around to handle nested gitignores. The parcel file watcher doesn't handle them well,
110+
* so we need to filter them out here.
111+
*/
112+
function filterUpdatedFiles(files: string[]) {
113+
try {
114+
const quoted = files.map((f) => '"' + f + '"');
115+
const ignored = execSync(`git check-ignore ${quoted.join(' ')}`)
116+
.toString()
117+
.split('\n');
118+
return files.filter((f) => ignored.indexOf(f) === -1);
119+
} catch (e) {
120+
// none of the files were ignored
121+
return files;
122+
}
123+
}
124+
107125
async function processCollectedUpdatedAndDeletedFiles() {
108126
try {
109127
performance.mark('hash-watched-changes-start');
110-
const updatedFiles = await defaultFileHasher.hashFiles([
111-
...collectedUpdatedFiles.values(),
112-
]);
128+
const updatedFiles = await defaultFileHasher.hashFiles(
129+
filterUpdatedFiles([...collectedUpdatedFiles.values()])
130+
);
113131
const deletedFiles = [...collectedDeletedFiles.values()];
114132
performance.mark('hash-watched-changes-end');
115133
performance.measure(

‎packages/nx/src/daemon/server/watcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export async function subscribeToWorkspaceChanges(
8181
path: normalizePath(relative(workspaceRoot, event.path)),
8282
};
8383
if (
84-
workspaceRelativeEvent.path === '.gitignore' ||
84+
workspaceRelativeEvent.path.endsWith('.gitignore') ||
8585
workspaceRelativeEvent.path === '.nxignore'
8686
) {
8787
hasIgnoreFileUpdate = true;

1 commit comments

Comments
 (1)

vercel[bot] commented on Apr 27, 2023

@vercel[bot]

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.