diff --git a/e2e/angular-core/src/module-federation.test.ts b/e2e/angular-core/src/module-federation.test.ts index b6e1c4621f..5f7b668844 100644 --- a/e2e/angular-core/src/module-federation.test.ts +++ b/e2e/angular-core/src/module-federation.test.ts @@ -4,12 +4,13 @@ import { cleanupProject, killProcessAndPorts, newProject, - readProjectConfig, + readJson, runCLI, runCommandUntil, uniq, updateFile, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Angular Module Federation', () => { let proj: string; @@ -183,10 +184,10 @@ describe('Angular Module Federation', () => { // ports const hostPort = 4500; - const remote1Port = (await readProjectConfig(remote1)).targets.serve.options - .port; - const remote2Port = (await readProjectConfig(remote2)).targets.serve.options - .port; + const remote1Port = readJson(join(remote1, 'project.json')).targets.serve + .options.port; + const remote2Port = readJson(join(remote2, 'project.json')).targets.serve + .options.port; const process = await runCommandUntil( `serve-ssr ${host} --port=${hostPort}`, diff --git a/e2e/angular-core/src/projects.test.ts b/e2e/angular-core/src/projects.test.ts index b366b016c3..4c56d41380 100644 --- a/e2e/angular-core/src/projects.test.ts +++ b/e2e/angular-core/src/projects.test.ts @@ -14,9 +14,9 @@ import { tmpProjPath, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; -import { normalize } from 'path'; +import { join, normalize } from 'path'; describe('Angular Projects', () => { let proj: string; @@ -269,8 +269,8 @@ describe('Angular Projects', () => { ` ); - // update the angular.json - await updateProjectConfig(app1, (config) => { + // update the project.json + updateJson(join(app1, 'project.json'), (config) => { config.targets.build.executor = '@nx/angular:webpack-browser'; config.targets.build.options = { ...config.targets.build.options, @@ -278,7 +278,7 @@ describe('Angular Projects', () => { }; return config; }); - await updateProjectConfig(esbuildApp, (config) => { + updateJson(join(esbuildApp, 'project.json'), (config) => { config.targets.build.executor = '@nx/angular:browser-esbuild'; config.targets.build.options = { ...config.targets.build.options, diff --git a/e2e/angular-extensions/src/cypress-component-tests.test.ts b/e2e/angular-extensions/src/cypress-component-tests.test.ts index 62a82584de..179dd210c3 100644 --- a/e2e/angular-extensions/src/cypress-component-tests.test.ts +++ b/e2e/angular-extensions/src/cypress-component-tests.test.ts @@ -7,9 +7,9 @@ import { runE2ETests, uniq, updateFile, - updateProjectConfig, removeFile, checkFilesExist, + updateJson, } from '../../utils'; import { names } from '@nx/devkit'; 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 = { includePaths: ['assets/styles'], }; diff --git a/e2e/angular-extensions/src/tailwind.test.ts b/e2e/angular-extensions/src/tailwind.test.ts index b6613da95c..de275e8c33 100644 --- a/e2e/angular-extensions/src/tailwind.test.ts +++ b/e2e/angular-extensions/src/tailwind.test.ts @@ -7,8 +7,9 @@ import { runCLI, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Tailwind support', () => { let project: string; @@ -358,7 +359,7 @@ describe('Tailwind support', () => { runCLI( `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.options = { ...config.targets.build.options, diff --git a/e2e/esbuild/src/esbuild.test.ts b/e2e/esbuild/src/esbuild.test.ts index f994963b8a..c25e9302a5 100644 --- a/e2e/esbuild/src/esbuild.test.ts +++ b/e2e/esbuild/src/esbuild.test.ts @@ -14,9 +14,10 @@ import { tmpProjPath, uniq, updateFile, - updateProjectConfig, + updateJson, waitUntil, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('EsBuild Plugin', () => { let proj: string; @@ -29,7 +30,7 @@ describe('EsBuild Plugin', () => { const myPkg = uniq('my-pkg'); runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`); 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/*`]; return json; }); @@ -188,7 +189,7 @@ describe('EsBuild Plugin', () => { runCLI(`generate @nx/js:lib ${myPkg} --bundler=esbuild`); updateFile(`libs/${myPkg}/src/index.ts`, `console.log('main');\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 = [ `libs/${myPkg}/src/extra.ts`, ]; @@ -216,7 +217,7 @@ describe('EsBuild Plugin', () => { `libs/${myPkg}/esbuild.config.js`, `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; json.targets.build.options.esbuildConfig = `libs/${myPkg}/esbuild.config.js`; return json; diff --git a/e2e/expo/src/expo.test.ts b/e2e/expo/src/expo.test.ts index 0824db1123..b552d95d58 100644 --- a/e2e/expo/src/expo.test.ts +++ b/e2e/expo/src/expo.test.ts @@ -7,7 +7,6 @@ import { newProject, promisifiedTreeKill, readJson, - readResolvedConfiguration, runCLI, runCLIAsync, runCommand, @@ -85,8 +84,7 @@ describe('expo', () => { it('should prebuild', async () => { // run prebuild command with git check disable // set a mock package name for ios and android in expo's app.json - const projects = await readResolvedConfiguration(); - const root = projects[appName].root; + const root = `apps/${appName}`; const appJsonPath = join(root, `app.json`); const appJson = await readJson(appJsonPath); if (appJson.expo.ios) { diff --git a/e2e/js/src/js-executor-node.test.ts b/e2e/js/src/js-executor-node.test.ts index 5011bebef0..a301ff748a 100644 --- a/e2e/js/src/js-executor-node.test.ts +++ b/e2e/js/src/js-executor-node.test.ts @@ -5,8 +5,9 @@ import { setMaxWorkers, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('js:node executor', () => { 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'] = { executor: '@nx/js:node', options: { @@ -62,7 +63,7 @@ describe('js:node executor', () => { `; }); - await updateProjectConfig(rollupLib, (config) => { + updateJson(join('libs', rollupLib, 'project.json'), (config) => { config.targets['run-node'] = { executor: '@nx/js:node', options: { @@ -88,7 +89,7 @@ describe('js:node executor', () => { `; }); - await updateProjectConfig(tscLib, (config) => { + updateJson(join('libs', tscLib, 'project.json'), (config) => { config.targets['run-node'] = { executor: '@nx/js:node', options: { @@ -114,7 +115,7 @@ describe('js:node executor', () => { `; }); - await updateProjectConfig(swcLib, (config) => { + updateJson(join('libs', swcLib, 'project.json'), (config) => { config.targets['run-node'] = { executor: '@nx/js:node', options: { @@ -135,7 +136,7 @@ describe('js:node executor', () => { runCLI( `generate @nx/node:application ${webpackProject} --bundler=webpack --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', webpackProject, 'project.json')); updateFile(`apps/${webpackProject}/src/main.ts`, () => { return ` @@ -143,7 +144,7 @@ describe('js:node executor', () => { `; }); - await updateProjectConfig(webpackProject, (config) => { + updateJson(join('apps', webpackProject, 'project.json'), (config) => { config.targets['run-node'] = { executor: '@nx/js:node', options: { diff --git a/e2e/js/src/js-packaging.test.ts b/e2e/js/src/js-packaging.test.ts index 2081337724..73768826c2 100644 --- a/e2e/js/src/js-packaging.test.ts +++ b/e2e/js/src/js-packaging.test.ts @@ -1,6 +1,5 @@ import { updateJson, - updateProjectConfig, cleanupProject, newProject, runCLI, @@ -161,7 +160,7 @@ describe('packaging libs', () => { ); // Add additional entry points for `exports` field - await updateProjectConfig(tscLib, (json) => { + updateJson(join('libs', tscLib, 'project.json'), (json) => { json.targets.build.options.additionalEntryPoints = [ `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/faz.ts`, `export const faz = 'faz';`); - await updateProjectConfig(swcLib, (json) => { + updateJson(join('libs', swcLib, 'project.json'), (json) => { json.targets.build.options.additionalEntryPoints = [ `libs/${swcLib}/src/foo/*.ts`, ]; diff --git a/e2e/linter/src/linter.test.ts b/e2e/linter/src/linter.test.ts index 121472cb23..54f81dd716 100644 --- a/e2e/linter/src/linter.test.ts +++ b/e2e/linter/src/linter.test.ts @@ -728,7 +728,7 @@ describe('Linter', () => { runCLI( `generate @nx/node:app ${myapp} --rootProject=true --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers('project.json'); verifySuccessfulStandaloneSetup(myapp); let appEslint = readJson('.eslintrc.json'); diff --git a/e2e/next-core/src/next-structure.test.ts b/e2e/next-core/src/next-structure.test.ts index 25ae302a77..1b5c34f3b7 100644 --- a/e2e/next-core/src/next-structure.test.ts +++ b/e2e/next-core/src/next-structure.test.ts @@ -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 { checkApp } from './utils'; import { @@ -13,8 +13,9 @@ import { tmpProjPath, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Next.js Apps Libs', () => { let proj: string; @@ -57,7 +58,7 @@ describe('Next.js Apps Libs', () => { // Additional assets that should be copied to dist const sharedLib = uniq('sharedLib'); - await updateProjectConfig(appName, (json) => { + updateJson(join('packages', appName, 'project.json'), (json) => { json.targets.build.options.assets = [ { glob: '**/*', diff --git a/e2e/next-core/src/next-webpack.test.ts b/e2e/next-core/src/next-webpack.test.ts index b1c956d64e..cc69d36acc 100644 --- a/e2e/next-core/src/next-webpack.test.ts +++ b/e2e/next-core/src/next-webpack.test.ts @@ -6,8 +6,9 @@ import { runCLI, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Next.js Webpack', () => { let proj: string; @@ -80,7 +81,7 @@ describe('Next.js Webpack', () => { checkFilesExist(`dist/apps/${appName}/next.config.js`); // Make sure withNx works with run-commands. - await updateProjectConfig(appName, (json) => { + updateJson(join('apps', appName, 'project.json'), (json) => { json.targets.build = { command: 'npx next build', outputs: [`apps/${appName}/.next`], diff --git a/e2e/node/src/node-esbuild.test.ts b/e2e/node/src/node-esbuild.test.ts index cf095bb08d..e98d7e71df 100644 --- a/e2e/node/src/node-esbuild.test.ts +++ b/e2e/node/src/node-esbuild.test.ts @@ -14,6 +14,7 @@ import { updateFile, } from '@nx/e2e/utils'; import { execSync } from 'child_process'; +import { join } from 'path'; describe('Node Applications + esbuild', () => { beforeEach(() => newProject()); @@ -24,7 +25,7 @@ describe('Node Applications + esbuild', () => { const app = uniq('nodeapp'); runCLI(`generate @nx/node:app ${app} --bundler=esbuild --no-interactive`); - await setMaxWorkers(); + setMaxWorkers(join('apps', app, 'project.json')); checkFilesDoNotExist(`apps/${app}/webpack.config.js`); diff --git a/e2e/node/src/node-server.test.ts b/e2e/node/src/node-server.test.ts index ec9df54dd9..c23a0b56ba 100644 --- a/e2e/node/src/node-server.test.ts +++ b/e2e/node/src/node-server.test.ts @@ -9,10 +9,11 @@ import { runCLI, runCommandUntil, uniq, - updateProjectConfig, updateFile, setMaxWorkers, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Node Applications + webpack', () => { let proj: string; @@ -73,14 +74,17 @@ describe('Node Applications + webpack', () => { runCLI( `generate @nx/node:app ${expressApp} --framework=express --no-interactive` ); + setMaxWorkers(join('apps', expressApp, 'project.json')); runCLI( `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`); + setMaxWorkers(join('apps', koaApp, 'project.json')); runCLI( `generate @nx/node:app ${nestApp} --framework=nest --bundler=webpack --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', nestApp, 'project.json')); // Use esbuild by default checkFilesDoNotExist(`apps/${expressApp}/webpack.config.js`); @@ -140,7 +144,7 @@ describe('Node Applications + webpack', () => { runCLI( `generate @nx/node:app ${expressApp} --framework=express --docker --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', expressApp, 'project.json')); checkFilesExist(`apps/${expressApp}/Dockerfile`); }, 300_000); @@ -151,11 +155,12 @@ describe('Node Applications + webpack', () => { runCLI( `generate @nx/node:app ${nodeApp1} --framework=none --no-interactive` ); + setMaxWorkers(join('apps', nodeApp1, 'project.json')); runCLI( `generate @nx/node:app ${nodeApp2} --framework=none --no-interactive` ); - await setMaxWorkers(); - await updateProjectConfig(nodeApp1, (config) => { + setMaxWorkers(join('apps', nodeApp2, 'project.json')); + updateJson(join('apps', nodeApp1, 'project.json'), (config) => { config.targets.serve.options.waitUntilTargets = [`${nodeApp2}:build`]; return config; }); diff --git a/e2e/node/src/node-webpack.test.ts b/e2e/node/src/node-webpack.test.ts index f4cdb1b279..e05fb46cc8 100644 --- a/e2e/node/src/node-webpack.test.ts +++ b/e2e/node/src/node-webpack.test.ts @@ -10,10 +10,11 @@ import { tmpProjPath, uniq, updateFile, - updateProjectConfig, setMaxWorkers, + updateJson, } from '@nx/e2e/utils'; import { execSync } from 'child_process'; +import { join } from 'path'; describe('Node Applications + webpack', () => { beforeEach(() => newProject()); @@ -24,7 +25,7 @@ describe('Node Applications + webpack', () => { const app = uniq('nodeapp'); runCLI(`generate @nx/node:app ${app} --bundler=webpack --no-interactive`); - await setMaxWorkers(); + setMaxWorkers(join('apps', app, 'project.json')); checkFilesExist(`apps/${app}/webpack.config.js`); @@ -57,7 +58,7 @@ describe('Node Applications + webpack', () => { const lib = uniq('nodelib'); 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. config.targets.build.options.buildLibsFromSource = false; config.targets.serve.options.runBuildTargetDependencies = true; diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index d9dd301e8d..fa21c9304a 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -22,13 +22,13 @@ import { uniq, updateFile, updateJson, - updateProjectConfig, setMaxWorkers, } from '@nx/e2e/utils'; import { exec, execSync } from 'child_process'; import * as http from 'http'; import { getLockFileName } from '@nx/js'; import { satisfies } from 'semver'; +import { join } from 'path'; function getData(port, path = '/api'): Promise { return new Promise((resolve) => { @@ -58,7 +58,7 @@ describe('Node Applications', () => { const nodeapp = uniq('nodeapp'); runCLI(`generate @nx/node:app ${nodeapp} --linter=eslint`); - await setMaxWorkers(); + setMaxWorkers(join('apps', nodeapp, 'project.json')); const lintResults = runCLI(`lint ${nodeapp}`); 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 () => { const nodeapp = uniq('nodeapp'); 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'; return config; }); @@ -93,12 +93,12 @@ describe('Node Applications', () => { runCLI( `generate @nx/node:app ${nodeapp} --linter=eslint --bundler=webpack` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', nodeapp, 'project.json')); const lintResults = runCLI(`lint ${nodeapp}`); expect(lintResults).toContain('All files pass linting.'); - await updateProjectConfig(nodeapp, (config) => { + updateJson(join('apps', nodeapp, 'project.json'), (config) => { config.targets.build.options.additionalEntryPoints = [ { entryName: 'additional-main', @@ -153,7 +153,7 @@ describe('Node Applications', () => { runCLI( `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"`); @@ -188,7 +188,7 @@ describe('Node Applications', () => { process.env.PORT = `${port}`; runCLI(`generate @nx/express:app ${nodeapp} --linter=eslint`); - await setMaxWorkers(); + setMaxWorkers(join('apps', nodeapp, 'project.json')); const lintResults = runCLI(`lint ${nodeapp}`); expect(lintResults).toContain('All files pass linting.'); @@ -230,7 +230,7 @@ describe('Node Applications', () => { const nestapp = uniq('nestapp'); const port = 3335; runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`); - await setMaxWorkers(); + setMaxWorkers(join('apps', nestapp, 'project.json')); const lintResults = runCLI(`lint ${nestapp}`); expect(lintResults).toContain('All files pass linting.'); @@ -292,13 +292,13 @@ describe('Node Applications', () => { runCLI( `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) => { config.module = 'esnext'; config.target = 'es2020'; return config; }); - await updateProjectConfig(esmapp, (config) => { + updateJson(join('apps', esmapp, 'project.json'), (config) => { config.targets.build.options.outputFileName = 'main.mjs'; config.targets.build.options.assets = []; return config; @@ -340,7 +340,7 @@ describe('Build Node apps', () => { const packageManager = detectPackageManager(tmpProjPath()); const nestapp = uniq('nestapp'); runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`); - await setMaxWorkers(); + setMaxWorkers(join('apps', nestapp, 'project.json')); await runCLIAsync(`build ${nestapp} --generatePackageJson`); @@ -402,7 +402,7 @@ describe('Build Node apps', () => { const nodeapp = uniq('nodeapp'); runCLI(`generate @nx/node:app ${nodeapp} --bundler=webpack`); - await setMaxWorkers(); + setMaxWorkers(join('apps', nodeapp, 'project.json')); const jslib = uniq('jslib'); runCLI(`generate @nx/js:lib ${jslib} --bundler=tsc`); @@ -443,7 +443,7 @@ ${jslib}(); const appName = uniq('app'); runCLI(`generate @nx/node:app ${appName} --no-interactive`); - await setMaxWorkers(); + setMaxWorkers(join('apps', appName, 'project.json')); // deleteOutputPath should default to true createFile(`dist/apps/${appName}/_should_remove.txt`); @@ -526,11 +526,11 @@ ${jslib}(); newProject(); const nestapp = uniq('nestapp'); runCLI(`generate @nx/nest:app ${nestapp} --linter=eslint`); - await setMaxWorkers(); + setMaxWorkers(join('apps', nestapp, 'project.json')); 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']; return config; }); @@ -643,7 +643,7 @@ describe('nest libraries', function () { packageInstall('@nestjs/swagger', undefined, '~6.3.0'); - await updateProjectConfig(nestlib, (config) => { + updateJson(join('libs', nestlib, 'project.json'), (config) => { config.targets.build.options.transformers = [ { name: '@nestjs/swagger/plugin', diff --git a/e2e/nx-misc/src/extras.test.ts b/e2e/nx-misc/src/extras.test.ts index 5949da6178..c036e3a5eb 100644 --- a/e2e/nx-misc/src/extras.test.ts +++ b/e2e/nx-misc/src/extras.test.ts @@ -8,8 +8,9 @@ import { setMaxWorkers, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Extra Nx Misc Tests', () => { beforeAll(() => newProject()); @@ -19,9 +20,9 @@ describe('Extra Nx Misc Tests', () => { it('should stream output', async () => { const myapp = 'abcdefghijklmon'; 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'] = { command: 'echo inner', }; @@ -125,7 +126,7 @@ describe('Extra Nx Misc Tests', () => { process.platform === 'win32' ? `%SHARED_VAR% %ROOT_ONLY% %NESTED_ONLY%` // Windows : `$SHARED_VAR $ROOT_ONLY $NESTED_ONLY`; - await updateProjectConfig(mylib, (config) => { + updateJson(join('libs', mylib, 'project.json'), (config) => { config.targets.echoEnvVariables.options.command += ` ${command}`; return config; }); @@ -138,7 +139,7 @@ describe('Extra Nx Misc Tests', () => { }, 120000); it('should pass options', async () => { - await updateProjectConfig(mylib, (config) => { + updateJson(join('libs', mylib, 'project.json'), (config) => { config.targets.echo = { command: 'echo --var1={args.var1}', options: { @@ -154,7 +155,7 @@ describe('Extra Nx Misc Tests', () => { it('should interpolate provided arguments', async () => { const echoTarget = uniq('echo'); - await updateProjectConfig(mylib, (config) => { + updateJson(join('libs', mylib, 'project.json'), (config) => { config.targets[echoTarget] = { executor: 'nx:run-commands', options: { @@ -189,7 +190,7 @@ describe('Extra Nx Misc Tests', () => { }, 120000); it('should fail when a process exits non-zero', async () => { - await updateProjectConfig(mylib, (config) => { + updateJson(join('libs', mylib, 'project.json'), (config) => { config.targets.error = { executor: 'nx:run-commands', 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 () => { - await updateProjectConfig(mylib, (config) => { + updateJson(join('libs', mylib, 'project.json'), (config) => { config.targets.lint.outputs = ['{options.outputFile}']; return config; }); @@ -244,7 +245,7 @@ describe('Extra Nx Misc Tests', () => { : `mkdir -p ${folder}`, `echo dummy > ${folder}/dummy.txt`, ]; - await updateProjectConfig(mylib, (config) => { + updateJson(join('libs', mylib, 'project.json'), (config) => { delete config.targets.build.options.command; config.targets.build.options = { ...config.targets.build.options, diff --git a/e2e/nx-misc/src/misc.test.ts b/e2e/nx-misc/src/misc.test.ts index 4b1762b2fa..7c7da03043 100644 --- a/e2e/nx-misc/src/misc.test.ts +++ b/e2e/nx-misc/src/misc.test.ts @@ -23,10 +23,10 @@ import { renameSync, writeFileSync } from 'fs'; import { ensureDirSync } from 'fs-extra'; import * as path from 'path'; import { major } from 'semver'; +import { join } from 'path'; describe('Nx Commands', () => { - let proj: string; - beforeAll(() => (proj = newProject())); + beforeAll(() => newProject()); afterAll(() => cleanupProject()); @@ -40,7 +40,7 @@ describe('Nx Commands', () => { runCLI(`generate @nx/web:app ${app1} --tags e2etag`); runCLI(`generate @nx/web:app ${app2}`); - await setMaxWorkers(); + setMaxWorkers(join('apps', app1, 'project.json')); const s = runCLI('show projects').split('\n'); @@ -150,8 +150,8 @@ describe('Nx Commands', () => { beforeAll(async () => { runCLI(`generate @nx/web:app ${myapp}`); + setMaxWorkers(join('apps', myapp, 'project.json')); runCLI(`generate @nx/js:lib ${mylib}`); - await setMaxWorkers(); }); beforeEach(() => { diff --git a/e2e/nx-misc/src/workspace.test.ts b/e2e/nx-misc/src/workspace.test.ts index 7c28ee110f..1e33185b2a 100644 --- a/e2e/nx-misc/src/workspace.test.ts +++ b/e2e/nx-misc/src/workspace.test.ts @@ -8,14 +8,12 @@ import { updateFile, readFile, exists, - updateProjectConfig, - readProjectConfig, tmpProjPath, - readResolvedConfiguration, getPackageManagerCommand, getSelectedPackageManager, runCommand, } from '@nx/e2e/utils'; +import { join } from 'path'; let proj: string; @@ -119,9 +117,10 @@ describe('Workspace Tests', () => { runCLI( `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` ); - await updateProjectConfig(lib3, (config) => { - config.implicitDependencies = [`${lib1}-data-access`]; - return config; + updateFile(join(lib3, 'project.json'), (content) => { + const data = JSON.parse(content); + data.implicitDependencies = [`${lib1}-data-access`]; + return JSON.stringify(data, null, 2); }); /** @@ -178,13 +177,13 @@ describe('Workspace Tests', () => { expect(moveOutput).toContain(`CREATE ${rootClassPath}`); checkFilesExist(rootClassPath); - let projects = await readResolvedConfiguration(); - expect(projects[`${lib1}-data-access`]).toBeUndefined(); - const newConfig = await readProjectConfig(newName); + let projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(`${lib1}-data-access`); + const newConfig = readJson(join(newPath, 'project.json')); expect(newConfig).toMatchObject({ tags: [], }); - const lib3Config = await readProjectConfig(lib3); + const lib3Config = readJson(join(lib3, 'project.json')); expect(lib3Config.implicitDependencies).toEqual([ `shared-${lib1}-data-access`, ]); @@ -200,9 +199,9 @@ describe('Workspace Tests', () => { ] ).toEqual([`shared/${lib1}/data-access/src/index.ts`]); - projects = await readResolvedConfiguration(); - expect(projects[`${lib1}-data-access`]).toBeUndefined(); - const project = await readProjectConfig(newName); + projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(`${lib1}-data-access`); + const project = readJson(join(newPath, 'project.json')); expect(project).toBeTruthy(); expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.targets.lint.options.lintFilePatterns).toEqual([ @@ -261,9 +260,10 @@ describe('Workspace Tests', () => { runCLI( `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` ); - await updateProjectConfig(lib3, (config) => { - config.implicitDependencies = [`${lib1}-data-access`]; - return config; + updateFile(join(lib3, 'project.json'), (content) => { + const data = JSON.parse(content); + 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`]); - const projects = await readResolvedConfiguration(); - expect(projects[`${lib1}-data-access`]).toBeUndefined(); - const project = await readProjectConfig(newName); + const projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(`${lib1}-data-access`); + const project = readJson(join(newPath, 'project.json')); expect(project).toBeTruthy(); expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.tags).toEqual([]); - const lib3Config = await readProjectConfig(lib3); + const lib3Config = readJson(join(lib3, 'project.json')); expect(lib3Config.implicitDependencies).toEqual([newName]); expect(project.targets.lint.options.lintFilePatterns).toEqual([ @@ -400,9 +400,10 @@ describe('Workspace Tests', () => { runCLI( `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=derived` ); - await updateProjectConfig(lib3, (config) => { - config.implicitDependencies = [`${lib1}-data-access`]; - return config; + updateFile(join('packages', lib3, 'project.json'), (content) => { + const data = JSON.parse(content); + 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`]); - const projects = await readResolvedConfiguration(); - expect(projects[`${lib1}-data-access`]).toBeUndefined(); - const project = await readProjectConfig(newName); + const projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(`${lib1}-data-access`); + const project = readJson(join(newPath, 'project.json')); expect(project).toBeTruthy(); expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.targets.lint.options.lintFilePatterns).toEqual([ @@ -532,9 +533,10 @@ describe('Workspace Tests', () => { runCLI( `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` ); - await updateProjectConfig(lib3, (config) => { - config.implicitDependencies = [lib1]; - return config; + updateFile(join(lib3, 'project.json'), (content) => { + const data = JSON.parse(content); + data.implicitDependencies = [lib1]; + return JSON.stringify(data, null, 2); }); /** @@ -587,13 +589,13 @@ describe('Workspace Tests', () => { expect(moveOutput).toContain(`CREATE ${rootClassPath}`); checkFilesExist(rootClassPath); - let projects = await readResolvedConfiguration(); - expect(projects[lib1]).toBeUndefined(); - const newConfig = await readProjectConfig(newName); + let projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(lib1); + const newConfig = readJson(join(newPath, 'project.json')); expect(newConfig).toMatchObject({ tags: [], }); - const lib3Config = await readProjectConfig(lib3); + const lib3Config = readJson(join(lib3, 'project.json')); expect(lib3Config.implicitDependencies).toEqual([`${lib1}-data-access`]); expect(moveOutput).toContain('UPDATE tsconfig.base.json'); @@ -605,9 +607,9 @@ describe('Workspace Tests', () => { rootTsConfig.compilerOptions.paths[`@${proj}/${lib1}-data-access`] ).toEqual([`${lib1}/data-access/src/index.ts`]); - projects = await readResolvedConfiguration(); - expect(projects[lib1]).toBeUndefined(); - const project = await readProjectConfig(newName); + projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(lib1); + const project = readJson(join(newPath, 'project.json')); expect(project).toBeTruthy(); expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.targets.lint.options.lintFilePatterns).toEqual([ @@ -676,9 +678,10 @@ describe('Workspace Tests', () => { runCLI( `generate @nx/js:lib ${lib3} --unitTestRunner=jest --project-name-and-root-format=as-provided` ); - await updateProjectConfig(lib3, (config) => { - config.implicitDependencies = [`${lib1}-data-access`]; - return config; + updateFile(join(lib3, 'project.json'), (content) => { + const data = JSON.parse(content); + data.implicitDependencies = [`${lib1}-data-access`]; + return JSON.stringify(data, null, 2); }); /** @@ -707,11 +710,11 @@ describe('Workspace Tests', () => { expect(moveOutput).toContain(`CREATE ${rootClassPath}`); checkFilesExist(rootClassPath); - const newConfig = await readProjectConfig(newName); + const newConfig = readJson(join(newPath, 'project.json')); expect(newConfig).toMatchObject({ tags: [], }); - const lib3Config = await readProjectConfig(lib3); + const lib3Config = readJson(join(lib3, 'project.json')); expect(lib3Config.implicitDependencies).toEqual([ `shared-${lib1}-data-access`, ]); @@ -725,9 +728,9 @@ describe('Workspace Tests', () => { rootTsConfig.compilerOptions.paths[`shared-${lib1}-data-access`] ).toEqual([`shared/${lib1}/data-access/src/index.ts`]); - const projects = await readResolvedConfiguration(); - expect(projects[`${lib1}-data-access`]).toBeUndefined(); - const project = await readProjectConfig(newName); + const projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(`${lib1}-data-access`); + const project = readJson(join(newPath, 'project.json')); expect(project).toBeTruthy(); expect(project.sourceRoot).toBe(`${newPath}/src`); expect(project.targets.lint.options.lintFilePatterns).toEqual([ @@ -762,9 +765,10 @@ describe('Workspace Tests', () => { */ runCLI(`generate @nx/js:lib ${lib2} --unitTestRunner=jest`); - await updateProjectConfig(lib2, (config) => { - config.implicitDependencies = [lib1]; - return config; + updateFile(join('libs', lib2, 'project.json'), (content) => { + const data = JSON.parse(content); + data.implicitDependencies = [lib1]; + return JSON.stringify(data, null, 2); }); /** @@ -796,9 +800,9 @@ describe('Workspace Tests', () => { expect(exists(tmpProjPath(`libs/${lib1}`))).toBeFalsy(); expect(removeOutputForced).not.toContain(`UPDATE nx.json`); - const projects = await readResolvedConfiguration(); - expect(projects[`${lib1}`]).toBeUndefined(); - const lib2Config = await readProjectConfig(lib2); + const projects = runCLI('show projects').split('\n'); + expect(projects).not.toContain(lib1); + const lib2Config = readJson(join('libs', lib2, 'project.json')); expect(lib2Config.implicitDependencies).toEqual([]); expect(projects[`${lib1}`]).toBeUndefined(); diff --git a/e2e/nx-run/src/affected-graph.test.ts b/e2e/nx-run/src/affected-graph.test.ts index 4a6e1b1cf4..61965c17c4 100644 --- a/e2e/nx-run/src/affected-graph.test.ts +++ b/e2e/nx-run/src/affected-graph.test.ts @@ -11,13 +11,12 @@ import { runCommand, uniq, updateFile, - updateProjectConfig, checkFilesExist, isWindows, fileExists, removeFile, - readResolvedConfiguration, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Nx Affected and Graph Tests', () => { let proj: string; @@ -218,10 +217,11 @@ describe('Nx Affected and Graph Tests', () => { // TODO: investigate why affected gives different results on windows if (isNotWindows()) { generateAll(); - await updateProjectConfig(myapp, (config) => ({ - ...config, - tags: ['tag'], - })); + updateFile(join('apps', myapp, 'project.json'), (content) => { + const data = JSON.parse(content); + data.tags = ['tag']; + return JSON.stringify(data, null, 2); + }); const output = runCLI('print-affected --select projects'); expect(output).toContain(myapp); expect(output).not.toContain(myapp2); @@ -231,7 +231,7 @@ describe('Nx Affected and Graph Tests', () => { it('should affect all projects by removing projects', async () => { generateAll(); - const root = (await readResolvedConfiguration())[mylib].root; + const root = `libs/${mylib}`; removeFile(root); const output = runCLI('print-affected --select projects'); expect(output).toContain(myapp); @@ -241,10 +241,11 @@ describe('Nx Affected and Graph Tests', () => { it('should detect changes to implicitly dependant projects', async () => { generateAll(); - await updateProjectConfig(myapp, (config) => ({ - ...config, - implicitDependencies: ['*', `!${myapp2}`], - })); + updateFile(join('apps', myapp, 'project.json'), (content) => { + const data = JSON.parse(content); + data.implicitDependencies = ['*', `!${myapp2}`]; + return JSON.stringify(data, null, 2); + }); runCommand('git commit -m "setup test"'); updateFile(`libs/${mylib}/index.html`, ''); @@ -256,10 +257,12 @@ describe('Nx Affected and Graph Tests', () => { expect(output).toContain(mylib); // Clear implicit deps to not interfere with other tests. - await updateProjectConfig(myapp, (config) => ({ - ...config, - implicitDependencies: [], - })); + + updateFile(join('apps', myapp, 'project.json'), (content) => { + const data = JSON.parse(content); + data.implicitDependencies = []; + return JSON.stringify(data, null, 2); + }); }); it('should handle file renames', () => { diff --git a/e2e/nx-run/src/cache.test.ts b/e2e/nx-run/src/cache.test.ts index d1ae7642d6..a6ffa7186a 100644 --- a/e2e/nx-run/src/cache.test.ts +++ b/e2e/nx-run/src/cache.test.ts @@ -11,8 +11,8 @@ import { uniq, updateFile, updateJson, - updateProjectConfig, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('cache', () => { beforeEach(() => newProject()); @@ -23,8 +23,9 @@ describe('cache', () => { const myapp1 = uniq('myapp1'); const myapp2 = uniq('myapp2'); runCLI(`generate @nx/web:app ${myapp1}`); + setMaxWorkers(join('apps', myapp1, 'project.json')); runCLI(`generate @nx/web:app ${myapp2}`); - await setMaxWorkers(); + setMaxWorkers(join('apps', myapp2, 'project.json')); // run build with caching // -------------------------------------------- @@ -153,7 +154,7 @@ describe('cache', () => { it('should support using globs as outputs', async () => { const mylib = uniq('mylib'); runCLI(`generate @nx/js:library ${mylib}`); - await updateProjectConfig(mylib, (c) => { + updateJson(join('libs', mylib, 'project.json'), (c) => { c.targets.build = { executor: 'nx:run-commands', outputs: ['{workspaceRoot}/dist/!(.next)/**/!(z|x).(txt|md)'], diff --git a/e2e/nx-run/src/invoke-runner.test.ts b/e2e/nx-run/src/invoke-runner.test.ts index 9d53d15e73..4f6f27073c 100644 --- a/e2e/nx-run/src/invoke-runner.test.ts +++ b/e2e/nx-run/src/invoke-runner.test.ts @@ -5,8 +5,9 @@ import { runCommand, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Invoke Runner', () => { let proj: string; @@ -16,7 +17,7 @@ describe('Invoke Runner', () => { it('should invoke runner imperatively ', async () => { const mylib = uniq('mylib'); runCLI(`generate @nx/js:lib ${mylib}`); - await updateProjectConfig(mylib, (c) => { + updateJson(join('libs', mylib, 'project.json'), (c) => { c.targets['prebuild'] = { command: 'echo prebuild', }; diff --git a/e2e/nx-run/src/run.test.ts b/e2e/nx-run/src/run.test.ts index d6a5a7f668..7e2af05d58 100644 --- a/e2e/nx-run/src/run.test.ts +++ b/e2e/nx-run/src/run.test.ts @@ -4,9 +4,7 @@ import { fileExists, isWindows, newProject, - readFile, readJson, - readProjectConfig, removeFile, runCLI, runCLIAsync, @@ -16,10 +14,10 @@ import { uniq, updateFile, updateJson, - updateProjectConfig, } from '@nx/e2e/utils'; import { PackageJson } from 'nx/src/utils/package-json'; import * as path from 'path'; +import { join } from 'path'; describe('Nx Running Tests', () => { let proj: string; @@ -29,9 +27,9 @@ describe('Nx Running Tests', () => { describe('running targets', () => { describe('(forwarding params)', () => { let proj = uniq('proj'); - beforeAll(async () => { + beforeAll(() => { runCLI(`generate @nx/js:lib ${proj}`); - await updateProjectConfig(proj, (c) => { + updateJson(`libs/${proj}/project.json`, (c) => { c.targets['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'); runCLI(`generate @nx/web:app ${myapp}`); - await updateProjectConfig(myapp, (c) => { + updateJson(`apps/${myapp}/project.json`, (c) => { c.targets['counter'] = { executor: '@nx/workspace:counter', options: { @@ -80,8 +78,8 @@ describe('Nx Running Tests', () => { runCLI(`generate @nx/node:lib ${mylib}`); // Used to restore targets to lib after test - const original = await readProjectConfig(mylib); - await updateProjectConfig(mylib, (j) => { + const original = readJson(`libs/${mylib}/project.json`); + updateJson(`libs/${mylib}/project.json`, (j) => { delete j.targets; return j; }); @@ -114,7 +112,7 @@ describe('Nx Running Tests', () => { `Cannot find configuration for task ${mylib}:echo:fail` ); - await updateProjectConfig(mylib, (c) => original); + updateJson(`libs/${mylib}/project.json`, (c) => original); }, 1000000); describe('tokens support', () => { @@ -123,11 +121,11 @@ describe('Nx Running Tests', () => { beforeAll(async () => { app = uniq('myapp'); 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 () => { - await updateProjectConfig(app, (c) => { + updateJson(`apps/${app}/project.json`, (c) => { c.targets['echo'] = { command: `node -e 'console.log("{projectRoot}")'`, }; @@ -138,8 +136,8 @@ describe('Nx Running Tests', () => { expect(output).toContain(`apps/${app}`); }); - it('should support using {projectName} in options blocks in project.json', async () => { - await updateProjectConfig(app, (c) => { + it('should support using {projectName} in options blocks in project.json', () => { + updateJson(`apps/${app}/project.json`, (c) => { c.targets['echo'] = { command: `node -e 'console.log("{projectName}")'`, }; @@ -159,7 +157,7 @@ describe('Nx Running Tests', () => { }; return json; }); - await updateProjectConfig(app, (c) => { + updateJson(`apps/${app}/project.json`, (c) => { c.targets['echo'] = {}; return c; }); @@ -167,7 +165,7 @@ describe('Nx Running Tests', () => { expect(output).toContain(`apps/${app}`); }); - it('should support using {projectName} in targetDefaults', async () => { + it('should support using {projectName} in targetDefaults', () => { updateJson(`nx.json`, (json) => { json.targetDefaults = { echo: { @@ -176,7 +174,7 @@ describe('Nx Running Tests', () => { }; return json; }); - await updateProjectConfig(app, (c) => { + updateJson(`apps/${app}/project.json`, (c) => { c.targets['echo'] = {}; return c; }); @@ -192,13 +190,13 @@ describe('Nx Running Tests', () => { const myapp2 = uniq('b'); runCLI(`generate @nx/web:app ${myapp1}`); runCLI(`generate @nx/web:app ${myapp2}`); - await updateProjectConfig(myapp1, (c) => { + updateJson(`apps/${myapp1}/project.json`, (c) => { c.targets['error'] = { command: 'echo boom1 && exit 1', }; return c; }); - await updateProjectConfig(myapp2, (c) => { + updateJson(`apps/${myapp2}/project.json`, (c) => { c.targets['error'] = { executor: 'nx:run-commands', options: { @@ -431,8 +429,8 @@ describe('Nx Running Tests', () => { }); it('should be able to include deps using dependsOn', async () => { - const originalWorkspace = await readProjectConfig(myapp); - await updateProjectConfig(myapp, (config) => { + const originalWorkspace = readJson(`apps/${myapp}/project.json`); + updateJson(`apps/${myapp}/project.json`, (config) => { config.targets.prep = { executor: 'nx:run-commands', options: { @@ -452,12 +450,12 @@ describe('Nx Running Tests', () => { expect(output).toContain(mylib2); expect(output).toContain('PREP'); - await updateProjectConfig(myapp, () => originalWorkspace); + updateJson(`apps/${myapp}/project.json`, () => originalWorkspace); }, 10000); it('should be able to include deps using target defaults defined at the root', async () => { const nxJson = readJson('nx.json'); - await updateProjectConfig(myapp, (config) => { + updateJson(`apps/${myapp}/project.json`, (config) => { config.targets.prep = { command: 'echo PREP > one.txt', }; diff --git a/e2e/plugin/src/nx-plugin.test.ts b/e2e/plugin/src/nx-plugin.test.ts index a725656cf8..97e3e653af 100644 --- a/e2e/plugin/src/nx-plugin.test.ts +++ b/e2e/plugin/src/nx-plugin.test.ts @@ -7,7 +7,6 @@ import { getPackageManagerCommand, newProject, readJson, - readProjectConfig, runCLI, runCLIAsync, runCommand, @@ -18,6 +17,7 @@ import { import type { PackageJson } from 'nx/src/utils/package-json'; import { ASYNC_GENERATOR_EXECUTOR_CONTENTS } from './nx-plugin.fixtures'; +import { join } from 'path'; describe('Nx Plugin', () => { let npmScope: string; @@ -387,19 +387,23 @@ describe('Nx Plugin', () => { `generate @nx/plugin:plugin ${plugin} --linter=eslint --directory subdir --e2eTestRunner=jest` ); checkFilesExist(`libs/subdir/${plugin}/package.json`); - const pluginProject = await readProjectConfig(`subdir-${plugin}`); - const pluginE2EProject = await readProjectConfig(`subdir-${plugin}-e2e`); + const pluginProject = readJson( + join('libs', 'subdir', plugin, 'project.json') + ); + const pluginE2EProject = readJson( + join('apps', 'subdir', `${plugin}-e2e`, 'project.json') + ); expect(pluginProject.targets).toBeDefined(); expect(pluginE2EProject).toBeTruthy(); }, 90000); }); describe('--tags', () => { - it('should add tags to project configuration', async () => { + it('should add tags to project configuration', () => { const plugin = uniq('plugin'); runCLI( `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']); }, 90000); }); diff --git a/e2e/react-core/src/react-module-federation.test.ts b/e2e/react-core/src/react-module-federation.test.ts index 2030c256fc..f03f99fa2c 100644 --- a/e2e/react-core/src/react-module-federation.test.ts +++ b/e2e/react-core/src/react-module-federation.test.ts @@ -3,12 +3,13 @@ import { checkFilesExist, cleanupProject, newProject, - readProjectConfig, + readJson, runCLI, runCLIAsync, uniq, updateFile, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('React Module Federation', () => { let proj: string; @@ -43,10 +44,10 @@ describe('React Module Federation', () => { combinedOutput: expect.stringContaining('Test Suites: 1 passed, 1 total'), }); - expect(await readPort(shell)).toEqual(4200); - expect(await readPort(remote1)).toEqual(4201); - expect(await readPort(remote2)).toEqual(4202); - expect(await readPort(remote3)).toEqual(4203); + expect(readPort(shell)).toEqual(4200); + expect(readPort(remote1)).toEqual(4201); + expect(readPort(remote2)).toEqual(4202); + expect(readPort(remote3)).toEqual(4203); updateFile( `apps/${shell}/webpack.config.js`, @@ -61,10 +62,10 @@ describe('React Module Federation', () => { ...baseConfig, remotes: [ '${remote1}', - ['${remote2}', 'http://localhost:${await readPort( + ['${remote2}', 'http://localhost:${readPort( remote2 )}/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( // await killPorts([ - // await readPort(shell), - // await readPort(remote1), - // await readPort(remote2), - // await readPort(remote3), + // readPort(shell), + // readPort(remote1), + // readPort(remote2), + // readPort(remote3), // ]) // ).toBeTruthy(); // } @@ -138,8 +139,8 @@ describe('React Module Federation', () => { expect(buildOutput).toContain('Successfully ran target build'); }, 500_000); - async function readPort(appName: string): Promise { - const config = await readProjectConfig(appName); + function readPort(appName: string): number { + const config = readJson(join('apps', appName, 'project.json')); return config.targets.serve.options.port; } }); diff --git a/e2e/react-core/src/react-package.test.ts b/e2e/react-core/src/react-package.test.ts index c30d5a6788..768c8ce6cf 100644 --- a/e2e/react-core/src/react-package.test.ts +++ b/e2e/react-core/src/react-package.test.ts @@ -14,9 +14,9 @@ import { uniq, updateFile, updateJson, - updateProjectConfig, } from '@nx/e2e/utils'; import { names } from '@nx/devkit'; +import { join } from 'path'; describe('Build React libraries and apps', () => { /** @@ -99,7 +99,7 @@ describe('Build React libraries and apps', () => { ); // 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`]; return json; }); diff --git a/e2e/react-core/src/react.test.ts b/e2e/react-core/src/react.test.ts index cb1fbba78b..b4374a2eea 100644 --- a/e2e/react-core/src/react.test.ts +++ b/e2e/react-core/src/react.test.ts @@ -13,7 +13,6 @@ import { uniq, updateFile, updateJson, - updateProjectConfig, } from '@nx/e2e/utils'; import { readFileSync } from 'fs-extra'; import { join } from 'path'; @@ -289,7 +288,7 @@ describe('React Applications', () => { ); // make sure stylePreprocessorOptions works - await updateProjectConfig(appName, (config) => { + updateJson(join('apps', appName, 'project.json'), (config) => { config.targets.build.options.stylePreprocessorOptions = { includePaths: ['libs/shared/lib'], }; diff --git a/e2e/react-extensions/src/cypress-component-tests.test.ts b/e2e/react-extensions/src/cypress-component-tests.test.ts index a5f61a859f..6824fbdd1d 100644 --- a/e2e/react-extensions/src/cypress-component-tests.test.ts +++ b/e2e/react-extensions/src/cypress-component-tests.test.ts @@ -8,8 +8,8 @@ import { uniq, updateFile, updateJson, - updateProjectConfig, } from '../../utils'; +import { join } from 'path'; describe('React Cypress Component Tests', () => { let projectName; @@ -131,7 +131,7 @@ export default Input; ` ); 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({ glob: '**/*', input: 'libs/assets', @@ -252,7 +252,7 @@ ${content}`; ); ` ); - await updateProjectConfig(appName, (config) => { + updateJson(join('apps', appName, 'project.json'), (config) => { config.targets[ 'build' ].options.webpackConfig = `apps/${appName}/webpack.config.js`; diff --git a/e2e/rollup/src/rollup.test.ts b/e2e/rollup/src/rollup.test.ts index f27c1c0cfd..237fcbfaf2 100644 --- a/e2e/rollup/src/rollup.test.ts +++ b/e2e/rollup/src/rollup.test.ts @@ -8,8 +8,9 @@ import { runCommand, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Rollup Plugin', () => { beforeAll(() => newProject()); @@ -38,7 +39,7 @@ describe('Rollup Plugin', () => { let output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`); expect(output).toMatch(/Hello/); - await updateProjectConfig(myPkg, (config) => { + updateJson(join('libs', myPkg, 'project.json'), (config) => { delete config.targets.build; return config; }); @@ -52,7 +53,7 @@ describe('Rollup Plugin', () => { output = runCommand(`node dist/libs/${myPkg}/index.cjs.js`); expect(output).toMatch(/Hello/); - await updateProjectConfig(myPkg, (config) => { + updateJson(join('libs', myPkg, 'project.json'), (config) => { delete config.targets.build; return config; }); @@ -73,7 +74,7 @@ describe('Rollup Plugin', () => { runCLI( `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.generateExportsField = true; config.targets.build.options.additionalEntryPoints = [ diff --git a/e2e/storybook/src/storybook.test.ts b/e2e/storybook/src/storybook.test.ts index e5bba8f764..a35d6fd8b3 100644 --- a/e2e/storybook/src/storybook.test.ts +++ b/e2e/storybook/src/storybook.test.ts @@ -11,6 +11,7 @@ import { } from '@nx/e2e/utils'; import { writeFileSync } from 'fs'; import { createFileSync } from 'fs-extra'; +import { join } from 'path'; describe('Storybook generators and executors for monorepos', () => { const reactStorybookApp = uniq('react-app'); @@ -20,7 +21,7 @@ describe('Storybook generators and executors for monorepos', () => { runCLI( `generate @nx/react:app ${reactStorybookApp} --bundler=webpack --project-name-and-root-format=as-provided --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers(join(reactStorybookApp, 'project.json')); runCLI( `generate @nx/react:storybook-configuration ${reactStorybookApp} --generateStories --no-interactive --bundler=webpack` ); diff --git a/e2e/utils/command-utils.ts b/e2e/utils/command-utils.ts index 603c0ac662..9f0144e3f8 100644 --- a/e2e/utils/command-utils.ts +++ b/e2e/utils/command-utils.ts @@ -14,11 +14,9 @@ import { TargetConfiguration } from '@nx/devkit'; import { ChildProcess, exec, execSync, ExecSyncOptions } from 'child_process'; import { join } from 'path'; 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 { 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 { silenceError?: boolean; @@ -35,15 +33,9 @@ export interface RunCmdOpts { * * maxWorkers required for: node, web, jest */ -export async function setMaxWorkers() { +export function setMaxWorkers(projectJsonPath: string) { if (isCI) { - const root = tmpProjPath(); - const projects: Record = ( - await retrieveProjectConfigurations(root, readNxJson(root)) - ).projectNodes; - - Object.keys(projects).forEach((appName) => { - let project = projects[appName]; + updateJson(projectJsonPath, (project) => { const { build } = project.targets as { [targetName: string]: TargetConfiguration; }; @@ -61,10 +53,7 @@ export async function setMaxWorkers() { build.options.maxWorkers = 4; } - updateFile( - join(project.root, 'project.json'), - JSON.stringify(project, null, 2) - ); + return project; }); } } diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index 07f20e19af..ea489d8560 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -8,6 +8,5 @@ export * from './create-project-utils'; export * from './file-utils'; export * from './get-env-info'; export * from './log-utils'; -export * from './project-config-utils'; export * from './test-utils'; export * from './process-utils'; diff --git a/e2e/utils/project-config-utils.ts b/e2e/utils/project-config-utils.ts deleted file mode 100644 index 37990e11c2..0000000000 --- a/e2e/utils/project-config-utils.ts +++ /dev/null @@ -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 -> { - process.env.NX_PROJECT_GLOB_CACHE = 'false'; - const root = tmpProjPath(); - return (await retrieveProjectConfigurations(root, readNxJson(root))) - .projectNodes; -} - -export async function readProjectConfig( - projectName: string -): Promise { - const root = (await readResolvedConfiguration())[projectName].root; - const path = join(root, 'project.json'); - return readJson(path); -} diff --git a/e2e/vite/src/vite.test.ts b/e2e/vite/src/vite.test.ts index 925a9104ea..49d3a24912 100644 --- a/e2e/vite/src/vite.test.ts +++ b/e2e/vite/src/vite.test.ts @@ -19,8 +19,9 @@ import { tmpProjPath, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; 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 = [ { 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; return config; }); diff --git a/e2e/web/src/file-server.test.ts b/e2e/web/src/file-server.test.ts index b9ef065200..3befa51433 100644 --- a/e2e/web/src/file-server.test.ts +++ b/e2e/web/src/file-server.test.ts @@ -7,8 +7,9 @@ import { runCommandUntil, setMaxWorkers, uniq, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('file-server', () => { beforeAll(() => { @@ -21,8 +22,8 @@ describe('file-server', () => { const port = 4301; runCLI(`generate @nx/web:app ${appName} --no-interactive`); - await setMaxWorkers(); - await updateProjectConfig(appName, (config) => { + setMaxWorkers(join('apps', appName, 'project.json')); + updateJson(join('apps', appName, 'project.json'), (config) => { config.targets['serve'].executor = '@nx/web:file-server'; return config; }); @@ -58,7 +59,7 @@ describe('file-server', () => { runCLI( `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; diff --git a/e2e/web/src/web-vite.test.ts b/e2e/web/src/web-vite.test.ts index a827310dc1..e5fbe1f7c6 100644 --- a/e2e/web/src/web-vite.test.ts +++ b/e2e/web/src/web-vite.test.ts @@ -12,6 +12,7 @@ import { setMaxWorkers, uniq, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Web Components Applications with bundler set as vite', () => { 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 () => { const appName = uniq('app'); runCLI(`generate @nx/web:app ${appName} --bundler=vite --no-interactive`); - await setMaxWorkers(); + setMaxWorkers(join('apps', appName, 'project.json')); const lintResults = runCLI(`lint ${appName}`); expect(lintResults).toContain('All files pass linting.'); @@ -51,7 +52,7 @@ describe('Web Components Applications with bundler set as vite', () => { runCLI( `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/libs/${libName}/_should_remove.txt`); diff --git a/e2e/web/src/web-webpack.test.ts b/e2e/web/src/web-webpack.test.ts index 569f47a1e2..251971dff7 100644 --- a/e2e/web/src/web-webpack.test.ts +++ b/e2e/web/src/web-webpack.test.ts @@ -6,6 +6,7 @@ import { setMaxWorkers, uniq, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Web Components Applications with bundler set as webpack', () => { beforeEach(() => newProject()); @@ -16,7 +17,7 @@ describe('Web Components Applications with bundler set as webpack', () => { runCLI( `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) => { return output.includes('listening at https://localhost:5000'); diff --git a/e2e/web/src/web.test.ts b/e2e/web/src/web.test.ts index 14cfa32acd..d84f82677d 100644 --- a/e2e/web/src/web.test.ts +++ b/e2e/web/src/web.test.ts @@ -16,7 +16,7 @@ import { tmpProjPath, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; import { join } from 'path'; import { copyFileSync } from 'fs'; @@ -30,7 +30,7 @@ describe('Web Components Applications', () => { runCLI( `generate @nx/web:app ${appName} --bundler=webpack --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', appName, 'project.json')); const lintResults = runCLI(`lint ${appName}`); expect(lintResults).toContain('All files pass linting.'); @@ -105,7 +105,7 @@ describe('Web Components Applications', () => { runCLI( `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`); @@ -131,7 +131,7 @@ describe('Web Components Applications', () => { runCLI( `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/libs/${libName}/_should_remove.txt`); @@ -168,7 +168,7 @@ describe('Web Components Applications', () => { runCLI( `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) => { const newContent = `${content} @@ -224,7 +224,7 @@ describe('Web Components Applications', () => { runCLI( `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) => { const newContent = `${content} @@ -267,9 +267,9 @@ describe('Web Components Applications', () => { runCLI( `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`; return config; }); @@ -388,7 +388,7 @@ describe('CLI - Environment Variables', () => { runCLI( `generate @nx/web:app ${appName} --bundler=webpack --no-interactive --compiler=babel` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', appName, 'project.json')); const content = readFile(main); @@ -414,7 +414,7 @@ describe('CLI - Environment Variables', () => { runCLI( `generate @nx/web:app ${appName2} --bundler=webpack --no-interactive --compiler=babel` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', appName2, 'project.json')); const content2 = readFile(main2); @@ -449,7 +449,7 @@ describe('Build Options', () => { runCLI( `generate @nx/web:app ${appName} --bundler=webpack --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', appName, 'project.json')); const srcPath = `apps/${appName}/src`; const fooCss = `${srcPath}/foo.css`; @@ -475,7 +475,7 @@ describe('Build Options', () => { const barScriptsBundleName = 'bar-scripts'; const barStylesBundleName = 'bar-styles'; - await updateProjectConfig(appName, (config) => { + updateJson(join('apps', appName, 'project.json'), (config) => { const buildOptions = config.targets.build.options; buildOptions.scripts = [ @@ -529,7 +529,7 @@ describe('index.html interpolation', () => { runCLI( `generate @nx/web:app ${appName} --bundler=webpack --no-interactive` ); - await setMaxWorkers(); + setMaxWorkers(join('apps', appName, 'project.json')); const srcPath = `apps/${appName}/src`; const indexPath = `${srcPath}/index.html`; @@ -562,7 +562,7 @@ describe('index.html interpolation', () => { updateFile(envFilePath, envFileContents); updateFile(indexPath, indexContent); - await updateProjectConfig(appName, (config) => { + updateJson(join('apps', appName, 'project.json'), (config) => { const buildOptions = config.targets.build.options; buildOptions.deployUrl = 'baz'; return config; diff --git a/e2e/webpack/src/webpack.test.ts b/e2e/webpack/src/webpack.test.ts index 4a28c276cb..d26bc1f19d 100644 --- a/e2e/webpack/src/webpack.test.ts +++ b/e2e/webpack/src/webpack.test.ts @@ -6,8 +6,9 @@ import { runCommand, uniq, updateFile, - updateProjectConfig, + updateJson, } from '@nx/e2e/utils'; +import { join } from 'path'; describe('Webpack Plugin', () => { beforeEach(() => newProject()); @@ -45,7 +46,7 @@ module.exports = composePlugins(withNx(), (config) => { expect(output).not.toMatch(/Conflicting/); expect(output).not.toMatch(/process.env.NODE_ENV/); - await updateProjectConfig(myPkg, (config) => { + updateJson(join('libs', myPkg, 'project.json'), (config) => { delete config.targets.build; return config; }); @@ -59,7 +60,7 @@ module.exports = composePlugins(withNx(), (config) => { output = runCommand(`node dist/libs/${myPkg}/main.js`); expect(output).toMatch(/Hello/); - await updateProjectConfig(myPkg, (config) => { + updateJson(join('libs', myPkg, 'project.json'), (config) => { delete config.targets.build; return config; });