using `windowsHide: true` is causing an issue on windows: Ctrl + C handling isn't enabled and no `SIGINT` is sent to the child process when users exit the process. See https://github.com/nodejs/node/issues/29837 and https://github.com/nodejs/node-v0.x-archive/issues/5054 for reference. This will cause leftover processes throughout nx. This PR sets `windowsHide: false` everywhere except for the plugin workers and some short-lived utils. They `spawn` child processes but have explicit handling to make sure they kill themselves when the parent process dies, so the missing Ctrl + C handling doesn't cause issues. We will follow up to make sure any other culprits that still cause windows popups (especially when used through Nx Console) are handled. Leaving no leftover processes running is more important for now, though. Keep in mind the underlying tooling (like vite) might have some windows popups themselves that Nx will inherit.
111 lines
2.7 KiB
TypeScript
111 lines
2.7 KiB
TypeScript
import { execSync } from 'child_process';
|
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
import * as yargs from 'yargs';
|
|
import { ensureDirSync, statSync } from 'fs-extra';
|
|
|
|
async function generateGraph(directory: string, name: string) {
|
|
if (!existsSync(directory)) {
|
|
console.error(`Could not find directory ${directory}`);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
execSync(
|
|
'npx nx graph --file ./node_modules/.cache/nx-graph-gen/graph.html',
|
|
{ cwd: directory, stdio: 'ignore', windowsHide: false }
|
|
);
|
|
} catch {
|
|
console.error(`Could not run graph command in directory ${directory}`);
|
|
return;
|
|
}
|
|
const environmentJs = readFileSync(
|
|
join(directory, 'node_modules/.cache/nx-graph-gen/static/environment.js'),
|
|
{ encoding: 'utf-8' }
|
|
);
|
|
|
|
const projectGraphResponse = environmentJs.match(
|
|
/window.projectGraphResponse = (.*?);/
|
|
);
|
|
|
|
const taskGraphResponse = environmentJs.match(
|
|
/window.taskGraphResponse = (.*?);/
|
|
);
|
|
|
|
const expandedTaskInputsReponse = environmentJs.match(
|
|
/window.expandedTaskInputsResponse = (.*?);/
|
|
);
|
|
|
|
const sourceMapsResponse = environmentJs.match(
|
|
/window.sourceMapsResponse = (.*?);/
|
|
);
|
|
|
|
ensureDirSync(
|
|
join(__dirname, '../graph/client/src/assets/generated-project-graphs/')
|
|
);
|
|
ensureDirSync(
|
|
join(__dirname, '../graph/client/src/assets/generated-task-graphs/')
|
|
);
|
|
ensureDirSync(
|
|
join(__dirname, '../graph/client/src/assets/generated-task-inputs/')
|
|
);
|
|
ensureDirSync(
|
|
join(__dirname, '../graph/client/src/assets/generated-source-maps/')
|
|
);
|
|
|
|
writeFileSync(
|
|
join(
|
|
__dirname,
|
|
'../graph/client/src/assets/generated-project-graphs/',
|
|
`${name}.json`
|
|
),
|
|
projectGraphResponse[1]
|
|
);
|
|
|
|
writeFileSync(
|
|
join(
|
|
__dirname,
|
|
'../graph/client/src/assets/generated-task-graphs/',
|
|
`${name}.json`
|
|
),
|
|
taskGraphResponse[1]
|
|
);
|
|
|
|
writeFileSync(
|
|
join(
|
|
__dirname,
|
|
'../graph/client/src/assets/generated-task-inputs/',
|
|
`${name}.json`
|
|
),
|
|
expandedTaskInputsReponse[1]
|
|
);
|
|
|
|
writeFileSync(
|
|
join(
|
|
__dirname,
|
|
'../graph/client/src/assets/generated-source-maps/',
|
|
`${name}.json`
|
|
),
|
|
sourceMapsResponse[1]
|
|
);
|
|
}
|
|
|
|
(async () => {
|
|
const parsedArgs = yargs
|
|
.scriptName('pnpm generate-graph')
|
|
.strictOptions()
|
|
.option('name', {
|
|
type: 'string',
|
|
requiresArg: true,
|
|
description: 'The snake-case name of the file created',
|
|
})
|
|
.option('directory', {
|
|
type: 'string',
|
|
requiresArg: true,
|
|
description: 'Directory of workspace',
|
|
})
|
|
.parseSync();
|
|
|
|
await generateGraph(parsedArgs.directory, parsedArgs.name);
|
|
})();
|