From d8f3c6b18644e7bb66e4e103152e5e130dc9c6bc Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 13 Oct 2022 13:37:37 -0400 Subject: [PATCH] fix(react): migrations use tsquery, so we should provide it (#12575) --- packages/cypress/migrations.json | 46 +- packages/cypress/package.json | 1 + .../update-8-1-0/update-8-1-0.spec.ts | 33 - .../migrations/update-8-1-0/update-8-1-0.ts | 34 - .../migrations/update-8-10-0/update-8-10-0.ts | 14 - .../migrations/update-8-12-0/update-8-12-0.ts | 14 - .../update-8-2-0/update-8-2-0.spec.ts | 146 --- .../migrations/update-8-2-0/update-8-2-0.ts | 237 ----- .../add-cypress-eslint-plugin-9-4-0.spec.ts | 99 -- .../add-cypress-eslint-plugin-9-4-0.ts | 65 -- .../update-14-2-0/split-create-empty-tree.ts | 2 +- .../update-tsconfigs-for-tests.ts | 2 +- .../add-missing-root-babel-config.ts | 2 +- .../update-jest-config-ext.spec.ts | 2 +- packages/linter/migrations.json | 84 -- .../add-json-ext-to-eslintrc.spec.ts | 115 --- .../update-10-3-0/add-json-ext-to-eslintrc.ts | 62 -- ...rc-json-to-workspace-implicit-deps.spec.ts | 56 -- ...slintrc-json-to-workspace-implicit-deps.ts | 16 - .../update-10-3-0/update-10-3-0.spec.ts | 21 - .../migrations/update-10-3-0/update-10-3-0.ts | 26 - .../update-eslint-builder-and-config.spec.ts | 150 --- .../update-eslint-builder-and-config.ts | 89 -- ...es-files-in-eslint-builder-options.spec.ts | 79 -- ...modules-files-in-eslint-builder-options.ts | 28 - ...e-eslint-configs-to-use-nx-presets.spec.ts | 899 ------------------ ...update-eslint-configs-to-use-nx-presets.ts | 541 ----------- ...oot-eslint-config-to-use-overrides.spec.ts | 209 ---- ...ate-root-eslint-config-to-use-overrides.ts | 117 --- ...roject-level-tsconfigs-with-eslint.spec.ts | 334 ------- ...use-project-level-tsconfigs-with-eslint.ts | 99 -- packages/nest/migrations.json | 68 -- packages/nest/package.json | 3 +- .../migrations/update-10-0-0/update-10-0-0.ts | 89 -- .../migrations/update-8-7-0/update-8-7-0.ts | 13 - packages/next/migrations.json | 109 --- .../migrations/update-10-1-0/update-10-1-0.ts | 13 - .../rename-emotion-packages-11-0-0.spec.ts | 62 -- .../rename-emotion-packages-11-0-0.ts | 12 - .../update-11-0-0/update-11-0-0.spec.ts | 45 - .../migrations/update-11-0-0/update-11-0-0.ts | 13 - .../remove-tsconfig-app-11-5-0.spec.ts | 188 ---- .../remove-tsconfig-app-11-5-0.ts | 36 - .../update-11-5-0/update-babel-config.spec.ts | 62 -- .../update-11-5-0/update-babel-config.ts | 22 - .../add-js-include-11-6-0.spec.ts | 41 - .../update-11-6-0/add-js-include-11-6-0.ts | 25 - .../migrations/update-8-10-0/update-8-10-0.ts | 13 - .../update-9-2-0/create-next-config.spec.ts | 106 --- .../update-9-2-0/create-next-config.ts | 52 - .../migrations/update-9-3-1/update-9-3-1.ts | 17 - packages/node/migrations.json | 10 - .../update-10-1-0/remove-root-dir.spec.ts | 90 -- .../update-10-1-0/remove-root-dir.ts | 59 -- .../set-build-libs-from-source.spec.ts | 47 - .../set-build-libs-from-source.ts | 30 - packages/nx-plugin/migrations.json | 15 - .../update-10-2-0/update-10-2-0.spec.ts | 60 -- .../migrations/update-10-2-0/update-10-2-0.ts | 32 - .../rename-ng-update-into-nx-migrate.ts | 13 - ...ma-version-for-executors-and-generators.ts | 19 - packages/react/package.json | 1 + packages/storybook/migrations.json | 53 -- .../update-10-2-1/update-10-2-1.spec.ts | 62 -- .../migrations/update-10-2-1/update-10-2-1.ts | 84 -- .../update-10-3-0/update-10-3-0.spec.ts | 258 ----- .../migrations/update-10-3-0/update-10-3-0.ts | 137 --- .../update-11-0-12/update-storybook.spec.ts | 50 - .../update-11-0-12/update-storybook.ts | 53 -- .../update-11-5-3/update-lint-ignores.spec.ts | 58 -- .../update-11-5-3/update-lint-ignores.ts | 94 -- .../update-11-6-0/update-storybook.spec.ts | 54 -- .../update-11-6-0/update-storybook.ts | 57 -- .../migrate-stories-to-6-2.ts | 2 +- packages/web/migrations.json | 33 - .../create-babelrc-for-workspace-libs.spec.ts | 229 ----- .../create-babelrc-for-workspace-libs.ts | 25 - .../update-existing-babelrc-files.spec.ts | 80 -- .../update-existing-babelrc-files.ts | 33 - .../update-root-babel-config.spec.ts | 23 - .../update-11-5-2/update-root-babel-config.ts | 15 - .../migrations/update-11-5-2/utils.spec.ts | 140 --- .../web/src/migrations/update-11-5-2/utils.ts | 42 - .../update-8-5-0/update-builder-8-5-0.spec.ts | 49 - .../update-8-5-0/update-builder-8-5-0.ts | 24 - .../update-9-0-0/update-builder-9-0-0.ts | 24 - .../set-build-libs-from-source.spec.ts | 49 - .../set-build-libs-from-source.ts | 26 - .../update-13-10-0/update-tasks-runner.ts | 2 +- scripts/depcheck/missing.ts | 20 +- 90 files changed, 27 insertions(+), 6736 deletions(-) delete mode 100644 packages/cypress/src/migrations/update-8-1-0/update-8-1-0.spec.ts delete mode 100644 packages/cypress/src/migrations/update-8-1-0/update-8-1-0.ts delete mode 100644 packages/cypress/src/migrations/update-8-10-0/update-8-10-0.ts delete mode 100644 packages/cypress/src/migrations/update-8-12-0/update-8-12-0.ts delete mode 100644 packages/cypress/src/migrations/update-8-2-0/update-8-2-0.spec.ts delete mode 100644 packages/cypress/src/migrations/update-8-2-0/update-8-2-0.ts delete mode 100644 packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.spec.ts delete mode 100644 packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.spec.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.spec.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/update-10-3-0.spec.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/update-10-3-0.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.spec.ts delete mode 100644 packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.ts delete mode 100644 packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.spec.ts delete mode 100644 packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.ts delete mode 100644 packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.spec.ts delete mode 100644 packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.ts delete mode 100644 packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.spec.ts delete mode 100644 packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.ts delete mode 100644 packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.spec.ts delete mode 100644 packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.ts delete mode 100644 packages/nest/src/migrations/update-10-0-0/update-10-0-0.ts delete mode 100644 packages/nest/src/migrations/update-8-7-0/update-8-7-0.ts delete mode 100644 packages/next/src/migrations/update-10-1-0/update-10-1-0.ts delete mode 100644 packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.spec.ts delete mode 100644 packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.ts delete mode 100644 packages/next/src/migrations/update-11-0-0/update-11-0-0.spec.ts delete mode 100644 packages/next/src/migrations/update-11-0-0/update-11-0-0.ts delete mode 100644 packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.spec.ts delete mode 100644 packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.ts delete mode 100644 packages/next/src/migrations/update-11-5-0/update-babel-config.spec.ts delete mode 100644 packages/next/src/migrations/update-11-5-0/update-babel-config.ts delete mode 100644 packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts delete mode 100644 packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.ts delete mode 100644 packages/next/src/migrations/update-8-10-0/update-8-10-0.ts delete mode 100644 packages/next/src/migrations/update-9-2-0/create-next-config.spec.ts delete mode 100644 packages/next/src/migrations/update-9-2-0/create-next-config.ts delete mode 100644 packages/next/src/migrations/update-9-3-1/update-9-3-1.ts delete mode 100644 packages/node/src/migrations/update-10-1-0/remove-root-dir.spec.ts delete mode 100644 packages/node/src/migrations/update-10-1-0/remove-root-dir.ts delete mode 100644 packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts delete mode 100644 packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.ts delete mode 100644 packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts delete mode 100644 packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.ts delete mode 100644 packages/nx-plugin/src/migrations/update-11-0-0/rename-ng-update-into-nx-migrate.ts delete mode 100644 packages/nx-plugin/src/migrations/update-11-0-0/update-schema-version-for-executors-and-generators.ts delete mode 100644 packages/storybook/src/migrations/update-10-2-1/update-10-2-1.spec.ts delete mode 100644 packages/storybook/src/migrations/update-10-2-1/update-10-2-1.ts delete mode 100644 packages/storybook/src/migrations/update-10-3-0/update-10-3-0.spec.ts delete mode 100644 packages/storybook/src/migrations/update-10-3-0/update-10-3-0.ts delete mode 100644 packages/storybook/src/migrations/update-11-0-12/update-storybook.spec.ts delete mode 100644 packages/storybook/src/migrations/update-11-0-12/update-storybook.ts delete mode 100644 packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.spec.ts delete mode 100644 packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.ts delete mode 100644 packages/storybook/src/migrations/update-11-6-0/update-storybook.spec.ts delete mode 100644 packages/storybook/src/migrations/update-11-6-0/update-storybook.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.spec.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.spec.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/update-root-babel-config.spec.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/update-root-babel-config.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/utils.spec.ts delete mode 100644 packages/web/src/migrations/update-11-5-2/utils.ts delete mode 100644 packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.spec.ts delete mode 100644 packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.ts delete mode 100644 packages/web/src/migrations/update-9-0-0/update-builder-9-0-0.ts delete mode 100644 packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts delete mode 100644 packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.ts diff --git a/packages/cypress/migrations.json b/packages/cypress/migrations.json index dfd13da951d1a..2021873f6e996 100644 --- a/packages/cypress/migrations.json +++ b/packages/cypress/migrations.json @@ -1,30 +1,5 @@ { "schematics": { - "update-8.1.0": { - "version": "8.1.0-beta.1", - "description": "Update cypress", - "factory": "./src/migrations/update-8-1-0/update-8-1-0" - }, - "update-8.2.0": { - "version": "8.2.0-beta.1", - "description": "Update Cypress Config", - "factory": "./src/migrations/update-8-2-0/update-8-2-0" - }, - "update-8.10.0": { - "version": "8.10.0-beta.1", - "description": "Update Cypress to 3.6.1", - "factory": "./src/migrations/update-8-10-0/update-8-10-0" - }, - "update-8.12.0": { - "version": "8.12.0-beta.1", - "description": "Update Cypress to ^3.8.2", - "factory": "./src/migrations/update-8-12-0/update-8-12-0" - }, - "add-cypress-eslint-plugin-9.4.0": { - "version": "9.4.0-beta.1", - "description": "Add Cypress ESLint plugin", - "factory": "./src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0" - }, "remove-typescript-plugin": { "cli": "nx", "version": "12.8.0-beta.0", @@ -56,24 +31,5 @@ "factory": "./src/migrations/update-15-0-0/update-cy-mount-usage" } }, - "packageJsonUpdates": { - "8.10.0": { - "version": "8.10.0-beta.1", - "packages": { - "cypress": { - "version": "3.6.1", - "alwaysAddToPackageJson": false - } - } - }, - "8.12.0": { - "version": "8.12.0-beta.1", - "packages": { - "cypress": { - "version": "^3.8.2", - "alwaysAddToPackageJson": false - } - } - } - } + "packageJsonUpdates": {} } diff --git a/packages/cypress/package.json b/packages/cypress/package.json index 5828314ee33d2..dd1e1b90f895f 100644 --- a/packages/cypress/package.json +++ b/packages/cypress/package.json @@ -45,6 +45,7 @@ "chalk": "4.1.0", "dotenv": "~10.0.0", "fork-ts-checker-webpack-plugin": "7.2.13", + "semver": "7.3.4", "ts-loader": "^9.3.1", "tsconfig-paths-webpack-plugin": "3.5.2", "tslib": "^2.3.0", diff --git a/packages/cypress/src/migrations/update-8-1-0/update-8-1-0.spec.ts b/packages/cypress/src/migrations/update-8-1-0/update-8-1-0.spec.ts deleted file mode 100644 index 5284376c53193..0000000000000 --- a/packages/cypress/src/migrations/update-8-1-0/update-8-1-0.spec.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; - -import * as path from 'path'; - -describe('Update 8.1.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = Tree.empty(); - initialTree.create( - 'package.json', - JSON.stringify({ - scripts: {}, - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/cypress', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it('should update cypress', async () => { - const result = await schematicRunner - .runSchematicAsync('update-8.1.0', {}, initialTree) - .toPromise(); - - const { devDependencies } = JSON.parse(result.readContent('package.json')); - - expect(devDependencies.cypress).toEqual('~3.3.1'); - }); -}); diff --git a/packages/cypress/src/migrations/update-8-1-0/update-8-1-0.ts b/packages/cypress/src/migrations/update-8-1-0/update-8-1-0.ts deleted file mode 100644 index 48e0529fd603f..0000000000000 --- a/packages/cypress/src/migrations/update-8-1-0/update-8-1-0.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { - Rule, - chain, - SchematicContext, - Tree, -} from '@angular-devkit/schematics'; -import { formatFiles, updateJsonInTree } from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; - -function displayInformation(host: Tree, context: SchematicContext) { - context.logger.info( - stripIndents`Cypress has been updated to a version that improves network speed by 300%! - - Additionally, this resolves an issue where '@types/jquery' needed to be temporarily included in your 'package.json'. - If you're not using '@types/jquery' in your project otherwise, you may now remove it from your 'devDependencies'.` - ); -} - -export default function (): Rule { - return chain([ - updateJsonInTree('package.json', (json) => { - json.devDependencies = json.devDependencies || {}; - - json.devDependencies = { - ...json.devDependencies, - cypress: '~3.3.1', - }; - - return json; - }), - displayInformation, - formatFiles(), - ]); -} diff --git a/packages/cypress/src/migrations/update-8-10-0/update-8-10-0.ts b/packages/cypress/src/migrations/update-8-10-0/update-8-10-0.ts deleted file mode 100644 index 2257c756503e3..0000000000000 --- a/packages/cypress/src/migrations/update-8-10-0/update-8-10-0.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { formatFiles, updatePackagesInPackageJson } from '@nrwl/workspace'; - -import { join } from 'path'; -import { chain } from '@angular-devkit/schematics'; - -export default () => { - return chain([ - updatePackagesInPackageJson( - join(__dirname, '../../../migrations.json'), - '8.10.0' - ), - formatFiles(), - ]); -}; diff --git a/packages/cypress/src/migrations/update-8-12-0/update-8-12-0.ts b/packages/cypress/src/migrations/update-8-12-0/update-8-12-0.ts deleted file mode 100644 index 6d526136aedc8..0000000000000 --- a/packages/cypress/src/migrations/update-8-12-0/update-8-12-0.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { formatFiles, updatePackagesInPackageJson } from '@nrwl/workspace'; - -import { join } from 'path'; -import { chain } from '@angular-devkit/schematics'; - -export default () => { - return chain([ - updatePackagesInPackageJson( - join(__dirname, '../../../migrations.json'), - '8.12.0' - ), - formatFiles(), - ]); -}; diff --git a/packages/cypress/src/migrations/update-8-2-0/update-8-2-0.spec.ts b/packages/cypress/src/migrations/update-8-2-0/update-8-2-0.spec.ts deleted file mode 100644 index 7b3718317e236..0000000000000 --- a/packages/cypress/src/migrations/update-8-2-0/update-8-2-0.spec.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { chain, Tree } from '@angular-devkit/schematics'; - -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; -import { callRule, runMigration } from '../../utils/testing'; -import { - updateWorkspace, - readJsonInTree, - updateJsonInTree, -} from '@nrwl/workspace'; - -describe('Update 8.2.0', () => { - let initialTree: Tree; - - beforeEach(async () => { - initialTree = createEmptyWorkspace(Tree.empty()); - initialTree = await callRule( - chain([ - updateWorkspace((workspace) => { - workspace.projects.add({ - root: 'project', - name: 'proejct', - targets: { - e2e: { - builder: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'project/cypress.json', - tsConfig: 'project/tsconfig.e2e.json', - devServerTarget: 'project:serve', - }, - configurations: { - production: { - cypressConfig: 'project/cypress.prod.json', - tsConfig: 'project/tsconfig.e2e.json', - devServerTarget: 'project:serve:production', - }, - }, - }, - }, - }); - }), - updateJsonInTree('project/cypress.json', () => ({ - fileServerFolder: '../dist/out-tsc/project', - fixturesFolder: '../dist/out-tsc/project/src/fixtures', - integrationFolder: '../dist/out-tsc/project/src/integration', - pluginsFile: '../dist/out-tsc/project/src/plugins/index.js', - supportFile: false, - video: true, - videosFolder: '../dist/out-tsc/project/videos', - screenshotsFolder: '../dist/out-tsc/project/screenshots', - })), - updateJsonInTree('project/cypress.prod.json', () => ({ - fileServerFolder: '../dist/out-tsc/project', - fixturesFolder: '../dist/out-tsc/project/src/fixtures', - integrationFolder: '../dist/out-tsc/project/src/integration', - pluginsFile: '../dist/out-tsc/project/src/plugins/index.js', - supportFile: false, - video: true, - videosFolder: '../dist/out-tsc/project/videos', - screenshotsFolder: '../dist/out-tsc/project/screenshots', - baseUrl: 'https://www.example.com', - })), - updateJsonInTree('project/tsconfig.e2e.json', () => ({ - extends: '../tsconfig.json', - compilerOptions: { - outDir: '../dist/out-tsc', - }, - include: ['**/*'], - })), - updateJsonInTree('tsconfig.json', () => ({ - compilerOptions: { - rootDir: '.', - }, - })), - (host) => { - host.create( - 'project/src/plugins/index.ts', - ` - import * as mod from 'module'; - - // *********************************************************** - // This example plugins/index.js can be used to load plugins - // - // You can change the location of this file or turn off loading - // the plugins file with the 'pluginsFile' configuration option. - // - // You can read more here: - // https://on.cypress.io/plugins-guide - // *********************************************************** - - // This function is called when a project is opened or re-opened (e.g. due to - // the project's config changing) - - module.exports = (on: Cypress.Actions, config: Cypress.ConfigOptions) => { - console.log(mod); - // \`on\` is used to hook into various events Cypress emits - // \`config\` is the resolved Cypress config - }; - - ` - ); - }, - ]), - initialTree - ); - }); - - it('should update cypress configs', async () => { - const result = await runMigration('update-8.2.0', {}, initialTree); - expect(readJsonInTree(result, 'project/cypress.json')).toEqual({ - fileServerFolder: './', - fixturesFolder: './src/fixtures', - integrationFolder: './src/integration', - pluginsFile: './src/plugins/index.js', - supportFile: false, - video: true, - videosFolder: '../dist/out-tsc/project/videos', - screenshotsFolder: '../dist/out-tsc/project/screenshots', - }); - expect(readJsonInTree(result, 'project/cypress.prod.json')).toEqual({ - fileServerFolder: './', - fixturesFolder: './src/fixtures', - integrationFolder: './src/integration', - pluginsFile: './src/plugins/index.js', - supportFile: false, - video: true, - videosFolder: '../dist/out-tsc/project/videos', - screenshotsFolder: '../dist/out-tsc/project/screenshots', - baseUrl: 'https://www.example.com', - }); - }); - - it('should transpile plugin files', async () => { - const result = await runMigration('update-8.2.0', {}, initialTree); - const newPluginsFile = result.readContent('project/src/plugins/index.js'); - expect(newPluginsFile).toContain( - 'module.exports = function (on, config) {' - ); - expect(newPluginsFile).toContain( - `const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor');` - ); - expect(newPluginsFile).toContain(`var mod = require('module');`); - expect(newPluginsFile).toContain( - `on('file:preprocessor', preprocessTypescript(config));` - ); - }); -}); diff --git a/packages/cypress/src/migrations/update-8-2-0/update-8-2-0.ts b/packages/cypress/src/migrations/update-8-2-0/update-8-2-0.ts deleted file mode 100644 index ef0228c4aa673..0000000000000 --- a/packages/cypress/src/migrations/update-8-2-0/update-8-2-0.ts +++ /dev/null @@ -1,237 +0,0 @@ -import { - chain, - Rule, - SchematicContext, - Tree, -} from '@angular-devkit/schematics'; -import { - formatFiles, - getWorkspace, - readJsonInTree, - updateJsonInTree, -} from '@nrwl/workspace'; -import { stripIndents } from '@angular-devkit/core/src/utils/literals'; -import { - parseConfigFileTextToJson, - ParseConfigHost, - parseJsonConfigFileContent, - transpileModule, - ModuleKind, - createSourceFile, - isBinaryExpression, - isExpressionStatement, - isIdentifier, - isPropertyAccessExpression, - isFunctionExpression, - isArrowFunction, - isBlock, - ScriptTarget, -} from 'typescript'; -import { dirname, join, relative } from 'path'; -import { normalize } from '@angular-devkit/core'; - -async function updateCypressJson(host: Tree, context: SchematicContext) { - const rules: Rule[] = []; - const workspace = await getWorkspace(host); - - workspace.projects.forEach((project) => { - project.targets.forEach((target) => { - if (target.builder !== '@nrwl/cypress:cypress') { - return; - } - - const parseConfigHost: ParseConfigHost = { - useCaseSensitiveFileNames: true, - fileExists: (path) => host.exists(path), - readDirectory: (dir) => host.getDir(dir).subfiles, - readFile: (path) => host.read(path).toString(), - }; - - const updatedCypressJsons = new Set(); - updatedCypressJsons.add(target.options.cypressConfig as string); - - rules.push( - updateJsonInTree(target.options.cypressConfig as string, (json) => { - function getUpdatedPath(path: string) { - if (typeof path !== 'string') { - return path; - } - return `./${normalize( - relative( - dirname(target.options.cypressConfig as string), - relative( - `./${tsConfig.options.outDir}`, - join(dirname(target.options.cypressConfig as string), path) - ) - ) - )}`; - } - - const tsConfig = parseJsonConfigFileContent( - parseConfigFileTextToJson( - target.options.tsConfig as string, - host.read(target.options.tsConfig as string).toString() - ).config, - parseConfigHost, - dirname(target.options.tsConfig as string) - ); - - json.fileServerFolder = getUpdatedPath(json.fileServerFolder); - json.fixturesFolder = getUpdatedPath(json.fixturesFolder); - json.integrationFolder = getUpdatedPath(json.integrationFolder); - json.pluginsFile = getUpdatedPath(json.pluginsFile); - json.supportFile = getUpdatedPath(json.supportFile); - return json; - }) - ); - - Object.values(target.configurations).forEach((config) => { - if ( - config.cypressConfig && - !updatedCypressJsons.has(config.cypressConfig) - ) { - rules.push( - updateJsonInTree(config.cypressConfig as string, (json) => { - function getUpdatedPath(path: string) { - if (typeof path !== 'string') { - return path; - } - return `./${relative( - dirname(config.cypressConfig as string), - relative( - `./${tsConfig.options.outDir}`, - join(dirname(config.cypressConfig as string), path) - ) - )}`; - } - - const tsConfig = parseJsonConfigFileContent( - parseConfigFileTextToJson( - config.tsConfig || (target.options.tsConfig as string), - host - .read( - config.tsConfig || (target.options.tsConfig as string) - ) - .toString() - ).config, - parseConfigHost, - dirname(config.tsConfig || (target.options.tsConfig as string)) - ); - - json.fileServerFolder = getUpdatedPath(json.fileServerFolder); - json.fixturesFolder = getUpdatedPath(json.fixturesFolder); - json.integrationFolder = getUpdatedPath(json.integrationFolder); - json.pluginsFile = getUpdatedPath(json.pluginsFile); - json.supportFile = getUpdatedPath(json.supportFile); - return json; - }) - ); - } - }); - }); - }); - - return chain(rules); -} - -async function updatePlugins(host: Tree, context: SchematicContext) { - const workspace = await getWorkspace(host); - - workspace.projects.forEach((project) => { - project.targets.forEach((target) => { - if (target.builder !== '@nrwl/cypress:cypress') { - return; - } - - [target.options, ...Object.values(target.configurations)].forEach( - (config) => { - if (!config.cypressConfig) { - return; - } - - const cypressConfig = readJsonInTree( - host, - config.cypressConfig as string - ); - - if (typeof cypressConfig.pluginsFile !== 'string') { - return; - } - - const pluginFile = join( - dirname(config.cypressConfig as string), - `${cypressConfig.pluginsFile.replace(/\.js$/, '')}.ts` - ); - const newPluginFile = pluginFile.replace(/\.ts$/, '.js'); - - if (!host.exists(pluginFile)) { - return; - } - - const result = transpileModule(host.read(pluginFile).toString(), { - compilerOptions: { - module: ModuleKind.CommonJS, - }, - }); - host.create(newPluginFile, result.outputText); - host.delete(pluginFile); - - const sourceFile = createSourceFile( - newPluginFile, - result.outputText, - ScriptTarget.Latest - ); - - const recorder = host.beginUpdate(newPluginFile); - - recorder.insertLeft( - 0, - `const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor');` - ); - sourceFile.statements.forEach((statement) => { - if ( - isExpressionStatement(statement) && - isBinaryExpression(statement.expression) && - isPropertyAccessExpression(statement.expression.left) && - isIdentifier(statement.expression.left.expression) && - statement.expression.left.expression.escapedText === 'module' && - isIdentifier(statement.expression.left.name) && - statement.expression.left.name.escapedText === 'exports' && - (isFunctionExpression(statement.expression.right) || - isArrowFunction(statement.expression.right)) && - statement.expression.right.parameters.length >= 2 - ) { - if (isBlock(statement.expression.right.body)) { - const onParamName = - statement.expression.right.parameters[0].name.getText( - sourceFile - ); - const configParamName = - statement.expression.right.parameters[1].name.getText( - sourceFile - ); - - recorder.insertLeft( - statement.expression.right.body.statements.end, - stripIndents` - ${onParamName}('file:preprocessor', preprocessTypescript(${configParamName})) - ` - ); - } else { - context.logger.warn(stripIndents` - We could not update ${pluginFile} with our new preprocessor - `); - } - } - }); - - host.commitUpdate(recorder); - } - ); - }); - }); -} - -export default function (): Rule { - return chain([updateCypressJson, updatePlugins, formatFiles()]); -} diff --git a/packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.spec.ts b/packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.spec.ts deleted file mode 100644 index 6753e05d09f24..0000000000000 --- a/packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.spec.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree, updateJsonInTree } from '@nrwl/workspace'; -import { callRule, runMigration } from '../../utils/testing'; - -describe('Add Cypress ESLint Plugin 9.4.0', () => { - let tree: Tree; - - beforeEach(() => { - tree = Tree.empty(); - tree.create( - 'package.json', - JSON.stringify({ - devDependencies: { '@nrwl/cypress': '9.3.0', eslint: '6.8.0' }, - }) - ); - - tree.create( - 'workspace.json', - JSON.stringify({ - projects: { - 'project-one-e2e': { - root: 'apps/project-one-e2e', - architect: { - e2e: { - builder: '@nrwl/cypress:cypress', - }, - }, - }, - 'project-two-e2e': { - root: 'apps/project-two-e2e', - architect: { - e2e: { - builder: '@nrwl/cypress:cypress', - }, - }, - }, - }, - }) - ); - - tree.create( - 'apps/project-one-e2e/.eslintrc', - JSON.stringify({ - extends: '../../.eslintrc', - }) - ); - - tree.create( - 'apps/project-two-e2e/.eslintrc', - JSON.stringify({ - extends: ['../../.eslintrc'], - }) - ); - }); - - it('should add eslint-plugin-cypress devDependency', async () => { - const result = await runMigration( - 'add-cypress-eslint-plugin-9.4.0', - {}, - tree - ); - - const { devDependencies } = readJsonInTree(result, '/package.json'); - const projectOneEslintrcJson = readJsonInTree( - result, - 'apps/project-one-e2e/.eslintrc' - ); - const projectTwoEslintrcJson = readJsonInTree( - result, - 'apps/project-two-e2e/.eslintrc' - ); - - expect(devDependencies['eslint-plugin-cypress']).toEqual('^2.10.3'); - expect(projectOneEslintrcJson.extends).toContain( - 'plugin:cypress/recommended' - ); - expect(projectTwoEslintrcJson.extends).toContain( - 'plugin:cypress/recommended' - ); - }); - - it('should not add eslint-plugin-cypress if eslint is not used', async () => { - tree = await callRule( - updateJsonInTree('package.json', (json) => { - delete json.devDependencies.eslint; - return json; - }), - tree - ); - - const result = await runMigration( - 'add-cypress-eslint-plugin-9.4.0', - {}, - tree - ); - const { devDependencies } = readJsonInTree(result, '/package.json'); - expect(devDependencies['eslint-plugin-cypress']).not.toBeDefined(); - }); -}); diff --git a/packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.ts b/packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.ts deleted file mode 100644 index 425f923e5a061..0000000000000 --- a/packages/cypress/src/migrations/update-9-4-0/add-cypress-eslint-plugin-9-4-0.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { chain, noop, Rule, Tree } from '@angular-devkit/schematics'; -import { - addDepsToPackageJson, - formatFiles, - readJsonInTree, - updateJsonInTree, - readWorkspace, -} from '@nrwl/workspace'; - -async function addCypressPluginToEslintrc(host: Tree) { - const rules: Rule[] = []; - const { devDependencies } = readJsonInTree(host, 'package.json'); - - const eslintrcFilePaths = []; - if (devDependencies && devDependencies['@nrwl/cypress']) { - const workspace = readWorkspace(host); - Object.values(workspace.projects).forEach((project) => { - Object.values(project.architect).forEach((target) => { - if (target.builder !== '@nrwl/cypress:cypress') { - return; - } - - if (host.exists(`${project.root}/.eslintrc`)) { - eslintrcFilePaths.push(`${project.root}/.eslintrc`); - } - }); - }); - - eslintrcFilePaths.forEach((eslintrcFilePath) => { - rules.push( - updateJsonInTree(eslintrcFilePath as string, (json) => { - if (json.extends) { - if (!Array.isArray(json.extends)) { - json.extends = [json.extends]; - } - - json.extends.push('plugin:cypress/recommended'); - } - - return json; - }) - ); - }); - } - - return chain(rules); -} - -export default () => { - return (host: Tree) => { - const packageJson = readJsonInTree(host, 'package.json'); - if ( - packageJson.devDependencies?.eslint || - packageJson.dependencies?.eslint - ) { - return chain([ - addDepsToPackageJson({}, { 'eslint-plugin-cypress': '^2.10.3' }), - addCypressPluginToEslintrc, - formatFiles(), - ]); - } else { - return noop(); - } - }; -}; diff --git a/packages/devkit/src/migrations/update-14-2-0/split-create-empty-tree.ts b/packages/devkit/src/migrations/update-14-2-0/split-create-empty-tree.ts index 5b74e12c62bbc..fc914c1ae1135 100644 --- a/packages/devkit/src/migrations/update-14-2-0/split-create-empty-tree.ts +++ b/packages/devkit/src/migrations/update-14-2-0/split-create-empty-tree.ts @@ -9,7 +9,7 @@ import { extname } from 'path'; import { tsquery } from '@phenomnomnominal/tsquery'; import { visitNotIgnoredFiles } from '../../generators/visit-not-ignored-files'; -import { formatFiles } from '@nrwl/devkit'; +import { formatFiles } from '../../generators/format-files'; export default async function update(tree: Tree): Promise { for (const [project, { root }] of getProjects(tree)) { diff --git a/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.ts b/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.ts index 729077726f5a8..d69fbb6bc1f5e 100644 --- a/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.ts +++ b/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.ts @@ -1,5 +1,4 @@ import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; -import { JestExecutorOptions } from '@nrwl/jest/src/executors/jest/schema'; import { formatFiles, logger, @@ -10,6 +9,7 @@ import { visitNotIgnoredFiles, } from '@nrwl/devkit'; import { basename } from 'path'; +import { JestExecutorOptions } from '../../executors/jest/schema'; function updateTsConfigsForTests(tree: Tree) { forEachExecutorOptions( diff --git a/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.ts b/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.ts index 46e773d0000fc..618aaa6216173 100644 --- a/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.ts +++ b/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.ts @@ -5,8 +5,8 @@ import { readProjectConfiguration, Tree, } from '@nrwl/devkit'; -import { JestExecutorOptions } from '@nrwl/jest/src/executors/jest/schema'; import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; +import { JestExecutorOptions } from '../../executors/jest/schema'; import { jestConfigObject } from '../../utils/config/functions'; import { nxVersion } from '../../utils/versions'; diff --git a/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts b/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts index c2c4048927401..a5ece8cb0115c 100644 --- a/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts +++ b/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts @@ -6,8 +6,8 @@ import { updateProjectConfiguration, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { jestInitGenerator } from '@nrwl/jest'; import { libraryGenerator as workspaceLib } from '@nrwl/workspace'; +import jestInitGenerator from '../../generators/init/init'; import { updateJestConfigExt } from './update-jest-config-ext'; const setupDefaults = { diff --git a/packages/linter/migrations.json b/packages/linter/migrations.json index b514e893e6e2d..78ca854082abf 100644 --- a/packages/linter/migrations.json +++ b/packages/linter/migrations.json @@ -1,46 +1,5 @@ { "schematics": { - "update-10.3.0": { - "version": "10.3.0-beta.1", - "description": "Update @typescript-eslint to v4.3", - "factory": "./src/migrations/update-10-3-0/update-10-3-0" - }, - "update-eslint-builder-and-config": { - "version": "10.3.0-beta.0", - "description": "Migrate to the new ESLint builder and ESLint config style", - "factory": "./src/migrations/update-10-3-0/update-eslint-builder-and-config" - }, - "add-json-ext-to-eslintrc": { - "version": "10.3.0-beta.2", - "description": "Add explicit .json file extension to .eslintrc files, not using an extension is deprecated", - "factory": "./src/migrations/update-10-3-0/add-json-ext-to-eslintrc" - }, - "add-root-eslintrc-json-to-workspace-implicit-deps": { - "version": "10.3.0-beta.3", - "description": "Update implicitDependencies within nx.json to include root .eslintrc.json", - "factory": "./src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps" - }, - "revert-node-modules-files-in-eslint-builder-options": { - "version": "10.3.1-beta.1", - "description": "Revert any node_modules lintFilesPatterns that were accidentally included by update-eslint-builder-and-config", - "factory": "./src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options" - }, - "update-eslint-configs-to-use-nx-presets": { - "version": "10.4.0-beta.0", - "description": "Update ESLint config files to use preset configs which eslint-plugin-nx exports", - "factory": "./src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets" - }, - "update-root-eslint-config-to-use-overrides": { - "version": "10.4.0-beta.1", - "description": "Update root ESLint config to use overrides", - "factory": "./src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides" - }, - "always-use-project-level-tsconfigs-with-eslint": { - "cli": "nx", - "version": "11.5.0-beta.0", - "description": "Update project .eslintrc.json files to always use project level tsconfigs", - "factory": "./src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint" - }, "remove-eslint-project-config-if-no-type-checking-rules": { "cli": "nx", "version": "12.4.0-beta.0", @@ -97,49 +56,6 @@ } }, "packageJsonUpdates": { - "10.3.0": { - "version": "10.3.0-beta.1", - "packages": { - "@typescript-eslint/parser": { - "version": "4.3.0", - "alwaysAddToPackageJson": false - }, - "@typescript-eslint/eslint-plugin": { - "version": "4.3.0", - "alwaysAddToPackageJson": false - }, - "eslint": { - "version": "7.10.0", - "alwaysAddToPackageJson": false - } - } - }, - "11.5.0": { - "version": "11.5.0-beta.0", - "packages": { - "eslint-config-prettier": { - "version": "8.1.0", - "alwaysAddToPackageJson": false - } - } - }, - "11.6.0": { - "version": "11.6.0-beta.1", - "packages": { - "@typescript-eslint/parser": { - "version": "4.19.0", - "alwaysAddToPackageJson": false - }, - "@typescript-eslint/eslint-plugin": { - "version": "4.19.0", - "alwaysAddToPackageJson": false - }, - "eslint": { - "version": "7.22.0", - "alwaysAddToPackageJson": false - } - } - }, "12.6.0": { "version": "12.6.0-beta.8", "packages": { diff --git a/packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.spec.ts b/packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.spec.ts deleted file mode 100644 index 3d44b7cb793d1..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.spec.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { - readJsonInTree, - readWorkspace, - updateJsonInTree, - updateWorkspace, -} from '@nrwl/workspace'; -import { callRule, createEmptyWorkspace } from '@nrwl/workspace/testing'; -import { runMigration } from '../../utils/testing'; - -describe('Add explicit .json file extension to .eslintrc files', () => { - let tree: Tree; - - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - tree = await callRule( - updateJsonInTree('.eslintrc', () => ({})), - tree - ); - tree = await callRule( - updateWorkspace((workspace) => { - // Old linter builder with ESLint, with explicit config file reference - // that needs to be updated - workspace.projects.add({ - name: 'testProject', - root: 'apps/testProject', - sourceRoot: 'apps/testProject/src', - projectType: 'application', - targets: { - lint: { - builder: '@nrwl/linter:lint', - options: { - linter: 'eslint', - config: '.eslintrc', - tsConfig: [ - 'apps/testProject/tsconfig.app.json', - 'apps/testProject/tsconfig.spec.json', - ], - exclude: ['**/node_modules/**', '!apps/testProject/**/*'], - }, - }, - }, - }); - - // New eslint builder, with explicit config file reference - // that needs to be updated - workspace.projects.add({ - name: 'testProject2', - root: 'apps/testProject2', - sourceRoot: 'apps/testProject2/src', - projectType: 'application', - targets: { - lint: { - builder: '@nrwl/linter:eslint', - options: { - eslintConfig: '.eslintrc', - lintFilePatterns: ['apps/testProject2/**/*.ts'], - }, - }, - }, - }); - }), - tree - ); - tree = await callRule( - updateJsonInTree('apps/testProject/.eslintrc', () => ({})), - tree - ); - tree = await callRule( - updateJsonInTree('apps/testProject2/.eslintrc', () => ({})), - tree - ); - }); - - it('should rename .eslintrc files to .eslintrc.json and update any project configuration references', async () => { - const result = await runMigration('add-json-ext-to-eslintrc', {}, tree); - - const workspace = readWorkspace(tree); - - // ---------------------------------------- Root - expect(() => - readJsonInTree(result, '.eslintrc') - ).toThrowErrorMatchingInlineSnapshot(`"Cannot find .eslintrc"`); - expect(readJsonInTree(result, '.eslintrc.json')).toMatchInlineSnapshot( - `Object {}` - ); - - // ---------------------------------------- testProject - expect(() => - readJsonInTree(result, 'apps/testProject/.eslintrc') - ).toThrowErrorMatchingInlineSnapshot( - `"Cannot find apps/testProject/.eslintrc"` - ); - expect( - readJsonInTree(result, 'apps/testProject/.eslintrc.json') - ).toMatchInlineSnapshot(`Object {}`); - expect( - workspace.projects['testProject'].architect.lint.options.config - ).toEqual('.eslintrc.json'); - - // ---------------------------------------- testProject2 - expect(() => - readJsonInTree(result, 'apps/testProject2/.eslintrc') - ).toThrowErrorMatchingInlineSnapshot( - `"Cannot find apps/testProject2/.eslintrc"` - ); - expect( - readJsonInTree(result, 'apps/testProject2/.eslintrc.json') - ).toMatchInlineSnapshot(`Object {}`); - expect( - workspace.projects['testProject2'].architect.lint.options.eslintConfig - ).toEqual('.eslintrc.json'); - }); -}); diff --git a/packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.ts b/packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.ts deleted file mode 100644 index bb435636c290c..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/add-json-ext-to-eslintrc.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { basename } from '@angular-devkit/core'; -import { chain } from '@angular-devkit/schematics'; -import { - formatFiles, - updateBuilderConfig, - visitNotIgnoredFiles, -} from '@nrwl/workspace'; - -function updateESLintConfigReferencesInWorkspace() { - return updateBuilderConfig( - (options, target, project) => { - if ( - target.builder === '@nrwl/linter:lint' && - options?.linter === 'tslint' - ) { - return options; - } - - if (target.builder === '@nrwl/linter:eslint') { - if (!options.eslintConfig) { - return options; - } - options.eslintConfig = `${options.eslintConfig}.json`; - return options; - } - - if (target.builder === '@nrwl/linter:lint') { - if (!options.config) { - return options; - } - options.config = `${options.config}.json`; - return options; - } - }, - '@nrwl/linter:eslint', - '@nrwl/linter:lint' - ); -} - -function renameESLintConfigFiles() { - return visitNotIgnoredFiles((file, host, context) => { - if (basename(file) !== '.eslintrc') { - return; - } - // Using .eslintrc without an explicit file extension is deprecated - const newFilePath = `${file}.json`; - context.logger.info(`Renaming ${file} to ${newFilePath}`); - try { - return host.rename(file, newFilePath); - } catch (e) { - context.logger.error(e); - } - }); -} - -export default function () { - return chain([ - renameESLintConfigFiles, - updateESLintConfigReferencesInWorkspace, - formatFiles(), - ]); -} diff --git a/packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.spec.ts b/packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.spec.ts deleted file mode 100644 index f59bd832a410c..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { runMigration } from '../../utils/testing'; -import { UnitTestTree } from '@angular-devkit/schematics/testing'; -import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree } from '@nrwl/workspace'; - -describe('Update implicitDependencies within nx.json to include root .eslintrc.json', () => { - let tree: UnitTestTree; - beforeEach(() => { - tree = new UnitTestTree(Tree.empty()); - tree.create( - 'nx.json', - JSON.stringify({ - npmScope: 'nrwl', - implicitDependencies: { - 'workspace.json': '*', - 'package.json': { - dependencies: '*', - devDependencies: '*', - }, - 'tsconfig.base.json': '*', - 'tslint.json': '*', - 'nx.json': '*', - }, - tasksRunnerOptions: {}, - workspaceLayout: { - libsDir: 'packages', - }, - affected: { - defaultBase: 'main', - }, - }) - ); - }); - - it('should add the root .eslintrc.json file to the implicitDependencies in nx.json', async () => { - const result = await runMigration( - 'add-root-eslintrc-json-to-workspace-implicit-deps', - {}, - tree - ); - expect(readJsonInTree(result, 'nx.json').implicitDependencies) - .toMatchInlineSnapshot(` - Object { - ".eslintrc.json": "*", - "nx.json": "*", - "package.json": Object { - "dependencies": "*", - "devDependencies": "*", - }, - "tsconfig.base.json": "*", - "tslint.json": "*", - "workspace.json": "*", - } - `); - }); -}); diff --git a/packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.ts b/packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.ts deleted file mode 100644 index 40dcbe5a39df5..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/add-root-eslintrc-json-to-workspace-implicit-deps.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { chain, noop, Tree } from '@angular-devkit/schematics'; -import { formatFiles, updateJsonInTree } from '@nrwl/workspace'; - -function addRootESLintrcToImplicitDependencies(host: Tree) { - return host.exists('nx.json') - ? updateJsonInTree('nx.json', (json) => { - json.implicitDependencies ||= {}; - json.implicitDependencies['.eslintrc.json'] = '*'; - return json; - }) - : noop(); -} - -export default function () { - return chain([addRootESLintrcToImplicitDependencies, formatFiles()]); -} diff --git a/packages/linter/src/migrations/update-10-3-0/update-10-3-0.spec.ts b/packages/linter/src/migrations/update-10-3-0/update-10-3-0.spec.ts deleted file mode 100644 index c2f00c2176925..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/update-10-3-0.spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { runMigration } from '../../utils/testing'; -import { UnitTestTree } from '@angular-devkit/schematics/testing'; -import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree } from '@nrwl/workspace'; - -describe('Update 10.3.0', () => { - let tree: UnitTestTree; - beforeEach(() => { - tree = new UnitTestTree(Tree.empty()); - tree.create('.eslintrc', '{}'); - }); - - it('should disable the "@typescript-eslint/explicit-module-boundary-types" rule', async () => { - const result = await runMigration('update-10.3.0', {}, tree); - expect( - readJsonInTree(result, '.eslintrc').rules[ - '@typescript-eslint/explicit-module-boundary-types' - ] - ).toEqual('off'); - }); -}); diff --git a/packages/linter/src/migrations/update-10-3-0/update-10-3-0.ts b/packages/linter/src/migrations/update-10-3-0/update-10-3-0.ts deleted file mode 100644 index 566fe7c6a69bf..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/update-10-3-0.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { chain, noop, Tree } from '@angular-devkit/schematics'; -import { - updatePackagesInPackageJson, - formatFiles, - updateJsonInTree, -} from '@nrwl/workspace'; -import { join } from 'path'; - -const updatePackages = updatePackagesInPackageJson( - join(__dirname, '../../..', 'migrations.json'), - '10.3.0' -); - -const addLintRule = (host: Tree) => { - return host.exists('.eslintrc') - ? updateJsonInTree('.eslintrc', (json) => { - json.rules ||= {}; - json.rules['@typescript-eslint/explicit-module-boundary-types'] = 'off'; - return json; - }) - : noop(); -}; - -export default function () { - return chain([updatePackages, addLintRule, formatFiles()]); -} diff --git a/packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.spec.ts b/packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.spec.ts deleted file mode 100644 index 5f8fad348536e..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.spec.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { - readWorkspace, - updateJsonInTree, - updateWorkspace, -} from '@nrwl/workspace'; -import { callRule, createEmptyWorkspace } from '@nrwl/workspace/testing'; -import { runMigration } from '../../utils/testing'; - -describe('Update eslint builder and config for 10.3.0', () => { - let tree: Tree; - - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - tree = await callRule( - updateJsonInTree('.eslintrc', () => ({ - root: true, - parser: '@typescript-eslint/parser', - parserOptions: { - ecmaVersion: 2018, - sourceType: 'module', - project: './tsconfig.*?.json', - }, - ignorePatterns: ['**/*'], - plugins: ['@typescript-eslint', '@nrwl/nx'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'prettier/@typescript-eslint', - ], - rules: { - '@typescript-eslint/explicit-member-accessibility': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/no-parameter-properties': 'off', - '@nrwl/nx/enforce-module-boundaries': [ - 'error', - { - enforceBuildableLibDependency: true, - allow: [], - depConstraints: [ - { sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }, - ], - }, - ], - }, - overrides: [ - { - files: ['*.tsx'], - rules: { - '@typescript-eslint/no-unused-vars': 'off', - }, - }, - ], - })), - tree - ); - tree = await callRule( - updateWorkspace((workspace) => { - workspace.projects.add({ - name: 'testProject', - root: 'apps/testProject', - sourceRoot: 'apps/testProject/src', - projectType: 'application', - targets: { - lint: { - builder: '@nrwl/linter:lint', - options: { - linter: 'eslint', - tsConfig: [ - 'apps/testProject/tsconfig.app.json', - 'apps/testProject/tsconfig.spec.json', - ], - exclude: ['**/node_modules/**', '!apps/testProject/**/*'], - }, - }, - }, - }); - }), - tree - ); - tree = await callRule( - updateJsonInTree('apps/testProject/tsconfig.app.json', () => ({ - include: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'], - files: [ - // We want to include this custom file - './some-random-relative-file.ts', - // We don't want to include these files from node_modules - '../../node_modules/@nrwl/react/typings/cssmodule.d.ts', - '../../node_modules/@nrwl/react/typings/image.d.ts', - ], - })), - tree - ); - tree = await callRule( - updateJsonInTree('apps/testProject/tsconfig.json', () => ({ - include: ['something-ad-hoc/**/*.ts'], - })), - tree - ); - tree = await callRule( - updateJsonInTree('apps/testProject/tsconfig.spec.json', () => ({ - include: [ - '**/*.spec.ts', - '**/*.spec.tsx', - '**/*.spec.js', - '**/*.spec.jsx', - '**/*.d.ts', - ], - })), - tree - ); - }); - - it('should migrate the lint builder usage to the new eslint builder', async () => { - await runMigration('update-eslint-builder-and-config', {}, tree); - - const workspace = readWorkspace(tree); - - expect(workspace.projects['testProject']).toMatchInlineSnapshot(` - Object { - "architect": Object { - "lint": Object { - "builder": "@nrwl/linter:eslint", - "options": Object { - "lintFilePatterns": Array [ - "apps/testProject/**/*.js", - "apps/testProject/**/*.jsx", - "apps/testProject/**/*.ts", - "apps/testProject/**/*.tsx", - "apps/testProject/some-random-relative-file.ts", - "apps/testProject/something-ad-hoc/**/*.ts", - "apps/testProject/**/*.spec.ts", - "apps/testProject/**/*.spec.tsx", - "apps/testProject/**/*.spec.js", - "apps/testProject/**/*.spec.jsx", - "apps/testProject/**/*.d.ts", - ], - }, - }, - }, - "projectType": "application", - "root": "apps/testProject", - "sourceRoot": "apps/testProject/src", - } - `); - }); -}); diff --git a/packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.ts b/packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.ts deleted file mode 100644 index 621635a7dc52c..0000000000000 --- a/packages/linter/src/migrations/update-10-3-0/update-eslint-builder-and-config.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { chain, Tree } from '@angular-devkit/schematics'; -import { - formatFiles, - readJsonInTree, - updateBuilderConfig, -} from '@nrwl/workspace'; -import { join, normalize } from '@angular-devkit/core'; - -/** - * When migrating projects we need to look up any relevant tsconfig files - * to figure out what glob patterns will stand the best chance of keeping - * the file includes behavior as consistent as possible, before and after - * the migration. - */ -function updateESLintBuilder(host: Tree) { - return updateBuilderConfig((options, target, project) => { - if (options.linter === 'tslint') { - return options; - } - target.builder = '@nrwl/linter:eslint'; - - const tsconfigs = []; - - if (options.tsConfig) { - const normalizedTsConfigOption = Array.isArray(options.tsConfig) - ? options.tsConfig - : [options.tsConfig]; - normalizedTsConfigOption.forEach((tsConfigPath) => { - try { - tsconfigs.push(readJsonInTree(host, tsConfigPath as string)); - } catch {} - try { - tsconfigs.push(readJsonInTree(host, `${project.root}/tsconfig.json`)); - } catch {} - }); - } else { - try { - tsconfigs.push(readJsonInTree(host, `${project.root}/tsconfig.json`)); - } catch {} - try { - tsconfigs.push( - readJsonInTree(host, `${project.root}/tsconfig.app.json`) - ); - } catch {} - try { - tsconfigs.push( - readJsonInTree(host, `${project.root}/tsconfig.lib.json`) - ); - } catch {} - try { - tsconfigs.push( - readJsonInTree(host, `${project.root}/tsconfig.spec.json`) - ); - } catch {} - try { - tsconfigs.push( - readJsonInTree(host, `${project.root}/tsconfig.e2e.json`) - ); - } catch {} - } - - const defaultLintFilePatterns = [`${project.root}/**/*.ts`]; - - // Merge any available `includes` and `files` from the tsconfig files - let lintFilePatterns = !tsconfigs.length - ? defaultLintFilePatterns - : tsconfigs - .map((tsconfig) => { - return [...(tsconfig.include || []), ...(tsconfig.files || [])]; - }) - .reduce((flat, val) => flat.concat(val), []) - .map((pattern) => join(normalize(project.root), pattern)) - /** - * Exclude any files coming from node_modules, they will be ignored by ESLint - * and it will print a warning about it. We shouldn't be spending time linting - * 3rd party files anyway, and if they are relevant to the TypeScript Program - * for the linting run they will still be included in that. - */ - .filter((pattern) => !pattern.includes('node_modules')); - - lintFilePatterns = [...new Set(lintFilePatterns)]; - - return { lintFilePatterns }; - }, '@nrwl/linter:lint'); -} - -export default function () { - return chain([updateESLintBuilder, formatFiles()]); -} diff --git a/packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.spec.ts b/packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.spec.ts deleted file mode 100644 index 15526b6495041..0000000000000 --- a/packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.spec.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readWorkspace, updateWorkspace } from '@nrwl/workspace'; -import { callRule, createEmptyWorkspace } from '@nrwl/workspace/testing'; -import { runMigration } from '../../utils/testing'; - -describe('Revert any node_modules lintFilesPatterns that were accidentally included by update-eslint-builder-and-config', () => { - let tree: Tree; - - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - tree = await callRule( - updateWorkspace((workspace) => { - workspace.projects.add({ - name: 'testProject', - root: 'apps/testProject', - sourceRoot: 'apps/testProject/src', - projectType: 'application', - targets: { - lint: { - builder: '@nrwl/linter:eslint', - options: { - lintFilePatterns: [ - 'apps/testProject/**/*.js', - 'apps/testProject/**/*.jsx', - 'apps/testProject/**/*.ts', - 'apps/testProject/**/*.tsx', - 'apps/testProject/some-random-relative-file.ts', - 'apps/testProject/something-ad-hoc/**/*.ts', - 'apps/testProject/**/*.spec.ts', - 'apps/testProject/**/*.spec.tsx', - 'apps/testProject/**/*.spec.js', - 'apps/testProject/**/*.spec.jsx', - 'apps/testProject/**/*.d.ts', - // These two should be removed by the migration - 'node_modules/@nrwl/react/typings/cssmodule.d.ts', - 'node_modules/@nrwl/react/typings/image.d.ts', - ], - }, - }, - }, - }); - }), - tree - ); - }); - - it('should remove any patterns starting with node_modules from the lintFilePatterns array', async () => { - await runMigration( - 'revert-node-modules-files-in-eslint-builder-options', - {}, - tree - ); - - const workspace = readWorkspace(tree); - - expect(workspace.projects['testProject'].architect.lint) - .toMatchInlineSnapshot(` - Object { - "builder": "@nrwl/linter:eslint", - "options": Object { - "lintFilePatterns": Array [ - "apps/testProject/**/*.js", - "apps/testProject/**/*.jsx", - "apps/testProject/**/*.ts", - "apps/testProject/**/*.tsx", - "apps/testProject/some-random-relative-file.ts", - "apps/testProject/something-ad-hoc/**/*.ts", - "apps/testProject/**/*.spec.ts", - "apps/testProject/**/*.spec.tsx", - "apps/testProject/**/*.spec.js", - "apps/testProject/**/*.spec.jsx", - "apps/testProject/**/*.d.ts", - ], - }, - } - `); - }); -}); diff --git a/packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.ts b/packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.ts deleted file mode 100644 index b3a1835c7f0f8..0000000000000 --- a/packages/linter/src/migrations/update-10-3-1/revert-node-modules-files-in-eslint-builder-options.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { chain } from '@angular-devkit/schematics'; -import { formatFiles, updateBuilderConfig } from '@nrwl/workspace'; - -/** - * The migration for v10.3.0 called "update-eslint-builder-and-config" initially had a bug - * where it included files from node_modules in the `lintFilePatterns` option if they were - * explicitly included in any of the relevant tsconfig files. - * - * This has now been fixed in the original migration, but this extra migration will handle - * fixing up any setups which migrated in the interim and are currently experiencing lint - * warnings as a result. - */ -function updateESLintBuilder() { - return updateBuilderConfig((options) => { - const lintFilePatterns: string[] = - (options.lintFilePatterns as string[]) || []; - return { - ...options, - lintFilePatterns: lintFilePatterns.filter( - (pattern) => !pattern.includes('node_modules') - ), - }; - }, '@nrwl/linter:eslint'); -} - -export default function () { - return chain([updateESLintBuilder, formatFiles()]); -} diff --git a/packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.spec.ts b/packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.spec.ts deleted file mode 100644 index 176669ada2d81..0000000000000 --- a/packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.spec.ts +++ /dev/null @@ -1,899 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree, updateWorkspace } from '@nrwl/workspace'; -import { callRule, createEmptyWorkspace } from '@nrwl/workspace/testing'; -import type { Linter } from 'eslint'; -import { runMigration } from '../../utils/testing'; -import { - updateExtendsAndRemoveDuplication, - updateObjPropAndRemoveDuplication, - updateOverridesAndRemoveDuplication, - updateParserOptionsAndRemoveDuplication, - updatePluginsAndRemoveDuplication, -} from './update-eslint-configs-to-use-nx-presets'; - -describe('Update ESLint config files to use preset configs which eslint-plugin-nx exports', () => { - let tree: Tree; - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - tree = await callRule( - updateWorkspace((workspace) => { - workspace.projects.add({ - name: 'reactapp', - root: 'apps/reactapp', - sourceRoot: 'apps/reactapp/src', - projectType: 'application', - targets: {}, - }); - workspace.projects.add({ - name: 'notreactapp', - root: 'apps/notreactapp', - sourceRoot: 'apps/notreactapp/src', - projectType: 'application', - targets: {}, - }); - workspace.projects.add({ - name: 'reactlib', - root: 'libs/reactlib', - sourceRoot: 'apps/reactlib/src', - projectType: 'library', - targets: {}, - }); - workspace.projects.add({ - name: 'notreactlib', - root: 'libs/notreactlib', - sourceRoot: 'apps/notreactlib/src', - projectType: 'library', - targets: {}, - }); - }), - tree - ); - }); - - it('should update the current (v10.3.0) root .eslintrc.json file to the use the eslint-plugin-nx shared config', async () => { - tree.create( - '.eslintrc.json', - JSON.stringify({ - root: true, - parser: '@typescript-eslint/parser', - parserOptions: { - ecmaVersion: 2018, - sourceType: 'module', - project: './tsconfig.*?.json', - }, - ignorePatterns: ['**/*'], - plugins: ['@typescript-eslint', '@nrwl/nx'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'prettier/@typescript-eslint', - ], - rules: { - '@typescript-eslint/explicit-member-accessibility': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/no-parameter-properties': 'off', - '@nrwl/nx/enforce-module-boundaries': [ - 'error', - { - enforceBuildableLibDependency: true, - allow: [], - depConstraints: [ - { sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }, - ], - }, - ], - }, - overrides: [ - { - files: ['*.tsx'], - rules: { - '@typescript-eslint/no-unused-vars': 'off', - }, - }, - ], - }) - ); - - const result = await runMigration( - 'update-eslint-configs-to-use-nx-presets', - {}, - tree - ); - expect(readJsonInTree(result, '.eslintrc.json')).toMatchInlineSnapshot(` - Object { - "extends": Array [ - "plugin:@nrwl/nx/typescript", - ], - "ignorePatterns": Array [ - "**/*", - ], - "parserOptions": Object { - "project": "./tsconfig.*?.json", - }, - "plugins": Array [ - "@nrwl/nx", - ], - "root": true, - "rules": Object { - "@nrwl/nx/enforce-module-boundaries": Array [ - "error", - Object { - "allow": Array [], - "depConstraints": Array [ - Object { - "onlyDependOnLibsWithTags": Array [ - "*", - ], - "sourceTag": "*", - }, - ], - "enforceBuildableLibDependency": true, - }, - ], - }, - } - `); - }); - - it('should update any react eslint configs to use the appropriate shareable config', async () => { - const reactESLintConfig = { - rules: { - 'array-callback-return': 'warn', - 'dot-location': ['warn', 'property'], - eqeqeq: ['warn', 'smart'], - 'new-parens': 'warn', - 'no-caller': 'warn', - 'no-cond-assign': ['warn', 'except-parens'], - 'no-const-assign': 'warn', - 'no-control-regex': 'warn', - 'no-delete-var': 'warn', - 'no-dupe-args': 'warn', - 'no-dupe-keys': 'warn', - 'no-duplicate-case': 'warn', - 'no-empty-character-class': 'warn', - 'no-empty-pattern': 'warn', - 'no-eval': 'warn', - 'no-ex-assign': 'warn', - 'no-extend-native': 'warn', - 'no-extra-bind': 'warn', - 'no-extra-label': 'warn', - 'no-fallthrough': 'warn', - 'no-func-assign': 'warn', - 'no-implied-eval': 'warn', - 'no-invalid-regexp': 'warn', - 'no-iterator': 'warn', - 'no-label-var': 'warn', - 'no-labels': ['warn', { allowLoop: true, allowSwitch: false }], - 'no-lone-blocks': 'warn', - 'no-loop-func': 'warn', - 'no-mixed-operators': [ - 'warn', - { - groups: [ - ['&', '|', '^', '~', '<<', '>>', '>>>'], - ['==', '!=', '===', '!==', '>', '>=', '<', '<='], - ['&&', '||'], - ['in', 'instanceof'], - ], - allowSamePrecedence: false, - }, - ], - 'no-multi-str': 'warn', - 'no-native-reassign': 'warn', - 'no-negated-in-lhs': 'warn', - 'no-new-func': 'warn', - 'no-new-object': 'warn', - 'no-new-symbol': 'warn', - 'no-new-wrappers': 'warn', - 'no-obj-calls': 'warn', - 'no-octal': 'warn', - 'no-octal-escape': 'warn', - 'no-redeclare': 'warn', - 'no-regex-spaces': 'warn', - 'no-restricted-syntax': ['warn', 'WithStatement'], - 'no-script-url': 'warn', - 'no-self-assign': 'warn', - 'no-self-compare': 'warn', - 'no-sequences': 'warn', - 'no-shadow-restricted-names': 'warn', - 'no-sparse-arrays': 'warn', - 'no-template-curly-in-string': 'warn', - 'no-this-before-super': 'warn', - 'no-throw-literal': 'warn', - 'no-restricted-globals': [ - 'error', - 'addEventListener', - 'blur', - 'close', - 'closed', - 'confirm', - 'defaultStatus', - 'defaultstatus', - 'event', - 'external', - 'find', - 'focus', - 'frameElement', - 'frames', - 'history', - 'innerHeight', - 'innerWidth', - 'length', - 'location', - 'locationbar', - 'menubar', - 'moveBy', - 'moveTo', - 'name', - 'onblur', - 'onerror', - 'onfocus', - 'onload', - 'onresize', - 'onunload', - 'open', - 'opener', - 'opera', - 'outerHeight', - 'outerWidth', - 'pageXOffset', - 'pageYOffset', - 'parent', - 'print', - 'removeEventListener', - 'resizeBy', - 'resizeTo', - 'screen', - 'screenLeft', - 'screenTop', - 'screenX', - 'screenY', - 'scroll', - 'scrollbars', - 'scrollBy', - 'scrollTo', - 'scrollX', - 'scrollY', - 'self', - 'status', - 'statusbar', - 'stop', - 'toolbar', - 'top', - ], - 'no-unexpected-multiline': 'warn', - 'no-unreachable': 'warn', - 'no-unused-expressions': 'off', - 'no-unused-labels': 'warn', - 'no-useless-computed-key': 'warn', - 'no-useless-concat': 'warn', - 'no-useless-escape': 'warn', - 'no-useless-rename': [ - 'warn', - { - ignoreDestructuring: false, - ignoreImport: false, - ignoreExport: false, - }, - ], - 'no-with': 'warn', - 'no-whitespace-before-property': 'warn', - 'react-hooks/exhaustive-deps': 'warn', - 'require-yield': 'warn', - 'rest-spread-spacing': ['warn', 'never'], - strict: ['warn', 'never'], - 'unicode-bom': ['warn', 'never'], - 'use-isnan': 'warn', - 'valid-typeof': 'warn', - 'no-restricted-properties': [ - 'error', - { - object: 'require', - property: 'ensure', - message: - 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', - }, - { - object: 'System', - property: 'import', - message: - 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', - }, - ], - 'getter-return': 'warn', - 'import/first': 'error', - 'import/no-amd': 'error', - 'import/no-webpack-loader-syntax': 'error', - 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }], - 'react/jsx-no-comment-textnodes': 'warn', - 'react/jsx-no-duplicate-props': 'warn', - 'react/jsx-no-target-blank': 'warn', - 'react/jsx-no-undef': 'error', - 'react/jsx-pascal-case': ['warn', { allowAllCaps: true, ignore: [] }], - 'react/jsx-uses-react': 'warn', - 'react/jsx-uses-vars': 'warn', - 'react/no-danger-with-children': 'warn', - 'react/no-direct-mutation-state': 'warn', - 'react/no-is-mounted': 'warn', - 'react/no-typos': 'error', - 'react/react-in-jsx-scope': 'error', - 'react/require-render-return': 'error', - 'react/style-prop-object': 'warn', - 'react/jsx-no-useless-fragment': 'warn', - 'jsx-a11y/accessible-emoji': 'warn', - 'jsx-a11y/alt-text': 'warn', - 'jsx-a11y/anchor-has-content': 'warn', - 'jsx-a11y/anchor-is-valid': [ - 'warn', - { aspects: ['noHref', 'invalidHref'] }, - ], - 'jsx-a11y/aria-activedescendant-has-tabindex': 'warn', - 'jsx-a11y/aria-props': 'warn', - 'jsx-a11y/aria-proptypes': 'warn', - 'jsx-a11y/aria-role': 'warn', - 'jsx-a11y/aria-unsupported-elements': 'warn', - 'jsx-a11y/heading-has-content': 'warn', - 'jsx-a11y/iframe-has-title': 'warn', - 'jsx-a11y/img-redundant-alt': 'warn', - 'jsx-a11y/no-access-key': 'warn', - 'jsx-a11y/no-distracting-elements': 'warn', - 'jsx-a11y/no-redundant-roles': 'warn', - 'jsx-a11y/role-has-required-aria-props': 'warn', - 'jsx-a11y/role-supports-aria-props': 'warn', - 'jsx-a11y/scope': 'warn', - 'react-hooks/rules-of-hooks': 'error', - 'default-case': 'off', - 'no-dupe-class-members': 'off', - 'no-undef': 'off', - '@typescript-eslint/consistent-type-assertions': 'warn', - 'no-array-constructor': 'off', - '@typescript-eslint/no-array-constructor': 'warn', - '@typescript-eslint/no-namespace': 'error', - 'no-use-before-define': 'off', - '@typescript-eslint/no-use-before-define': [ - 'warn', - { - functions: false, - classes: false, - variables: false, - typedefs: false, - }, - ], - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': [ - 'warn', - { args: 'none', ignoreRestSiblings: true }, - ], - 'no-useless-constructor': 'off', - '@typescript-eslint/no-useless-constructor': 'warn', - '@typescript-eslint/no-unused-expressions': [ - 'error', - { - allowShortCircuit: true, - allowTernary: true, - allowTaggedTemplates: true, - }, - ], - }, - env: { - browser: true, - commonjs: true, - es6: true, - jest: true, - node: true, - }, - settings: { react: { version: 'detect' } }, - plugins: ['import', 'jsx-a11y', 'react', 'react-hooks'], - extends: ['../../.eslintrc'], - ignorePatterns: ['!**/*'], - }; - - const notReactESLintConfig = { - extends: ['../../.eslintrc'], - ignorePatterns: ['!**/*'], - rules: { - foo: ['error'], - }, - }; - - tree.create( - 'apps/reactapp/.eslintrc.json', - JSON.stringify(reactESLintConfig) - ); - - tree.create( - 'apps/notreactapp/.eslintrc.json', - JSON.stringify(notReactESLintConfig) - ); - - tree.create( - 'libs/reactlib/.eslintrc.json', - JSON.stringify(reactESLintConfig) - ); - - tree.create( - 'libs/notreactlib/.eslintrc.json', - JSON.stringify(notReactESLintConfig) - ); - - const result = await runMigration( - 'update-eslint-configs-to-use-nx-presets', - {}, - tree - ); - - expect(readJsonInTree(result, 'apps/reactapp/.eslintrc.json')) - .toMatchInlineSnapshot(` - Object { - "extends": Array [ - "plugin:@nrwl/nx/react", - "../../.eslintrc", - ], - "ignorePatterns": Array [ - "!**/*", - ], - "rules": Object {}, - } - `); - - expect(readJsonInTree(result, 'libs/reactlib/.eslintrc.json')) - .toMatchInlineSnapshot(` - Object { - "extends": Array [ - "plugin:@nrwl/nx/react", - "../../.eslintrc", - ], - "ignorePatterns": Array [ - "!**/*", - ], - "rules": Object {}, - } - `); - - // No change expected in non-react projects - expect(readJsonInTree(result, 'apps/notreactapp/.eslintrc.json')).toEqual( - notReactESLintConfig - ); - expect(readJsonInTree(result, 'libs/notreactlib/.eslintrc.json')).toEqual( - notReactESLintConfig - ); - }); - - describe('utils', () => { - describe('updatePluginsAndRemoveDuplication()', () => { - interface TestCase { - json: Linter.Config; - configBeingExtended: Linter.Config; - ensurePlugin: string; - expectedJSON: Linter.Config; - } - - const testCases: TestCase[] = [ - { - json: { - plugins: [], - }, - configBeingExtended: { - plugins: ['@typescript-eslint'], - }, - ensurePlugin: '@nrwl/nx', - expectedJSON: { - plugins: ['@nrwl/nx'], - }, - }, - { - json: {}, - configBeingExtended: { - plugins: ['@typescript-eslint'], - }, - ensurePlugin: '@nrwl/nx', - expectedJSON: { - plugins: ['@nrwl/nx'], - }, - }, - { - json: { - plugins: ['@typescript-eslint', '@nrwl/nx'], - }, - configBeingExtended: { - plugins: ['@typescript-eslint'], - }, - ensurePlugin: '@nrwl/nx', - expectedJSON: { - plugins: ['@nrwl/nx'], - }, - }, - { - json: { - plugins: ['@typescript-eslint', 'some-entirely-custom-user-plugin'], - }, - configBeingExtended: { - plugins: ['@typescript-eslint'], - }, - ensurePlugin: '@nrwl/nx', - expectedJSON: { - plugins: ['@nrwl/nx', 'some-entirely-custom-user-plugin'], - }, - }, - ]; - - testCases.forEach((tc, i) => { - it(`should remove duplication between the plugins array of the first-party config and the config being extended, CASE ${i}`, () => { - updatePluginsAndRemoveDuplication( - tc.json, - tc.configBeingExtended, - true, - tc.ensurePlugin - ); - expect(tc.json).toEqual(tc.expectedJSON); - }); - }); - }); - - describe('updateExtendsAndRemoveDuplication()', () => { - interface TestCase { - json: Linter.Config; - configBeingExtended: Linter.Config; - extendsToAdd: string; - expectedJSON: Linter.Config; - } - - const testCases: TestCase[] = [ - { - json: { - extends: 'eslint:recommended', - }, - configBeingExtended: { - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'prettier/@typescript-eslint', - ], - }, - extendsToAdd: 'plugin:@nrwl/nx/typescript', - expectedJSON: { - extends: ['plugin:@nrwl/nx/typescript'], - }, - }, - { - json: { - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'prettier/@typescript-eslint', - ], - }, - configBeingExtended: { - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'prettier/@typescript-eslint', - ], - }, - extendsToAdd: 'plugin:@nrwl/nx/typescript', - expectedJSON: { - extends: ['plugin:@nrwl/nx/typescript'], - }, - }, - { - json: { - extends: ['eslint:recommended', 'something-custom'], - }, - configBeingExtended: { - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'prettier/@typescript-eslint', - ], - }, - extendsToAdd: 'plugin:@nrwl/nx/typescript', - expectedJSON: { - extends: ['plugin:@nrwl/nx/typescript', 'something-custom'], - }, - }, - ]; - - testCases.forEach((tc, i) => { - it(`should remove duplication between the extends array of the first-party config and the config being extended, CASE ${i}`, () => { - updateExtendsAndRemoveDuplication( - tc.json, - tc.configBeingExtended, - true, - tc.extendsToAdd - ); - expect(tc.json).toEqual(tc.expectedJSON); - }); - }); - }); - - describe('updateParserOptionsAndRemoveDuplication()', () => { - interface TestCase { - json: Linter.Config; - configBeingExtended: Linter.Config; - expectedJSON: Linter.Config; - } - - const testCases: TestCase[] = [ - { - json: {}, - configBeingExtended: {}, - expectedJSON: { - parserOptions: {}, - }, - }, - { - json: { - parserOptions: { - ecmaVersion: 2018, - }, - }, - configBeingExtended: { - parserOptions: { - ecmaVersion: 2020, - }, - }, - expectedJSON: { - parserOptions: {}, - }, - }, - { - json: { - parserOptions: { - // Strings will work (in spite of the type info) - ecmaVersion: '2020' as any, - }, - }, - configBeingExtended: { - parserOptions: { - ecmaVersion: 2020, - }, - }, - expectedJSON: { - parserOptions: {}, - }, - }, - { - json: { - parserOptions: { - // Made up value - ecmaVersion: 2021 as any, - }, - }, - configBeingExtended: { - parserOptions: { - ecmaVersion: 2020, - }, - }, - expectedJSON: { - parserOptions: { - // Made up value - ecmaVersion: 2021 as any, - }, - }, - }, - { - json: { - parserOptions: { - project: './tsconfig.*?.json', - sourceType: 'module', - }, - }, - configBeingExtended: { - parserOptions: { - sourceType: 'module', - foo: true, - bar: true, - }, - }, - expectedJSON: { - parserOptions: { - project: './tsconfig.*?.json', - }, - }, - }, - ]; - - testCases.forEach((tc, i) => { - it(`should remove duplication between the parserOptions of the first-party config and the config being extended, CASE ${i}`, () => { - updateParserOptionsAndRemoveDuplication( - tc.json, - tc.configBeingExtended - ); - expect(tc.json).toEqual(tc.expectedJSON); - }); - }); - }); - - describe('updateObjPropAndRemoveDuplication()', () => { - interface TestCase { - json: Linter.Config; - configBeingExtended: Linter.Config; - objPropName: string; - deleteIfUltimatelyEmpty: boolean; - expectedJSON: Linter.Config; - } - - const testCases: TestCase[] = [ - { - json: {}, - configBeingExtended: {}, - objPropName: 'rules', - deleteIfUltimatelyEmpty: false, - expectedJSON: { - rules: {}, - }, - }, - { - json: {}, - configBeingExtended: {}, - objPropName: 'rules', - deleteIfUltimatelyEmpty: true, - expectedJSON: {}, - }, - { - json: { - rules: { - '@typescript-eslint/explicit-member-accessibility': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/no-parameter-properties': 'off', - }, - }, - configBeingExtended: { - rules: { - '@typescript-eslint/explicit-member-accessibility': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/no-parameter-properties': 'off', - }, - }, - objPropName: 'rules', - deleteIfUltimatelyEmpty: false, - expectedJSON: { - rules: {}, - }, - }, - { - json: { - rules: { - 'extra-rule-in-first-party': 'error', - 'rule-1-same-despite-options-order': [ - 'error', - { configOption1: true, configOption2: 'SOMETHING' }, - ], - 'rule-2-different-severity': ['off'], - 'rule-3-same-severity-different-options': [ - 'error', - { - a: false, - }, - ], - }, - }, - configBeingExtended: { - rules: { - 'extra-rule-in-extended': 'error', - 'rule-1-same-despite-options-order': [ - 'error', - { configOption2: 'SOMETHING', configOption1: true }, - ], - 'rule-2-different-severity': ['error'], - 'rule-3-same-severity-different-options': [ - 'error', - { - a: true, - }, - ], - }, - }, - objPropName: 'rules', - deleteIfUltimatelyEmpty: false, - expectedJSON: { - rules: { - 'extra-rule-in-first-party': 'error', - 'rule-2-different-severity': ['off'], - 'rule-3-same-severity-different-options': [ - 'error', - { - a: false, - }, - ], - }, - }, - }, - { - json: { - settings: { react: { version: 'detect' } }, - }, - configBeingExtended: { - settings: { react: { version: 'detect' } }, - }, - objPropName: 'settings', - deleteIfUltimatelyEmpty: true, - expectedJSON: {}, - }, - { - json: { - // Different env in first party config - env: { - browser: true, - commonjs: false, - es6: false, - jest: true, - node: true, - }, - }, - configBeingExtended: { - env: { - browser: true, - commonjs: true, - es6: true, - jest: true, - node: false, - }, - }, - objPropName: 'env', - deleteIfUltimatelyEmpty: true, - expectedJSON: { - env: { - commonjs: false, - es6: false, - node: true, - }, - }, - }, - ]; - - testCases.forEach((tc, i) => { - it(`should remove duplication between the object property of the first-party config and the config being extended, CASE ${i}`, () => { - updateObjPropAndRemoveDuplication( - tc.json, - tc.configBeingExtended, - tc.objPropName, - tc.deleteIfUltimatelyEmpty - ); - expect(tc.json).toEqual(tc.expectedJSON); - }); - }); - }); - - describe('updateOverridesAndRemoveDuplication()', () => { - interface TestCase { - json: Linter.Config; - configBeingExtended: Linter.Config; - expectedJSON: Linter.Config; - } - - const testCases: TestCase[] = [ - { - json: {}, - configBeingExtended: {}, - expectedJSON: {}, - }, - ]; - - testCases.forEach((tc, i) => { - it(`should remove duplication between the overrides of the first-party config and the config being extended, CASE ${i}`, () => { - updateOverridesAndRemoveDuplication( - tc.json, - tc.configBeingExtended, - true - ); - expect(tc.json).toEqual(tc.expectedJSON); - }); - }); - }); - }); -}); diff --git a/packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.ts b/packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.ts deleted file mode 100644 index db980413970a1..0000000000000 --- a/packages/linter/src/migrations/update-10-4-0/update-eslint-configs-to-use-nx-presets.ts +++ /dev/null @@ -1,541 +0,0 @@ -import { join, normalize } from '@angular-devkit/core'; -import { chain, noop, Tree } from '@angular-devkit/schematics'; -import { formatFiles, readWorkspace, updateJsonInTree } from '@nrwl/workspace'; -import * as assert from 'assert'; -import type { Linter } from 'eslint'; - -/** - * We want to update the JSON in such a way that we: - * - extend from our Nx shareable configs where applicable - * - remove as much duplication between the JSON and the underlying - * shareable config as is safely possible - */ -function updateRootESLintConfig(host: Tree) { - return host.exists('.eslintrc.json') - ? updateJsonInTree('.eslintrc.json', (json) => { - updateExtendsAndRemoveDuplication( - json, - currentTypescriptConfig, - true, - 'plugin:@nrwl/nx/typescript' - ); - - /** - * We always want to explicitly include the @nrwl/nx plugin - * because we continue to use the @nrwl/nx/enforce-module-boundaries - * in the first party config and it helps make things clearer - */ - updatePluginsAndRemoveDuplication( - json, - currentTypescriptConfig, - true, - '@nrwl/nx' - ); - - updateParserOptionsAndRemoveDuplication(json, currentTypescriptConfig); - - /** - * In the case of the existing Nx root .eslintrc.json out of the box, - * there is a single overrides for .tsx files. This is now covered - * by the shared config, so if the user still has that defined we can - * also remove that safely. - */ - updateOverridesAndRemoveDuplication( - json, - currentTypescriptConfig, - true - ); - - updateObjPropAndRemoveDuplication( - json, - currentTypescriptConfig, - 'rules', - false - ); - - if (json.parser === currentTypescriptConfig.parser) { - delete json.parser; - } - - return json; - }) - : noop(); -} - -function updateReactESLintConfigs(host: Tree) { - const workspace = readWorkspace(host); - return chain([ - ...Object.keys(workspace.projects).map((k) => { - const p = workspace.projects[k]; - const eslintConfigPath = join(normalize(p.root), '.eslintrc.json'); - - if (!host.exists(eslintConfigPath)) { - return noop(); - } - - return updateJsonInTree(eslintConfigPath, (json) => { - /** - * There isn't a way to know for sure if a project was started with the Nx - * original inline React ESLint config (for applications it is easy to know - * from the project configuration, but that is not the case for all libraries). - * - * We therefore try and infer it based on the presence of react eslint plugins - * within the config that is currently there. - */ - if ( - json.plugins?.includes('react') || - json.plugins?.includes('react-hooks') || - json.plugins?.includes('jsx-a11y') - ) { - updateExtendsAndRemoveDuplication( - json, - currentReactConfig, - true, - 'plugin:@nrwl/nx/react' - ); - - updatePluginsAndRemoveDuplication(json, currentReactConfig, true); - - updateObjPropAndRemoveDuplication( - json, - currentReactConfig, - 'rules', - false - ); - - updateObjPropAndRemoveDuplication( - json, - currentReactConfig, - 'env', - true - ); - - updateObjPropAndRemoveDuplication( - json, - currentReactConfig, - 'settings', - true - ); - } - return json; - }); - }), - ]); -} - -export default function () { - return chain([ - updateRootESLintConfig, - updateReactESLintConfigs, - formatFiles(), - ]); -} - -const currentReactConfig: Linter.Config = { - rules: { - 'array-callback-return': 'warn', - 'dot-location': ['warn', 'property'], - eqeqeq: ['warn', 'smart'], - 'new-parens': 'warn', - 'no-caller': 'warn', - 'no-cond-assign': ['warn', 'except-parens'], - 'no-const-assign': 'warn', - 'no-control-regex': 'warn', - 'no-delete-var': 'warn', - 'no-dupe-args': 'warn', - 'no-dupe-keys': 'warn', - 'no-duplicate-case': 'warn', - 'no-empty-character-class': 'warn', - 'no-empty-pattern': 'warn', - 'no-eval': 'warn', - 'no-ex-assign': 'warn', - 'no-extend-native': 'warn', - 'no-extra-bind': 'warn', - 'no-extra-label': 'warn', - 'no-fallthrough': 'warn', - 'no-func-assign': 'warn', - 'no-implied-eval': 'warn', - 'no-invalid-regexp': 'warn', - 'no-iterator': 'warn', - 'no-label-var': 'warn', - 'no-labels': ['warn', { allowLoop: true, allowSwitch: false }], - 'no-lone-blocks': 'warn', - 'no-loop-func': 'warn', - 'no-mixed-operators': [ - 'warn', - { - groups: [ - ['&', '|', '^', '~', '<<', '>>', '>>>'], - ['==', '!=', '===', '!==', '>', '>=', '<', '<='], - ['&&', '||'], - ['in', 'instanceof'], - ], - allowSamePrecedence: false, - }, - ], - 'no-multi-str': 'warn', - 'no-native-reassign': 'warn', - 'no-negated-in-lhs': 'warn', - 'no-new-func': 'warn', - 'no-new-object': 'warn', - 'no-new-symbol': 'warn', - 'no-new-wrappers': 'warn', - 'no-obj-calls': 'warn', - 'no-octal': 'warn', - 'no-octal-escape': 'warn', - 'no-redeclare': 'warn', - 'no-regex-spaces': 'warn', - 'no-restricted-syntax': ['warn', 'WithStatement'], - 'no-script-url': 'warn', - 'no-self-assign': 'warn', - 'no-self-compare': 'warn', - 'no-sequences': 'warn', - 'no-shadow-restricted-names': 'warn', - 'no-sparse-arrays': 'warn', - 'no-template-curly-in-string': 'warn', - 'no-this-before-super': 'warn', - 'no-throw-literal': 'warn', - 'no-restricted-globals': [ - 'error', - 'addEventListener', - 'blur', - 'close', - 'closed', - 'confirm', - 'defaultStatus', - 'defaultstatus', - 'event', - 'external', - 'find', - 'focus', - 'frameElement', - 'frames', - 'history', - 'innerHeight', - 'innerWidth', - 'length', - 'location', - 'locationbar', - 'menubar', - 'moveBy', - 'moveTo', - 'name', - 'onblur', - 'onerror', - 'onfocus', - 'onload', - 'onresize', - 'onunload', - 'open', - 'opener', - 'opera', - 'outerHeight', - 'outerWidth', - 'pageXOffset', - 'pageYOffset', - 'parent', - 'print', - 'removeEventListener', - 'resizeBy', - 'resizeTo', - 'screen', - 'screenLeft', - 'screenTop', - 'screenX', - 'screenY', - 'scroll', - 'scrollbars', - 'scrollBy', - 'scrollTo', - 'scrollX', - 'scrollY', - 'self', - 'status', - 'statusbar', - 'stop', - 'toolbar', - 'top', - ], - 'no-unexpected-multiline': 'warn', - 'no-unreachable': 'warn', - 'no-unused-expressions': 'off', - 'no-unused-labels': 'warn', - 'no-useless-computed-key': 'warn', - 'no-useless-concat': 'warn', - 'no-useless-escape': 'warn', - 'no-useless-rename': [ - 'warn', - { - ignoreDestructuring: false, - ignoreImport: false, - ignoreExport: false, - }, - ], - 'no-with': 'warn', - 'no-whitespace-before-property': 'warn', - 'react-hooks/exhaustive-deps': 'warn', - 'require-yield': 'warn', - 'rest-spread-spacing': ['warn', 'never'], - strict: ['warn', 'never'], - 'unicode-bom': ['warn', 'never'], - 'use-isnan': 'warn', - 'valid-typeof': 'warn', - 'no-restricted-properties': [ - 'error', - { - object: 'require', - property: 'ensure', - message: - 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', - }, - { - object: 'System', - property: 'import', - message: - 'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting', - }, - ], - 'getter-return': 'warn', - 'import/first': 'error', - 'import/no-amd': 'error', - 'import/no-webpack-loader-syntax': 'error', - 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }], - 'react/jsx-no-comment-textnodes': 'warn', - 'react/jsx-no-duplicate-props': 'warn', - 'react/jsx-no-target-blank': 'warn', - 'react/jsx-no-undef': 'error', - 'react/jsx-pascal-case': ['warn', { allowAllCaps: true, ignore: [] }], - 'react/jsx-uses-react': 'warn', - 'react/jsx-uses-vars': 'warn', - 'react/no-danger-with-children': 'warn', - 'react/no-direct-mutation-state': 'warn', - 'react/no-is-mounted': 'warn', - 'react/no-typos': 'error', - 'react/react-in-jsx-scope': 'error', - 'react/require-render-return': 'error', - 'react/style-prop-object': 'warn', - 'react/jsx-no-useless-fragment': 'warn', - 'jsx-a11y/accessible-emoji': 'warn', - 'jsx-a11y/alt-text': 'warn', - 'jsx-a11y/anchor-has-content': 'warn', - 'jsx-a11y/anchor-is-valid': [ - 'warn', - { aspects: ['noHref', 'invalidHref'] }, - ], - 'jsx-a11y/aria-activedescendant-has-tabindex': 'warn', - 'jsx-a11y/aria-props': 'warn', - 'jsx-a11y/aria-proptypes': 'warn', - 'jsx-a11y/aria-role': 'warn', - 'jsx-a11y/aria-unsupported-elements': 'warn', - 'jsx-a11y/heading-has-content': 'warn', - 'jsx-a11y/iframe-has-title': 'warn', - 'jsx-a11y/img-redundant-alt': 'warn', - 'jsx-a11y/no-access-key': 'warn', - 'jsx-a11y/no-distracting-elements': 'warn', - 'jsx-a11y/no-redundant-roles': 'warn', - 'jsx-a11y/role-has-required-aria-props': 'warn', - 'jsx-a11y/role-supports-aria-props': 'warn', - 'jsx-a11y/scope': 'warn', - 'react-hooks/rules-of-hooks': 'error', - 'default-case': 'off', - 'no-dupe-class-members': 'off', - 'no-undef': 'off', - '@typescript-eslint/consistent-type-assertions': 'warn', - 'no-array-constructor': 'off', - '@typescript-eslint/no-array-constructor': 'warn', - '@typescript-eslint/no-namespace': 'error', - 'no-use-before-define': 'off', - '@typescript-eslint/no-use-before-define': [ - 'warn', - { - functions: false, - classes: false, - variables: false, - typedefs: false, - }, - ], - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': [ - 'warn', - { args: 'none', ignoreRestSiblings: true }, - ], - 'no-useless-constructor': 'off', - '@typescript-eslint/no-useless-constructor': 'warn', - '@typescript-eslint/no-unused-expressions': [ - 'error', - { - allowShortCircuit: true, - allowTernary: true, - allowTaggedTemplates: true, - }, - ], - }, - env: { - browser: true, - commonjs: true, - es6: true, - jest: true, - node: true, - }, - settings: { react: { version: 'detect' } }, - plugins: ['import', 'jsx-a11y', 'react', 'react-hooks'], -}; - -const currentTypescriptConfig: Linter.Config = { - parser: '@typescript-eslint/parser', - parserOptions: { - ecmaVersion: 2020, - sourceType: 'module', - }, - plugins: ['@typescript-eslint'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier', - 'prettier/@typescript-eslint', - ], - rules: { - '@typescript-eslint/explicit-member-accessibility': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/no-parameter-properties': 'off', - }, - overrides: [ - { - files: ['*.tsx'], - rules: { - '@typescript-eslint/no-unused-vars': 'off', - }, - }, - ], -}; - -function ensureStringArray(val: string | string[]): string[] { - if (typeof val === 'string') { - return [val]; - } - return val || []; -} - -export function updateExtendsAndRemoveDuplication( - json: Linter.Config, - configBeingExtended: Linter.Config, - deleteIfUltimatelyEmpty: boolean, - extendsToAdd: string -): void { - // Extends can be a string or an array, normalize first - json.extends = ensureStringArray(json.extends); - configBeingExtended.extends = ensureStringArray(configBeingExtended.extends); - - json.extends.unshift(extendsToAdd); - json.extends = json.extends.filter( - (extended) => !configBeingExtended.extends.includes(extended) - ); - json.extends = Array.from(new Set(json.extends)); - if (deleteIfUltimatelyEmpty && json.extends.length === 0) { - delete json.extends; - } -} - -export function updatePluginsAndRemoveDuplication( - json: Linter.Config, - configBeingExtended: Linter.Config, - deleteIfUltimatelyEmpty: boolean, - ensurePlugin?: string -): void { - json.plugins ||= []; - configBeingExtended.plugins ||= []; - if (ensurePlugin && !json.plugins.includes(ensurePlugin)) { - json.plugins.unshift(ensurePlugin); - } - json.plugins = json.plugins.filter( - (extended: string) => !configBeingExtended.plugins.includes(extended) - ); - json.plugins = Array.from(new Set(json.plugins)); - if (deleteIfUltimatelyEmpty && json.plugins.length === 0) { - delete json.plugins; - } -} - -export function updateParserOptionsAndRemoveDuplication( - json: Linter.Config, - configBeingExtended: Linter.Config -): void { - json.parserOptions ||= {}; - configBeingExtended.parserOptions ||= {}; - /** - * If the user is still using the 2018 ecmaVersion that Nx set for them - * previously we can just remove it and let them inherit the new 2020 value. - * If the user has set something else (other than 2018 or 2020), we just leave it. - */ - if ( - Number(json.parserOptions.ecmaVersion) === 2018 || - Number(json.parserOptions.ecmaVersion) === - Number(configBeingExtended.parserOptions.ecmaVersion) - ) { - delete json.parserOptions.ecmaVersion; - } - - for (const [parserOptionName, parserOptionVal] of Object.entries( - json.parserOptions - )) { - if ( - parserOptionVal === configBeingExtended.parserOptions[parserOptionName] - ) { - delete json.parserOptions[parserOptionName]; - } - } -} - -export function updateObjPropAndRemoveDuplication( - json: Linter.Config, - configBeingExtended: Linter.Config, - objPropName: string, - deleteIfUltimatelyEmpty: boolean -): void { - json[objPropName] ||= {}; - configBeingExtended[objPropName] ||= {}; - - for (const [name, val] of Object.entries(json[objPropName])) { - const valueOfSamePropInExtendedConfig = - configBeingExtended[objPropName][name]; - - try { - assert.deepStrictEqual(val, valueOfSamePropInExtendedConfig); - delete json[objPropName][name]; - } catch {} - } - - if (deleteIfUltimatelyEmpty && Object.keys(json[objPropName]).length === 0) { - delete json[objPropName]; - } -} - -export function updateOverridesAndRemoveDuplication( - json: Linter.Config, - configBeingExtended: Linter.Config, - deleteIfUltimatelyEmpty: boolean -): void { - if (!Array.isArray(json.overrides) || !json.overrides.length) { - return; - } - if ( - !Array.isArray(configBeingExtended.overrides) || - !configBeingExtended.overrides.length - ) { - return; - } - json.overrides = json.overrides.filter((o) => { - for (const extendedOverride of configBeingExtended.overrides) { - try { - assert.deepStrictEqual(o, extendedOverride); - return false; - } catch {} - } - return false; - }); - if (deleteIfUltimatelyEmpty && json.overrides.length === 0) { - delete json.overrides; - } -} diff --git a/packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.spec.ts b/packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.spec.ts deleted file mode 100644 index 5bed6601b6976..0000000000000 --- a/packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.spec.ts +++ /dev/null @@ -1,209 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree } from '@nrwl/workspace'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; -import { runMigration } from '../../utils/testing'; - -describe('Update root ESLint config to use overrides', () => { - let tree: Tree; - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - }); - - const testCases = [ - { - // Most recent root ESLint config (before this change) with no modifications - input: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - extends: ['plugin:@nrwl/nx/typescript'], - rules: { - '@nrwl/nx/enforce-module-boundaries': [ - 'error', - { - enforceBuildableLibDependency: true, - allow: [], - depConstraints: [ - { sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }, - ], - }, - ], - }, - }, - expected: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - overrides: [ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - rules: { - '@nrwl/nx/enforce-module-boundaries': [ - 'error', - { - enforceBuildableLibDependency: true, - allow: [], - depConstraints: [ - { sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }, - ], - }, - ], - }, - }, - { - files: ['*.ts', '*.tsx'], - extends: ['plugin:@nrwl/nx/typescript'], - parserOptions: { project: './tsconfig.*?.json' }, - rules: {}, - }, - { - files: ['*.js', '*.jsx'], - extends: ['plugin:@nrwl/nx/javascript'], - rules: {}, - }, - ], - }, - }, - - { - // Example using custom overrides already (should be a noop) - input: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - extends: ['plugin:@nrwl/nx/typescript'], - overrides: [ - { - files: ['*.ts'], - rules: { - foo: 'error', - }, - }, - ], - }, - expected: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - extends: ['plugin:@nrwl/nx/typescript'], - overrides: [ - { - files: ['*.ts'], - rules: { - foo: 'error', - }, - }, - ], - }, - }, - - { - // Example using custom rules and plugins at the top-level - input: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx', 'plugin-a', 'plugin-b'], - extends: ['plugin:@nrwl/nx/typescript'], - rules: { - bar: 'warn', - 'plugin-a/qux': ['error', { someConfig: true }], - 'plugin-b/baz': 'off', - }, - }, - expected: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - overrides: [ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - plugins: ['plugin-a', 'plugin-b'], - rules: { - bar: 'warn', - 'plugin-a/qux': ['error', { someConfig: true }], - 'plugin-b/baz': 'off', - }, - }, - { - files: ['*.ts', '*.tsx'], - extends: ['plugin:@nrwl/nx/typescript'], - parserOptions: { project: './tsconfig.*?.json' }, - rules: {}, - }, - { - files: ['*.js', '*.jsx'], - extends: ['plugin:@nrwl/nx/javascript'], - rules: {}, - }, - ], - }, - }, - - { - // Example using other custom config at the top-level - input: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - settings: { - foo: 'bar', - }, - env: { - browser: true, - }, - parser: 'some-custom-parser-value', - parserOptions: { - custom: 'option', - }, - extends: ['plugin:@nrwl/nx/typescript', 'custom-extends-config'], - }, - expected: { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - overrides: [ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - extends: ['custom-extends-config'], - env: { - browser: true, - }, - settings: { - foo: 'bar', - }, - parser: 'some-custom-parser-value', - parserOptions: { - custom: 'option', - }, - rules: {}, - }, - { - files: ['*.ts', '*.tsx'], - extends: ['plugin:@nrwl/nx/typescript'], - parserOptions: { project: './tsconfig.*?.json' }, - rules: {}, - }, - { - files: ['*.js', '*.jsx'], - extends: ['plugin:@nrwl/nx/javascript'], - rules: {}, - }, - ], - }, - }, - ]; - - testCases.forEach((tc, i) => { - it(`should update the existing root .eslintrc.json file to use overrides, CASE ${i}`, async () => { - tree.create('.eslintrc.json', JSON.stringify(tc.input)); - - const result = await runMigration( - 'update-root-eslint-config-to-use-overrides', - {}, - tree - ); - expect(readJsonInTree(result, '.eslintrc.json')).toEqual(tc.expected); - }); - }); -}); diff --git a/packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.ts b/packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.ts deleted file mode 100644 index 9cf8a4ccaa622..0000000000000 --- a/packages/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { chain, noop, Tree } from '@angular-devkit/schematics'; -import { formatFiles, updateJsonInTree } from '@nrwl/workspace'; -import type { Linter } from 'eslint'; - -/** - * We want to update the JSON in such a way that we: - * - translate the config to use overrides - * - don't break existing setups - * - * In order to achieve the second point we need to assume - * that any existing top level rules/plugins etc are intended - * to be run on all source files. - */ -function updateRootESLintConfig(host: Tree) { - return host.exists('.eslintrc.json') - ? updateJsonInTree('.eslintrc.json', (json: Linter.Config) => { - /** - * If the user already has overrides specified it is likely they have "forged their own path" - * when it comes to their ESLint setup, so we do nothing. - */ - if (Array.isArray(json.overrides)) { - return json; - } - - let normalizedExtends: string[] | undefined = undefined; - if (json.extends) { - if (typeof json.extends === 'string') { - normalizedExtends = [json.extends]; - } else if (Array.isArray(json.extends)) { - normalizedExtends = json.extends; - } - } - - json.overrides = [ - /** - * This configuration is intended to apply to all "source code" (but not - * markup like HTML, or other custom file types like GraphQL). - * - * This is where we will apply any top-level config that the user currently - * has to ensure that it behaves the same before and after the migration. - */ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - extends: undefinedIfEmptyArr( - normalizedExtends - ? normalizedExtends.filter( - (e) => e !== 'plugin:@nrwl/nx/typescript' - ) - : normalizedExtends - ), - env: json.env, - settings: json.settings, - parser: json.parser, - parserOptions: json.parserOptions, - plugins: undefinedIfEmptyArr( - json.plugins.filter((p) => p !== '@nrwl/nx') // remains at top-level, used everywhere - ), - rules: json.rules || {}, - }, - - /** - * This configuration is intended to apply to all TypeScript source files. - * See the eslint-plugin-nx package for what is in the referenced shareable config. - */ - { - files: ['*.ts', '*.tsx'], - extends: ['plugin:@nrwl/nx/typescript'], - parserOptions: { project: './tsconfig.*?.json' }, - /** - * Having an empty rules object present makes it more obvious to the user where they would - * extend things from if they needed to - */ - rules: {}, - }, - - /** - * This configuration is intended to apply to all JavaScript source files. - * See the eslint-plugin-nx package for what is in the referenced shareable config. - */ - { - files: ['*.js', '*.jsx'], - extends: ['plugin:@nrwl/nx/javascript'], - /** - * Having an empty rules object present makes it more obvious to the user where they would - * extend things from if they needed to - */ - rules: {}, - }, - ]; - - /** - * Clean up after copying config to main override - */ - json.plugins = ['@nrwl/nx']; - delete json.rules; - delete json.extends; - delete json.env; - delete json.settings; - delete json.globals; - delete json.parser; - delete json.parserOptions; - - return json; - }) - : noop(); -} - -function undefinedIfEmptyArr(possibleArr: T): T | undefined { - if (Array.isArray(possibleArr) && possibleArr.length === 0) { - return undefined; - } - return possibleArr; -} - -export default function () { - return chain([updateRootESLintConfig, formatFiles()]); -} diff --git a/packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.spec.ts b/packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.spec.ts deleted file mode 100644 index a79267bbf2e94..0000000000000 --- a/packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.spec.ts +++ /dev/null @@ -1,334 +0,0 @@ -import { - addProjectConfiguration, - Tree, - readJson, - writeJson, -} from '@nrwl/devkit'; -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import updateTsConfigsWithEslint from './always-use-project-level-tsconfigs-with-eslint'; - -describe('Always use project level tsconfigs with eslint', () => { - let tree: Tree; - beforeEach(async () => { - tree = createTreeWithEmptyV1Workspace(); - addProjectConfiguration(tree, 'react-app', { - root: 'apps/react-app', - sourceRoot: 'apps/react-app/src', - projectType: 'application', - targets: {}, - }); - addProjectConfiguration(tree, 'workspace-lib', { - root: 'libs/workspace-lib', - sourceRoot: 'libs/workspace-lib/src', - projectType: 'library', - targets: {}, - }); - addProjectConfiguration(tree, 'some-lib', { - root: 'libs/some-lib', - sourceRoot: 'libs/some-lib/src', - projectType: 'library', - targets: {}, - }); - }); - - it('should remove the "project" parserOption from the root ESLint config', async () => { - writeJson(tree, '.eslintrc.json', { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - overrides: [ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - parserOptions: { project: './tsconfig.*?.json' }, - rules: { - '@nrwl/nx/enforce-module-boundaries': [ - 'error', - { - enforceBuildableLibDependency: true, - allow: [], - depConstraints: [ - { sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }, - ], - }, - ], - }, - }, - { - files: ['*.ts', '*.tsx'], - extends: ['plugin:@nrwl/nx/typescript'], - parserOptions: { project: './tsconfig.*?.json' }, - rules: {}, - }, - { - files: ['*.js', '*.jsx'], - extends: ['plugin:@nrwl/nx/javascript'], - rules: {}, - }, - ], - }); - - await updateTsConfigsWithEslint(tree); - - expect(readJson(tree, '.eslintrc.json')).toMatchInlineSnapshot(` - Object { - "ignorePatterns": Array [ - "**/*", - ], - "overrides": Array [ - Object { - "files": Array [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "rules": Object { - "@nrwl/nx/enforce-module-boundaries": Array [ - "error", - Object { - "allow": Array [], - "depConstraints": Array [ - Object { - "onlyDependOnLibsWithTags": Array [ - "*", - ], - "sourceTag": "*", - }, - ], - "enforceBuildableLibDependency": true, - }, - ], - }, - }, - Object { - "extends": Array [ - "plugin:@nrwl/nx/typescript", - ], - "files": Array [ - "*.ts", - "*.tsx", - ], - "rules": Object {}, - }, - Object { - "extends": Array [ - "plugin:@nrwl/nx/javascript", - ], - "files": Array [ - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - ], - "plugins": Array [ - "@nrwl/nx", - ], - "root": true, - } - `); - }); - - it('should set the "project" parserOption within all project ESLint configs, if not already set', async () => { - // No overrides set at all - const projectEslintConfig1 = { - extends: ['plugin:@nrwl/nx/react', '../../.eslintrc.json'], - ignorePatterns: ['!**/*'], - rules: { - 'jsx-a11y/anchor-is-valid': ['off'], - }, - }; - writeJson(tree, 'apps/react-app/.eslintrc.json', projectEslintConfig1); - - // Has overrides array, but no parserOptions.project anywhere - add it for them - const projectEslintConfig2 = { - extends: '../../../.eslintrc.json', - ignorePatterns: ['!**/*'], - overrides: [ - { - files: ['*.js'], - rules: { - 'some-custom-override-rule': 'error', - }, - }, - ], - }; - writeJson(tree, 'libs/workspace-lib/.eslintrc.json', projectEslintConfig2); - - // parserOptions.project already set manually by the user at some point, leave it alone - const projectEslintConfig3 = { - extends: '../../../.eslintrc.json', - ignorePatterns: ['!**/*'], - overrides: [ - { - files: ['*.ts', '*.tsx'], - parserOptions: { - project: 'some-path-to-tsconfig.json', - }, - rules: {}, - }, - ], - }; - writeJson(tree, 'libs/some-lib/.eslintrc.json', projectEslintConfig3); - - await updateTsConfigsWithEslint(tree); - - expect(readJson(tree, 'apps/react-app/.eslintrc.json')) - .toMatchInlineSnapshot(` - Object { - "extends": Array [ - "plugin:@nrwl/nx/react", - "../../.eslintrc.json", - ], - "ignorePatterns": Array [ - "!**/*", - ], - "overrides": Array [ - Object { - "files": Array [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "parserOptions": Object { - "project": Array [ - "apps/react-app/tsconfig.*?.json", - ], - }, - "rules": Object {}, - }, - Object { - "files": Array [ - "*.ts", - "*.tsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - ], - "rules": Object { - "jsx-a11y/anchor-is-valid": Array [ - "off", - ], - }, - } - `); - - expect(readJson(tree, 'libs/workspace-lib/.eslintrc.json')) - .toMatchInlineSnapshot(` - Object { - "extends": "../../../.eslintrc.json", - "ignorePatterns": Array [ - "!**/*", - ], - "overrides": Array [ - Object { - "files": Array [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "parserOptions": Object { - "project": Array [ - "libs/workspace-lib/tsconfig.*?.json", - ], - }, - "rules": Object {}, - }, - Object { - "files": Array [ - "*.js", - ], - "rules": Object { - "some-custom-override-rule": "error", - }, - }, - ], - } - `); - - // No change - expect(readJson(tree, 'libs/some-lib/.eslintrc.json')).toEqual( - projectEslintConfig3 - ); - }); - - it('should set Next.js eslint "project" option to include tsconfig.json', async () => { - addProjectConfiguration(tree, 'next-app', { - root: 'apps/next-app', - sourceRoot: 'apps/next-app/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - }, - }, - }); - const projectEslintConfig1 = { - extends: ['plugin:@nrwl/nx/react', '../../.eslintrc.json'], - ignorePatterns: ['!**/*'], - rules: { - 'jsx-a11y/anchor-is-valid': ['off'], - }, - }; - writeJson(tree, 'apps/next-app/.eslintrc.json', projectEslintConfig1); - - await updateTsConfigsWithEslint(tree); - - expect(readJson(tree, 'apps/next-app/.eslintrc.json')) - .toMatchInlineSnapshot(` - Object { - "extends": Array [ - "plugin:@nrwl/nx/react", - "../../.eslintrc.json", - ], - "ignorePatterns": Array [ - "!**/*", - ], - "overrides": Array [ - Object { - "files": Array [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "parserOptions": Object { - "project": Array [ - "apps/next-app/tsconfig(.*)?.json", - ], - }, - "rules": Object {}, - }, - Object { - "files": Array [ - "*.ts", - "*.tsx", - ], - "rules": Object {}, - }, - Object { - "files": Array [ - "*.js", - "*.jsx", - ], - "rules": Object {}, - }, - ], - "rules": Object { - "jsx-a11y/anchor-is-valid": Array [ - "off", - ], - }, - } - `); - }); -}); diff --git a/packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.ts b/packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.ts deleted file mode 100644 index 12afd46237d22..0000000000000 --- a/packages/linter/src/migrations/update-11-5-0/always-use-project-level-tsconfigs-with-eslint.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { formatFiles, getProjects, updateJson } from '@nrwl/devkit'; -import type { Tree } from '@nrwl/devkit'; -import type { Linter } from 'eslint'; -import { join } from 'path'; - -function updateRootESLintConfig(host: Tree) { - if (!host.exists('.eslintrc.json')) { - return; - } - updateJson(host, '.eslintrc.json', (json: Linter.Config) => { - /** - * If the user is still using OOTB Nx config, then they will have a "project" - * parserOption set for TS files in their root config. - * - * We remove this to both be consistent with new workspace generation, and - * to ensure they receive an explicit error if they miss off project level - * configuration (instead of there being a silent, much slower fallback). - */ - if (json.overrides) { - json.overrides = json.overrides.map((o) => { - if (o.parserOptions && o.parserOptions.project) { - delete o.parserOptions.project; - // If the parserOptions object is now empty as a result, delete it too - if (Object.keys(o.parserOptions).length === 0) { - delete o.parserOptions; - } - } - return o; - }); - } - return json; - }); -} - -function updateProjectESLintConfigs(host: Tree) { - const projects = getProjects(host); - projects.forEach((p) => { - const eslintConfigPath = join(p.root, '.eslintrc.json'); - - if (!host.exists(eslintConfigPath)) { - return; - } - - const isNextJs = p.targets?.build?.executor === '@nrwl/next:build'; - - const parserOptionsProjectVal = isNextJs - ? [`${p.root}/tsconfig(.*)?.json`] - : [`${p.root}/tsconfig.*?.json`]; - - return updateJson(host, eslintConfigPath, (json) => { - if (!json.overrides) { - json.overrides = [ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - parserOptions: { - project: parserOptionsProjectVal, - }, - /** - * Having an empty rules object present makes it more obvious to the user where they would - * extend things from if they needed to - */ - rules: {}, - }, - { - files: ['*.ts', '*.tsx'], - rules: {}, - }, - { - files: ['*.js', '*.jsx'], - rules: {}, - }, - ]; - } else { - if ( - !json.overrides.some( - (o) => o.parserOptions && o.parserOptions.project - ) - ) { - json.overrides.unshift({ - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - parserOptions: { - project: parserOptionsProjectVal, - }, - rules: {}, - }); - } - } - return json; - }); - }); -} - -export async function updateTsConfigsWithEslint(host: Tree) { - updateRootESLintConfig(host); - updateProjectESLintConfigs(host); - await formatFiles(host); -} - -export default updateTsConfigsWithEslint; diff --git a/packages/nest/migrations.json b/packages/nest/migrations.json index ca5e8ffd86bd3..b8717feba12bf 100644 --- a/packages/nest/migrations.json +++ b/packages/nest/migrations.json @@ -1,15 +1,5 @@ { "schematics": { - "update-8-7-0.": { - "version": "8.7.0-beta.1", - "description": "Update Nest.js libraries", - "factory": "./src/migrations/update-8-7-0/update-8-7-0" - }, - "update-10-0-0": { - "version": "10.0.0-beta.1", - "description": "Update Nest.js libraries", - "factory": "./src/migrations/update-10-0-0/update-10-0-0" - }, "update-to-nest-8": { "cli": "nx", "version": "13.2.0-beta.0", @@ -18,64 +8,6 @@ } }, "packageJsonUpdates": { - "8.7.0": { - "version": "8.7.0-beta.1", - "packages": { - "@nestjs/common": { - "version": "^6.8.3", - "alwaysAddToPackageJson": false - }, - "@nestjs/core": { - "version": "^6.8.3", - "alwaysAddToPackageJson": false - }, - "@nestjs/platform-express": { - "version": "^6.8.3", - "alwaysAddToPackageJson": false - }, - "@nestjs/schematics": { - "version": "^6.7.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/testing": { - "version": "^6.8.3", - "alwaysAddToPackageJson": false - }, - "reflect-metadata": { - "version": "^0.1.13", - "alwaysAddToPackageJson": false - } - } - }, - "10.0.0": { - "version": "10.0.0-beta.1", - "packages": { - "@nestjs/common": { - "version": "^7.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/core": { - "version": "^7.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/platform-express": { - "version": "^7.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/schematics": { - "version": "^7.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/testing": { - "version": "^7.0.0", - "alwaysAddToPackageJson": false - }, - "rxjs": { - "version": "~6.5.5", - "alwaysAddToPackageJson": true - } - } - }, "14.5.0": { "version": "14.5.0-beta.1", "packages": { diff --git a/packages/nest/package.json b/packages/nest/package.json index 6e22b2b0aa2de..d3fbfdb2d98e9 100644 --- a/packages/nest/package.json +++ b/packages/nest/package.json @@ -34,7 +34,8 @@ "@nrwl/devkit": "file:../devkit", "@nrwl/js": "file:../js", "@nrwl/linter": "file:../linter", - "@nrwl/node": "file:../node" + "@nrwl/node": "file:../node", + "enquirer": "~2.3.6" }, "publishConfig": { "access": "public" diff --git a/packages/nest/src/migrations/update-10-0-0/update-10-0-0.ts b/packages/nest/src/migrations/update-10-0-0/update-10-0-0.ts deleted file mode 100644 index 79dd5cc9a4385..0000000000000 --- a/packages/nest/src/migrations/update-10-0-0/update-10-0-0.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { - chain, - Rule, - SchematicContext, - Tree, -} from '@angular-devkit/schematics'; -import { - formatFiles, - insert, - updateJsonInTree, - updatePackagesInPackageJson, -} from '@nrwl/workspace'; -import { ReplaceChange } from '@nrwl/workspace/src/utils/ast-utils'; -import { join, relative } from 'path'; -import { - createSourceFile, - isImportDeclaration, - isStringLiteral, - ScriptTarget, -} from 'typescript'; -import ignore from 'ignore'; - -export default function update(): Rule { - return chain([ - updatePackagesInPackageJson( - join(__dirname, '../../../', 'migrations.json'), - '10.0.0' - ), - formatFiles(), - updateImports, - removeObsoletePackages, - (_, context: SchematicContext) => { - console.info( - 'NX We upgraded Nest.js to v7. Make sure to read the migration guide: https://docs.nestjs.com/migration-guide' - ); - }, - ]); -} - -function removeObsoletePackages() { - return updateJsonInTree('package.json', (json) => { - if (json.dependencies && json.dependencies['type-graphql']) { - delete json.dependencies['type-graphql']; - } - return json; - }); -} - -function updateImports(host: Tree) { - let ig = ignore(); - - if (host.exists('.gitignore')) { - ig = ig.add(host.read('.gitignore').toString()); - } - - host.visit((path) => { - if (ig.ignores(relative('/', path)) || !/\.ts?$/.test(path)) { - return; - } - - const sourceFile = createSourceFile( - path, - host.read(path).toString(), - ScriptTarget.Latest, - true - ); - const changes = []; - sourceFile.statements.forEach((statement) => { - if ( - isImportDeclaration(statement) && - isStringLiteral(statement.moduleSpecifier) - ) { - const nodeText = statement.moduleSpecifier.getText(sourceFile); - const modulePath = nodeText.slice(1, -1); - if (modulePath === 'type-graphql') { - changes.push( - new ReplaceChange( - path, - statement.moduleSpecifier.getStart(sourceFile), - nodeText, - `'@nestjs/graphql'` - ) - ); - } - } - }); - insert(host, path, changes); - }); -} diff --git a/packages/nest/src/migrations/update-8-7-0/update-8-7-0.ts b/packages/nest/src/migrations/update-8-7-0/update-8-7-0.ts deleted file mode 100644 index 2238636f91a66..0000000000000 --- a/packages/nest/src/migrations/update-8-7-0/update-8-7-0.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updatePackagesInPackageJson } from '@nrwl/workspace'; -import * as path from 'path'; - -export default function update(): Rule { - return chain([ - updatePackagesInPackageJson( - path.join(__dirname, '../../../', 'migrations.json'), - '8.7.0' - ), - formatFiles(), - ]); -} diff --git a/packages/next/migrations.json b/packages/next/migrations.json index 5c02a81ceeb29..2244b598aabe8 100644 --- a/packages/next/migrations.json +++ b/packages/next/migrations.json @@ -1,48 +1,5 @@ { "schematics": { - "update-8.10.0": { - "version": "8.10.0-beta.1", - "description": "Update Next.js libraries", - "factory": "./src/migrations/update-8-10-0/update-8-10-0" - }, - "create-next-config-9.2.0": { - "version": "9.2.0-beta.1", - "description": "Add next.config.js file to Next apps", - "factory": "./src/migrations/update-9-2-0/create-next-config" - }, - "update-9.3.1": { - "version": "9.3.1-beta.1", - "description": "Rename @nrwl/next:dev-server to @nrwl/next:server", - "factory": "./src/migrations/update-9-3-1/update-9-3-1" - }, - "rename-emotion-packages-11.0.0": { - "version": "11.0.0-beta.0", - "description": "Rename emotion packages to match new 11.0.0 package names", - "factory": "./src/migrations/update-11-0-0/rename-emotion-packages-11-0-0" - }, - "update-11.0.0": { - "version": "11.0.0-beta.0", - "description": "Update libraries", - "factory": "./src/migrations/update-11-0-0/update-11-0-0" - }, - "update-babel-config-11.5.0": { - "cli": "nx", - "version": "11.5.0-beta.1", - "description": "Update .babelrc to use '@nrwl/next/babel' instead of 'next/babel'", - "factory": "./src/migrations/update-11-5-0/update-babel-config" - }, - "remove-tsconfig-app-11.5.0": { - "cli": "nx", - "version": "11.5.0-beta.1", - "description": "Remove tsconfig.app.json", - "factory": "./src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0" - }, - "add-js-include-11.6.0": { - "cli": "nx", - "version": "11.6.0-beta.0", - "description": "Add js patterns to tsconfig.json", - "factory": "./src/migrations/update-11-6-0/add-js-include-11-6-0" - }, "add-next-eslint-12.6.0": { "cli": "nx", "version": "12.6.0-beta.0", @@ -105,72 +62,6 @@ } }, "packageJsonUpdates": { - "8.10.0": { - "version": "8.10.0", - "packages": { - "next": { - "version": "9.1.5", - "alwaysAddToPackageJson": false - } - } - }, - "9.2.0": { - "version": "9.2.0", - "packages": { - "next": { - "version": "9.3.3", - "alwaysAddToPackageJson": false - } - } - }, - "10.1.0": { - "version": "10.1.0-beta.0", - "packages": { - "next": { - "version": "9.5.2", - "alwaysAddToPackageJson": false - }, - "node-sass": { - "version": "4.14.1", - "alwaysAddToPackageJson": false - } - } - }, - "11.0.0": { - "version": "11.0.0-beta.0", - "packages": { - "next": { - "version": "10.0.1", - "alwaysAddToPackageJson": false - }, - "@emotion/server": { - "version": "11.0.0", - "alwaysAddToPackageJson": false - }, - "@emotion/styled": { - "version": "11.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "11.5.2": { - "version": "11.5.2-beta.0", - "packages": { - "next": { - "version": "10.0.9", - "alwaysAddToPackageJson": false - } - } - }, - "11.6.1": { - "version": "11.6.1-beta.0", - "packages": { - "next": { - "version": "10.1.2", - "alwaysAddToPackageJson": false - } - } - }, "12.1.2": { "version": "12.1.2-beta.0", "packages": { diff --git a/packages/next/src/migrations/update-10-1-0/update-10-1-0.ts b/packages/next/src/migrations/update-10-1-0/update-10-1-0.ts deleted file mode 100644 index 9e18196a45cb1..0000000000000 --- a/packages/next/src/migrations/update-10-1-0/update-10-1-0.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updatePackagesInPackageJson } from '@nrwl/workspace'; -import * as path from 'path'; - -export default function update(): Rule { - return chain([ - updatePackagesInPackageJson( - path.join(__dirname, '../../../', 'migrations.json'), - '10.1.0' - ), - formatFiles(), - ]); -} diff --git a/packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.spec.ts b/packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.spec.ts deleted file mode 100644 index 1f19671b9bdd2..0000000000000 --- a/packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { readJsonInTree } from '@nrwl/workspace'; -import * as path from 'path'; -import { createEmptyWorkspace, runSchematic } from '@nrwl/workspace/testing'; -import { emotionServerVersion } from '../../utils/versions'; - -describe('Rename Emotion Packages 11.0.0', () => { - let tree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - schematicRunner = new SchematicTestRunner( - '@nrwl/next', - path.join(__dirname, '../../../migrations.json') - ); - tree.overwrite( - 'package.json', - JSON.stringify({ - devDependencies: { - 'emotion-server': '10.0.27', - }, - }) - ); - }); - - it(`should update emotion, if used, to the new package names`, async () => { - tree = await schematicRunner - .runSchematicAsync('rename-emotion-packages-11.0.0', {}, tree) - .toPromise(); - - const packageJson = readJsonInTree(tree, '/package.json'); - expect(packageJson).toMatchObject({ - devDependencies: { - '@emotion/server': emotionServerVersion, - }, - }); - }); - - it(`should update emotion, if used, to the new package names where imported`, async () => { - tree = await runSchematic('lib', { name: 'library-1' }, tree); - - const moduleThatImports = 'libs/library-1/src/importer.ts'; - tree.create( - moduleThatImports, - `import serve from 'emotion-server'; - - export const doSomething = (...args) => serve(...args); - ` - ); - - tree = await schematicRunner - .runSchematicAsync('rename-emotion-packages-11.0.0', {}, tree) - .toPromise(); - - expect(tree.read(moduleThatImports).toString()).toContain( - `import serve from '@emotion/server'` - ); - }); -}); diff --git a/packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.ts b/packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.ts deleted file mode 100644 index 4a8d51affbc46..0000000000000 --- a/packages/next/src/migrations/update-11-0-0/rename-emotion-packages-11-0-0.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { chain } from '@angular-devkit/schematics'; -import { formatFiles, renameNpmPackages } from '@nrwl/workspace'; -import { emotionServerVersion } from '../../utils/versions'; - -export default function update() { - return chain([ - renameNpmPackages({ - 'emotion-server': ['@emotion/server', emotionServerVersion], - }), - formatFiles(), - ]); -} diff --git a/packages/next/src/migrations/update-11-0-0/update-11-0-0.spec.ts b/packages/next/src/migrations/update-11-0-0/update-11-0-0.spec.ts deleted file mode 100644 index 9d0d6a512860c..0000000000000 --- a/packages/next/src/migrations/update-11-0-0/update-11-0-0.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { readJsonInTree } from '@nrwl/workspace'; -import * as path from 'path'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; - -describe('Update 11.0.0', () => { - let tree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - schematicRunner = new SchematicTestRunner( - '@nrwl/react', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it(`should update libs`, async () => { - tree.overwrite( - 'package.json', - JSON.stringify({ - dependencies: {}, - devDependencies: { - next: '9.5.2', - '@emotion/server': '10.0.27', - }, - }) - ); - - tree = await schematicRunner - .runSchematicAsync('update-11.0.0', {}, tree) - .toPromise(); - - const packageJson = readJsonInTree(tree, '/package.json'); - expect(packageJson).toMatchObject({ - dependencies: {}, - devDependencies: { - next: '10.0.1', - '@emotion/server': '11.0.0', - }, - }); - }); -}); diff --git a/packages/next/src/migrations/update-11-0-0/update-11-0-0.ts b/packages/next/src/migrations/update-11-0-0/update-11-0-0.ts deleted file mode 100644 index f1e4543f83a75..0000000000000 --- a/packages/next/src/migrations/update-11-0-0/update-11-0-0.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updatePackagesInPackageJson } from '@nrwl/workspace'; -import * as path from 'path'; - -export default function update(): Rule { - return chain([ - updatePackagesInPackageJson( - path.join(__dirname, '../../../', 'migrations.json'), - '11.0.0' - ), - formatFiles(), - ]); -} diff --git a/packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.spec.ts b/packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.spec.ts deleted file mode 100644 index c03a9232ef6ad..0000000000000 --- a/packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.spec.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { readJson, Tree } from '@nrwl/devkit'; -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import removeTsconfigApp from './remove-tsconfig-app-11-5-0'; - -describe('Remove tsconfig.app.json 11.5.0', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyV1Workspace(); - }); - - it('should remove tsconfig.app.json', async () => { - tree.write( - 'workspace.json', - JSON.stringify({ - projects: { - app1: { - root: 'apps/app1', - targets: { - build: { - executor: '@nrwl/next:build', - }, - }, - }, - }, - }) - ); - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - app1: {}, - }, - }) - ); - tree.write( - 'apps/app1/tsconfig.json', - JSON.stringify({ - include: [], - }) - ); - tree.write( - 'apps/app1/tsconfig.app.json', - JSON.stringify({ - extends: './tsconfig.json', - }) - ); - - await removeTsconfigApp(tree); - - expect(tree.exists('apps/app1/tsconfig.app.json')).toBe(false); - }); - - it('should update tsconfig.json with "include" from tsconfig.app.json', async () => { - tree.write( - 'workspace.json', - JSON.stringify({ - projects: { - app1: { - root: 'apps/app1', - targets: { - build: { - executor: '@nrwl/next:build', - }, - }, - }, - }, - }) - ); - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - app1: {}, - }, - }) - ); - tree.write( - 'apps/app1/tsconfig.json', - JSON.stringify({ - include: [], - }) - ); - tree.write( - 'apps/app1/tsconfig.app.json', - JSON.stringify({ - extends: './tsconfig.json', - include: ['**/*.ts', '**/*.tsx', 'next-env.d.ts'], - }) - ); - - await removeTsconfigApp(tree); - - expect(readJson(tree, 'apps/app1/tsconfig.json')).toMatchObject({ - include: ['**/*.ts', '**/*.tsx', 'next-env.d.ts'], - }); - }); - - it('should update tsconfig.json to remove "references"', async () => { - tree.write( - 'workspace.json', - JSON.stringify({ - projects: { - app1: { - root: 'apps/app1', - targets: { - build: { - executor: '@nrwl/next:build', - }, - }, - }, - }, - }) - ); - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - app1: {}, - }, - }) - ); - tree.write( - 'apps/app1/tsconfig.json', - JSON.stringify({ - references: [ - { - path: './tsconfig.app.json', - }, - ], - }) - ); - tree.write( - 'apps/app1/tsconfig.app.json', - JSON.stringify({ - extends: './tsconfig.json', - }) - ); - - await removeTsconfigApp(tree); - - expect( - readJson(tree, 'apps/app1/tsconfig.json').references - ).toBeUndefined(); - }); - - it('should not change projects that are not next.js', async () => { - tree.write( - 'workspace.json', - JSON.stringify({ - projects: { - app1: { - root: 'apps/app1', - targets: { - build: { - executor: '@nrwl/react:build', - }, - }, - }, - }, - }) - ); - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - app1: {}, - }, - }) - ); - tree.write( - 'apps/app1/tsconfig.json', - JSON.stringify({ - include: [], - }) - ); - tree.write( - 'apps/app1/tsconfig.app.json', - JSON.stringify({ - extends: './tsconfig.json', - }) - ); - - await removeTsconfigApp(tree); - - expect(tree.exists('apps/app1/tsconfig.app.json')).toBe(true); - }); -}); diff --git a/packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.ts b/packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.ts deleted file mode 100644 index e4c4f4a52ebce..0000000000000 --- a/packages/next/src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { - getProjects, - Tree, - readJson, - updateJson, - formatFiles, -} from '@nrwl/devkit'; - -export async function removeTsconfigApp(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - const tsconfigAppPath = `${project.root}/tsconfig.app.json`; - const tsconfigPath = `${project.root}/tsconfig.json`; - - if (project.targets?.build?.executor !== '@nrwl/next:build') return; - - if (!host.exists(tsconfigAppPath)) return; - - const tsconfigAppContents = readJson(host, tsconfigAppPath); - - updateJson(host, tsconfigPath, (json) => { - json.include = tsconfigAppContents.include; - if (json.references) { - delete json.references; - } - return json; - }); - - host.delete(tsconfigAppPath); - }); - - await formatFiles(host); -} - -export default removeTsconfigApp; diff --git a/packages/next/src/migrations/update-11-5-0/update-babel-config.spec.ts b/packages/next/src/migrations/update-11-5-0/update-babel-config.spec.ts deleted file mode 100644 index 56e24a7764c25..0000000000000 --- a/packages/next/src/migrations/update-11-5-0/update-babel-config.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import { readJson, Tree } from '@nrwl/devkit'; -import updateBabelConfig from './update-babel-config'; - -describe('Migrate babel setup', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyV1Workspace(); - }); - - it(`should add web babel preset if it does not exist`, async () => { - tree.write( - 'workspace.json', - JSON.stringify({ - projects: { - app1: { - root: 'apps/app1', - }, - app2: { - root: 'apps/app2', - }, - app3: { - root: 'apps/app3', - }, - }, - }) - ); - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - app1: {}, - app2: {}, - app3: {}, - }, - }) - ); - tree.write( - 'apps/app1/.babelrc', - JSON.stringify({ - presets: ['@nrwl/react/babel'], - }) - ); - tree.write( - 'apps/app2/.babelrc', - JSON.stringify({ presets: ['next/babel'] }) - ); - - await updateBabelConfig(tree); - - expect(readJson(tree, 'apps/app1/.babelrc')).toMatchObject({ - presets: ['@nrwl/react/babel'], - }); - - expect(readJson(tree, 'apps/app2/.babelrc')).toMatchObject({ - presets: ['@nrwl/next/babel'], - }); - - expect(tree.exists('apps/app3/.babelrc')).not.toBeTruthy(); - }); -}); diff --git a/packages/next/src/migrations/update-11-5-0/update-babel-config.ts b/packages/next/src/migrations/update-11-5-0/update-babel-config.ts deleted file mode 100644 index 47c32090d2bb8..0000000000000 --- a/packages/next/src/migrations/update-11-5-0/update-babel-config.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { formatFiles, getProjects, Tree, updateJson } from '@nrwl/devkit'; - -export async function updateBabelConfig(host: Tree) { - const projects = getProjects(host); - - projects.forEach((p) => { - const babelrcPath = `${p.root}/.babelrc`; - if (!host.exists(babelrcPath)) return; - - updateJson(host, babelrcPath, (json) => { - json.presets = json.presets || []; - json.presets = json.presets.map((x) => - x === 'next/babel' ? '@nrwl/next/babel' : x - ); - return json; - }); - }); - - await formatFiles(host); -} - -export default updateBabelConfig; diff --git a/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts b/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts deleted file mode 100644 index 13f4bcd63fb63..0000000000000 --- a/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { readJson, Tree, writeJson } from '@nrwl/devkit'; -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import addJsInclude from './add-js-include-11-6-0'; - -describe('Add js include 11.6.0', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyV1Workspace(); - }); - - it('should add js patterns to tsconfig "include"', async () => { - writeJson(tree, 'workspace.json', { - projects: { - app1: { - root: 'apps/app1', - targets: { - build: { - executor: '@nrwl/next:build', - }, - }, - }, - }, - }); - - writeJson(tree, 'nx.json', { - projects: { - app1: {}, - }, - }); - writeJson(tree, 'apps/app1/tsconfig.json', { - include: ['**/*.ts'], - }); - - await addJsInclude(tree); - - expect(readJson(tree, 'apps/app1/tsconfig.json')).toMatchObject({ - include: ['**/*.ts', '**/*.js', '**/*.jsx'], - }); - }); -}); diff --git a/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.ts b/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.ts deleted file mode 100644 index 9ea787bf9b801..0000000000000 --- a/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { getProjects, Tree, updateJson } from '@nrwl/devkit'; - -export async function addJsInclude(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - const tsconfigPath = `${project.root}/tsconfig.json`; - - if (project.targets?.build?.executor !== '@nrwl/next:build') return; - - if (!host.exists(tsconfigPath)) return; - - updateJson(host, tsconfigPath, (json) => { - if (!json.include) { - json.include = []; - } - json.include = uniq([...json.include, '**/*.js', '**/*.jsx']); - return json; - }); - }); -} - -const uniq = (value: T) => [...new Set(value)] as T; - -export default addJsInclude; diff --git a/packages/next/src/migrations/update-8-10-0/update-8-10-0.ts b/packages/next/src/migrations/update-8-10-0/update-8-10-0.ts deleted file mode 100644 index 44354a45ff6fa..0000000000000 --- a/packages/next/src/migrations/update-8-10-0/update-8-10-0.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updatePackagesInPackageJson } from '@nrwl/workspace'; -import * as path from 'path'; - -export default function update(): Rule { - return chain([ - updatePackagesInPackageJson( - path.join(__dirname, '../../../', 'migrations.json'), - '8.10.0' - ), - formatFiles(), - ]); -} diff --git a/packages/next/src/migrations/update-9-2-0/create-next-config.spec.ts b/packages/next/src/migrations/update-9-2-0/create-next-config.spec.ts deleted file mode 100644 index e7531a62e5b5b..0000000000000 --- a/packages/next/src/migrations/update-9-2-0/create-next-config.spec.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import * as path from 'path'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; - -describe('create-next-config-9.2.0', () => { - let tree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - tree = Tree.empty(); - tree = createEmptyWorkspace(tree); - schematicRunner = new SchematicTestRunner( - '@nrwl/next', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it('should create next.config.js if it does not exist', async () => { - tree.overwrite( - '/workspace.json', - JSON.stringify({ - version: 1, - projects: { - demo1: { - root: 'apps/demo1', - sourceRoot: 'apps/demo1/src', - architect: { - build: { - builder: '@nrwl/next:build', - options: {}, - }, - }, - }, - demo2: { - root: 'apps/demo2', - sourceRoot: 'apps/demo2/src', - architect: { - build: { - builder: '@nrwl/react:build', - options: {}, - }, - }, - }, - demo3: { - root: 'apps/demo3', - sourceRoot: 'apps/demo3/src', - architect: { - build: { - builder: '@nrwl/next:build', - options: {}, - }, - }, - }, - }, - newProjectRoot: '', - }) - ); - - tree = await schematicRunner - .runSchematicAsync('create-next-config-9.2.0', {}, tree) - .toPromise(); - - // Creates config for Next apps - const content = tree.read('apps/demo1/next.config.js').toString(); - expect(content).toContain('withStylus('); - expect(content).toContain('withLess('); - expect(content).toContain('withSass('); - expect(content).toContain('withCSS('); - - // Doesn't create config for non-Next apps - expect(tree.exists('apps/demo2/next.config.js')).toBe(false); - }); - - it('should keep existing next.config.js', async () => { - tree.overwrite( - '/workspace.json', - JSON.stringify({ - version: 1, - projects: { - demo: { - root: 'apps/demo', - sourceRoot: 'apps/demo/src', - architect: { - build: { - builder: '@nrwl/next:build', - options: {}, - }, - }, - }, - }, - newProjectRoot: '', - }) - ); - - tree.create('apps/demo/next.config.js', `module.exports = {};`); - - tree = await schematicRunner - .runSchematicAsync('create-next-config-9.2.0', {}, tree) - .toPromise(); - - const content = tree.read(`apps/demo/next.config.js`).toString(); - - expect(content).not.toContain('withStylus(withLess(withSass(withCSS({'); - }); -}); diff --git a/packages/next/src/migrations/update-9-2-0/create-next-config.ts b/packages/next/src/migrations/update-9-2-0/create-next-config.ts deleted file mode 100644 index 46f9e8a9989b9..0000000000000 --- a/packages/next/src/migrations/update-9-2-0/create-next-config.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { chain, Rule, Tree } from '@angular-devkit/schematics'; -import { formatFiles, readWorkspace } from '@nrwl/workspace'; -import { join } from 'path'; - -import { CONFIG_FILES } from '../../utils/constants'; - -const defaultConfig = `const withSass = require('@zeit/next-sass'); -const withLess = require('@zeit/next-less'); -const withStylus = require('@zeit/next-stylus'); -const withCSS = require('@zeit/next-css'); - -/* - * This file was generated by Nx 9.2.0 to allow greater control over configuration - * for Next apps. To optimize your configuration please update the following export - * with only the style plugin you are using. - * - * e.g. module.exports = withCSS({ cssModules: false }); - */ -module.exports = withStylus(withLess(withSass(withCSS({ - // Set this to true if you use CSS modules. - // See: https://github.com/css-modules/css-modules - cssModules: false -})))); -`; - -export default function update(): Rule { - return chain([ - (host: Tree) => { - const workspaceJson = readWorkspace(host); - const nextProjects = Object.keys(workspaceJson.projects) - .map((name) => { - const p = workspaceJson.projects[name]; - const buildBuilder = - p.architect && p.architect.build && p.architect.build.builder; - return buildBuilder === '@nrwl/next:build' ? p : null; - }) - .filter(Boolean); - - nextProjects.forEach((p) => { - // Next.js 12 specifies two config files. - const configFile = Array.isArray(CONFIG_FILES) - ? CONFIG_FILES[0] - : 'next.config.js'; - const configPath = join(p.root, configFile); - if (!host.exists(configPath)) { - host.create(configPath, defaultConfig); - } - }); - }, - formatFiles(), - ]); -} diff --git a/packages/next/src/migrations/update-9-3-1/update-9-3-1.ts b/packages/next/src/migrations/update-9-3-1/update-9-3-1.ts deleted file mode 100644 index 701780ffc8b86..0000000000000 --- a/packages/next/src/migrations/update-9-3-1/update-9-3-1.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles } from '@nrwl/workspace'; -import { updateWorkspace } from '@nrwl/workspace/src/utils/workspace'; - -export default function update(): Rule { - return chain([renameDevServerInWorkspace, formatFiles()]); -} - -const renameDevServerInWorkspace = updateWorkspace((workspace) => { - workspace.projects.forEach((project) => { - project.targets.forEach((target) => { - if (target.builder === '@nrwl/next:dev-server') { - target.builder = '@nrwl/next:server'; - } - }); - }); -}); diff --git a/packages/node/migrations.json b/packages/node/migrations.json index 106ee566952d6..a5c560c4d1b21 100644 --- a/packages/node/migrations.json +++ b/packages/node/migrations.json @@ -1,15 +1,5 @@ { "schematics": { - "set-build-libs-from-source": { - "version": "9.2.0-beta.1", - "description": "Set buildLibsFromSource property to true to not break existing projects.", - "factory": "./src/migrations/update-9-2-0/set-build-libs-from-source" - }, - "remove-root-dir": { - "version": "10.1.0-beta.1", - "description": "Removes rootDir from node libs' tsconfig", - "factory": "./src/migrations/update-10-1-0/remove-root-dir" - }, "remove-webpack-5-packages": { "cli": "nx", "version": "13.0.0-beta.1", diff --git a/packages/node/src/migrations/update-10-1-0/remove-root-dir.spec.ts b/packages/node/src/migrations/update-10-1-0/remove-root-dir.spec.ts deleted file mode 100644 index 9c7edc55e1fba..0000000000000 --- a/packages/node/src/migrations/update-10-1-0/remove-root-dir.spec.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; -import * as path from 'path'; - -describe('update 10.1.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - const tsConfig = String.raw` - { - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "commonjs", - "outDir": "../../dist/out-tsc", - "declaration": true, - "rootDir": "./src", - "types": ["node"] - }, - "exclude": ["**/*.spec.ts"], - "include": ["**/*.ts"] - } - `; - - beforeEach(() => { - initialTree = createEmptyWorkspace(Tree.empty()); - initialTree.create('libs/my-node-lib/tsconfig.lib.json', tsConfig); - initialTree.overwrite( - 'workspace.json', - JSON.stringify({ - version: 1, - projects: { - 'my-node-lib': { - root: 'libs/my-node-lib', - sourceRoot: 'libs/my-node-lib/src', - projectType: 'library', - schematics: {}, - architect: { - build: { - builder: '@nrwl/node:package', - options: { - outputPath: 'dist/libs/my-node-lib', - tsConfig: 'libs/my-node-lib/tsconfig.lib.json', - packageJson: 'libs/my-node-lib/package.json', - main: 'libs/my-node-lib/src/index.ts', - assets: ['libs/my-node-lib/*.md'], - }, - }, - }, - }, - }, - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/node', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it('should remove rootDir from tsconfigs', async () => { - const result = await schematicRunner - .runSchematicAsync('remove-root-dir', {}, initialTree) - .toPromise(); - - const updatedTsConfig = JSON.parse( - result.readContent('libs/my-node-lib/tsconfig.lib.json') - ); - expect(updatedTsConfig).toEqual({ - extends: './tsconfig.json', - compilerOptions: { - module: 'commonjs', - outDir: '../../dist/out-tsc', - declaration: true, - types: ['node'], - }, - exclude: ['**/*.spec.ts'], - include: ['**/*.ts'], - }); - - const workspace = JSON.parse(result.readContent('workspace.json')); - expect(workspace.projects['my-node-lib'].architect.build.options).toEqual({ - outputPath: 'dist/libs/my-node-lib', - tsConfig: 'libs/my-node-lib/tsconfig.lib.json', - packageJson: 'libs/my-node-lib/package.json', - main: 'libs/my-node-lib/src/index.ts', - assets: ['libs/my-node-lib/*.md'], - srcRootForCompilationRoot: 'libs/my-node-lib/src', - }); - }); -}); diff --git a/packages/node/src/migrations/update-10-1-0/remove-root-dir.ts b/packages/node/src/migrations/update-10-1-0/remove-root-dir.ts deleted file mode 100644 index e369c9573ceb3..0000000000000 --- a/packages/node/src/migrations/update-10-1-0/remove-root-dir.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { - chain, - Rule, - SchematicContext, - Tree, -} from '@angular-devkit/schematics'; -import { - formatFiles, - getWorkspace, - getWorkspacePath, - readJsonInTree, - updateJsonInTree, - updateWorkspace, -} from '@nrwl/workspace'; -import { join } from 'path'; - -function removeRootDirInTsConfig() { - return async (host: Tree, _: SchematicContext) => { - const workspace = await getWorkspace(host, getWorkspacePath(host)); - - const rules = []; - - for (const [, projectDefinition] of workspace.projects) { - for (const [, buildTarget] of projectDefinition.targets) { - if (buildTarget.builder !== '@nrwl/node:package') { - continue; - } - const tsConfigPath = buildTarget.options.tsConfig as string; - if (!host.exists(tsConfigPath)) { - continue; - } - - const tsConfig = readJsonInTree(host, tsConfigPath); - if ( - tsConfig.compilerOptions.rootDir !== './' || - tsConfig.compilerOptions.rootDir !== '.' - ) { - buildTarget.options.srcRootForCompilationRoot = join( - projectDefinition.root, - tsConfig.compilerOptions.rootDir - ); - } - - rules.push( - updateJsonInTree(tsConfigPath, (json) => { - delete json.compilerOptions.rootDir; - return json; - }) - ); - } - } - - return chain([updateWorkspace(workspace), ...rules]); - }; -} - -export default function update(): Rule { - return chain([removeRootDirInTsConfig(), formatFiles()]); -} diff --git a/packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts b/packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts deleted file mode 100644 index ed9fe96e9e002..0000000000000 --- a/packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { readWorkspace } from '@nrwl/workspace'; - -import * as path from 'path'; - -describe('set buildLibsFromSource to true', () => { - let tree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - tree = Tree.empty(); - schematicRunner = new SchematicTestRunner( - '@nrwl/web', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it(`should set buildLibsFromSource to true`, async () => { - tree.create( - 'workspace.json', - JSON.stringify({ - projects: { - demo: { - root: 'apps/demo', - sourceRoot: 'apps/demo/src', - architect: { - build: { - builder: '@nrwl/node:build', - options: {}, - }, - }, - }, - }, - }) - ); - - tree = await schematicRunner - .runSchematicAsync('set-build-libs-from-source', {}, tree) - .toPromise(); - - const config = readWorkspace(tree); - expect(config.projects.demo.architect.build.options).toEqual({ - buildLibsFromSource: true, - }); - }); -}); diff --git a/packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.ts b/packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.ts deleted file mode 100644 index 9e9a3216d9745..0000000000000 --- a/packages/node/src/migrations/update-9-2-0/set-build-libs-from-source.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updateWorkspaceInTree } from '@nrwl/workspace'; - -export default function update(): Rule { - return chain([ - updateWorkspaceInTree((workspaceJson) => { - Object.entries(workspaceJson.projects).forEach( - ([projectName, project]) => { - if (!project.architect) { - return; - } - - Object.entries(project.architect).forEach( - ([targetName, targetConfig]) => { - if (targetConfig.builder === '@nrwl/node:build') { - const architect = - workspaceJson.projects[projectName].architect[targetName]; - if (architect && architect.options) { - architect.options.buildLibsFromSource = true; - } - } - } - ); - } - ); - return workspaceJson; - }), - formatFiles(), - ]); -} diff --git a/packages/nx-plugin/migrations.json b/packages/nx-plugin/migrations.json index 08ec14092b6e5..7355ea097f627 100644 --- a/packages/nx-plugin/migrations.json +++ b/packages/nx-plugin/migrations.json @@ -1,20 +1,5 @@ { "schematics": { - "update-10.2.0": { - "version": "10.2.0", - "description": "Remove deprecated jest builder options", - "factory": "./src/migrations/update-10-2-0/update-10-2-0" - }, - "rename-ng-update-into-nx-migrate": { - "version": "11.0.0-beta.4", - "description": "Rename ng-update into nx-migrate", - "factory": "./src/migrations/update-11-0-0/rename-ng-update-into-nx-migrate" - }, - "update-schema-version-for-executors-and-generators": { - "version": "11.0.17", - "description": "Update schema versions for executors and generators", - "factory": "./src/migrations/update-11-0-0/update-schema-version-for-executors-and-generators" - }, "add-swc-deps": { "cli": "nx", "version": "14.1.9-beta.0", diff --git a/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts b/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts deleted file mode 100644 index d4b062f3eafa0..0000000000000 --- a/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { readJsonInTree } from '@nrwl/workspace'; -import { createEmptyWorkspace } from '@nrwl/workspace/testing'; -import * as path from 'path'; - -describe('update 10.2.0', () => { - let initialTree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(() => { - initialTree = createEmptyWorkspace(Tree.empty()); - - initialTree.overwrite( - 'workspace.json', - JSON.stringify({ - version: 1, - projects: { - 'my-plugin-e2e': { - projectType: 'application', - root: 'apps/my-plugin-e2e', - sourceRoot: 'apps/my-plugin-e2e/src', - architect: { - e2e: { - builder: '@nrwl/nx-plugin:e2e', - options: { - target: 'my-plugin:build', - npmPackageName: '@repo/my-plugin', - pluginOutputPath: 'dist/libs/my-plugin', - jestConfig: 'apps/my-plugin-e2e/jest.config.js', - tsSpecConfig: 'apps/my-plugin-e2e/tsconfig.spec.json', - }, - }, - }, - }, - }, - }) - ); - schematicRunner = new SchematicTestRunner( - '@nrwl/jest', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it('should remove setupFile and tsconfig in test architect from workspace.json', async () => { - const result = await schematicRunner - .runSchematicAsync('update-10.2.0', {}, initialTree) - .toPromise(); - - const updatedWorkspace = readJsonInTree(result, 'workspace.json'); - expect( - updatedWorkspace.projects['my-plugin-e2e'].architect.e2e.options - ).toEqual({ - target: expect.anything(), - npmPackageName: expect.anything(), - pluginOutputPath: expect.anything(), - jestConfig: expect.anything(), - }); - }); -}); diff --git a/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.ts b/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.ts deleted file mode 100644 index 1027e5c11c584..0000000000000 --- a/packages/nx-plugin/src/migrations/update-10-2-0/update-10-2-0.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { chain, Rule, Tree } from '@angular-devkit/schematics'; -import { - formatFiles, - getWorkspace, - getWorkspacePath, - updateWorkspace, -} from '@nrwl/workspace'; - -function removeDeprecatedJestBuilderOptions() { - return async (host: Tree) => { - const workspace = await getWorkspace(host, getWorkspacePath(host)); - - for (const [, projectDefinition] of workspace.projects) { - for (const [, testTarget] of projectDefinition.targets) { - if (testTarget.builder !== '@nrwl/nx-plugin:e2e') { - continue; - } - - const updatedOptions = { ...testTarget.options }; - delete updatedOptions.tsSpecConfig; - - testTarget.options = updatedOptions; - } - } - - return updateWorkspace(workspace); - }; -} - -export default function update(): Rule { - return chain([removeDeprecatedJestBuilderOptions(), formatFiles()]); -} diff --git a/packages/nx-plugin/src/migrations/update-11-0-0/rename-ng-update-into-nx-migrate.ts b/packages/nx-plugin/src/migrations/update-11-0-0/rename-ng-update-into-nx-migrate.ts deleted file mode 100644 index 9a582d95e56bb..0000000000000 --- a/packages/nx-plugin/src/migrations/update-11-0-0/rename-ng-update-into-nx-migrate.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { readJsonInTree } from '@nrwl/workspace'; -import { serializeJson } from '@nrwl/devkit'; - -export default function () { - return (host: any) => { - const p = readJsonInTree(host, 'package.json'); - if (p['ng-update']) { - p['nx-migrations'] = p['ng-update']; - delete p['ng-update']; - } - host.overwrite('package.json', serializeJson(p)); - }; -} diff --git a/packages/nx-plugin/src/migrations/update-11-0-0/update-schema-version-for-executors-and-generators.ts b/packages/nx-plugin/src/migrations/update-11-0-0/update-schema-version-for-executors-and-generators.ts deleted file mode 100644 index 56bc598f08d11..0000000000000 --- a/packages/nx-plugin/src/migrations/update-11-0-0/update-schema-version-for-executors-and-generators.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { basename } from 'path'; -import { visitNotIgnoredFiles, readJsonInTree } from '@nrwl/workspace'; -import { serializeJson } from '@nrwl/devkit'; - -export default function () { - return visitNotIgnoredFiles((file, host) => { - if (basename(file) === 'schema.json') { - const p = readJsonInTree(host as any, file); - if ( - p.$schema === 'https://json-schema.org/draft-07/schema' || - p.$schema === 'http://json-schema.org/draft-07/schema' - ) { - p.$schema = 'http://json-schema.org/schema'; - delete p.$id; - } - host.overwrite(file, serializeJson(p)); - } - }); -} diff --git a/packages/react/package.json b/packages/react/package.json index 8bbd8011109d9..1776ee7663fb0 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -43,6 +43,7 @@ "@nrwl/webpack": "file:../webpack", "@nrwl/workspace": "file:../workspace", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.7", + "@phenomnomnominal/tsquery": "4.1.1", "@svgr/webpack": "^6.1.2", "chalk": "4.1.0", "css-loader": "^6.4.0", diff --git a/packages/storybook/migrations.json b/packages/storybook/migrations.json index b91f107b7c1f9..5f970bec0f857 100644 --- a/packages/storybook/migrations.json +++ b/packages/storybook/migrations.json @@ -1,43 +1,11 @@ { "schematics": { - "update-10.2.1": { - "version": "10.2.1-beta.1", - "description": "Adjusts the tsconfig mapping", - "factory": "./src/migrations/update-10-2-1/update-10-2-1" - }, - "update-10.3.1": { - "version": "10.3.1-beta.1", - "description": "Add missing storybook config to lint target", - "factory": "./src/migrations/update-10-3-0/update-10-3-0" - }, - "update-11-0-12": { - "version": "11.0.12", - "description": "Update storybook if installed and above 6", - "factory": "./src/migrations/update-11-0-12/update-storybook" - }, - "update-11-5-3": { - "version": "11.5.3-beta.1", - "description": "Update react storybook lint config", - "factory": "./src/migrations/update-11-5-3/update-lint-ignores" - }, - "update-11-6-0": { - "version": "11.6.4", - "cli": "nx", - "description": "Update storybook if installed and above 6 but below 6.2.9", - "factory": "./src/migrations/update-11-6-0/update-storybook" - }, "update-12-1-0": { "version": "12.1.0-beta.7", "cli": "nx", "description": "Update react storybook tsconfig to avoid VSCode errors", "factory": "./src/migrations/update-12-1-0/fix-storybook-tsconfig" }, - "update-12-3-0": { - "version": "12.3.0-rc.1", - "cli": "nx", - "description": "Update storybook if installed and above 6 but below 6.2.9", - "factory": "./src/migrations/update-11-6-0/update-storybook" - }, "update-12-5-0": { "version": "12.5.0-beta.5", "cli": "nx", @@ -240,27 +208,6 @@ "alwaysAddToPackageJson": true } } - }, - "9.0.0": { - "version": "9.0.0-beta.1", - "packages": { - "@storybook/angular": { - "version": "5.3.9", - "alwaysAddToPackageJson": false - }, - "@storybook/react": { - "version": "5.3.9", - "alwaysAddToPackageJson": false - }, - "@storybook/web": { - "version": "5.3.9", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-knobs": { - "version": "5.3.9", - "alwaysAddToPackageJson": false - } - } } } } diff --git a/packages/storybook/src/migrations/update-10-2-1/update-10-2-1.spec.ts b/packages/storybook/src/migrations/update-10-2-1/update-10-2-1.spec.ts deleted file mode 100644 index 7b537e2fb0b01..0000000000000 --- a/packages/storybook/src/migrations/update-10-2-1/update-10-2-1.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readWorkspace } from '@nrwl/workspace'; -import { getFileContent } from '@nrwl/workspace/testing'; - -import { runMigration } from '../../utils/testing'; - -describe('Update 10-2-1', () => { - let tree: Tree; - - beforeEach(async () => { - tree = Tree.empty(); - - // create workspace - tree.create( - 'workspace.json', - JSON.stringify({ - projects: { - ['home-ui-angular']: { - projectType: 'library', - root: 'libs/home/ui-angular', - sourceRoot: 'libs/home/ui-angular/src', - prefix: 'app', - architect: { - storybook: { - builder: '@nrwl/storybook:storybook', - options: { - uiFramework: '@storybook/angular', - port: 4400, - config: { - configFolder: 'libs/home/ui-angular/.storybook', - }, - }, - }, - }, - }, - }, - }) - ); - - tree.create( - 'libs/home/ui-angular/.storybook/tsconfig.json', - JSON.stringify({ - extends: '../../../../tsconfig.base.json', - }) - ); - }); - - it(`should properly fix the storybook tsconfig extends property to point to the lib relative tsconfig.json`, async () => { - tree = await runMigration('update-10.2.1', {}, tree); - - const config = readWorkspace(tree); - - expect( - getFileContent(tree, 'libs/home/ui-angular/.storybook/tsconfig.json') - ).toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"../tsconfig.json\\" - } - " - `); - }); -}); diff --git a/packages/storybook/src/migrations/update-10-2-1/update-10-2-1.ts b/packages/storybook/src/migrations/update-10-2-1/update-10-2-1.ts deleted file mode 100644 index 9ed343a14a1fd..0000000000000 --- a/packages/storybook/src/migrations/update-10-2-1/update-10-2-1.ts +++ /dev/null @@ -1,84 +0,0 @@ -import * as path from 'path'; -import { - chain, - Tree, - SchematicContext, - Rule, -} from '@angular-devkit/schematics'; - -import { - formatFiles, - updateWorkspaceInTree, - readJsonInTree, -} from '@nrwl/workspace'; - -import { TsConfig } from '../../utils/utilities'; -import { serializeJson } from '@nrwl/devkit'; - -interface ProjectDefinition { - root: string; - sourceRoot: string; - projectType: 'library' | 'application'; - - schematic?: Record; - architect: Record< - string, - import('@angular-devkit/core').workspaces.TargetDefinition - >; -} - -export default function () { - return chain([updateTsConfig, formatFiles()]); -} - -function updateTsConfig(): Rule { - return updateWorkspaceInTree((config, context, tree) => { - Object.entries(config.projects).forEach( - ([projectName, projectConfig]) => { - updateStorybookTsConfigPath(tree, context, { - projectName, - projectConfig, - }); - } - ); - - return config; - }); -} - -function updateStorybookTsConfigPath( - tree: Tree, - context: SchematicContext, - options: { - projectName: string; - projectConfig: ProjectDefinition; - } -) { - const architect = options.projectConfig.architect; - - const paths = { - tsConfigStorybook: path.join( - options.projectConfig.root, - '.storybook/tsconfig.json' - ), - }; - - const hasStorybookConfig = - architect && architect.storybook && tree.exists(paths.tsConfigStorybook); - - if (!hasStorybookConfig) { - context.logger.info( - `${options.projectName}: no storybook configured. skipping migration...` - ); - return; - } - - const tsConfig = { - storybook: readJsonInTree(tree, paths.tsConfigStorybook), - }; - - // update extends prop to point to the lib relative tsconfig rather - // than the root tsconfig.base.json - tsConfig.storybook.extends = '../tsconfig.json'; - tree.overwrite(paths.tsConfigStorybook, serializeJson(tsConfig.storybook)); -} diff --git a/packages/storybook/src/migrations/update-10-3-0/update-10-3-0.spec.ts b/packages/storybook/src/migrations/update-10-3-0/update-10-3-0.spec.ts deleted file mode 100644 index 6e604cea7671c..0000000000000 --- a/packages/storybook/src/migrations/update-10-3-0/update-10-3-0.spec.ts +++ /dev/null @@ -1,258 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readWorkspace } from '@nrwl/workspace'; -import { getFileContent } from '@nrwl/workspace/testing'; - -import { runMigration } from '../../utils/testing'; - -describe('Update 10-3-0', () => { - let tree: Tree; - - beforeEach(async () => { - tree = Tree.empty(); - - // create workspace - tree.create( - 'workspace.json', - JSON.stringify({ - projects: { - ['home-ui-angular']: { - projectType: 'library', - root: 'libs/home/ui-angular', - sourceRoot: 'libs/home/ui-angular/src', - prefix: 'app', - architect: { - lint: { - builder: '@nrwl/linter:lint', - options: { - linter: 'eslint', - config: 'libs/home/ui-angular/.eslintrc', - tsConfig: [ - 'libs/home/ui-angular/tsconfig.lib.json', - 'libs/home/ui-angular/tsconfig.spec.json', - ], - exclude: ['**/node_modules/**'], - }, - }, - storybook: { - builder: '@nrwl/storybook:storybook', - options: { - uiFramework: '@storybook/angular', - port: 4400, - config: { - configFolder: 'libs/home/ui-angular/.storybook', - }, - }, - }, - }, - }, - ['home-ui-react']: { - projectType: 'library', - root: 'libs/home/ui-react', - sourceRoot: 'libs/home/ui-react/src', - architect: { - lint: { - builder: '@nrwl/linter:lint', - options: { - linter: 'eslint', - config: 'libs/home/ui-react/.eslintrc', - tsConfig: [ - 'libs/home/ui-react/tsconfig.lib.json', - 'libs/home/ui-react/tsconfig.spec.json', - ], - exclude: ['**/node_modules/**'], - }, - }, - storybook: { - builder: '@nrwl/storybook:storybook', - options: { - uiFramework: '@storybook/react', - port: 4400, - config: { - configFolder: 'libs/home/ui-react/.storybook', - }, - }, - }, - }, - }, - }, - }) - ); - - // create angular lib - tree.create( - 'libs/home/ui-angular/tsconfig.json', - JSON.stringify({ - extends: '../../tsconfig.base.json', - references: [ - { - path: './tsconfig.lib.json', - }, - { - path: './tsconfig.spec.json', - }, - ], - }) - ); - tree.create( - 'libs/home/ui-angular/tsconfig.lib.json', - JSON.stringify({ - extends: './tsconfig.json', - exclude: ['**/*.spec.ts'], - include: ['**/*.ts'], - }) - ); - tree.create( - 'libs/home/ui-angular/.storybook/tsconfig.json', - JSON.stringify({ - extends: '../tsconfig.json', - exclude: ['../**/*.spec.ts'], - include: ['../src/**/*'], - }) - ); - - // create react lib - tree.create( - 'libs/home/ui-react/tsconfig.json', - JSON.stringify({ - extends: '../../tsconfig.base.json', - references: [ - { - path: './tsconfig.lib.json', - }, - { - path: './tsconfig.spec.json', - }, - ], - }) - ); - tree.create( - 'libs/home/ui-react/tsconfig.lib.json', - JSON.stringify({ - extends: './tsconfig.json', - exclude: ['**/*.spec.ts', '**/*.spec.tsx'], - include: ['**/*.ts', '**/*.tsx'], - }) - ); - tree.create( - 'libs/home/ui-react/.storybook/tsconfig.json', - JSON.stringify({ - extends: '../tsconfig.json', - exclude: ['../**/*.spec.ts'], - include: ['../src/**/*'], - }) - ); - }); - - it(`should add storybook tsconfig to lint target and update tsconfigs in project for Angular project`, async () => { - tree = await runMigration('update-10.3.1', {}, tree); - - const config = readWorkspace(tree); - - expect( - config.projects['home-ui-angular'].architect.lint.options.tsConfig - ).toEqual([ - 'libs/home/ui-angular/tsconfig.lib.json', - 'libs/home/ui-angular/tsconfig.spec.json', - 'libs/home/ui-angular/.storybook/tsconfig.json', - ]); - - expect(getFileContent(tree, 'libs/home/ui-angular/tsconfig.json')) - .toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"../../tsconfig.base.json\\", - \\"references\\": [ - { - \\"path\\": \\"./tsconfig.lib.json\\" - }, - { - \\"path\\": \\"./tsconfig.spec.json\\" - }, - { - \\"path\\": \\".storybook/tsconfig.json\\" - } - ] - } - " - `); - expect(getFileContent(tree, 'libs/home/ui-angular/tsconfig.lib.json')) - .toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"./tsconfig.json\\", - \\"exclude\\": [\\"**/*.spec.ts\\"], - \\"include\\": [\\"**/*.ts\\"] - } - " - `); - expect( - getFileContent(tree, 'libs/home/ui-angular/.storybook/tsconfig.json') - ).toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"../tsconfig.json\\", - \\"exclude\\": [\\"../**/*.spec.ts\\"], - \\"include\\": [\\"../src/**/*\\"] - } - " - `); - }); - - it(`should add storybook tsconfig to lint target and update tsconfigs in project for React project`, async () => { - tree = await runMigration('update-10.3.1', {}, tree); - - const config = readWorkspace(tree); - - expect( - config.projects['home-ui-react'].architect.lint.options.tsConfig - ).toEqual([ - 'libs/home/ui-react/tsconfig.lib.json', - 'libs/home/ui-react/tsconfig.spec.json', - 'libs/home/ui-react/.storybook/tsconfig.json', - ]); - - expect(getFileContent(tree, 'libs/home/ui-react/tsconfig.json')) - .toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"../../tsconfig.base.json\\", - \\"references\\": [ - { - \\"path\\": \\"./tsconfig.lib.json\\" - }, - { - \\"path\\": \\"./tsconfig.spec.json\\" - }, - { - \\"path\\": \\".storybook/tsconfig.json\\" - } - ] - } - " - `); - expect(getFileContent(tree, 'libs/home/ui-react/tsconfig.lib.json')) - .toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"./tsconfig.json\\", - \\"exclude\\": [ - \\"**/*.spec.ts\\", - \\"**/*.spec.tsx\\", - \\"**/*.stories.jsx\\", - \\"**/*.stories.tsx\\" - ], - \\"include\\": [\\"**/*.ts\\", \\"**/*.tsx\\"] - } - " - `); - expect(getFileContent(tree, 'libs/home/ui-react/.storybook/tsconfig.json')) - .toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"../tsconfig.json\\", - \\"exclude\\": [ - \\"../**/*.spec.ts\\", - \\"../**/*.spec.js\\", - \\"../**/*.spec.tsx\\", - \\"../**/*.spec.jsx\\" - ], - \\"include\\": [\\"../src/**/*\\"] - } - " - `); - }); -}); diff --git a/packages/storybook/src/migrations/update-10-3-0/update-10-3-0.ts b/packages/storybook/src/migrations/update-10-3-0/update-10-3-0.ts deleted file mode 100644 index d1adbf219ada2..0000000000000 --- a/packages/storybook/src/migrations/update-10-3-0/update-10-3-0.ts +++ /dev/null @@ -1,137 +0,0 @@ -import * as path from 'path'; -import { - chain, - Tree, - SchematicContext, - Rule, -} from '@angular-devkit/schematics'; - -import { - formatFiles, - readJsonInTree, - updateWorkspaceInTree, -} from '@nrwl/workspace'; - -import { isFramework, TsConfig } from '../../utils/utilities'; -import { normalize } from '@angular-devkit/core'; -import { serializeJson } from '@nrwl/devkit'; - -interface ProjectDefinition { - root: string; - sourceRoot: string; - projectType: 'library' | 'application'; - - schematic?: Record; - architect: Record< - string, - import('@angular-devkit/core').workspaces.TargetDefinition - >; -} - -export default function (tree: Tree, context: SchematicContext) { - return chain([update, formatFiles()]); -} - -function update(tree: Tree, context: SchematicContext): Rule { - return updateWorkspaceInTree((config, context, tree) => { - Object.entries(config.projects).forEach( - ([projectName, projectConfig]) => { - updateLintTarget(tree, context, { projectName, projectConfig }); - } - ); - - return config; - }); -} - -function updateLintTarget( - tree: Tree, - context: SchematicContext, - options: { - projectName: string; - projectConfig: ProjectDefinition; - } -) { - const architect = options.projectConfig.architect; - - const paths = { - tsConfig: path.join(options.projectConfig.root, 'tsconfig.json'), - tsConfigLib: path.join(options.projectConfig.root, 'tsconfig.lib.json'), - tsConfigStorybook: normalize( - path.join(options.projectConfig.root, '.storybook/tsconfig.json') - ), - }; - - const hasStorybookConfig = - architect.storybook && tree.exists(paths.tsConfigStorybook); - - if (!hasStorybookConfig) { - context.logger.info( - `${options.projectName}: no storybook configured. skipping migration...` - ); - return; - } - - const isReactProject = isFramework('react', { - uiFramework: architect.storybook.options?.uiFramework as Parameters< - typeof isFramework - >[1]['uiFramework'], - }); - - const mainTsConfigContent = readJsonInTree(tree, paths.tsConfig); - - const tsConfig = { - main: mainTsConfigContent, - lib: tree.exists(paths.tsConfigLib) - ? readJsonInTree(tree, paths.tsConfigLib) - : mainTsConfigContent, - storybook: readJsonInTree(tree, paths.tsConfigStorybook), - }; - - if (isReactProject && Array.isArray(tsConfig.lib.exclude)) { - tsConfig.lib.exclude = uniqueArray([ - ...tsConfig.lib.exclude, - '**/*.stories.jsx', - '**/*.stories.tsx', - ]); - tree.overwrite(paths.tsConfigLib, serializeJson(tsConfig.lib)); - } - - if ( - Array.isArray(tsConfig.main.references) && - tsConfig.main.references.every( - (ref) => ref.path !== './.storybook/tsconfig.json' - ) - ) { - tsConfig.main.references.push({ - path: normalize('./.storybook/tsconfig.json'), - }); - tree.overwrite(paths.tsConfig, serializeJson(tsConfig.main)); - } - - if (isReactProject && Array.isArray(tsConfig.storybook.exclude)) { - tsConfig.storybook.exclude = uniqueArray([ - ...tsConfig.storybook.exclude, - '../**/*.spec.js', - '../**/*.spec.tsx', - '../**/*.spec.jsx', - ]); - tree.overwrite(paths.tsConfigStorybook, serializeJson(tsConfig.storybook)); - } - - // update workspace - if ( - architect.lint && - architect.lint.options && - Array.isArray(architect.lint.options.tsConfig) - ) { - architect.lint.options.tsConfig = uniqueArray([ - ...architect.lint.options.tsConfig, - paths.tsConfigStorybook, - ]); - } -} - -function uniqueArray>(value: T) { - return [...new Set(value)] as T; -} diff --git a/packages/storybook/src/migrations/update-11-0-12/update-storybook.spec.ts b/packages/storybook/src/migrations/update-11-0-12/update-storybook.spec.ts deleted file mode 100644 index 52a2c0aaa9aba..0000000000000 --- a/packages/storybook/src/migrations/update-11-0-12/update-storybook.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree } from '@nrwl/workspace'; - -import { runMigration } from '../../utils/testing'; - -describe('Update 11-0-12', () => { - let tree: Tree; - - beforeEach(async () => { - tree = Tree.empty(); - }); - - it('should update storybook versions if storybook is already above 6', async () => { - tree.create( - 'package.json', - JSON.stringify({ - devDependencies: { - '@storybook/angular': '^6.0.0', - '@storybook/react': '^6.0.0', - '@storybook/addon-knobs': '^6.0.0', - }, - }) - ); - const result = await runMigration('update-11-0-12', {}, tree); - expect( - readJsonInTree(result, 'package.json').devDependencies[ - '@storybook/angular' - ] - ).toBe('^6.1.11'); - }); - - it('should not update storybook versions if storybook is below 6', async () => { - tree.create( - 'package.json', - JSON.stringify({ - devDependencies: { - '@storybook/angular': '^5.0.0', - '@storybook/react': '^5.0.0', - '@storybook/addon-knobs': '^5.0.0', - }, - }) - ); - const result = await runMigration('update-11-0-12', {}, tree); - expect( - readJsonInTree(result, 'package.json').devDependencies[ - '@storybook/angular' - ] - ).toBe('^5.0.0'); - }); -}); diff --git a/packages/storybook/src/migrations/update-11-0-12/update-storybook.ts b/packages/storybook/src/migrations/update-11-0-12/update-storybook.ts deleted file mode 100644 index 2435676f06ff4..0000000000000 --- a/packages/storybook/src/migrations/update-11-0-12/update-storybook.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { chain, SchematicContext, Tree } from '@angular-devkit/schematics'; -import { - addInstallTask, - checkAndCleanWithSemver, - formatFiles, - updateJsonInTree, -} from '@nrwl/workspace'; - -import { gte } from 'semver'; -let needsInstall = false; - -const maybeUpdateVersion = updateJsonInTree('package.json', (json) => { - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - const storybookPackages = [ - '@storybook/angular', - '@storybook/react', - '@storybook/addon-knobs', - ]; - storybookPackages.forEach((storybookPackageName) => { - if (json.dependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.dependencies[storybookPackageName] - ); - if (gte(version, '6.0.0')) { - json.dependencies[storybookPackageName] = '^6.1.11'; - needsInstall = true; - } - } - if (json.devDependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.devDependencies[storybookPackageName] - ); - if (gte(version, '6.0.0')) { - json.devDependencies[storybookPackageName] = '^6.1.11'; - needsInstall = true; - } - } - }); - - return json; -}); - -export default function (tree: Tree, context: SchematicContext) { - return chain([ - maybeUpdateVersion, - formatFiles(), - addInstallTask({ skipInstall: !needsInstall }), - ]); -} diff --git a/packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.spec.ts b/packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.spec.ts deleted file mode 100644 index 7526e7a8da3ac..0000000000000 --- a/packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { getFileContent } from '@nrwl/workspace/testing'; -import { runMigration } from '../../utils/testing'; - -describe('Update 11-5-3', () => { - let tree: Tree; - - beforeEach(async () => { - tree = Tree.empty(); - - // create workspace - tree.create( - 'workspace.json', - JSON.stringify({ - projects: { - ['home-ui-react']: { - projectType: 'library', - root: 'libs/home/ui-react', - sourceRoot: 'libs/home/ui-react/src', - architect: { - storybook: { - builder: '@nrwl/storybook:storybook', - options: { - uiFramework: '@storybook/react', - port: 4400, - config: { - configFolder: 'libs/home/ui-react/.storybook', - }, - }, - }, - }, - }, - }, - }) - ); - - tree.create( - 'libs/home/ui-react/.storybook/tsconfig.json', - JSON.stringify({ - extends: '../tsconfig.json', - include: ['../src/**/*'], - }) - ); - }); - - it(`should add storybook tsconfig to lint target and update tsconfigs in project for React project`, async () => { - tree = await runMigration('update-11-5-3', {}, tree); - - expect(getFileContent(tree, 'libs/home/ui-react/.storybook/tsconfig.json')) - .toMatchInlineSnapshot(` - "{ - \\"extends\\": \\"../tsconfig.json\\", - \\"include\\": [\\"../src/**/*\\", \\"./*.js\\"] - } - " - `); - }); -}); diff --git a/packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.ts b/packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.ts deleted file mode 100644 index 668e2b7796e96..0000000000000 --- a/packages/storybook/src/migrations/update-11-5-3/update-lint-ignores.ts +++ /dev/null @@ -1,94 +0,0 @@ -import * as path from 'path'; -import { - chain, - Tree, - SchematicContext, - Rule, -} from '@angular-devkit/schematics'; - -import { - formatFiles, - readJsonInTree, - updateWorkspaceInTree, -} from '@nrwl/workspace'; - -import { isFramework, TsConfig } from '../../utils/utilities'; -import { normalize } from '@angular-devkit/core'; -import { serializeJson } from '@nrwl/devkit'; - -interface ProjectDefinition { - root: string; - sourceRoot: string; - projectType: 'library' | 'application'; - - schematic?: Record; - architect: Record< - string, - import('@angular-devkit/core').workspaces.TargetDefinition - >; -} - -export default function (tree: Tree, context: SchematicContext) { - return chain([update, formatFiles()]); -} - -function update(tree: Tree, context: SchematicContext): Rule { - return updateWorkspaceInTree((config, context, tree) => { - Object.entries(config.projects).forEach( - ([projectName, projectConfig]) => { - updateTsconfigInclude(tree, context, { projectName, projectConfig }); - } - ); - - return config; - }); -} - -function updateTsconfigInclude( - tree: Tree, - context: SchematicContext, - options: { - projectName: string; - projectConfig: ProjectDefinition; - } -) { - const architect = options.projectConfig.architect; - - const paths = { - tsConfigStorybook: normalize( - path.join(options.projectConfig.root, '.storybook/tsconfig.json') - ), - }; - - const hasStorybookConfig = - architect.storybook && tree.exists(paths.tsConfigStorybook); - - if (!hasStorybookConfig) { - context.logger.info( - `${options.projectName}: no storybook configured. skipping migration...` - ); - return; - } - - const isReactProject = isFramework('react', { - uiFramework: architect.storybook.options?.uiFramework as Parameters< - typeof isFramework - >[1]['uiFramework'], - }); - - const tsConfig = { - storybook: readJsonInTree(tree, paths.tsConfigStorybook), - }; - - if (isReactProject && Array.isArray(tsConfig.storybook.include)) { - tsConfig.storybook.include = uniqueArray([ - ...tsConfig.storybook.include, - './*.js', - ]); - tree.overwrite(paths.tsConfigStorybook, serializeJson(tsConfig.storybook)); - } -} - -function uniqueArray>(value: T) { - return [...new Set(value)] as T; -} diff --git a/packages/storybook/src/migrations/update-11-6-0/update-storybook.spec.ts b/packages/storybook/src/migrations/update-11-6-0/update-storybook.spec.ts deleted file mode 100644 index e0f61b995f553..0000000000000 --- a/packages/storybook/src/migrations/update-11-6-0/update-storybook.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Tree, readJson, writeJson } from '@nrwl/devkit'; -import { createTree } from '@nrwl/devkit/testing'; - -import updateStorybook from './update-storybook'; - -describe('Update 11-6-0/12-3-0', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTree(); - }); - - it('should update storybook versions if storybook is already above 6 but below 6.2.9', async () => { - writeJson(tree, 'package.json', { - devDependencies: { - '@storybook/angular': '^6.0.0', - '@storybook/react': '^6.0.0', - '@storybook/addon-knobs': '^6.0.0', - }, - }); - await updateStorybook(tree); - expect( - readJson(tree, 'package.json').devDependencies['@storybook/angular'] - ).toBe('~6.2.9'); - }); - - it('should not update storybook versions if storybook is already above 6.2.9', async () => { - writeJson(tree, 'package.json', { - devDependencies: { - '@storybook/angular': '~6.2.9', - '@storybook/react': '~6.2.9', - '@storybook/addon-knobs': '~6.2.9', - }, - }); - await updateStorybook(tree); - expect( - readJson(tree, 'package.json').devDependencies['@storybook/angular'] - ).toBe('~6.2.9'); - }); - - it('should not update storybook versions if storybook is below 6', async () => { - writeJson(tree, 'package.json', { - devDependencies: { - '@storybook/angular': '^5.0.0', - '@storybook/react': '^5.0.0', - '@storybook/addon-knobs': '^5.0.0', - }, - }); - await updateStorybook(tree); - expect( - readJson(tree, 'package.json').devDependencies['@storybook/angular'] - ).toBe('^5.0.0'); - }); -}); diff --git a/packages/storybook/src/migrations/update-11-6-0/update-storybook.ts b/packages/storybook/src/migrations/update-11-6-0/update-storybook.ts deleted file mode 100644 index 253888b7d1879..0000000000000 --- a/packages/storybook/src/migrations/update-11-6-0/update-storybook.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils'; - -import { gte, lt } from 'semver'; -import { - formatFiles, - installPackagesTask, - Tree, - updateJson, -} from '@nrwl/devkit'; - -let needsInstall = false; - -function maybeUpdateVersion(tree: Tree) { - updateJson(tree, 'package.json', (json) => { - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - const storybookPackages = [ - '@storybook/angular', - '@storybook/react', - '@storybook/addon-knobs', - ]; - storybookPackages.forEach((storybookPackageName) => { - if (json.dependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.dependencies[storybookPackageName] - ); - if (gte(version, '6.0.0') && lt(version, '6.2.9')) { - json.dependencies[storybookPackageName] = '~6.2.9'; - needsInstall = true; - } - } - if (json.devDependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.devDependencies[storybookPackageName] - ); - if (gte(version, '6.0.0') && lt(version, '6.2.9')) { - json.devDependencies[storybookPackageName] = '~6.2.9'; - needsInstall = true; - } - } - }); - - return json; - }); -} - -export default async function (tree: Tree) { - maybeUpdateVersion(tree); - await formatFiles(tree); - - return () => { - installPackagesTask(tree); - }; -} diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts index 34f8650e18db6..45d8f0d7e0a72 100644 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts +++ b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts @@ -8,11 +8,11 @@ import { Tree, visitNotIgnoredFiles, } from '@nrwl/devkit'; -import { getTsSourceFile } from '@nrwl/storybook/src/utils/utilities'; import { fileExists } from '@nrwl/workspace/src/utilities/fileutils'; import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes'; import { join, normalize } from 'path'; import { SyntaxKind } from 'typescript'; +import { getTsSourceFile } from '../../../utils/utilities'; import ts = require('typescript'); export async function migrateStoriesTo62Generator(tree: Tree) { diff --git a/packages/web/migrations.json b/packages/web/migrations.json index c98353c5e43d1..6c03ade81a24d 100644 --- a/packages/web/migrations.json +++ b/packages/web/migrations.json @@ -1,38 +1,5 @@ { "schematics": { - "update-builder-8.5.0": { - "version": "8.5.0-beta.1", - "description": "Update web build builder", - "factory": "./src/migrations/update-8-5-0/update-builder-8-5-0" - }, - "update-builder-9.0.0": { - "version": "9.0.0-beta.1", - "description": "Rename @nrwl/web:bundle => @nrwl/web:package", - "factory": "./src/migrations/update-9-0-0/update-builder-9-0-0" - }, - "set-build-libs-from-source": { - "version": "9.2.0-beta.1", - "description": "Set buildLibsFromSource property to true to not break existing projects.", - "factory": "./src/migrations/update-9-2-0/set-build-libs-from-source" - }, - "update-root-babel-config-11-5-2": { - "cli": "nx", - "version": "11.5.2-beta.1", - "description": "Remove presets from the root babel.config.json file to prevent conflicts with babel presets used in apps.", - "factory": "./src/migrations/update-11-5-2/update-root-babel-config" - }, - "create-babelrc-for-workspace-libs-11-5-2": { - "cli": "nx", - "version": "11.5.2-beta.1", - "description": "Create .babelrc files for workspace libs to fix compatibility with the new babel.config.json setup.", - "factory": "./src/migrations/update-11-5-2/create-babelrc-for-workspace-libs" - }, - "update-existing-babelrc-files-11-5-2": { - "cli": "nx", - "version": "11.5.2-beta.1", - "description": "Update existing .babelrc files to add missing '@nrwl/web/babel' preset if necessary.", - "factory": "./src/migrations/update-11-5-2/update-existing-babelrc-files" - }, "remove-node-sass-13-0-0": { "cli": "nx", "version": "13.0.0-beta.1", diff --git a/packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.spec.ts b/packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.spec.ts deleted file mode 100644 index b70888d5b953d..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.spec.ts +++ /dev/null @@ -1,229 +0,0 @@ -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import { readJson, writeJson, DependencyType } from '@nrwl/devkit'; -import { createBabelrcForWorkspaceLibs } from './create-babelrc-for-workspace-libs'; -import type { ProjectGraph, Tree } from '@nrwl/devkit'; - -let projectGraph: ProjectGraph; -jest.mock('@nrwl/devkit', () => ({ - ...jest.requireActual('@nrwl/devkit'), - createProjectGraphAsync: jest - .fn() - .mockImplementation(async () => projectGraph), -})); - -describe('Create missing .babelrc files', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyV1Workspace(); - }); - - it(`should create .babelrc files for libs that are used in '@nrwl/web:build'`, async () => { - writeJson(tree, 'workspace.json', { - projects: { - webapp: { - root: 'apps/webapp', - projectType: 'application', - targets: { - build: { executor: '@nrwl/web:build' }, - }, - }, - nodeapp: { - root: 'apps/nodeapp', - projectType: 'application', - targets: { - build: { executor: '@nrwl/node:build' }, - }, - }, - weblib: { - root: 'libs/weblib', - projectType: 'library', - }, - nodelib: { - root: 'libs/nodelib', - projectType: 'library', - }, - }, - }); - writeJson(tree, 'nx.json', { - npmScope: 'proj', - projects: { - webapp: {}, - nodeapp: {}, - weblib: {}, - nodelib: {}, - }, - }); - tree.write('apps/webapp/index.ts', `import '@proj/weblib';`); - - projectGraph = { - nodes: { - webapp: { - name: 'webapp', - type: 'app', - data: { - files: [], - root: 'apps/webapp', - }, - }, - nodeapp: { - name: 'nodeapp', - type: 'app', - data: { - files: [], - root: 'apps/nodeapp', - }, - }, - weblib: { - name: 'weblib', - type: 'lib', - data: { - files: [], - root: 'libs/weblib', - }, - }, - nodelib: { - name: 'nodelib', - type: 'lib', - data: { - files: [], - root: 'libs/nodelib', - }, - }, - }, - dependencies: { - webapp: [ - { - type: DependencyType.static, - source: 'webapp', - target: 'weblib', - }, - ], - }, - }; - - await createBabelrcForWorkspaceLibs(tree); - - expect(readJson(tree, 'libs/weblib/.babelrc')).toMatchObject({ - presets: ['@nrwl/web/babel'], - }); - - expect(tree.exists('libs/nodelib/.babelrc')).toBeFalsy(); - }); - - it('should not error if there are circular dependencies', async () => { - writeJson(tree, 'workspace.json', { - projects: { - webapp: { - root: 'apps/webapp', - projectType: 'application', - targets: { - build: { executor: '@nrwl/web:build' }, - }, - }, - nodeapp: { - root: 'apps/nodeapp', - projectType: 'application', - targets: { - build: { executor: '@nrwl/node:build' }, - }, - }, - weblib: { - root: 'libs/weblib', - projectType: 'library', - }, - nodelib: { - root: 'libs/nodelib', - projectType: 'library', - }, - }, - }); - writeJson(tree, 'nx.json', { - npmScope: 'proj', - projects: { - webapp: {}, - nodeapp: {}, - weblib: {}, - nodelib: {}, - }, - }); - tree.write('apps/webapp/index.ts', `import '@proj/weblib';`); - - projectGraph = { - nodes: { - webapp: { - name: 'webapp', - type: 'app', - data: { - files: [], - root: 'apps/webapp', - }, - }, - nodeapp: { - name: 'nodeapp', - type: 'app', - data: { - files: [], - root: 'apps/nodeapp', - }, - }, - weblib: { - name: 'weblib', - type: 'lib', - data: { - files: [], - root: 'libs/weblib', - }, - }, - nodelib: { - name: 'nodelib', - type: 'lib', - data: { - files: [], - root: 'libs/nodelib', - }, - }, - nodelib2: { - name: 'nodelib2', - type: 'lib', - data: { - files: [], - root: 'libs/nodelib2', - }, - }, - }, - dependencies: { - webapp: [ - { - type: DependencyType.static, - source: 'webapp', - target: 'weblib', - }, - ], - nodelib: [ - { - type: DependencyType.static, - source: 'nodelib', - target: 'nodelib2', - }, - ], - nodelib2: [ - { - type: DependencyType.static, - source: 'nodelib2', - target: 'nodelib', - }, - ], - }, - }; - - await createBabelrcForWorkspaceLibs(tree); - - expect(readJson(tree, 'libs/weblib/.babelrc')).toMatchObject({ - presets: ['@nrwl/web/babel'], - }); - - expect(tree.exists('libs/nodelib/.babelrc')).toBeFalsy(); - expect(tree.exists('libs/nodelib2/.babelrc')).toBeFalsy(); - }); -}); diff --git a/packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.ts b/packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.ts deleted file mode 100644 index c694abe958ee6..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/create-babelrc-for-workspace-libs.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { formatFiles, getProjects, Tree, writeJson } from '@nrwl/devkit'; -import { createProjectGraphAsync, reverse } from '@nrwl/devkit'; -import { hasDependentAppUsingWebBuild } from './utils'; - -export async function createBabelrcForWorkspaceLibs(host: Tree) { - const projects = getProjects(host); - const graph = reverse(await createProjectGraphAsync()); - - for (const [name, p] of projects.entries()) { - if (!hasDependentAppUsingWebBuild(name, graph, projects)) { - continue; - } - - const babelrcPath = `${p.root}/.babelrc`; - if (p.projectType === 'library' && !host.exists(babelrcPath)) { - // Library is included in applications that require .babelrc to - // exist and contain '@nrwl/web/babel' preset. - writeJson(host, babelrcPath, { presets: ['@nrwl/web/babel'] }); - } - } - - await formatFiles(host); -} - -export default createBabelrcForWorkspaceLibs; diff --git a/packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.spec.ts b/packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.spec.ts deleted file mode 100644 index a5ee1a1706c3b..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.spec.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import { readJson, writeJson, Tree } from '@nrwl/devkit'; -import { updateExistingBabelrcFiles } from './update-existing-babelrc-files'; - -describe('Create missing .babelrc files', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyV1Workspace(); - }); - - it(`should add web babel preset if it does not exist`, async () => { - writeJson(tree, 'workspace.json', { - projects: { - 'missing-babel-presets': { - root: 'apps/missing-babel-presets', - projectType: 'application', - }, - 'web-app': { - root: 'apps/web-app', - projectType: 'application', - }, - 'react-app': { - root: 'apps/react-app', - projectType: 'application', - }, - 'not-using-babel': { - root: 'apps/not-using-babel', - projectType: 'application', - }, - 'next-app': { - root: 'apps/next-app', - projectType: 'application', - }, - }, - }); - writeJson(tree, 'nx.json', { - projects: { - 'missing-babel-presets': {}, - 'web-app': {}, - 'react-app': {}, - 'not-using-babel': {}, - 'next-app': {}, - }, - }); - writeJson(tree, 'babel.config.json', { - presets: ['@nrwl/web/babel'], - }); - writeJson(tree, 'apps/missing-babel-presets/.babelrc', {}); - writeJson(tree, 'apps/web-app/.babelrc', { presets: ['@nrwl/web/babel'] }); - writeJson(tree, 'apps/react-app/.babelrc', { - presets: ['@nrwl/react/babel'], - }); - writeJson(tree, 'apps/next-app/.babelrc', { - presets: ['@nrwl/next/babel'], - }); - - await updateExistingBabelrcFiles(tree); - - expect(readJson(tree, 'apps/missing-babel-presets/.babelrc')).toMatchObject( - { - presets: ['@nrwl/web/babel'], - } - ); - - expect(readJson(tree, 'apps/web-app/.babelrc')).toMatchObject({ - presets: ['@nrwl/web/babel'], - }); - - expect(readJson(tree, 'apps/react-app/.babelrc')).toMatchObject({ - presets: ['@nrwl/react/babel'], - }); - - expect(tree.exists('apps/not-using-babel/.babelrc')).not.toBeTruthy(); - - expect(readJson(tree, 'apps/next-app/.babelrc')).toMatchObject({ - presets: ['@nrwl/next/babel'], - }); - }); -}); diff --git a/packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.ts b/packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.ts deleted file mode 100644 index 757fce97b081e..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/update-existing-babelrc-files.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { formatFiles, getProjects, Tree, updateJson } from '@nrwl/devkit'; - -export async function updateExistingBabelrcFiles(host: Tree) { - const projects = getProjects(host); - - projects.forEach((p) => { - const babelrcPath = `${p.root}/.babelrc`; - - // Add `@nrwl/web/babel` to projects that did not previously use it. - // This is needed because we removed it from the root. - if (host.exists(babelrcPath)) { - updateJson(host, babelrcPath, (json) => { - json.presets ||= []; - if ( - -1 === - json.presets.findIndex( - (x) => - x === '@nrwl/web/babel' || - x === '@nrwl/react/babel' || - x === '@nrwl/next/babel' - ) - ) { - json.presets.push('@nrwl/web/babel'); - } - return json; - }); - } - }); - - await formatFiles(host); -} - -export default updateExistingBabelrcFiles; diff --git a/packages/web/src/migrations/update-11-5-2/update-root-babel-config.spec.ts b/packages/web/src/migrations/update-11-5-2/update-root-babel-config.spec.ts deleted file mode 100644 index 4116f2ec6d70b..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/update-root-babel-config.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; -import { readJson, writeJson, Tree } from '@nrwl/devkit'; -import { updateRootBabelConfig } from './update-root-babel-config'; - -describe('Update root babel config', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyV1Workspace(); - }); - - it(`should add web babel preset if it does not exist`, async () => { - writeJson(tree, 'babel.config.json', { - presets: ['@nrwl/web/babel'], - }); - - await updateRootBabelConfig(tree); - - expect(readJson(tree, 'babel.config.json').presets).not.toContain( - '@nrwl/web/babel' - ); - }); -}); diff --git a/packages/web/src/migrations/update-11-5-2/update-root-babel-config.ts b/packages/web/src/migrations/update-11-5-2/update-root-babel-config.ts deleted file mode 100644 index 1f0507ae13ab9..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/update-root-babel-config.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { formatFiles, Tree, updateJson } from '@nrwl/devkit'; - -export async function updateRootBabelConfig(host: Tree) { - if (host.exists('babel.config.json')) { - updateJson(host, 'babel.config.json', (json) => { - if (Array.isArray(json.presets)) { - json.presets = json.presets.filter((x) => x !== '@nrwl/web/babel'); - } - return json; - }); - } - await formatFiles(host); -} - -export default updateRootBabelConfig; diff --git a/packages/web/src/migrations/update-11-5-2/utils.spec.ts b/packages/web/src/migrations/update-11-5-2/utils.spec.ts deleted file mode 100644 index 5640d45cc06a4..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/utils.spec.ts +++ /dev/null @@ -1,140 +0,0 @@ -import { getProjects, ProjectGraph, DependencyType } from '@nrwl/devkit'; -import { reverse } from '@nrwl/devkit'; -import { hasDependentAppUsingWebBuild } from './utils'; - -describe('hasDependentAppUsingWebBuild', () => { - const graph: ProjectGraph = reverse({ - nodes: { - webapp: { name: 'webapp', data: { files: [] }, type: 'app' }, - nodeapp: { name: 'nodeapp', data: { files: [] }, type: 'app' }, - weblib1: { name: 'weblib1', data: { files: [] }, type: 'lib' }, - weblib2: { name: 'weblib2', data: { files: [] }, type: 'lib' }, - weblib3: { name: 'weblib3', data: { files: [] }, type: 'lib' }, - stylelib: { name: 'stylelib', data: { files: [] }, type: 'lib' }, - sharedlib: { name: 'sharedlib', data: { files: [] }, type: 'lib' }, - nodelib: { name: 'nodelib', data: { files: [] }, type: 'lib' }, - }, - dependencies: { - webapp: [ - { source: 'webapp', target: 'weblib1', type: DependencyType.static }, - { source: 'webapp', target: 'sharedlib', type: DependencyType.static }, - { - source: 'webapp', - target: 'stylelib', - type: DependencyType.implicit, - }, - ], - nodeapp: [ - { source: 'nodeapp', target: 'nodelib', type: DependencyType.static }, - { source: 'nodeapp', target: 'sharedlib', type: DependencyType.static }, - ], - weblib1: [ - { source: 'weblib1', target: 'weblib2', type: DependencyType.static }, - ], - weblib2: [ - { source: 'weblib2', target: 'weblib3', type: DependencyType.static }, - ], - }, - }); - - const projects: ReturnType = new Map([ - [ - 'webapp', - { - projectType: 'application', - root: 'webapp', - targets: { - build: { executor: '@nrwl/web:build' }, - }, - }, - ], - [ - 'nodeapp', - { - projectType: 'application', - root: 'nodeapp', - targets: { - build: { executor: '@nrwl/node:build' }, - }, - }, - ], - [ - 'weblib1', - { - projectType: 'library', - root: 'weblib1', - targets: {}, - }, - ], - [ - 'weblib2', - { - projectType: 'library', - root: 'weblib2', - targets: {}, - }, - ], - [ - 'weblib3', - { - projectType: 'library', - root: 'weblib3', - targets: {}, - }, - ], - [ - 'stylelib', - { - projectType: 'library', - root: 'stylelib', - targets: {}, - }, - ], - [ - 'nodelib', - { - projectType: 'library', - root: 'nodelib', - targets: {}, - }, - ], - [ - 'sharedlib', - { - projectType: 'library', - root: 'sharedlib', - targets: {}, - }, - ], - ]); - - it('should return true if project is in the dependency chain of an app using `@nrwl/web:build`', () => { - expect( - hasDependentAppUsingWebBuild('weblib1', graph, projects) - ).toBeTruthy(); - - expect( - hasDependentAppUsingWebBuild('weblib2', graph, projects) - ).toBeTruthy(); - - expect( - hasDependentAppUsingWebBuild('weblib3', graph, projects) - ).toBeTruthy(); - - expect( - hasDependentAppUsingWebBuild('sharedlib', graph, projects) - ).toBeTruthy(); - }); - - it('should return false if project an implicit dependency of an app using`@nrwl/web:build`', () => { - expect( - hasDependentAppUsingWebBuild('stylelib', graph, projects) - ).toBeFalsy(); - }); - - it('should return false if project is not used by an app using `@nrwl/web:build`', () => { - expect( - hasDependentAppUsingWebBuild('nodelib', graph, projects) - ).toBeFalsy(); - }); -}); diff --git a/packages/web/src/migrations/update-11-5-2/utils.ts b/packages/web/src/migrations/update-11-5-2/utils.ts deleted file mode 100644 index 2cf3900343332..0000000000000 --- a/packages/web/src/migrations/update-11-5-2/utils.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { getProjects, ProjectGraph, DependencyType } from '@nrwl/devkit'; - -const cache = new Map(); - -export function hasDependentAppUsingWebBuild( - projectName: string, - reversedProjectGraph: ProjectGraph, - projects: ReturnType -) { - const seen = new Set(); - function walk(currProject: string) { - if (seen.has(currProject)) { - return false; - } - seen.add(currProject); - - if (cache.has(currProject)) { - return cache.get(currProject); - } - const project = projects.get(currProject); - - if (project?.targets?.build?.executor === '@nrwl/web:build') { - cache.set(currProject, true); - return true; - } - - const deps = reversedProjectGraph.dependencies[currProject]; - - if (deps.length === 0) { - cache.set(currProject, false); - return false; - } - - const result = deps.some( - (dep) => dep.type !== DependencyType.implicit && walk(dep.target) - ); - cache.set(currProject, result); - return result; - } - - return walk(projectName); -} diff --git a/packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.spec.ts b/packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.spec.ts deleted file mode 100644 index 648f3a2429830..0000000000000 --- a/packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { readWorkspace, updateJsonInTree } from '@nrwl/workspace'; - -import * as path from 'path'; - -describe('Update 8-5-0', () => { - let tree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - tree = Tree.empty(); - schematicRunner = new SchematicTestRunner( - '@nrwl/web', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it(`should remove differentialLoading as an option for build builder`, async () => { - tree = await schematicRunner - .callRule( - updateJsonInTree('workspace.json', () => ({ - projects: { - demo: { - root: 'apps/demo', - sourceRoot: 'apps/demo/src', - architect: { - build: { - builder: '@nrwl/web:build', - options: { - differentialLoading: true, - }, - }, - }, - }, - }, - })), - tree - ) - .toPromise(); - - tree = await schematicRunner - .runSchematicAsync('update-builder-8.5.0', {}, tree) - .toPromise(); - - const config = readWorkspace(tree); - expect(config.projects.demo.architect.build.options).toEqual({}); - }); -}); diff --git a/packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.ts b/packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.ts deleted file mode 100644 index 8609283d12a97..0000000000000 --- a/packages/web/src/migrations/update-8-5-0/update-builder-8-5-0.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updateWorkspaceInTree } from '@nrwl/workspace'; - -export default function update(): Rule { - return chain([ - updateWorkspaceInTree((config) => { - const filteredProjects = []; - Object.keys(config.projects).forEach((name) => { - if ( - config.projects[name].architect && - config.projects[name].architect.build && - config.projects[name].architect.build.builder === '@nrwl/web:build' - ) { - filteredProjects.push(config.projects[name]); - } - }); - filteredProjects.forEach((p) => { - delete p.architect.build.options.differentialLoading; - }); - return config; - }), - formatFiles(), - ]); -} diff --git a/packages/web/src/migrations/update-9-0-0/update-builder-9-0-0.ts b/packages/web/src/migrations/update-9-0-0/update-builder-9-0-0.ts deleted file mode 100644 index 8a27386fe3f74..0000000000000 --- a/packages/web/src/migrations/update-9-0-0/update-builder-9-0-0.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updateWorkspaceInTree } from '@nrwl/workspace'; - -export default function update(): Rule { - return chain([ - updateWorkspaceInTree((workspaceJson) => { - Object.entries(workspaceJson.projects).forEach( - ([projectName, project]) => { - Object.entries(project.architect).forEach( - ([targetName, targetConfig]) => { - if (targetConfig.builder === '@nrwl/web:bundle') { - workspaceJson.projects[projectName].architect[ - targetName - ].builder = '@nrwl/web:package'; - } - } - ); - } - ); - return workspaceJson; - }), - formatFiles(), - ]); -} diff --git a/packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts b/packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts deleted file mode 100644 index 76fae77494890..0000000000000 --- a/packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Tree } from '@angular-devkit/schematics'; -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; -import { readWorkspace, updateJsonInTree } from '@nrwl/workspace'; - -import * as path from 'path'; - -describe('set buildLibsFromSource to true', () => { - let tree: Tree; - let schematicRunner: SchematicTestRunner; - - beforeEach(async () => { - tree = Tree.empty(); - schematicRunner = new SchematicTestRunner( - '@nrwl/web', - path.join(__dirname, '../../../migrations.json') - ); - }); - - it(`should set buildLibsFromSource to true`, async () => { - tree = await schematicRunner - .callRule( - updateJsonInTree('workspace.json', () => ({ - projects: { - demo: { - root: 'apps/demo', - sourceRoot: 'apps/demo/src', - architect: { - build: { - builder: '@nrwl/web:build', - options: {}, - }, - }, - }, - }, - })), - tree - ) - .toPromise(); - - tree = await schematicRunner - .runSchematicAsync('set-build-libs-from-source', {}, tree) - .toPromise(); - - const config = readWorkspace(tree); - expect(config.projects.demo.architect.build.options).toEqual({ - buildLibsFromSource: true, - }); - }); -}); diff --git a/packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.ts b/packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.ts deleted file mode 100644 index f4008621e5635..0000000000000 --- a/packages/web/src/migrations/update-9-2-0/set-build-libs-from-source.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { chain, Rule } from '@angular-devkit/schematics'; -import { formatFiles, updateWorkspaceInTree } from '@nrwl/workspace'; - -export default function update(): Rule { - return chain([ - updateWorkspaceInTree((workspaceJson) => { - Object.entries(workspaceJson.projects).forEach( - ([projectName, project]) => { - Object.entries(project.architect).forEach( - ([targetName, targetConfig]) => { - if (targetConfig.builder === '@nrwl/web:build') { - const architect = - workspaceJson.projects[projectName].architect[targetName]; - if (architect && architect.options) { - architect.options.buildLibsFromSource = true; - } - } - } - ); - } - ); - return workspaceJson; - }), - formatFiles(), - ]); -} diff --git a/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts b/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts index d450289045463..37f930864bf0d 100644 --- a/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts +++ b/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts @@ -7,7 +7,7 @@ import { export function updateTasksRunner(host: Tree) { const config = readWorkspaceConfiguration(host); if ( - config?.tasksRunnerOptions['default'] && + config?.tasksRunnerOptions?.['default'] && config?.tasksRunnerOptions['default'].runner == '@nrwl/workspace/tasks-runners/default' ) { diff --git a/scripts/depcheck/missing.ts b/scripts/depcheck/missing.ts index ac0302e28b4ed..6c849c67ca5ac 100644 --- a/scripts/depcheck/missing.ts +++ b/scripts/depcheck/missing.ts @@ -1,7 +1,8 @@ import * as depcheck from 'depcheck'; +import { join, relative } from 'path'; // Ignore packages that are defined here per package -const IGNORE_MATCHES = { +const IGNORE_MATCHES_IN_PACKAGE = { '*': ['nx', '@nrwl/cli', '@nrwl/workspace', 'prettier', 'typescript', 'rxjs'], angular: [ '@angular-devkit/architect', @@ -130,6 +131,15 @@ const IGNORE_MATCHES = { 'make-angular-cli-faster': ['@angular/core'], }; +const IGNORE_MATCHES_BY_FILE: Record = { + '@storybook/core': [ + join( + __dirname, + '../../packages/angular/src/migrations/update-12-3-0/update-storybook.ts' + ), + ], +}; + export default async function getMissingDependencies( name: string, path: string, @@ -169,7 +179,6 @@ export default async function getMissingDependencies( '.eslintrc.json', '*.spec*', 'src/schematics/**/files/**', - 'src/migrations/**', ], }; let { missing } = await depcheck(path, { @@ -179,8 +188,11 @@ export default async function getMissingDependencies( const packagesMissing = Object.keys(missing).filter( (m) => - !IGNORE_MATCHES['*'].includes(m) && - !(IGNORE_MATCHES[name] || []).includes(m) + !IGNORE_MATCHES_IN_PACKAGE['*'].includes(m) && + !(IGNORE_MATCHES_IN_PACKAGE[name] || []).includes(m) && + missing[m].filter( + (occurence) => !IGNORE_MATCHES_BY_FILE[m]?.includes(occurence) + ).length ); if (verbose) {