angular/devtools/tools/dev-server/ibazel.ts
AleksanderBodurri 445fbf81fd refactor(devtools): bring the angular devtools directory into the root bazel workspace
Previously devtools used a nested workspace for its bazel configurations. This meant framework dependencies were consumed via npm.

Now devtools is part of the root bazel directory that all other files in this codebase fall under. This allows us to build devtools using local angular packages, removing the need to consume these dependencies with npn. This is useful because we no longer have to update these dependencies with an automated tool like renovate, and our CI tests will always run against the most up to date framework packages.
2022-01-26 16:35:31 -05:00

43 lines
1.3 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {createInterface} from 'readline';
import {DevServer} from './dev-server';
// ibazel will write this string after a successful build.
const ibazelNotifySuccessMessage = 'IBAZEL_BUILD_COMPLETED SUCCESS';
/**
* Sets up ibazel support for the specified devserver. ibazel communicates with
* an executable over the "stdin" interface. Whenever a specific message is sent
* over "stdin", the devserver can be reloaded.
*/
export function setupBazelWatcherSupport(server: DevServer) {
// If iBazel is not configured for this process, we do not setup the watcher.
if (process.env['IBAZEL_NOTIFY_CHANGES'] !== 'y') {
return;
}
// ibazel communicates via the stdin interface.
const rl = createInterface({input: process.stdin, terminal: false});
rl.on('line', (chunk: string) => {
if (chunk === ibazelNotifySuccessMessage) {
server.reload();
}
});
rl.on('close', () => {
// Give ibazel 5s to kill this process, otherwise we exit the process manually.
setTimeout(() => {
console.error('ibazel failed to stop the devserver after 5s.');
process.exit(1);
}, 5000);
});
}