@@ -12,18 +12,32 @@ const {
1212
1313const root = resolve ( rootPackageJSONPath , '../' ) ;
1414
15- const watchPaths = new Set ( [ './src/' ] ) ;
15+ const dependingLocalPackages = new Set ( Object . keys ( currentPackageJSON . localDependencies || { } ) ) ;
16+ /** @type Map<string, string> */
17+ const localPackageJSONPath = new Map ( ) ;
1618
17- for ( const [ packageName ] of Object . entries ( currentPackageJSON . localDependencies || { } ) ) {
19+ for ( const packageName of Array . from ( dependingLocalPackages ) ) {
1820 for ( const workspace of workspaces ) {
1921 const packageJSON = await readPackage ( { cwd : resolve ( root , workspace ) } ) ;
2022
2123 if ( packageJSON . name === packageName ) {
22- watchPaths . add ( resolve ( root , workspace , 'package.json' ) ) ;
24+ for ( const transientLocalPackageName of Object . keys ( packageJSON . localDependencies ) ) {
25+ dependingLocalPackages . delete ( transientLocalPackageName ) ;
26+ }
27+
28+ localPackageJSONPath . set ( packageName , resolve ( root , workspace , 'package.json' ) ) ;
2329 }
2430 }
2531}
2632
33+ const watchPaths = new Set ( [ './src/' ] ) ;
34+
35+ // Only includes packages that are absolutely needed to watch.
36+ // For example, "api -> api-graph -> core" and "api -> core". Then we only need to watch "api-graph" but not "core".
37+ for ( const packageName of dependingLocalPackages ) {
38+ localPackageJSONPath . has ( packageName ) && watchPaths . add ( localPackageJSONPath . get ( packageName ) ) ;
39+ }
40+
2741// "nodemon" will pick up every file change, trigger build too many times.
2842// console.log(
2943// `node --watch ${watchPaths.map(path => `--watch-path "${path}"`).join(' ')} --watch-preserve-output $(which npm) run build:run`
0 commit comments