@@ -13,6 +13,7 @@ import { REPO_ROOT } from '@kbn/repo-info';
1313import { RepoSourceClassifier } from '@kbn/repo-source-classifier' ;
1414import { ImportResolver } from '@kbn/import-resolver' ;
1515import { makeMatcher } from '@kbn/picomatcher' ;
16+ import Path from 'path' ;
1617
1718import type { Log } from './log' ;
1819
@@ -41,6 +42,7 @@ export class Watcher {
4142 private readonly repoRoot : string ;
4243 private readonly classifier : RepoSourceClassifier ;
4344 private readonly restart$ = new Rx . Subject < void > ( ) ;
45+ private readonly restartOptimizer$ = new Rx . Subject < void > ( ) ;
4446 private readonly resolver : ImportResolver ;
4547
4648 constructor ( options : Options ) {
@@ -63,6 +65,11 @@ export class Watcher {
6365 this . restart$ . next ( ) ;
6466 } ;
6567
68+ const fireOptimizer = ( repoRel : string ) => {
69+ this . log . warn ( `restarting optimizer` , `due to changes in ${ repoRel } ` ) ;
70+ this . restartOptimizer$ . next ( ) ;
71+ } ;
72+
6673 Pw . subscribe (
6774 this . repoRoot ,
6875 ( error , events ) => {
@@ -139,13 +146,43 @@ export class Watcher {
139146 }
140147 ) ;
141148
149+ const sharedDepsDir = Path . resolve (
150+ this . repoRoot ,
151+ 'target/build/src/platform/packages/private/kbn-ui-shared-deps-npm/shared_built_assets'
152+ ) ;
153+ const manifestName = 'kbn-ui-shared-deps-npm-manifest.json' ;
154+
155+ // check for shared dependencies manifest update and restart Optimizer
156+ Pw . subscribe ( sharedDepsDir , ( err , events ) => {
157+ if ( err ) return ;
158+
159+ const isManifestChanged = events . some (
160+ ( e ) =>
161+ Path . basename ( e . path ) === manifestName && ( e . type === 'update' || e . type === 'create' )
162+ ) ;
163+
164+ if ( isManifestChanged ) {
165+ fireOptimizer ( Path . relative ( this . repoRoot , Path . join ( sharedDepsDir , manifestName ) ) ) ;
166+ }
167+ } ) . then (
168+ ( sub ) => subscriber . add ( ( ) => sub . unsubscribe ( ) ) ,
169+ ( ) => {
170+ // ignore errors, file might not exist
171+ }
172+ ) ;
173+
142174 // complete state subjects when run$ completes
143175 subscriber . add ( ( ) => {
144176 this . restart$ . complete ( ) ;
177+ this . restartOptimizer$ . complete ( ) ;
145178 } ) ;
146179 } ) ;
147180
148181 serverShouldRestart$ ( ) {
149182 return this . restart$ . asObservable ( ) ;
150183 }
184+
185+ optimizerShouldRestart$ ( ) {
186+ return this . restartOptimizer$ . asObservable ( ) ;
187+ }
151188}
0 commit comments