diff --git a/docs/generated/cli/add.md b/docs/generated/cli/add.md index cc8e3592343708..40b53cd2e18c5b 100644 --- a/docs/generated/cli/add.md +++ b/docs/generated/cli/add.md @@ -53,7 +53,7 @@ The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) t Type: `boolean` -Update `package.json` scripts with inferred targets. Defaults to `true` when `NX_PCV3=true` and the package is a core Nx plugin +Update `package.json` scripts with inferred targets. Defaults to `true` when the package is a core Nx plugin ### verbose diff --git a/docs/generated/cli/init.md b/docs/generated/cli/init.md index f7489013bb241d..c56f35d2750665 100644 --- a/docs/generated/cli/init.md +++ b/docs/generated/cli/init.md @@ -17,36 +17,12 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npx nx` ## Options -### addE2e - -Type: `boolean` - -Default: `false` - -Set up Cypress E2E tests in integrated workspaces. Only for CRA projects. - -### force - -Type: `boolean` - -Default: `false` - -Force the migration to continue and ignore custom webpack setup or uncommitted changes. Only for CRA projects. - ### help Type: `boolean` Show help -### integrated - -Type: `boolean` - -Default: `false` - -Migrate to an Nx integrated layout workspace. Only for Angular CLI workspaces and CRA projects. - ### interactive Type: `boolean` @@ -59,7 +35,7 @@ When false disables interactive input prompts for options. Type: `boolean` -Set up remote caching with Nx Cloud. +Set up distributed caching with Nx Cloud. ### useDotNxInstallation @@ -74,11 +50,3 @@ Initialize an Nx workspace setup in the .nx directory of the current repository. Type: `boolean` Show version number - -### vite - -Type: `boolean` - -Default: `true` - -Use Vite as the bundler. Only for CRA projects. diff --git a/docs/generated/packages/nx/documents/add.md b/docs/generated/packages/nx/documents/add.md index cc8e3592343708..40b53cd2e18c5b 100644 --- a/docs/generated/packages/nx/documents/add.md +++ b/docs/generated/packages/nx/documents/add.md @@ -53,7 +53,7 @@ The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) t Type: `boolean` -Update `package.json` scripts with inferred targets. Defaults to `true` when `NX_PCV3=true` and the package is a core Nx plugin +Update `package.json` scripts with inferred targets. Defaults to `true` when the package is a core Nx plugin ### verbose diff --git a/docs/generated/packages/nx/documents/init.md b/docs/generated/packages/nx/documents/init.md index f7489013bb241d..c56f35d2750665 100644 --- a/docs/generated/packages/nx/documents/init.md +++ b/docs/generated/packages/nx/documents/init.md @@ -17,36 +17,12 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npx nx` ## Options -### addE2e - -Type: `boolean` - -Default: `false` - -Set up Cypress E2E tests in integrated workspaces. Only for CRA projects. - -### force - -Type: `boolean` - -Default: `false` - -Force the migration to continue and ignore custom webpack setup or uncommitted changes. Only for CRA projects. - ### help Type: `boolean` Show help -### integrated - -Type: `boolean` - -Default: `false` - -Migrate to an Nx integrated layout workspace. Only for Angular CLI workspaces and CRA projects. - ### interactive Type: `boolean` @@ -59,7 +35,7 @@ When false disables interactive input prompts for options. Type: `boolean` -Set up remote caching with Nx Cloud. +Set up distributed caching with Nx Cloud. ### useDotNxInstallation @@ -74,11 +50,3 @@ Initialize an Nx workspace setup in the .nx directory of the current repository. Type: `boolean` Show version number - -### vite - -Type: `boolean` - -Default: `true` - -Use Vite as the bundler. Only for CRA projects. diff --git a/e2e/detox/src/detox-pcv3.test.ts b/e2e/detox/src/detox-legacy.test.ts similarity index 95% rename from e2e/detox/src/detox-pcv3.test.ts rename to e2e/detox/src/detox-legacy.test.ts index 2b8a922931b0b4..036975d46cfef4 100644 --- a/e2e/detox/src/detox-pcv3.test.ts +++ b/e2e/detox/src/detox-legacy.test.ts @@ -7,7 +7,7 @@ import { updateJson, } from 'e2e/utils'; -describe('@nx/detox/plugin', () => { +describe('@nx/detox (legacy)', () => { let project: string; let appName: string; @@ -16,7 +16,7 @@ describe('@nx/detox/plugin', () => { appName = uniq('app'); runCLI( `generate @nx/react-native:app ${appName} --e2eTestRunner=detox --install=false --project-name-and-root-format=as-provided --interactive=false`, - { env: { NX_PCV3: 'true' } } + { env: { NX_ADD_PLUGINS: 'false' } } ); updateJson(`${appName}-e2e/.detoxrc.json`, (json) => { json.apps['e2e.debug'] = { diff --git a/e2e/eslint/src/linter.test.ts b/e2e/eslint/src/linter.test.ts index c6a5b664a667c2..e44bdcd3296c32 100644 --- a/e2e/eslint/src/linter.test.ts +++ b/e2e/eslint/src/linter.test.ts @@ -790,10 +790,10 @@ describe('Linter', () => { }); }); - it('should lint example app', () => { + it('should lint example app (legacy)', () => { runCLI( `generate @nx/react:app ${myapp} --directory apps/${myapp} --unitTestRunner=none --bundler=vite --e2eTestRunner=cypress --style=css --no-interactive --projectNameAndRootFormat=as-provided`, - { env: { NX_PCV3: 'true' } } + { env: { NX_ADD_PLUGINS: 'false' } } ); let lintResults = runCLI(`lint ${myapp}`); diff --git a/e2e/expo/src/expo-pcv3.test.ts b/e2e/expo/src/expo-pcv3.test.ts index d688f51e3bcb0d..a1f85afb629e64 100644 --- a/e2e/expo/src/expo-pcv3.test.ts +++ b/e2e/expo/src/expo-pcv3.test.ts @@ -13,7 +13,7 @@ import { } from 'e2e/utils'; import { join } from 'path'; -describe('@nx/expo/plugin', () => { +describe('@nx/expo (legacy)', () => { let project: string; let appName: string; @@ -22,7 +22,7 @@ describe('@nx/expo/plugin', () => { appName = uniq('app'); runCLI( `generate @nx/expo:app ${appName} --project-name-and-root-format=as-provided --no-interactive`, - { env: { NX_PCV3: 'true' } } + { env: { NX_ADD_PLUGINS: 'false' } } ); }); diff --git a/e2e/next-core/src/next-pcv3.test.ts b/e2e/next-core/src/next-legacy.test.ts similarity index 93% rename from e2e/next-core/src/next-pcv3.test.ts rename to e2e/next-core/src/next-legacy.test.ts index 0ee191908ed3bd..96047f7778d477 100644 --- a/e2e/next-core/src/next-pcv3.test.ts +++ b/e2e/next-core/src/next-legacy.test.ts @@ -12,7 +12,7 @@ import { createFile, } from 'e2e/utils'; -describe('@nx/next/plugin', () => { +describe('@nx/next (legacy)', () => { let project: string; let appName: string; @@ -23,7 +23,7 @@ describe('@nx/next/plugin', () => { appName = uniq('app'); runCLI( `generate @nx/next:app ${appName} --project-name-and-root-format=as-provided --no-interactive`, - { env: { NX_PCV3: 'true' } } + { env: { NX_ADD_PLUGINS: 'false' } } ); // update package.json to add next as a script @@ -50,7 +50,7 @@ describe('@nx/next/plugin', () => { it('should build the app', async () => { const result = runCLI(`build ${appName}`); - // check build output for PCV3 artifacts (e.g. .next directory) are inside the project directory + // check build output for cached artifacts (e.g. .next directory) are inside the project directory directoryExists(`${appName}/.next`); expect(result).toContain( diff --git a/e2e/playwright/src/playwright.test.ts b/e2e/playwright/src/playwright.test.ts index 3a2a7e86ac1866..f4639fd72613dc 100644 --- a/e2e/playwright/src/playwright.test.ts +++ b/e2e/playwright/src/playwright.test.ts @@ -69,23 +69,23 @@ describe('Playwright E2E Test runner', () => { ); }); -describe('Playwright E2E Test Runner - PCV3', () => { +describe('Playwright E2E Test Runner - legacy', () => { let env: string | undefined; beforeAll(() => { - env = process.env.NX_PCV3; + env = process.env.NX_ADD_PLUGINS; newProject({ name: uniq('playwright'), unsetProjectNameAndRootFormat: false, }); - process.env.NX_PCV3 = 'true'; + process.env.NX_ADD_PLUGINS = 'false'; }); afterAll(() => { if (env) { - process.env.NX_PCV3 = env; + process.env.NX_ADD_PLUGINS = env; } else { - delete process.env.NX_PCV3; + delete process.env.NX_ADD_PLUGINS; } }); diff --git a/e2e/react-native/src/react-native-pcv3.test.ts b/e2e/react-native/src/react-native-legacy.test.ts similarity index 72% rename from e2e/react-native/src/react-native-pcv3.test.ts rename to e2e/react-native/src/react-native-legacy.test.ts index bdc4993ac2a790..49dec5e5c94a93 100644 --- a/e2e/react-native/src/react-native-pcv3.test.ts +++ b/e2e/react-native/src/react-native-legacy.test.ts @@ -10,7 +10,7 @@ import { fileExists, } from 'e2e/utils'; -describe('@nx/react-native/plugin', () => { +describe('@nx/react-native (legacy)', () => { let appName: string; beforeAll(() => { @@ -18,23 +18,12 @@ describe('@nx/react-native/plugin', () => { appName = uniq('app'); runCLI( `generate @nx/react-native:app ${appName} --project-name-and-root-format=as-provided --install=false --no-interactive`, - { env: { NX_PCV3: 'true' } } + { env: { NX_ADD_PLUGINS: 'false' } } ); }); afterAll(() => cleanupProject()); - it('nx.json should contain plugin configuration', () => { - const nxJson = readJson('nx.json'); - const reactNativePlugin = nxJson.plugins.find( - (plugin) => plugin.plugin === '@nx/react-native/plugin' - ); - expect(reactNativePlugin).toBeDefined(); - expect(reactNativePlugin.options).toBeDefined(); - expect(reactNativePlugin.options.bundleTargetName).toEqual('bundle'); - expect(reactNativePlugin.options.startTargetName).toEqual('start'); - }); - it('should bundle the app', async () => { const result = runCLI( `bundle ${appName} --platform=ios --bundle-output=dist.js --entry-file=src/main.tsx` diff --git a/e2e/utils/get-env-info.ts b/e2e/utils/get-env-info.ts index cb834febdb1cbd..4798c1f717fdcb 100644 --- a/e2e/utils/get-env-info.ts +++ b/e2e/utils/get-env-info.ts @@ -157,7 +157,7 @@ export function getStrippedEnvironmentVariables() { return true; } - const allowedKeys = ['NX_PCV3']; + const allowedKeys = ['NX_ADD_PLUGINS']; if (key.startsWith('NX_') && !allowedKeys.includes(key)) { return false; diff --git a/e2e/vite/src/vite-pcv3.test.ts b/e2e/vite/src/vite-legacy.test.ts similarity index 94% rename from e2e/vite/src/vite-pcv3.test.ts rename to e2e/vite/src/vite-legacy.test.ts index 358c1603b35c41..0e9e028a49e870 100644 --- a/e2e/vite/src/vite-pcv3.test.ts +++ b/e2e/vite/src/vite-legacy.test.ts @@ -18,8 +18,8 @@ describe('@nx/vite/plugin', () => { describe('with react', () => { beforeAll(() => { - originalEnv = process.env.NX_PCV3; - process.env.NX_PCV3 = 'true'; + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; proj = newProject({ packages: ['@nx/react', '@nx/vue'], }); @@ -83,8 +83,8 @@ describe('@nx/vite/plugin', () => { const reactVitest = uniq('reactVitest'); beforeAll(() => { - originalEnv = process.env.NX_PCV3; - process.env.NX_PCV3 = 'true'; + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; proj = newProject({ packages: ['@nx/vite', '@nx/react'], }); diff --git a/e2e/webpack/src/webpack.pcv3.test.ts b/e2e/webpack/src/webpack.legacy.test.ts similarity index 86% rename from e2e/webpack/src/webpack.pcv3.test.ts rename to e2e/webpack/src/webpack.legacy.test.ts index 7c63be3ced7c41..ecc9f52f2117da 100644 --- a/e2e/webpack/src/webpack.pcv3.test.ts +++ b/e2e/webpack/src/webpack.legacy.test.ts @@ -8,14 +8,14 @@ import { } from '@nx/e2e/utils'; import { ChildProcess } from 'child_process'; -describe('Webpack Plugin (PCv3)', () => { - let originalPcv3: string | undefined; +describe('Webpack Plugin (legacy)', () => { + let originalAddPluginsEnv: string | undefined; const appName = uniq('app'); const libName = uniq('lib'); beforeAll(() => { - originalPcv3 = process.env.NX_PCV3; - process.env.NX_PCV3 = 'true'; + originalAddPluginsEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; newProject({ packages: ['@nx/react'], unsetProjectNameAndRootFormat: false, @@ -29,7 +29,7 @@ describe('Webpack Plugin (PCv3)', () => { }); afterAll(() => { - process.env.NX_PCV3 = originalPcv3; + process.env.NX_ADD_PLUGINS = originalAddPluginsEnv; cleanupProject(); }); diff --git a/packages/angular/src/generators/add-linting/add-linting.spec.ts b/packages/angular/src/generators/add-linting/add-linting.spec.ts index 1cd3cffdf89573..155022dcd0fa3b 100644 --- a/packages/angular/src/generators/add-linting/add-linting.spec.ts +++ b/packages/angular/src/generators/add-linting/add-linting.spec.ts @@ -1,4 +1,4 @@ -import type { ProjectConfiguration, Tree } from '@nx/devkit'; +import { ProjectConfiguration, readNxJson, Tree } from '@nx/devkit'; import { addProjectConfiguration, readJson, @@ -65,7 +65,7 @@ describe('addLinting generator', () => { expect(eslintConfig).toMatchSnapshot(); }); - it('should update the project with the right lint target configuration', async () => { + it('should add @nx/eslint/plugin', async () => { await addLintingGenerator(tree, { prefix: 'myOrg', projectName: appProjectName, @@ -73,9 +73,15 @@ describe('addLinting generator', () => { skipFormat: true, }); - const project = readProjectConfiguration(tree, appProjectName); - expect(project.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); + const nxJson = readNxJson(tree); + expect( + nxJson.plugins.find((p) => { + if (typeof p === 'string') { + return p === '@nx/eslint/plugin'; + } else { + return p.plugin === '@nx/eslint/plugin'; + } + }) + ).toBeTruthy(); }); }); diff --git a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap index 072f5e11f8e213..0710122358fe2d 100644 --- a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap @@ -268,9 +268,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh "buildTarget": "my-dir-my-app:build", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, "serve": { "configurations": { "development": { @@ -290,15 +287,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh "staticFilePath": "dist/apps/my-dir/my-app/browser", }, }, - "test": { - "executor": "@nx/jest:jest", - "options": { - "jestConfig": "apps/my-dir/my-app/jest.config.ts", - }, - "outputs": [ - "{workspaceRoot}/coverage/{projectRoot}", - ], - }, }, } `; @@ -331,9 +319,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh "testingType": "e2e", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, }, } `; @@ -487,9 +472,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh "buildTarget": "my-app:build", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, "serve": { "configurations": { "development": { @@ -509,15 +491,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh "staticFilePath": "dist/apps/my-app/browser", }, }, - "test": { - "executor": "@nx/jest:jest", - "options": { - "jestConfig": "apps/my-app/jest.config.ts", - }, - "outputs": [ - "{workspaceRoot}/coverage/{projectRoot}", - ], - }, }, } `; @@ -550,9 +523,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh "testingType": "e2e", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, }, } `; @@ -1001,9 +971,6 @@ exports[`app nested should create project configs 1`] = ` "buildTarget": "my-app:build", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, "serve": { "configurations": { "development": { @@ -1023,15 +990,6 @@ exports[`app nested should create project configs 1`] = ` "staticFilePath": "dist/my-dir/my-app/browser", }, }, - "test": { - "executor": "@nx/jest:jest", - "options": { - "jestConfig": "my-dir/my-app/jest.config.ts", - }, - "outputs": [ - "{workspaceRoot}/coverage/{projectRoot}", - ], - }, }, } `; @@ -1064,9 +1022,6 @@ exports[`app nested should create project configs 2`] = ` "testingType": "e2e", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, }, } `; @@ -1133,9 +1088,6 @@ exports[`app not nested should create project configs 1`] = ` "buildTarget": "my-app:build", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, "serve": { "configurations": { "development": { @@ -1155,15 +1107,6 @@ exports[`app not nested should create project configs 1`] = ` "staticFilePath": "dist/my-app/browser", }, }, - "test": { - "executor": "@nx/jest:jest", - "options": { - "jestConfig": "my-app/jest.config.ts", - }, - "outputs": [ - "{workspaceRoot}/coverage/{projectRoot}", - ], - }, }, } `; @@ -1196,9 +1139,6 @@ exports[`app not nested should create project configs 2`] = ` "testingType": "e2e", }, }, - "lint": { - "executor": "@nx/eslint:lint", - }, }, } `; diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index 89b1bfb50d400b..2d1bef25f6977e 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -176,10 +176,6 @@ describe('app', () => { expect( appTree.exists('playwright-app-e2e/src/example.spec.ts') ).toBeTruthy(); - expect( - readProjectConfiguration(appTree, 'playwright-app-e2e')?.targets?.e2e - ?.executor - ).toEqual('@nx/playwright:playwright'); }); it('should setup jest with serializers', async () => { @@ -536,18 +532,12 @@ describe('app', () => { describe('eslint', () => { it('should add lint target', async () => { await generateApp(appTree, 'my-app', { linter: Linter.EsLint }); - expect(readProjectConfiguration(appTree, 'my-app').targets.lint) - .toMatchInlineSnapshot(` - { - "executor": "@nx/eslint:lint", - } - `); - expect(readProjectConfiguration(appTree, 'my-app-e2e').targets.lint) - .toMatchInlineSnapshot(` - { - "executor": "@nx/eslint:lint", - } - `); + expect( + readProjectConfiguration(appTree, 'my-app').targets.lint + ).toMatchInlineSnapshot(`undefined`); + expect( + readProjectConfiguration(appTree, 'my-app-e2e').targets.lint + ).toMatchInlineSnapshot(`undefined`); }); it('should add valid eslint JSON configuration which extends from Nx presets', async () => { @@ -882,9 +872,6 @@ describe('app', () => { e2eTestRunner: E2eTestRunner.Playwright, rootProject: true, }); - expect( - readProjectConfiguration(appTree, 'e2e').targets.e2e.executor - ).toEqual('@nx/playwright:playwright'); expect(appTree.exists('e2e/playwright.config.ts')).toBeTruthy(); expect(appTree.exists('e2e/src/example.spec.ts')).toBeTruthy(); }); diff --git a/packages/angular/src/generators/library/library.spec.ts b/packages/angular/src/generators/library/library.spec.ts index 918735a309340f..49ee4808a02f13 100644 --- a/packages/angular/src/generators/library/library.spec.ts +++ b/packages/angular/src/generators/library/library.spec.ts @@ -1172,19 +1172,6 @@ describe('lib', () => { describe('--linter', () => { describe('eslint', () => { - it('should add a lint target', async () => { - // ACT - await runLibraryGeneratorWithOpts({ linter: Linter.EsLint }); - - // ASSERT - expect(readProjectConfiguration(tree, 'my-lib').targets['lint']) - .toMatchInlineSnapshot(` - { - "executor": "@nx/eslint:lint", - } - `); - }); - it('should add valid eslint JSON configuration which extends from Nx presets', async () => { // ACT await runLibraryGeneratorWithOpts({ linter: Linter.EsLint }); diff --git a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap index 0a05e6f56a312a..1c3ec92a0748bd 100644 --- a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap +++ b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap @@ -99,16 +99,15 @@ exports[`workspace move to nx layout should create nx.json 1`] = ` ], "sharedGlobals": [], }, - "targetDefaults": { - "@nx/eslint:lint": { - "cache": true, - "inputs": [ - "default", - "{workspaceRoot}/.eslintrc.json", - "{workspaceRoot}/.eslintignore", - "{workspaceRoot}/eslint.config.js", - ], + "plugins": [ + { + "options": { + "targetName": "lint", + }, + "plugin": "@nx/eslint/plugin", }, + ], + "targetDefaults": { "build": { "cache": true, "dependsOn": [ diff --git a/packages/angular/src/generators/ng-add/migrators/projects/e2e.migrator.spec.ts b/packages/angular/src/generators/ng-add/migrators/projects/e2e.migrator.spec.ts index df84c4ab2716dc..a136262d2e0615 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/e2e.migrator.spec.ts +++ b/packages/angular/src/generators/ng-add/migrators/projects/e2e.migrator.spec.ts @@ -468,8 +468,7 @@ describe('e2e migrator', () => { await migrator.migrate(); - const appProject = readProjectConfiguration(tree, 'app1-e2e'); - expect(appProject.targets.lint).toBeTruthy(); + expect(tree.exists('apps/app1-e2e/.eslintrc.json')).toBe(true); }); it('should not add a lint target when the application is not using it', async () => { @@ -701,8 +700,7 @@ describe('e2e migrator', () => { await migrator.migrate(); - const e2eProject = readProjectConfiguration(tree, 'app1-e2e'); - expect(e2eProject.targets.lint).toBeTruthy(); + expect(tree.exists('apps/app1-e2e/.eslintrc.json')).toBe(true); }); it('should not add a lint target when the application is not using it', async () => { diff --git a/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts b/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts index 5da3ccf68b663e..3d8b78a908fb1a 100644 --- a/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts +++ b/packages/angular/src/migrations/update-15-9-0/update-testing-tsconfig.spec.ts @@ -33,6 +33,16 @@ describe('Jest+Ng - 15.9.0 - tsconfig updates', () => { }; }); + let originalEnv: string; + beforeEach(() => { + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; + }); + + afterEach(() => { + process.env.NX_ADD_PLUGINS = originalEnv; + }); + it('should update tsconfig.spec.json with target es2016', async () => { await setup(tree, 'proj'); await updateTestingTsconfigForJest(tree); diff --git a/packages/cypress/src/generators/component-configuration/component-configuration.spec.ts b/packages/cypress/src/generators/component-configuration/component-configuration.spec.ts index 1cbe90f6359cb7..4d0ac3b03aa3cf 100644 --- a/packages/cypress/src/generators/component-configuration/component-configuration.spec.ts +++ b/packages/cypress/src/generators/component-configuration/component-configuration.spec.ts @@ -99,7 +99,6 @@ describe('Cypress Component Configuration', () => { }); it('should not add the target when @nx/cypress/plugin is registered', async () => { - process.env.NX_PCV3 = 'true'; await cypressInitGenerator(tree, {}); const nxJson = readNxJson(tree); nxJson.namedInputs = { @@ -125,8 +124,6 @@ describe('Cypress Component Configuration', () => { "!{projectRoot}/cypress.config.[jt]s", ] `); - - delete process.env.NX_PCV3; }); it('should add base cypress component testing config', async () => { diff --git a/packages/cypress/src/generators/configuration/configuration.spec.ts b/packages/cypress/src/generators/configuration/configuration.spec.ts index 7d411ebba82c12..e54c4b6686617b 100644 --- a/packages/cypress/src/generators/configuration/configuration.spec.ts +++ b/packages/cypress/src/generators/configuration/configuration.spec.ts @@ -35,7 +35,6 @@ describe('Cypress e2e configuration', () => { }); it('should add web server commands to the cypress config when the @nx/cypress/plugin is present', async () => { - process.env.NX_PCV3 = 'true'; await cypressInitGenerator(tree, {}); addProject(tree, { name: 'my-app', type: 'apps' }); @@ -99,7 +98,6 @@ describe('Cypress e2e configuration', () => { } `); assertCypressFiles(tree, 'apps/my-app/src'); - delete process.env.NX_PCV3; }); it('should add e2e target to existing app', async () => { diff --git a/packages/cypress/src/generators/init/init.spec.ts b/packages/cypress/src/generators/init/init.spec.ts index 996623a54393e9..63929c3b3b00d4 100644 --- a/packages/cypress/src/generators/init/init.spec.ts +++ b/packages/cypress/src/generators/init/init.spec.ts @@ -49,7 +49,6 @@ describe('init', () => { }); it('should setup @nx/cypress/plugin', async () => { - process.env.NX_PCV3 = 'true'; updateJson(tree, 'nx.json', (json) => { json.namedInputs ??= {}; json.namedInputs.production = ['default']; @@ -91,7 +90,5 @@ describe('init', () => { }, } `); - - delete process.env.NX_PCV3; }); }); diff --git a/packages/cypress/src/generators/init/init.ts b/packages/cypress/src/generators/init/init.ts index 5d427c8d3bd4e5..58ae4c984ef210 100644 --- a/packages/cypress/src/generators/init/init.ts +++ b/packages/cypress/src/generators/init/init.ts @@ -99,7 +99,7 @@ function updateProductionFileset(tree: Tree) { export async function cypressInitGenerator(tree: Tree, options: Schema) { updateProductionFileset(tree); - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(tree); } else { setupE2ETargetDefaults(tree); diff --git a/packages/detox/src/generators/application/lib/add-linting.spec.ts b/packages/detox/src/generators/application/lib/add-linting.spec.ts index c049bdd38fe474..a7a818d1164751 100644 --- a/packages/detox/src/generators/application/lib/add-linting.spec.ts +++ b/packages/detox/src/generators/application/lib/add-linting.spec.ts @@ -38,10 +38,8 @@ describe('Add Linting', () => { linter: Linter.EsLint, framework: 'react-native', }); - const project = readProjectConfiguration(tree, 'my-app-e2e'); - expect(project.targets.lint).toBeDefined(); - expect(project.targets.lint.executor).toEqual('@nx/eslint:lint'); + expect(tree.exists('apps/my-app-e2e/.eslintrc.json')).toBeTruthy(); }); it('should not add lint target when "none" is passed', async () => { diff --git a/packages/detox/src/generators/init/init.ts b/packages/detox/src/generators/init/init.ts index cfa8cd08774193..96cc345a56e855 100644 --- a/packages/detox/src/generators/init/init.ts +++ b/packages/detox/src/generators/init/init.ts @@ -21,7 +21,7 @@ export async function detoxInitGenerator(host: Tree, schema: Schema) { tasks.push(updateDependencies(host, schema)); } - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(host); } diff --git a/packages/eslint/src/generators/init/init.spec.ts b/packages/eslint/src/generators/init/init.spec.ts index 60b8ef8d68d1ff..9193f8391226a9 100644 --- a/packages/eslint/src/generators/init/init.spec.ts +++ b/packages/eslint/src/generators/init/init.spec.ts @@ -1,21 +1,14 @@ -import { Linter } from '../utils/linter'; import { NxJsonConfiguration, readJson, Tree, updateJson } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { lintInitGenerator } from './init'; describe('@nx/eslint:init', () => { let tree: Tree; - let envV3: string | undefined; beforeEach(() => { - envV3 = process.env.NX_PCV3; tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); - afterEach(() => { - process.env.NX_PCV3 = envV3; - }); - it('should add the root eslint config to the lint targetDefaults for lint', async () => { await lintInitGenerator(tree, {}); @@ -65,7 +58,6 @@ describe('@nx/eslint:init', () => { }); it('should setup @nx/eslint/plugin', async () => { - process.env.NX_PCV3 = 'true'; updateJson(tree, 'nx.json', (json) => { json.namedInputs ??= {}; json.namedInputs.production = ['default']; @@ -104,7 +96,6 @@ describe('@nx/eslint:init', () => { readJson(tree, 'nx.json').plugins ).not.toBeDefined(); - process.env.NX_PCV3 = 'true'; lintInitGenerator(tree, {}); expect(readJson(tree, 'nx.json').plugins) .toMatchInlineSnapshot(` diff --git a/packages/eslint/src/generators/init/init.ts b/packages/eslint/src/generators/init/init.ts index a2f03f7fe2f972..cee25a46218ce6 100644 --- a/packages/eslint/src/generators/init/init.ts +++ b/packages/eslint/src/generators/init/init.ts @@ -73,7 +73,7 @@ async function initEsLint( tree: Tree, options: LinterInitOptions ): Promise { - const addPlugins = process.env.NX_PCV3 === 'true'; + const addPlugins = process.env.NX_ADD_PLUGINS !== 'false'; const hasPlugin = hasEslintPlugin(tree); const rootEslintFile = findEslintFile(tree); diff --git a/packages/expo/src/generators/init/init.ts b/packages/expo/src/generators/init/init.ts index 3f0425a14c375f..eb4b63261f3760 100644 --- a/packages/expo/src/generators/init/init.ts +++ b/packages/expo/src/generators/init/init.ts @@ -26,7 +26,7 @@ import { Schema } from './schema'; export async function expoInitGenerator(host: Tree, schema: Schema) { addGitIgnoreEntry(host); - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(host); } diff --git a/packages/expo/src/generators/library/library.spec.ts b/packages/expo/src/generators/library/library.spec.ts index f4c0549aa8ef3c..106b5f9c957e08 100644 --- a/packages/expo/src/generators/library/library.spec.ts +++ b/packages/expo/src/generators/library/library.spec.ts @@ -37,12 +37,20 @@ describe('lib', () => { tags: 'one,two', }); const projectConfiguration = readProjectConfiguration(appTree, 'my-lib'); - expect(projectConfiguration.root).toEqual('my-lib'); - expect(projectConfiguration.targets.build).toBeUndefined(); - expect(projectConfiguration.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); - expect(projectConfiguration.tags).toEqual(['one', 'two']); + expect(projectConfiguration).toMatchInlineSnapshot(` + { + "$schema": "../node_modules/nx/schemas/project-schema.json", + "name": "my-lib", + "projectType": "library", + "root": "my-lib", + "sourceRoot": "my-lib/src", + "tags": [ + "one", + "two", + ], + "targets": {}, + } + `); }); it('should update tsconfig.base.json', async () => { @@ -144,9 +152,17 @@ describe('lib', () => { appTree, 'my-dir-my-lib' ); - expect(projectConfiguration.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); + expect(projectConfiguration).toMatchInlineSnapshot(` + { + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "name": "my-dir-my-lib", + "projectType": "library", + "root": "my-dir/my-lib", + "sourceRoot": "my-dir/my-lib/src", + "tags": [], + "targets": {}, + } + `); }); it('should update tsconfig.base.json', async () => { @@ -189,10 +205,17 @@ describe('lib', () => { expect(appTree.exists('my-lib/tsconfig.spec.json')).toBeFalsy(); expect(appTree.exists('my-lib/jest.config.ts')).toBeFalsy(); const projectConfiguration = readProjectConfiguration(appTree, 'my-lib'); - expect(projectConfiguration.targets.test).toBeUndefined(); - expect(projectConfiguration.targets.lint).toMatchObject({ - executor: '@nx/eslint:lint', - }); + expect(projectConfiguration).toMatchInlineSnapshot(` + { + "$schema": "../node_modules/nx/schemas/project-schema.json", + "name": "my-lib", + "projectType": "library", + "root": "my-lib", + "sourceRoot": "my-lib/src", + "tags": [], + "targets": {}, + } + `); }); }); diff --git a/packages/expo/src/utils/add-linting.spec.ts b/packages/expo/src/utils/add-linting.spec.ts index 68ad82e24ed63b..6ea01d7da7a9ef 100644 --- a/packages/expo/src/utils/add-linting.spec.ts +++ b/packages/expo/src/utils/add-linting.spec.ts @@ -1,4 +1,4 @@ -import { readProjectConfiguration, Tree } from '@nx/devkit'; +import { Tree } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { Linter } from '@nx/eslint'; import { libraryGenerator } from '@nx/js'; @@ -23,10 +23,8 @@ describe('Add Linting', () => { tsConfigPaths: ['my-lib/tsconfig.lib.json'], projectRoot: 'my-lib', }); - const project = readProjectConfiguration(tree, 'my-lib'); - expect(project.targets.lint).toBeDefined(); - expect(project.targets.lint.executor).toEqual('@nx/eslint:lint'); + expect(tree.exists('my-lib/.eslintrc.json')).toBeTruthy(); }); it('should not add lint target when "none" is passed', async () => { @@ -36,8 +34,7 @@ describe('Add Linting', () => { tsConfigPaths: ['my-lib/tsconfig.lib.json'], projectRoot: 'my-lib', }); - const project = readProjectConfiguration(tree, 'my-lib'); - expect(project.targets.lint).toBeUndefined(); + expect(tree.exists('my-lib/.eslintrc.json')).toBeFalsy(); }); }); diff --git a/packages/jest/src/generators/configuration/__snapshots__/configuration.spec.ts.snap b/packages/jest/src/generators/configuration/__snapshots__/configuration.spec.ts.snap index efae77a3531760..d41f58442b460c 100644 --- a/packages/jest/src/generators/configuration/__snapshots__/configuration.spec.ts.snap +++ b/packages/jest/src/generators/configuration/__snapshots__/configuration.spec.ts.snap @@ -111,15 +111,3 @@ export default { }; " `; - -exports[`jestProject should use jest.config.js in project config with --js flag 1`] = ` -{ - "executor": "@nx/jest:jest", - "options": { - "jestConfig": "libs/lib1/jest.config.js", - }, - "outputs": [ - "{workspaceRoot}/coverage/{projectRoot}", - ], -} -`; diff --git a/packages/jest/src/generators/configuration/configuration.spec.ts b/packages/jest/src/generators/configuration/configuration.spec.ts index 2af6696f8a8b81..ed873a1ab13402 100644 --- a/packages/jest/src/generators/configuration/configuration.spec.ts +++ b/packages/jest/src/generators/configuration/configuration.spec.ts @@ -72,22 +72,6 @@ describe('jestProject', () => { }).not.toThrow(); }); - it('should alter project configuration', async () => { - await configurationGenerator(tree, { - ...defaultOptions, - project: 'lib1', - setupFile: 'angular', - } as JestProjectSchema); - const lib1 = readProjectConfiguration(tree, 'lib1'); - expect(lib1.targets.test).toEqual({ - executor: '@nx/jest:jest', - outputs: ['{workspaceRoot}/coverage/{projectRoot}'], - options: { - jestConfig: 'libs/lib1/jest.config.ts', - }, - }); - }); - it('should create a jest.config.ts', async () => { await configurationGenerator(tree, { ...defaultOptions, @@ -169,16 +153,6 @@ describe('jestProject', () => { expect(jestConfig).toMatchSnapshot(); }); - it('should not list the setup file in project configuration', async () => { - await configurationGenerator(tree, { - ...defaultOptions, - project: 'lib1', - setupFile: 'none', - } as JestProjectSchema); - const lib1 = readProjectConfiguration(tree, 'lib1'); - expect(lib1.targets.test.options.setupFile).toBeUndefined(); - }); - it('should not list the setup file in tsconfig.spec.json', async () => { await configurationGenerator(tree, { ...defaultOptions, @@ -200,16 +174,6 @@ describe('jestProject', () => { expect(tree.exists('src/test-setup.ts')).toBeFalsy(); }); - it('should not list the setup file in project configuration', async () => { - await configurationGenerator(tree, { - ...defaultOptions, - project: 'lib1', - skipSetupFile: true, - } as JestProjectSchema); - const lib1 = readProjectConfiguration(tree, 'lib1'); - expect(lib1.targets.test.options.setupFile).toBeUndefined(); - }); - it('should not list the setup file in tsconfig.spec.json', async () => { await configurationGenerator(tree, { ...defaultOptions, @@ -292,9 +256,6 @@ describe('jestProject', () => { js: true, } as JestProjectSchema); expect(tree.exists('libs/lib1/jest.config.js')).toBeTruthy(); - expect( - readProjectConfiguration(tree, 'lib1').targets['test'] - ).toMatchSnapshot(); }); it('should always use jest.preset.js with --js', async () => { diff --git a/packages/jest/src/generators/init/init.spec.ts b/packages/jest/src/generators/init/init.spec.ts index de753c3cea4f33..32937e334053cb 100644 --- a/packages/jest/src/generators/init/init.spec.ts +++ b/packages/jest/src/generators/init/init.spec.ts @@ -14,7 +14,7 @@ describe('jest', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); - it('should add target defaults for test', async () => { + it('should exclude jest files from production fileset', async () => { updateJson(tree, 'nx.json', (json) => { json.namedInputs ??= {}; json.namedInputs.production = ['default']; @@ -33,19 +33,6 @@ describe('jest', () => { expect(productionFileSet).toContain('!{projectRoot}/tsconfig.spec.json'); expect(productionFileSet).toContain('!{projectRoot}/jest.config.[jt]s'); expect(productionFileSet).toContain('!{projectRoot}/src/test-setup.[jt]s'); - expect(jestDefaults).toEqual({ - cache: true, - inputs: ['default', '^production', '{workspaceRoot}/jest.preset.js'], - options: { - passWithNoTests: true, - }, - configurations: { - ci: { - ci: true, - codeCoverage: true, - }, - }, - }); }); it('should not alter target defaults if jest.preset.js already exists', async () => { diff --git a/packages/jest/src/generators/init/init.ts b/packages/jest/src/generators/init/init.ts index a50f0393f0efed..f718a8876256a4 100644 --- a/packages/jest/src/generators/init/init.ts +++ b/packages/jest/src/generators/init/init.ts @@ -107,7 +107,7 @@ export async function jestInitGenerator( ): Promise { if (!tree.exists('jest.preset.js')) { updateProductionFileSet(tree); - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(tree); } else { addJestTargetDefaults(tree); diff --git a/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts b/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts index f1aa03e9c0d669..fa1877e9b7a51f 100644 --- a/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts +++ b/packages/jest/src/migrations/update-15-8-0/update-configs-jest-29.spec.ts @@ -18,6 +18,16 @@ jest.mock('@nx/devkit', () => ({ describe('Jest Migration - jest 29 update configs', () => { let tree: Tree; + + let originalEnv: string; + beforeEach(() => { + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; + }); + afterEach(() => { + process.env.NX_ADD_PLUGINS = originalEnv; + }); + beforeEach(() => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); diff --git a/packages/js/src/generators/library/__snapshots__/library.spec.ts.snap b/packages/js/src/generators/library/__snapshots__/library.spec.ts.snap index 38fe8a80eec7c7..27233c7556dc09 100644 --- a/packages/js/src/generators/library/__snapshots__/library.spec.ts.snap +++ b/packages/js/src/generators/library/__snapshots__/library.spec.ts.snap @@ -1,6 +1,72 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`lib --bundler=vite should add build and test targets with vite and vitest 1`] = ` +"/// +import { defineConfig } from 'vite'; +import dts from 'vite-plugin-dts'; +import * as path from 'path'; +import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; + +export default defineConfig({ + root: __dirname, + cacheDir: '../node_modules/.vite/my-lib', + + plugins: [ + nxViteTsPaths(), + dts({ + entryRoot: 'src', + tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'), + skipDiagnostics: true, + }), + ], + + // Uncomment this if you are using workers. + // worker: { + // plugins: [ nxViteTsPaths() ], + // }, + + // Configuration for building your library. + // See: https://vitejs.dev/guide/build.html#library-mode + build: { + outDir: '../dist/my-lib', + reportCompressedSize: true, + commonjsOptions: { + transformMixedEsModules: true, + }, + lib: { + // Could also be a dictionary or array of multiple entry points. + entry: 'src/index.ts', + name: 'my-lib', + fileName: 'index', + // Change this to the formats you want to support. + // Don't forget to update your package.json as well. + formats: ['es', 'cjs'], + }, + rollupOptions: { + // External packages that should not be bundled into your library. + external: [], + }, + }, + + test: { + globals: true, + cache: { + dir: '../node_modules/.vitest', + }, + environment: 'jsdom', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + + reporters: ['default'], + coverage: { + reportsDirectory: '../coverage/my-lib', + provider: 'v8', + }, + }, +}); +" +`; + +exports[`lib --bundler=vite should add build and test targets with vite and vitest 2`] = ` "# my-lib This library was generated with [Nx](https://nx.dev). @@ -15,7 +81,7 @@ Run \`nx test my-lib\` to execute the unit tests via [Vitest](https://vitest.dev " `; -exports[`lib --bundler=vite should add build and test targets with vite and vitest 2`] = ` +exports[`lib --bundler=vite should add build and test targets with vite and vitest 3`] = ` "{ "extends": "./tsconfig.json", "compilerOptions": { @@ -83,6 +149,20 @@ exports[`lib --bundler=vite should respect unitTestRunner if passed 4`] = ` " `; +exports[`lib --bundler=vite should respect unitTestRunner if passed 5`] = ` +"/* eslint-disable */ +export default { + displayName: 'my-lib', + preset: '../jest.preset.js', + transform: { + '^.+\\\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../coverage/my-lib', +}; +" +`; + exports[`lib --unit-test-runner jest should generate test configuration with swc and js 1`] = ` "/* eslint-disable */ const { readFileSync } = require('fs'); diff --git a/packages/js/src/generators/library/library.spec.ts b/packages/js/src/generators/library/library.spec.ts index c5b61e93108c6a..51e23626e2907a 100644 --- a/packages/js/src/generators/library/library.spec.ts +++ b/packages/js/src/generators/library/library.spec.ts @@ -487,17 +487,6 @@ describe('lib', () => { }); describe('not nested', () => { - it('should update configuration', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'my-lib', - projectNameAndRootFormat: 'as-provided', - }); - expect(readProjectConfiguration(tree, 'my-lib').targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); - }); - it('should create a local .eslintrc.json', async () => { await libraryGenerator(tree, { ...defaultOptions, @@ -554,19 +543,6 @@ describe('lib', () => { }); describe('nested', () => { - it('should update configuration', async () => { - await libraryGenerator(tree, { - ...defaultOptions, - name: 'my-lib', - directory: 'my-dir/my-lib', - projectNameAndRootFormat: 'as-provided', - }); - - expect(readProjectConfiguration(tree, 'my-lib').targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); - }); - it('should create a local .eslintrc.json', async () => { await libraryGenerator(tree, { ...defaultOptions, @@ -762,9 +738,6 @@ describe('lib', () => { expect(tree.exists('my-lib/jest.config.ts')).toBeTruthy(); expect(tree.exists('my-lib/src/lib/my-lib.spec.ts')).toBeTruthy(); - const projectConfig = readProjectConfiguration(tree, 'my-lib'); - expect(projectConfig.targets.test).toBeDefined(); - expect(tree.exists(`my-lib/jest.config.ts`)).toBeTruthy(); expect(tree.read(`my-lib/jest.config.ts`, 'utf-8')) .toMatchInlineSnapshot(` @@ -798,9 +771,6 @@ describe('lib', () => { expect(tree.exists('my-lib/jest.config.js')).toBeTruthy(); expect(tree.exists('my-lib/src/lib/my-lib.spec.js')).toBeTruthy(); - const projectConfig = readProjectConfiguration(tree, 'my-lib'); - expect(projectConfig.targets.test).toBeDefined(); - expect(tree.exists(`my-lib/jest.config.js`)).toBeTruthy(); expect(tree.read(`my-lib/jest.config.js`, 'utf-8')).toMatchSnapshot(); const readme = tree.read('my-lib/README.md', 'utf-8'); @@ -1171,14 +1141,8 @@ describe('lib', () => { projectNameAndRootFormat: 'as-provided', }); - const project = readProjectConfiguration(tree, 'my-lib'); - expect(project.targets.build).toMatchObject({ - executor: '@nx/vite:build', - }); - expect(project.targets.test).toMatchObject({ - executor: '@nx/vite:test', - }); expect(tree.exists('my-lib/vite.config.ts')).toBeTruthy(); + expect(tree.read('my-lib/vite.config.ts', 'utf-8')).toMatchSnapshot(); expect(tree.read('my-lib/README.md', 'utf-8')).toMatchSnapshot(); expect(tree.read('my-lib/tsconfig.lib.json', 'utf-8')).toMatchSnapshot(); expect(readJson(tree, 'my-lib/.eslintrc.json').overrides).toContainEqual({ @@ -1196,12 +1160,12 @@ describe('lib', () => { }); it.each` - unitTestRunner | executor + unitTestRunner | configPath ${'none'} | ${undefined} - ${'jest'} | ${'@nx/jest:jest'} + ${'jest'} | ${'my-lib/jest.config.ts'} `( 'should respect unitTestRunner if passed', - async ({ unitTestRunner, executor }) => { + async ({ unitTestRunner, configPath }) => { await libraryGenerator(tree, { ...defaultOptions, name: 'my-lib', @@ -1210,12 +1174,13 @@ describe('lib', () => { projectNameAndRootFormat: 'as-provided', }); - const project = readProjectConfiguration(tree, 'my-lib'); - expect(project.targets.test?.executor).toEqual(executor); expect(tree.read('my-lib/README.md', 'utf-8')).toMatchSnapshot(); expect( tree.read('my-lib/tsconfig.lib.json', 'utf-8') ).toMatchSnapshot(); + if (configPath) { + expect(tree.read(configPath, 'utf-8')).toMatchSnapshot(); + } } ); }); diff --git a/packages/js/src/migrations/update-15-8-0/rename-swcrc-config.spec.ts b/packages/js/src/migrations/update-15-8-0/rename-swcrc-config.spec.ts index 4b41010a742b8e..4285e43fcf8a87 100644 --- a/packages/js/src/migrations/update-15-8-0/rename-swcrc-config.spec.ts +++ b/packages/js/src/migrations/update-15-8-0/rename-swcrc-config.spec.ts @@ -10,6 +10,15 @@ import renameSwcrcConfig from './rename-swcrc-config'; describe('Rename swcrc file migration', () => { let tree: Tree; + let originalEnv: string; + beforeEach(() => { + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; + }); + afterEach(() => { + process.env.NX_ADD_PLUGINS = originalEnv; + }); + beforeEach(() => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); diff --git a/packages/next/src/generators/application/application.spec.ts b/packages/next/src/generators/application/application.spec.ts index 6d836461db4846..e8845d28046a55 100644 --- a/packages/next/src/generators/application/application.spec.ts +++ b/packages/next/src/generators/application/application.spec.ts @@ -726,9 +726,9 @@ describe('app', () => { }); }); -describe('app with Project Configuration V3 enabeled', () => { +describe('app (legacy)', () => { let tree: Tree; - let originalPVC3; + let originalEnv; const schema: Schema = { name: 'app', @@ -741,15 +741,15 @@ describe('app with Project Configuration V3 enabeled', () => { beforeAll(() => { tree = createTreeWithEmptyWorkspace(); - originalPVC3 = process.env['NX_PCV3']; - process.env['NX_PCV3'] = 'true'; + originalEnv = process.env['NX_ADD_PLUGINS']; + process.env['NX_ADD_PLUGINS'] = 'false'; }); afterAll(() => { - if (originalPVC3) { - process.env['NX_PCV3'] = originalPVC3; + if (originalEnv) { + process.env['NX_ADD_PLUGINS'] = originalEnv; } else { - delete process.env['NX_PCV3']; + delete process.env['NX_ADD_PLUGINS']; } }); diff --git a/packages/next/src/generators/init/init.ts b/packages/next/src/generators/init/init.ts index 45d9865f156cc8..e0605a6bcf9c09 100644 --- a/packages/next/src/generators/init/init.ts +++ b/packages/next/src/generators/init/init.ts @@ -37,7 +37,7 @@ function updateDependencies(host: Tree, schema: InitSchema) { } export async function nextInitGenerator(host: Tree, schema: InitSchema) { - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(host); } diff --git a/packages/node/src/generators/application/application.legacy.spec.ts b/packages/node/src/generators/application/application.legacy.spec.ts new file mode 100644 index 00000000000000..ade7cbe8513362 --- /dev/null +++ b/packages/node/src/generators/application/application.legacy.spec.ts @@ -0,0 +1,67 @@ +import { + readNxJson, + readProjectConfiguration, + Tree, + updateNxJson, +} from '@nx/devkit'; +import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; + +// nx-ignore-next-line +import { applicationGenerator } from './application'; + +describe('node app generator (legacy)', () => { + let tree: Tree; + let originalEnv: string; + beforeEach(() => { + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; + }); + + afterEach(() => { + process.env.NX_ADD_PLUGINS = originalEnv; + }); + + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + const nxJson = readNxJson(tree); + updateNxJson(tree, nxJson); + }); + + it('should not skip the build target', async () => { + await applicationGenerator(tree, { + name: 'my-node-app', + bundler: 'webpack', + projectNameAndRootFormat: 'as-provided', + }); + const project = readProjectConfiguration(tree, 'my-node-app'); + expect(project.root).toEqual('my-node-app'); + expect(project.targets.build).toMatchInlineSnapshot(` + { + "configurations": { + "development": {}, + "production": {}, + }, + "defaultConfiguration": "production", + "executor": "@nx/webpack:webpack", + "options": { + "assets": [ + "my-node-app/src/assets", + ], + "compiler": "tsc", + "main": "my-node-app/src/main.ts", + "outputPath": "dist/my-node-app", + "target": "node", + "tsConfig": "my-node-app/tsconfig.app.json", + "webpackConfig": "my-node-app/webpack.config.js", + }, + "outputs": [ + "{options.outputPath}", + ], + } + `); + + const webpackConfig = tree.read('my-node-app/webpack.config.js', 'utf-8'); + expect(webpackConfig).toContain(`composePlugins`); + expect(webpackConfig).toContain(`target: 'node'`); + }); +}); diff --git a/packages/node/src/generators/application/application.pcv3.spec.ts b/packages/node/src/generators/application/application.pcv3.spec.ts deleted file mode 100644 index 5ff7a341764074..00000000000000 --- a/packages/node/src/generators/application/application.pcv3.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - readNxJson, - readProjectConfiguration, - Tree, - updateNxJson, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -// nx-ignore-next-line -import { applicationGenerator } from './application'; - -describe('node app generator (PCv3)', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace(); - const nxJson = readNxJson(tree); - nxJson.plugins ??= []; - nxJson.plugins.push('@nx/webpack/plugin'); - updateNxJson(tree, nxJson); - }); - - it('should skip the build target and setup webpack config', async () => { - await applicationGenerator(tree, { - name: 'my-node-app', - bundler: 'webpack', - projectNameAndRootFormat: 'as-provided', - }); - const project = readProjectConfiguration(tree, 'my-node-app'); - expect(project.root).toEqual('my-node-app'); - expect(project.targets.build).toBeUndefined(); - - const webpackConfig = tree.read('my-node-app/webpack.config.js', 'utf-8'); - expect(webpackConfig).toContain(`new NxWebpackPlugin`); - expect(webpackConfig).toContain(`target: 'node'`); - expect(webpackConfig).toContain(`'../dist/my-node-app'`); - expect(webpackConfig).toContain(`main: './src/main.ts'`); - expect(webpackConfig).toContain(`tsConfig: './tsconfig.app.json'`); - }); -}); diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index 1da5f32b1ff2db..503b10218963a7 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -29,47 +29,33 @@ describe('app', () => { projectNameAndRootFormat: 'as-provided', }); const project = readProjectConfiguration(tree, 'my-node-app'); - expect(project.root).toEqual('my-node-app'); - expect(project.targets).toEqual( - expect.objectContaining({ - build: { - executor: '@nx/webpack:webpack', - outputs: ['{options.outputPath}'], - defaultConfiguration: 'production', - options: { - target: 'node', - compiler: 'tsc', - outputPath: 'dist/my-node-app', - main: 'my-node-app/src/main.ts', - tsConfig: 'my-node-app/tsconfig.app.json', - webpackConfig: 'my-node-app/webpack.config.js', - assets: ['my-node-app/src/assets'], - }, - configurations: { - development: {}, - production: {}, - }, - }, - serve: { - executor: '@nx/js:node', - defaultConfiguration: 'development', - options: { - buildTarget: 'my-node-app:build', - }, - configurations: { - development: { - buildTarget: 'my-node-app:build:development', + expect(project).toMatchInlineSnapshot(` + { + "$schema": "../node_modules/nx/schemas/project-schema.json", + "name": "my-node-app", + "projectType": "application", + "root": "my-node-app", + "sourceRoot": "my-node-app/src", + "tags": [], + "targets": { + "serve": { + "configurations": { + "development": { + "buildTarget": "my-node-app:build:development", + }, + "production": { + "buildTarget": "my-node-app:build:production", + }, }, - production: { - buildTarget: 'my-node-app:build:production', + "defaultConfiguration": "development", + "executor": "@nx/js:node", + "options": { + "buildTarget": "my-node-app:build", }, }, }, - }) - ); - expect(project.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); + } + `); expect(() => readProjectConfiguration(tree, 'my-node-app-e2e') ).not.toThrow(); @@ -185,11 +171,71 @@ describe('app', () => { }); const project = readProjectConfiguration(tree, 'my-node-app'); - expect(project.root).toEqual('my-dir/my-node-app'); - - expect(project.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); + expect(project).toMatchInlineSnapshot(` + { + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "name": "my-node-app", + "projectType": "application", + "root": "my-dir/my-node-app", + "sourceRoot": "my-dir/my-node-app/src", + "tags": [], + "targets": { + "build": { + "configurations": { + "development": {}, + "production": { + "esbuildOptions": { + "outExtension": { + ".js": ".js", + }, + "sourcemap": false, + }, + }, + }, + "defaultConfiguration": "production", + "executor": "@nx/esbuild:esbuild", + "options": { + "assets": [ + "my-dir/my-node-app/src/assets", + ], + "bundle": false, + "esbuildOptions": { + "outExtension": { + ".js": ".js", + }, + "sourcemap": true, + }, + "format": [ + "cjs", + ], + "generatePackageJson": true, + "main": "my-dir/my-node-app/src/main.ts", + "outputPath": "dist/my-dir/my-node-app", + "platform": "node", + "tsConfig": "my-dir/my-node-app/tsconfig.app.json", + }, + "outputs": [ + "{options.outputPath}", + ], + }, + "serve": { + "configurations": { + "development": { + "buildTarget": "my-node-app:build:development", + }, + "production": { + "buildTarget": "my-node-app:build:production", + }, + }, + "defaultConfiguration": "development", + "executor": "@nx/js:node", + "options": { + "buildTarget": "my-node-app:build", + }, + }, + }, + } + `); expect(() => readProjectConfiguration(tree, 'my-node-app-e2e') @@ -270,13 +316,6 @@ describe('app', () => { expect(tree.exists('my-node-app/src/test.ts')).toBeFalsy(); expect(tree.exists('my-node-app/tsconfig.spec.json')).toBeFalsy(); expect(tree.exists('my-node-app/jest.config.ts')).toBeFalsy(); - const project = readProjectConfiguration(tree, 'my-node-app'); - expect(project.targets.test).toBeUndefined(); - expect(project.targets.lint).toMatchInlineSnapshot(` - { - "executor": "@nx/eslint:lint", - } - `); }); }); @@ -477,8 +516,7 @@ describe('app', () => { framework, }); - const project = readProjectConfiguration(tree, 'api'); - expect(project.targets.test).toBeDefined(); + expect(tree.exists(`api/jest.config.ts`)).toBeTruthy(); if (checkSpecFile) { expect(tree.exists(`api/src/app/app.spec.ts`)).toBeTruthy(); diff --git a/packages/node/src/generators/library/__snapshots__/library.spec.ts.snap b/packages/node/src/generators/library/__snapshots__/library.spec.ts.snap new file mode 100644 index 00000000000000..969c956e03d7cd --- /dev/null +++ b/packages/node/src/generators/library/__snapshots__/library.spec.ts.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`lib not nested should update configuration 1`] = ` +"/* eslint-disable */ +export default { + displayName: 'my-lib', + preset: '../jest.preset.js', + testEnvironment: 'node', + transform: { + '^.+\\\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../coverage/my-lib', +}; +" +`; diff --git a/packages/node/src/generators/library/library.spec.ts b/packages/node/src/generators/library/library.spec.ts index 42f8a4f1f32953..164da44c54d2f6 100644 --- a/packages/node/src/generators/library/library.spec.ts +++ b/packages/node/src/generators/library/library.spec.ts @@ -28,16 +28,7 @@ describe('lib', () => { const configuration = readProjectConfiguration(tree, 'my-lib'); expect(configuration.root).toEqual('my-lib'); expect(configuration.targets.build).toBeUndefined(); - expect(configuration.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); - expect(configuration.targets.test).toEqual({ - executor: '@nx/jest:jest', - outputs: ['{workspaceRoot}/coverage/{projectRoot}'], - options: { - jestConfig: 'my-lib/jest.config.ts', - }, - }); + expect(tree.read('my-lib/jest.config.ts', 'utf-8')).toMatchSnapshot(); expect( readJson(tree, 'package.json').devDependencies['jest-environment-jsdom'] ).not.toBeDefined(); @@ -209,17 +200,24 @@ describe('lib', () => { expect(tree.exists('my-dir/my-lib/src/index.ts')).toBeTruthy(); }); - it('should update workspace.json', async () => { + it('should update project.json', async () => { await libraryGenerator(tree, { ...baseLibraryConfig, directory: 'my-dir/my-lib', }); const project = readProjectConfiguration(tree, 'my-lib'); - expect(project.root).toEqual('my-dir/my-lib'); - expect(project.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - }); + expect(project).toMatchInlineSnapshot(` + { + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "name": "my-lib", + "projectType": "library", + "root": "my-dir/my-lib", + "sourceRoot": "my-dir/my-lib/src", + "tags": [], + "targets": {}, + } + `); }); it('should update tsconfig.json', async () => { diff --git a/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap index c8c41ed40dd0f1..6dbf02ba149d5b 100644 --- a/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap @@ -68,11 +68,7 @@ exports[`app generated files content - as-provided general application should co "$schema": "../node_modules/nx/schemas/project-schema.json", "projectType": "application", "sourceRoot": "my-app/src", - "targets": { - "lint": { - "executor": "@nx/eslint:lint" - } - } + "targets": {} } " `; diff --git a/packages/nuxt/src/generators/application/application.spec.ts b/packages/nuxt/src/generators/application/application.spec.ts index dd075f33bfe616..1edbf249fc0bf8 100644 --- a/packages/nuxt/src/generators/application/application.spec.ts +++ b/packages/nuxt/src/generators/application/application.spec.ts @@ -8,7 +8,7 @@ describe('app', () => { describe('generated files content - as-provided', () => { describe('general application', () => { - beforeAll(async () => { + beforeEach(async () => { tree = createTreeWithEmptyWorkspace(); await applicationGenerator(tree, { name, @@ -16,6 +16,14 @@ describe('app', () => { unitTestRunner: 'vitest', }); }); + + it('should not add targets', async () => { + const projectConfig = readProjectConfiguration(tree, name); + expect(projectConfig.targets.build).toBeUndefined(); + expect(projectConfig.targets.serve).toBeUndefined(); + expect(projectConfig.targets.test).toBeUndefined(); + }); + it('should create all new files in the correct location', async () => { const newFiles = tree.listChanges().map((change) => change.path); expect(newFiles).toMatchSnapshot(); @@ -97,35 +105,5 @@ describe('app', () => { expect(tree.read('myapp4/nuxt.config.ts', 'utf-8')).toMatchSnapshot(); }); }); - - describe('pcv3', () => { - let originalValue: string | undefined; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace(); - originalValue = process.env['NX_PCV3']; - process.env['NX_PCV3'] = 'true'; - }); - - afterEach(() => { - if (originalValue) { - process.env['NX_PCV3'] = originalValue; - } else { - delete process.env['NX_PCV3']; - } - }); - - it('should not add targets', async () => { - await applicationGenerator(tree, { - name, - projectNameAndRootFormat: 'as-provided', - unitTestRunner: 'vitest', - }); - - const projectConfi = readProjectConfiguration(tree, name); - expect(projectConfi.targets.build).toBeUndefined(); - expect(projectConfi.targets.serve).toBeUndefined(); - expect(projectConfi.targets.test).toBeUndefined(); - }); - }); }); }); diff --git a/packages/nuxt/src/generators/init/init.spec.ts b/packages/nuxt/src/generators/init/init.spec.ts index cb0515d4ff1964..051051613932fd 100644 --- a/packages/nuxt/src/generators/init/init.spec.ts +++ b/packages/nuxt/src/generators/init/init.spec.ts @@ -17,26 +17,24 @@ describe('init', () => { expect(packageJson).toMatchSnapshot(); }); - describe('pcv3', () => { - beforeEach(() => { - tree = createTreeWithEmptyWorkspace(); - }); + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + }); - it('should not add targets', async () => { - await nuxtInitGenerator(tree, { - skipFormat: false, - }); - const nxJson = readNxJson(tree); - expect(nxJson.plugins).toMatchObject([ - { - options: { buildTargetName: 'build', serveTargetName: 'serve' }, - plugin: '@nx/nuxt/plugin', - }, - { - options: { testTargetName: 'test' }, - plugin: '@nx/vite/plugin', - }, - ]); + it('should not add targets', async () => { + await nuxtInitGenerator(tree, { + skipFormat: false, }); + const nxJson = readNxJson(tree); + expect(nxJson.plugins).toMatchObject([ + { + options: { buildTargetName: 'build', serveTargetName: 'serve' }, + plugin: '@nx/nuxt/plugin', + }, + { + options: { testTargetName: 'test' }, + plugin: '@nx/vite/plugin', + }, + ]); }); }); diff --git a/packages/nx/src/command-line/add/add.ts b/packages/nx/src/command-line/add/add.ts index 4a45e6c05be3a8..d9fd026fd796af 100644 --- a/packages/nx/src/command-line/add/add.ts +++ b/packages/nx/src/command-line/add/add.ts @@ -112,7 +112,8 @@ async function initializePlugin( updatePackageScripts = options.updatePackageScripts; } else { updatePackageScripts = - process.env.NX_PCV3 === 'true' && coreNxPlugins.includes(pkgName); + process.env.NX_ADD_PLUGINS !== 'false' && + coreNxPlugins.includes(pkgName); } await runNxAsync( `g ${pkgName}:${initGenerator} --keepExistingVersions${ diff --git a/packages/nx/src/command-line/add/command-object.ts b/packages/nx/src/command-line/add/command-object.ts index 1069f4cd6a3314..88226676705634 100644 --- a/packages/nx/src/command-line/add/command-object.ts +++ b/packages/nx/src/command-line/add/command-object.ts @@ -22,7 +22,7 @@ export const yargsAddCommand: CommandModule< .option('updatePackageScripts', { type: 'boolean', description: - 'Update `package.json` scripts with inferred targets. Defaults to `true` when `NX_PCV3=true` and the package is a core Nx plugin', + 'Update `package.json` scripts with inferred targets. Defaults to `true` when the package is a core Nx plugin', }) .option('verbose', { type: 'boolean', diff --git a/packages/nx/src/command-line/init/command-object.ts b/packages/nx/src/command-line/init/command-object.ts index b2f411e657b255..706cde2a87478e 100644 --- a/packages/nx/src/command-line/init/command-object.ts +++ b/packages/nx/src/command-line/init/command-object.ts @@ -1,7 +1,7 @@ import { Argv, CommandModule } from 'yargs'; import { parseCSV } from '../yargs-utils/shared-options'; -const isPCv3 = process.env['NX_PCV3'] === 'true'; +const useV2 = process.env['NX_ADD_PLUGINS'] !== 'false'; export const yargsInitCommand: CommandModule = { command: 'init', @@ -9,7 +9,7 @@ export const yargsInitCommand: CommandModule = { 'Adds Nx to any type of workspace. It installs nx, creates an nx.json configuration file and optionally sets up remote caching. For more info, check https://nx.dev/recipes/adopting-nx.', builder: (yargs) => withInitOptions(yargs), handler: async (args: any) => { - if (isPCv3) { + if (useV2) { await require('./init-v2').initHandler(args); } else { await require('./init-v1').initHandler(args); @@ -19,7 +19,7 @@ export const yargsInitCommand: CommandModule = { }; function withInitOptions(yargs: Argv) { - if (isPCv3) { + if (useV2) { return yargs .option('nxCloud', { type: 'boolean', diff --git a/packages/nx/src/command-line/init/init-v2.ts b/packages/nx/src/command-line/init/init-v2.ts index e508a0c561df2d..d1543a3b9f3c83 100644 --- a/packages/nx/src/command-line/init/init-v2.ts +++ b/packages/nx/src/command-line/init/init-v2.ts @@ -49,7 +49,7 @@ export async function initHandler(options: InitArgs): Promise { return; } - // TODO(jack): Remove this Angular logic once `@nx/plugin` is compatible with PCv3. + // TODO(jack): Remove this Angular logic once `@nx/angular` is compatible with inferred targets. if (existsSync('angular.json')) { await addNxToAngularCliRepo({ ...options, @@ -97,7 +97,7 @@ export async function initHandler(options: InitArgs): Promise { if (useNxCloud) { output.log({ title: '🛠️ Setting up Nx Cloud' }); execSync( - `${pmc.exec} nx g nx:connect-to-nx-cloud --installationSource=nx-init-pcv3 --quiet --hideFormatLogs --no-interactive`, + `${pmc.exec} nx g nx:connect-to-nx-cloud --installationSource=nx-init --quiet --hideFormatLogs --no-interactive`, { stdio: [0, 1, 2], cwd: repoRoot, diff --git a/packages/playwright/src/generators/init/init.spec.ts b/packages/playwright/src/generators/init/init.spec.ts index 1289875c41f0c0..e8cedd946867f7 100644 --- a/packages/playwright/src/generators/init/init.spec.ts +++ b/packages/playwright/src/generators/init/init.spec.ts @@ -11,18 +11,11 @@ describe('@nx/playwright:init', () => { tree = createTreeWithEmptyWorkspace(); }); - it('should add the plugin if PCV3 is set', async () => { - await withEnvironmentVariables( - { - NX_PCV3: 'true', - }, - async () => { - await initGenerator(tree, { - skipFormat: true, - skipPackageJson: false, - }); - } - ); + it('should add the plugin', async () => { + await initGenerator(tree, { + skipFormat: true, + skipPackageJson: false, + }); const nxJson = readNxJson(tree); expect(nxJson.plugins).toMatchInlineSnapshot(` [ @@ -40,17 +33,10 @@ describe('@nx/playwright:init', () => { updateNxJson(tree, { plugins: ['foo'], }); - await withEnvironmentVariables( - { - NX_PCV3: 'true', - }, - async () => { - await initGenerator(tree, { - skipFormat: true, - skipPackageJson: false, - }); - } - ); + await initGenerator(tree, { + skipFormat: true, + skipPackageJson: false, + }); const nxJson = readNxJson(tree); expect(nxJson.plugins).toMatchInlineSnapshot(` [ @@ -69,17 +55,10 @@ describe('@nx/playwright:init', () => { updateNxJson(tree, { plugins: ['@nx/playwright/plugin'], }); - await withEnvironmentVariables( - { - NX_PCV3: 'true', - }, - async () => { - await initGenerator(tree, { - skipFormat: true, - skipPackageJson: false, - }); - } - ); + await initGenerator(tree, { + skipFormat: true, + skipPackageJson: false, + }); const nxJson = readNxJson(tree); expect(nxJson.plugins).toMatchInlineSnapshot(` [ @@ -88,10 +67,10 @@ describe('@nx/playwright:init', () => { `); }); - it('should not add plugin if environment variable is not set', async () => { + it('should not add plugin if NX_ADD_PLUGINS variable is set', async () => { await withEnvironmentVariables( { - NX_PCV3: undefined, + NX_ADD_PLUGINS: 'false', }, async () => { await initGenerator(tree, { diff --git a/packages/playwright/src/generators/init/init.ts b/packages/playwright/src/generators/init/init.ts index 418c9a20c39a91..8092a4b1b0edff 100644 --- a/packages/playwright/src/generators/init/init.ts +++ b/packages/playwright/src/generators/init/init.ts @@ -30,7 +30,7 @@ export async function initGenerator(tree: Tree, options: InitGeneratorSchema) { ); } - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(tree); } diff --git a/packages/react-native/src/generators/init/init.ts b/packages/react-native/src/generators/init/init.ts index bbb05726eba774..28373e306466ef 100644 --- a/packages/react-native/src/generators/init/init.ts +++ b/packages/react-native/src/generators/init/init.ts @@ -25,7 +25,7 @@ import { Schema } from './schema'; export async function reactNativeInitGenerator(host: Tree, schema: Schema) { addGitIgnoreEntry(host); - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(host); } diff --git a/packages/react/src/generators/application/application.pcv3.spec.ts b/packages/react/src/generators/application/application.legacy.spec.ts similarity index 90% rename from packages/react/src/generators/application/application.pcv3.spec.ts rename to packages/react/src/generators/application/application.legacy.spec.ts index 1e0289dba29ace..88243686e2a186 100644 --- a/packages/react/src/generators/application/application.pcv3.spec.ts +++ b/packages/react/src/generators/application/application.legacy.spec.ts @@ -13,7 +13,7 @@ import { Schema } from './schema'; // need to mock cypress otherwise it'll use the nx installed version from package.json // which is v9 while we are testing for the new v10 version jest.mock('@nx/cypress/src/utils/cypress-version'); -describe('react app generator (PCv3)', () => { +describe('react app generator (legacy)', () => { let appTree: Tree; let schema: Schema = { compiler: 'babel', @@ -28,14 +28,21 @@ describe('react app generator (PCv3)', () => { let mockedInstalledCypressVersion: jest.Mock< ReturnType > = installedCypressVersion as never; + + let originalEnv: string; + + beforeEach(() => { + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; + }); + + afterEach(() => { + process.env.NX_ADD_PLUGINS = originalEnv; + }); + beforeEach(() => { mockedInstalledCypressVersion.mockReturnValue(10); appTree = createTreeWithEmptyWorkspace(); - const nxJson = readNxJson(appTree); - nxJson.plugins ??= []; - nxJson.plugins.push('@nx/webpack/plugin'); - nxJson.plugins.push('@nx/vite/plugin'); - updateNxJson(appTree, nxJson); }); it('should setup webpack config that is compatible without project targets', async () => { diff --git a/packages/remix/src/generators/init/init.spec.ts b/packages/remix/src/generators/init/init.spec.ts index 51d89b4eeb5d0b..1ea1db85360ee0 100644 --- a/packages/remix/src/generators/init/init.spec.ts +++ b/packages/remix/src/generators/init/init.spec.ts @@ -3,35 +3,33 @@ import { readJson } from '@nx/devkit'; import initGenerator from './init'; describe('Remix Init Generator', () => { - describe('NX_PCV3=false', () => { - it('should setup the workspace and add dependencies', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace(); + it('should setup the workspace and add dependencies', async () => { + // ARRANGE + const tree = createTreeWithEmptyWorkspace(); - // ACT - await initGenerator(tree, {}); + // ACT + await initGenerator(tree, {}); - // ASSERT - const pkgJson = readJson(tree, 'package.json'); - expect(pkgJson.dependencies).toMatchInlineSnapshot(` + // ASSERT + const pkgJson = readJson(tree, 'package.json'); + expect(pkgJson.dependencies).toMatchInlineSnapshot(` { "@remix-run/serve": "^2.3.0", } `); - expect(pkgJson.devDependencies).toMatchInlineSnapshot(` + expect(pkgJson.devDependencies).toMatchInlineSnapshot(` { "@nx/web": "0.0.1", "@remix-run/dev": "^2.3.0", } `); - }); }); - describe('NX_PCV3=true', () => { + describe('NX_ADD_PLUGINS=false', () => { it('should setup the workspace and add dependencies', async () => { // ARRANGE const tree = createTreeWithEmptyWorkspace(); - process.env.NX_PCV3 = 'true'; + process.env.NX_ADD_PLUGINS = 'false'; // ACT await initGenerator(tree, {}); diff --git a/packages/remix/src/generators/init/init.ts b/packages/remix/src/generators/init/init.ts index 4c06cbd359fd73..0e826cf9acd086 100644 --- a/packages/remix/src/generators/init/init.ts +++ b/packages/remix/src/generators/init/init.ts @@ -58,7 +58,7 @@ export async function remixInitGenerator(tree: Tree, options: Schema) { tasks.push(installTask); } - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(tree); } diff --git a/packages/storybook/src/generators/init/init.spec.ts b/packages/storybook/src/generators/init/init.spec.ts index cf4e7734f36d1f..b9c5cb898f73e9 100644 --- a/packages/storybook/src/generators/init/init.spec.ts +++ b/packages/storybook/src/generators/init/init.spec.ts @@ -9,22 +9,21 @@ describe('@nx/storybook:init', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); - it('should add build-storybook to cacheable operations', async () => { + it('should add build-storybook to cacheable operations if NX_ADD_PLUGINS=false', async () => { + process.env.NX_ADD_PLUGINS = 'false'; await initGenerator(tree, {}); const nxJson = readJson(tree, 'nx.json'); expect(nxJson.targetDefaults['build-storybook'].cache).toEqual(true); + delete process.env.NX_ADD_PLUGINS; }); it('should add storybook-static to .gitignore', async () => { - process.env.NX_PCV3 = 'true'; tree.write('.gitignore', ''); await initGenerator(tree, {}); expect(tree.read('.gitignore', 'utf-8')).toContain('storybook-static'); - delete process.env.NX_PCV3; }); it('should not add storybook-static to .gitignore if it already exists', async () => { - process.env.NX_PCV3 = 'true'; tree.write( '.gitignore', ` @@ -35,6 +34,5 @@ describe('@nx/storybook:init', () => { ); await initGenerator(tree, {}); expect(tree.read('.gitignore', 'utf-8')).toMatchSnapshot(); - delete process.env.NX_PCV3; }); }); diff --git a/packages/storybook/src/generators/init/init.ts b/packages/storybook/src/generators/init/init.ts index 4293c45a64669c..d6cf9396d3afbc 100644 --- a/packages/storybook/src/generators/init/init.ts +++ b/packages/storybook/src/generators/init/init.ts @@ -30,7 +30,7 @@ function checkDependenciesInstalled( '@nx/web': nxVersion, }; - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { let storybook7VersionToInstall = storybookVersion; if ( storybookMajorVersion() >= 7 && @@ -91,7 +91,7 @@ function moveToDevDependencies(tree: Tree): GeneratorCallback { } export async function initGenerator(tree: Tree, schema: Schema) { - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(tree); updateGitignore(tree); } else { diff --git a/packages/vite/src/generators/init/init.spec.ts b/packages/vite/src/generators/init/init.spec.ts index 3b2c33fd2573b4..da4b978f69719a 100644 --- a/packages/vite/src/generators/init/init.spec.ts +++ b/packages/vite/src/generators/init/init.spec.ts @@ -2,6 +2,7 @@ import { addDependenciesToPackageJson, NxJsonConfiguration, readJson, + readNxJson, Tree, updateJson, } from '@nx/devkit'; @@ -43,22 +44,42 @@ describe('@nx/vite:init', () => { await initGenerator(tree, {}); - const productionNamedInputs = readJson(tree, 'nx.json').namedInputs - .production; - const vitestDefaults = readJson(tree, 'nx.json').targetDefaults[ - '@nx/vite:test' - ]; + const nxJson = readNxJson(tree); - expect(productionNamedInputs).toContain( - '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)' - ); - expect(productionNamedInputs).toContain( - '!{projectRoot}/tsconfig.spec.json' - ); - expect(vitestDefaults).toEqual({ - cache: true, - inputs: ['default', '^production'], - }); + expect(nxJson).toMatchInlineSnapshot(` + { + "affected": { + "defaultBase": "main", + }, + "namedInputs": { + "production": [ + "default", + "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)", + "!{projectRoot}/tsconfig.spec.json", + ], + }, + "plugins": [ + { + "options": { + "buildTargetName": "build", + "previewTargetName": "preview", + "serveStaticTargetName": "serve-static", + "serveTargetName": "serve", + "testTargetName": "test", + }, + "plugin": "@nx/vite/plugin", + }, + ], + "targetDefaults": { + "build": { + "cache": true, + }, + "lint": { + "cache": true, + }, + }, + } + `); }); }); }); diff --git a/packages/vite/src/generators/init/init.ts b/packages/vite/src/generators/init/init.ts index 6a724706de3b32..89f47edd84d249 100644 --- a/packages/vite/src/generators/init/init.ts +++ b/packages/vite/src/generators/init/init.ts @@ -49,7 +49,7 @@ export function updateNxJsonSettings(tree: Tree) { } export async function initGenerator(tree: Tree, schema: InitGeneratorSchema) { - if (process.env.NX_PCV3 === 'true') { + if (process.env.NX_ADD_PLUGINS !== 'false') { addPlugin(tree); } diff --git a/packages/vite/src/generators/vitest/vitest.spec.ts b/packages/vite/src/generators/vitest/vitest.spec.ts index 80336aa433bf28..ae922062617ce1 100644 --- a/packages/vite/src/generators/vitest/vitest.spec.ts +++ b/packages/vite/src/generators/vitest/vitest.spec.ts @@ -24,46 +24,6 @@ describe('vitest generator', () => { appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); - it('Should add the test target to existing test target', async () => { - mockReactAppGenerator(appTree); - await generator(appTree, options); - const config = readProjectConfiguration(appTree, 'my-test-react-app'); - expect(config.targets['test']).toMatchInlineSnapshot(` - { - "executor": "@nx/vite:test", - "options": { - "passWithNoTests": true, - }, - "outputs": [ - "{workspaceRoot}/coverage/{projectRoot}", - ], - } - `); - }); - - it('should add the test target if its missing', async () => { - mockReactAppGenerator(appTree); - const projectConfig = readProjectConfiguration( - appTree, - 'my-test-react-app' - ); - delete projectConfig.targets.test; - updateProjectConfiguration(appTree, 'my-test-react-app', projectConfig); - await generator(appTree, options); - const config = readProjectConfiguration(appTree, 'my-test-react-app'); - expect(config.targets['test']).toMatchInlineSnapshot(` - { - "executor": "@nx/vite:test", - "options": { - "reportsDirectory": "../../coverage/apps/my-test-react-app", - }, - "outputs": [ - "{options.reportsDirectory}", - ], - } - `); - }); - describe('tsconfig', () => { it('should add a tsconfig.spec.json file', async () => { mockReactAppGenerator(appTree); diff --git a/packages/vite/src/plugins/plugin.spec.ts b/packages/vite/src/plugins/plugin.spec.ts index f5897cfb5de8e0..2c5561817322f3 100644 --- a/packages/vite/src/plugins/plugin.spec.ts +++ b/packages/vite/src/plugins/plugin.spec.ts @@ -29,7 +29,7 @@ describe('@nx/vite/plugin', () => { describe('root project', () => { let tempFs; beforeEach(async () => { - tempFs = new TempFs(''); + tempFs = new TempFs('vite-plugin-tests'); context = { nxJsonConfiguration: { // These defaults should be overridden by plugin diff --git a/packages/web/src/generators/application/application.pcv3.spec.ts b/packages/web/src/generators/application/application.legacy.spec.ts similarity index 86% rename from packages/web/src/generators/application/application.pcv3.spec.ts rename to packages/web/src/generators/application/application.legacy.spec.ts index f420f56f2e0c8f..f9cca26a412bd9 100644 --- a/packages/web/src/generators/application/application.pcv3.spec.ts +++ b/packages/web/src/generators/application/application.legacy.spec.ts @@ -1,11 +1,5 @@ import { installedCypressVersion } from '@nx/cypress/src/utils/cypress-version'; -import { - getProjects, - readNxJson, - readProjectConfiguration, - Tree, - updateNxJson, -} from '@nx/devkit'; +import { getProjects, readProjectConfiguration, Tree } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { applicationGenerator } from './application'; @@ -18,19 +12,26 @@ jest.mock('@nx/devkit', () => { ensurePackage: jest.fn((pkg) => jest.requireActual(pkg)), }; }); -describe('web app generator (PCv3)', () => { +describe('web app generator (legacy)', () => { let tree: Tree; let mockedInstalledCypressVersion: jest.Mock< ReturnType > = installedCypressVersion as never; + + let originalEnv: string; + + beforeEach(() => { + originalEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; + }); + + afterEach(() => { + process.env.NX_ADD_PLUGINS = originalEnv; + }); + beforeEach(() => { mockedInstalledCypressVersion.mockReturnValue(10); tree = createTreeWithEmptyWorkspace(); - const nxJson = readNxJson(tree); - nxJson.plugins ??= []; - nxJson.plugins.push('@nx/webpack/plugin'); - nxJson.plugins.push('@nx/vite/plugin'); - updateNxJson(tree, nxJson); }); it('should setup webpack configuration', async () => { diff --git a/packages/webpack/src/generators/configuration/configuration.pcv3.spec.ts b/packages/webpack/src/generators/configuration/configuration.pcv3.spec.ts deleted file mode 100644 index 736b0109080d6d..00000000000000 --- a/packages/webpack/src/generators/configuration/configuration.pcv3.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { - addProjectConfiguration, - readNxJson, - readProjectConfiguration, - Tree, - updateNxJson, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import configurationGenerator from './configuration'; - -describe('webpackProject', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - const nxJson = readNxJson(tree); - nxJson.plugins ??= []; - nxJson.plugins.push('@nx/webpack/plugin'); - updateNxJson(tree, nxJson); - addProjectConfiguration(tree, 'mypkg', { - root: 'libs/mypkg', - sourceRoot: 'libs/mypkg/src', - targets: {}, - }); - }); - - it('should generate files', async () => { - await configurationGenerator(tree, { - project: 'mypkg', - }); - const project = readProjectConfiguration(tree, 'mypkg'); - expect(project.targets.build).toBeUndefined(); - expect(project.targets.serve).toBeUndefined(); - }); - - it('should support --main option', async () => { - await configurationGenerator(tree, { - project: 'mypkg', - main: 'libs/mypkg/index.ts', - }); - - expect(tree.read('libs/mypkg/webpack.config.js', 'utf-8')).toContain( - `main: 'libs/mypkg/index.ts'` - ); - }); - - it('should support --tsConfig option', async () => { - await configurationGenerator(tree, { - project: 'mypkg', - tsConfig: 'libs/mypkg/tsconfig.custom.json', - }); - - expect(tree.read('libs/mypkg/webpack.config.js', 'utf-8')).toContain( - `tsConfig: 'libs/mypkg/tsconfig.custom.json'` - ); - }); -}); diff --git a/packages/webpack/src/generators/configuration/configuration.spec.ts b/packages/webpack/src/generators/configuration/configuration.spec.ts index 0430b754cd35f9..c251f0f3d6c1fc 100644 --- a/packages/webpack/src/generators/configuration/configuration.spec.ts +++ b/packages/webpack/src/generators/configuration/configuration.spec.ts @@ -24,18 +24,7 @@ describe('webpackProject', () => { project: 'mypkg', }); - const project = readProjectConfiguration(tree, 'mypkg'); - - expect(project.targets).toMatchObject({ - build: { - executor: '@nx/webpack:webpack', - outputs: ['{options.outputPath}'], - defaultConfiguration: 'production', - options: { - main: 'libs/mypkg/src/main.ts', - }, - }, - }); + expect(tree.exists('libs/mypkg/webpack.config.js')).toBeTruthy(); }); it('should support --main option', async () => { @@ -44,18 +33,9 @@ describe('webpackProject', () => { main: 'libs/mypkg/index.ts', }); - const project = readProjectConfiguration(tree, 'mypkg'); - - expect(project.targets).toMatchObject({ - build: { - executor: '@nx/webpack:webpack', - outputs: ['{options.outputPath}'], - defaultConfiguration: 'production', - options: { - main: 'libs/mypkg/index.ts', - }, - }, - }); + expect(tree.read('libs/mypkg/webpack.config.js', 'utf-8')).toContain( + `main: 'libs/mypkg/index.ts'` + ); }); it('should support --tsConfig option', async () => { @@ -64,40 +44,8 @@ describe('webpackProject', () => { tsConfig: 'libs/mypkg/tsconfig.custom.json', }); - const project = readProjectConfiguration(tree, 'mypkg'); - - expect(project.targets).toMatchObject({ - build: { - executor: '@nx/webpack:webpack', - outputs: ['{options.outputPath}'], - defaultConfiguration: 'production', - options: { - tsConfig: 'libs/mypkg/tsconfig.custom.json', - }, - }, - }); - }); - - it('should support --devServer option', async () => { - await configurationGenerator(tree, { - project: 'mypkg', - devServer: true, - }); - - const project = readProjectConfiguration(tree, 'mypkg'); - - expect(project.targets).toMatchObject({ - serve: { - executor: '@nx/webpack:dev-server', - options: { - buildTarget: 'mypkg:build', - }, - configurations: { - production: { - buildTarget: `mypkg:build:production`, - }, - }, - }, - }); + expect(tree.read('libs/mypkg/webpack.config.js', 'utf-8')).toContain( + `tsConfig: 'libs/mypkg/tsconfig.custom.json'` + ); }); }); diff --git a/packages/webpack/src/generators/init/init.pcv3.spec.ts b/packages/webpack/src/generators/init/init.legacy.spec.ts similarity index 72% rename from packages/webpack/src/generators/init/init.pcv3.spec.ts rename to packages/webpack/src/generators/init/init.legacy.spec.ts index 2bdd65a35fa32d..8e920e664f5d73 100644 --- a/packages/webpack/src/generators/init/init.pcv3.spec.ts +++ b/packages/webpack/src/generators/init/init.legacy.spec.ts @@ -3,21 +3,21 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { webpackInitGenerator } from './init'; -describe('webpackInitGenerator (PCv3)', () => { +describe('webpackInitGenerator (legacy)', () => { let tree: Tree; let previousEnv: string | undefined; beforeEach(async () => { - previousEnv = process.env.NX_PCV3; - process.env.NX_PCV3 = 'true'; + previousEnv = process.env.NX_ADD_PLUGINS; + process.env.NX_ADD_PLUGINS = 'false'; tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); afterEach(() => { - process.env.NX_PCV3 = previousEnv; + process.env.NX_ADD_PLUGINS = previousEnv; }); - it('should install webpack-cli', async () => { + it('should not install webpack dependencies', async () => { await webpackInitGenerator(tree, {}); const packageJson = readJson(tree, 'package.json'); @@ -27,7 +27,6 @@ describe('webpackInitGenerator (PCv3)', () => { devDependencies: { '@nx/web': expect.any(String), '@nx/webpack': expect.any(String), - 'webpack-cli': expect.any(String), }, }); }); diff --git a/packages/webpack/src/generators/init/init.spec.ts b/packages/webpack/src/generators/init/init.spec.ts index df9d18ecfe5be3..1c54f002fb4061 100644 --- a/packages/webpack/src/generators/init/init.spec.ts +++ b/packages/webpack/src/generators/init/init.spec.ts @@ -10,7 +10,7 @@ describe('webpackInitGenerator', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); - it('should install plugin', async () => { + it('should install plugin and webpack-cli', async () => { await webpackInitGenerator(tree, {}); const packageJson = readJson(tree, 'package.json'); @@ -20,6 +20,7 @@ describe('webpackInitGenerator', () => { devDependencies: { '@nx/webpack': expect.any(String), '@nx/web': expect.any(String), + 'webpack-cli': expect.any(String), }, }); }); diff --git a/packages/webpack/src/generators/init/init.ts b/packages/webpack/src/generators/init/init.ts index b2838757823dd3..d389b188eca55d 100644 --- a/packages/webpack/src/generators/init/init.ts +++ b/packages/webpack/src/generators/init/init.ts @@ -12,7 +12,7 @@ import { nxVersion, webpackCliVersion } from '../../utils/versions'; import { Schema } from './schema'; export async function webpackInitGenerator(tree: Tree, schema: Schema) { - const shouldAddPlugin = process.env.NX_PCV3 === 'true'; + const shouldAddPlugin = process.env.NX_ADD_PLUGINS !== 'false'; if (shouldAddPlugin) { addPlugin(tree); } diff --git a/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap b/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap index bd36babcb5ed13..4fd9caa93dae64 100644 --- a/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap +++ b/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap @@ -29,20 +29,5 @@ exports[`new should generate an empty nx.json 1`] = ` ], "sharedGlobals": [], }, - "targetDefaults": { - "build": { - "cache": true, - "dependsOn": [ - "^build", - ], - "inputs": [ - "production", - "^production", - ], - }, - "lint": { - "cache": true, - }, - }, } `; diff --git a/packages/workspace/src/generators/new/generate-workspace-files.spec.ts b/packages/workspace/src/generators/new/generate-workspace-files.spec.ts index 4ec00c959e7a26..1aa6153a4d8918 100644 --- a/packages/workspace/src/generators/new/generate-workspace-files.spec.ts +++ b/packages/workspace/src/generators/new/generate-workspace-files.spec.ts @@ -102,28 +102,13 @@ describe('@nx/workspace:generateWorkspaceFiles', () => { ], "sharedGlobals": [], }, - "targetDefaults": { - "build": { - "cache": true, - "dependsOn": [ - "^build", - ], - "inputs": [ - "production", - "^production", - ], - }, - "lint": { - "cache": true, - }, - }, } `); const validateNxJson = ajv.compile(nxSchema); expect(validateNxJson(nxJson)).toEqual(true); }); - it('should setup named inputs and target defaults for non-empty presets', async () => { + it('should setup named inputs for non-empty presets', async () => { await generateWorkspaceFiles(tree, { name: 'proj', directory: 'proj', @@ -145,21 +130,6 @@ describe('@nx/workspace:generateWorkspaceFiles', () => { ], "sharedGlobals": [], }, - "targetDefaults": { - "build": { - "cache": true, - "dependsOn": [ - "^build", - ], - "inputs": [ - "production", - "^production", - ], - }, - "lint": { - "cache": true, - }, - }, } `); }); @@ -211,17 +181,6 @@ describe('@nx/workspace:generateWorkspaceFiles', () => { { "$schema": "./node_modules/nx/schemas/nx-schema.json", "extends": "nx/presets/npm.json", - "targetDefaults": { - "build": { - "cache": true, - "dependsOn": [ - "^build", - ], - }, - "lint": { - "cache": true, - }, - }, } `); diff --git a/packages/workspace/src/generators/new/generate-workspace-files.ts b/packages/workspace/src/generators/new/generate-workspace-files.ts index 3ed27703cecb7b..c30b73e1f094db 100644 --- a/packages/workspace/src/generators/new/generate-workspace-files.ts +++ b/packages/workspace/src/generators/new/generate-workspace-files.ts @@ -68,7 +68,7 @@ function createNxJson( defaultBase, }, targetDefaults: - process.env.NX_PCV3 !== 'true' + process.env.NX_ADD_PLUGINS === 'false' ? { build: { cache: true, @@ -90,7 +90,7 @@ function createNxJson( production: ['default'], sharedGlobals: [], }; - if (process.env.NX_PCV3 !== 'true') { + if (process.env.NX_ADD_PLUGINS === 'false') { nxJson.targetDefaults.build.inputs = ['production', '^production']; } } diff --git a/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap b/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap index cf9dd101d19f33..d5c7a913ad8428 100644 --- a/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap +++ b/packages/workspace/src/generators/preset/__snapshots__/preset.spec.ts.snap @@ -36,62 +36,229 @@ exports[`preset should create files (preset = angular-monorepo) 3`] = ` ] `; +exports[`preset should create files (preset = react-monorepo) 1`] = ` +"const { NxWebpackPlugin } = require('@nx/webpack'); +const { NxReactWebpackPlugin } = require('@nx/react'); +const { join } = require('path'); + +module.exports = { + output: { + path: join(__dirname, '../../dist/apps/proj'), + }, + devServer: { + port: 4200, + }, + plugins: [ + new NxWebpackPlugin({ + tsConfig: './tsconfig.app.json', + compiler: 'babel', + main: './src/main.tsx', + index: './src/index.html', + baseHref: '/', + assets: ['./src/favicon.ico', './src/assets'], + styles: ['./src/styles.css'], + outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none', + optimization: process.env['NODE_ENV'] === 'production', + }), + new NxReactWebpackPlugin({ + // Uncomment this line if you don't want to use SVGR + // See: https://react-svgr.com/ + // svgr: false + }), + ], +}; +" +`; + exports[`preset should create files (preset = react-standalone bundler = vite) 1`] = ` -{ - "configurations": { - "development": { - "buildTarget": "proj:build:development", - "hmr": true, - }, - "production": { - "buildTarget": "proj:build:production", - "hmr": false, +"/// +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; +import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; + +export default defineConfig({ + root: __dirname, + cacheDir: './node_modules/.vite/.', + + server: { + port: 4200, + host: 'localhost', + }, + + preview: { + port: 4300, + host: 'localhost', + }, + + plugins: [react(), nxViteTsPaths()], + + // Uncomment this if you are using workers. + // worker: { + // plugins: [ nxViteTsPaths() ], + // }, + + build: { + outDir: './dist/proj', + reportCompressedSize: true, + commonjsOptions: { + transformMixedEsModules: true, }, }, - "defaultConfiguration": "development", - "executor": "@nx/vite:dev-server", - "options": { - "buildTarget": "proj:build", + + test: { + globals: true, + cache: { + dir: './node_modules/.vitest', + }, + environment: 'jsdom', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + + reporters: ['default'], + coverage: { + reportsDirectory: './coverage/proj', + provider: 'v8', + }, }, -} +}); +" `; exports[`preset should create files (preset = react-standalone bundler = webpack) 1`] = ` -{ - "configurations": { - "development": { - "buildTarget": "proj:build:development", - }, - "production": { - "buildTarget": "proj:build:production", - "hmr": false, +"const { NxWebpackPlugin } = require('@nx/webpack'); +const { NxReactWebpackPlugin } = require('@nx/react'); +const { join } = require('path'); + +module.exports = { + output: { + path: join(__dirname, './dist/proj'), + }, + devServer: { + port: 4200, + }, + plugins: [ + new NxWebpackPlugin({ + tsConfig: './tsconfig.app.json', + compiler: 'babel', + main: './src/main.tsx', + index: './src/index.html', + baseHref: '/', + assets: ['./src/favicon.ico', './src/assets'], + styles: ['./src/styles.css'], + outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none', + optimization: process.env['NODE_ENV'] === 'production', + }), + new NxReactWebpackPlugin({ + // Uncomment this line if you don't want to use SVGR + // See: https://react-svgr.com/ + // svgr: false + }), + ], +}; +" +`; + +exports[`preset should create files (preset = vue-monorepo) 1`] = ` +"/// +import { defineConfig } from 'vite'; +import vue from '@vitejs/plugin-vue'; +import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; + +export default defineConfig({ + root: __dirname, + cacheDir: '../../node_modules/.vite/apps/proj', + + server: { + port: 4200, + host: 'localhost', + }, + + preview: { + port: 4300, + host: 'localhost', + }, + + plugins: [vue(), nxViteTsPaths()], + + // Uncomment this if you are using workers. + // worker: { + // plugins: [ nxViteTsPaths() ], + // }, + + build: { + outDir: '../../dist/apps/proj', + reportCompressedSize: true, + commonjsOptions: { + transformMixedEsModules: true, }, }, - "defaultConfiguration": "development", - "executor": "@nx/webpack:dev-server", - "options": { - "buildTarget": "proj:build", - "hmr": true, + + test: { + globals: true, + cache: { + dir: '../../node_modules/.vitest', + }, + environment: 'jsdom', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + + reporters: ['default'], + coverage: { + reportsDirectory: '../../coverage/apps/proj', + provider: 'v8', + }, }, -} +}); +" `; exports[`preset should create files (preset = vue-standalone) 1`] = ` -{ - "configurations": { - "development": { - "buildTarget": "proj:build:development", - "hmr": true, - }, - "production": { - "buildTarget": "proj:build:production", - "hmr": false, +"/// +import { defineConfig } from 'vite'; +import vue from '@vitejs/plugin-vue'; +import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; + +export default defineConfig({ + root: __dirname, + cacheDir: './node_modules/.vite/.', + + server: { + port: 4200, + host: 'localhost', + }, + + preview: { + port: 4300, + host: 'localhost', + }, + + plugins: [vue(), nxViteTsPaths()], + + // Uncomment this if you are using workers. + // worker: { + // plugins: [ nxViteTsPaths() ], + // }, + + build: { + outDir: './dist/proj', + reportCompressedSize: true, + commonjsOptions: { + transformMixedEsModules: true, }, }, - "defaultConfiguration": "development", - "executor": "@nx/vite:dev-server", - "options": { - "buildTarget": "proj:build", + + test: { + globals: true, + cache: { + dir: './node_modules/.vitest', + }, + environment: 'jsdom', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], + + reporters: ['default'], + coverage: { + reportsDirectory: './coverage/proj', + provider: 'v8', + }, }, -} +}); +" `; diff --git a/packages/workspace/src/generators/preset/preset.spec.ts b/packages/workspace/src/generators/preset/preset.spec.ts index 00d1d788b3dda8..9dc0bc4af7d560 100644 --- a/packages/workspace/src/generators/preset/preset.spec.ts +++ b/packages/workspace/src/generators/preset/preset.spec.ts @@ -38,7 +38,7 @@ describe('preset', () => { linter: 'eslint', }); expect(tree.exists('/apps/proj/src/main.tsx')).toBe(true); - expect(readProjectConfiguration(tree, 'proj').targets.serve).toBeDefined(); + expect(tree.read('apps/proj/webpack.config.js', 'utf-8')).toMatchSnapshot(); }); it(`should create files (preset = ${Preset.VueMonorepo})`, async () => { @@ -49,7 +49,7 @@ describe('preset', () => { linter: 'eslint', }); expect(tree.exists('apps/proj/src/main.ts')).toBe(true); - expect(readProjectConfiguration(tree, 'proj').targets.serve).toBeDefined(); + expect(tree.read('apps/proj/vite.config.ts', 'utf-8')).toMatchSnapshot(); }); it(`should create files (preset = ${Preset.Nuxt})`, async () => { @@ -103,9 +103,7 @@ describe('preset', () => { bundler: 'webpack', }); expect(tree.exists('webpack.config.js')).toBe(true); - expect( - readProjectConfiguration(tree, 'proj').targets.serve - ).toMatchSnapshot(); + expect(tree.read('webpack.config.js', 'utf-8')).toMatchSnapshot(); }); it(`should create files (preset = ${Preset.ReactStandalone} bundler = vite)`, async () => { @@ -117,9 +115,7 @@ describe('preset', () => { bundler: 'vite', }); expect(tree.exists('vite.config.ts')).toBe(true); - expect( - readProjectConfiguration(tree, 'proj').targets.serve - ).toMatchSnapshot(); + expect(tree.read('vite.config.ts', 'utf-8')).toMatchSnapshot(); }); it(`should create files (preset = ${Preset.VueStandalone})`, async () => { @@ -130,9 +126,7 @@ describe('preset', () => { e2eTestRunner: 'cypress', }); expect(tree.exists('vite.config.ts')).toBe(true); - expect( - readProjectConfiguration(tree, 'proj').targets.serve - ).toMatchSnapshot(); + expect(tree.read('vite.config.ts', 'utf-8')).toMatchSnapshot(); }); it(`should create files (preset = ${Preset.NuxtStandalone})`, async () => {