Skip to content

Commit cd4cf24

Browse files
chore(kbn-cli-dev-mode): restart optimizer on DLL change
1 parent 71d9519 commit cd4cf24

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

packages/kbn-cli-dev-mode/src/cli_dev_mode.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ it('passes correct args to sub-classes', () => {
105105
"mapLogLine": [Function],
106106
"script": <absolute path>/scripts/kibana,
107107
"watcher": Watcher {
108+
"optimizerShouldRestart$": [MockFunction],
108109
"serverShouldRestart$": [MockFunction],
109110
},
110111
},
@@ -219,6 +220,7 @@ describe('#start()/#stop()', () => {
219220
watcherRun$ = new Rx.Subject();
220221
return {
221222
run$: watcherRun$,
223+
optimizerShouldRestart$: jest.fn(() => Rx.NEVER),
222224
};
223225
});
224226
DevServer.mockImplementation(() => {

packages/kbn-cli-dev-mode/src/cli_dev_mode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ export class CliDevMode {
245245
}
246246

247247
this.subscription.add(
248-
this.optimizer.run$
248+
// the same pattern as: `kibana/packages/kbn-cli-dev-mode/src/dev_server.ts`
249+
Rx.concat([undefined], this.watcher.optimizerShouldRestart$())
249250
.pipe(
251+
switchMap(() => this.optimizer.run$),
250252
// stop the optimizer as soon as we get an exit signal
251253
takeUntil(exitSignal$)
252254
)

packages/kbn-cli-dev-mode/src/watcher.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { REPO_ROOT } from '@kbn/repo-info';
1313
import { RepoSourceClassifier } from '@kbn/repo-source-classifier';
1414
import { ImportResolver } from '@kbn/import-resolver';
1515
import { makeMatcher } from '@kbn/picomatcher';
16+
import Path from 'path';
1617

1718
import 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

Comments
 (0)