77 */
88
99import { BuilderContext } from '@angular-devkit/architect' ;
10- import { existsSync } from 'node:fs' ;
11- import path from 'node:path' ;
1210import {
1311 BuildOutputAsset ,
1412 ExecutionResult ,
@@ -21,10 +19,8 @@ import {
2119} from '../../tools/esbuild/stylesheets/sass-language' ;
2220import { logMessages , withNoProgress , withSpinner } from '../../tools/esbuild/utils' ;
2321import { ChangedFiles } from '../../tools/esbuild/watcher' ;
24- import { shouldWatchRoot } from '../../utils/environment-options' ;
2522import { initializeHash } from '../../utils/hash' ;
2623import { NormalizedCachedOptions } from '../../utils/normalize-cache' ;
27- import { toPosixPath } from '../../utils/path' ;
2824import { NormalizedApplicationBuildOptions , NormalizedOutputOptions } from './options' ;
2925import {
3026 ComponentUpdateResult ,
@@ -35,20 +31,6 @@ import {
3531 ResultMessage ,
3632} from './results' ;
3733
38- // Watch workspace for package manager changes
39- const packageWatchFiles = [
40- // manifest can affect module resolution
41- 'package.json' ,
42- // npm lock file
43- 'package-lock.json' ,
44- // pnpm lock file
45- 'pnpm-lock.yaml' ,
46- // yarn lock file including Yarn PnP manifest files (https://yarnpkg.com/advanced/pnp-spec/)
47- 'yarn.lock' ,
48- '.pnp.cjs' ,
49- '.pnp.data.json' ,
50- ] ;
51-
5234// eslint-disable-next-line max-lines-per-function
5335export async function * runEsBuildBuildAction (
5436 action : ( rebuildState ?: RebuildState ) => Promise < ExecutionResult > ,
@@ -115,55 +97,18 @@ export async function* runEsBuildBuildAction(
11597 logger . info ( 'Watch mode enabled. Watching for file changes...' ) ;
11698 }
11799
118- const normalizedOutputBase = toPosixPath ( outputOptions . base ) ;
119- const normalizedCacheBase = toPosixPath ( cacheOptions . basePath ) ;
120- const ignored : string [ ] = [
121- // Ignore the output and cache paths to avoid infinite rebuild cycles
122- normalizedOutputBase ,
123- `${ normalizedOutputBase } /**` ,
124- normalizedCacheBase ,
125- `${ normalizedCacheBase } /**` ,
126- `${ toPosixPath ( workspaceRoot ) } /**/.*/**` ,
127- ] ;
128-
129- if ( cacheOptions . localBasePath && cacheOptions . localBasePath !== cacheOptions . basePath ) {
130- const normalizedLocalCacheBase = toPosixPath ( cacheOptions . localBasePath ) ;
131- ignored . push ( normalizedLocalCacheBase , `${ normalizedLocalCacheBase } /**` ) ;
132- }
133-
134100 // Setup a watcher
135- const { createWatcher } = await import ( '../../tools/esbuild/watcher' ) ;
136- watcher = await createWatcher ( {
137- polling : typeof poll === 'number' ,
138- interval : poll ,
139- followSymlinks : preserveSymlinks ,
140- ignored,
141- cwd : workspaceRoot ,
101+ const { setupWatcher } = await import ( '../../tools/esbuild/watcher' ) ;
102+ watcher = await setupWatcher ( {
103+ workspaceRoot,
104+ projectRoot,
105+ outputPath : outputOptions . base ,
106+ cacheOptions,
107+ poll,
108+ preserveSymlinks,
109+ signal : options . signal ,
110+ watchFiles : result . watchFiles ,
142111 } ) ;
143-
144- // Setup abort support
145- options . signal ?. addEventListener ( 'abort' , ( ) => void watcher ?. close ( ) ) ;
146-
147- // Watch the entire project root if 'NG_BUILD_WATCH_ROOT' environment variable is set
148- if ( shouldWatchRoot ) {
149- if ( ! preserveSymlinks ) {
150- // Ignore all node modules directories to avoid excessive file watchers.
151- // Package changes are handled below by watching manifest and lock files.
152- // NOTE: this is not enable when preserveSymlinks is true as this would break `npm link` usages.
153- ignored . push ( '**/node_modules/**' ) ;
154-
155- watcher . add (
156- packageWatchFiles
157- . map ( ( file ) => path . join ( workspaceRoot , file ) )
158- . filter ( ( file ) => existsSync ( file ) ) ,
159- ) ;
160- }
161-
162- watcher . add ( projectRoot ) ;
163- }
164-
165- // Watch locations provided by the initial build result
166- watcher . add ( result . watchFiles ) ;
167112 }
168113
169114 // Output the first build results after setting up the watcher to ensure that any code executed
0 commit comments