Skip to content

Commit

Permalink
refactor(@angular/build): only ignore watching node modules when watc…
Browse files Browse the repository at this point in the history
…hing root

The application builder performs fine-grained file watching now which removes
the need to watch the project root by default as it did in early implementations.
As a result, the need to ignore the `node_modules` directory is not longer necessary
by default and is only needed when the `NG_BUILD_WATCH_ROOT` environment variable
is enabled.
  • Loading branch information
clydin committed Oct 8, 2024
1 parent 6ce5c69 commit 834925d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/angular/build/src/builders/application/build-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,6 @@ export async function* runEsBuildBuildAction(
`${workspaceRoot.replace(/\\/g, '/')}/**/.*/**`,
];

if (!preserveSymlinks) {
// Ignore all node modules directories to avoid excessive file watchers.
// Package changes are handled below by watching manifest and lock files.
// NOTE: this is not enable when preserveSymlinks is true as this would break `npm link` usages.
ignored.push('**/node_modules/**');
}

// Setup a watcher
const { createWatcher } = await import('../../tools/esbuild/watcher');
watcher = createWatcher({
Expand All @@ -119,15 +112,22 @@ export async function* runEsBuildBuildAction(

// Watch the entire project root if 'NG_BUILD_WATCH_ROOT' environment variable is set
if (shouldWatchRoot) {
if (!preserveSymlinks) {
// Ignore all node modules directories to avoid excessive file watchers.
// Package changes are handled below by watching manifest and lock files.
// NOTE: this is not enable when preserveSymlinks is true as this would break `npm link` usages.
ignored.push('**/node_modules/**');

watcher.add(
packageWatchFiles
.map((file) => path.join(workspaceRoot, file))
.filter((file) => existsSync(file)),
);
}

watcher.add(projectRoot);
}

watcher.add(
packageWatchFiles
.map((file) => path.join(workspaceRoot, file))
.filter((file) => existsSync(file)),
);

// Watch locations provided by the initial build result
watcher.add(result.watchFiles);
}
Expand Down

0 comments on commit 834925d

Please sign in to comment.