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