@nx/vite
Version:
74 lines (73 loc) • 2.77 kB
JavaScript
Object.defineProperty(exports, "nxViteBuildCoordinationPlugin", {
enumerable: true,
get: function() {
return nxViteBuildCoordinationPlugin;
}
});
const _watch = require("nx/src/command-line/watch/watch");
const _child_process = require("child_process");
const _client = require("nx/src/daemon/client/client");
const _output = require("nx/src/utils/output");
function nxViteBuildCoordinationPlugin(options) {
let activeBuildProcess;
let unregisterFileWatcher;
async function buildChangedProjects() {
await new Promise((res)=>{
activeBuildProcess = (0, _child_process.exec)(options.buildCommand, {
windowsHide: false
});
activeBuildProcess.stdout.pipe(process.stdout);
activeBuildProcess.stderr.pipe(process.stderr);
activeBuildProcess.on('exit', ()=>{
res();
});
activeBuildProcess.on('error', ()=>{
res();
});
});
activeBuildProcess = undefined;
}
function createFileWatcher() {
const runner = new _watch.BatchFunctionRunner(()=>buildChangedProjects());
return _client.daemonClient.registerFileWatcher({
watchProjects: 'all'
}, (err, { changedProjects, changedFiles })=>{
if (err === 'closed') {
_output.output.error({
title: 'Watch connection closed',
bodyLines: [
'The daemon had closed the connection to this watch process.',
'Please restart your watch command.'
]
});
process.exit(1);
}
if (activeBuildProcess) {
activeBuildProcess.kill(2);
activeBuildProcess = undefined;
}
runner.enqueue(changedProjects, changedFiles);
});
}
let firstBuildStart = true;
return {
name: 'nx-vite-build-coordination-plugin',
async buildStart () {
if (firstBuildStart) {
firstBuildStart = false;
await buildChangedProjects();
if (_client.daemonClient.enabled()) {
unregisterFileWatcher = await createFileWatcher();
process.on('exit', ()=>unregisterFileWatcher());
process.on('SIGINT', ()=>process.exit());
} else {
_output.output.warn({
title: 'Nx Daemon is not enabled. Projects will not be rebuilt when files change.'
});
}
}
}
};
}
//# sourceMappingURL=nx-vite-build-coordination.plugin.js.map
;