chore(misc): remove e2e utils that use internal nx functions (#19085)

This commit is contained in:
Jason Jean 2023-09-11 19:56:58 -04:00 committed by GitHub
parent 228393724c
commit 50b62524f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 259 additions and 276 deletions

View File

@ -4,12 +4,13 @@ import {
cleanupProject, cleanupProject,
killProcessAndPorts, killProcessAndPorts,
newProject, newProject,
readProjectConfig, readJson,
runCLI, runCLI,
runCommandUntil, runCommandUntil,
uniq, uniq,
updateFile, updateFile,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Angular Module Federation', () => { describe('Angular Module Federation', () => {
let proj: string; let proj: string;
@ -183,10 +184,10 @@ describe('Angular Module Federation', () => {
// ports // ports
const hostPort = 4500; const hostPort = 4500;
const remote1Port = (await readProjectConfig(remote1)).targets.serve.options const remote1Port = readJson(join(remote1, 'project.json')).targets.serve
.port; .options.port;
const remote2Port = (await readProjectConfig(remote2)).targets.serve.options const remote2Port = readJson(join(remote2, 'project.json')).targets.serve
.port; .options.port;
const process = await runCommandUntil( const process = await runCommandUntil(
`serve-ssr ${host} --port=${hostPort}`, `serve-ssr ${host} --port=${hostPort}`,

View File

@ -14,9 +14,9 @@ import {
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { normalize } from 'path'; import { join, normalize } from 'path';
describe('Angular Projects', () => { describe('Angular Projects', () => {
let proj: string; let proj: string;
@ -269,8 +269,8 @@ describe('Angular Projects', () => {
` `
); );
// update the angular.json // update the project.json
await updateProjectConfig(app1, (config) => { updateJson(join(app1, 'project.json'), (config) => {
config.targets.build.executor = '@nx/angular:webpack-browser'; config.targets.build.executor = '@nx/angular:webpack-browser';
config.targets.build.options = { config.targets.build.options = {
...config.targets.build.options, ...config.targets.build.options,
@ -278,7 +278,7 @@ describe('Angular Projects', () => {
}; };
return config; return config;
}); });
await updateProjectConfig(esbuildApp, (config) => { updateJson(join(esbuildApp, 'project.json'), (config) => {
config.targets.build.executor = '@nx/angular:browser-esbuild'; config.targets.build.executor = '@nx/angular:browser-esbuild';
config.targets.build.options = { config.targets.build.options = {
...config.targets.build.options, ...config.targets.build.options,

View File

@ -7,9 +7,9 @@ import {
runE2ETests, runE2ETests,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig,
removeFile, removeFile,
checkFilesExist, checkFilesExist,
updateJson,
} from '../../utils'; } from '../../utils';
import { names } from '@nx/devkit'; import { names } from '@nx/devkit';
import { join } from 'path'; import { join } from 'path';
@ -283,7 +283,7 @@ async function useWorkspaceAssetsInApp(appName: string) {
} }
` `
); );
await updateProjectConfig(appName, (config) => { updateJson(join(appName, 'project.json'), (config) => {
config.targets['build'].options.stylePreprocessorOptions = { config.targets['build'].options.stylePreprocessorOptions = {
includePaths: ['assets/styles'], includePaths: ['assets/styles'],
}; };

View File

@ -7,8 +7,9 @@ import {
runCLI, runCLI,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Tailwind support', () => { describe('Tailwind support', () => {
let project: string; let project: string;
@ -358,7 +359,7 @@ describe('Tailwind support', () => {
runCLI( runCLI(
`generate @nx/angular:app ${appWithTailwind} --add-tailwind --project-name-and-root-format=as-provided --no-interactive` `generate @nx/angular:app ${appWithTailwind} --add-tailwind --project-name-and-root-format=as-provided --no-interactive`
); );
await updateProjectConfig(appWithTailwind, (config) => { updateJson(join(appWithTailwind, 'project.json'), (config) => {
config.targets.build.executor = '@nx/angular:webpack-browser'; config.targets.build.executor = '@nx/angular:webpack-browser';
config.targets.build.options = { config.targets.build.options = {
...config.targets.build.options, ...config.targets.build.options,

View File

@ -14,9 +14,10 @@ import {
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
waitUntil, waitUntil,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('EsBuild Plugin', () => { describe('EsBuild Plugin', () => {
let proj: string; let proj: string;
@ -29,7 +30,7 @@ describe('EsBuild Plugin', () => {
const myPkg = uniq('my-pkg'); const myPkg = uniq('my-pkg');
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`); runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
updateFile(`libs/${myPkg}/src/index.ts`, `console.log('Hello');\n`); updateFile(`libs/${myPkg}/src/index.ts`, `console.log('Hello');\n`);
await updateProjectConfig(myPkg, (json) => { updateJson(join('libs', myPkg, 'project.json'), (json) => {
json.targets.build.options.assets = [`libs/${myPkg}/assets/*`]; json.targets.build.options.assets = [`libs/${myPkg}/assets/*`];
return json; return json;
}); });
@ -188,7 +189,7 @@ describe('EsBuild Plugin', () => {
runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`); runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`);
updateFile(`libs/${myPkg}/src/index.ts`, `console.log('main');\n`); updateFile(`libs/${myPkg}/src/index.ts`, `console.log('main');\n`);
updateFile(`libs/${myPkg}/src/extra.ts`, `console.log('extra');\n`); updateFile(`libs/${myPkg}/src/extra.ts`, `console.log('extra');\n`);
await updateProjectConfig(myPkg, (json) => { updateJson(join('libs', myPkg, 'project.json'), (json) => {
json.targets.build.options.additionalEntryPoints = [ json.targets.build.options.additionalEntryPoints = [
`libs/${myPkg}/src/extra.ts`, `libs/${myPkg}/src/extra.ts`,
]; ];
@ -216,7 +217,7 @@ describe('EsBuild Plugin', () => {
`libs/${myPkg}/esbuild.config.js`, `libs/${myPkg}/esbuild.config.js`,
`console.log('custom config loaded');\nmodule.exports = {};\n` `console.log('custom config loaded');\nmodule.exports = {};\n`
); );
await updateProjectConfig(myPkg, (json) => { updateJson(join('libs', myPkg, 'project.json'), (json) => {
delete json.targets.build.options.esbuildOptions; delete json.targets.build.options.esbuildOptions;
json.targets.build.options.esbuildConfig = `libs/${myPkg}/esbuild.config.js`; json.targets.build.options.esbuildConfig = `libs/${myPkg}/esbuild.config.js`;
return json; return json;

View File

@ -7,7 +7,6 @@ import {
newProject, newProject,
promisifiedTreeKill, promisifiedTreeKill,
readJson, readJson,
readResolvedConfiguration,
runCLI, runCLI,
runCLIAsync, runCLIAsync,
runCommand, runCommand,
@ -85,8 +84,7 @@ describe('expo', () => {
it('should prebuild', async () => { it('should prebuild', async () => {
// run prebuild command with git check disable // run prebuild command with git check disable
// set a mock package name for ios and android in expo's app.json // set a mock package name for ios and android in expo's app.json
const projects = await readResolvedConfiguration(); const root = `apps/${appName}`;
const root = projects[appName].root;
const appJsonPath = join(root, `app.json`); const appJsonPath = join(root, `app.json`);
const appJson = await readJson(appJsonPath); const appJson = await readJson(appJsonPath);
if (appJson.expo.ios) { if (appJson.expo.ios) {

View File

@ -5,8 +5,9 @@ import {
setMaxWorkers, setMaxWorkers,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('js:node executor', () => { describe('js:node executor', () => {
let scope: string; let scope: string;
@ -31,7 +32,7 @@ describe('js:node executor', () => {
`; `;
}); });
await updateProjectConfig(esbuildLib, (config) => { updateJson(join('libs', esbuildLib, 'project.json'), (config) => {
config.targets['run-node'] = { config.targets['run-node'] = {
executor: '@nx/js:node', executor: '@nx/js:node',
options: { options: {
@ -62,7 +63,7 @@ describe('js:node executor', () => {
`; `;
}); });
await updateProjectConfig(rollupLib, (config) => { updateJson(join('libs', rollupLib, 'project.json'), (config) => {
config.targets['run-node'] = { config.targets['run-node'] = {
executor: '@nx/js:node', executor: '@nx/js:node',
options: { options: {
@ -88,7 +89,7 @@ describe('js:node executor', () => {
`; `;
}); });
await updateProjectConfig(tscLib, (config) => { updateJson(join('libs', tscLib, 'project.json'), (config) => {
config.targets['run-node'] = { config.targets['run-node'] = {
executor: '@nx/js:node', executor: '@nx/js:node',
options: { options: {
@ -114,7 +115,7 @@ describe('js:node executor', () => {
`; `;
}); });
await updateProjectConfig(swcLib, (config) => { updateJson(join('libs', swcLib, 'project.json'), (config) => {
config.targets['run-node'] = { config.targets['run-node'] = {
executor: '@nx/js:node', executor: '@nx/js:node',
options: { options: {
@ -135,7 +136,7 @@ describe('js:node executor', () => {
runCLI( runCLI(
`generate @nx/node:application ${webpackProject} --bundler=webpack --no-interactive` `generate @nx/node:application ${webpackProject} --bundler=webpack --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', webpackProject, 'project.json'));
updateFile(`apps/${webpackProject}/src/main.ts`, () => { updateFile(`apps/${webpackProject}/src/main.ts`, () => {
return ` return `
@ -143,7 +144,7 @@ describe('js:node executor', () => {
`; `;
}); });
await updateProjectConfig(webpackProject, (config) => { updateJson(join('apps', webpackProject, 'project.json'), (config) => {
config.targets['run-node'] = { config.targets['run-node'] = {
executor: '@nx/js:node', executor: '@nx/js:node',
options: { options: {

View File

@ -1,6 +1,5 @@
import { import {
updateJson, updateJson,
updateProjectConfig,
cleanupProject, cleanupProject,
newProject, newProject,
runCLI, runCLI,
@ -161,7 +160,7 @@ describe('packaging libs', () => {
); );
// Add additional entry points for `exports` field // Add additional entry points for `exports` field
await updateProjectConfig(tscLib, (json) => { updateJson(join('libs', tscLib, 'project.json'), (json) => {
json.targets.build.options.additionalEntryPoints = [ json.targets.build.options.additionalEntryPoints = [
`libs/${tscLib}/src/foo/*.ts`, `libs/${tscLib}/src/foo/*.ts`,
]; ];
@ -169,7 +168,7 @@ describe('packaging libs', () => {
}); });
updateFile(`libs/${tscLib}/src/foo/bar.ts`, `export const bar = 'bar';`); updateFile(`libs/${tscLib}/src/foo/bar.ts`, `export const bar = 'bar';`);
updateFile(`libs/${tscLib}/src/foo/faz.ts`, `export const faz = 'faz';`); updateFile(`libs/${tscLib}/src/foo/faz.ts`, `export const faz = 'faz';`);
await updateProjectConfig(swcLib, (json) => { updateJson(join('libs', swcLib, 'project.json'), (json) => {
json.targets.build.options.additionalEntryPoints = [ json.targets.build.options.additionalEntryPoints = [
`libs/${swcLib}/src/foo/*.ts`, `libs/${swcLib}/src/foo/*.ts`,
]; ];

View File

@ -728,7 +728,7 @@ describe('Linter', () => {
runCLI( runCLI(
`generate @nx/node:app ${myapp} --rootProject=true --no-interactive` `generate @nx/node:app ${myapp} --rootProject=true --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers('project.json');
verifySuccessfulStandaloneSetup(myapp); verifySuccessfulStandaloneSetup(myapp);
let appEslint = readJson('.eslintrc.json'); let appEslint = readJson('.eslintrc.json');

View File

@ -1,4 +1,4 @@
import { removeSync, mkdirSync } from 'fs-extra'; import { mkdirSync, removeSync } from 'fs-extra';
import { capitalize } from '@nx/devkit/src/utils/string-utils'; import { capitalize } from '@nx/devkit/src/utils/string-utils';
import { checkApp } from './utils'; import { checkApp } from './utils';
import { import {
@ -13,8 +13,9 @@ import {
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Next.js Apps Libs', () => { describe('Next.js Apps Libs', () => {
let proj: string; let proj: string;
@ -57,7 +58,7 @@ describe('Next.js Apps Libs', () => {
// Additional assets that should be copied to dist // Additional assets that should be copied to dist
const sharedLib = uniq('sharedLib'); const sharedLib = uniq('sharedLib');
await updateProjectConfig(appName, (json) => { updateJson(join('packages', appName, 'project.json'), (json) => {
json.targets.build.options.assets = [ json.targets.build.options.assets = [
{ {
glob: '**/*', glob: '**/*',

View File

@ -6,8 +6,9 @@ import {
runCLI, runCLI,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Next.js Webpack', () => { describe('Next.js Webpack', () => {
let proj: string; let proj: string;
@ -80,7 +81,7 @@ describe('Next.js Webpack', () => {
checkFilesExist(`dist/apps/${appName}/next.config.js`); checkFilesExist(`dist/apps/${appName}/next.config.js`);
// Make sure withNx works with run-commands. // Make sure withNx works with run-commands.
await updateProjectConfig(appName, (json) => { updateJson(join('apps', appName, 'project.json'), (json) => {
json.targets.build = { json.targets.build = {
command: 'npx next build', command: 'npx next build',
outputs: [`apps/${appName}/.next`], outputs: [`apps/${appName}/.next`],

View File

@ -14,6 +14,7 @@ import {
updateFile, updateFile,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { join } from 'path';
describe('Node Applications + esbuild', () => { describe('Node Applications + esbuild', () => {
beforeEach(() => newProject()); beforeEach(() => newProject());
@ -24,7 +25,7 @@ describe('Node Applications + esbuild', () => {
const app = uniq('nodeapp'); const app = uniq('nodeapp');
runCLI(`generate @nx/node:app ${app} --bundler=esbuild --no-interactive`); runCLI(`generate @nx/node:app ${app} --bundler=esbuild --no-interactive`);
await setMaxWorkers(); setMaxWorkers(join('apps', app, 'project.json'));
checkFilesDoNotExist(`apps/${app}/webpack.config.js`); checkFilesDoNotExist(`apps/${app}/webpack.config.js`);

View File

@ -9,10 +9,11 @@ import {
runCLI, runCLI,
runCommandUntil, runCommandUntil,
uniq, uniq,
updateProjectConfig,
updateFile, updateFile,
setMaxWorkers, setMaxWorkers,
updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Node Applications + webpack', () => { describe('Node Applications + webpack', () => {
let proj: string; let proj: string;
@ -73,14 +74,17 @@ describe('Node Applications + webpack', () => {
runCLI( runCLI(
`generate @nx/node:app ${expressApp} --framework=express --no-interactive` `generate @nx/node:app ${expressApp} --framework=express --no-interactive`
); );
setMaxWorkers(join('apps', expressApp, 'project.json'));
runCLI( runCLI(
`generate @nx/node:app ${fastifyApp} --framework=fastify --no-interactive` `generate @nx/node:app ${fastifyApp} --framework=fastify --no-interactive`
); );
setMaxWorkers(join('apps', fastifyApp, 'project.json'));
runCLI(`generate @nx/node:app ${koaApp} --framework=koa --no-interactive`); runCLI(`generate @nx/node:app ${koaApp} --framework=koa --no-interactive`);
setMaxWorkers(join('apps', koaApp, 'project.json'));
runCLI( runCLI(
`generate @nx/node:app ${nestApp} --framework=nest --bundler=webpack --no-interactive` `generate @nx/node:app ${nestApp} --framework=nest --bundler=webpack --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', nestApp, 'project.json'));
// Use esbuild by default // Use esbuild by default
checkFilesDoNotExist(`apps/${expressApp}/webpack.config.js`); checkFilesDoNotExist(`apps/${expressApp}/webpack.config.js`);
@ -140,7 +144,7 @@ describe('Node Applications + webpack', () => {
runCLI( runCLI(
`generate @nx/node:app ${expressApp} --framework=express --docker --no-interactive` `generate @nx/node:app ${expressApp} --framework=express --docker --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', expressApp, 'project.json'));
checkFilesExist(`apps/${expressApp}/Dockerfile`); checkFilesExist(`apps/${expressApp}/Dockerfile`);
}, 300_000); }, 300_000);
@ -151,11 +155,12 @@ describe('Node Applications + webpack', () => {
runCLI( runCLI(
`generate @nx/node:app ${nodeApp1} --framework=none --no-interactive` `generate @nx/node:app ${nodeApp1} --framework=none --no-interactive`
); );
setMaxWorkers(join('apps', nodeApp1, 'project.json'));
runCLI( runCLI(
`generate @nx/node:app ${nodeApp2} --framework=none --no-interactive` `generate @nx/node:app ${nodeApp2} --framework=none --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', nodeApp2, 'project.json'));
await updateProjectConfig(nodeApp1, (config) => { updateJson(join('apps', nodeApp1, 'project.json'), (config) => {
config.targets.serve.options.waitUntilTargets = [`${nodeApp2}:build`]; config.targets.serve.options.waitUntilTargets = [`${nodeApp2}:build`];
return config; return config;
}); });

View File

@ -10,10 +10,11 @@ import {
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig,
setMaxWorkers, setMaxWorkers,
updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { join } from 'path';
describe('Node Applications + webpack', () => { describe('Node Applications + webpack', () => {
beforeEach(() => newProject()); beforeEach(() => newProject());
@ -24,7 +25,7 @@ describe('Node Applications + webpack', () => {
const app = uniq('nodeapp'); const app = uniq('nodeapp');
runCLI(`generate @nx/node:app ${app} --bundler=webpack --no-interactive`); runCLI(`generate @nx/node:app ${app} --bundler=webpack --no-interactive`);
await setMaxWorkers(); setMaxWorkers(join('apps', app, 'project.json'));
checkFilesExist(`apps/${app}/webpack.config.js`); checkFilesExist(`apps/${app}/webpack.config.js`);
@ -57,7 +58,7 @@ describe('Node Applications + webpack', () => {
const lib = uniq('nodelib'); const lib = uniq('nodelib');
runCLI(`generate @nx/js:lib ${lib} --bundler=esbuild --no-interactive`); runCLI(`generate @nx/js:lib ${lib} --bundler=esbuild --no-interactive`);
await updateProjectConfig(app, (config) => { updateJson(join('apps', app, 'project.json'), (config) => {
// Since we read from lib from dist, we should re-build it when lib changes. // Since we read from lib from dist, we should re-build it when lib changes.
config.targets.build.options.buildLibsFromSource = false; config.targets.build.options.buildLibsFromSource = false;
config.targets.serve.options.runBuildTargetDependencies = true; config.targets.serve.options.runBuildTargetDependencies = true;

View File

@ -22,13 +22,13 @@ import {
uniq, uniq,
updateFile, updateFile,
updateJson, updateJson,
updateProjectConfig,
setMaxWorkers, setMaxWorkers,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
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/js'; import { getLockFileName } from '@nx/js';
import { satisfies } from 'semver'; import { satisfies } from 'semver';
import { join } from 'path';
function getData(port, path = '/api'): Promise<any> { function getData(port, path = '/api'): Promise<any> {
return new Promise((resolve) => { return new Promise((resolve) => {
@ -58,7 +58,7 @@ describe('Node Applications', () => {
const nodeapp = uniq('nodeapp'); const nodeapp = uniq('nodeapp');
runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`); runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`);
await setMaxWorkers(); setMaxWorkers(join('apps', nodeapp, 'project.json'));
const lintResults = runCLI(`lint ${nodeapp}`); const lintResults = runCLI(`lint ${nodeapp}`);
expect(lintResults).toContain('All files pass linting.'); expect(lintResults).toContain('All files pass linting.');
@ -76,9 +76,9 @@ describe('Node Applications', () => {
it('should be able to generate the correct outputFileName in options', async () => { it('should be able to generate the correct outputFileName in options', async () => {
const nodeapp = uniq('nodeapp'); const nodeapp = uniq('nodeapp');
runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`); runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`);
await setMaxWorkers(); setMaxWorkers(join('apps', nodeapp, 'project.json'));
await updateProjectConfig(nodeapp, (config) => { updateJson(join('apps', nodeapp, 'project.json'), (config) => {
config.targets.build.options.outputFileName = 'index.js'; config.targets.build.options.outputFileName = 'index.js';
return config; return config;
}); });
@ -93,12 +93,12 @@ describe('Node Applications', () => {
runCLI( runCLI(
`generate @nx/node:app ${nodeapp} --linter=eslint --bundler=webpack` `generate @nx/node:app ${nodeapp} --linter=eslint --bundler=webpack`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', nodeapp, 'project.json'));
const lintResults = runCLI(`lint ${nodeapp}`); const lintResults = runCLI(`lint ${nodeapp}`);
expect(lintResults).toContain('All files pass linting.'); expect(lintResults).toContain('All files pass linting.');
await updateProjectConfig(nodeapp, (config) => { updateJson(join('apps', nodeapp, 'project.json'), (config) => {
config.targets.build.options.additionalEntryPoints = [ config.targets.build.options.additionalEntryPoints = [
{ {
entryName: 'additional-main', entryName: 'additional-main',
@ -153,7 +153,7 @@ describe('Node Applications', () => {
runCLI( runCLI(
`generate @nx/node:app ${nodeapp} --linter=eslint --bundler=webpack --framework=none` `generate @nx/node:app ${nodeapp} --linter=eslint --bundler=webpack --framework=none`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', nodeapp, 'project.json'));
updateFile('.env', `NX_FOOBAR="test foo bar"`); updateFile('.env', `NX_FOOBAR="test foo bar"`);
@ -188,7 +188,7 @@ describe('Node Applications', () => {
process.env.PORT = `${port}`; process.env.PORT = `${port}`;
runCLI(`generate @nx/express:app ${nodeapp} --linter=eslint`); runCLI(`generate @nx/express:app ${nodeapp} --linter=eslint`);
await setMaxWorkers(); setMaxWorkers(join('apps', nodeapp, 'project.json'));
const lintResults = runCLI(`lint ${nodeapp}`); const lintResults = runCLI(`lint ${nodeapp}`);
expect(lintResults).toContain('All files pass linting.'); expect(lintResults).toContain('All files pass linting.');
@ -230,7 +230,7 @@ describe('Node Applications', () => {
const nestapp = uniq('nestapp'); const nestapp = uniq('nestapp');
const port = 3335; const port = 3335;
runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`); runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`);
await setMaxWorkers(); setMaxWorkers(join('apps', nestapp, 'project.json'));
const lintResults = runCLI(`lint ${nestapp}`); const lintResults = runCLI(`lint ${nestapp}`);
expect(lintResults).toContain('All files pass linting.'); expect(lintResults).toContain('All files pass linting.');
@ -292,13 +292,13 @@ describe('Node Applications', () => {
runCLI( runCLI(
`generate @nrwl/node:app ${esmapp} --linter=eslint --framework=none --bundler=webpack` `generate @nrwl/node:app ${esmapp} --linter=eslint --framework=none --bundler=webpack`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', esmapp, 'project.json'));
updateJson(`apps/${esmapp}/tsconfig.app.json`, (config) => { updateJson(`apps/${esmapp}/tsconfig.app.json`, (config) => {
config.module = 'esnext'; config.module = 'esnext';
config.target = 'es2020'; config.target = 'es2020';
return config; return config;
}); });
await updateProjectConfig(esmapp, (config) => { updateJson(join('apps', esmapp, 'project.json'), (config) => {
config.targets.build.options.outputFileName = 'main.mjs'; config.targets.build.options.outputFileName = 'main.mjs';
config.targets.build.options.assets = []; config.targets.build.options.assets = [];
return config; return config;
@ -340,7 +340,7 @@ describe('Build Node apps', () => {
const packageManager = detectPackageManager(tmpProjPath()); const packageManager = detectPackageManager(tmpProjPath());
const nestapp = uniq('nestapp'); const nestapp = uniq('nestapp');
runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`); runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`);
await setMaxWorkers(); setMaxWorkers(join('apps', nestapp, 'project.json'));
await runCLIAsync(`build ${nestapp} --generatePackageJson`); await runCLIAsync(`build ${nestapp} --generatePackageJson`);
@ -402,7 +402,7 @@ describe('Build Node apps', () => {
const nodeapp = uniq('nodeapp'); const nodeapp = uniq('nodeapp');
runCLI(`generate @nx/node:app ${nodeapp} --bundler=webpack`); runCLI(`generate @nx/node:app ${nodeapp} --bundler=webpack`);
await setMaxWorkers(); setMaxWorkers(join('apps', nodeapp, 'project.json'));
const jslib = uniq('jslib'); const jslib = uniq('jslib');
runCLI(`generate @nx/js:lib ${jslib} --bundler=tsc`); runCLI(`generate @nx/js:lib ${jslib} --bundler=tsc`);
@ -443,7 +443,7 @@ ${jslib}();
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nx/node:app ${appName} --no-interactive`); runCLI(`generate @nx/node:app ${appName} --no-interactive`);
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
// deleteOutputPath should default to true // deleteOutputPath should default to true
createFile(`dist/apps/${appName}/_should_remove.txt`); createFile(`dist/apps/${appName}/_should_remove.txt`);
@ -526,11 +526,11 @@ ${jslib}();
newProject(); newProject();
const nestapp = uniq('nestapp'); const nestapp = uniq('nestapp');
runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`); runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`);
await setMaxWorkers(); setMaxWorkers(join('apps', nestapp, 'project.json'));
packageInstall('@nestjs/swagger', undefined, '^6.0.0'); packageInstall('@nestjs/swagger', undefined, '^6.0.0');
await updateProjectConfig(nestapp, (config) => { updateJson(join('apps', nestapp, 'project.json'), (config) => {
config.targets.build.options.tsPlugins = ['@nestjs/swagger/plugin']; config.targets.build.options.tsPlugins = ['@nestjs/swagger/plugin'];
return config; return config;
}); });
@ -643,7 +643,7 @@ describe('nest libraries', function () {
packageInstall('@nestjs/swagger', undefined, '~6.3.0'); packageInstall('@nestjs/swagger', undefined, '~6.3.0');
await updateProjectConfig(nestlib, (config) => { updateJson(join('libs', nestlib, 'project.json'), (config) => {
config.targets.build.options.transformers = [ config.targets.build.options.transformers = [
{ {
name: '@nestjs/swagger/plugin', name: '@nestjs/swagger/plugin',

View File

@ -8,8 +8,9 @@ import {
setMaxWorkers, setMaxWorkers,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Extra Nx Misc Tests', () => { describe('Extra Nx Misc Tests', () => {
beforeAll(() => newProject()); beforeAll(() => newProject());
@ -19,9 +20,9 @@ describe('Extra Nx Misc Tests', () => {
it('should stream output', async () => { it('should stream output', async () => {
const myapp = 'abcdefghijklmon'; const myapp = 'abcdefghijklmon';
runCLI(`generate @nx/web:app ${myapp}`); runCLI(`generate @nx/web:app ${myapp}`);
await setMaxWorkers(); setMaxWorkers(join('apps', myapp, 'project.json'));
await updateProjectConfig(myapp, (c) => { updateJson(join('apps', myapp, 'project.json'), (c) => {
c.targets['inner'] = { c.targets['inner'] = {
command: 'echo inner', command: 'echo inner',
}; };
@ -125,7 +126,7 @@ describe('Extra Nx Misc Tests', () => {
process.platform === 'win32' process.platform === 'win32'
? `%SHARED_VAR% %ROOT_ONLY% %NESTED_ONLY%` // Windows ? `%SHARED_VAR% %ROOT_ONLY% %NESTED_ONLY%` // Windows
: `$SHARED_VAR $ROOT_ONLY $NESTED_ONLY`; : `$SHARED_VAR $ROOT_ONLY $NESTED_ONLY`;
await updateProjectConfig(mylib, (config) => { updateJson(join('libs', mylib, 'project.json'), (config) => {
config.targets.echoEnvVariables.options.command += ` ${command}`; config.targets.echoEnvVariables.options.command += ` ${command}`;
return config; return config;
}); });
@ -138,7 +139,7 @@ describe('Extra Nx Misc Tests', () => {
}, 120000); }, 120000);
it('should pass options', async () => { it('should pass options', async () => {
await updateProjectConfig(mylib, (config) => { updateJson(join('libs', mylib, 'project.json'), (config) => {
config.targets.echo = { config.targets.echo = {
command: 'echo --var1={args.var1}', command: 'echo --var1={args.var1}',
options: { options: {
@ -154,7 +155,7 @@ describe('Extra Nx Misc Tests', () => {
it('should interpolate provided arguments', async () => { it('should interpolate provided arguments', async () => {
const echoTarget = uniq('echo'); const echoTarget = uniq('echo');
await updateProjectConfig(mylib, (config) => { updateJson(join('libs', mylib, 'project.json'), (config) => {
config.targets[echoTarget] = { config.targets[echoTarget] = {
executor: 'nx:run-commands', executor: 'nx:run-commands',
options: { options: {
@ -189,7 +190,7 @@ describe('Extra Nx Misc Tests', () => {
}, 120000); }, 120000);
it('should fail when a process exits non-zero', async () => { it('should fail when a process exits non-zero', async () => {
await updateProjectConfig(mylib, (config) => { updateJson(join('libs', mylib, 'project.json'), (config) => {
config.targets.error = { config.targets.error = {
executor: 'nx:run-commands', executor: 'nx:run-commands',
options: { options: {
@ -210,7 +211,7 @@ describe('Extra Nx Misc Tests', () => {
}); });
it('run command should not break if output property is missing in options and arguments', async () => { it('run command should not break if output property is missing in options and arguments', async () => {
await updateProjectConfig(mylib, (config) => { updateJson(join('libs', mylib, 'project.json'), (config) => {
config.targets.lint.outputs = ['{options.outputFile}']; config.targets.lint.outputs = ['{options.outputFile}'];
return config; return config;
}); });
@ -244,7 +245,7 @@ describe('Extra Nx Misc Tests', () => {
: `mkdir -p ${folder}`, : `mkdir -p ${folder}`,
`echo dummy > ${folder}/dummy.txt`, `echo dummy > ${folder}/dummy.txt`,
]; ];
await updateProjectConfig(mylib, (config) => { updateJson(join('libs', mylib, 'project.json'), (config) => {
delete config.targets.build.options.command; delete config.targets.build.options.command;
config.targets.build.options = { config.targets.build.options = {
...config.targets.build.options, ...config.targets.build.options,

View File

@ -23,10 +23,10 @@ import { renameSync, writeFileSync } from 'fs';
import { ensureDirSync } from 'fs-extra'; import { ensureDirSync } from 'fs-extra';
import * as path from 'path'; import * as path from 'path';
import { major } from 'semver'; import { major } from 'semver';
import { join } from 'path';
describe('Nx Commands', () => { describe('Nx Commands', () => {
let proj: string; beforeAll(() => newProject());
beforeAll(() => (proj = newProject()));
afterAll(() => cleanupProject()); afterAll(() => cleanupProject());
@ -40,7 +40,7 @@ describe('Nx Commands', () => {
runCLI(`generate @nx/web:app ${app1} --tags e2etag`); runCLI(`generate @nx/web:app ${app1} --tags e2etag`);
runCLI(`generate @nx/web:app ${app2}`); runCLI(`generate @nx/web:app ${app2}`);
await setMaxWorkers(); setMaxWorkers(join('apps', app1, 'project.json'));
const s = runCLI('show projects').split('\n'); const s = runCLI('show projects').split('\n');
@ -150,8 +150,8 @@ describe('Nx Commands', () => {
beforeAll(async () => { beforeAll(async () => {
runCLI(`generate @nx/web:app ${myapp}`); runCLI(`generate @nx/web:app ${myapp}`);
setMaxWorkers(join('apps', myapp, 'project.json'));
runCLI(`generate @nx/js:lib ${mylib}`); runCLI(`generate @nx/js:lib ${mylib}`);
await setMaxWorkers();
}); });
beforeEach(() => { beforeEach(() => {

View File

@ -8,14 +8,12 @@ import {
updateFile, updateFile,
readFile, readFile,
exists, exists,
updateProjectConfig,
readProjectConfig,
tmpProjPath, tmpProjPath,
readResolvedConfiguration,
getPackageManagerCommand, getPackageManagerCommand,
getSelectedPackageManager, getSelectedPackageManager,
runCommand, runCommand,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
let proj: string; let proj: string;
@ -119,9 +117,10 @@ describe('Workspace Tests', () => {
runCLI( runCLI(
`generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided`
); );
await updateProjectConfig(lib3, (config) => { updateFile(join(lib3, 'project.json'), (content) => {
config.implicitDependencies = [`${lib1}-data-access`]; const data = JSON.parse(content);
return config; data.implicitDependencies = [`${lib1}-data-access`];
return JSON.stringify(data, null, 2);
}); });
/** /**
@ -178,13 +177,13 @@ describe('Workspace Tests', () => {
expect(moveOutput).toContain(`CREATE ${rootClassPath}`); expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
checkFilesExist(rootClassPath); checkFilesExist(rootClassPath);
let projects = await readResolvedConfiguration(); let projects = runCLI('show projects').split('\n');
expect(projects[`${lib1}-data-access`]).toBeUndefined(); expect(projects).not.toContain(`${lib1}-data-access`);
const newConfig = await readProjectConfig(newName); const newConfig = readJson(join(newPath, 'project.json'));
expect(newConfig).toMatchObject({ expect(newConfig).toMatchObject({
tags: [], tags: [],
}); });
const lib3Config = await readProjectConfig(lib3); const lib3Config = readJson(join(lib3, 'project.json'));
expect(lib3Config.implicitDependencies).toEqual([ expect(lib3Config.implicitDependencies).toEqual([
`shared-${lib1}-data-access`, `shared-${lib1}-data-access`,
]); ]);
@ -200,9 +199,9 @@ describe('Workspace Tests', () => {
] ]
).toEqual([`shared/${lib1}/data-access/src/index.ts`]); ).toEqual([`shared/${lib1}/data-access/src/index.ts`]);
projects = await readResolvedConfiguration(); projects = runCLI('show projects').split('\n');
expect(projects[`${lib1}-data-access`]).toBeUndefined(); expect(projects).not.toContain(`${lib1}-data-access`);
const project = await readProjectConfig(newName); const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy(); expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([ expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -261,9 +260,10 @@ describe('Workspace Tests', () => {
runCLI( runCLI(
`generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided`
); );
await updateProjectConfig(lib3, (config) => { updateFile(join(lib3, 'project.json'), (content) => {
config.implicitDependencies = [`${lib1}-data-access`]; const data = JSON.parse(content);
return config; data.implicitDependencies = [`${lib1}-data-access`];
return JSON.stringify(data, null, 2);
}); });
/** /**
@ -331,13 +331,13 @@ describe('Workspace Tests', () => {
] ]
).toEqual([`shared/${lib1}/data-access/src/index.ts`]); ).toEqual([`shared/${lib1}/data-access/src/index.ts`]);
const projects = await readResolvedConfiguration(); const projects = runCLI('show projects').split('\n');
expect(projects[`${lib1}-data-access`]).toBeUndefined(); expect(projects).not.toContain(`${lib1}-data-access`);
const project = await readProjectConfig(newName); const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy(); expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.tags).toEqual([]); expect(project.tags).toEqual([]);
const lib3Config = await readProjectConfig(lib3); const lib3Config = readJson(join(lib3, 'project.json'));
expect(lib3Config.implicitDependencies).toEqual([newName]); expect(lib3Config.implicitDependencies).toEqual([newName]);
expect(project.targets.lint.options.lintFilePatterns).toEqual([ expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -400,9 +400,10 @@ describe('Workspace Tests', () => {
runCLI( runCLI(
`generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=derived` `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=derived`
); );
await updateProjectConfig(lib3, (config) => { updateFile(join('packages', lib3, 'project.json'), (content) => {
config.implicitDependencies = [`${lib1}-data-access`]; const data = JSON.parse(content);
return config; data.implicitDependencies = [`${lib1}-data-access`];
return JSON.stringify(data, null, 2);
}); });
/** /**
@ -470,9 +471,9 @@ describe('Workspace Tests', () => {
] ]
).toEqual([`packages/shared/${lib1}/data-access/src/index.ts`]); ).toEqual([`packages/shared/${lib1}/data-access/src/index.ts`]);
const projects = await readResolvedConfiguration(); const projects = runCLI('show projects').split('\n');
expect(projects[`${lib1}-data-access`]).toBeUndefined(); expect(projects).not.toContain(`${lib1}-data-access`);
const project = await readProjectConfig(newName); const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy(); expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([ expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -532,9 +533,10 @@ describe('Workspace Tests', () => {
runCLI( runCLI(
`generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided`
); );
await updateProjectConfig(lib3, (config) => { updateFile(join(lib3, 'project.json'), (content) => {
config.implicitDependencies = [lib1]; const data = JSON.parse(content);
return config; data.implicitDependencies = [lib1];
return JSON.stringify(data, null, 2);
}); });
/** /**
@ -587,13 +589,13 @@ describe('Workspace Tests', () => {
expect(moveOutput).toContain(`CREATE ${rootClassPath}`); expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
checkFilesExist(rootClassPath); checkFilesExist(rootClassPath);
let projects = await readResolvedConfiguration(); let projects = runCLI('show projects').split('\n');
expect(projects[lib1]).toBeUndefined(); expect(projects).not.toContain(lib1);
const newConfig = await readProjectConfig(newName); const newConfig = readJson(join(newPath, 'project.json'));
expect(newConfig).toMatchObject({ expect(newConfig).toMatchObject({
tags: [], tags: [],
}); });
const lib3Config = await readProjectConfig(lib3); const lib3Config = readJson(join(lib3, 'project.json'));
expect(lib3Config.implicitDependencies).toEqual([`${lib1}-data-access`]); expect(lib3Config.implicitDependencies).toEqual([`${lib1}-data-access`]);
expect(moveOutput).toContain('UPDATE tsconfig.base.json'); expect(moveOutput).toContain('UPDATE tsconfig.base.json');
@ -605,9 +607,9 @@ describe('Workspace Tests', () => {
rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}-data-access`] rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}-data-access`]
).toEqual([`${lib1}/data-access/src/index.ts`]); ).toEqual([`${lib1}/data-access/src/index.ts`]);
projects = await readResolvedConfiguration(); projects = runCLI('show projects').split('\n');
expect(projects[lib1]).toBeUndefined(); expect(projects).not.toContain(lib1);
const project = await readProjectConfig(newName); const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy(); expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([ expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -676,9 +678,10 @@ describe('Workspace Tests', () => {
runCLI( runCLI(
`generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided`
); );
await updateProjectConfig(lib3, (config) => { updateFile(join(lib3, 'project.json'), (content) => {
config.implicitDependencies = [`${lib1}-data-access`]; const data = JSON.parse(content);
return config; data.implicitDependencies = [`${lib1}-data-access`];
return JSON.stringify(data, null, 2);
}); });
/** /**
@ -707,11 +710,11 @@ describe('Workspace Tests', () => {
expect(moveOutput).toContain(`CREATE ${rootClassPath}`); expect(moveOutput).toContain(`CREATE ${rootClassPath}`);
checkFilesExist(rootClassPath); checkFilesExist(rootClassPath);
const newConfig = await readProjectConfig(newName); const newConfig = readJson(join(newPath, 'project.json'));
expect(newConfig).toMatchObject({ expect(newConfig).toMatchObject({
tags: [], tags: [],
}); });
const lib3Config = await readProjectConfig(lib3); const lib3Config = readJson(join(lib3, 'project.json'));
expect(lib3Config.implicitDependencies).toEqual([ expect(lib3Config.implicitDependencies).toEqual([
`shared-${lib1}-data-access`, `shared-${lib1}-data-access`,
]); ]);
@ -725,9 +728,9 @@ describe('Workspace Tests', () => {
rootTsConfig.compilerOptions.paths[`shared-${lib1}-data-access`] rootTsConfig.compilerOptions.paths[`shared-${lib1}-data-access`]
).toEqual([`shared/${lib1}/data-access/src/index.ts`]); ).toEqual([`shared/${lib1}/data-access/src/index.ts`]);
const projects = await readResolvedConfiguration(); const projects = runCLI('show projects').split('\n');
expect(projects[`${lib1}-data-access`]).toBeUndefined(); expect(projects).not.toContain(`${lib1}-data-access`);
const project = await readProjectConfig(newName); const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy(); expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([ expect(project.targets.lint.options.lintFilePatterns).toEqual([
@ -762,9 +765,10 @@ describe('Workspace Tests', () => {
*/ */
runCLI(`generate @nx/js:lib ${lib2} --unitTestRunner=jest`); runCLI(`generate @nx/js:lib ${lib2} --unitTestRunner=jest`);
await updateProjectConfig(lib2, (config) => { updateFile(join('libs', lib2, 'project.json'), (content) => {
config.implicitDependencies = [lib1]; const data = JSON.parse(content);
return config; data.implicitDependencies = [lib1];
return JSON.stringify(data, null, 2);
}); });
/** /**
@ -796,9 +800,9 @@ describe('Workspace Tests', () => {
expect(exists(tmpProjPath(`libs/${lib1}`))).toBeFalsy(); expect(exists(tmpProjPath(`libs/${lib1}`))).toBeFalsy();
expect(removeOutputForced).not.toContain(`UPDATE nx.json`); expect(removeOutputForced).not.toContain(`UPDATE nx.json`);
const projects = await readResolvedConfiguration(); const projects = runCLI('show projects').split('\n');
expect(projects[`${lib1}`]).toBeUndefined(); expect(projects).not.toContain(lib1);
const lib2Config = await readProjectConfig(lib2); const lib2Config = readJson(join('libs', lib2, 'project.json'));
expect(lib2Config.implicitDependencies).toEqual([]); expect(lib2Config.implicitDependencies).toEqual([]);
expect(projects[`${lib1}`]).toBeUndefined(); expect(projects[`${lib1}`]).toBeUndefined();

View File

@ -11,13 +11,12 @@ import {
runCommand, runCommand,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig,
checkFilesExist, checkFilesExist,
isWindows, isWindows,
fileExists, fileExists,
removeFile, removeFile,
readResolvedConfiguration,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Nx Affected and Graph Tests', () => { describe('Nx Affected and Graph Tests', () => {
let proj: string; let proj: string;
@ -218,10 +217,11 @@ describe('Nx Affected and Graph Tests', () => {
// TODO: investigate why affected gives different results on windows // TODO: investigate why affected gives different results on windows
if (isNotWindows()) { if (isNotWindows()) {
generateAll(); generateAll();
await updateProjectConfig(myapp, (config) => ({ updateFile(join('apps', myapp, 'project.json'), (content) => {
...config, const data = JSON.parse(content);
tags: ['tag'], data.tags = ['tag'];
})); return JSON.stringify(data, null, 2);
});
const output = runCLI('print-affected --select projects'); const output = runCLI('print-affected --select projects');
expect(output).toContain(myapp); expect(output).toContain(myapp);
expect(output).not.toContain(myapp2); expect(output).not.toContain(myapp2);
@ -231,7 +231,7 @@ describe('Nx Affected and Graph Tests', () => {
it('should affect all projects by removing projects', async () => { it('should affect all projects by removing projects', async () => {
generateAll(); generateAll();
const root = (await readResolvedConfiguration())[mylib].root; const root = `libs/${mylib}`;
removeFile(root); removeFile(root);
const output = runCLI('print-affected --select projects'); const output = runCLI('print-affected --select projects');
expect(output).toContain(myapp); expect(output).toContain(myapp);
@ -241,10 +241,11 @@ describe('Nx Affected and Graph Tests', () => {
it('should detect changes to implicitly dependant projects', async () => { it('should detect changes to implicitly dependant projects', async () => {
generateAll(); generateAll();
await updateProjectConfig(myapp, (config) => ({ updateFile(join('apps', myapp, 'project.json'), (content) => {
...config, const data = JSON.parse(content);
implicitDependencies: ['*', `!${myapp2}`], data.implicitDependencies = ['*', `!${myapp2}`];
})); return JSON.stringify(data, null, 2);
});
runCommand('git commit -m "setup test"'); runCommand('git commit -m "setup test"');
updateFile(`libs/${mylib}/index.html`, '<html></html>'); updateFile(`libs/${mylib}/index.html`, '<html></html>');
@ -256,10 +257,12 @@ describe('Nx Affected and Graph Tests', () => {
expect(output).toContain(mylib); expect(output).toContain(mylib);
// Clear implicit deps to not interfere with other tests. // Clear implicit deps to not interfere with other tests.
await updateProjectConfig(myapp, (config) => ({
...config, updateFile(join('apps', myapp, 'project.json'), (content) => {
implicitDependencies: [], const data = JSON.parse(content);
})); data.implicitDependencies = [];
return JSON.stringify(data, null, 2);
});
}); });
it('should handle file renames', () => { it('should handle file renames', () => {

View File

@ -11,8 +11,8 @@ import {
uniq, uniq,
updateFile, updateFile,
updateJson, updateJson,
updateProjectConfig,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('cache', () => { describe('cache', () => {
beforeEach(() => newProject()); beforeEach(() => newProject());
@ -23,8 +23,9 @@ describe('cache', () => {
const myapp1 = uniq('myapp1'); const myapp1 = uniq('myapp1');
const myapp2 = uniq('myapp2'); const myapp2 = uniq('myapp2');
runCLI(`generate @nx/web:app ${myapp1}`); runCLI(`generate @nx/web:app ${myapp1}`);
setMaxWorkers(join('apps', myapp1, 'project.json'));
runCLI(`generate @nx/web:app ${myapp2}`); runCLI(`generate @nx/web:app ${myapp2}`);
await setMaxWorkers(); setMaxWorkers(join('apps', myapp2, 'project.json'));
// run build with caching // run build with caching
// -------------------------------------------- // --------------------------------------------
@ -153,7 +154,7 @@ describe('cache', () => {
it('should support using globs as outputs', async () => { it('should support using globs as outputs', async () => {
const mylib = uniq('mylib'); const mylib = uniq('mylib');
runCLI(`generate @nx/js:library ${mylib}`); runCLI(`generate @nx/js:library ${mylib}`);
await updateProjectConfig(mylib, (c) => { updateJson(join('libs', mylib, 'project.json'), (c) => {
c.targets.build = { c.targets.build = {
executor: 'nx:run-commands', executor: 'nx:run-commands',
outputs: ['{workspaceRoot}/dist/!(.next)/**/!(z|x).(txt|md)'], outputs: ['{workspaceRoot}/dist/!(.next)/**/!(z|x).(txt|md)'],

View File

@ -5,8 +5,9 @@ import {
runCommand, runCommand,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Invoke Runner', () => { describe('Invoke Runner', () => {
let proj: string; let proj: string;
@ -16,7 +17,7 @@ describe('Invoke Runner', () => {
it('should invoke runner imperatively ', async () => { it('should invoke runner imperatively ', async () => {
const mylib = uniq('mylib'); const mylib = uniq('mylib');
runCLI(`generate @nx/js:lib ${mylib}`); runCLI(`generate @nx/js:lib ${mylib}`);
await updateProjectConfig(mylib, (c) => { updateJson(join('libs', mylib, 'project.json'), (c) => {
c.targets['prebuild'] = { c.targets['prebuild'] = {
command: 'echo prebuild', command: 'echo prebuild',
}; };

View File

@ -4,9 +4,7 @@ import {
fileExists, fileExists,
isWindows, isWindows,
newProject, newProject,
readFile,
readJson, readJson,
readProjectConfig,
removeFile, removeFile,
runCLI, runCLI,
runCLIAsync, runCLIAsync,
@ -16,10 +14,10 @@ import {
uniq, uniq,
updateFile, updateFile,
updateJson, updateJson,
updateProjectConfig,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { PackageJson } from 'nx/src/utils/package-json'; import { PackageJson } from 'nx/src/utils/package-json';
import * as path from 'path'; import * as path from 'path';
import { join } from 'path';
describe('Nx Running Tests', () => { describe('Nx Running Tests', () => {
let proj: string; let proj: string;
@ -29,9 +27,9 @@ describe('Nx Running Tests', () => {
describe('running targets', () => { describe('running targets', () => {
describe('(forwarding params)', () => { describe('(forwarding params)', () => {
let proj = uniq('proj'); let proj = uniq('proj');
beforeAll(async () => { beforeAll(() => {
runCLI(`generate @nx/js:lib ${proj}`); runCLI(`generate @nx/js:lib ${proj}`);
await updateProjectConfig(proj, (c) => { updateJson(`libs/${proj}/project.json`, (c) => {
c.targets['echo'] = { c.targets['echo'] = {
command: 'echo ECHO:', command: 'echo ECHO:',
}; };
@ -55,10 +53,10 @@ describe('Nx Running Tests', () => {
}); });
}); });
it('should execute long running tasks', async () => { it('should execute long running tasks', () => {
const myapp = uniq('myapp'); const myapp = uniq('myapp');
runCLI(`generate @nx/web:app ${myapp}`); runCLI(`generate @nx/web:app ${myapp}`);
await updateProjectConfig(myapp, (c) => { updateJson(`apps/${myapp}/project.json`, (c) => {
c.targets['counter'] = { c.targets['counter'] = {
executor: '@nx/workspace:counter', executor: '@nx/workspace:counter',
options: { options: {
@ -80,8 +78,8 @@ describe('Nx Running Tests', () => {
runCLI(`generate @nx/node:lib ${mylib}`); runCLI(`generate @nx/node:lib ${mylib}`);
// Used to restore targets to lib after test // Used to restore targets to lib after test
const original = await readProjectConfig(mylib); const original = readJson(`libs/${mylib}/project.json`);
await updateProjectConfig(mylib, (j) => { updateJson(`libs/${mylib}/project.json`, (j) => {
delete j.targets; delete j.targets;
return j; return j;
}); });
@ -114,7 +112,7 @@ describe('Nx Running Tests', () => {
`Cannot find configuration for task ${mylib}:echo:fail` `Cannot find configuration for task ${mylib}:echo:fail`
); );
await updateProjectConfig(mylib, (c) => original); updateJson(`libs/${mylib}/project.json`, (c) => original);
}, 1000000); }, 1000000);
describe('tokens support', () => { describe('tokens support', () => {
@ -123,11 +121,11 @@ describe('Nx Running Tests', () => {
beforeAll(async () => { beforeAll(async () => {
app = uniq('myapp'); app = uniq('myapp');
runCLI(`generate @nx/web:app ${app}`); runCLI(`generate @nx/web:app ${app}`);
await setMaxWorkers(); setMaxWorkers(join('apps', app, 'project.json'));
}); });
it('should support using {projectRoot} in options blocks in project.json', async () => { it('should support using {projectRoot} in options blocks in project.json', async () => {
await updateProjectConfig(app, (c) => { updateJson(`apps/${app}/project.json`, (c) => {
c.targets['echo'] = { c.targets['echo'] = {
command: `node -e 'console.log("{projectRoot}")'`, command: `node -e 'console.log("{projectRoot}")'`,
}; };
@ -138,8 +136,8 @@ describe('Nx Running Tests', () => {
expect(output).toContain(`apps/${app}`); expect(output).toContain(`apps/${app}`);
}); });
it('should support using {projectName} in options blocks in project.json', async () => { it('should support using {projectName} in options blocks in project.json', () => {
await updateProjectConfig(app, (c) => { updateJson(`apps/${app}/project.json`, (c) => {
c.targets['echo'] = { c.targets['echo'] = {
command: `node -e 'console.log("{projectName}")'`, command: `node -e 'console.log("{projectName}")'`,
}; };
@ -159,7 +157,7 @@ describe('Nx Running Tests', () => {
}; };
return json; return json;
}); });
await updateProjectConfig(app, (c) => { updateJson(`apps/${app}/project.json`, (c) => {
c.targets['echo'] = {}; c.targets['echo'] = {};
return c; return c;
}); });
@ -167,7 +165,7 @@ describe('Nx Running Tests', () => {
expect(output).toContain(`apps/${app}`); expect(output).toContain(`apps/${app}`);
}); });
it('should support using {projectName} in targetDefaults', async () => { it('should support using {projectName} in targetDefaults', () => {
updateJson(`nx.json`, (json) => { updateJson(`nx.json`, (json) => {
json.targetDefaults = { json.targetDefaults = {
echo: { echo: {
@ -176,7 +174,7 @@ describe('Nx Running Tests', () => {
}; };
return json; return json;
}); });
await updateProjectConfig(app, (c) => { updateJson(`apps/${app}/project.json`, (c) => {
c.targets['echo'] = {}; c.targets['echo'] = {};
return c; return c;
}); });
@ -192,13 +190,13 @@ describe('Nx Running Tests', () => {
const myapp2 = uniq('b'); const myapp2 = uniq('b');
runCLI(`generate @nx/web:app ${myapp1}`); runCLI(`generate @nx/web:app ${myapp1}`);
runCLI(`generate @nx/web:app ${myapp2}`); runCLI(`generate @nx/web:app ${myapp2}`);
await updateProjectConfig(myapp1, (c) => { updateJson(`apps/${myapp1}/project.json`, (c) => {
c.targets['error'] = { c.targets['error'] = {
command: 'echo boom1 && exit 1', command: 'echo boom1 && exit 1',
}; };
return c; return c;
}); });
await updateProjectConfig(myapp2, (c) => { updateJson(`apps/${myapp2}/project.json`, (c) => {
c.targets['error'] = { c.targets['error'] = {
executor: 'nx:run-commands', executor: 'nx:run-commands',
options: { options: {
@ -431,8 +429,8 @@ describe('Nx Running Tests', () => {
}); });
it('should be able to include deps using dependsOn', async () => { it('should be able to include deps using dependsOn', async () => {
const originalWorkspace = await readProjectConfig(myapp); const originalWorkspace = readJson(`apps/${myapp}/project.json`);
await updateProjectConfig(myapp, (config) => { updateJson(`apps/${myapp}/project.json`, (config) => {
config.targets.prep = { config.targets.prep = {
executor: 'nx:run-commands', executor: 'nx:run-commands',
options: { options: {
@ -452,12 +450,12 @@ describe('Nx Running Tests', () => {
expect(output).toContain(mylib2); expect(output).toContain(mylib2);
expect(output).toContain('PREP'); expect(output).toContain('PREP');
await updateProjectConfig(myapp, () => originalWorkspace); updateJson(`apps/${myapp}/project.json`, () => originalWorkspace);
}, 10000); }, 10000);
it('should be able to include deps using target defaults defined at the root', async () => { it('should be able to include deps using target defaults defined at the root', async () => {
const nxJson = readJson('nx.json'); const nxJson = readJson('nx.json');
await updateProjectConfig(myapp, (config) => { updateJson(`apps/${myapp}/project.json`, (config) => {
config.targets.prep = { config.targets.prep = {
command: 'echo PREP > one.txt', command: 'echo PREP > one.txt',
}; };

View File

@ -7,7 +7,6 @@ import {
getPackageManagerCommand, getPackageManagerCommand,
newProject, newProject,
readJson, readJson,
readProjectConfig,
runCLI, runCLI,
runCLIAsync, runCLIAsync,
runCommand, runCommand,
@ -18,6 +17,7 @@ import {
import type { PackageJson } from 'nx/src/utils/package-json'; import type { PackageJson } from 'nx/src/utils/package-json';
import { ASYNC_GENERATOR_EXECUTOR_CONTENTS } from './nx-plugin.fixtures'; import { ASYNC_GENERATOR_EXECUTOR_CONTENTS } from './nx-plugin.fixtures';
import { join } from 'path';
describe('Nx Plugin', () => { describe('Nx Plugin', () => {
let npmScope: string; let npmScope: string;
@ -387,19 +387,23 @@ describe('Nx Plugin', () => {
`generate @nx/plugin:plugin ${plugin} --linter=eslint --directory subdir --e2eTestRunner=jest` `generate @nx/plugin:plugin ${plugin} --linter=eslint --directory subdir --e2eTestRunner=jest`
); );
checkFilesExist(`libs/subdir/${plugin}/package.json`); checkFilesExist(`libs/subdir/${plugin}/package.json`);
const pluginProject = await readProjectConfig(`subdir-${plugin}`); const pluginProject = readJson(
const pluginE2EProject = await readProjectConfig(`subdir-${plugin}-e2e`); join('libs', 'subdir', plugin, 'project.json')
);
const pluginE2EProject = readJson(
join('apps', 'subdir', `${plugin}-e2e`, 'project.json')
);
expect(pluginProject.targets).toBeDefined(); expect(pluginProject.targets).toBeDefined();
expect(pluginE2EProject).toBeTruthy(); expect(pluginE2EProject).toBeTruthy();
}, 90000); }, 90000);
}); });
describe('--tags', () => { describe('--tags', () => {
it('should add tags to project configuration', async () => { it('should add tags to project configuration', () => {
const plugin = uniq('plugin'); const plugin = uniq('plugin');
runCLI( runCLI(
`generate @nx/plugin:plugin ${plugin} --linter=eslint --tags=e2etag,e2ePackage ` `generate @nx/plugin:plugin ${plugin} --linter=eslint --tags=e2etag,e2ePackage `
); );
const pluginProject = await readProjectConfig(plugin); const pluginProject = readJson(join('libs', plugin, 'project.json'));
expect(pluginProject.tags).toEqual(['e2etag', 'e2ePackage']); expect(pluginProject.tags).toEqual(['e2etag', 'e2ePackage']);
}, 90000); }, 90000);
}); });

View File

@ -3,12 +3,13 @@ import {
checkFilesExist, checkFilesExist,
cleanupProject, cleanupProject,
newProject, newProject,
readProjectConfig, readJson,
runCLI, runCLI,
runCLIAsync, runCLIAsync,
uniq, uniq,
updateFile, updateFile,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('React Module Federation', () => { describe('React Module Federation', () => {
let proj: string; let proj: string;
@ -43,10 +44,10 @@ describe('React Module Federation', () => {
combinedOutput: expect.stringContaining('Test Suites: 1 passed, 1 total'), combinedOutput: expect.stringContaining('Test Suites: 1 passed, 1 total'),
}); });
expect(await readPort(shell)).toEqual(4200); expect(readPort(shell)).toEqual(4200);
expect(await readPort(remote1)).toEqual(4201); expect(readPort(remote1)).toEqual(4201);
expect(await readPort(remote2)).toEqual(4202); expect(readPort(remote2)).toEqual(4202);
expect(await readPort(remote3)).toEqual(4203); expect(readPort(remote3)).toEqual(4203);
updateFile( updateFile(
`apps/${shell}/webpack.config.js`, `apps/${shell}/webpack.config.js`,
@ -61,10 +62,10 @@ describe('React Module Federation', () => {
...baseConfig, ...baseConfig,
remotes: [ remotes: [
'${remote1}', '${remote1}',
['${remote2}', 'http://localhost:${await readPort( ['${remote2}', 'http://localhost:${readPort(
remote2 remote2
)}/remoteEntry.js'], )}/remoteEntry.js'],
['${remote3}', 'http://localhost:${await readPort(remote3)}'], ['${remote3}', 'http://localhost:${readPort(remote3)}'],
], ],
}; };
@ -108,10 +109,10 @@ describe('React Module Federation', () => {
// expect(e2eResults).toContain('All specs passed!'); // expect(e2eResults).toContain('All specs passed!');
// expect( // expect(
// await killPorts([ // await killPorts([
// await readPort(shell), // readPort(shell),
// await readPort(remote1), // readPort(remote1),
// await readPort(remote2), // readPort(remote2),
// await readPort(remote3), // readPort(remote3),
// ]) // ])
// ).toBeTruthy(); // ).toBeTruthy();
// } // }
@ -138,8 +139,8 @@ describe('React Module Federation', () => {
expect(buildOutput).toContain('Successfully ran target build'); expect(buildOutput).toContain('Successfully ran target build');
}, 500_000); }, 500_000);
async function readPort(appName: string): Promise<number> { function readPort(appName: string): number {
const config = await readProjectConfig(appName); const config = readJson(join('apps', appName, 'project.json'));
return config.targets.serve.options.port; return config.targets.serve.options.port;
} }
}); });

View File

@ -14,9 +14,9 @@ import {
uniq, uniq,
updateFile, updateFile,
updateJson, updateJson,
updateProjectConfig,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { names } from '@nx/devkit'; import { names } from '@nx/devkit';
import { join } from 'path';
describe('Build React libraries and apps', () => { describe('Build React libraries and apps', () => {
/** /**
@ -99,7 +99,7 @@ describe('Build React libraries and apps', () => {
); );
// Add assets to child lib // Add assets to child lib
await updateProjectConfig(childLib, (json) => { updateJson(join('libs', childLib, 'project.json'), (json) => {
json.targets.build.options.assets = [`libs/${childLib}/src/assets`]; json.targets.build.options.assets = [`libs/${childLib}/src/assets`];
return json; return json;
}); });

View File

@ -13,7 +13,6 @@ import {
uniq, uniq,
updateFile, updateFile,
updateJson, updateJson,
updateProjectConfig,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { readFileSync } from 'fs-extra'; import { readFileSync } from 'fs-extra';
import { join } from 'path'; import { join } from 'path';
@ -289,7 +288,7 @@ describe('React Applications', () => {
); );
// make sure stylePreprocessorOptions works // make sure stylePreprocessorOptions works
await updateProjectConfig(appName, (config) => { updateJson(join('apps', appName, 'project.json'), (config) => {
config.targets.build.options.stylePreprocessorOptions = { config.targets.build.options.stylePreprocessorOptions = {
includePaths: ['libs/shared/lib'], includePaths: ['libs/shared/lib'],
}; };

View File

@ -8,8 +8,8 @@ import {
uniq, uniq,
updateFile, updateFile,
updateJson, updateJson,
updateProjectConfig,
} from '../../utils'; } from '../../utils';
import { join } from 'path';
describe('React Cypress Component Tests', () => { describe('React Cypress Component Tests', () => {
let projectName; let projectName;
@ -131,7 +131,7 @@ export default Input;
` `
); );
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' })); createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
await updateProjectConfig(appName, (config) => { updateJson(join('apps', appName, 'project.json'), (config) => {
config.targets['build'].options.assets.push({ config.targets['build'].options.assets.push({
glob: '**/*', glob: '**/*',
input: 'libs/assets', input: 'libs/assets',
@ -252,7 +252,7 @@ ${content}`;
); );
` `
); );
await updateProjectConfig(appName, (config) => { updateJson(join('apps', appName, 'project.json'), (config) => {
config.targets[ config.targets[
'build' 'build'
].options.webpackConfig = `apps/${appName}/webpack.config.js`; ].options.webpackConfig = `apps/${appName}/webpack.config.js`;

View File

@ -8,8 +8,9 @@ import {
runCommand, runCommand,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Rollup Plugin', () => { describe('Rollup Plugin', () => {
beforeAll(() => newProject()); beforeAll(() => newProject());
@ -38,7 +39,7 @@ describe('Rollup Plugin', () => {
let output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`); let output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
expect(output).toMatch(/Hello/); expect(output).toMatch(/Hello/);
await updateProjectConfig(myPkg, (config) => { updateJson(join('libs', myPkg, 'project.json'), (config) => {
delete config.targets.build; delete config.targets.build;
return config; return config;
}); });
@ -52,7 +53,7 @@ describe('Rollup Plugin', () => {
output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`); output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`);
expect(output).toMatch(/Hello/); expect(output).toMatch(/Hello/);
await updateProjectConfig(myPkg, (config) => { updateJson(join('libs', myPkg, 'project.json'), (config) => {
delete config.targets.build; delete config.targets.build;
return config; return config;
}); });
@ -73,7 +74,7 @@ describe('Rollup Plugin', () => {
runCLI( runCLI(
`generate @nx/rollup:configuration ${myPkg} --target=node --tsConfig=libs/${myPkg}/tsconfig.lib.json --main=libs/${myPkg}/src/index.ts --compiler=tsc` `generate @nx/rollup:configuration ${myPkg} --target=node --tsConfig=libs/${myPkg}/tsconfig.lib.json --main=libs/${myPkg}/src/index.ts --compiler=tsc`
); );
await updateProjectConfig(myPkg, (config) => { updateJson(join('libs', myPkg, 'project.json'), (config) => {
config.targets.build.options.format = ['cjs', 'esm']; config.targets.build.options.format = ['cjs', 'esm'];
config.targets.build.options.generateExportsField = true; config.targets.build.options.generateExportsField = true;
config.targets.build.options.additionalEntryPoints = [ config.targets.build.options.additionalEntryPoints = [

View File

@ -11,6 +11,7 @@ import {
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { writeFileSync } from 'fs'; import { writeFileSync } from 'fs';
import { createFileSync } from 'fs-extra'; import { createFileSync } from 'fs-extra';
import { join } from 'path';
describe('Storybook generators and executors for monorepos', () => { describe('Storybook generators and executors for monorepos', () => {
const reactStorybookApp = uniq('react-app'); const reactStorybookApp = uniq('react-app');
@ -20,7 +21,7 @@ describe('Storybook generators and executors for monorepos', () => {
runCLI( runCLI(
`generate @nx/react:app ${reactStorybookApp} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` `generate @nx/react:app ${reactStorybookApp} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join(reactStorybookApp, 'project.json'));
runCLI( runCLI(
`generate @nx/react:storybook-configuration ${reactStorybookApp} --generateStories --no-interactive --bundler=webpack` `generate @nx/react:storybook-configuration ${reactStorybookApp} --generateStories --no-interactive --bundler=webpack`
); );

View File

@ -14,11 +14,9 @@ import { TargetConfiguration } from '@nx/devkit';
import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process'; import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process';
import { join } from 'path'; import { join } from 'path';
import * as isCI from 'is-ci'; import * as isCI from 'is-ci';
import { fileExists, readJson, updateFile } from './file-utils'; import { fileExists, readJson, updateJson } from './file-utils';
import { logError, stripConsoleColors } from './log-utils'; import { logError, stripConsoleColors } from './log-utils';
import { existsSync } from 'fs-extra'; import { existsSync } from 'fs-extra';
import { retrieveProjectConfigurations } from '../../packages/nx/src/project-graph/utils/retrieve-workspace-files';
import { readNxJson } from '../../packages/nx/src/config/nx-json';
export interface RunCmdOpts { export interface RunCmdOpts {
silenceError?: boolean; silenceError?: boolean;
@ -35,15 +33,9 @@ export interface RunCmdOpts {
* *
* maxWorkers required for: node, web, jest * maxWorkers required for: node, web, jest
*/ */
export async function setMaxWorkers() { export function setMaxWorkers(projectJsonPath: string) {
if (isCI) { if (isCI) {
const root = tmpProjPath(); updateJson<ProjectConfiguration>(projectJsonPath, (project) => {
const projects: Record<string, ProjectConfiguration> = (
await retrieveProjectConfigurations(root, readNxJson(root))
).projectNodes;
Object.keys(projects).forEach((appName) => {
let project = projects[appName];
const { build } = project.targets as { const { build } = project.targets as {
[targetName: string]: TargetConfiguration<any>; [targetName: string]: TargetConfiguration<any>;
}; };
@ -61,10 +53,7 @@ export async function setMaxWorkers() {
build.options.maxWorkers = 4; build.options.maxWorkers = 4;
} }
updateFile( return project;
join(project.root, 'project.json'),
JSON.stringify(project, null, 2)
);
}); });
} }
} }

View File

@ -8,6 +8,5 @@ export * from './create-project-utils';
export * from './file-utils'; export * from './file-utils';
export * from './get-env-info'; export * from './get-env-info';
export * from './log-utils'; export * from './log-utils';
export * from './project-config-utils';
export * from './test-utils'; export * from './test-utils';
export * from './process-utils'; export * from './process-utils';

View File

@ -1,34 +0,0 @@
import { ProjectConfiguration } from '@nx/devkit';
import { join } from 'path';
import { tmpProjPath } from './create-project-utils';
import { readJson, updateFile } from './file-utils';
import { retrieveProjectConfigurations } from '../../packages/nx/src/project-graph/utils/retrieve-workspace-files';
import { readNxJson } from '../../packages/nx/src/config/nx-json';
export async function updateProjectConfig(
projectName: string,
callback: (c: ProjectConfiguration) => ProjectConfiguration
) {
const projects = await readResolvedConfiguration();
const root = projects[projectName].root;
const path = join(root, 'project.json');
const current = readJson(path);
updateFile(path, JSON.stringify(callback(current), null, 2));
}
export async function readResolvedConfiguration(): Promise<
Record<string, ProjectConfiguration>
> {
process.env.NX_PROJECT_GLOB_CACHE = 'false';
const root = tmpProjPath();
return (await retrieveProjectConfigurations(root, readNxJson(root)))
.projectNodes;
}
export async function readProjectConfig(
projectName: string
): Promise<ProjectConfiguration> {
const root = (await readResolvedConfiguration())[projectName].root;
const path = join(root, 'project.json');
return readJson(path);
}

View File

@ -19,8 +19,9 @@ import {
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
const myApp = uniq('my-app'); const myApp = uniq('my-app');
@ -100,7 +101,7 @@ describe('Vite Plugin', () => {
` `
); );
await updateProjectConfig(myApp, (config) => { updateJson(join('apps', myApp, 'project.json'), (config) => {
config.targets.build.options.fileReplacements = [ config.targets.build.options.fileReplacements = [
{ {
replace: `apps/${myApp}/src/environments/environment.ts`, replace: `apps/${myApp}/src/environments/environment.ts`,
@ -434,7 +435,7 @@ export default defineConfig({
}); });
`; `;
}); });
await updateProjectConfig(lib, (config) => { updateJson(join('libs', lib, 'project.json'), (config) => {
delete config.targets.test.options.reportsDirectory; delete config.targets.test.options.reportsDirectory;
return config; return config;
}); });

View File

@ -7,8 +7,9 @@ import {
runCommandUntil, runCommandUntil,
setMaxWorkers, setMaxWorkers,
uniq, uniq,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('file-server', () => { describe('file-server', () => {
beforeAll(() => { beforeAll(() => {
@ -21,8 +22,8 @@ describe('file-server', () => {
const port = 4301; const port = 4301;
runCLI(`generate @nx/web:app ${appName} --no-interactive`); runCLI(`generate @nx/web:app ${appName} --no-interactive`);
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
await updateProjectConfig(appName, (config) => { updateJson(join('apps', appName, 'project.json'), (config) => {
config.targets['serve'].executor = '@nx/web:file-server'; config.targets['serve'].executor = '@nx/web:file-server';
return config; return config;
}); });
@ -58,7 +59,7 @@ describe('file-server', () => {
runCLI( runCLI(
`generate @nx/web:static-config --buildTarget=${reactAppName}:build --targetName=custom-serve-static --no-interactive` `generate @nx/web:static-config --buildTarget=${reactAppName}:build --targetName=custom-serve-static --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', reactAppName, 'project.json'));
const port = 6200; const port = 6200;

View File

@ -12,6 +12,7 @@ import {
setMaxWorkers, setMaxWorkers,
uniq, uniq,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Web Components Applications with bundler set as vite', () => { describe('Web Components Applications with bundler set as vite', () => {
beforeEach(() => newProject()); beforeEach(() => newProject());
@ -20,7 +21,7 @@ describe('Web Components Applications with bundler set as vite', () => {
it('should be able to generate a web app', async () => { it('should be able to generate a web app', async () => {
const appName = uniq('app'); const appName = uniq('app');
runCLI(`generate @nx/web:app ${appName} --bundler=vite --no-interactive`); runCLI(`generate @nx/web:app ${appName} --bundler=vite --no-interactive`);
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
const lintResults = runCLI(`lint ${appName}`); const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.'); expect(lintResults).toContain('All files pass linting.');
@ -51,7 +52,7 @@ describe('Web Components Applications with bundler set as vite', () => {
runCLI( runCLI(
`generate @nx/react:lib ${libName} --bundler=vite --no-interactive --unitTestRunner=vitest` `generate @nx/react:lib ${libName} --bundler=vite --no-interactive --unitTestRunner=vitest`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
createFile(`dist/apps/${appName}/_should_remove.txt`); createFile(`dist/apps/${appName}/_should_remove.txt`);
createFile(`dist/libs/${libName}/_should_remove.txt`); createFile(`dist/libs/${libName}/_should_remove.txt`);

View File

@ -6,6 +6,7 @@ import {
setMaxWorkers, setMaxWorkers,
uniq, uniq,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Web Components Applications with bundler set as webpack', () => { describe('Web Components Applications with bundler set as webpack', () => {
beforeEach(() => newProject()); beforeEach(() => newProject());
@ -16,7 +17,7 @@ describe('Web Components Applications with bundler set as webpack', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
await runCommandUntil(`serve ${appName} --port=5000 --ssl`, (output) => { await runCommandUntil(`serve ${appName} --port=5000 --ssl`, (output) => {
return output.includes('listening at https://localhost:5000'); return output.includes('listening at https://localhost:5000');

View File

@ -16,7 +16,7 @@ import {
tmpProjPath, tmpProjPath,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path'; import { join } from 'path';
import { copyFileSync } from 'fs'; import { copyFileSync } from 'fs';
@ -30,7 +30,7 @@ describe('Web Components Applications', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
const lintResults = runCLI(`lint ${appName}`); const lintResults = runCLI(`lint ${appName}`);
expect(lintResults).toContain('All files pass linting.'); expect(lintResults).toContain('All files pass linting.');
@ -105,7 +105,7 @@ describe('Web Components Applications', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --e2eTestRunner=playwright --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --e2eTestRunner=playwright --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
const lintE2eResults = runCLI(`lint ${appName}-e2e`); const lintE2eResults = runCLI(`lint ${appName}-e2e`);
@ -131,7 +131,7 @@ describe('Web Components Applications', () => {
runCLI( runCLI(
`generate @nx/react:lib ${libName} --bundler=rollup --no-interactive --compiler swc --unitTestRunner=jest` `generate @nx/react:lib ${libName} --bundler=rollup --no-interactive --compiler swc --unitTestRunner=jest`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
createFile(`dist/apps/${appName}/_should_remove.txt`); createFile(`dist/apps/${appName}/_should_remove.txt`);
createFile(`dist/libs/${libName}/_should_remove.txt`); createFile(`dist/libs/${libName}/_should_remove.txt`);
@ -168,7 +168,7 @@ describe('Web Components Applications', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --compiler=babel --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --compiler=babel --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
updateFile(`apps/${appName}/src/app/app.element.ts`, (content) => { updateFile(`apps/${appName}/src/app/app.element.ts`, (content) => {
const newContent = `${content} const newContent = `${content}
@ -224,7 +224,7 @@ describe('Web Components Applications', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --compiler=swc --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --compiler=swc --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
updateFile(`apps/${appName}/src/app/app.element.ts`, (content) => { updateFile(`apps/${appName}/src/app/app.element.ts`, (content) => {
const newContent = `${content} const newContent = `${content}
@ -267,9 +267,9 @@ describe('Web Components Applications', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
await updateProjectConfig(appName, (config) => { updateJson(join('apps', appName, 'project.json'), (config) => {
config.targets.build.options.webpackConfig = `apps/${appName}/webpack.config.js`; config.targets.build.options.webpackConfig = `apps/${appName}/webpack.config.js`;
return config; return config;
}); });
@ -388,7 +388,7 @@ describe('CLI - Environment Variables', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive --compiler=babel` `generate @nx/web:app ${appName} --bundler=webpack --no-interactive --compiler=babel`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
const content = readFile(main); const content = readFile(main);
@ -414,7 +414,7 @@ describe('CLI - Environment Variables', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName2} --bundler=webpack --no-interactive --compiler=babel` `generate @nx/web:app ${appName2} --bundler=webpack --no-interactive --compiler=babel`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName2, 'project.json'));
const content2 = readFile(main2); const content2 = readFile(main2);
@ -449,7 +449,7 @@ describe('Build Options', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
const srcPath = `apps/${appName}/src`; const srcPath = `apps/${appName}/src`;
const fooCss = `${srcPath}/foo.css`; const fooCss = `${srcPath}/foo.css`;
@ -475,7 +475,7 @@ describe('Build Options', () => {
const barScriptsBundleName = 'bar-scripts'; const barScriptsBundleName = 'bar-scripts';
const barStylesBundleName = 'bar-styles'; const barStylesBundleName = 'bar-styles';
await updateProjectConfig(appName, (config) => { updateJson(join('apps', appName, 'project.json'), (config) => {
const buildOptions = config.targets.build.options; const buildOptions = config.targets.build.options;
buildOptions.scripts = [ buildOptions.scripts = [
@ -529,7 +529,7 @@ describe('index.html interpolation', () => {
runCLI( runCLI(
`generate @nx/web:app ${appName} --bundler=webpack --no-interactive` `generate @nx/web:app ${appName} --bundler=webpack --no-interactive`
); );
await setMaxWorkers(); setMaxWorkers(join('apps', appName, 'project.json'));
const srcPath = `apps/${appName}/src`; const srcPath = `apps/${appName}/src`;
const indexPath = `${srcPath}/index.html`; const indexPath = `${srcPath}/index.html`;
@ -562,7 +562,7 @@ describe('index.html interpolation', () => {
updateFile(envFilePath, envFileContents); updateFile(envFilePath, envFileContents);
updateFile(indexPath, indexContent); updateFile(indexPath, indexContent);
await updateProjectConfig(appName, (config) => { updateJson(join('apps', appName, 'project.json'), (config) => {
const buildOptions = config.targets.build.options; const buildOptions = config.targets.build.options;
buildOptions.deployUrl = 'baz'; buildOptions.deployUrl = 'baz';
return config; return config;

View File

@ -6,8 +6,9 @@ import {
runCommand, runCommand,
uniq, uniq,
updateFile, updateFile,
updateProjectConfig, updateJson,
} from '@nx/e2e/utils'; } from '@nx/e2e/utils';
import { join } from 'path';
describe('Webpack Plugin', () => { describe('Webpack Plugin', () => {
beforeEach(() => newProject()); beforeEach(() => newProject());
@ -45,7 +46,7 @@ module.exports = composePlugins(withNx(), (config) => {
expect(output).not.toMatch(/Conflicting/); expect(output).not.toMatch(/Conflicting/);
expect(output).not.toMatch(/process.env.NODE_ENV/); expect(output).not.toMatch(/process.env.NODE_ENV/);
await updateProjectConfig(myPkg, (config) => { updateJson(join('libs', myPkg, 'project.json'), (config) => {
delete config.targets.build; delete config.targets.build;
return config; return config;
}); });
@ -59,7 +60,7 @@ module.exports = composePlugins(withNx(), (config) => {
output = runCommand(`node dist/libs/${myPkg}/main.js`); output = runCommand(`node dist/libs/${myPkg}/main.js`);
expect(output).toMatch(/Hello/); expect(output).toMatch(/Hello/);
await updateProjectConfig(myPkg, (config) => { updateJson(join('libs', myPkg, 'project.json'), (config) => {
delete config.targets.build; delete config.targets.build;
return config; return config;
}); });