cleanup(core): move js graph creation its own folder (#14283)
This commit is contained in:
parent
e002bd3479
commit
dc6da76900
@ -103,7 +103,7 @@ describe('js e2e', () => {
|
||||
const swcHelpersFromDist = readJson(`dist/libs/${lib}/package.json`)
|
||||
.peerDependencies['@swc/helpers'];
|
||||
|
||||
expect(satisfies(swcHelpersFromDist, swcHelpersFromRoot)).toBeTruthy();
|
||||
expect(swcHelpersFromDist).toEqual(swcHelpersFromRoot);
|
||||
|
||||
updateJson(`libs/${lib}/.lib.swcrc`, (json) => {
|
||||
json.jsc.externalHelpers = false;
|
||||
|
||||
@ -144,11 +144,8 @@ describe('js e2e', () => {
|
||||
const rootPackageJson = readJson(`package.json`);
|
||||
|
||||
expect(
|
||||
satisfies(
|
||||
readJson(`dist/libs/${lib}/package.json`).peerDependencies.tslib,
|
||||
rootPackageJson.dependencies.tslib
|
||||
)
|
||||
).toBeTruthy();
|
||||
readJson(`dist/libs/${lib}/package.json`).peerDependencies.tslib
|
||||
).toEqual(rootPackageJson.dependencies.tslib);
|
||||
|
||||
updateJson(`libs/${lib}/tsconfig.json`, (json) => {
|
||||
json.compilerOptions = { ...json.compilerOptions, importHelpers: false };
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
packageInstall,
|
||||
promisifiedTreeKill,
|
||||
readFile,
|
||||
readJson,
|
||||
runCLI,
|
||||
runCLIAsync,
|
||||
runCommandUntil,
|
||||
@ -22,7 +23,6 @@ import {
|
||||
import { exec, execSync } from 'child_process';
|
||||
import * as http from 'http';
|
||||
import { getLockFileName } from 'nx/src/lock-file/lock-file';
|
||||
import { satisfies } from 'semver';
|
||||
|
||||
function getData(port, path = '/api'): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
@ -246,6 +246,7 @@ describe('Build Node apps', () => {
|
||||
detectPackageManager(tmpProjPath())
|
||||
)}`
|
||||
);
|
||||
const rootPackageJson = JSON.parse(readFile(`package.json`));
|
||||
const packageJson = JSON.parse(
|
||||
readFile(`dist/apps/${nestapp}/package.json`)
|
||||
);
|
||||
@ -256,17 +257,22 @@ describe('Build Node apps', () => {
|
||||
version: '0.0.1',
|
||||
})
|
||||
);
|
||||
expect(
|
||||
satisfies(packageJson.dependencies['@nestjs/common'], '^9.0.0')
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
satisfies(packageJson.dependencies['@nestjs/core'], '^9.0.0')
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
satisfies(packageJson.dependencies['reflect-metadata'], '^0.1.13')
|
||||
).toBeTruthy();
|
||||
expect(satisfies(packageJson.dependencies['rxjs'], '^7.0.0')).toBeTruthy();
|
||||
expect(satisfies(packageJson.dependencies['tslib'], '^2.3.0')).toBeTruthy();
|
||||
|
||||
expect(packageJson.dependencies['@nestjs/common']).toEqual(
|
||||
rootPackageJson.dependencies['@nestjs/common']
|
||||
);
|
||||
expect(packageJson.dependencies['@nestjs/core']).toEqual(
|
||||
rootPackageJson.dependencies['@nestjs/core']
|
||||
);
|
||||
expect(packageJson.dependencies['reflect-metadata']).toEqual(
|
||||
rootPackageJson.dependencies['reflect-metadata']
|
||||
);
|
||||
expect(packageJson.dependencies['rxjs']).toEqual(
|
||||
rootPackageJson.dependencies['rxjs']
|
||||
);
|
||||
expect(packageJson.dependencies['tslib']).toEqual(
|
||||
rootPackageJson.dependencies['tslib']
|
||||
);
|
||||
|
||||
const nodeapp = uniq('nodeapp');
|
||||
runCLI(`generate @nrwl/node:app ${nodeapp} --bundler=webpack`);
|
||||
|
||||
11
packages/nx/src/plugins/js/index.ts
Normal file
11
packages/nx/src/plugins/js/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { ProjectGraphProcessor } from '../../config/project-graph';
|
||||
import { ProjectGraphBuilder } from '../../project-graph/project-graph-builder';
|
||||
import { buildNpmPackageNodes } from './project-graph/build-nodes/build-npm-package-nodes';
|
||||
|
||||
export const processProjectGraph: ProjectGraphProcessor = (graph) => {
|
||||
const builder = new ProjectGraphBuilder(graph);
|
||||
|
||||
buildNpmPackageNodes(builder);
|
||||
|
||||
return builder.getUpdatedProjectGraph();
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
import { ProjectGraphBuilder } from '../../../../project-graph/project-graph-builder';
|
||||
import { readJsonFile } from '../../../../utils/fileutils';
|
||||
import { join } from 'path';
|
||||
import { workspaceRoot } from '../../utils/workspace-root';
|
||||
import { readJsonFile } from '../../utils/fileutils';
|
||||
import { ProjectGraphBuilder } from '../project-graph-builder';
|
||||
import { workspaceRoot } from '../../../../utils/workspace-root';
|
||||
|
||||
export function buildNpmPackageNodes(builder: ProjectGraphBuilder) {
|
||||
const packageJson = readJsonFile(join(workspaceRoot, 'package.json'));
|
||||
@ -1,2 +1 @@
|
||||
export * from './workspace-projects';
|
||||
export * from './npm-packages';
|
||||
|
||||
@ -12,10 +12,7 @@ import {
|
||||
writeCache,
|
||||
} from './nx-deps-cache';
|
||||
import { buildImplicitProjectDependencies } from './build-dependencies';
|
||||
import {
|
||||
buildNpmPackageNodes,
|
||||
buildWorkspaceProjectNodes,
|
||||
} from './build-nodes';
|
||||
import { buildWorkspaceProjectNodes } from './build-nodes';
|
||||
import * as os from 'os';
|
||||
import { buildExplicitTypescriptAndPackageJsonDependencies } from './build-dependencies/build-explicit-typescript-and-package-json-dependencies';
|
||||
import { loadNxPlugins } from '../utils/nx-plugin';
|
||||
@ -175,13 +172,16 @@ async function buildProjectGraphUsingContext(
|
||||
performance.mark('build project graph:start');
|
||||
|
||||
const builder = new ProjectGraphBuilder(partialGraph);
|
||||
builder.setVersion(projectGraphVersion);
|
||||
|
||||
buildWorkspaceProjectNodes(ctx, builder, nxJson);
|
||||
if (!partialGraph) {
|
||||
buildNpmPackageNodes(builder);
|
||||
}
|
||||
const initProjectGraph = builder.getUpdatedProjectGraph();
|
||||
|
||||
const r = await updateProjectGraphWithPlugins(ctx, initProjectGraph);
|
||||
|
||||
const updatedBuilder = new ProjectGraphBuilder(r);
|
||||
for (const proj of Object.keys(cachedFileData)) {
|
||||
for (const f of builder.graph.nodes[proj].data.files) {
|
||||
for (const f of updatedBuilder.graph.nodes[proj].data.files) {
|
||||
const cached = cachedFileData[proj][f.file];
|
||||
if (cached && cached.deps) {
|
||||
f.deps = [...cached.deps];
|
||||
@ -192,14 +192,12 @@ async function buildProjectGraphUsingContext(
|
||||
await buildExplicitDependencies(
|
||||
jsPluginConfig(nxJson, packageJsonDeps),
|
||||
ctx,
|
||||
builder
|
||||
updatedBuilder
|
||||
);
|
||||
|
||||
buildImplicitProjectDependencies(ctx, builder);
|
||||
builder.setVersion(projectGraphVersion);
|
||||
const initProjectGraph = builder.getUpdatedProjectGraph();
|
||||
buildImplicitProjectDependencies(ctx, updatedBuilder);
|
||||
|
||||
const r = await updateProjectGraphWithPlugins(ctx, initProjectGraph);
|
||||
const finalGraph = updatedBuilder.getUpdatedProjectGraph();
|
||||
|
||||
performance.mark('build project graph:end');
|
||||
performance.measure(
|
||||
@ -208,7 +206,7 @@ async function buildProjectGraphUsingContext(
|
||||
'build project graph:end'
|
||||
);
|
||||
|
||||
return r;
|
||||
return finalGraph;
|
||||
}
|
||||
|
||||
function jsPluginConfig(
|
||||
|
||||
@ -47,14 +47,8 @@ export interface NxPlugin {
|
||||
// Allows loadNxPlugins to be called multiple times w/o
|
||||
// executing resolution mulitple times.
|
||||
let nxPluginCache: NxPlugin[] = null;
|
||||
export function loadNxPlugins(
|
||||
plugins?: string[],
|
||||
paths = [workspaceRoot],
|
||||
root = workspaceRoot
|
||||
): NxPlugin[] {
|
||||
return plugins?.length
|
||||
? nxPluginCache ||
|
||||
(nxPluginCache = plugins.map((moduleName) => {
|
||||
|
||||
function loadNxPlugin(moduleName: string, paths: string[], root: string) {
|
||||
let pluginPath: string;
|
||||
try {
|
||||
pluginPath = require.resolve(moduleName, {
|
||||
@ -69,9 +63,7 @@ export function loadNxPlugins(
|
||||
);
|
||||
pluginPath = main ? path.join(root, main) : plugin.path;
|
||||
} else {
|
||||
logger.error(
|
||||
`Plugin listed in \`nx.json\` not found: ${moduleName}`
|
||||
);
|
||||
logger.error(`Plugin listed in \`nx.json\` not found: ${moduleName}`);
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
@ -88,8 +80,30 @@ export function loadNxPlugins(
|
||||
plugin.name = name;
|
||||
|
||||
return plugin;
|
||||
}))
|
||||
: [];
|
||||
}
|
||||
|
||||
export function loadNxPlugins(
|
||||
plugins?: string[],
|
||||
paths = [workspaceRoot],
|
||||
root = workspaceRoot
|
||||
): NxPlugin[] {
|
||||
const result: NxPlugin[] = [];
|
||||
|
||||
// TODO: This should be specified in nx.json
|
||||
// Temporarily load js as if it were a plugin which is built into nx
|
||||
// In the future, this will be optional and need to be specified in nx.json
|
||||
const jsPlugin = require('../plugins/js');
|
||||
jsPlugin.name = 'index';
|
||||
result.push(jsPlugin as NxPlugin);
|
||||
|
||||
plugins ??= [];
|
||||
if (!nxPluginCache) {
|
||||
nxPluginCache = plugins.map((moduleName) =>
|
||||
loadNxPlugin(moduleName, paths, root)
|
||||
);
|
||||
}
|
||||
|
||||
return result.concat(nxPluginCache);
|
||||
}
|
||||
|
||||
export function mergePluginTargetsWithNxTargets(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user