Skip to content

Commit

Permalink
fix(core): handle nested gitignores in the filewatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Apr 27, 2023
1 parent 2be25eb commit 9753acb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/daemon/server/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

1 comment on commit 9753acb

@vercel
Copy link

@vercel vercel bot commented on 9753acb Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.