Skip to content

Commit f99e106

Browse files
clydinangular-robot[bot]
authored andcommitted
refactor(@angular-devkit/build-angular): directly watch package lock files in esbuild builder
When using the esbuild-based browser application builder in watch mode, all `node_modules` directories will now be ignored by the file watcher. Instead all relevant package manifests and lock files for `npm`, `yarn, and `pnpm` will be watched to detect potential changes to the project's dependencies. This avoids creating a potentially large amount of filesystem watchers as the node modules directories can be very large.
1 parent 8e57db6 commit f99e106

File tree

1 file changed

+22
-7
lines changed
  • packages/angular_devkit/build_angular/src/builders/browser-esbuild

1 file changed

+22
-7
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -677,18 +677,33 @@ export async function* buildEsbuildBrowser(
677677
const watcher = createWatcher({
678678
polling: typeof userOptions.poll === 'number',
679679
interval: userOptions.poll,
680-
// Ignore the output and cache paths to avoid infinite rebuild cycles
681-
ignored: [normalizedOptions.outputPath, normalizedOptions.cacheOptions.basePath],
680+
ignored: [
681+
// Ignore the output and cache paths to avoid infinite rebuild cycles
682+
normalizedOptions.outputPath,
683+
normalizedOptions.cacheOptions.basePath,
684+
// Ignore all node modules directories to avoid excessive file watchers.
685+
// Package changes are handled below by watching manifest and lock files.
686+
'**/node_modules/**',
687+
],
682688
});
683689

684690
// Temporarily watch the entire project
685691
watcher.add(normalizedOptions.projectRoot);
686692

687-
// Watch workspace root node modules
688-
// Includes Yarn PnP manifest files (https://yarnpkg.com/advanced/pnp-spec/)
689-
watcher.add(path.join(normalizedOptions.workspaceRoot, 'node_modules'));
690-
watcher.add(path.join(normalizedOptions.workspaceRoot, '.pnp.cjs'));
691-
watcher.add(path.join(normalizedOptions.workspaceRoot, '.pnp.data.json'));
693+
// Watch workspace for package manager changes
694+
const packageWatchFiles = [
695+
// manifest can affect module resolution
696+
'package.json',
697+
// npm lock file
698+
'package-lock.json',
699+
// pnpm lock file
700+
'pnpm-lock.yaml',
701+
// yarn lock file including Yarn PnP manifest files (https://yarnpkg.com/advanced/pnp-spec/)
702+
'yarn.lock',
703+
'.pnp.cjs',
704+
'.pnp.data.json',
705+
];
706+
watcher.add(packageWatchFiles.map((file) => path.join(normalizedOptions.workspaceRoot, file)));
692707

693708
// Wait for changes and rebuild as needed
694709
try {

0 commit comments

Comments
 (0)