Files
nrwl--nx/scripts/generate-graph.ts
Nicholas Cunningham 0ca4aacd0b feat(repo): use ts solution in the nx repo (#31654)
This PR updates the Nx repo to use ts solution to improve build
processes and module resolution via the `@nx/js/typescript` plugin.

- Added `@nx/js/typescript` (adding new targets `typecheck` and
`build-base`)
- Updated all e2e test projects for consistent module resolution. (Now
contains `package.json` for all dependencies)
- Fixed module resolution conflicts by streamlining `NODE_PATH` handling
in e2e tests.
- Added `legacy-post-build` executor merging `copy-asset` and
`package.json` cleanup.
- Added `package.json` to e2e projects for proper dependency management.

---------

Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
Co-authored-by: Emily Xiong <xiongemi@gmail.com>
Co-authored-by: yarden-island <yarden@island.io>
Co-authored-by: Julien Marcou <julien.marcou@convelio.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Colum Ferry <cferry09@gmail.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-18 14:49:03 -04:00

111 lines
2.6 KiB
TypeScript

import { execSync } from 'child_process';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import * as yargs from 'yargs';
import { ensureDirSync } 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);
})();