From 47e9fc8ed6140b576913de18e66c9a3470d77c19 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 11 Oct 2023 10:46:17 -0400 Subject: [PATCH] feat(misc): remove migrations for v14 and under (#19552) --- package.json | 2 +- packages/cypress/migrations.json | 18 - .../remove-typescript-plugin.spec.ts | 80 -- .../update-12-8-0/remove-typescript-plugin.ts | 125 --- .../update-cypress-configs-presets.spec.ts | 420 -------- .../update-cypress-configs-presets.ts | 170 --- .../update-cypress-version-if-10.spec.ts | 78 -- .../update-cypress-version-if-10.ts | 46 - packages/detox/migrations.json | 164 --- .../add-verbose-jest-config-13-10-3.spec.ts | 37 - .../add-verbose-jest-config-13-10-3.ts | 32 - .../add-build-target-test-13-5-0.spec.ts | 73 -- .../add-build-target-test-13-5-0.ts | 35 - .../remove-types-detox-13-8-2.spec.ts | 35 - .../remove-types-detox-13-8-2.ts | 26 - packages/expo/migrations.json | 409 -------- ...d-project-root-metro-config-14-0-0.spec.ts | 192 ---- .../add-project-root-metro-config-14-0-0.ts | 43 - .../add-eject-target-14-1-2.spec.ts | 31 - .../update-14-1-2/add-eject-target-14-1-2.ts | 26 - .../add-eas-build-target.spec.ts | 41 - .../update-14-4-3/add-eas-build-target.ts | 43 - .../add-eas-update-target.spec.ts | 31 - .../update-14-5-1/add-eas-update-target.ts | 27 - packages/express/migrations.json | 25 +- packages/jest/migrations.json | 199 ---- .../update-jest-preset-angular.ts | 88 -- .../update-12-1-2/update-ts-jest.ts | 50 - .../add-test-environment-for-node.ts | 57 - .../update-jest-preset-angular.ts | 148 --- .../update-base-jest-config.spec.ts | 100 -- .../update-12-6-0/update-base-jest-config.ts | 62 -- .../update-tsconfigs-for-tests.spec.ts | 296 ------ .../update-tsconfigs-for-tests.ts | 85 -- .../add-missing-root-babel-config.spec.ts | 113 -- .../add-missing-root-babel-config.ts | 62 -- .../update-jest-config-ext.spec.ts.snap | 94 -- .../update-jest-config-ext.spec.ts | 314 ------ .../update-14-0-0/update-jest-config-ext.ts | 180 ---- .../update-exports-jest-config.spec.ts.snap | 76 -- .../update-exports-jest-config.spec.ts | 201 ---- .../update-exports-jest-config.ts | 93 -- .../update-configs-jest-28.spec.ts | 221 ---- .../update-14-6-0/update-configs-jest-28.ts | 117 --- .../update-tests-jest-28.spec.ts | 346 ------- .../update-14-6-0/update-tests-jest-28.ts | 202 ---- packages/js/migrations.json | 30 - .../update-lib-swcrc-exclude.spec.ts.snap | 36 - .../update-lib-swcrc-exclude.spec.ts | 90 -- .../update-lib-swcrc-exclude.ts | 41 - .../update-node-executor.spec.ts | 59 -- .../update-13-8-5/update-node-executor.ts | 36 - .../update-13-8-5/update-swcrc.spec.ts | 95 -- .../migrations/update-13-8-5/update-swcrc.ts | 39 - .../exclude-jest-config-swcrc.spec.ts.snap | 36 - .../exclude-jest-config-swcrc.spec.ts | 89 -- .../exclude-jest-config-swcrc.ts | 35 - .../update-14-1-5/update-swcrc-path.spec.ts | 31 - .../update-14-1-5/update-swcrc-path.ts | 46 - packages/linter/migrations.json | 208 ---- packages/linter/package.json | 1 - ...t-config-if-no-type-checking-rules.spec.ts | 231 ----- ...roject-config-if-no-type-checking-rules.ts | 38 - .../update-12-9-0/add-outputs.spec.ts | 71 -- .../migrations/update-12-9-0/add-outputs.ts | 26 - .../update-13-3-0/eslint-8-updates.spec.ts | 115 --- .../update-13-3-0/eslint-8-updates.ts | 56 - .../update-14-1-9/add-swc-deps-if-needed.ts | 13 - .../experimental-to-utils-deps.spec.ts.snap | 36 - .../experimental-to-utils-deps.spec.ts | 51 - .../experimental-to-utils-deps.ts | 45 - .../experimental-to-utils-rules.spec.ts | 132 --- .../experimental-to-utils-rules.ts | 39 - packages/nest/migrations.json | 35 - packages/nest/package.json | 2 - .../update-13-2-0/update-to-nest-8.ts | 89 -- packages/next/migrations.json | 260 ----- .../fix-page-dir-for-eslint.spec.ts | 114 -- .../update-12-10-0/fix-page-dir-for-eslint.ts | 45 - .../remove-styled-jsx-babel-plugin.spec.ts | 56 - .../remove-styled-jsx-babel-plugin.ts | 33 - .../update-emotion-setup.spec.ts | 85 -- .../update-13-0-0/update-emotion-setup.ts | 42 - .../update-13-0-0/update-to-webpack-5.spec.ts | 97 -- .../update-13-0-0/update-to-webpack-5.ts | 51 - .../src/migrations/update-13-0-3/fix-less.ts | 40 - .../update-13-1-1/enable-swc.spec.ts | 203 ---- .../migrations/update-13-1-1/enable-swc.ts | 62 -- ...default-development-configurations.spec.ts | 101 -- .../add-default-development-configurations.ts | 36 - .../update-14-4-3/add-dev-output-path.spec.ts | 65 -- .../update-14-4-3/add-dev-output-path.ts | 25 - .../update-14-5-3/add-gitignore-entry.ts | 9 - .../update-dev-output-path.spec.ts | 95 -- .../update-14-5-3/update-dev-output-path.ts | 31 - .../update-14-5-7/update-next-eslint.spec.ts | 60 -- .../update-14-5-7/update-next-eslint.ts | 28 - packages/node/migrations.json | 51 +- packages/node/package.json | 3 +- .../remove-deprecated-options-13-0-0.spec.ts | 52 - .../remove-deprecated-options-13-0-0.ts | 45 - .../remove-webpack-5-packages-13-0-0.spec.ts | 126 --- .../remove-webpack-5-packages-13-0-0.ts | 37 - .../rename-build-to-webpack.spec.ts | 42 - .../update-13-8-5/rename-build-to-webpack.ts | 21 - .../rename-execute-to-node.spec.ts | 42 - .../update-13-8-5/rename-execute-to-node.ts | 21 - .../update-package-to-tsc.spec.ts | 81 -- .../update-13-8-5/update-package-to-tsc.ts | 60 -- .../update-webpack-executor.spec.ts | 45 - .../update-14-7-6/update-webpack-executor.ts | 23 - packages/nx/migrations.json | 30 - .../update-14-0-6/remove-roots.spec.ts | 52 - .../migrations/update-14-0-6/remove-roots.ts | 18 - .../update-14-2-0/add-json-schema.spec.ts | 64 -- .../update-14-2-0/add-json-schema.ts | 59 -- .../remove-default-collection.spec.ts | 58 -- .../remove-default-collection.ts | 21 - ...lace-all-relative-outputs-with-absolute.ts | 25 - .../create-target-defaults.spec.ts | 46 - .../update-14-3-4/create-target-defaults.ts | 41 - packages/plugin/migrations.json | 12 - .../update-14-1-9/add-swc-deps-if-needed.ts | 8 - packages/react-native/migrations.json | 972 ------------------ .../add-react-native-svg-12-10-0.spec.ts | 79 -- .../add-react-native-svg-12-10-0.ts | 78 -- .../update-jest-for-react-native.ts | 86 -- .../add-babel-config-root-13-5-0.spec.ts | 48 - .../add-babel-config-root-13-5-0.ts | 23 - ...ate-react-native-typing-svg-13-5-0.spec.ts | 61 -- .../update-react-native-typing-svg-13-5-0.ts | 46 - ...d-project-root-metro-config-14-0-0.spec.ts | 192 ---- .../add-project-root-metro-config-14-0-0.ts | 42 - .../update-entry-file-bundle-14-0-0.spec.ts | 84 -- .../update-entry-file-bundle-14-0-0.ts | 45 - .../change-main-to-class-name-14-0-2.spec.ts | 48 - .../change-main-to-class-name-14-0-2.ts | 45 - .../rename-blockList-metro-config.spec.ts | 190 ---- .../rename-blockList-metro-config.ts | 40 - .../add-exclude-sync-deps.spec.ts | 39 - .../update-14-5-5/add-exclude-sync-deps.ts | 28 - .../change-searchDir-storybook.spec.ts | 39 - .../change-searchDir-storybook.ts | 28 - .../remove-jest-transform.spec.ts | 109 -- .../update-14-6-0/remove-jest-transform.ts | 68 -- packages/react/migrations.json | 698 ------------- .../remove-react-redux-types-package.ts | 11 - .../update-emotion-setup.spec.ts | 118 --- .../update-12-0-0/update-emotion-setup.ts | 65 -- .../use-react-jsx-in-tsconfig.spec.ts | 60 -- .../use-react-jsx-in-tsconfig.ts | 23 - .../migrations/update-12-8-0/update-12-8-0.ts | 13 - .../webpack5-changes-utils.spec.ts.snap | 14 - .../migrate-storybook-to-webpack-5.spec.ts | 360 ------- .../migrate-storybook-to-webpack-5.ts | 46 - .../update-emotion-setup.spec.ts | 83 -- .../update-13-0-0/update-emotion-setup.ts | 42 - .../webpack5-changes-utils.spec.ts | 61 -- .../update-13-0-0/webpack5-changes-utils.ts | 330 ------ .../update-13-10-0/update-13-10-0.spec.ts | 50 - .../update-13-10-0/update-13-10-0.ts | 35 - ...date-react-dom-render-for-v18.spec.ts.snap | 45 - ...default-development-configurations.spec.ts | 111 -- .../add-default-development-configurations.ts | 40 - ...replace-testing-library-react-hook.spec.ts | 40 - .../replace-testing-library-react-hook.ts | 36 - .../update-react-dom-render-for-v18.spec.ts | 117 --- .../update-react-dom-render-for-v18.ts | 104 -- ...pdate-external-emotion-jsx-runtime.spec.ts | 61 -- .../update-external-emotion-jsx-runtime.ts | 49 - .../add-preset-jest-config.spec.ts | 195 ---- .../update-14-6-0/add-preset-jest-config.ts | 56 - packages/rollup/migrations.json | 2 +- packages/storybook/migrations.json | 171 --- packages/storybook/package.json | 3 +- .../update-13-4-6/set-project-build-config.ts | 79 -- .../test-configs/custom-names-config.json | 146 --- .../test-configs/default-config.json | 146 --- .../test-configs/non-angular.json | 60 -- .../migrate-defaults-5-to-6.spec.ts | 165 --- .../migrate-defaults-5-to-6.ts | 210 ---- .../migrate-stories-to-6-2.spec.ts | 171 --- .../migrate-stories-to-6-2.ts | 406 -------- .../update-14-0-0/migrate-to-storybook-6.ts | 8 - ...e-storybook-targets-generator.spec.ts.snap | 133 --- ...change-storybook-targets-generator.spec.ts | 63 -- .../change-storybook-targets-generator.ts | 173 ---- .../update-14-1-8/change-storybook-targets.ts | 6 - .../test-configs/custom-names-config.json | 154 --- .../test-configs/default-config.json | 154 --- .../extra-options-for-storybook.json | 222 ---- .../no-build-storybook-target.json | 60 -- .../test-configs/no-storybook-targets.json | 34 - .../test-configs/non-angular.json | 60 -- packages/web/migrations.json | 57 +- .../remove-deprecated-options-13-0-0.spec.ts | 54 - .../remove-deprecated-options-13-0-0.ts | 39 - .../remove-node-sass-13-0-0.spec.ts | 40 - .../update-13-0-0/remove-node-sass-13-0-0.ts | 28 - .../remove-webpack-5-packages-13-0-0.spec.ts | 126 --- .../remove-webpack-5-packages-13-0-0.ts | 37 - .../rename-build-to-webpack.spec.ts | 42 - .../update-13-3-0/rename-build-to-webpack.ts | 20 - .../rename-package-to-rollup.spec.ts | 42 - .../update-13-3-0/rename-package-to-rollup.ts | 20 - .../add-postcss-config-option.spec.ts | 77 -- .../add-postcss-config-option.ts | 27 - ...lup-format-backwards-compatibility.spec.ts | 54 - .../rollup-format-backwards-compatibility.ts | 24 - .../update-webpack-executor.spec.ts | 50 - .../update-14-7-6/update-webpack-executor.ts | 27 - packages/workspace/migrations.json | 135 --- .../update-12-5-0/add-target-dependencies.ts | 49 - .../config-locations/config-locations.ts | 46 - .../set-default-base-if-not-set.spec.ts | 30 - .../set-default-base-if-not-set.ts | 23 - .../update-13-10-0/update-decorate-cli.ts | 20 - .../update-13-10-0/update-tasks-runner.ts | 15 - .../update-13-2-0/set-parallel-default.ts | 20 - .../update-tsc-executor-location.spec.ts | 87 -- .../update-tsc-executor-location.ts | 41 - .../remove-old-task-runner-options.spec.ts | 44 - .../remove-old-task-runner-options.ts | 13 - .../update-13-9-0/replace-tao-with-nx.ts | 25 - .../update-13-9-0/update-decorate-cli.ts | 13 - .../change-npm-script-executor.spec.ts | 51 - .../change-npm-script-executor.ts | 27 - .../update-14-0-0/change-nx-json-presets.ts | 19 - .../update-14-2-0/enable-source-analysis.ts | 25 - .../change-run-commands-executor.spec.ts | 51 - .../change-run-commands-executor.ts | 27 - pnpm-lock.yaml | 54 +- tools/workspace-plugin/.eslintrc.json | 32 + tools/workspace-plugin/README.md | 11 + tools/workspace-plugin/generators.json | 9 + tools/workspace-plugin/jest.config.ts | 10 + tools/workspace-plugin/package.json | 12 + tools/workspace-plugin/project.json | 33 + .../generators/remove-migrations/generator.ts | 101 ++ .../generators/remove-migrations/schema.json | 12 + tools/workspace-plugin/src/index.ts | 0 tools/workspace-plugin/tsconfig.json | 16 + tools/workspace-plugin/tsconfig.lib.json | 10 + tools/workspace-plugin/tsconfig.spec.json | 14 + tsconfig.base.json | 1 + 245 files changed, 295 insertions(+), 19209 deletions(-) delete mode 100644 packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.spec.ts delete mode 100644 packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.ts delete mode 100644 packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts delete mode 100644 packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.ts delete mode 100644 packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.spec.ts delete mode 100644 packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.ts delete mode 100644 packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.spec.ts delete mode 100644 packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.ts delete mode 100644 packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.spec.ts delete mode 100644 packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.ts delete mode 100644 packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.spec.ts delete mode 100644 packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.ts delete mode 100644 packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts delete mode 100644 packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts delete mode 100644 packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.spec.ts delete mode 100644 packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.ts delete mode 100644 packages/expo/src/migrations/update-14-4-3/add-eas-build-target.spec.ts delete mode 100644 packages/expo/src/migrations/update-14-4-3/add-eas-build-target.ts delete mode 100644 packages/expo/src/migrations/update-14-5-1/add-eas-update-target.spec.ts delete mode 100644 packages/expo/src/migrations/update-14-5-1/add-eas-update-target.ts delete mode 100644 packages/jest/src/migrations/update-12-1-2/update-jest-preset-angular.ts delete mode 100644 packages/jest/src/migrations/update-12-1-2/update-ts-jest.ts delete mode 100644 packages/jest/src/migrations/update-12-4-0/add-test-environment-for-node.ts delete mode 100644 packages/jest/src/migrations/update-12-4-0/update-jest-preset-angular.ts delete mode 100644 packages/jest/src/migrations/update-12-6-0/update-base-jest-config.spec.ts delete mode 100644 packages/jest/src/migrations/update-12-6-0/update-base-jest-config.ts delete mode 100644 packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.spec.ts delete mode 100644 packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.ts delete mode 100644 packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.spec.ts delete mode 100644 packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.ts delete mode 100644 packages/jest/src/migrations/update-14-0-0/__snapshots__/update-jest-config-ext.spec.ts.snap delete mode 100644 packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts delete mode 100644 packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.ts delete mode 100644 packages/jest/src/migrations/update-14-1-5/__snapshots__/update-exports-jest-config.spec.ts.snap delete mode 100644 packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts delete mode 100644 packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.ts delete mode 100644 packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts delete mode 100644 packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.ts delete mode 100644 packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts delete mode 100644 packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.ts delete mode 100644 packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap delete mode 100644 packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.spec.ts delete mode 100644 packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.ts delete mode 100644 packages/js/src/migrations/update-13-8-5/update-node-executor.spec.ts delete mode 100644 packages/js/src/migrations/update-13-8-5/update-node-executor.ts delete mode 100644 packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts delete mode 100644 packages/js/src/migrations/update-13-8-5/update-swcrc.ts delete mode 100644 packages/js/src/migrations/update-14-0-0/__snapshots__/exclude-jest-config-swcrc.spec.ts.snap delete mode 100644 packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.spec.ts delete mode 100644 packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.ts delete mode 100644 packages/js/src/migrations/update-14-1-5/update-swcrc-path.spec.ts delete mode 100644 packages/js/src/migrations/update-14-1-5/update-swcrc-path.ts delete mode 100644 packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts delete mode 100644 packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts delete mode 100644 packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts delete mode 100644 packages/linter/src/migrations/update-12-9-0/add-outputs.ts delete mode 100644 packages/linter/src/migrations/update-13-3-0/eslint-8-updates.spec.ts delete mode 100644 packages/linter/src/migrations/update-13-3-0/eslint-8-updates.ts delete mode 100644 packages/linter/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts delete mode 100644 packages/linter/src/migrations/update-14-4-4/__snapshots__/experimental-to-utils-deps.spec.ts.snap delete mode 100644 packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.spec.ts delete mode 100644 packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.ts delete mode 100644 packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.spec.ts delete mode 100644 packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.ts delete mode 100644 packages/nest/src/migrations/update-13-2-0/update-to-nest-8.ts delete mode 100644 packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.spec.ts delete mode 100644 packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.ts delete mode 100644 packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.spec.ts delete mode 100644 packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.ts delete mode 100644 packages/next/src/migrations/update-13-0-0/update-emotion-setup.spec.ts delete mode 100644 packages/next/src/migrations/update-13-0-0/update-emotion-setup.ts delete mode 100644 packages/next/src/migrations/update-13-0-0/update-to-webpack-5.spec.ts delete mode 100644 packages/next/src/migrations/update-13-0-0/update-to-webpack-5.ts delete mode 100644 packages/next/src/migrations/update-13-0-3/fix-less.ts delete mode 100644 packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts delete mode 100644 packages/next/src/migrations/update-13-1-1/enable-swc.ts delete mode 100644 packages/next/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts delete mode 100644 packages/next/src/migrations/update-14-0-0/add-default-development-configurations.ts delete mode 100644 packages/next/src/migrations/update-14-4-3/add-dev-output-path.spec.ts delete mode 100644 packages/next/src/migrations/update-14-4-3/add-dev-output-path.ts delete mode 100644 packages/next/src/migrations/update-14-5-3/add-gitignore-entry.ts delete mode 100644 packages/next/src/migrations/update-14-5-3/update-dev-output-path.spec.ts delete mode 100644 packages/next/src/migrations/update-14-5-3/update-dev-output-path.ts delete mode 100644 packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts delete mode 100644 packages/next/src/migrations/update-14-5-7/update-next-eslint.ts delete mode 100644 packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts delete mode 100644 packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts delete mode 100644 packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts delete mode 100644 packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts delete mode 100644 packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.spec.ts delete mode 100644 packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.ts delete mode 100644 packages/node/src/migrations/update-13-8-5/rename-execute-to-node.spec.ts delete mode 100644 packages/node/src/migrations/update-13-8-5/rename-execute-to-node.ts delete mode 100644 packages/node/src/migrations/update-13-8-5/update-package-to-tsc.spec.ts delete mode 100644 packages/node/src/migrations/update-13-8-5/update-package-to-tsc.ts delete mode 100644 packages/node/src/migrations/update-14-7-6/update-webpack-executor.spec.ts delete mode 100644 packages/node/src/migrations/update-14-7-6/update-webpack-executor.ts delete mode 100644 packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts delete mode 100644 packages/nx/src/migrations/update-14-0-6/remove-roots.ts delete mode 100644 packages/nx/src/migrations/update-14-2-0/add-json-schema.spec.ts delete mode 100644 packages/nx/src/migrations/update-14-2-0/add-json-schema.ts delete mode 100644 packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts delete mode 100644 packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts delete mode 100644 packages/nx/src/migrations/update-14-2-0/replace-all-relative-outputs-with-absolute.ts delete mode 100644 packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts delete mode 100644 packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts delete mode 100644 packages/plugin/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts delete mode 100644 packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.spec.ts delete mode 100644 packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.ts delete mode 100644 packages/react-native/src/migrations/update-12-5-0/update-jest-for-react-native.ts delete mode 100644 packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.spec.ts delete mode 100644 packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.ts delete mode 100644 packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.spec.ts delete mode 100644 packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.ts delete mode 100644 packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts delete mode 100644 packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts delete mode 100644 packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.spec.ts delete mode 100644 packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.ts delete mode 100644 packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.spec.ts delete mode 100644 packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.ts delete mode 100644 packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.spec.ts delete mode 100644 packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.ts delete mode 100644 packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.spec.ts delete mode 100644 packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.ts delete mode 100644 packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.spec.ts delete mode 100644 packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts delete mode 100644 packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.spec.ts delete mode 100644 packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.ts delete mode 100644 packages/react/src/migrations/update-12-0-0/remove-react-redux-types-package.ts delete mode 100644 packages/react/src/migrations/update-12-0-0/update-emotion-setup.spec.ts delete mode 100644 packages/react/src/migrations/update-12-0-0/update-emotion-setup.ts delete mode 100644 packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.spec.ts delete mode 100644 packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.ts delete mode 100644 packages/react/src/migrations/update-12-8-0/update-12-8-0.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/__snapshots__/webpack5-changes-utils.spec.ts.snap delete mode 100644 packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.spec.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/update-emotion-setup.spec.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/update-emotion-setup.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts delete mode 100644 packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts delete mode 100644 packages/react/src/migrations/update-13-10-0/update-13-10-0.spec.ts delete mode 100644 packages/react/src/migrations/update-13-10-0/update-13-10-0.ts delete mode 100644 packages/react/src/migrations/update-14-0-0/__snapshots__/update-react-dom-render-for-v18.spec.ts.snap delete mode 100644 packages/react/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts delete mode 100644 packages/react/src/migrations/update-14-0-0/add-default-development-configurations.ts delete mode 100644 packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.spec.ts delete mode 100644 packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.ts delete mode 100644 packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.spec.ts delete mode 100644 packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts delete mode 100644 packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.spec.ts delete mode 100644 packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.ts delete mode 100644 packages/react/src/migrations/update-14-6-0/add-preset-jest-config.spec.ts delete mode 100644 packages/react/src/migrations/update-14-6-0/add-preset-jest-config.ts delete mode 100644 packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts delete mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json delete mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json delete mode 100644 packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts delete mode 100644 packages/storybook/src/migrations/update-14-0-0/migrate-to-storybook-6.ts delete mode 100644 packages/storybook/src/migrations/update-14-1-8/__snapshots__/change-storybook-targets-generator.spec.ts.snap delete mode 100644 packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts delete mode 100644 packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts delete mode 100644 packages/storybook/src/migrations/update-14-1-8/change-storybook-targets.ts delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json delete mode 100644 packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.spec.ts delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.ts delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts delete mode 100644 packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts delete mode 100644 packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.spec.ts delete mode 100644 packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.ts delete mode 100644 packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.spec.ts delete mode 100644 packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.ts delete mode 100644 packages/web/src/migrations/update-13-8-0/add-postcss-config-option.spec.ts delete mode 100644 packages/web/src/migrations/update-13-8-0/add-postcss-config-option.ts delete mode 100644 packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts delete mode 100644 packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts delete mode 100644 packages/web/src/migrations/update-14-7-6/update-webpack-executor.spec.ts delete mode 100644 packages/web/src/migrations/update-14-7-6/update-webpack-executor.ts delete mode 100644 packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts delete mode 100644 packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts delete mode 100644 packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts delete mode 100644 packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts delete mode 100644 packages/workspace/src/migrations/update-13-10-0/update-decorate-cli.ts delete mode 100644 packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts delete mode 100644 packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts delete mode 100644 packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.spec.ts delete mode 100644 packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.ts delete mode 100644 packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.spec.ts delete mode 100644 packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts delete mode 100644 packages/workspace/src/migrations/update-13-9-0/replace-tao-with-nx.ts delete mode 100644 packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts delete mode 100644 packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts delete mode 100644 packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts delete mode 100644 packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts delete mode 100644 packages/workspace/src/migrations/update-14-2-0/enable-source-analysis.ts delete mode 100644 packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.spec.ts delete mode 100644 packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.ts create mode 100644 tools/workspace-plugin/.eslintrc.json create mode 100644 tools/workspace-plugin/README.md create mode 100644 tools/workspace-plugin/generators.json create mode 100644 tools/workspace-plugin/jest.config.ts create mode 100644 tools/workspace-plugin/package.json create mode 100644 tools/workspace-plugin/project.json create mode 100644 tools/workspace-plugin/src/generators/remove-migrations/generator.ts create mode 100644 tools/workspace-plugin/src/generators/remove-migrations/schema.json create mode 100644 tools/workspace-plugin/src/index.ts create mode 100644 tools/workspace-plugin/tsconfig.json create mode 100644 tools/workspace-plugin/tsconfig.lib.json create mode 100644 tools/workspace-plugin/tsconfig.spec.json diff --git a/package.json b/package.json index 22221c15b44ea..7038a34e535a4 100644 --- a/package.json +++ b/package.json @@ -315,7 +315,7 @@ "@markdoc/markdoc": "0.2.2", "@monaco-editor/react": "^4.4.6", "@napi-rs/canvas": "^0.1.19", - "@swc/helpers": "0.5.0", + "@swc/helpers": "~0.5.2", "@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/forms": "^0.5.3", "@tailwindcss/line-clamp": "^0.4.2", diff --git a/packages/cypress/migrations.json b/packages/cypress/migrations.json index ffd13a3e40983..05dfff1a369c6 100644 --- a/packages/cypress/migrations.json +++ b/packages/cypress/migrations.json @@ -1,23 +1,5 @@ { "generators": { - "remove-typescript-plugin": { - "cli": "nx", - "version": "12.8.0-beta.0", - "description": "Remove Typescript Preprocessor Plugin", - "factory": "./src/migrations/update-12-8-0/remove-typescript-plugin" - }, - "update-cypress-configs-preset": { - "cli": "nx", - "version": "14.6.1-beta.0", - "description": "Change Cypress e2e and component testing presets to use __filename instead of __dirname and include a devServerTarget for component testing.", - "factory": "./src/migrations/update-14-6-1/update-cypress-configs-presets" - }, - "update-cypress-if-v10": { - "cli": "nx", - "version": "14.7.0-beta.0", - "description": "Update Cypress if using v10 to support latest component testing features", - "factory": "./src/migrations/update-14-7-0/update-cypress-version-if-10" - }, "add-cypress-inputs": { "cli": "nx", "version": "15.0.0-beta.0", diff --git a/packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.spec.ts b/packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.spec.ts deleted file mode 100644 index 587a5eb8e4dd6..0000000000000 --- a/packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.spec.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, Tree, writeJson } from '@nx/devkit'; -import removeTypescriptPlugin from './remove-typescript-plugin'; - -describe('remove typescript plugin', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'proj', { - root: 'proj', - targets: { - cypress: { - executor: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'proj/cypress.json', - }, - }, - }, - }); - - writeJson(tree, 'proj/cypress.json', { - pluginsFile: './plugins.js', - }); - - tree.write( - 'proj/plugins.js', - ` - // *********************************************************** - // 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) - - const { preprocessTypescript } = require('@nx/cypress/plugins/preprocessor'); - - module.exports = (on, config) => { - // \`on\` is used to hook into various events Cypress emits - // \`config\` is the resolved Cypress config - - // Preprocess Typescript - on('file:preprocessor', preprocessTypescript(config)); - }; - ` - ); - }); - - it('should remove the plugin', async () => { - await removeTypescriptPlugin(tree); - - expect(tree.read('proj/plugins.js', 'utf-8')).not.toContain( - 'preprocessTypescript(config)' - ); - }); - - it('should not remove the plugin if they have a custom webpack config', async () => { - tree.write( - 'proj/plugins.js', - tree - .read('proj/plugins.js', 'utf-8') - .replace( - 'preprocessTypescript(config)', - 'preprocessTypescript(config, webpackFunction)' - ) - ); - await removeTypescriptPlugin(tree); - - expect(tree.read('proj/plugins.js', 'utf-8')).toContain( - 'preprocessTypescript(config, webpackFunction)' - ); - }); -}); diff --git a/packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.ts b/packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.ts deleted file mode 100644 index 1bff0abc7aba6..0000000000000 --- a/packages/cypress/src/migrations/update-12-8-0/remove-typescript-plugin.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { - applyChangesToString, - ChangeType, - formatFiles, - getProjects, - ProjectConfiguration, - readJson, - StringDeletion, - TargetConfiguration, - Tree, -} from '@nx/devkit'; -import { - createSourceFile, - isCallExpression, - isExpressionStatement, - isIdentifier, - Node, - ScriptTarget, -} from 'typescript'; -import { dirname, join } from 'path'; -import { installedCypressVersion } from '../../utils/cypress-version'; - -export default async function removeTypescriptPlugin(tree: Tree) { - const cypressVersion = installedCypressVersion(); - if (cypressVersion < 7) { - console.warn( - `Cypress v${cypressVersion} is installed. This migration was skipped. Please rerun this migration after updating to Cypress 7.` - ); - return; - } - - for (const [_, proj] of getProjects(tree)) { - const cypressTargets = getCypressTargets(proj); - if (cypressTargets.length <= 0) { - continue; - } - - for (const target of cypressTargets) { - const cypressConfigs = getCypressConfigs(target); - - for (const config of cypressConfigs) { - const cypressConfig = readJson(tree, config); - if (cypressConfig.pluginsFile) { - let pluginPath = join(dirname(config), cypressConfig.pluginsFile); - if (!tree.exists(pluginPath)) { - pluginPath = ['.js', '.ts'] - .map((ext) => pluginPath + ext) - .find((path) => tree.exists(path)); - } - removePreprocessor(tree, pluginPath); - } - } - } - } - - await formatFiles(tree); -} - -function removePreprocessor(tree: Tree, pluginPath: string) { - const pluginContents = tree.read(pluginPath, 'utf-8'); - const sourceFile = createSourceFile( - pluginPath, - pluginContents, - ScriptTarget.ESNext, - true - ); - - const deletions: StringDeletion[] = []; - - const callback = (node: Node) => { - // Look for the invocation of preprocessTypescript - if ( - isCallExpression(node) && - isIdentifier(node.expression) && - node.expression.getText(sourceFile) === 'preprocessTypescript' && - node.arguments.length < 2 - ) { - // Get the Statement that the function call belongs to - let n: Node = node.parent; - while (!isExpressionStatement(n) && n === sourceFile) { - n = n.parent; - } - - deletions.push({ - type: ChangeType.Delete, - start: n.getStart(), - length: - n.getWidth() + - (pluginContents[n.getStart() + n.getWidth()] === ';' ? 1 : 0), - }); - } - }; - - // Call the callback for every node in the file - sourceFile.forEachChild(recurse); - - function recurse(node: Node) { - callback(node); - node.forEachChild((child) => recurse(child)); - } - - // Remove the preprocessor from the file - tree.write(pluginPath, applyChangesToString(pluginContents, deletions)); -} - -function getCypressConfigs(target: TargetConfiguration): string[] { - if (!target.configurations && !target.options.cypressConfig) { - return []; - } else if (!target.configurations && target.options.cypressConfig) { - return [target.options.cypressConfig]; - } - - return [target.options, Object.values(target.configurations)] - .filter((options) => !!options.cypressConfig) - .map((options) => options.cypressConfig); -} - -function getCypressTargets(proj: ProjectConfiguration) { - if (!proj.targets) { - return []; - } - return Object.values(proj.targets).filter( - (target) => target.executor === '@nrwl/cypress:cypress' - ); -} diff --git a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts b/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts deleted file mode 100644 index fcd97df652eb9..0000000000000 --- a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.spec.ts +++ /dev/null @@ -1,420 +0,0 @@ -import { updateCypressConfigsPresets } from './update-cypress-configs-presets'; -import { installedCypressVersion } from '../../utils/cypress-version'; -import { - addProjectConfiguration, - DependencyType, - logger, - ProjectGraph, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { cypressProjectGenerator } from '../../generators/cypress-project/cypress-project'; -import { libraryGenerator } from '@nx/js'; - -let projectGraph: ProjectGraph; -jest.mock('@nx/devkit', () => { - return { - ...jest.requireActual('@nx/devkit'), - createProjectGraphAsync: jest.fn().mockImplementation(() => projectGraph), - readTargetOptions: jest.fn().mockImplementation(() => ({})), - }; -}); -jest.mock('../../utils/cypress-version'); -describe('updateComponentTestingConfig', () => { - let tree: Tree; - let mockedInstalledCypressVersion: jest.Mock< - ReturnType - > = installedCypressVersion as never; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - it('should update', async () => { - mockedInstalledCypressVersion.mockReturnValue(10); - await setup(tree, { name: 'something' }); - await updateCypressConfigsPresets(tree); - expect( - tree.read('libs/something-lib/cypress.config.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__filename), -}); -` - ); - expect( - tree.read('libs/something-lib/cypress.config-two.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__filename, { ctTargetName: 'ct' }), -}); -` - ); - - expect(tree.read('apps/something-e2e/cypress.config.ts', 'utf-8')) - .toContain(`export default defineConfig({ - e2e: nxE2EPreset(__filename), -}); -`); - expect(tree.read('apps/something-e2e/cypress.storybook-config.ts', 'utf-8')) - .toContain(`export default defineConfig({ - e2e: nxE2EStorybookPreset(__filename), -}); -`); - const libProjectConfig = readProjectConfiguration(tree, 'something-lib'); - expect(libProjectConfig.targets['component-test']).toEqual({ - executor: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'libs/something-lib/cypress.config.ts', - testingType: 'component', - devServerTarget: 'something-app:build', - skipServe: true, - }, - }); - expect(libProjectConfig.targets['ct']).toEqual({ - executor: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'libs/something-lib/cypress.config-two.ts', - testingType: 'component', - devServerTarget: 'something-app:build', - skipServe: true, - }, - configurations: { - prod: { - baseUrl: 'https://example.com', - }, - }, - }); - }); - - it('should list out projects when unable to update config', async () => { - const loggerSpy = jest.spyOn(logger, 'warn'); - await setup(tree, { name: 'something' }); - projectGraph = { - nodes: {}, - dependencies: {}, - }; - await updateCypressConfigsPresets(tree); - - expect(loggerSpy.mock.calls).toEqual([ - [ - 'Unable to find a build target to add to the component testing target in the following projects:', - ], - ['- something-lib'], - [ - `You can manually add the 'devServerTarget' option to the -component testing target to specify the build target to use. -The build configuration should be using @nrwl/web:webpack as the executor. -Usually this is a React app in your workspace. -Component testing will fallback to a default configuration if one isn't provided, -but might require modifications if your projects are more complex.`, - ], - ]); - }); - - it('should handle already updated config', async () => { - mockedInstalledCypressVersion.mockReturnValue(10); - await setup(tree, { name: 'something' }); - - expect(async () => { - await updateCypressConfigsPresets(tree); - }).not.toThrow(); - expect(tree.read('libs/something-lib/cypress.config.ts', 'utf-8')) - .toContain(`export default defineConfig({ - component: nxComponentTestingPreset(__filename), -}); -`); - expect( - tree.read('libs/something-lib/cypress.config-two.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__filename, { ctTargetName: 'ct' }), -}); -` - ); - - expect(tree.read('apps/something-e2e/cypress.config.ts', 'utf-8')) - .toContain(`export default defineConfig({ - e2e: nxE2EPreset(__filename), -}); -`); - }); - it('should not update if using < v10', async () => { - mockedInstalledCypressVersion.mockReturnValue(9); - await setup(tree, { name: 'something' }); - await updateCypressConfigsPresets(tree); - expect( - tree.read('libs/something-lib/cypress.config.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__dirname), -}); -` - ); - expect( - tree.read('libs/something-lib/cypress.config-two.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__dirname), -}); -` - ); - - expect(tree.read('apps/something-e2e/cypress.config.ts', 'utf-8')) - .toContain(`export default defineConfig({ - e2e: nxE2EPreset(__dirname), -}); -`); - }); - - it('should be idempotent', async () => { - mockedInstalledCypressVersion.mockReturnValue(10); - await setup(tree, { name: 'something' }); - await updateCypressConfigsPresets(tree); - expect( - tree.read('libs/something-lib/cypress.config.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__filename), -}); -` - ); - expect( - tree.read('libs/something-lib/cypress.config-two.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__filename, { ctTargetName: 'ct' }), -}); -` - ); - - expect(tree.read('apps/something-e2e/cypress.config.ts', 'utf-8')) - .toContain(`export default defineConfig({ - e2e: nxE2EPreset(__filename), -}); -`); - const libProjectConfig = readProjectConfiguration(tree, 'something-lib'); - expect(libProjectConfig.targets['component-test']).toEqual({ - executor: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'libs/something-lib/cypress.config.ts', - testingType: 'component', - devServerTarget: 'something-app:build', - skipServe: true, - }, - }); - expect(libProjectConfig.targets['ct']).toEqual({ - executor: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'libs/something-lib/cypress.config-two.ts', - testingType: 'component', - devServerTarget: 'something-app:build', - skipServe: true, - }, - configurations: { - prod: { - baseUrl: 'https://example.com', - }, - }, - }); - - await updateCypressConfigsPresets(tree); - expect( - tree.read('libs/something-lib/cypress.config.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__filename), -}); -` - ); - expect( - tree.read('libs/something-lib/cypress.config-two.ts', 'utf-8') - ).toContain( - `export default defineConfig({ - component: nxComponentTestingPreset(__filename, { ctTargetName: 'ct' }), -}); -` - ); - - expect(tree.read('apps/something-e2e/cypress.config.ts', 'utf-8')) - .toContain(`export default defineConfig({ - e2e: nxE2EPreset(__filename), -}); -`); - const libProjectConfig2 = readProjectConfiguration(tree, 'something-lib'); - expect(libProjectConfig2.targets['component-test']).toEqual({ - executor: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'libs/something-lib/cypress.config.ts', - testingType: 'component', - devServerTarget: 'something-app:build', - skipServe: true, - }, - }); - expect(libProjectConfig2.targets['ct']).toEqual({ - executor: '@nrwl/cypress:cypress', - options: { - cypressConfig: 'libs/something-lib/cypress.config-two.ts', - testingType: 'component', - devServerTarget: 'something-app:build', - skipServe: true, - }, - configurations: { - prod: { - baseUrl: 'https://example.com', - }, - }, - }); - }); -}); - -async function setup(tree: Tree, options: { name: string }) { - const appName = `${options.name}-app`; - const libName = `${options.name}-lib`; - const e2eName = `${options.name}-e2e`; - tree.write( - 'apps/my-app/cypress.config.ts', - `import { defineConfig } from 'cypress'; -import { nxComponentTestingPreset } from '@nrwl/cypress/plugins/component-testing'; - -export default defineConfig({ - component: nxComponentTestingPreset(__dirname), -}); -` - ); - - addProjectConfiguration(tree, appName, { - root: `apps/my-app`, - sourceRoot: `apps/${appName}/src`, - targets: { - build: { - executor: '@nrwl/web:webpack', - outputs: ['{options.outputPath}'], - options: { - compiler: 'babel', - outputPath: `dist/apps/${appName}`, - index: `apps/${appName}/src/index.html`, - baseHref: '/', - main: `apps/${appName}/src/main.tsx`, - polyfills: `apps/${appName}/src/polyfills.ts`, - tsConfig: `apps/${appName}/tsconfig.app.json`, - }, - }, - }, - }); - await cypressProjectGenerator(tree, { project: appName, name: e2eName }); - const e2eProjectConfig = readProjectConfiguration(tree, e2eName); - e2eProjectConfig.targets['e2e'] = { - ...e2eProjectConfig.targets['e2e'], - executor: '@nrwl/cypress:cypress', - }; - e2eProjectConfig.targets['e2e'].configurations = { - ...e2eProjectConfig.targets['e2e'].configurations, - sb: { - cypressConfig: `apps/${e2eName}/cypress.storybook-config.ts`, - }, - }; - updateProjectConfiguration(tree, e2eName, e2eProjectConfig); - tree.write( - `apps/${e2eName}/cypress.config.ts`, - `import { defineConfig } from 'cypress'; -import { nxE2EPreset } from '@nrwl/cypress/plugins/cypress-preset'; - -export default defineConfig({ - e2e: nxE2EPreset(__dirname), -}); -` - ); - tree.write( - `apps/${e2eName}/cypress.storybook-config.ts`, - ` - import { defineConfig } from 'cypress'; -import { nxE2EStorybookPreset } from '@nrwl/cypress/plugins/cypress-preset'; - -export default defineConfig({ - e2e: nxE2EStorybookPreset(__dirname), -}); -` - ); - // lib - await libraryGenerator(tree, { name: libName }); - const libProjectConfig = readProjectConfiguration(tree, libName); - libProjectConfig.targets = { - ...libProjectConfig.targets, - 'component-test': { - executor: '@nrwl/cypress:cypress', - options: { - testingType: 'component', - cypressConfig: `libs/${libName}/cypress.config.ts`, - }, - }, - ct: { - executor: '@nrwl/cypress:cypress', - options: { - testingType: 'component', - cypressConfig: `libs/${libName}/cypress.config-two.ts`, - }, - configurations: { - prod: { - baseUrl: 'https://example.com', - }, - }, - }, - }; - updateProjectConfiguration(tree, libName, libProjectConfig); - tree.write( - `libs/${libName}/cypress.config.ts`, - `import { defineConfig } from 'cypress'; -import { nxComponentTestingPreset } from '@nrwl/cypress/plugins/component-testing'; - -export default defineConfig({ - component: nxComponentTestingPreset(__dirname), -}); -` - ); - tree.write( - `libs/${libName}/cypress.config-two.ts`, - `import { defineConfig } from 'cypress'; -import { nxComponentTestingPreset } from '@nrwl/cypress/plugins/component-testing'; - -export default defineConfig({ - component: nxComponentTestingPreset(__dirname), -}); -` - ); - - projectGraph = { - nodes: { - [appName]: { - name: appName, - type: 'app', - data: { - ...readProjectConfiguration(tree, appName), - }, - }, - [e2eName]: { - name: e2eName, - type: 'e2e', - data: { - ...readProjectConfiguration(tree, e2eName), - }, - }, - [libName]: { - name: libName, - type: 'lib', - data: { - ...readProjectConfiguration(tree, libName), - }, - }, - } as any, - dependencies: { - [appName]: [ - { type: DependencyType.static, source: appName, target: libName }, - ], - [e2eName]: [ - { type: DependencyType.implicit, source: e2eName, target: libName }, - ], - }, - }; -} diff --git a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.ts b/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.ts deleted file mode 100644 index 310aae3e90eda..0000000000000 --- a/packages/cypress/src/migrations/update-14-6-1/update-cypress-configs-presets.ts +++ /dev/null @@ -1,170 +0,0 @@ -import { - logger, - readProjectConfiguration, - stripIndents, - Tree, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { tsquery } from '@phenomnomnominal/tsquery'; -import * as ts from 'typescript'; -import { CypressExecutorOptions } from '../../executors/cypress/cypress.impl'; -import { installedCypressVersion } from '../../utils/cypress-version'; -import { findBuildConfig } from '../../utils/find-target-options'; - -export async function updateCypressConfigsPresets(tree: Tree) { - if (installedCypressVersion() < 10) { - return; - } - - const projectsWithoutDevServerTarget = new Set(); - const updateTasks = []; - forEachExecutorOptions( - tree, - '@nrwl/cypress:cypress', - (options, projectName, targetName, configName) => { - if (options.cypressConfig && tree.exists(options.cypressConfig)) { - updatePreset(tree, options, targetName); - } - - const projectConfig = readProjectConfiguration(tree, projectName); - const testingType = - options.testingType || - projectConfig.targets[targetName]?.options?.testingType; - const devServerTarget = - options.devServerTarget || - projectConfig.targets[targetName]?.options?.devServerTarget; - - if (!devServerTarget && testingType === 'component') { - updateTasks.push( - addBuildTargetToConfig( - tree, - projectName, - targetName, - configName - ).then((didUpdate) => { - if (!didUpdate) { - projectsWithoutDevServerTarget.add(projectName); - } - }) - ); - } - } - ); - - if (updateTasks.length > 0) { - cacheComponentTestTarget(tree); - } - - await Promise.all(updateTasks); - - if (projectsWithoutDevServerTarget.size > 0) { - logger.warn( - `Unable to find a build target to add to the component testing target in the following projects:` - ); - logger.warn(`- ${Array.from(projectsWithoutDevServerTarget).join('\n- ')}`); - logger.warn(stripIndents` -You can manually add the 'devServerTarget' option to the -component testing target to specify the build target to use. -The build configuration should be using @nrwl/web:webpack as the executor. -Usually this is a React app in your workspace. -Component testing will fallback to a default configuration if one isn't provided, -but might require modifications if your projects are more complex. - `); - } -} - -function updatePreset( - tree: Tree, - options: CypressExecutorOptions, - targetName: string | undefined -) { - let contents = tsquery.replace( - tree.read(options.cypressConfig, 'utf-8'), - 'CallExpression', - (node: ts.CallExpression) => { - // technically someone could have both component and e2e in the same project. - const expression = node.expression.getText(); - if (expression === 'nxE2EPreset') { - return 'nxE2EPreset(__filename)'; - } else if (expression === 'nxE2EStorybookPreset') { - return 'nxE2EStorybookPreset(__filename)'; - } else if (node.expression.getText() === 'nxComponentTestingPreset') { - return targetName && targetName !== 'component-test' // the default - ? `nxComponentTestingPreset(__filename, { ctTargetName: '${targetName}' })` - : 'nxComponentTestingPreset(__filename)'; - } - return; - } - ); - - tree.write(options.cypressConfig, contents); -} - -async function addBuildTargetToConfig( - tree: Tree, - projectName: string, - targetName: string, - configName?: string -): Promise { - const projectWithBuild = await findBuildConfig(tree, { - project: projectName, - validExecutorNames: new Set(['@nrwl/web:webpack']), - skipGetOptions: true, - }); - // didn't find the config so can't update. consumer should collect list of them and display a warning at the end - // no reason to fail since the preset will fallback to a default config so should still keep working. - if (!projectWithBuild?.target) { - return false; - } - - const projectConfig = readProjectConfiguration(tree, projectName); - // if using a custom config and the devServerTarget default args - // has a different target, then add it to the custom target config - // otherwise add it to the default options - if ( - configName && - projectWithBuild.target !== - projectConfig.targets[targetName]?.options?.devServerTarget - ) { - projectConfig.targets[targetName].configurations[configName] = { - ...projectConfig.targets[targetName].configurations[configName], - devServerTarget: projectWithBuild.target, - skipServe: true, - }; - } else { - projectConfig.targets[targetName].options = { - ...projectConfig.targets[targetName].options, - devServerTarget: projectWithBuild.target, - skipServe: true, - }; - } - - updateProjectConfiguration(tree, projectName, projectConfig); - return true; -} - -function cacheComponentTestTarget(tree: Tree) { - updateJson(tree, 'nx.json', (json) => ({ - ...json, - tasksRunnerOptions: { - ...json.tasksRunnerOptions, - default: { - ...json.tasksRunnerOptions?.default, - options: { - ...json.tasksRunnerOptions?.default?.options, - cacheableOperations: Array.from( - new Set([ - ...(json.tasksRunnerOptions?.default?.options - ?.cacheableOperations ?? []), - 'component-test', - ]) - ), - }, - }, - }, - })); -} - -export default updateCypressConfigsPresets; diff --git a/packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.spec.ts b/packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.spec.ts deleted file mode 100644 index ce1de150fe027..0000000000000 --- a/packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.spec.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { updateCypressVersionIf10 } from './update-cypress-version-if-10'; -import { installedCypressVersion } from '../../utils/cypress-version'; -import { readJson, Tree, updateJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -describe('Update Cypress if v10 migration', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - 'package.json', - JSON.stringify({ - dependencies: {}, - devDependencies: {}, - }) - ); - }); - - it('should update the version if the installed version is v10', () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies['cypress'] = '^10.5.0'; - return json; - }); - updateCypressVersionIf10(tree); - const pkgJson = readJson(tree, 'package.json'); - expect(pkgJson.devDependencies['cypress']).toBe('^10.7.0'); - }); - - it('should not update the version < v10', () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies['cypress'] = '9.0.0'; - return json; - }); - updateCypressVersionIf10(tree); - const pkgJson = readJson(tree, 'package.json'); - expect(pkgJson.devDependencies['cypress']).toBe('9.0.0'); - }); - - it('should not update if the version > v10', () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies['cypress'] = '11.0.0'; - return json; - }); - updateCypressVersionIf10(tree); - const pkgJson = readJson(tree, 'package.json'); - expect(pkgJson.devDependencies['cypress']).toBe('11.0.0'); - }); - - it('should not update if the version is not defined', () => { - updateCypressVersionIf10(tree); - const pkgJson = readJson(tree, 'package.json'); - expect(pkgJson.devDependencies['cypress']).toBe(undefined); - }); - - it('should not update if v10.7.0 < version < v11', () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies['cypress'] = '^10.8.0'; - return json; - }); - updateCypressVersionIf10(tree); - const pkgJson1 = readJson(tree, 'package.json'); - expect(pkgJson1.devDependencies['cypress']).toBe('^10.8.0'); - }); - - it('should be idempotent', () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies['cypress'] = '^10.3.0'; - return json; - }); - updateCypressVersionIf10(tree); - const pkgJson1 = readJson(tree, 'package.json'); - expect(pkgJson1.devDependencies['cypress']).toBe('^10.7.0'); - updateCypressVersionIf10(tree); - const pkgJson2 = readJson(tree, 'package.json'); - expect(pkgJson2.devDependencies['cypress']).toBe('^10.7.0'); - }); -}); diff --git a/packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.ts b/packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.ts deleted file mode 100644 index 65187dcd96de4..0000000000000 --- a/packages/cypress/src/migrations/update-14-7-0/update-cypress-version-if-10.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - GeneratorCallback, - installPackagesTask, - readJson, - Tree, - updateJson, -} from '@nx/devkit'; -// don't import from root level to prevent issue where angular isn't installed. -import { checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver'; -import { gte, lt } from 'semver'; - -export function updateCypressVersionIf10(tree: Tree): GeneratorCallback { - const installedVersion = readJson(tree, 'package.json').devDependencies?.[ - 'cypress' - ]; - - if (!installedVersion) { - return; - } - const normalizedInstalledCypressVersion = checkAndCleanWithSemver( - 'cypress', - installedVersion - ); - - // not using v10 - if ( - lt(normalizedInstalledCypressVersion, '10.0.0') || - gte(normalizedInstalledCypressVersion, '11.0.0') - ) { - return; - } - - const ngComponentTestingVersion = '10.7.0'; - - if (lt(normalizedInstalledCypressVersion, ngComponentTestingVersion)) { - updateJson(tree, 'package.json', (json) => { - json.devDependencies['cypress'] = `^${ngComponentTestingVersion}`; - return json; - }); - return () => { - installPackagesTask(tree); - }; - } -} - -export default updateCypressVersionIf10; diff --git a/packages/detox/migrations.json b/packages/detox/migrations.json index 4e7f542ea29ab..39313f3bb1426 100644 --- a/packages/detox/migrations.json +++ b/packages/detox/migrations.json @@ -1,23 +1,5 @@ { "generators": { - "add-build-target-test-13-5-0": { - "version": "13.5.0-beta.0", - "cli": "nx", - "description": "add buildTarget to test-ios and test-android for detox app", - "factory": "./src/migrations/update-13-5-0/add-build-target-test-13-5-0" - }, - "remove-types-detox-13-8-2": { - "version": "13.8.2-beta.0", - "cli": "nx", - "description": "remove deprecated @types/detox from package.json", - "factory": "./src/migrations/update-13-8-2/remove-types-detox-13-8-2" - }, - "add-verbose-jest-config-13-10-3": { - "version": "13.10.3-beta.0", - "cli": "nx", - "description": "Update jest.config.json under detox project, add key verbsoe: true", - "factory": "./src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3" - }, "update-16-0-0-add-nx-packages": { "cli": "nx", "version": "16.0.0-beta.1", @@ -38,152 +20,6 @@ } }, "packageJsonUpdates": { - "12.8.0": { - "version": "12.8.0-beta.0", - "packages": { - "detox": { - "version": "18.20.2", - "alwaysAddToPackageJson": false - } - } - }, - "12.10.0-beta.1": { - "version": "12.10.0-beta.1", - "packages": { - "detox": { - "version": "18.22.1", - "alwaysAddToPackageJson": false - } - } - }, - "13.0.0": { - "version": "13.0.0-beta.1", - "packages": { - "detox": { - "version": "18.22.2", - "alwaysAddToPackageJson": false - } - } - }, - "13.2.0": { - "version": "13.2.0-beta.0", - "packages": { - "detox": { - "version": "19.0.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-dom": { - "version": "5.15.0", - "alwaysAddToPackageJson": false - } - } - }, - "13.5.0": { - "version": "13.5.0-beta.0", - "packages": { - "detox": { - "version": "19.4.1", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-dom": { - "version": "5.16.1", - "alwaysAddToPackageJson": false - } - } - }, - "13.8.2": { - "version": "13.8.2-beta.0", - "packages": { - "detox": { - "version": "19.4.5", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-dom": { - "version": "5.16.1", - "alwaysAddToPackageJson": false - } - } - }, - "13.8.6": { - "version": "13.8.6-beta.0", - "packages": { - "detox": { - "version": "19.5.1", - "alwaysAddToPackageJson": false - } - } - }, - "13.9.3": { - "version": "13.9.3-beta.0", - "packages": { - "detox": { - "version": "19.5.7", - "alwaysAddToPackageJson": false - } - } - }, - "13.10.3": { - "version": "13.10.3-beta.0", - "packages": { - "detox": { - "version": "19.6.5", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-dom": { - "version": "5.16.4", - "alwaysAddToPackageJson": false - } - } - }, - "14.1.8": { - "version": "14.1.8-beta.0", - "packages": { - "detox": { - "version": "19.6.9", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.1": { - "version": "14.2.1-beta.0", - "packages": { - "detox": { - "version": "19.7.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.7": { - "version": "14.5.7-beta.0", - "packages": { - "detox": { - "version": "19.9.3", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-dom": { - "version": "5.16.5", - "alwaysAddToPackageJson": false - } - } - }, - "14.6.1": { - "version": "14.6.1-beta.0", - "packages": { - "detox": { - "version": "19.10.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.7.4": { - "version": "14.7.4-beta.0", - "packages": { - "detox": { - "version": "19.12.1", - "alwaysAddToPackageJson": false - } - } - }, "15.0.0": { "version": "15.0.0-beta.0", "packages": { diff --git a/packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.spec.ts b/packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.spec.ts deleted file mode 100644 index 1fbefe0111df8..0000000000000 --- a/packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './add-verbose-jest-config-13-10-3'; - -describe('Set verbose to true for jest.config.json for detox apps', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - 'test-ios': { - executor: '@nrwl/detox:test', - }, - }, - }); - }); - - it(`should add verbose true to jest.config.json`, async () => { - tree.write('apps/products/jest.config.json', '{}'); - await update(tree); - - const jestConfig = readJson(tree, 'apps/products/jest.config.json'); - expect(jestConfig.verbose).toEqual(true); - }); - - it(`should change verbose to true in jest.config.json`, async () => { - tree.write('apps/products/jest.config.json', '{"verbose": false}'); - await update(tree); - - const jestConfig = readJson(tree, 'apps/products/jest.config.json'); - expect(jestConfig.verbose).toEqual(true); - }); -}); diff --git a/packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.ts b/packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.ts deleted file mode 100644 index 4082d53f49c1d..0000000000000 --- a/packages/detox/src/migrations/update-13-10-3/add-verbose-jest-config-13-10-3.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { - Tree, - formatFiles, - getProjects, - updateJson, - ProjectConfiguration, -} from '@nx/devkit'; - -/** - * Update jest.config.json under detox project, add key verbsoe: true - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((project) => { - if (project.targets?.['test-ios']?.executor !== '@nrwl/detox:test') return; - updateJestConfig(tree, project); - }); - - await formatFiles(tree); -} - -function updateJestConfig(host: Tree, project: ProjectConfiguration) { - const jestConfigPath = `${project.root}/jest.config.json`; - if (!host.exists(jestConfigPath)) return; - updateJson(host, jestConfigPath, (json) => { - if (!json.verbose) { - json.verbose = true; - } - return json; - }); -} diff --git a/packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.spec.ts b/packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.spec.ts deleted file mode 100644 index 634dde0e3a295..0000000000000 --- a/packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.spec.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { addProjectConfiguration, getProjects, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './add-build-target-test-13-5-0'; - -describe('add-e2e-targets-13-5-0', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products-e2e', { - root: 'apps/products-e2e', - sourceRoot: 'apps/products-e2e/src', - targets: { - 'test-ios': { - executor: '@nrwl/detox:test', - options: { - detoxConfiguration: 'ios.sim.debug', - }, - configurations: { - production: { - detoxConfiguration: 'ios.sim.release', - }, - }, - }, - 'test-android': { - executor: '@nrwl/detox:test', - options: { - detoxConfiguration: 'android.emu.debug', - }, - configurations: { - production: { - detoxConfiguration: 'android.emu.release', - }, - }, - }, - }, - }); - }); - - it(`should update project.json with targets e2e`, async () => { - await update(tree); - - getProjects(tree).forEach((project) => { - expect(project.targets['test-ios']).toEqual({ - executor: '@nrwl/detox:test', - options: { - detoxConfiguration: 'ios.sim.debug', - buildTarget: 'products-e2e:build-ios', - }, - configurations: { - production: { - detoxConfiguration: 'ios.sim.release', - buildTarget: 'products-e2e:build-ios:prod', - }, - }, - }); - - expect(project.targets['test-android']).toEqual({ - executor: '@nrwl/detox:test', - options: { - detoxConfiguration: 'android.emu.debug', - buildTarget: 'products-e2e:build-android', - }, - configurations: { - production: { - detoxConfiguration: 'android.emu.release', - buildTarget: 'products-e2e:build-android:prod', - }, - }, - }); - }); - }); -}); diff --git a/packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.ts b/packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.ts deleted file mode 100644 index abd0e6585f233..0000000000000 --- a/packages/detox/src/migrations/update-13-5-0/add-build-target-test-13-5-0.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - Tree, - formatFiles, - getProjects, - updateProjectConfiguration, -} from '@nx/devkit'; - -/** - * This function buildTarget to test-ios and test-android - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - for (const [name, config] of projects.entries()) { - if (config.targets?.['test-ios']?.executor === '@nrwl/detox:test') { - config.targets['test-ios'].options.buildTarget = `${name}:build-ios`; - config.targets[ - 'test-ios' - ].configurations.production.buildTarget = `${name}:build-ios:prod`; - } - - if (config.targets?.['test-android']?.executor === '@nrwl/detox:test') { - config.targets[ - 'test-android' - ].options.buildTarget = `${name}:build-android`; - config.targets[ - 'test-android' - ].configurations.production.buildTarget = `${name}:build-android:prod`; - } - - updateProjectConfiguration(tree, name, config); - } - - await formatFiles(tree); -} diff --git a/packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.spec.ts b/packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.spec.ts deleted file mode 100644 index ac5f44da0f57b..0000000000000 --- a/packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - addProjectConfiguration, - readJson, - Tree, - updateJson, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './remove-types-detox-13-8-2'; - -describe('remove-types-detox-13-8-2', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (packageJson) => { - packageJson.devDependencies['@types/detox'] = '*'; - return packageJson; - }); - addProjectConfiguration(tree, 'products-e2e', { - root: 'apps/products-e2e', - sourceRoot: 'apps/products-e2e/src', - targets: { - 'test-ios': { - executor: '@nrwl/detox:test', - }, - }, - }); - }); - - it(`should remove @types/detox from package.json`, async () => { - await update(tree); - const packageJson = readJson(tree, 'package.json'); - expect(packageJson.devDependencies['@types/detox']).toBeUndefined(); - }); -}); diff --git a/packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.ts b/packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.ts deleted file mode 100644 index 55058106ce5a7..0000000000000 --- a/packages/detox/src/migrations/update-13-8-2/remove-types-detox-13-8-2.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { getProjects, readJson, Tree, updateJson } from '@nx/devkit'; - -export default async function update(tree: Tree) { - const packageJson = readJson(tree, 'package.json'); - - if (!packageJson.devDependencies['@types/detox']) { - return; - } - - const projects = getProjects(tree); - const hasDetoxProject = Array.from(projects) - .map(([_, project]) => project) - .some( - (project) => - project.targets?.['test-ios']?.executor === '@nrwl/detox:test' - ); - - if (!hasDetoxProject) { - return; - } - - updateJson(tree, 'package.json', (packageJson) => { - delete packageJson.devDependencies['@types/detox']; - return packageJson; - }); -} diff --git a/packages/expo/migrations.json b/packages/expo/migrations.json index 87d707e99da32..caecda8dc8320 100644 --- a/packages/expo/migrations.json +++ b/packages/expo/migrations.json @@ -1,29 +1,5 @@ { "generators": { - "add-project-root-metro-config-14-0-0": { - "version": "14.0.1-beta.0", - "cli": "nx", - "description": "Add projectRoot option in metro.config.js", - "factory": "./src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0" - }, - "add-eject-target-14-1-2": { - "version": "14.1.2-beta.0", - "cli": "nx", - "description": "Add target eject for expo projects in project.json", - "factory": "./src/migrations/update-14-1-2/add-eject-target-14-1-2" - }, - "add-build-target-14-4-3": { - "version": "14.4.3-beta.0", - "cli": "nx", - "description": "Add target build and build-list for expo projects in project.json", - "factory": "./src/migrations/update-14-4-3/add-eas-build-target" - }, - "add-update-target-14-5-1": { - "version": "14.5.1-beta.0", - "cli": "nx", - "description": "Add target update for expo projects in project.json", - "factory": "./src/migrations/update-14-5-1/add-eas-update-target" - }, "change-expo-jest-preset": { "version": "15.0.3-beta.0", "cli": "nx", @@ -92,391 +68,6 @@ } }, "packageJsonUpdates": { - "13.8.6": { - "version": "13.8.6-beta.0", - "packages": { - "expo-cli": { - "version": "5.3.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.0": { - "version": "14.0.0-beta.0", - "packages": { - "expo-cli": { - "version": "5.4.0", - "alwaysAddToPackageJson": false - }, - "babel-preset-expo": { - "version": "~9.0.2", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - } - } - }, - "14.0.1": { - "version": "14.0.1-beta.0", - "packages": { - "expo-cli": { - "version": "5.4.3", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.2": { - "version": "14.0.2-beta.0", - "packages": { - "metro-resolver": { - "version": "0.70.2", - "alwaysAddToPackageJson": false - }, - "expo-dev-client": { - "version": "0.8.5", - "alwaysAddToPackageJson": false - }, - "@expo/metro-config": { - "version": "0.3.16", - "alwaysAddToPackageJson": false - }, - "expo-updates": { - "version": "~0.11.7", - "alwaysAddToPackageJson": false - } - } - }, - "14.1.1": { - "version": "14.1.1-beta.0", - "packages": { - "expo": { - "version": "45.0.4", - "alwaysAddToPackageJson": false - }, - "expo-dev-client": { - "version": "~0.9.6", - "alwaysAddToPackageJson": false - }, - "expo-status-bar": { - "version": "~1.3.0", - "alwaysAddToPackageJson": false - }, - "@expo/metro-config": { - "version": "0.3.17", - "alwaysAddToPackageJson": false - }, - "expo-splash-screen": { - "version": "0.15.1", - "alwaysAddToPackageJson": false - }, - "expo-updates": { - "version": "~0.13.1", - "alwaysAddToPackageJson": false - }, - "jest-expo": { - "version": "45.0.1", - "alwaysAddToPackageJson": false - }, - "expo-cli": { - "version": "5.4.6", - "alwaysAddToPackageJson": false - }, - "babel-preset-expo": { - "version": "~9.1.0", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.68.2", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.67.7", - "alwaysAddToPackageJson": false - }, - "react-native-web": { - "version": "0.17.7", - "alwaysAddToPackageJson": false - }, - "react-native-gesture-handler": { - "version": "~2.2.1", - "alwaysAddToPackageJson": false - }, - "react-native-reanimated": { - "version": "~2.8.0", - "alwaysAddToPackageJson": false - }, - "react-native-safe-area-context": { - "version": "4.2.4", - "alwaysAddToPackageJson": false - }, - "react-native-screens": { - "version": "~3.11.1", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "12.3.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.70.3", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "9.1.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.5", - "alwaysAddToPackageJson": false - } - } - }, - "14.1.2": { - "version": "14.1.2-beta.0", - "packages": { - "expo": { - "version": "45.0.5", - "alwaysAddToPackageJson": false - }, - "expo-cli": { - "version": "5.4.9", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.71.0", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.71.0", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - }, - "react-test-renderer": { - "version": "18.1.0", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - }, - "expo-updates": { - "version": "~0.13.2", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.67.8", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.3": { - "version": "14.2.3-beta.0", - "packages": { - "expo-dev-client": { - "version": "~0.10.0", - "alwaysAddToPackageJson": false - }, - "expo-structured-headers": { - "version": "~2.2.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.4": { - "version": "14.2.4-beta.0", - "packages": { - "expo-dev-client": { - "version": "~1.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.3.2": { - "version": "14.3.2-beta.0", - "packages": { - "expo": { - "version": "45.0.6", - "alwaysAddToPackageJson": false - }, - "expo-cli": { - "version": "5.4.11", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.68.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.4.3": { - "version": "14.4.3-beta.0", - "packages": { - "eas-cli": { - "version": "0.55.1", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - }, - "expo-cli": { - "version": "5.5.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.1": { - "version": "14.5.1-beta.0", - "packages": { - "expo": { - "version": "46.0.2", - "alwaysAddToPackageJson": false - }, - "expo-dev-client": { - "version": "~1.1.1", - "alwaysAddToPackageJson": false - }, - "expo-status-bar": { - "version": "~1.4.0", - "alwaysAddToPackageJson": false - }, - "@expo/metro-config": { - "version": "0.3.21", - "alwaysAddToPackageJson": false - }, - "expo-splash-screen": { - "version": "~0.16.1", - "alwaysAddToPackageJson": false - }, - "expo-updates": { - "version": "~0.14.3", - "alwaysAddToPackageJson": false - }, - "jest-expo": { - "version": "46.0.1", - "alwaysAddToPackageJson": false - }, - "expo-cli": { - "version": "6.0.1", - "alwaysAddToPackageJson": false - }, - "eas-cli": { - "version": "0.57.0", - "alwaysAddToPackageJson": false - }, - "babel-preset-expo": { - "version": "~9.2.0", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.69.3", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.69.5", - "alwaysAddToPackageJson": false - }, - "react-native-web": { - "version": "~0.18.7", - "alwaysAddToPackageJson": false - }, - "react-native-gesture-handler": { - "version": "~2.5.0", - "alwaysAddToPackageJson": false - }, - "react-native-reanimated": { - "version": "~2.9.1", - "alwaysAddToPackageJson": false - }, - "react-native-safe-area-context": { - "version": "4.3.1", - "alwaysAddToPackageJson": false - }, - "react-native-screens": { - "version": "~3.15.0", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "12.4.3", - "alwaysAddToPackageJson": false - }, - "@svgr/webpack": { - "version": "^6.3.1", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.72.0", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.72.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "11.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.2": { - "version": "14.5.2-beta.0", - "packages": { - "expo": { - "version": "46.0.9", - "alwaysAddToPackageJson": false - }, - "expo-cli": { - "version": "6.0.5", - "alwaysAddToPackageJson": false - }, - "eas-cli": { - "version": "1.1.1", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.69.4", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "13.0.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.72.1", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.11", - "alwaysAddToPackageJson": false - }, - "@expo/metro-config": { - "version": "0.3.22", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.3": { - "version": "14.5.3-beta.0", - "packages": { - "expo": { - "version": "46.0.10", - "alwaysAddToPackageJson": false - }, - "eas-cli": { - "version": "2.1.0", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.69.5", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.69.8", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "13.1.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.72.2", - "alwaysAddToPackageJson": false - } - } - }, "15.0.0": { "version": "15.0.0-beta.0", "packages": { diff --git a/packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts b/packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts deleted file mode 100644 index c5b0ec89409dc..0000000000000 --- a/packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './add-project-root-metro-config-14-0-0'; - -describe('Add projectRoot option in metro.config.js', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - }, - }); - }); - - it(`should udpate metro.config.js and add key projectRoot`, async () => { - tree.write( - 'apps/products/metro.config.js', - ` -const { withNxMetro } = require('@nx/react-native'); -const { getDefaultConfig } = require('metro-config'); - -module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); -})(); -` - ); - await update(tree); - - expect(tree.read('apps/products/metro.config.js', 'utf-8')) - .toMatchInlineSnapshot(` - "const { withNxMetro } = require('@nx/react-native'); - const { getDefaultConfig } = require('metro-config'); - - module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - projectRoot: __dirname, - watchFolders: [], - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); - })(); - " - `); - }); - - it(`should not udpate metro.config.js if projectRoot already exists`, async () => { - tree.write( - 'apps/products/metro.config.js', - ` -const { withNxMetro } = require('@nx/react-native'); -const { getDefaultConfig } = require('metro-config'); - -module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - projectRoot: __dirname, - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); -})(); -` - ); - await update(tree); - - expect(tree.read('apps/products/metro.config.js', 'utf-8')) - .toMatchInlineSnapshot(` - "const { withNxMetro } = require('@nx/react-native'); - const { getDefaultConfig } = require('metro-config'); - - module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - projectRoot: __dirname, - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); - })(); - " - `); - }); -}); diff --git a/packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts b/packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts deleted file mode 100644 index a561a30d7f5dd..0000000000000 --- a/packages/expo/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - stripIndents, - Tree, -} from '@nx/devkit'; - -/** - * Add projectRoot and watchFolders options in metro.config.js - * @param tree - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((project) => { - const metroConfigPath = `${project.root}/metro.config.js`; - if ( - project.targets?.start?.executor !== '@nrwl/react-native:start' || - !tree.exists(metroConfigPath) - ) - return; - try { - const metroConfigContent = tree.read(metroConfigPath, 'utf-8'); - if (metroConfigContent.includes('projectRoot: __dirname')) { - return; - } - if (metroConfigContent.includes('projectRoot')) return; - tree.write( - metroConfigPath, - metroConfigContent.replace( - 'debug: ', - 'projectRoot: __dirname, watchFolders: [], debug: ' - ) - ); - } catch { - logger.error( - stripIndents`Unable to update ${metroConfigPath} for project ${project.root}.` - ); - } - }); - await formatFiles(tree); -} diff --git a/packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.spec.ts b/packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.spec.ts deleted file mode 100644 index 173fc5b720860..0000000000000 --- a/packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { addProjectConfiguration, getProjects, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './add-eject-target-14-1-2'; - -describe('add-eject-target-14-1-2', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'product', { - root: 'apps/product', - sourceRoot: 'apps/product/src', - targets: { - start: { - executor: '@nrwl/expo:start', - }, - }, - }); - }); - - it(`should update project.json with target eject`, async () => { - await update(tree); - - getProjects(tree).forEach((project) => { - expect(project.targets['eject']).toEqual({ - executor: '@nrwl/expo:eject', - options: {}, - }); - }); - }); -}); diff --git a/packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.ts b/packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.ts deleted file mode 100644 index 9cc53a9213903..0000000000000 --- a/packages/expo/src/migrations/update-14-1-2/add-eject-target-14-1-2.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { - Tree, - formatFiles, - getProjects, - updateProjectConfiguration, -} from '@nx/devkit'; - -/** - * Add eject to targets for expo app - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - for (const [name, config] of projects.entries()) { - if (config.targets?.['start']?.executor === '@nrwl/expo:start') { - config.targets['eject'] = { - executor: '@nrwl/expo:eject', - options: {}, - }; - } - - updateProjectConfiguration(tree, name, config); - } - - await formatFiles(tree); -} diff --git a/packages/expo/src/migrations/update-14-4-3/add-eas-build-target.spec.ts b/packages/expo/src/migrations/update-14-4-3/add-eas-build-target.spec.ts deleted file mode 100644 index 997e8a3142d2e..0000000000000 --- a/packages/expo/src/migrations/update-14-4-3/add-eas-build-target.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { addProjectConfiguration, getProjects, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './add-eas-build-target'; - -describe('add-eas-build-target', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'product', { - root: 'apps/product', - sourceRoot: 'apps/product/src', - targets: { - start: { - executor: '@nrwl/expo:start', - }, - }, - }); - }); - - it(`should update project.json with target build and build-list`, async () => { - await update(tree); - - getProjects(tree).forEach((project) => { - expect(project.targets['build']).toEqual({ - executor: '@nrwl/expo:build', - options: {}, - }); - expect(project.targets['build-list']).toEqual({ - executor: '@nrwl/expo:build-list', - options: {}, - }); - expect(project.targets['download']).toEqual({ - executor: '@nrwl/expo:download', - options: { - output: 'apps/product/dist', - }, - }); - }); - }); -}); diff --git a/packages/expo/src/migrations/update-14-4-3/add-eas-build-target.ts b/packages/expo/src/migrations/update-14-4-3/add-eas-build-target.ts deleted file mode 100644 index 3acd185b5be19..0000000000000 --- a/packages/expo/src/migrations/update-14-4-3/add-eas-build-target.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { - Tree, - formatFiles, - getProjects, - updateProjectConfiguration, -} from '@nx/devkit'; -import { join } from 'path'; - -/** - * Add eas build and build-list target for expo - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - for (const [name, config] of projects.entries()) { - if (config.targets?.['start']?.executor === '@nrwl/expo:start') { - if (!config.targets['build']) { - config.targets['build'] = { - executor: '@nrwl/expo:build', - options: {}, - }; - } - if (!config.targets['build-list']) { - config.targets['build-list'] = { - executor: '@nrwl/expo:build-list', - options: {}, - }; - } - if (!config.targets['download']) { - config.targets['download'] = { - executor: '@nrwl/expo:download', - options: { - output: join(config.root, 'dist'), - }, - }; - } - } - - updateProjectConfiguration(tree, name, config); - } - - await formatFiles(tree); -} diff --git a/packages/expo/src/migrations/update-14-5-1/add-eas-update-target.spec.ts b/packages/expo/src/migrations/update-14-5-1/add-eas-update-target.spec.ts deleted file mode 100644 index 5c53ca04a8e50..0000000000000 --- a/packages/expo/src/migrations/update-14-5-1/add-eas-update-target.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { addProjectConfiguration, getProjects, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './add-eas-update-target'; - -describe('add-eas-update-target', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'product', { - root: 'apps/product', - sourceRoot: 'apps/product/src', - targets: { - start: { - executor: '@nrwl/expo:start', - }, - }, - }); - }); - - it(`should update project.json with target update`, async () => { - await update(tree); - - getProjects(tree).forEach((project) => { - expect(project.targets['update']).toEqual({ - executor: '@nrwl/expo:update', - options: {}, - }); - }); - }); -}); diff --git a/packages/expo/src/migrations/update-14-5-1/add-eas-update-target.ts b/packages/expo/src/migrations/update-14-5-1/add-eas-update-target.ts deleted file mode 100644 index 9339ecde50beb..0000000000000 --- a/packages/expo/src/migrations/update-14-5-1/add-eas-update-target.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - Tree, - formatFiles, - getProjects, - updateProjectConfiguration, -} from '@nx/devkit'; - -/** - * Add eas update target for expo - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - for (const [name, config] of projects.entries()) { - if (config.targets?.['start']?.executor === '@nrwl/expo:start') { - if (!config.targets['update']) { - config.targets['update'] = { - executor: '@nrwl/expo:update', - options: {}, - }; - } - updateProjectConfiguration(tree, name, config); - } - } - - await formatFiles(tree); -} diff --git a/packages/express/migrations.json b/packages/express/migrations.json index c302e2d554fbc..1f28dfafc3cf7 100644 --- a/packages/express/migrations.json +++ b/packages/express/migrations.json @@ -7,28 +7,5 @@ "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages" } }, - "packageJsonUpdates": { - "13.7.0": { - "version": "13.7.0", - "packages": { - "express": { - "version": "4.17.2", - "alwaysAddToPackageJson": false - }, - "@types/express": { - "version": "4.17.13", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.0": { - "version": "14.5.0-beta.4", - "packages": { - "express": { - "version": "^4.18.1", - "alwaysAddToPackageJson": false - } - } - } - } + "packageJsonUpdates": {} } diff --git a/packages/jest/migrations.json b/packages/jest/migrations.json index 7189072a8ad46..d3420bb69af0f 100644 --- a/packages/jest/migrations.json +++ b/packages/jest/migrations.json @@ -1,77 +1,5 @@ { "generators": { - "update-jest-preset-angular-8-4-0": { - "version": "12.1.0-beta.1", - "cli": "nx", - "description": "Update jest-preset-angular to version 8.4.0", - "factory": "./src/migrations/update-12-1-2/update-jest-preset-angular" - }, - "update-ts-jest-6-5-5": { - "version": "12.1.2-beta.1", - "cli": "nx", - "description": "Replace tsConfig with tsconfig for ts-jest in jest.config.js", - "factory": "./src/migrations/update-12-1-2/update-ts-jest" - }, - "support-jest-27": { - "version": "12.4.0-beta.1", - "cli": "nx", - "description": "Add testEnvironment: 'jsdom' in web apps + libraries", - "factory": "./src/migrations/update-12-4-0/add-test-environment-for-node" - }, - "update-ts-jest-and-jest-preset-angular": { - "version": "12.4.0-beta.1", - "cli": "nx", - "description": "Support for Jest 27 via updating ts-jest + jest-preset-angular", - "factory": "./src/migrations/update-12-4-0/update-jest-preset-angular" - }, - "update-jest-config-to-use-util": { - "version": "12.6.0-beta.0", - "cli": "nx", - "description": "Uses `getJestProjects()` to populate projects array in root level `jest.config.js` file.", - "factory": "./src/migrations/update-12-6-0/update-base-jest-config" - }, - "update-ts-config-for-test-filenames": { - "version": "13.1.2-beta.0", - "cli": "nx", - "description": "Support .test. file names in tsconfigs", - "factory": "./src/migrations/update-13-1-2/update-tsconfigs-for-tests" - }, - "add-missing-root-babel-config": { - "version": "13.4.4-beta.0", - "cli": "nx", - "description": "Create a root babel config file if it doesn't exist and using babel-jest in jest.config.js and add @nrwl/web as needed", - "factory": "./src/migrations/update-13-4-4/add-missing-root-babel-config" - }, - "update-jest-config-extensions": { - "version": "14.0.0-beta.2", - "cli": "nx", - "description": "Update move jest config files to .ts files.", - "factory": "./src/migrations/update-14-0-0/update-jest-config-ext" - }, - "update-to-export-default": { - "version": "14.1.5-beta.0", - "cli": "nx", - "description": "Update to export default in jest config and revert jest.preset.ts to jest.preset.js", - "factory": "./src/migrations/update-14-1-5/update-exports-jest-config" - }, - "exclude-jest-config-from-ts-config": { - "version": "14.5.5-beta.0", - "cli": "nx", - "description": "Exclude jest.config.ts from tsconfig where missing.", - "factory": "./src/migrations/update-14-0-0/update-jest-config-ext" - }, - "update-configs-jest-28": { - "version": "14.6.0-beta.0", - "cli": "nx", - "description": "Update jest configs to support jest 28 changes (https://jestjs.io/docs/upgrading-to-jest28#configuration-options)", - "factory": "./src/migrations/update-14-6-0/update-configs-jest-28" - }, - "update-tests-jest-28": { - "version": "14.6.0-beta.0", - "cli": "nx", - "description": "Update jest test files to support jest 28 changes (https://jestjs.io/docs/upgrading-to-jest28)", - "factory": "./src/migrations/update-14-6-0/update-tests-jest-28" - }, "add-jest-inputs": { "version": "15.0.0-beta.0", "cli": "nx", @@ -104,133 +32,6 @@ } }, "packageJsonUpdates": { - "12.1.0": { - "version": "12.1.0-beta.1", - "packages": { - "jest-preset-angular": { - "version": "8.4.0", - "alwaysAddToPackageJson": false - }, - "ts-jest": { - "version": "26.5.5", - "alwaysAddToPackageJson": false - } - } - }, - "12.4.0": { - "version": "12.4.0-beta.1", - "packages": { - "jest": { - "version": "27.0.3", - "alwaysAddToPackageJson": false - }, - "ts-jest": { - "version": "27.0.3", - "alwaysAddToPackageJson": false - }, - "jest-preset-angular": { - "version": "9.0.3", - "alwaysAddToPackageJson": false - } - } - }, - "12.10.0": { - "version": "12.10.0-beta.1", - "packages": { - "jest": { - "version": "27.2.3", - "alwaysAddToPackageJson": false - }, - "@types/jest": { - "version": "27.0.2", - "alwaysAddToPackageJson": false - }, - "ts-jest": { - "version": "27.0.5", - "alwaysAddToPackageJson": false - }, - "babel-jest": { - "version": "27.2.3", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.0": { - "version": "14.0.0-beta.2", - "packages": { - "jest": { - "version": "27.5.1", - "alwaysAddToPackageJson": false - }, - "@types/jest": { - "version": "27.4.1", - "alwaysAddToPackageJson": false - }, - "ts-jest": { - "version": "27.1.4", - "alwaysAddToPackageJson": false - }, - "babel-jest": { - "version": "27.5.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.0": { - "version": "14.2.0-rc.2", - "packages": { - "ts-node": { - "version": "~10.8.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.5": { - "version": "14.5.5-beta.0", - "packages": { - "ts-node": { - "version": "10.9.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.6.0": { - "version": "14.6.0-beta.0", - "packages": { - "jest": { - "version": "~28.1.1", - "alwaysAddToPackageJson": false - }, - "@types/jest": { - "version": "~28.1.1", - "alwaysAddToPackageJson": false - }, - "expect": { - "version": "~28.1.1", - "alwaysAddToPackageJson": false - }, - "@jest/globals": { - "version": "~28.1.1", - "alwaysAddToPackageJson": false - }, - "jest-jasmine2": { - "version": "~28.1.1", - "alwaysAddToPackageJson": false - }, - "jest-environment-jsdom": { - "version": "~28.1.1", - "alwaysAddToPackageJson": false - }, - "ts-jest": { - "version": "~28.0.5", - "alwaysAddToPackageJson": false - }, - "babel-jest": { - "version": "~28.1.1", - "alwaysAddToPackageJson": false - } - } - }, "15.0.1-beta.3": { "version": "15.0.1-beta.3", "packages": { diff --git a/packages/jest/src/migrations/update-12-1-2/update-jest-preset-angular.ts b/packages/jest/src/migrations/update-12-1-2/update-jest-preset-angular.ts deleted file mode 100644 index f190f16056b82..0000000000000 --- a/packages/jest/src/migrations/update-12-1-2/update-jest-preset-angular.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { - formatFiles, - logger, - readProjectConfiguration, - stripIndents, - Tree, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { join } from 'path'; -import { - addPropertyToJestConfig, - removePropertyFromJestConfig, -} from '../../utils/config/update-config'; -import { JestExecutorOptions } from '../../executors/jest/schema'; - -function updateJestConfig(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, projectName) => { - const config = require(join(tree.root, options.jestConfig as string)); - - // migrate serializers - if ( - config.snapshotSerializers && - Array.isArray(config.snapshotSerializers) - ) { - const snapshotSerializers = config.snapshotSerializers.map( - (snapshotSerializer) => { - switch (snapshotSerializer) { - case 'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js': - return 'jest-preset-angular/build/serializers/no-ng-attributes'; - case 'jest-preset-angular/build/AngularSnapshotSerializer.js': - return 'jest-preset-angular/build/serializers/ng-snapshot'; - case 'jest-preset-angular/build/HTMLCommentSerializer.js': - return 'jest-preset-angular/build/serializers/html-comment'; - default: - return snapshotSerializer; - } - } - ); - - try { - removePropertyFromJestConfig( - tree, - options.jestConfig as string, - 'snapshotSerializers' - ); - addPropertyToJestConfig( - tree, - options.jestConfig as string, - 'snapshotSerializers', - snapshotSerializers - ); - } catch { - logger.error( - stripIndents`Unable to update snapshotSerializers for project ${projectName}. - More information you can check online documentation https://github.com/thymikee/jest-preset-angular/blob/master/CHANGELOG.md#840-2021-03-04` - ); - } - } - - try { - const { sourceRoot } = readProjectConfiguration(tree, projectName); - const setupTestPath = join(sourceRoot, 'test-setup.ts'); - if (tree.exists(setupTestPath)) { - const contents = tree.read(setupTestPath, 'utf-8'); - tree.write( - setupTestPath, - contents.replace( - `import 'jest-preset-angular';`, - `import 'jest-preset-angular/setup-jest';` - ) - ); - } - } catch { - logger.error( - stripIndents`Unable to update test-setup.ts for project ${projectName}.` - ); - } - } - ); -} - -export default async function update(tree) { - updateJestConfig(tree); - await formatFiles(tree); -} diff --git a/packages/jest/src/migrations/update-12-1-2/update-ts-jest.ts b/packages/jest/src/migrations/update-12-1-2/update-ts-jest.ts deleted file mode 100644 index 6bb914c9af08d..0000000000000 --- a/packages/jest/src/migrations/update-12-1-2/update-ts-jest.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { formatFiles, logger, stripIndents, Tree } from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { join } from 'path'; -import { JestExecutorOptions } from '../../executors/jest/schema'; -import { - addPropertyToJestConfig, - removePropertyFromJestConfig, -} from '../../utils/config/update-config'; - -function updateJestConfig(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, project) => { - if (!options.jestConfig) { - return; - } - - const jestConfigPath = options.jestConfig; - const config = require(join(tree.root, jestConfigPath)); - const tsJestConfig = config.globals?.['ts-jest']; - if (!(tsJestConfig && tsJestConfig.tsConfig)) { - return; - } - - try { - removePropertyFromJestConfig( - tree, - jestConfigPath, - 'globals.ts-jest.tsConfig' - ); - addPropertyToJestConfig( - tree, - jestConfigPath, - 'globals.ts-jest.tsconfig', - tsJestConfig.tsConfig - ); - } catch { - logger.error( - stripIndents`Unable to update jest.config.js for project ${project}.` - ); - } - } - ); -} - -export default async function update(tree: Tree) { - updateJestConfig(tree); - await formatFiles(tree); -} diff --git a/packages/jest/src/migrations/update-12-4-0/add-test-environment-for-node.ts b/packages/jest/src/migrations/update-12-4-0/add-test-environment-for-node.ts deleted file mode 100644 index 68f48f6c02828..0000000000000 --- a/packages/jest/src/migrations/update-12-4-0/add-test-environment-for-node.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { - formatFiles, - logger, - ProjectConfiguration, - readProjectConfiguration, - stripIndents, - Tree, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { join } from 'path'; -import { JestExecutorOptions } from '../../executors/jest/schema'; -import { addPropertyToJestConfig } from '../../utils/config/update-config'; - -function updateJestConfig(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, project) => { - if (!options.jestConfig) { - return; - } - - const jestConfigPath = options.jestConfig; - const jestConfig = require(join(tree.root, jestConfigPath)); - const projectConfig = readProjectConfiguration(tree, project); - const testEnvironment = jestConfig.testEnvironment; - - if (testEnvironment || !checkIfNodeProject(projectConfig)) { - return; - } - - try { - addPropertyToJestConfig( - tree, - jestConfigPath, - 'testEnvironment', - 'node' - ); - } catch { - logger.error( - stripIndents`Unable to update jest.config.js for project ${project}.` - ); - } - } - ); -} - -export default async function update(tree: Tree) { - updateJestConfig(tree); - await formatFiles(tree); -} - -function checkIfNodeProject(config: ProjectConfiguration) { - return Object.entries(config.targets).some(([targetName, targetConfig]) => - targetConfig.executor?.includes?.('node') - ); -} diff --git a/packages/jest/src/migrations/update-12-4-0/update-jest-preset-angular.ts b/packages/jest/src/migrations/update-12-4-0/update-jest-preset-angular.ts deleted file mode 100644 index 2ce441390c1df..0000000000000 --- a/packages/jest/src/migrations/update-12-4-0/update-jest-preset-angular.ts +++ /dev/null @@ -1,148 +0,0 @@ -import { formatFiles, logger, stripIndents, Tree } from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { join } from 'path'; -import { JestExecutorOptions } from '../../executors/jest/schema'; -import { - addPropertyToJestConfig, - removePropertyFromJestConfig, -} from '../../utils/config/update-config'; - -function updateJestConfig(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, project) => { - if (!options.jestConfig) { - return; - } - - const jestConfigPath = options.jestConfig; - const jestConfig = require(join( - tree.root, - jestConfigPath - )) as PartialJestConfig; - - if (!usesJestPresetAngular(jestConfig)) { - return; - } - - try { - updateASTTransformers(tree, jestConfigPath, jestConfig); - updateTransform(tree, jestConfigPath, jestConfig); - } catch { - logger.error( - stripIndents`Unable to update jest.config.js for project ${project}.` - ); - } - } - ); -} - -export default async function update(tree: Tree) { - updateJestConfig(tree); - await formatFiles(tree); -} - -export function updateASTTransformers( - tree: Tree, - jestConfigPath: string, - jestConfig: PartialJestConfig -) { - const newTransformers = getNewAstTransformers( - jestConfig.globals?.['ts-jest']?.astTransformers - ); - if (newTransformers === null) { - removePropertyFromJestConfig( - tree, - jestConfigPath, - 'globals.ts-jest.astTransformers' - ); - } else { - addPropertyToJestConfig( - tree, - jestConfigPath, - 'globals.ts-jest.astTransformers', - newTransformers - ); - } -} - -export function updateTransform( - tree: Tree, - jestConfigPath: string, - jestConfig: PartialJestConfig -) { - removePropertyFromJestConfig(tree, jestConfigPath, 'transform'); - addPropertyToJestConfig(tree, jestConfigPath, 'transform', { - '^.+\\.(ts|js|html)$': 'jest-preset-angular', - }); -} - -interface PartialJestConfig { - globals: { - 'ts-jest': { - astTransformers: ASTTransformers; - }; - }; - transform?: Record; -} - -interface ASTTransformer { - path: string; - options: unknown; -} - -interface ASTTransformers { - before: (ASTTransformer | string)[]; - after: (ASTTransformer | string)[]; - afterDeclarations: (ASTTransformer | string)[]; -} - -export function getNewAstTransformers( - astTransformers: ASTTransformers -): ASTTransformers | null { - let result = { - before: astTransformers?.before?.filter?.( - (x) => !transformerIsFromJestPresetAngular(x) - ), - after: astTransformers?.after?.filter?.( - (x) => !transformerIsFromJestPresetAngular(x) - ), - afterDeclarations: astTransformers?.afterDeclarations?.filter?.( - (x) => !transformerIsFromJestPresetAngular(x) - ), - }; - - result = { - before: result.before?.length > 0 ? result.before : undefined, - after: result.after?.length > 0 ? result.after : undefined, - afterDeclarations: - result.afterDeclarations?.length > 0 - ? result.afterDeclarations - : undefined, - }; - - if (!result.before && !result.after && !result.afterDeclarations) { - return null; - } else { - return result; - } -} - -export function transformerIsFromJestPresetAngular( - transformer: ASTTransformer | string -) { - return typeof transformer === 'string' - ? transformer.includes('jest-preset-angular') - : transformer.path.includes('jest-preset-angular'); -} - -export function usesJestPresetAngular(jestConfig: PartialJestConfig) { - const transformers = Array.isArray( - jestConfig.globals?.['ts-jest']?.astTransformers - ) - ? jestConfig.globals?.['ts-jest']?.astTransformers || [] - : jestConfig.globals?.['ts-jest']?.astTransformers?.before || []; - - return transformers.some((x) => transformerIsFromJestPresetAngular(x)); -} diff --git a/packages/jest/src/migrations/update-12-6-0/update-base-jest-config.spec.ts b/packages/jest/src/migrations/update-12-6-0/update-base-jest-config.spec.ts deleted file mode 100644 index 45543c8f747c6..0000000000000 --- a/packages/jest/src/migrations/update-12-6-0/update-base-jest-config.spec.ts +++ /dev/null @@ -1,100 +0,0 @@ -const mockGetJestProjects = jest.fn(() => []); -jest.mock('../../utils/config/get-jest-projects', () => ({ - getJestProjects: mockGetJestProjects, -})); -const mockResolveConfig = jest.fn(() => - Promise.resolve({ singleQuote: true, endOfLine: 'lf' }) -); - -import { Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './update-base-jest-config'; - -describe('update 12.6.0', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - 'jest.config.js', - `module.exports = { - projects: ['/test-1'] - }` - ); - }); - - beforeEach(async () => { - const prettier = await import('prettier'); - prettier.resolveConfig = mockResolveConfig as any; - }); - - test('no projects key configured', async () => { - tree.write('jest.config.js', 'module.exports = {}'); - - await update(tree); - - const result = tree.read('jest.config.js').toString(); - expect(result).toMatchInlineSnapshot(` - "const { getJestProjects } = require('@nx/jest'); - - module.exports = { projects: getJestProjects() }; - " - `); - }); - - test('all jest projects covered', async () => { - mockGetJestProjects.mockImplementation(() => ['/test-1']); - await update(tree); - const result = tree.read('jest.config.js').toString(); - expect(result).toMatchInlineSnapshot(` - "const { getJestProjects } = require('@nx/jest'); - - module.exports = { projects: getJestProjects() }; - " - `); - }); - - test('some jest projects uncovered', async () => { - mockGetJestProjects.mockImplementation(() => ['/test-2']); - await update(tree); - const result = tree.read('jest.config.js').toString(); - expect(result).toMatchInlineSnapshot(` - "const { getJestProjects } = require('@nx/jest'); - - module.exports = { projects: [...getJestProjects(), '/test-1'] }; - " - `); - }); - - test('proper formatting with multiple uncovered jest projects', async () => { - mockGetJestProjects.mockImplementation(() => ['/test-2']); - tree.write( - 'jest.config.js', - ` -module.exports = { - projects: [ - '/test-1', - '/test-2', - '/test-3', - '/test-4', - '/test-5' - ] -}` - ); - await update(tree); - const result = tree.read('jest.config.js').toString(); - expect(result).toMatchInlineSnapshot(` -"const { getJestProjects } = require('@nx/jest'); - -module.exports = { - projects: [ - ...getJestProjects(), - '/test-1', - '/test-3', - '/test-4', - '/test-5', - ], -}; -" -`); - }); -}); diff --git a/packages/jest/src/migrations/update-12-6-0/update-base-jest-config.ts b/packages/jest/src/migrations/update-12-6-0/update-base-jest-config.ts deleted file mode 100644 index 384f0b6c3ac53..0000000000000 --- a/packages/jest/src/migrations/update-12-6-0/update-base-jest-config.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { formatFiles, Tree } from '@nx/devkit'; -import { jestConfigObject } from '../../utils/config/functions'; -import { getJestProjects } from '../../utils/config/get-jest-projects'; -import { - addImportStatementToJestConfig, - addPropertyToJestConfig, - removePropertyFromJestConfig, -} from '../../utils/config/update-config'; - -function determineUncoveredJestProjects(existingProjects: string[]) { - const coveredJestProjects = (getJestProjects() as string[]).reduce( - (acc, key) => { - acc[key] = true; - return acc; - }, - {} - ); - return existingProjects.filter((project) => !coveredJestProjects[project]); -} - -function determineProjectsValue(uncoveredJestProjects: string[]): string { - if (!uncoveredJestProjects.length) { - return `getJestProjects()`; - } - return `[...getJestProjects(), ${uncoveredJestProjects - .map((projectName) => `'${projectName}', `) - .join('')}]`; -} - -function updateBaseJestConfig( - tree: Tree, - baseJestConfigPath = 'jest.config.js' -) { - if (tree.read('/jest.config.js', 'utf-8').includes('getJestProjects()')) { - return; - } - const currentConfig = jestConfigObject(tree, baseJestConfigPath); - currentConfig.projects ??= []; - - const uncoveredJestProjects = determineUncoveredJestProjects( - currentConfig.projects as string[] - ); - removePropertyFromJestConfig(tree, baseJestConfigPath, 'projects'); - addPropertyToJestConfig( - tree, - baseJestConfigPath, - 'projects', - determineProjectsValue(uncoveredJestProjects), - { valueAsString: true } - ); - addImportStatementToJestConfig( - tree, - baseJestConfigPath, - `const { getJestProjects } = require('@nx/jest');` - ); - return; -} - -export default async function update(tree: Tree) { - updateBaseJestConfig(tree); - await formatFiles(tree); -} diff --git a/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.spec.ts b/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.spec.ts deleted file mode 100644 index 8869953f7b954..0000000000000 --- a/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.spec.ts +++ /dev/null @@ -1,296 +0,0 @@ -import { addProjectConfiguration, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './update-tsconfigs-for-tests'; - -const reactTsConfigs = { - app: { - extends: './tsconfig.json', - compilerOptions: { - outDir: '../../dist/out-tsc', - types: ['node'], - }, - files: [ - '../../node_modules/@nrwl/react/typings/cssmodule.d.ts', - '../../node_modules/@nrwl/react/typings/image.d.ts', - ], - exclude: [ - '**/*.spec.ts', - '**/*_spec.ts', - '**/*.spec.tsx', - '**/*.spec.js', - '**/*.spec.jsx', - ], - include: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'], - }, - lib: { - extends: './tsconfig.json', - compilerOptions: { - outDir: '../../dist/out-tsc', - types: ['node'], - }, - files: [ - '../../node_modules/@nrwl/react/typings/cssmodule.d.ts', - '../../node_modules/@nrwl/react/typings/image.d.ts', - ], - exclude: [ - '**/*.spec.ts', - '**/*_spec.ts', - '**/*.spec.tsx', - '**/*.spec.js', - '**/*.spec.jsx', - ], - include: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'], - }, - spec: { - extends: './tsconfig.json', - compilerOptions: { - outDir: '../../dist/out-tsc', - module: 'commonjs', - types: ['jest', 'node'], - }, - include: [ - '**/*.spec.ts', - '**/*_spec.ts', - '**/*.spec.tsx', - '**/*.spec.js', - '**/*.spec.jsx', - '**/*.d.ts', - ], - files: [ - '../../node_modules/@nrwl/react/typings/cssmodule.d.ts', - '../../node_modules/@nrwl/react/typings/image.d.ts', - ], - }, - base: { - include: [], - files: [], - references: [ - { - path: './tsconfig.app.json', - }, - { - path: './tsconfig.lib.json', - }, - { - path: './tsconfig.spec.json', - }, - ], - }, - expectedFilesToContain: [ - '**/*.spec.ts', - '**/*.test.ts', - '**/*_spec.ts', - '**/*_test.ts', - '**/*.spec.tsx', - '**/*.test.tsx', - '**/*.spec.js', - '**/*.test.js', - '**/*.spec.jsx', - '**/*.test.jsx', - ], -}; -const angularTsConfigs = { - app: { - extends: './tsconfig.json', - compilerOptions: { - outDir: '../../dist/out-tsc', - types: [], - }, - files: ['src/main.ts', 'src/polyfills.ts'], - include: ['src/**/*.d.ts'], - exclude: ['**/*.spec.ts', '**/*_spec.ts'], - }, - lib: { - extends: './tsconfig.json', - compilerOptions: { - outDir: '../../dist/out-tsc', - target: 'es2015', - declaration: true, - declarationMap: true, - inlineSources: true, - types: [], - lib: ['dom', 'es2018'], - }, - exclude: ['src/test-setup.ts', '**/*.spec.ts'], - include: ['**/*.ts'], - }, - spec: { - extends: './tsconfig.json', - compilerOptions: { - outDir: '../../dist/out-tsc', - module: 'commonjs', - types: ['jest', 'node'], - }, - files: ['src/test-setup.ts'], - include: ['**/*.spec.ts', '**/*_spec.ts', '**/*.d.ts'], - }, - expectedFilesToContain: [ - '**/*.spec.ts', - '**/*.test.ts', - '**/*_spec.ts', - '**/*_test.ts', - ], -}; - -const tsConfigLibBase = { - include: [], - files: [], - references: [ - { - path: './tsconfig.lib.json', - }, - { - path: './tsconfig.spec.json', - }, - ], -}; -const tsConfigAppBase = { - include: [], - files: [], - references: [ - { - path: './tsconfig.app.json', - }, - { - path: './tsconfig.spec.json', - }, - ], -}; -const tsConfigWithExclude = { - exclude: ['**/*.spec.ts', '**/*_spec.ts'], -}; - -[ - // test TSX/JSX support - { name: 'React App', configs: reactTsConfigs }, - // test non TSX/JSX support - { name: 'Angular App', configs: angularTsConfigs }, -].forEach(({ name, configs }) => { - describe(`Jest Migration (v13.1.2): ${name}`, () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - 'apps/project-one/tsconfig.app.json', - String.raw`${JSON.stringify(configs.app, null, 2)}` - ); - tree.write( - 'apps/project-one/tsconfig.spec.json', - String.raw`${JSON.stringify(configs.spec, null, 2)}` - ); - tree.write( - `apps/project-one/tsconfig.json`, - String.raw`${JSON.stringify(tsConfigAppBase, null, 2)}` - ); - tree.write( - 'libs/lib-one/tsconfig.lib.json', - String.raw`${JSON.stringify(configs.lib, null, 2)}` - ); - tree.write( - 'libs/lib-one/tsconfig.spec.json', - String.raw`${JSON.stringify(configs.spec, null, 2)}` - ); - tree.write( - `libs/lib-one/tsconfig.json`, - String.raw`${JSON.stringify(tsConfigLibBase, null, 2)}` - ); - - addProjectConfiguration(tree, 'lib-one', { - root: 'libs/lib-one', - sourceRoot: 'libs/lib-one/src', - projectType: 'library', - targets: { - build: { - executor: '@nrwl/web:build', - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'libs/lib-one/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - addProjectConfiguration(tree, 'project-one', { - root: 'apps/project-one', - sourceRoot: 'apps/project-one/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:build', - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/project-one/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - }); - - it('should update tsconfig.spec.json to include .test. files', async () => { - await update(tree); - const tsAppSpecConfig = JSON.parse( - tree.read('apps/project-one/tsconfig.spec.json', 'utf-8') - ); - const tsLibSpecConfig = JSON.parse( - tree.read('apps/project-one/tsconfig.spec.json', 'utf-8') - ); - - expect(tsAppSpecConfig.include).toEqual( - expect.arrayContaining(configs.expectedFilesToContain) - ); - - expect(tsLibSpecConfig.include).toEqual( - expect.arrayContaining(configs.expectedFilesToContain) - ); - }); - - it('should update tsconfig.{lib|app}.json to exclude .test. files', async () => { - await update(tree); - const tsAppConfig = JSON.parse( - tree.read('apps/project-one/tsconfig.app.json', 'utf-8') - ); - const tsLibConfig = JSON.parse( - tree.read('apps/project-one/tsconfig.app.json', 'utf-8') - ); - - expect(tsAppConfig.exclude).toEqual( - expect.arrayContaining(configs.expectedFilesToContain) - ); - expect(tsLibConfig.exclude).toEqual( - expect.arrayContaining(configs.expectedFilesToContain) - ); - }); - - it('should not update tsconfig without spec. patterns for include or exclude', async () => { - await update(tree); - const tsConfig = JSON.parse( - tree.read('apps/project-one/tsconfig.json', 'utf-8') - ); - expect(tsConfig).toEqual(tsConfigAppBase); - }); - - it('should update any tsconfig with spec pattern for include or exclude', async () => { - tree.write( - 'apps/project-one/tsconfig.random.json', - String.raw`${JSON.stringify(tsConfigWithExclude, null, 2)}` - ); - await update(tree); - - const randomTsConfig = JSON.parse( - tree.read('apps/project-one/tsconfig.random.json', 'utf-8') - ); - expect(randomTsConfig.exclude).toEqual([ - '**/*.spec.ts', - '**/*.test.ts', - '**/*_spec.ts', - '**/*_test.ts', - ]); - }); - }); -}); 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 deleted file mode 100644 index 1763c912a0c56..0000000000000 --- a/packages/jest/src/migrations/update-13-1-2/update-tsconfigs-for-tests.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { - formatFiles, - logger, - readProjectConfiguration, - stripIndents, - Tree, - updateJson, - visitNotIgnoredFiles, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { basename } from 'path'; -import { JestExecutorOptions } from '../../executors/jest/schema'; - -function updateTsConfigsForTests(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (jestOptions, projectName) => { - const projectConfig = readProjectConfiguration(tree, projectName); - - visitNotIgnoredFiles(tree, projectConfig.root, (path) => { - const fileName = basename(path); - if (fileName.startsWith('tsconfig') && fileName.endsWith('.json')) { - updateTsConfig(tree, path); - } - }); - } - ); - - function updateTsConfig(tree: Tree, tsconfigSpecPath: string) { - try { - updateJson(tree, tsconfigSpecPath, (value) => { - if (value.include) { - value.include = makeAllPatternsFromSpecPatterns(value.include); - } - - if (value.exclude) { - value.exclude = makeAllPatternsFromSpecPatterns(value.exclude); - } - return value; - }); - } catch (error) { - // issue trying to parse the tsconfig file bc it's invalid JSON from template markup/comments - // ignore and move on - logger.warn(stripIndents`Unable to update ${tsconfigSpecPath}. `); - } - } -} - -/** - * take an array of patterns and create patterns from those containing .spec. with .test. - * by default the pattern ** /*.spec.ts will be used if no value is passed in. - */ -function makeAllPatternsFromSpecPatterns( - specGlobs: string[] = ['**/*.spec.ts'] -): string[] { - return makeUniquePatterns( - specGlobs.reduce((patterns, current) => { - patterns.push(current); - // .spec. and _spec. can used as testing file name patterns - if (current.includes('spec.')) { - patterns.push(current.replace('spec.', 'test.')); - } - return patterns; - }, []) - ); -} - -function makeUniquePatterns(items: string[] = []): string[] { - return [...new Set(items)]; -} - -export default async function update(tree: Tree) { - updateTsConfigsForTests(tree); - await formatFiles(tree); -} - -interface TsConfig { - files?: string[]; - include?: string[]; - exclude?: string[]; - references?: { - path: string; - }[]; -} diff --git a/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.spec.ts b/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.spec.ts deleted file mode 100644 index 870f4c546407c..0000000000000 --- a/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.spec.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './add-missing-root-babel-config'; - -describe('Jest Migration (v13.4.4)', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - 'package.json', - JSON.stringify({ - name: 'test', - version: '', - description: '', - devDependencies: {}, - }) - ); - tree.write( - 'libs/lib-one/jest.config.js', - String.raw`module.exports = { - transform: { - '^.+\\\\.[tj]sx?$': 'babel-jest', - } - }` - ); - - addProjectConfiguration(tree, 'lib-one', { - root: 'libs/lib-one', - sourceRoot: 'libs/lib-one/src', - projectType: 'library', - targets: { - build: { - executor: '@nrwl/web:build', - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'libs/lib-one/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - - addProjectConfiguration(tree, 'lib-two', { - root: 'libs/lib-two', - sourceRoot: 'libs/lib-two/src', - projectType: 'library', - targets: { - build: { - executor: '@nrwl/web:build', - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'libs/lib-two/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - }); - - it('should create root babel.config.json and install @nrwl/web', async () => { - await update(tree); - expect(tree.exists('babel.config.json')).toBeTruthy(); - const packageJson = readJson(tree, 'package.json'); - expect(packageJson.devDependencies['@nrwl/web']).toBeTruthy(); - }); - - it('should not change anything if root babel.config.json is found', async () => { - tree.write('babel.config.json', '{"babelrcRoots": ["*"]}'); - await update(tree); - const packageJson = readJson(tree, 'package.json'); - expect(packageJson.devDependencies['@nrwl/web']).toBeFalsy(); - }); - - it('should update w/ Array value for babel-jest transformer', async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'libs/lib-three/jest.config.js', - String.raw`module.exports = { - transform: { - '^.+\\\\.[tj]sx?$': ['babel-jest', {someOptionsThatDontMatter: false}], - } - }` - ); - - addProjectConfiguration(tree, 'lib-three', { - root: 'libs/lib-three', - sourceRoot: 'libs/lib-three/src', - projectType: 'library', - targets: { - build: { - executor: '@nrwl/web:build', - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'libs/lib-three/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - - await update(tree); - expect(tree.exists('babel.config.json')).toBeTruthy(); - const packageJson = readJson(tree, 'package.json'); - expect(packageJson.devDependencies['@nrwl/web']).toBeTruthy(); - }); -}); 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 deleted file mode 100644 index 2874517fc7179..0000000000000 --- a/packages/jest/src/migrations/update-13-4-4/add-missing-root-babel-config.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - addDependenciesToPackageJson, - formatFiles, - joinPathFragments, - readProjectConfiguration, - Tree, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { JestExecutorOptions } from '../../executors/jest/schema'; -import { jestConfigObject } from '../../utils/config/functions'; -import { nxVersion } from '../../utils/versions'; - -function checkIfProjectNeedsUpdate(tree: Tree): boolean { - if (tree.exists('babel.config.json')) { - // the project is already running on babel and good to go - return false; - } - - let shouldUpdate = false; - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (jestOptions, projectName) => { - const projectConfig = readProjectConfiguration(tree, projectName); - const jestConfigPath = joinPathFragments( - projectConfig.root, - 'jest.config.js' - ); - - if (!tree.exists(jestConfigPath)) { - return; - } - - const config = jestConfigObject(tree, jestConfigPath); - - if (config.transform) { - for (const transformer of Object.values(config.transform)) { - if ( - (typeof transformer === 'string' && transformer === 'babel-jest') || - (Array.isArray(transformer) && transformer[0] === 'babel-jest') - ) { - shouldUpdate = true; - } - } - } - } - ); - - return shouldUpdate; -} - -export default async function update(tree: Tree) { - const shouldUpdateConfigs = checkIfProjectNeedsUpdate(tree); - - if (shouldUpdateConfigs) { - addDependenciesToPackageJson(tree, {}, { '@nrwl/web': nxVersion }); - - tree.write('babel.config.json', '{"babelrcRoots": ["*"]}'); - - await formatFiles(tree); - } -} diff --git a/packages/jest/src/migrations/update-14-0-0/__snapshots__/update-jest-config-ext.spec.ts.snap b/packages/jest/src/migrations/update-14-0-0/__snapshots__/update-jest-config-ext.spec.ts.snap deleted file mode 100644 index 7bccc6517f60f..0000000000000 --- a/packages/jest/src/migrations/update-14-0-0/__snapshots__/update-jest-config-ext.spec.ts.snap +++ /dev/null @@ -1,94 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Jest Migration (v14.0.0) should NOT update jest.config.ts preset 1`] = ` -"/* eslint-disable */ - -module.exports = { - displayName: 'lib-one', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - transform: { - '^.+\\\\.[tj]sx?$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/libs/lib-one', -}; -" -`; - -exports[`Jest Migration (v14.0.0) should produce the same results when running multiple times 1`] = ` -{ - "files": [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "parserOptions": { - "project": [ - "libs/my-next-proj/tsconfig.*?.json", - ], - }, - "rules": {}, -} -`; - -exports[`Jest Migration (v14.0.0) should produce the same results when running multiple times 2`] = ` -"/* eslint-disable */ -module.exports = { - displayName: 'lib-one', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - transform: { - '^.+\\\\.[tj]sx?$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/libs/lib-one', -}; -" -`; - -exports[`Jest Migration (v14.0.0) should rename project jest.config.js to jest.config.ts 1`] = ` -"/* eslint-disable */ - -module.exports = { - displayName: 'lib-one', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - transform: { - '^.+\\\\.[tj]sx?$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/libs/lib-one', -}; -" -`; - -exports[`Jest Migration (v14.0.0) should update the excludes of next js apps using the project parser settings 1`] = ` -{ - "files": [ - "*.ts", - "*.tsx", - "*.js", - "*.jsx", - ], - "parserOptions": { - "project": [ - "libs/lib-one/tsconfig.*?.json", - ], - }, - "rules": {}, -} -`; 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 deleted file mode 100644 index f6ba082e3df9b..0000000000000 --- a/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.spec.ts +++ /dev/null @@ -1,314 +0,0 @@ -import { - readJson, - readProjectConfiguration, - Tree, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nx/js'; -import jestInitGenerator from '../../generators/init/init'; -import { updateJestConfigExt } from './update-jest-config-ext'; - -const setupDefaults = { - js: true, - skipPackageJson: true, - libName: 'lib-one', - setParserOptionsProject: false, -}; -const oldConfig = ` -module.exports = { - displayName: 'PLACE_HOLDER', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - } - }, - transform: { - '^.+\\\\.[tj]sx?$': 'ts-jest' - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/libs/PLACE_HOLDER' -}; -`; - -async function libSetUp(tree: Tree, options = setupDefaults) { - jestInitGenerator(tree, { - js: options.js, - skipPackageJson: options.skipPackageJson, - }); - await workspaceLib(tree, { - name: options.libName, - setParserOptionsProject: options.setParserOptionsProject, - }); - tree.rename( - `libs/${options.libName}/jest.config.ts`, - `libs/${options.libName}/jest.config.js` - ); - tree.write( - `libs/${options.libName}/jest.config.js`, - oldConfig.replace(/PLACE_HOLDER/g, options.libName) - ); - updateProjectConfiguration(tree, options.libName, { - ...readProjectConfiguration(tree, options.libName), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: `libs/${options.libName}/jest.config.js`, - passWithNoTests: true, - }, - configurations: { - production: { - silent: true, - }, - }, - }, - }, - }); -} - -describe('Jest Migration (v14.0.0)', () => { - let tree: Tree; - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should rename project jest.config.js to jest.config.ts', async () => { - await libSetUp(tree); - - await updateJestConfigExt(tree); - expect(tree.exists('libs/lib-one/jest.config.ts')).toBeTruthy(); - expect(tree.read('libs/lib-one/jest.config.ts', 'utf-8')).toMatchSnapshot(); - }); - - it('should rename root jest.config.js', async () => { - await libSetUp(tree); - - await updateJestConfigExt(tree); - expect(tree.exists('jest.config.ts')).toBeTruthy(); - expect(tree.exists('jest.preset.js')).toBeTruthy(); - }); - - it('should NOT update jest.config.ts preset', async () => { - await libSetUp(tree); - - tree.rename('libs/lib-one/jest.config.js', 'libs/lib-one/jest.config.ts'); - const projectConfig = readProjectConfiguration(tree, 'lib-one'); - updateProjectConfiguration(tree, 'lib-one', { - ...projectConfig, - targets: { - test: { - ...projectConfig.targets.test, - options: { - jestConfig: 'libs/lib-one/jest.config.ts', - passWithNoTests: true, - }, - }, - }, - }); - expect(tree.exists('libs/lib-one/jest.config.ts')).toBeTruthy(); - await updateJestConfigExt(tree); - expect(tree.exists('libs/lib-one/jest.config.ts')).toBeTruthy(); - expect(tree.read('libs/lib-one/jest.config.ts', 'utf-8')).toMatchSnapshot(); - }); - - it('should only update js/ts files', async () => { - await libSetUp(tree); - - tree.rename('libs/lib-one/jest.config.js', 'libs/lib-one/jest.config.ts'); - updateProjectConfiguration(tree, 'lib-one', { - ...readProjectConfiguration(tree, 'lib-one'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'libs/lib-one/jest.config.ts', - passWithNoTests: true, - }, - }, - }, - }); - - await libSetUp(tree, { ...setupDefaults, libName: 'lib-two' }); - tree.delete('libs/lib-two/jest.config.ts'); // lib generator creates a ts file - tree.write('libs/lib-two/jest.config.json', '{}'); - updateProjectConfiguration(tree, 'lib-two', { - ...readProjectConfiguration(tree, 'lib-two'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'libs/lib-two/jest.config.json', - passWithNoTests: true, - }, - }, - }, - }); - - await libSetUp(tree, { ...setupDefaults, libName: 'lib-three' }); - expect(tree.exists('libs/lib-one/jest.config.ts')).toBeTruthy(); - await updateJestConfigExt(tree); - expect(tree.exists('libs/lib-one/jest.config.ts')).toBeTruthy(); - expect(tree.exists('libs/lib-two/jest.config.ts')).toBeFalsy(); - expect(tree.exists('libs/lib-two/jest.config.json')).toBeTruthy(); - expect(tree.exists('libs/lib-three/jest.config.ts')).toBeTruthy(); - }); - - it('should not throw error if file does not exit', async () => { - await libSetUp(tree); - - tree.delete('libs/lib-one/jest.config.js'); - await updateJestConfigExt(tree); - expect(tree.exists('libs/lib-one/jest.config.ts')).toBeFalsy(); - expect(tree.exists('libs/lib-one/jest.config.js')).toBeFalsy(); - }); - - it('should update correct tsconfigs', async () => { - await libSetUp(tree); - - updateJson(tree, 'libs/lib-one/tsconfig.lib.json', (json) => { - json.exclude = ['src/**/*.spec.ts']; - return json; - }); - - updateJson(tree, 'libs/lib-one/tsconfig.spec.json', (json) => { - json.include = ['src/**/*.spec.ts']; - return json; - }); - - await updateJestConfigExt(tree); - - const tsconfig = readJson(tree, 'libs/lib-one/tsconfig.json'); - const libTsConfig = readJson(tree, 'libs/lib-one/tsconfig.lib.json'); - const specTsConfig = readJson(tree, 'libs/lib-one/tsconfig.spec.json'); - - expect(tsconfig.exclude).toBeFalsy(); - expect(libTsConfig.exclude).toEqual(['src/**/*.spec.ts', 'jest.config.ts']); - expect(specTsConfig.exclude).toBeFalsy(); - expect(specTsConfig.include).toEqual([ - 'src/**/*.spec.ts', - 'jest.config.ts', - ]); - }); - - it('should add exclude to root tsconfig with no references', async () => { - await libSetUp(tree); - - tree.delete('libs/lib-one/tsconfig.spec.json'); - tree.delete('libs/lib-one/tsconfig.lib.json'); - - updateJson(tree, 'libs/lib-one/tsconfig.json', (json) => { - delete json.references; - return json; - }); - - await updateJestConfigExt(tree); - - const tsconfig = readJson(tree, 'libs/lib-one/tsconfig.json'); - - expect(tsconfig.exclude).toEqual(['jest.config.ts']); - expect(tree.exists('libs/lib-one/tsconfig.spec.json')).toBeFalsy(); - expect(tree.exists('libs/lib-one/tsconfig.lib.json')).toBeFalsy(); - }); - - it('should update the excludes of next js apps using the project parser settings', async () => { - await libSetUp(tree, { ...setupDefaults, setParserOptionsProject: true }); - - const projectConfig = readProjectConfiguration(tree, 'lib-one'); - projectConfig.targets['build'] = { - executor: '@nrwl/next:build', - options: {}, - }; - updateProjectConfiguration(tree, 'lib-one', projectConfig); - updateJson(tree, 'libs/lib-one/tsconfig.json', (json) => { - // simulate nextJS tsconfig; - json.exclude = ['node_modules']; - return json; - }); - const esLintJson = readJson(tree, 'libs/lib-one/.eslintrc.json'); - // make sure the parserOptions are set correctly - expect(esLintJson.overrides[0]).toMatchSnapshot(); - - await updateJestConfigExt(tree); - - const tsconfigSpec = readJson(tree, 'libs/lib-one/tsconfig.spec.json'); - expect(tsconfigSpec.exclude).toEqual(['node_modules']); - }); - - it('should produce the same results when running multiple times', async () => { - await libSetUp(tree); - updateJson(tree, 'libs/lib-one/tsconfig.lib.json', (json) => { - json.exclude = ['src/**/*.spec.ts']; - return json; - }); - updateJson(tree, 'libs/lib-one/tsconfig.spec.json', (json) => { - json.include = ['src/**/*.spec.ts']; - return json; - }); - - await setupNextProj(tree); - - const esLintJson = readJson(tree, 'libs/my-next-proj/.eslintrc.json'); - // make sure the parserOptions are set correctly for next - expect(esLintJson.overrides[0]).toMatchSnapshot(); - - await updateJestConfigExt(tree); - - assertNextProj(tree); - assertLib(tree); - - await updateJestConfigExt(tree); - - assertNextProj(tree); - assertLib(tree); - - expect(tree.read('libs/lib-one/jest.config.ts', 'utf-8')).toMatchSnapshot(); - }); -}); - -async function setupNextProj(tree: Tree) { - await libSetUp(tree, { - ...setupDefaults, - libName: 'my-next-proj', - setParserOptionsProject: true, - }); - const projectConfig = readProjectConfiguration(tree, 'my-next-proj'); - projectConfig.targets['build'] = { - executor: '@nrwl/next:build', - options: {}, - }; - updateProjectConfiguration(tree, 'my-next-proj', projectConfig); - updateJson(tree, 'libs/my-next-proj/tsconfig.json', (json) => { - // simulate nextJS tsconfig; - json.exclude = ['node_modules']; - return json; - }); -} - -function assertNextProj(tree: Tree) { - expect( - readJson(tree, 'libs/my-next-proj/tsconfig.spec.json').exclude - ).toEqual(['node_modules']); - expect( - readJson(tree, 'libs/my-next-proj/tsconfig.spec.json').include - ).toEqual(expect.arrayContaining(['jest.config.ts'])); -} - -function assertLib(tree: Tree) { - expect(readJson(tree, 'libs/lib-one/tsconfig.json').exclude).toBeFalsy(); - expect(readJson(tree, 'libs/lib-one/tsconfig.spec.json').exclude).toBeFalsy(); - expect(readJson(tree, 'libs/lib-one/tsconfig.spec.json').include).toEqual([ - 'src/**/*.spec.ts', - 'jest.config.ts', - ]); - - expect(readJson(tree, 'libs/lib-one/tsconfig.lib.json').exclude).toEqual([ - 'src/**/*.spec.ts', - 'jest.config.ts', - ]); - expect(readJson(tree, 'libs/lib-one/tsconfig.lib.json').include).toEqual([ - 'src/**/*.ts', - ]); -} diff --git a/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.ts b/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.ts deleted file mode 100644 index a2b079657a9ad..0000000000000 --- a/packages/jest/src/migrations/update-14-0-0/update-jest-config-ext.ts +++ /dev/null @@ -1,180 +0,0 @@ -import { - formatFiles, - getProjects, - joinPathFragments, - logger, - ProjectConfiguration, - readJson, - stripIndents, - Tree, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { extname } from 'path'; -import { JestExecutorOptions } from '../../executors/jest/schema'; - -const allowedExt = ['.ts', '.js']; - -function updateTsConfig(tree: Tree, tsConfigPath: string) { - try { - updateJson( - tree, - tsConfigPath, - (json) => { - json.exclude = Array.from( - new Set([...(json.exclude || []), 'jest.config.ts']) - ); - return json; - }, - { - allowTrailingComma: true, - disallowComments: false, - } - ); - } catch (e) { - logger.warn( - stripIndents`Nx Unable to update ${tsConfigPath}. Please manually ignore the jest.config.ts file.` - ); - } -} - -function addEsLintIgnoreComments(tree: Tree, filePath: string) { - if (tree.exists(filePath)) { - const contents = tree.read(filePath, 'utf-8'); - if (!contents.startsWith('/* eslint-disable */')) { - tree.write( - filePath, - `/* eslint-disable */ -${contents}` - ); - } - } -} - -function isJestConfigValid(tree: Tree, options: JestExecutorOptions) { - const configExt = extname(options.jestConfig); - - if (!tree.exists(options.jestConfig) || !allowedExt.includes(configExt)) { - logger.debug( - `unable to update file because it doesn't exist or is not a js or ts file. Config: ${ - options.jestConfig - }. Exists?: ${tree.exists(options.jestConfig)}` - ); - return false; - } - return true; -} - -function updateTsconfigSpec( - tree: Tree, - projectConfig: ProjectConfiguration, - path, - options: { isNextWithProjectParse: boolean; tsConfigPath: string } = { - isNextWithProjectParse: false, - tsConfigPath: '', - } -) { - updateJson(tree, joinPathFragments(projectConfig.root, path), (json) => { - json.include = Array.from( - new Set([...(json.include || []), 'jest.config.ts']) - ); - if (options.isNextWithProjectParse) { - const tsConfig = readJson(tree, options.tsConfigPath); - const tsConfigExclude = (tsConfig.exclude || []).filter( - (e) => e !== 'jest.config.ts' - ); - json.exclude = Array.from( - new Set([...(json.exclude || []), ...tsConfigExclude]) - ); - } - return json; - }); -} - -function isNextWithProjectLint( - projectConfig: ProjectConfiguration, - esLintJson: any -) { - const esLintOverrides = esLintJson?.overrides?.find((o) => - ['*.ts', '*.tsx', '*.js', '*.jsx'].every((ext) => o.files.includes(ext)) - ); - - // check if it's a next app and has a parserOptions.project set in the eslint overrides - return !!( - projectConfig?.targets?.['build']?.executor === '@nrwl/next:build' && - esLintOverrides?.parserOptions?.project - ); -} - -export async function updateJestConfigExt(tree: Tree) { - if (tree.exists('jest.config.js')) { - tree.rename('jest.config.js', 'jest.config.ts'); - } - - const projects = getProjects(tree); - - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, projectName, target, configuration) => { - const projectConfig = projects.get(projectName); - - if (!options.jestConfig || !isJestConfigValid(tree, options)) { - return; - } - - addEsLintIgnoreComments(tree, options.jestConfig); - - const newJestConfigPath = options.jestConfig.replace('.js', '.ts'); - tree.rename(options.jestConfig, newJestConfigPath); - - const rootFiles = tree.children(projectConfig.root); - for (const fileName of rootFiles) { - if (fileName === 'tsconfig.json') { - const filePath = joinPathFragments(projectConfig.root, fileName); - const tsConfig = readJson(tree, filePath, { - allowTrailingComma: true, - disallowComments: false, - }); - - if (tsConfig.references) { - for (const { path } of tsConfig.references) { - // skip as editor.json should include everything anyway. - if (path.endsWith('tsconfig.editor.json')) { - continue; - } - - if (path.endsWith('tsconfig.spec.json')) { - const eslintPath = joinPathFragments( - projectConfig.root, - '.eslintrc.json' - ); - updateTsconfigSpec(tree, projectConfig, path, { - isNextWithProjectParse: tree.exists(eslintPath) - ? isNextWithProjectLint( - projectConfig, - readJson(tree, eslintPath) - ) - : false, - tsConfigPath: filePath, - }); - continue; - } - - updateTsConfig(tree, joinPathFragments(projectConfig.root, path)); - } - } else { - updateTsConfig(tree, filePath); - } - } - } - - projectConfig.targets[target].options.jestConfig = newJestConfigPath; - updateProjectConfiguration(tree, projectName, projectConfig); - } - ); - await formatFiles(tree); -} - -export default updateJestConfigExt; diff --git a/packages/jest/src/migrations/update-14-1-5/__snapshots__/update-exports-jest-config.spec.ts.snap b/packages/jest/src/migrations/update-14-1-5/__snapshots__/update-exports-jest-config.spec.ts.snap deleted file mode 100644 index 3777b5983f833..0000000000000 --- a/packages/jest/src/migrations/update-14-1-5/__snapshots__/update-exports-jest-config.spec.ts.snap +++ /dev/null @@ -1,76 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Jest Migration (v14.1.2) should convert module.exports => export default 1`] = ` -"const { getJestProjects } = require('@nrwl/jest'); -const nxPreset = require('@nrwl/jest/preset'); - - -const someFn = () => ({more: 'stuff'}); -module.export.abc = someFn; -export default { -...nxPreset, -more: 'stuff', -someFn, -projects: getJestProjects() -};" -`; - -exports[`Jest Migration (v14.1.2) should update individual project jest configs 1`] = ` -" -const nxPreset = require('@nrwl/jest/preset').default; -const someOtherImport = require('../something/else.js'); -export default { - ...someOtherImport, - ...nxPreset, - displayName: 'lib-one', - preset: '../../jest.preset.js', - setupFilesAfterEnv: ['/src/test-setup.ts'], - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\\\.(html|svg)$', - }, - }, - coverageDirectory: '../../coverage/apps/lib-one', - transform: { - '^.+\\\\.(ts|mjs|js|html)$': 'jest-preset-angular', - }, - transformIgnorePatterns: ['node_modules/(?!.*\\\\.mjs$)'], - snapshotSerializers: [ - 'jest-preset-angular/build/serializers/no-ng-attributes', - 'jest-preset-angular/build/serializers/ng-snapshot', - 'jest-preset-angular/build/serializers/html-comment', - ], -}; -" -`; - -exports[`Jest Migration (v14.1.2) should work with multiple configurations 1`] = ` -" -const nxPreset = require('@nrwl/jest/preset').default; -const someOtherImport = require('../something/else.js'); -export default { - ...someOtherImport, - ...nxPreset, - displayName: 'lib-one', - preset: '../../jest.preset.js', - setupFilesAfterEnv: ['/src/test-setup.ts'], - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\\\.(html|svg)$', - }, - }, - coverageDirectory: '../../coverage/apps/lib-one', - transform: { - '^.+\\\\.(ts|mjs|js|html)$': 'jest-preset-angular', - }, - transformIgnorePatterns: ['node_modules/(?!.*\\\\.mjs$)'], - snapshotSerializers: [ - 'jest-preset-angular/build/serializers/no-ng-attributes', - 'jest-preset-angular/build/serializers/ng-snapshot', - 'jest-preset-angular/build/serializers/html-comment', - ], -}; -" -`; diff --git a/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts b/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts deleted file mode 100644 index f58041927ae18..0000000000000 --- a/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.spec.ts +++ /dev/null @@ -1,201 +0,0 @@ -import { - readProjectConfiguration, - stripIndents, - Tree, - updateProjectConfiguration, - updateJson, - readJson, -} from '@nx/devkit'; -import { createTree, createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nx/js'; -import { - updateExportsJestConfig, - updateRootFiles, - updateToDefaultExport, -} from './update-exports-jest-config'; - -describe('Jest Migration (v14.1.2)', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should update root jest files', () => { - tree.write( - 'jest.config.ts', - stripIndents` - const { getJestProjects } = require('@nrwl/jest'); - - module.exports = { - projects: getJestProjects() - };` - ); - - tree.write( - 'jest.preset.ts', - stripIndents` - const nxPreset = require('@nrwl/jest/preset'); - - module.exports = { ...nxPreset };` - ); - - const status = updateRootFiles(tree); - - expect(status).toEqual({ didUpdateRootPreset: true }); - expect(tree.read('jest.config.ts', 'utf-8')).toEqual(stripIndents` - const { getJestProjects } = require('@nrwl/jest'); - - export default { - projects: getJestProjects() - }; - `); - expect(tree.read('jest.preset.js', 'utf-8')).toEqual(stripIndents` - const nxPreset = require('@nrwl/jest/preset').default; - - module.exports = { ...nxPreset };`); - }); - - it('should update individual project jest configs', async () => { - await workspaceLib(tree, { name: 'lib-one' }); - const projectConfiguration = readProjectConfiguration(tree, 'lib-one'); - updateProjectConfiguration(tree, 'lib-one', { - ...projectConfiguration, - targets: { - ...projectConfiguration.targets, - test: { - ...projectConfiguration.targets.test, - executor: '@nrwl/jest:jest', - }, - }, - }); - tree.rename('jest.preset.js', 'jest.preset.ts'); - tree.write( - 'libs/lib-one/jest.config.ts', - ` -const nxPreset = require('@nrwl/jest/preset'); -const someOtherImport = require('../something/else.js'); -module.exports = { - ...someOtherImport, - ...nxPreset, - displayName: 'lib-one', - preset: '../../jest.preset.ts', - setupFilesAfterEnv: ['/src/test-setup.ts'], - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\\\.(html|svg)$', - }, - }, - coverageDirectory: '../../coverage/apps/lib-one', - transform: { - '^.+\\\\.(ts|mjs|js|html)$': 'jest-preset-angular', - }, - transformIgnorePatterns: ['node_modules/(?!.*\\\\.mjs$)'], - snapshotSerializers: [ - 'jest-preset-angular/build/serializers/no-ng-attributes', - 'jest-preset-angular/build/serializers/ng-snapshot', - 'jest-preset-angular/build/serializers/html-comment', - ], -}; -` - ); - updateJson(tree, 'package.json', (json) => { - delete json.devDependencies['ts-node']; - return json; - }); - expect( - readJson(tree, 'package.json').devDependencies['ts-node'] - ).toBeUndefined(); - updateExportsJestConfig(tree); - - const config = tree.read('libs/lib-one/jest.config.ts', 'utf-8'); - expect(readJson(tree, 'package.json').devDependencies['ts-node']).toEqual( - '10.9.1' - ); - expect(config).toMatchSnapshot(); - }); - - it('should work with multiple configurations', async () => { - await workspaceLib(tree, { name: 'lib-one' }); - tree.rename('jest.preset.js', 'jest.preset.ts'); - updateProjectConfiguration(tree, 'lib-one', { - ...readProjectConfiguration(tree, 'lib-one'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'libs/lib-one/jest.config.ts', - passWithoutTests: true, - }, - configurations: { - production: { - silent: true, - }, - }, - }, - }, - }); - - tree.write( - 'libs/lib-one/jest.config.ts', - ` -const nxPreset = require('@nrwl/jest/preset'); -const someOtherImport = require('../something/else.js'); -module.exports = { - ...someOtherImport, - ...nxPreset, - displayName: 'lib-one', - preset: '../../jest.preset.ts', - setupFilesAfterEnv: ['/src/test-setup.ts'], - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\\\.(html|svg)$', - }, - }, - coverageDirectory: '../../coverage/apps/lib-one', - transform: { - '^.+\\\\.(ts|mjs|js|html)$': 'jest-preset-angular', - }, - transformIgnorePatterns: ['node_modules/(?!.*\\\\.mjs$)'], - snapshotSerializers: [ - 'jest-preset-angular/build/serializers/no-ng-attributes', - 'jest-preset-angular/build/serializers/ng-snapshot', - 'jest-preset-angular/build/serializers/html-comment', - ], -}; -` - ); - - updateExportsJestConfig(tree); - - const config = tree.read('libs/lib-one/jest.config.ts', 'utf-8'); - expect(config).toMatchSnapshot(); - expect(tree.exists('jest.preset.ts')).toBeFalsy(); - expect(tree.exists('jest.preset.js')).toBeTruthy(); - }); - - it('should convert module.exports => export default', () => { - tree = createTree(); - - tree.write( - 'jest.config.js', - stripIndents` - const { getJestProjects } = require('@nrwl/jest'); - const nxPreset = require('@nrwl/jest/preset'); - - - const someFn = () => ({more: 'stuff'}); - module.export.abc = someFn; - module.exports = { - ...nxPreset, - more: 'stuff', - someFn, - projects: getJestProjects() - };` - ); - updateToDefaultExport(tree, 'jest.config.js'); - - expect(tree.read('jest.config.js', 'utf-8')).toMatchSnapshot(); - }); -}); diff --git a/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.ts b/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.ts deleted file mode 100644 index 35f1d1b1eb846..0000000000000 --- a/packages/jest/src/migrations/update-14-1-5/update-exports-jest-config.ts +++ /dev/null @@ -1,93 +0,0 @@ -import type { Tree } from '@nx/devkit'; -import { addDependenciesToPackageJson } from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { tsNodeVersion } from '../../utils/versions'; -import { tsquery } from '@phenomnomnominal/tsquery'; -import type { BinaryExpression } from 'typescript'; -import type { JestExecutorOptions } from '../../executors/jest/schema'; - -export function updateExportsJestConfig(tree: Tree) { - const { didUpdateRootPreset } = updateRootFiles(tree); - let shouldInstallTsNode = false; - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options) => { - if (options.jestConfig && tree.exists(options.jestConfig)) { - if (options.jestConfig.endsWith('.ts')) { - updateToDefaultExport(tree, options.jestConfig); - shouldInstallTsNode = true; - } - - const updatedImport = updateNxPresetImport( - tree.read(options.jestConfig, 'utf-8') - ); - tree.write(options.jestConfig, updatedImport); - - // jest.preset.ts => jest.preset.js - if (didUpdateRootPreset) { - const projectConfig = tree.read(options.jestConfig, 'utf-8'); - const updatedConfig = projectConfig.replace( - /(preset:\s*['"][.\/]*)(jest\.preset\.ts)(['"])/g, - '$1jest.preset.js$3' - ); - tree.write(options.jestConfig, updatedConfig); - } - } - } - ); - - return shouldInstallTsNode - ? addDependenciesToPackageJson(tree, {}, { 'ts-node': tsNodeVersion }) - : () => {}; -} - -export function updateRootFiles(tree: Tree): { didUpdateRootPreset: boolean } { - let didUpdateRootPreset = false; - if (tree.exists('jest.config.ts')) { - updateToDefaultExport(tree, 'jest.config.ts'); - } - - if (tree.exists('jest.preset.ts')) { - // fix those who ran v14 migration where this was renamed. - tree.rename('jest.preset.ts', 'jest.preset.js'); - didUpdateRootPreset = true; - } - - if (tree.exists('jest.preset.js')) { - const newContents = updateNxPresetImport( - tree.read('jest.preset.js', 'utf-8') - ); - tree.write('jest.preset.js', newContents); - } - - return { - didUpdateRootPreset, - }; -} - -function updateNxPresetImport(fileContents: string): string { - return fileContents.replace( - /require\(['"]@nrwl\/jest\/preset['"]\)[;\s]*?[\n\r]/g, - `require('@nrwl/jest/preset').default; -` - ); -} - -export function updateToDefaultExport(tree: Tree, filePath: string) { - const newConfig = tsquery.replace( - tree.read(filePath, 'utf-8'), - 'ExpressionStatement BinaryExpression', - (node: BinaryExpression) => { - if (node.left.getText() === 'module.exports') { - return `export default ${node.right.getText()}`; - } - - return node.getText(); - } - ); - - tree.write(filePath, newConfig); -} - -export default updateExportsJestConfig; diff --git a/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts b/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts deleted file mode 100644 index aa80240743558..0000000000000 --- a/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.spec.ts +++ /dev/null @@ -1,221 +0,0 @@ -import { - readJson, - readProjectConfiguration, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nx/js'; -import { - checkDeps, - updateConfigsJest28, - updateJestConfig, -} from './update-configs-jest-28'; - -const mockJestConfig = ` -import { nxPreset } from '@nrwl/jest/preset' -const myGlobals = ['Math', 'Promise']; - -export default { - ...nxPreset, - displayName: 'test-ng-app', - preset: '../../jest.preset.js', - setupFilesAfterEnv: ['/src/test-setup.ts'], - extraGlobals: ['Math', 'Something'], - extraGlobals: [], - extraGlobals: myGlobals, - timers: 'fake', - timers: 'modern', - timers: 'legacy', - timers: 'real', - testURL: 'http://localhost', - testURL: "123abc", - testURL: \`BLAH\`, - testEnvironment: 'jsdom', - testRunner: 'jest-jasmine2', -} -`; -describe('Jest Migration - jest 28 config support', () => { - it('should update "extraGlobals" config option', () => { - const actual = updateJestConfig(mockJestConfig); - expect(actual).not.toContain(`extraGlobals`); - expect(actual).toContain(`sandboxInjectedGlobals: ['Math', 'Something'],`); - expect(actual).toContain(`sandboxInjectedGlobals: [],`); - expect(actual).toContain(`sandboxInjectedGlobals: myGlobals,`); - }); - - it('should update "testURL" config option', () => { - const actual = updateJestConfig(mockJestConfig); - expect(actual).not.toContain(`testURL`); - expect(actual).toContain( - `testEnvironmentOptions: {url: 'http://localhost'},` - ); - expect(actual).toContain(`testEnvironmentOptions: {url: "123abc"},`); - expect(actual).toContain(`testEnvironmentOptions: {url: \`BLAH\`},`); - }); - - it('should update "timers" config option', () => { - const actual = updateJestConfig(mockJestConfig); - expect(actual).not.toContain(`timers`); - expect(actual).toContain(`fakeTimers: { enableGlobally: false },`); - expect(actual).toContain(`fakeTimers: { enableGlobally: true },`); - expect(actual).toContain(`fakeTimers: { enableGlobally: true },`); - expect(actual).toContain( - `fakeTimers: { enableGlobally: true, legacyFakeTimers: true },` - ); - }); - - it('should update jest-environment-jsdom if being used', async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - `package.json`, - `{ - "name": "jest-28-test", - "version": "0.0.0", - "license": "MIT", - "devDependencies": { - "jest": "^28.1.1", - "jest-environment-jsdom": "^27.1.0", - "jest-preset-angular": "^11.0.0", - "nx": "14.1.6", - "ts-jest": "^27.0.2", - "ts-node": "9.1.1", - "typescript": "~4.6.2" - }, - "dependencies": { - } -} -` - ); - - const actual = checkDeps(tree); - expect(actual).toEqual({ - 'jest-environment-jsdom': '28.1.1', - }); - }); - - it('should update jest-jasmine2 if being used as a test runner', () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - `package.json`, - `{ - "name": "jest-28-test", - "version": "0.0.0", - "license": "MIT", - "devDependencies": { - "jest": "^27.1.1", - "jest-jasmine2": "^27.1.0", - "nx": "14.1.6", - "ts-jest": "^27.0.2", - "ts-node": "9.1.1", - "typescript": "~4.6.2" - }, - "dependencies": { - } -} -` - ); - - tree.write( - 'jest.preset.js', - ` -const nxPreset = require('@nx/jest/preset').default; -module.exports = { - ...nxPreset, - testRunner: 'jest-jasmine2', -};` - ); - - const actual = checkDeps(tree); - expect(actual).toEqual({ - 'jest-jasmine2': '28.1.1', - }); - }); - - it('should not install deps if they are not used', () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - `package.json`, - `{ - "name": "jest-28-test", - "version": "0.0.0", - "license": "MIT", - "devDependencies": { - "jest": "^27.1.0", - "nx": "14.1.6", - "ts-jest": "^27.0.2", - "ts-node": "9.1.1", - "typescript": "~4.6.2" - }, - "dependencies": { - } -} -` - ); - - const actual = checkDeps(tree); - expect(actual).toEqual({}); - }); - - it('should update deps from jest.config.ts', async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await workspaceLib(tree, { name: 'my-lib', unitTestRunner: 'jest' }); - const projectConfiguration = readProjectConfiguration(tree, 'my-lib'); - updateProjectConfiguration(tree, 'my-lib', { - ...projectConfiguration, - targets: { - ...projectConfiguration.targets, - test: { - ...projectConfiguration.targets.test, - executor: '@nrwl/jest:jest', - }, - }, - }); - - updateJson(tree, 'package.json', (json) => { - json.devDependencies['jest'] = '27.1.1'; - json.devDependencies['jest-environment-jsdom'] = '27.1.1'; - return json; - }); - tree.write( - 'libs/my-lib/jest.config.ts', - ` -export default { - displayName: 'test-ng-app', - preset: '../../jest.preset.js', - setupFilesAfterEnv: ['/src/test-setup.ts'], - globals: { - 'ts-jest': { - useESM: true, - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\\\.(html|svg)$', - }, - }, - testEnvironment: 'jsdom', - testRunner: 'jest-jasmine2', - coverageDirectory: '../../coverage/apps/test-ng-app', - transform: { - '^.+\\\\.(ts|mjs|js|html)$': 'jest-preset-angular', - }, - transformIgnorePatterns: [ - 'node_modules/(?!.*\\\\.mjs$|rxjs)', - // 'node_modules/(?!rxjs)' - ], - snapshotSerializers: [ - 'jest-preset-angular/build/serializers/no-ng-attributes', - 'jest-preset-angular/build/serializers/ng-snapshot', - 'jest-preset-angular/build/serializers/html-comment', - ], -}` - ); - updateConfigsJest28(tree); - - const packageJson = readJson(tree, 'package.json'); - expect(packageJson.devDependencies).toEqual( - expect.objectContaining({ - 'jest-environment-jsdom': '28.1.1', - 'jest-jasmine2': '28.1.1', - }) - ); - }); -}); diff --git a/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.ts b/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.ts deleted file mode 100644 index ae25b9f963b6d..0000000000000 --- a/packages/jest/src/migrations/update-14-6-0/update-configs-jest-28.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { addDependenciesToPackageJson, readJson, Tree } from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { tsquery } from '@phenomnomnominal/tsquery'; -import { isStringLiteralLike, PropertyAssignment } from 'typescript'; -import { JestExecutorOptions } from '../../executors/jest/schema'; -import { - findRootJestConfig, - findRootJestPreset, -} from '../../utils/config/find-root-jest-files'; - -const jestVersion = '28.1.1'; - -const JASMINE_TEST_RUNNER = /(testRunner:\s*['"`])(jest-jasmine2)(['"`])/g; -const JSDOM_TEST_ENV = /(testEnvironment:\s*['"`])(jsdom)(['"`])/g; - -export function updateConfigsJest28(tree: Tree) { - let devDeps = checkDeps(tree); - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options) => { - if (options.jestConfig && tree.exists(options.jestConfig)) { - const updatedConfig = updateJestConfig( - tree.read(options.jestConfig, 'utf-8') - ); - - tree.write(options.jestConfig, updatedConfig); - - const projectConfigCheck = testFileForDep(updatedConfig); - devDeps = { ...devDeps, ...projectConfigCheck }; - } - } - ); - - return addDependenciesToPackageJson(tree, {}, devDeps); -} - -export function updateJestConfig(config: string): string { - let content = tsquery.replace( - config, - 'PropertyAssignment:has(Identifier[name="testURL"])', - (node: PropertyAssignment) => { - const value = node?.initializer?.getText(); - return `testEnvironmentOptions: {url: ${value}}`; - } - ); - - content = tsquery.replace( - content, - 'PropertyAssignment > Identifier[name="extraGlobals"]', - () => { - return 'sandboxInjectedGlobals'; - } - ); - - return tsquery.replace( - content, - 'PropertyAssignment:has(Identifier[name="timers"])', - (node: PropertyAssignment) => { - // must guard against non string properties as that means it's already been manually migrated - if (node?.initializer && isStringLiteralLike(node.initializer)) { - const value = node?.initializer.getText().trim() as - | 'fake' - | 'modern' - | 'real' - | 'legacy'; - - // use .includes to ignore the different quotes (' " `) - if (value.includes('fake') || value.includes('modern')) { - return `fakeTimers: { enableGlobally: true }`; - } - if (value.includes('real')) { - return `fakeTimers: { enableGlobally: false }`; - } - if (value.includes('legacy')) { - return `fakeTimers: { enableGlobally: true, legacyFakeTimers: true }`; - } - } - } - ); -} - -export function checkDeps(tree: Tree): Record { - const packageJson = readJson(tree, 'package.json'); - let devDeps = {}; - - if (packageJson.devDependencies['jest-preset-angular']) { - devDeps['jest-environment-jsdom'] = jestVersion; - } - - const rootJestConfig = findRootJestConfig(tree); - if (rootJestConfig) { - const rootConfigCheck = testFileForDep(tree.read(rootJestConfig, 'utf-8')); - devDeps = { ...devDeps, ...rootConfigCheck }; - } - - const rootJestPreset = findRootJestPreset(tree); - if (rootJestPreset) { - const rootPresetCheck = testFileForDep(tree.read(rootJestPreset, 'utf-8')); - devDeps = { ...devDeps, ...rootPresetCheck }; - } - - return devDeps; -} - -function testFileForDep(config: string): Record { - const deps = {}; - if (JASMINE_TEST_RUNNER.test(config)) { - deps['jest-jasmine2'] = jestVersion; - } - if (JSDOM_TEST_ENV.test(config)) { - deps['jest-environment-jsdom'] = jestVersion; - } - return deps; -} - -export default updateConfigsJest28; diff --git a/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts b/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts deleted file mode 100644 index 2b9c528498c58..0000000000000 --- a/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.spec.ts +++ /dev/null @@ -1,346 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { libraryGenerator as workspaceLib } from '@nx/js'; -import { - readProjectConfiguration, - updateProjectConfiguration, -} from 'nx/src/generators/utils/project-configuration'; -import { - updateJestFnMocks, - updateJestImports, - updateJestTimers, - updateTestsJest28, -} from './update-tests-jest-28'; - -describe('Jest Migration - jest 28 test files', () => { - it('should convert test files', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await workspaceLib(tree, { - name: 'blah', - linter: undefined, - unitTestRunner: 'jest', - }); - const projectConfiguration = readProjectConfiguration(tree, 'blah'); - updateProjectConfiguration(tree, 'blah', { - ...projectConfiguration, - targets: { - ...projectConfiguration.targets, - test: { - ...projectConfiguration.targets.test, - executor: '@nrwl/jest:jest', - }, - }, - }); - - await workspaceLib(tree, { - name: 'blah-again', - linter: undefined, - unitTestRunner: 'jest', - js: true, - }); - const projectConfiguration2 = readProjectConfiguration(tree, 'blah-again'); - updateProjectConfiguration(tree, 'blah-again', { - ...projectConfiguration2, - targets: { - ...projectConfiguration2.targets, - test: { - ...projectConfiguration2.targets.test, - executor: '@nrwl/jest:jest', - }, - }, - }); - - tree.write( - 'libs/blah/src/lib/something/something.spec.ts', - ` - import expect from 'expect'; - import { something } from './something'; - import { jest } from '@jest/globals'; - describe('my cool test', () => { - it('should do something', () => { - jest.useFakeTimers('modern') - const mock = jest.fn, Parameters>(); - expect(something()).toBe(true) - }) - it('should do something pt 2', () => { - jest.useFakeTimers('legacy') - const mock = jest.fn(); - expect(something()).toBe(true) - }) - it('should do something', () => { - const mock = jest.fn, []>(); - expect(something()).toBe(true) - }) - })` - ); - - tree.write( - 'libs/blah/src/lib/something/another.spec.ts', - ` - import expect from 'expect'; - import { something } from './something'; - describe('my cool test', () => { - it('should do something', () => { - jest.useFakeTimers('modern') - const mock = jest.fn, Parameters>(); - expect(something()).toBe(true) - }) - it('should do something pt 2', () => { - jest.useFakeTimers('legacy') - const mock = jest.fn(); - expect(something()).toBe(true) - }) - it('should do something', () => { - const mock = jest.fn, []>(); - expect(something()).toBe(true) - }) - })` - ); - const pc = readProjectConfiguration(tree, 'blah'); - pc.targets['test'].configurations = { - production: { - ...pc.targets['test'].options, - ci: true, - }, - }; - pc.targets['another-config'] = pc.targets['test']; - updateProjectConfiguration(tree, 'blah', pc); - - updateTestsJest28(tree); - - expect(tree.read('libs/blah/src/lib/something/something.spec.ts', 'utf-8')) - .toEqual(` - import { expect } from 'expect'; - import { something } from './something'; - import { jest } from '@jest/globals'; - describe('my cool test', () => { - it('should do something', () => { - jest.useFakeTimers() - const mock = jest.fn(); - expect(something()).toBe(true) - }) - it('should do something pt 2', () => { - jest.useFakeTimers({ legacyFakeTimers: true }) - const mock = jest.fn<() => boolean>(); - expect(something()).toBe(true) - }) - it('should do something', () => { - const mock = jest.fn<() => Promise<{}>>(); - expect(something()).toBe(true) - }) - })`); - expect(tree.read('libs/blah/src/lib/something/another.spec.ts', 'utf-8')) - .toEqual(` - import { expect } from 'expect'; - import { something } from './something'; - describe('my cool test', () => { - it('should do something', () => { - jest.useFakeTimers() - const mock = jest.fn, Parameters>(); - expect(something()).toBe(true) - }) - it('should do something pt 2', () => { - jest.useFakeTimers({ legacyFakeTimers: true }) - const mock = jest.fn(); - expect(something()).toBe(true) - }) - it('should do something', () => { - const mock = jest.fn, []>(); - expect(something()).toBe(true) - }) - })`); - }); - - it('should update ts-jest/utils to jest-mock', () => { - // import { mocked } from 'ts-jest/utils' => import { mocked } from 'jest-mock'; - // const { mocked } = require('ts-jest/utils'); => const { mocked } = require('jest-mock'); - - const actual = updateJestImports(` - import { mocked } from 'ts-jest/utils'; - import { somethingElse } from 'ts-jest/utils'; - const { mocked } = require('ts-jest/utils'); - const { somethingElse } = require('ts-jest/utils'); - import * from ts from 'typescript' - const mockTs = mocked(ts); - - describe('something expected', () => { - it('should do something', () => { - const actual = somethingExpected('abc'); - expect(1 + 1).toBe(2); - }); - }) - `); - - const expected = ` - import { mocked } from 'jest-mock'; - import { somethingElse } from 'ts-jest/utils'; - const { mocked } = require('jest-mock'); - const { somethingElse } = require('ts-jest/utils'); - import * from ts from 'typescript' - const mockTs = mocked(ts); - - describe('something expected', () => { - it('should do something', () => { - const actual = somethingExpected('abc'); - expect(1 + 1).toBe(2); - }); - }) - `; - expect(actual).toEqual(expected); - }); - it('should update "expect" default import to named import', () => { - // import expect from 'expect' => import { expect } from 'expect' - // const expect = require('expect') => const { expect } = require('expect') - const actual = updateJestImports(` - import expect from 'expect'; - const expect = require('expect'); - const expect = require('something-else'); - import somethingExpected from 'my-expect'; - - describe('something expected', () => { - it('should do something', () => { - const actual = somethingExpected('abc'); - expect(1 + 1).toBe(2); - }); - }) - `); - - const expected = ` - import { expect } from 'expect'; - const { expect } = require('expect'); - const expect = require('something-else'); - import somethingExpected from 'my-expect'; - - describe('something expected', () => { - it('should do something', () => { - const actual = somethingExpected('abc'); - expect(1 + 1).toBe(2); - }); - }) - `; - expect(actual).toEqual(expected); - }); - - it('should update jest.useFakeTimers() to new timer api', () => { - const actual = updateJestTimers( - ` - describe('some test', () => { - it('should do something', () => { - jest.useFakeTimers('modern') - }) - - it('should do something else', () => { - jest.useFakeTimers('legacy') - }) - }) - `, - false - ); - - expect(actual).not.toContain("jest.useFakeTimers('modern')"); - expect(actual).not.toContain("jest.useFakeTimers('legacy')"); - expect(actual).toContain('jest.useFakeTimers()'); - expect(actual).toContain('jest.useFakeTimers({ legacyFakeTimers: true })'); - }); - - it('should update jest timers to new timer api w/legacy timers set in config', () => { - const actual = updateJestTimers( - ` - describe('some test', () => { - it('should do something', () => { - jest.useFakeTimers('modern') - }) - - it('should do something else', () => { - jest.useFakeTimers('legacy') - }) - }) - `, - true - ); - // jest.useFakeTimers('modern') -> jest.useFakeTimers() - // jest.useFakeTimers('legacy') -> jest.useFakeTimers({legacyFakeTimers: true}) - // if legacyFakeTimers is true in config, then - // jest.useFakeTimers('modern') -> jest.useRealTimers({legacyFakeTimers: false}) - expect(actual).toEqual(` - describe('some test', () => { - it('should do something', () => { - jest.useRealTimers({ legacyFakeTimers: false }) - }) - - it('should do something else', () => { - jest.useFakeTimers({ legacyFakeTimers: true }) - }) - }) - `); - }); - - it('should update jest.fn usage', () => { - const actual = updateJestFnMocks(` - import add from './add'; - describe('something', () => { - it('should do something', () => { - const noTypedMockAdd = jest.fn(); - }) - it('should do something', () => { - const asyncMock = jest.fn, []>() - }) - it('should do something', () => { - const mock = jest.fn() - }) - it('should do something', () => { - const mockAdd = jest.fn, Parameters>(); - }) - }) - `); - - expect(actual).not.toContain( - 'jest.fn, Parameters>()' - ); - expect(actual).toContain('jest.fn()'); - expect(actual).not.toContain('jest.fn()'); - expect(actual).toContain('jest.fn<() => number>()'); - expect(actual).not.toContain('jest.fn, []>()'); - expect(actual).toContain('jest.fn<() => Promise>()'); - }); - - it('should leave a TODO comment if it does not know how to upgrade', () => { - const actual = updateJestFnMocks(` - import add from './add'; - describe('something', () => { - it('should do something', () => { - const noTypedMockAdd = jest.fn(); - }) - }) - `); - - expect(actual).toContain( - '/** TODO: Update jest.fn() type args for Jest v28 https://jestjs.io/docs/upgrading-to-jest28#jestfn */ jest.fn();' - ); - }); - - it('should not touch already migrate jest.fn usage', () => { - const original = ` - import add from './add'; - describe('something', () => { - it('should do something', () => { - const noTypedMockAdd = jest.fn(); - }) - it('should do something', () => { - const asyncMock = jest.fn<() => number>>() - }) - it('should do something', () => { - const mock = jest.fn<() => Promise>() - }) - it('should do something', () => { - const mockAdd = jest.fn(); - }) - }) - `; - const actual = updateJestFnMocks(original); - - expect(actual).toEqual(original); - expect(actual).not.toContain( - '/** TODO: Update jest.fn() types for Jest v28 https://jestjs.io/docs/upgrading-to-jest28#jestfn' - ); - }); -}); diff --git a/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.ts b/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.ts deleted file mode 100644 index 9642607b56a89..0000000000000 --- a/packages/jest/src/migrations/update-14-6-0/update-tests-jest-28.ts +++ /dev/null @@ -1,202 +0,0 @@ -import { - readProjectConfiguration, - Tree, - visitNotIgnoredFiles, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { tsquery } from '@phenomnomnominal/tsquery'; -import * as ts from 'typescript'; -import { JestExecutorOptions } from '../../executors/jest/schema'; - -export function updateTestsJest28(tree: Tree) { - const testFilePatterns = /.*.(spec|test)\.(ts|js)x?/g; - const legacyTimers = - /(timers:\s*['"`]legacy['"`])|(legacyFakeTimers:\s*true)/g; - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, projectName) => { - const projectConfig = readProjectConfiguration(tree, projectName); - - const isUsingLegacyTimers = - options.jestConfig && - tree.exists(options.jestConfig) && - legacyTimers.test(tree.read(options.jestConfig, 'utf-8')); - - visitNotIgnoredFiles(tree, projectConfig.root, (filePath) => { - if (!filePath.match(testFilePatterns)) { - return; - } - let fileContent = tree.read(filePath, 'utf-8'); - fileContent = updateJestTimers(fileContent, isUsingLegacyTimers); - - if (fileContent.includes('@jest/globals')) { - fileContent = updateJestFnMocks(fileContent); - } - - fileContent = updateJestImports(fileContent); - - tree.write(filePath, fileContent); - }); - } - ); -} - -/** - * jest.useFakeTimers('modern') -> jest.useFakeTimers() - * jest.useFakeTimers('legacy') -> jest.useFakeTimers({legacyFakeTimers: true}) - * if legacyFakeTimers is true in config, then - * jest.useFakeTimers('modern') -> jest.useRealTimers({legacyFakeTimers: false}) - */ -export function updateJestTimers( - fileContents: string, - legacyFakeTimersInConfig: boolean -) { - return tsquery.replace( - fileContents, - 'CallExpression', - (node: ts.StringLiteral) => { - if (!node?.getText().startsWith('jest.useFakeTimers')) { - return; - } - - const timerType = node.getText(); - // will be modern or legacy with quotes - // just make sure it's included to ignore different quote types - if (timerType.includes('legacy')) { - return 'jest.useFakeTimers({ legacyFakeTimers: true })'; - } - if (legacyFakeTimersInConfig) { - // using modern but have config set to legacy - return 'jest.useRealTimers({ legacyFakeTimers: false })'; - } - // have to include space otherwise empty string will not remove the string literal - return 'jest.useFakeTimers()'; - } - ); -} - -/** - * make sure using jest.fn - */ -function isTypedJestFnMock(node: ts.CallExpression): boolean { - return ts.isCallExpression(node) && node.getText().startsWith('jest.fn<'); -} - -/** - * has 2 args where the second is a tuple or array - * i.e. - * jest.fn, []>() - * jest.fn() - * jest.fn() - */ -function isValid2Args(node: ts.CallExpression): boolean { - const r = - node?.typeArguments.length === 2 && - (node.typeArguments[1]?.kind === ts.SyntaxKind.TupleType || - node.typeArguments[1]?.kind === ts.SyntaxKind.ArrayType); - return r; -} - -/** - * has 1 arg where the type is NOT a FunctionType - * if it's a function type then it's already using the correct syntax - * i.e. - * jest.fn() - * jest.fn<() => Promise>() is already valid, don't change it. - */ -function isValid1Arg(node: ts.CallExpression): boolean { - const r = - node?.typeArguments.length === 1 && - node.typeArguments[0]?.kind !== ts.SyntaxKind.FunctionType && - node.typeArguments[0]?.kind !== ts.SyntaxKind.TypeQuery; - return r; -} - -/** - * has a type reference as a type args - * jest.fn, Parameters>(); - */ -function isValidTypeRef(node: ts.CallExpression): boolean { - const r = - node.typeArguments[0].kind === ts.SyntaxKind.TypeReference && - !!(node.typeArguments?.[0] as ts.TypeReferenceNode)?.typeArguments; - return r; -} - -/** - * has valid type args. prevent converting an already converted jest.fn() - */ -function isValidType(node: ts.CallExpression): boolean { - const r = - node?.typeArguments.length === 1 && - (node.typeArguments[0]?.kind === ts.SyntaxKind.FunctionType || - node.typeArguments[0]?.kind === ts.SyntaxKind.TypeReference || - node.typeArguments[0]?.kind === ts.SyntaxKind.TypeQuery || - node.parent.getText().includes('/** TODO:')); // has already been marked by a previous run. - return r; -} - -/** - * this only applies to tests using @jest/globals - * jest.fn, []>() -> jest.fn<() => Promise>() - * jest.fn() -> jest.fn<() => number>() - * jest.fn, Parameters>(); -> jest.fn() - */ -export function updateJestFnMocks(fileContents: string): string { - return tsquery.replace( - fileContents, - 'CallExpression', - (node: ts.CallExpression) => { - if (!isTypedJestFnMock(node) || isValidType(node)) { - return; - } - - if (isValid2Args(node) || isValid1Arg(node)) { - return `${ - node.getText().split('<')[0] - }<() => ${node.typeArguments[0].getText()}>()`; - } - - if (isValidTypeRef(node)) { - const innerType = (node.typeArguments[0] as ts.TypeReferenceNode) - .typeArguments; - return `${node.getText().split('<')[0]}<${innerType[0].getText()}>()`; - } - - return `/** TODO: Update jest.fn() type args for Jest v28 https://jestjs.io/docs/upgrading-to-jest28#jestfn */ ${node.getText()}`; - } - ); -} - -/** - * import expect from 'expect' -> import { expect } from 'expect' - * const expect = require('expect') -> const { expect } = require('expect') - * import { mocked } from 'ts-jest/utils' => import { mocked } from 'jest-mock'; - * const { mocked } = require('ts-jest/utils'); => const { mocked } = require('jest-mock'); - */ -export function updateJestImports(content: string): string { - const mockUpdatedImports = tsquery.replace( - content, - ':matches(ImportDeclaration:has(Identifier[name="mocked"]) StringLiteral[value="ts-jest/utils"], VariableStatement:has(Identifier[name="mocked"]) StringLiteral[value="ts-jest/utils"])', - () => { - return "'jest-mock'"; - } - ); - - return tsquery.replace( - mockUpdatedImports, - ':matches(ImportDeclaration:has(StringLiteral[value="expect"]), VariableDeclaration:has(StringLiteral[value="expect"]))', - (node: ts.ImportDeclaration | ts.VariableDeclaration) => { - if (ts.isImportDeclaration(node)) { - return `import { expect } from 'expect';`; - } - if (ts.isVariableDeclaration(node)) { - return `{ expect } = require('expect')`; // this query doesn't capture the ; so we don't need to add it in the replace. - } - return; - } - ); -} - -export default updateTestsJest28; diff --git a/packages/js/migrations.json b/packages/js/migrations.json index 257390ded43b4..a30667009afbc 100644 --- a/packages/js/migrations.json +++ b/packages/js/migrations.json @@ -1,35 +1,5 @@ { "generators": { - "update-node-executor": { - "cli": "nx", - "version": "13.8.5-beta.1", - "description": "Renames @nrwl/js:node to @nrwl/node:node", - "factory": "./src/migrations/update-13-8-5/update-node-executor" - }, - "update-swcrc": { - "cli": "nx", - "version": "13.8.5-beta.1", - "description": "Adjust .swcrc to .lib.swcrc", - "factory": "./src/migrations/update-13-8-5/update-swcrc" - }, - "update-swcrc-exclude": { - "cli": "nx", - "version": "13.10.1-beta.1", - "description": "Update .lib.swcrc to exclude missing test files", - "factory": "./src/migrations/update-13-10-1/update-lib-swcrc-exclude" - }, - "exclude-jest-config-swcrc": { - "cli": "nx", - "version": "14.0.0-beta.2", - "description": "Exclude jest config from .lib.swcrc", - "factory": "./src/migrations/update-14-0-0/exclude-jest-config-swcrc" - }, - "update-swcrc-path": { - "cli": "nx", - "version": "14.1.5-beta.0", - "description": "Rename option swcrcPath to swcrc, and resolve relative to workspace root", - "factory": "./src/migrations/update-14-1-5/update-swcrc-path" - }, "rename-swcrc-config": { "cli": "nx", "version": "15.8.0-beta.0", diff --git a/packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap b/packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap deleted file mode 100644 index 0406607c8e0c6..0000000000000 --- a/packages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap +++ /dev/null @@ -1,36 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Update .lib.swcrc exclude should update the exclude pattern 1`] = ` -"{ - "jsc": { - "target": "es2017", - "parser": { - "syntax": "typescript", - "decorators": true, - "dynamicImport": true - }, - "transform": { - "decoratorMetadata": true, - "legacyDecorator": true - }, - "keepClassNames": true, - "externalHelpers": true, - "loose": true - }, - "module": { - "type": "commonjs", - "strict": true, - "noInterop": true - }, - "sourceMaps": true, - "exclude": [ - "jest.config.ts", - ".*\\\\.spec.tsx?$", - ".*\\\\.test.tsx?$", - "./src/jest-setup.ts$", - "./**/jest-setup.ts$", - ".*.js$" - ] -} -" -`; diff --git a/packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.spec.ts b/packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.spec.ts deleted file mode 100644 index 298160acb64e8..0000000000000 --- a/packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.spec.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { - addProjectConfiguration, - ProjectConfiguration, - readJson, - Tree, - updateJson, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import updateSwcRcExclude from './update-lib-swcrc-exclude'; - -const projectConfig: ProjectConfiguration = { - root: 'libs/swc-lib', - sourceRoot: 'libs/swc-lib/src', - targets: { - build: { - executor: '@nrwl/js:swc', - outputs: ['{options.outputPath}'], - options: { - outputPath: 'dist/libs/swc-lib', - main: 'libs/swc-lib/src/index.ts', - tsConfig: 'libs/swc-lib/tsconfig.lib.json', - assets: ['libs/swc-lib/*.md'], - }, - }, - }, -}; -const oldSwcRc = { - jsc: { - target: 'es2017', - parser: { - syntax: 'typescript', - decorators: true, - dynamicImport: true, - }, - transform: { - decoratorMetadata: true, - legacyDecorator: true, - }, - keepClassNames: true, - externalHelpers: true, - loose: true, - }, - module: { - type: 'commonjs', - strict: true, - noInterop: true, - }, - sourceMaps: true, - exclude: [ - './src/**/.*.spec.ts$', - './**/.*.spec.ts$', - './src/**/jest-setup.ts$', - './**/jest-setup.ts$', - './**/.*.js$', - ], -}; -describe('Update .lib.swcrc exclude', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'swc-lib', projectConfig); - - tree.write('libs/swc-lib/.lib.swcrc', JSON.stringify(oldSwcRc)); - }); - - it('should update the exclude pattern', () => { - updateSwcRcExclude(tree); - expect(tree.read('libs/swc-lib/.lib.swcrc', 'utf-8')).toMatchSnapshot(); - }); - - it('should NOT update the exclude pattern if not present', () => { - updateJson(tree, 'libs/swc-lib/.lib.swcrc', (json) => { - delete json.exclude; - return json; - }); - - const before = readJson(tree, 'libs/swc-lib/.lib.swcrc'); - updateSwcRcExclude(tree); - const after = readJson(tree, 'libs/swc-lib/.lib.swcrc'); - - expect(after.exclude).toBeFalsy(); - expect(after).toEqual(before); - }); - - it('should do nothing if .lib.swcrc doest not exist', () => { - tree.delete('libs/swc-lib/.lib-swcrc'); - - expect(() => updateSwcRcExclude(tree)).not.toThrowError(); - }); -}); diff --git a/packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.ts b/packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.ts deleted file mode 100644 index 730a52a812c72..0000000000000 --- a/packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { readProjectConfiguration, Tree, updateJson } from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { join } from 'path'; -import { SwcExecutorOptions } from '../../utils/schema'; -import { defaultExclude } from '../../utils/swc/add-swc-config'; - -export default function updateSwcRcExclude(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/js:swc', - (config: SwcExecutorOptions, projectName) => { - const projectConfig = readProjectConfiguration(tree, projectName); - const libSwcPath = join(projectConfig.root, '.lib.swcrc'); - - if (!tree.exists(libSwcPath)) return; - - updateJson( - tree, - libSwcPath, - (json) => { - if (json.exclude) { - const excludePatterns = new Set([ - ...defaultExclude, - ...json.exclude, - ]); - // remove old patterns that are duplicate for new patterns - // defined in defaultExclude - excludePatterns.delete('./**/.*.spec.ts$'); - excludePatterns.delete('./src/**/.*.spec.ts$'); - excludePatterns.delete('./**/.*.js$'); - excludePatterns.delete('./src/**/jest-setup.ts$'); - - json.exclude = [...excludePatterns]; - } - return json; - }, - { expectComments: true } - ); - } - ); -} diff --git a/packages/js/src/migrations/update-13-8-5/update-node-executor.spec.ts b/packages/js/src/migrations/update-13-8-5/update-node-executor.spec.ts deleted file mode 100644 index fec61feeb330f..0000000000000 --- a/packages/js/src/migrations/update-13-8-5/update-node-executor.spec.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './update-node-executor'; - -describe('Migration: rename execute to node', () => { - it(`should rename the "execute" executor to "node"`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - serve: { - executor: '@nrwl/js:node', - options: {}, - }, - }, - }); - - const tasks = await update(tree); - - expect(tasks).toBeDefined(); - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - serve: { - executor: '@nrwl/node:node', - options: {}, - }, - }, - }); - }); - - it(`should skip migration if no projects use @nrwl/js:node`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'workspace.json', - JSON.stringify({ - version: 2, - projects: {}, - }) - ); - - const tasks = await update(tree); - - expect(tasks).toBeUndefined(); - }); -}); diff --git a/packages/js/src/migrations/update-13-8-5/update-node-executor.ts b/packages/js/src/migrations/update-13-8-5/update-node-executor.ts deleted file mode 100644 index aaed56cd4afbb..0000000000000 --- a/packages/js/src/migrations/update-13-8-5/update-node-executor.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { - addDependenciesToPackageJson, - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { nxVersion } from '@nx/workspace/src/utils/versions'; - -export default async function update(host: Tree) { - const projects = getProjects(host); - let installNeeded = false; - - for (const [name, config] of projects.entries()) { - if (config?.targets?.serve?.executor !== '@nrwl/js:node') continue; - - config.targets.serve.executor = '@nrwl/node:node'; - - installNeeded = true; - updateProjectConfiguration(host, name, config); - } - - const task = installNeeded - ? addDependenciesToPackageJson( - host, - {}, - { - '@nrwl/node': nxVersion, - } - ) - : undefined; - - await formatFiles(host); - - return task; -} diff --git a/packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts b/packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts deleted file mode 100644 index 27f551662ae88..0000000000000 --- a/packages/js/src/migrations/update-13-8-5/update-swcrc.spec.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { - ProjectConfiguration, - readJson, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { libraryGenerator } from '../../generators/library/library'; -import { defaultExclude } from '../../utils/swc/add-swc-config'; -import update from './update-swcrc'; - -describe('Migration: adjust .swcrc', () => { - let tree: Tree; - let projectConfiguration: ProjectConfiguration; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await libraryGenerator(tree, { - name: 'swc', - buildable: true, - linter: 'none', - unitTestRunner: 'none', - }); - projectConfiguration = readProjectConfiguration(tree, 'swc'); - updateProjectConfiguration(tree, 'swc', { - ...projectConfiguration, - targets: { - ...projectConfiguration.targets, - build: { - ...projectConfiguration.targets['build'], - executor: '@nrwl/js:swc', - }, - }, - }); - // re-read the project configuration - projectConfiguration = readProjectConfiguration(tree, 'swc'); - }); - - it('should rename .swcrc to .lib.swcrc', async () => { - addSwcrc(); - await update(tree); - - expect(tree.exists('libs/swc/.swcrc')).toEqual(false); - expect(tree.exists('libs/swc/.lib.swcrc')).toEqual(true); - }); - - it('should assign default exclude if swcrc does not already have exclude', async () => { - addSwcrc(); - await update(tree); - - expect(readJson(tree, 'libs/swc/.lib.swcrc')['exclude']).toEqual( - defaultExclude - ); - }); - - it('should use swcExclude (deprecated) to assign to exclude', async () => { - const swcExclude = ['./src/**/.*.spec.ts$']; - updateProjectConfiguration(tree, 'swc', { - ...projectConfiguration, - targets: { - ...projectConfiguration.targets, - build: { - ...projectConfiguration.targets['build'], - options: { - ...projectConfiguration.targets['build']['options'], - swcExclude, - }, - }, - }, - }); - - addSwcrc(); - await update(tree); - - expect(readJson(tree, 'libs/swc/.lib.swcrc')['exclude']).toEqual( - swcExclude - ); - }); - - it('should skip updating "exclude" if swcrc already has "exclude" field', async () => { - addSwcrc(true); - await update(tree); - expect(readJson(tree, 'libs/swc/.lib.swcrc')['exclude']).toEqual([ - './**/.*.spec.ts$', - ]); - }); - - function addSwcrc(withExclude = false) { - tree.write( - 'libs/swc/.swcrc', - JSON.stringify(withExclude ? { exclude: ['./**/.*.spec.ts$'] } : {}) - ); - } -}); diff --git a/packages/js/src/migrations/update-13-8-5/update-swcrc.ts b/packages/js/src/migrations/update-13-8-5/update-swcrc.ts deleted file mode 100644 index 1cff15514bf92..0000000000000 --- a/packages/js/src/migrations/update-13-8-5/update-swcrc.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - formatFiles, - getProjects, - readJson, - Tree, - updateJson, -} from '@nx/devkit'; -import { join } from 'path'; -import { defaultExclude } from '../../utils/swc/add-swc-config'; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const config of projects.values()) { - if (config?.targets?.build?.executor !== '@nrwl/js:swc') continue; - - const swcrcPath = join(config.root, '.swcrc'); - if (!host.exists(swcrcPath)) continue; - - // rename - const libSwcrcPath = join(config.root, '.lib.swcrc'); - host.rename(swcrcPath, libSwcrcPath); - - const swcrcContent = readJson(host, libSwcrcPath); - - // skip if swcrc already has "exclude" field - if (swcrcContent['exclude']) continue; - - // check swcExclude build options - const exclude = - config?.targets?.build?.options?.['swcExclude'] || defaultExclude; - updateJson(host, libSwcrcPath, (swcrc) => { - swcrc['exclude'] = exclude; - return swcrc; - }); - } - - await formatFiles(host); -} diff --git a/packages/js/src/migrations/update-14-0-0/__snapshots__/exclude-jest-config-swcrc.spec.ts.snap b/packages/js/src/migrations/update-14-0-0/__snapshots__/exclude-jest-config-swcrc.spec.ts.snap deleted file mode 100644 index 6b0200b138169..0000000000000 --- a/packages/js/src/migrations/update-14-0-0/__snapshots__/exclude-jest-config-swcrc.spec.ts.snap +++ /dev/null @@ -1,36 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`JS Migration (v14.0.0) should update the exclude pattern 1`] = ` -"{ - "jsc": { - "target": "es2017", - "parser": { - "syntax": "typescript", - "decorators": true, - "dynamicImport": true - }, - "transform": { - "decoratorMetadata": true, - "legacyDecorator": true - }, - "keepClassNames": true, - "externalHelpers": true, - "loose": true - }, - "module": { - "type": "commonjs", - "strict": true, - "noInterop": true - }, - "sourceMaps": true, - "exclude": [ - "jest.config.js", - ".*.spec.tsx?$", - ".*.test.tsx?$", - "./src/jest-setup.ts$", - "./**/jest-setup.ts$", - ".*.js$" - ] -} -" -`; diff --git a/packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.spec.ts b/packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.spec.ts deleted file mode 100644 index c253e07445754..0000000000000 --- a/packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.spec.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { - addProjectConfiguration, - readJson, - Tree, - updateJson, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { excludeJestConfigSwcrc } from './exclude-jest-config-swcrc'; -import { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json'; - -const projectConfig: ProjectConfiguration = { - root: 'libs/swc-lib', - sourceRoot: 'libs/swc-lib/src', - targets: { - build: { - executor: '@nrwl/js:swc', - outputs: ['{options.outputPath}'], - options: { - outputPath: 'dist/libs/swc-lib', - main: 'libs/swc-lib/src/index.ts', - tsConfig: 'libs/swc-lib/tsconfig.lib.json', - assets: ['libs/swc-lib/*.md'], - }, - }, - }, -}; -const oldSwcRc = { - jsc: { - target: 'es2017', - parser: { - syntax: 'typescript', - decorators: true, - dynamicImport: true, - }, - transform: { - decoratorMetadata: true, - legacyDecorator: true, - }, - keepClassNames: true, - externalHelpers: true, - loose: true, - }, - module: { - type: 'commonjs', - strict: true, - noInterop: true, - }, - sourceMaps: true, - exclude: [ - '.*.spec.tsx?$', - '.*.test.tsx?$', - './src/jest-setup.ts$', - './**/jest-setup.ts$', - '.*.js$', - ], -}; -describe('JS Migration (v14.0.0)', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'swc-lib', projectConfig); - - tree.write('libs/swc-lib/.lib.swcrc', JSON.stringify(oldSwcRc)); - }); - - it('should update the exclude pattern', () => { - excludeJestConfigSwcrc(tree); - expect(tree.read('libs/swc-lib/.lib.swcrc', 'utf-8')).toMatchSnapshot(); - }); - - it('should NOT update the exclude pattern if not present', () => { - updateJson(tree, 'libs/swc-lib/.lib.swcrc', (json) => { - delete json.exclude; - return json; - }); - - const before = readJson(tree, 'libs/swc-lib/.lib.swcrc'); - excludeJestConfigSwcrc(tree); - const after = readJson(tree, 'libs/swc-lib/.lib.swcrc'); - - expect(after.exclude).toBeFalsy(); - expect(after).toEqual(before); - }); - - it('should do nothing if .lib.swcrc doest not exist', () => { - tree.delete('libs/swc-lib/.lib-swcrc'); - expect(() => excludeJestConfigSwcrc(tree)).not.toThrowError(); - }); -}); diff --git a/packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.ts b/packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.ts deleted file mode 100644 index 28d5472ea31b5..0000000000000 --- a/packages/js/src/migrations/update-14-0-0/exclude-jest-config-swcrc.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { readProjectConfiguration, Tree, updateJson } from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { SwcExecutorOptions } from '../../utils/schema'; -import { join } from 'path'; - -export function excludeJestConfigSwcrc(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/js:swc', - (config: SwcExecutorOptions, projectName) => { - const projectConfig = readProjectConfiguration(tree, projectName); - const libSwcPath = join(projectConfig.root, '.lib.swcrc'); - - if (!tree.exists(libSwcPath)) return; - - updateJson( - tree, - libSwcPath, - (json) => { - if (json.exclude) { - const excludePatterns = new Set([ - 'jest.config.js', - ...json.exclude, - ]); - json.exclude = [...excludePatterns]; - } - return json; - }, - { expectComments: true } - ); - } - ); -} - -export default excludeJestConfigSwcrc; diff --git a/packages/js/src/migrations/update-14-1-5/update-swcrc-path.spec.ts b/packages/js/src/migrations/update-14-1-5/update-swcrc-path.spec.ts deleted file mode 100644 index c51122232e78e..0000000000000 --- a/packages/js/src/migrations/update-14-1-5/update-swcrc-path.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import updateSwcrcPath from './update-swcrc-path'; - -describe('update-swcrc-path migration', () => { - it('should replace relative `swcrcPath` option with absolute `swcrc`', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'test-package', { - root: 'packages/test-package', - targets: { - build: { - executor: '@nrwl/js:swc', - options: { - swcrcPath: 'config/swcrc.json', - somethingThatShouldNotBeRemoved: true, - }, - }, - }, - }); - - await updateSwcrcPath(tree); - - const { targets, root } = readProjectConfiguration(tree, 'test-package'); - expect(root).toBe('packages/test-package'); - expect(targets.build.options.somethingThatShouldNotBeRemoved).toBeDefined(); - expect(targets.build.options.swcrcPath).toBeUndefined(); - expect(targets.build.options.swcrc).toBe( - 'packages/test-package/config/swcrc.json' - ); - }); -}); diff --git a/packages/js/src/migrations/update-14-1-5/update-swcrc-path.ts b/packages/js/src/migrations/update-14-1-5/update-swcrc-path.ts deleted file mode 100644 index 3c8f810659c25..0000000000000 --- a/packages/js/src/migrations/update-14-1-5/update-swcrc-path.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - formatFiles, - joinPathFragments, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { SwcExecutorOptions } from '../../utils/schema'; - -type OldSwcExecutorOptions = SwcExecutorOptions & { swcrcPath?: string }; - -export async function updateSwcrcPath(tree: Tree) { - let changesMade = false; - - forEachExecutorOptions( - tree, - '@nrwl/js:swc', - (_, projectName, targetName, configurationName) => { - const projectConfig = readProjectConfiguration(tree, projectName); - const executorOptions: OldSwcExecutorOptions = configurationName - ? projectConfig.targets[targetName].configurations[configurationName] - : projectConfig.targets[targetName].options; - - if (!executorOptions.swcrcPath) return; - - const newSwcrcPath = joinPathFragments( - projectConfig.root, - executorOptions.swcrcPath - ); - - delete executorOptions.swcrcPath; - executorOptions.swcrc = newSwcrcPath; - - updateProjectConfiguration(tree, projectName, projectConfig); - - changesMade = true; - } - ); - - if (changesMade) { - await formatFiles(tree); - } -} - -export default updateSwcrcPath; diff --git a/packages/linter/migrations.json b/packages/linter/migrations.json index a8f39d348116d..37d7fc4b923bc 100644 --- a/packages/linter/migrations.json +++ b/packages/linter/migrations.json @@ -1,53 +1,5 @@ { "generators": { - "remove-eslint-project-config-if-no-type-checking-rules": { - "cli": "nx", - "version": "12.4.0-beta.0", - "description": "Remove ESLint parserOptions.project config if no rules requiring type-checking are in use", - "factory": "./src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules" - }, - "add-outputs": { - "cli": "nx", - "version": "12.9.0-beta.0", - "description": "Add outputs for caching", - "factory": "./src/migrations/update-12-9-0/add-outputs" - }, - "remove-eslint-project-config-if-no-type-checking-rules-again": { - "cli": "nx", - "version": "12.9.0-beta.0", - "description": "Remove ESLint parserOptions.project config if no rules requiring type-checking are in use", - "factory": "./src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules" - }, - "eslint-8-updates": { - "cli": "nx", - "version": "13.3.0-beta.0", - "description": "Update eslint-rules jest.config.js in order to support ESLint v8 exports mapping, remove category field", - "factory": "./src/migrations/update-13-3-0/eslint-8-updates" - }, - "add-swc-deps": { - "cli": "nx", - "version": "14.1.9-beta.0", - "description": "Adds @swc/core and @swc-node as a dev dep if you are using them", - "factory": "./src/migrations/update-14-1-9/add-swc-deps-if-needed" - }, - "add-swc-deps-again": { - "cli": "nx", - "version": "14.2.3-beta.0", - "description": "Adds @swc/core and @swc-node as a dev dep if you are using them (repeated due to prior mistake)", - "factory": "./src/migrations/update-14-1-9/add-swc-deps-if-needed" - }, - "experimental-to-utils-deps": { - "cli": "nx", - "version": "14.4.4", - "description": "Adds @typescript-eslint/utils as a dev dep", - "factory": "./src/migrations/update-14-4-4/experimental-to-utils-deps" - }, - "experimental-to-utils-rules": { - "cli": "nx", - "version": "14.4.4", - "description": "Switch from @typescript-eslint/experimental-utils to @typescript-eslint/utils in all rules and rules.spec files", - "factory": "./src/migrations/update-14-4-4/experimental-to-utils-rules" - }, "add-eslint-inputs": { "cli": "nx", "version": "15.0.0-beta.0", @@ -73,166 +25,6 @@ } }, "packageJsonUpdates": { - "12.6.0": { - "version": "12.6.0-beta.8", - "packages": { - "@typescript-eslint/parser": { - "version": "~4.28.0" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~4.28.0" - } - } - }, - "12.10.0": { - "version": "12.10.0-beta.1", - "packages": { - "@typescript-eslint/parser": { - "version": "~4.31.1" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~4.31.1" - }, - "@typescript-eslint/experimental-utils": { - "version": "~4.31.1" - } - } - }, - "13.0.0": { - "version": "12.10.0", - "packages": { - "@typescript-eslint/parser": { - "version": "~4.33.0" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~4.33.0" - }, - "@typescript-eslint/experimental-utils": { - "version": "~4.33.0" - }, - "eslint": { - "version": "7.32.0" - } - } - }, - "13.3.0": { - "version": "13.3.0-beta.0", - "packages": { - "@typescript-eslint/parser": { - "version": "~5.3.0" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~5.3.0" - }, - "@typescript-eslint/experimental-utils": { - "version": "~5.3.0" - }, - "eslint": { - "version": "8.2.0" - } - } - }, - "13.7.0": { - "version": "13.7.0-beta.0", - "packages": { - "@typescript-eslint/parser": { - "version": "~5.10.0" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~5.10.0" - }, - "@typescript-eslint/experimental-utils": { - "version": "~5.10.0" - }, - "eslint": { - "version": "~8.7.0" - } - } - }, - "13.10.0": { - "version": "13.10.0-beta.0", - "packages": { - "@typescript-eslint/parser": { - "version": "~5.18.0" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~5.18.0" - }, - "@typescript-eslint/experimental-utils": { - "version": "~5.18.0" - }, - "eslint": { - "version": "~8.12.0" - } - } - }, - "14.2.0": { - "version": "14.2.0-beta.0", - "packages": { - "@typescript-eslint/parser": { - "version": "~5.24.0" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~5.24.0" - }, - "@typescript-eslint/experimental-utils": { - "version": "~5.24.0" - }, - "eslint": { - "version": "~8.15.0" - } - } - }, - "14.3.7": { - "version": "14.3.6", - "packages": { - "@typescript-eslint/parser": { - "version": "^5.29.0" - }, - "@typescript-eslint/eslint-plugin": { - "version": "^5.29.0" - }, - "@typescript-eslint/experimental-utils": { - "version": "^5.29.0" - } - } - }, - "14.4.4": { - "version": "14.4.4", - "packages": { - "@typescript-eslint/utils": { - "version": "^5.29.0" - } - } - }, - "14.6.0": { - "version": "14.6.0-rc.2", - "packages": { - "@typescript-eslint/parser": { - "version": "~5.33.1" - }, - "@typescript-eslint/eslint-plugin": { - "version": "~5.33.1" - }, - "@typescript-eslint/utils": { - "version": "~5.33.1" - } - } - }, - "14.8.0": { - "version": "14.8.0-beta.0", - "packages": { - "@typescript-eslint/parser": { - "version": "^5.36.1" - }, - "@typescript-eslint/eslint-plugin": { - "version": "^5.36.1" - }, - "@typescript-eslint/utils": { - "version": "^5.36.1" - } - } - }, "16.0.0": { "version": "16.0.0-beta.0", "packages": { diff --git a/packages/linter/package.json b/packages/linter/package.json index 1229ee6600ec2..93341f1e5866d 100644 --- a/packages/linter/package.json +++ b/packages/linter/package.json @@ -33,7 +33,6 @@ "eslint": "^8.0.0" }, "dependencies": { - "@phenomnomnominal/tsquery": "~5.0.1", "tslib": "^2.3.0", "@nx/devkit": "file:../devkit", "@nx/js": "file:../js", diff --git a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts b/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts deleted file mode 100644 index 3721f5a9a22a3..0000000000000 --- a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts +++ /dev/null @@ -1,231 +0,0 @@ -import { addProjectConfiguration, readJson, Tree, writeJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import removeESLintProjectConfigIfNoTypeCheckingRules from './remove-eslint-project-config-if-no-type-checking-rules'; -import type { Linter } from 'eslint'; -const KNOWN_RULE_REQUIRING_TYPE_CHECKING = '@typescript-eslint/await-thenable'; - -describe('Remove ESLint parserOptions.project config if no rules requiring type-checking are in use', () => { - let tree: Tree; - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - 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: {}, - }); - addProjectConfiguration(tree, 'another-lib', { - root: 'libs/another-lib', - sourceRoot: 'libs/another-lib/src', - projectType: 'library', - targets: {}, - }); - }); - - it('should not update any configs if the root .eslintrc.json contains at least one rule requiring type-checking', async () => { - const rootEslintConfig = { - 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'], - rules: { - [KNOWN_RULE_REQUIRING_TYPE_CHECKING]: 'error', - }, - }, - { - files: ['*.js', '*.jsx'], - extends: ['plugin:@nrwl/nx/javascript'], - rules: {}, - }, - ], - }; - writeJson(tree, '.eslintrc.json', rootEslintConfig); - - const projectEslintConfig1 = { - extends: '../../../.eslintrc.json', - ignorePatterns: ['!**/*'], - overrides: [ - { - files: ['*.ts', '*.tsx'], - parserOptions: { - project: 'some-path-to-tsconfig.json', - }, - rules: {}, - }, - ], - }; - writeJson(tree, 'apps/react-app/.eslintrc.json', projectEslintConfig1); - - const projectEslintConfig2 = { - extends: '../../../.eslintrc.json', - ignorePatterns: ['!**/*'], - overrides: [ - { - files: ['*.ts', '*.tsx'], - parserOptions: { - project: 'some-path-to-tsconfig.json', - }, - rules: {}, - }, - ], - }; - writeJson(tree, 'libs/workspace-lib/.eslintrc.json', projectEslintConfig2); - - await removeESLintProjectConfigIfNoTypeCheckingRules(tree); - - // No change - expect(readJson(tree, 'apps/react-app/.eslintrc.json')).toEqual( - projectEslintConfig1 - ); - - // No change - expect(readJson(tree, 'libs/workspace-lib/.eslintrc.json')).toEqual( - projectEslintConfig1 - ); - }); - - it('should remove the parserOptions.project from any project .eslintrc.json files that do not contain any rules requiring type-checking', async () => { - // Root doesn't contain any rules requiring type-checking - const rootEslintConfig = { - root: true, - ignorePatterns: ['**/*'], - plugins: ['@nrwl/nx'], - overrides: [], - }; - writeJson(tree, '.eslintrc.json', rootEslintConfig); - - const projectEslintConfig1: Linter.Config = { - extends: '../../../.eslintrc.json', - ignorePatterns: ['!**/*'], - overrides: [ - { - files: ['*.ts', '*.tsx'], - parserOptions: { - project: 'some-path-to-tsconfig.json', - }, - rules: { - [KNOWN_RULE_REQUIRING_TYPE_CHECKING]: 'error', - }, - }, - ], - }; - writeJson(tree, 'apps/react-app/.eslintrc.json', projectEslintConfig1); - - const projectEslintConfig2: Linter.Config = { - extends: '../../../.eslintrc.json', - ignorePatterns: ['!**/*'], - overrides: [ - { - files: ['*.ts', '*.tsx'], - parserOptions: { - project: 'some-path-to-tsconfig.json', - }, - rules: { - // No rules requiring type-checking - }, - }, - ], - }; - writeJson(tree, 'libs/workspace-lib/.eslintrc.json', projectEslintConfig2); - - const projectEslintConfig3: Linter.Config = { - extends: '../../../.eslintrc.json', - ignorePatterns: ['!**/*'], - overrides: [ - { - files: ['*.ts', '*.tsx'], - parserOptions: { - project: 'some-path-to-tsconfig.json', - }, - rules: { - [KNOWN_RULE_REQUIRING_TYPE_CHECKING]: 'off', - }, - }, - ], - }; - writeJson(tree, 'libs/another-lib/.eslintrc.json', projectEslintConfig3); - - await removeESLintProjectConfigIfNoTypeCheckingRules(tree); - - // No change - uses rule requiring type-checking - expect(readJson(tree, 'apps/react-app/.eslintrc.json')).toEqual( - projectEslintConfig1 - ); - - // Updated - no more parserOptions.project - expect(readJson(tree, 'libs/workspace-lib/.eslintrc.json')) - .toMatchInlineSnapshot(` - { - "extends": "../../../.eslintrc.json", - "ignorePatterns": [ - "!**/*", - ], - "overrides": [ - { - "files": [ - "*.ts", - "*.tsx", - ], - "rules": {}, - }, - ], - } - `); - - // Updated - no more parserOptions.project - expect(readJson(tree, 'libs/another-lib/.eslintrc.json')) - .toMatchInlineSnapshot(` - { - "extends": "../../../.eslintrc.json", - "ignorePatterns": [ - "!**/*", - ], - "overrides": [ - { - "files": [ - "*.ts", - "*.tsx", - ], - "rules": { - "@typescript-eslint/await-thenable": "off", - }, - }, - ], - } - `); - }); - - it('should not error if .eslintrc.json does not exist', async () => { - await removeESLintProjectConfigIfNoTypeCheckingRules(tree); - }); -}); diff --git a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts b/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts deleted file mode 100644 index 497c67c4baa9c..0000000000000 --- a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { formatFiles, getProjects, readJson, updateJson } from '@nx/devkit'; -import type { Tree } from '@nx/devkit'; -import { join } from 'path'; -import { - hasRulesRequiringTypeChecking, - removeParserOptionsProjectIfNotRequired, -} from '../../utils/rules-requiring-type-checking'; - -function updateProjectESLintConfigs(host: Tree) { - const projects = getProjects(host); - projects.forEach((p) => { - const eslintConfigPath = join(p.root, '.eslintrc.json'); - if (!host.exists(eslintConfigPath)) { - return; - } - return updateJson( - host, - eslintConfigPath, - removeParserOptionsProjectIfNotRequired - ); - }); -} - -export default async function removeESLintProjectConfigIfNoTypeCheckingRules( - host: Tree -) { - if (!host.exists('.eslintrc.json')) { - return; - } - - // If the root level config uses at least one rule requiring type-checking, do not migrate any project configs - const rootESLintConfig = readJson(host, '.eslintrc.json'); - if (hasRulesRequiringTypeChecking(rootESLintConfig)) { - return; - } - updateProjectESLintConfigs(host); - await formatFiles(host); -} diff --git a/packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts b/packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts deleted file mode 100644 index 56819b2c039f6..0000000000000 --- a/packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { - addProjectConfiguration, - readProjectConfiguration, - TargetConfiguration, - Tree, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import addOutputs from './add-outputs'; - -describe('addOutputs', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - const lintWithoutOutputs: TargetConfiguration = { - executor: '@nrwl/linter:eslint', - options: {}, - }; - const lintWithOutputs: TargetConfiguration = { - executor: '@nrwl/linter:eslint', - outputs: ['dist'], - options: {}, - }; - const notLint: TargetConfiguration = { - executor: '@nrwl/node:build', - options: {}, - }; - - addProjectConfiguration(tree, 'proj', { - root: 'proj', - targets: { - lintWithoutOutputs, - lintWithOutputs, - notLint, - }, - }); - }); - - it('should add outputs to targets that do not have outputs', async () => { - await addOutputs(tree); - - expect(readProjectConfiguration(tree, 'proj')).toMatchInlineSnapshot(` - { - "$schema": "../node_modules/nx/schemas/project-schema.json", - "name": "proj", - "root": "proj", - "targets": { - "lintWithOutputs": { - "executor": "@nrwl/linter:eslint", - "options": {}, - "outputs": [ - "dist", - ], - }, - "lintWithoutOutputs": { - "executor": "@nrwl/linter:eslint", - "options": {}, - "outputs": [ - "{options.outputFile}", - ], - }, - "notLint": { - "executor": "@nrwl/node:build", - "options": {}, - }, - }, - } - `); - }); -}); diff --git a/packages/linter/src/migrations/update-12-9-0/add-outputs.ts b/packages/linter/src/migrations/update-12-9-0/add-outputs.ts deleted file mode 100644 index 84213058b7dc8..0000000000000 --- a/packages/linter/src/migrations/update-12-9-0/add-outputs.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export default async function addOutputs(tree: Tree) { - for (const [projectName, project] of getProjects(tree)) { - if (!project.targets) { - continue; - } - - for (const target of Object.values(project.targets)) { - if (target.executor !== '@nrwl/linter:eslint' || target.outputs) { - continue; - } - - target.outputs = ['{options.outputFile}']; - - updateProjectConfiguration(tree, projectName, project); - } - } - - await formatFiles(tree); -} diff --git a/packages/linter/src/migrations/update-13-3-0/eslint-8-updates.spec.ts b/packages/linter/src/migrations/update-13-3-0/eslint-8-updates.spec.ts deleted file mode 100644 index 5c56d621a463f..0000000000000 --- a/packages/linter/src/migrations/update-13-3-0/eslint-8-updates.spec.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import eslint8Updates from './eslint-8-updates'; - -describe('eslint8Updates()', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - `tools/eslint-rules/jest.config.js`, - ` - module.exports = { - displayName: 'eslint-rules', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - transform: { - '^.+\\.[tj]s$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../coverage/tools/eslint-rules', - }; - ` - ); - - tree.write( - `tools/eslint-rules/rules/existing-rule.ts`, - ` - import { ESLintUtils } from '@typescript-eslint/experimental-utils'; - - // NOTE: The rule will be available in ESLint configs as "@nrwl/nx/workspace/existing-rule" - export const RULE_NAME = 'existing-rule'; - - export const rule = ESLintUtils.RuleCreator(() => __filename)({ - name: RULE_NAME, - meta: { - type: 'problem', - docs: { - description: \`\`, - category: 'Possible Errors', - recommended: 'error', - }, - schema: [], - messages: {}, - }, - defaultOptions: [], - create(context) { - return {}; - }, - }); - ` - ); - }); - - it('should add module mapping for ESLint to the jest config', async () => { - await eslint8Updates(tree); - - expect(tree.read('tools/eslint-rules/jest.config.js').toString('utf-8')) - .toMatchInlineSnapshot(` - "module.exports = { - displayName: 'eslint-rules', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - transform: { - '^.+.[tj]s$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../coverage/tools/eslint-rules', - moduleNameMapper: { - '@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc-universal.cjs', - }, - }; - " - `); - }); - - it('should remove the category meta property from any existing workspace rules', async () => { - await eslint8Updates(tree); - - expect( - tree.read(`tools/eslint-rules/rules/existing-rule.ts`).toString('utf-8') - ).toMatchInlineSnapshot(` - "import { ESLintUtils } from '@typescript-eslint/experimental-utils'; - - // NOTE: The rule will be available in ESLint configs as "@nrwl/nx/workspace/existing-rule" - export const RULE_NAME = 'existing-rule'; - - export const rule = ESLintUtils.RuleCreator(() => __filename)({ - name: RULE_NAME, - meta: { - type: 'problem', - docs: { - description: \`\`, - recommended: 'error', - }, - schema: [], - messages: {}, - }, - defaultOptions: [], - create(context) { - return {}; - }, - }); - " - `); - }); -}); diff --git a/packages/linter/src/migrations/update-13-3-0/eslint-8-updates.ts b/packages/linter/src/migrations/update-13-3-0/eslint-8-updates.ts deleted file mode 100644 index b1c9643771e55..0000000000000 --- a/packages/linter/src/migrations/update-13-3-0/eslint-8-updates.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { - ensurePackage, - formatFiles, - normalizePath, - Tree, - visitNotIgnoredFiles, -} from '@nx/devkit'; -import { tsquery } from '@phenomnomnominal/tsquery'; -import { nxVersion } from '../../utils/versions'; - -export default async function eslint8Updates(tree: Tree) { - try { - const { addPropertyToJestConfig } = ensurePackage('@nx/jest', nxVersion); - const existingJestConfigPath = normalizePath( - 'tools/eslint-rules/jest.config.js' - ); - - // Add extra config to the jest.config.js file to allow ESLint 8 exports mapping to work with jest - addPropertyToJestConfig(tree, existingJestConfigPath, 'moduleNameMapper', { - '@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc-universal.cjs', - }); - - visitNotIgnoredFiles(tree, 'tools/eslint-rules', (path) => { - if (!path.endsWith('.ts')) { - return; - } - const fileContents = tree.read(path).toString('utf-8'); - const fileAst = tsquery.ast(fileContents); - const isESLintRuleFile = - tsquery( - fileAst, - 'PropertyAccessExpression[expression.escapedText=ESLintUtils][name.escapedText=RuleCreator]' - ).length > 0; - if (!isESLintRuleFile) { - return; - } - const categoryPropertyAssignmentNode = tsquery( - fileAst, - 'PropertyAssignment[name.escapedText=meta] PropertyAssignment[name.escapedText=docs] PropertyAssignment[name.escapedText=category]' - )[0]; - if (!categoryPropertyAssignmentNode) { - return; - } - let end = categoryPropertyAssignmentNode.getEnd(); - if (fileContents.substring(end, end + 1) === ',') { - end++; - } - const updatedContents = - fileContents.slice(0, categoryPropertyAssignmentNode.getFullStart()) + - fileContents.slice(end); - tree.write(path, updatedContents); - }); - - await formatFiles(tree); - } catch {} -} diff --git a/packages/linter/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts b/packages/linter/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts deleted file mode 100644 index 9fd36504392cf..0000000000000 --- a/packages/linter/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { formatFiles, Tree } from '@nx/devkit'; -import { addSwcRegisterDependencies } from '@nx/js/src/utils/swc/add-swc-dependencies'; -import { WORKSPACE_PLUGIN_DIR } from '../../generators/workspace-rules-project/workspace-rules-project'; - -export default async function addSwcNodeIfNeeded(tree: Tree) { - try { - if (tree.exists(WORKSPACE_PLUGIN_DIR)) { - addSwcRegisterDependencies(tree); - await formatFiles(tree); - return; - } - } catch {} -} diff --git a/packages/linter/src/migrations/update-14-4-4/__snapshots__/experimental-to-utils-deps.spec.ts.snap b/packages/linter/src/migrations/update-14-4-4/__snapshots__/experimental-to-utils-deps.spec.ts.snap deleted file mode 100644 index 7beeec5a23c20..0000000000000 --- a/packages/linter/src/migrations/update-14-4-4/__snapshots__/experimental-to-utils-deps.spec.ts.snap +++ /dev/null @@ -1,36 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`addTypescriptEslintUtilsIfNeeded() should add @typescript-eslint/utils if plugins folder exists 1`] = ` -"{ - "name": "test-name", - "dependencies": {}, - "devDependencies": { - "@typescript-eslint/utils": "^5.60.1" - } -} -" -`; - -exports[`addTypescriptEslintUtilsIfNeeded() should not add @typescript-eslint/utils if plugins folder or experimental-utils dont exist 1`] = `"{"name":"test-name","dependencies":{},"devDependencies":{}}"`; - -exports[`addTypescriptEslintUtilsIfNeeded() should remove @typescript-eslint/experimental-utils from package.json devDependencies and add @typescript-eslint/utils 1`] = ` -"{ - "name": "test-name", - "dependencies": {}, - "devDependencies": { - "@typescript-eslint/utils": "^5.60.1" - } -} -" -`; - -exports[`addTypescriptEslintUtilsIfNeeded() should remove @typescript-eslint/experimental-utils from package.json devDependencies and add @typescript-eslint/utils 2`] = ` -"{ - "name": "test-name", - "dependencies": {}, - "devDependencies": { - "@typescript-eslint/utils": "^5.60.1" - } -} -" -`; diff --git a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.spec.ts b/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.spec.ts deleted file mode 100644 index 9852c3a754d6f..0000000000000 --- a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { updateJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { WORKSPACE_PLUGIN_DIR } from '../../generators/workspace-rules-project/workspace-rules-project'; -import addTypescriptEslintUtilsIfNeeded from './experimental-to-utils-deps'; - -describe('addTypescriptEslintUtilsIfNeeded()', () => { - it('should remove @typescript-eslint/experimental-utils from package.json devDependencies and add @typescript-eslint/utils', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => { - json.devDependencies['@typescript-eslint/experimental-utils'] = '12.3.4'; - return json; - }); - - await addTypescriptEslintUtilsIfNeeded(tree); - - expect(tree.read(`package.json`).toString('utf-8')).toMatchSnapshot(); - }); - - it('should remove @typescript-eslint/experimental-utils from package.json devDependencies and add @typescript-eslint/utils', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => { - json.dependencies['@typescript-eslint/experimental-utils'] = '12.3.4'; - return json; - }); - - await addTypescriptEslintUtilsIfNeeded(tree); - - expect(tree.read(`package.json`).toString('utf-8')).toMatchSnapshot(); - }); - - it('should add @typescript-eslint/utils if plugins folder exists', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - `${WORKSPACE_PLUGIN_DIR}/rules/my-rule.ts`, - 'console.log("not important");' - ); - - await addTypescriptEslintUtilsIfNeeded(tree); - - expect(tree.read(`package.json`).toString('utf-8')).toMatchSnapshot(); - }); - - it('should not add @typescript-eslint/utils if plugins folder or experimental-utils dont exist', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - await addTypescriptEslintUtilsIfNeeded(tree); - - expect(tree.read(`package.json`).toString('utf-8')).toMatchSnapshot(); - }); -}); diff --git a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.ts b/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.ts deleted file mode 100644 index 63ec330359333..0000000000000 --- a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-deps.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - addDependenciesToPackageJson, - formatFiles, - readJson, - removeDependenciesFromPackageJson, - Tree, -} from '@nx/devkit'; -import { WORKSPACE_PLUGIN_DIR } from '../../generators/workspace-rules-project/workspace-rules-project'; -import { typescriptESLintVersion } from '../../utils/versions'; - -export default async function addTypescriptEslintUtilsIfNeeded(tree: Tree) { - try { - const packageJson = readJson(tree, 'package.json'); - let removed = false; - - if (packageJson.devDependencies['@typescript-eslint/experimental-utils']) { - await removeDependenciesFromPackageJson( - tree, - [], - ['@typescript-eslint/experimental-utils'] - ); - removed = true; - } - - if (packageJson.dependencies['@typescript-eslint/experimental-utils']) { - await removeDependenciesFromPackageJson( - tree, - ['@typescript-eslint/experimental-utils'], - [] - ); - removed = true; - } - - if (removed || tree.exists(WORKSPACE_PLUGIN_DIR)) { - addDependenciesToPackageJson( - tree, - {}, - { '@typescript-eslint/utils': typescriptESLintVersion } - ); - - await formatFiles(tree); - } - return; - } catch {} -} diff --git a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.spec.ts b/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.spec.ts deleted file mode 100644 index 1a1a3a2f77f93..0000000000000 --- a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.spec.ts +++ /dev/null @@ -1,132 +0,0 @@ -import { Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import experimentalToUtilsUpdate from './experimental-to-utils-rules'; - -describe('experimentalToUtilsUpdate()', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.write( - `tools/eslint-rules/rules/existing-rule.ts`, - ` - import { ESLintUtils } from '@typescript-eslint/experimental-utils'; - import { rule, RULE_NAME } from './existing-rule'; - - // NOTE: The rule will be available in ESLint configs as "@nrwl/nx/workspace/existing-rule" - export const RULE_NAME = 'existing-rule'; - - export const rule = ESLintUtils.RuleCreator(() => __filename)({ - name: RULE_NAME, - meta: { - type: 'problem', - docs: { - description: \`\`, - recommended: 'error', - }, - schema: [], - messages: {}, - }, - defaultOptions: [], - create(context) { - return {}; - }, - }); - ` - ); - - tree.write( - `tools/eslint-rules/rules/existing-rule.spec.ts`, - ` - import { TSESLint } from '@typescript-eslint/experimental-utils'; - import { rule, RULE_NAME } from './existing-rule'; - - const ruleTester = new TSESLint.RuleTester({ - parser: require.resolve('@typescript-eslint/parser'), - }); - - ruleTester.run(RULE_NAME, rule, { - valid: [\`const example = true;\`], - invalid: [], - }); - ` - ); - - tree.write( - `tools/eslint-rules/rules/multi-import.ts`, - ` - import { ESLintUtils } from '@typescript-eslint/experimental-utils'; - import { TSESLint } from '@typescript-eslint/experimental-utils'; - import { rule, RULE_NAME } from './existing-rule'; - - // NOTE: remaining code is irrelevant for this test - ` - ); - }); - - it('should switch import from @typescript-eslint/experimental-utils to @typescript-eslint/utils in rule and spec file', async () => { - await experimentalToUtilsUpdate(tree); - - expect( - tree.read(`tools/eslint-rules/rules/existing-rule.ts`).toString('utf-8') - ).toMatchInlineSnapshot(` - "import { ESLintUtils } from '@typescript-eslint/utils'; - import { rule, RULE_NAME } from './existing-rule'; - - // NOTE: The rule will be available in ESLint configs as "@nrwl/nx/workspace/existing-rule" - export const RULE_NAME = 'existing-rule'; - - export const rule = ESLintUtils.RuleCreator(() => __filename)({ - name: RULE_NAME, - meta: { - type: 'problem', - docs: { - description: \`\`, - recommended: 'error', - }, - schema: [], - messages: {}, - }, - defaultOptions: [], - create(context) { - return {}; - }, - }); - " - `); - - expect( - tree - .read(`tools/eslint-rules/rules/existing-rule.spec.ts`) - .toString('utf-8') - ).toMatchInlineSnapshot(` - "import { TSESLint } from '@typescript-eslint/utils'; - import { rule, RULE_NAME } from './existing-rule'; - - const ruleTester = new TSESLint.RuleTester({ - parser: require.resolve('@typescript-eslint/parser'), - }); - - ruleTester.run(RULE_NAME, rule, { - valid: [\`const example = true;\`], - invalid: [], - }); - " - `); - }); - - it('should switch import from @typescript-eslint/experimental-utils to @typescript-eslint/utils on multiple imports', async () => { - await experimentalToUtilsUpdate(tree); - - expect( - tree.read(`tools/eslint-rules/rules/multi-import.ts`).toString('utf-8') - ).toMatchInlineSnapshot(` - "import { ESLintUtils } from '@typescript-eslint/utils'; - import { TSESLint } from '@typescript-eslint/utils'; - import { rule, RULE_NAME } from './existing-rule'; - - // NOTE: remaining code is irrelevant for this test - " - `); - }); -}); diff --git a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.ts b/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.ts deleted file mode 100644 index d1f4a55e31985..0000000000000 --- a/packages/linter/src/migrations/update-14-4-4/experimental-to-utils-rules.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { formatFiles, Tree, visitNotIgnoredFiles } from '@nx/devkit'; -import { tsquery } from '@phenomnomnominal/tsquery'; - -function updateFile(fileAst: any, fileContents: string): string | undefined { - const importStatement: any[] = tsquery( - fileAst, - 'ImportDeclaration StringLiteral[value=@typescript-eslint/experimental-utils]' - ); - if (importStatement.length === 0) { - return; - } - const contentSlices = fileContents.split( - '@typescript-eslint/experimental-utils' - ); - let updatedFileContents = ''; - for (let i = 0; i < contentSlices.length / 2; i++) { - updatedFileContents += `${contentSlices[i]}@typescript-eslint/utils`; - } - updatedFileContents += contentSlices[contentSlices.length - 1]; - return updatedFileContents; -} - -export default async function experimentalToUtilsUpdate(tree: Tree) { - try { - visitNotIgnoredFiles(tree, 'tools/eslint-rules', (path) => { - if (path.endsWith('.ts')) { - const fileContents = tree.read(path).toString('utf-8'); - const fileAst = tsquery.ast(fileContents); - - const updatedContents = updateFile(fileAst, fileContents); - if (updatedContents) { - tree.write(path, updatedContents); - } - } - }); - - await formatFiles(tree); - } catch {} -} diff --git a/packages/nest/migrations.json b/packages/nest/migrations.json index dc12360273ac7..27068d586797b 100644 --- a/packages/nest/migrations.json +++ b/packages/nest/migrations.json @@ -1,11 +1,5 @@ { "generators": { - "update-to-nest-8": { - "cli": "nx", - "version": "13.2.0-beta.0", - "description": "Update Nest.js libraries", - "factory": "./src/migrations/update-13-2-0/update-to-nest-8" - }, "update-16-0-0-add-nx-packages": { "cli": "nx", "version": "16.0.0-beta.1", @@ -20,35 +14,6 @@ } }, "packageJsonUpdates": { - "14.5.0": { - "version": "14.5.0-beta.1", - "packages": { - "@nestjs/common": { - "version": "^9.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/core": { - "version": "^9.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/platform-express": { - "version": "^9.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/schematics": { - "version": "^9.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/swagger": { - "version": "^6.0.0", - "alwaysAddToPackageJson": false - }, - "@nestjs/testing": { - "version": "^9.0.0", - "alwaysAddToPackageJson": false - } - } - }, "16.1.0": { "version": "16.1.0-beta.0", "packages": { diff --git a/packages/nest/package.json b/packages/nest/package.json index fb9eeac789a24..dc6b924ab48d5 100644 --- a/packages/nest/package.json +++ b/packages/nest/package.json @@ -31,13 +31,11 @@ }, "dependencies": { "@nestjs/schematics": "^9.1.0", - "enquirer": "~2.3.6", "@nx/devkit": "file:../devkit", "@nx/js": "file:../js", "@nx/linter": "file:../linter", "@nx/node": "file:../node", "@phenomnomnominal/tsquery": "~5.0.1", - "semver": "7.5.3", "tslib": "^2.3.0" }, "publishConfig": { diff --git a/packages/nest/src/migrations/update-13-2-0/update-to-nest-8.ts b/packages/nest/src/migrations/update-13-2-0/update-to-nest-8.ts deleted file mode 100644 index 2544658100584..0000000000000 --- a/packages/nest/src/migrations/update-13-2-0/update-to-nest-8.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { formatFiles, logger, readJson, Tree, updateJson } from '@nx/devkit'; -import { checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver'; -import { satisfies } from 'semver'; -import { sortObjectByKeys } from 'nx/src/utils/object-sort'; - -const nestJsSchematicsVersion = '^9.0.0'; -const nestJsVersion8 = '^8.0.0'; -const rxjsVersion7 = '^7.0.0'; - -export default async function update(tree: Tree) { - const shouldUpdate = await isUpdatable(tree); - - if (!shouldUpdate) { - return; - } - - updateVersion(tree); - - await formatFiles(tree); - - return (): void => { - logger.info( - 'Please make sure to run npm install or yarn install to get the latest packages added by this migration' - ); - }; -} - -async function isUpdatable(tree: Tree) { - const json = readJson(tree, 'package.json'); - - if (json.dependencies['@angular/core']) { - const rxjs = checkAndCleanWithSemver('rxjs', json.dependencies['rxjs']); - if (satisfies(rxjs, rxjsVersion7)) { - return true; - } - - const { Confirm } = require('enquirer'); - const prompt = new Confirm({ - name: 'question', - message: 'Do you want to update to RxJS 7 + Nest 8?', - initial: true, - }); - - return await prompt.run(); - } - - return true; -} - -function updateVersion(tree: Tree) { - updateJson(tree, 'package.json', (json) => { - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - const rxjs = checkAndCleanWithSemver('rxjs', json.dependencies['rxjs']); - - json.dependencies = { - ...json.dependencies, - '@nestjs/common': nestJsVersion8, - '@nestjs/core': nestJsVersion8, - rxjs: satisfies(rxjs, rxjsVersion7) - ? json.dependencies['rxjs'] - : rxjsVersion7, - }; - - if (json.dependencies['@nestjs/platform-express']) { - json.dependencies['@nestjs/platform-express'] = nestJsVersion8; - } - - if (json.dependencies['@nestjs/platform-fastify']) { - json.dependencies['@nestjs/platform-fastify'] = nestJsVersion8; - } - - json.devDependencies = { - ...json.devDependencies, - '@nestjs/schematics': nestJsSchematicsVersion, - '@nestjs/testing': nestJsVersion8, - }; - - if (json.devDependencies['jasmine-marbles']) { - json.devDependencies['jasmine-marbles'] = '~0.9.1'; - } - - json.dependencies = sortObjectByKeys(json.dependencies); - json.devDependencies = sortObjectByKeys(json.devDependencies); - - return json; - }); -} diff --git a/packages/next/migrations.json b/packages/next/migrations.json index 2ed345d54cfaa..e198c0fcbbb41 100644 --- a/packages/next/migrations.json +++ b/packages/next/migrations.json @@ -1,59 +1,5 @@ { "generators": { - "fix-nextjs-lib-babel-config-12.8.0": { - "cli": "nx", - "version": "12.8.0-beta.11", - "description": "Adjust the Next.js lib babel configuration for styled-jsx", - "factory": "./src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin" - }, - "fix-page-dir-for-eslint": { - "cli": "nx", - "version": "12.10.0-beta.1", - "description": "Updates .eslintrc.json file to use the correct pages directory for '@next/next/no-html-link-for-pages'.", - "factory": "./src/migrations/update-12-10-0/fix-page-dir-for-eslint" - }, - "update-emotion-setup-13.0.0": { - "cli": "nx", - "version": "13.0.0-beta.0", - "description": "Update tsconfig.json to use `jsxImportSource` to support css prop", - "factory": "./src/migrations/update-13-0-0/update-emotion-setup" - }, - "update-to-webpack-5": { - "cli": "nx", - "version": "13.0.0-beta.1", - "description": "Set `webpack5: true` for all next.js projects.", - "factory": "./src/migrations/update-13-0-0/update-to-webpack-5" - }, - "fix-less": { - "cli": "nx", - "version": "13.0.3-beta.1", - "description": "Fix setup for less stylesheets", - "factory": "./src/migrations/update-13-0-3/fix-less" - }, - "add-default-development-configurations-14.0.0": { - "cli": "nx", - "version": "14.0.0-beta.0", - "description": "Add a default development configuration for build and serve targets.", - "factory": "./src/migrations/update-14-0-0/add-default-development-configurations" - }, - "add-dev-output-path": { - "cli": "nx", - "version": "14.4.3-beta.0", - "description": "Add a development outputPath to avoid conflict with the production build.", - "factory": "./src/migrations/update-14-4-3/add-dev-output-path" - }, - "add-gitignore-entry": { - "cli": "nx", - "version": "14.5.3-beta.0", - "description": "Add .next folder to gitignore.", - "factory": "./src/migrations/update-14-5-3/add-gitignore-entry" - }, - "update-dev-output-path": { - "cli": "nx", - "version": "14.5.3-beta.0", - "description": "Update development outputPath to the project root.", - "factory": "./src/migrations/update-14-5-3/update-dev-output-path" - }, "add-style-packages": { "cli": "nx", "version": "15.8.8-beta.0", @@ -80,212 +26,6 @@ } }, "packageJsonUpdates": { - "12.1.2": { - "version": "12.1.2-beta.0", - "packages": { - "next": { - "version": "10.2.0", - "alwaysAddToPackageJson": false - } - } - }, - "12.6.0": { - "version": "12.6.0-beta.0", - "packages": { - "next": { - "version": "11.0.1", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "11.0.1", - "addToPackageJson": "devDependencies" - } - } - }, - "update-12.7.2": { - "version": "12.7.2-beta.0", - "packages": { - "next": { - "version": "11.1.0", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "11.1.0", - "alwaysAddToPackageJson": false - } - } - }, - "update-13.0.3": { - "version": "13.0.3-beta.0", - "packages": { - "next": { - "version": "12.0.0", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "13.3.0": { - "version": "13.3.0-beta.0", - "packages": { - "next": { - "version": "12.0.7", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.0.7", - "alwaysAddToPackageJson": false - } - } - }, - "13.9.0": { - "version": "13.9.0-beta.0", - "packages": { - "next": { - "version": "12.1.0", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.1.0", - "alwaysAddToPackageJson": false - } - } - }, - "13.10.0": { - "version": "13.10.0-beta.1", - "packages": { - "next": { - "version": "12.1.2", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.1.2", - "alwaysAddToPackageJson": false - }, - "sass": { - "version": "1.49.9", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.0": { - "version": "14.0.0-beta.1", - "packages": { - "next": { - "version": "12.1.5", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.1.5", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.3": { - "version": "14.2.3-beta.0", - "packages": { - "next": { - "version": "12.1.6", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.1.6", - "alwaysAddToPackageJson": false - }, - "sass": { - "version": "1.52.3", - "alwaysAddToPackageJson": false - }, - "less-loader": { - "version": "11.0.0", - "alwaysAddToPackageJson": false - }, - "stylus-loader": { - "version": "7.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.4.3": { - "version": "14.4.3", - "packages": { - "next": { - "version": "12.2.2", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.2.2", - "alwaysAddToPackageJson": false - }, - "sass": { - "version": "1.53.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.0": { - "version": "14.5.0-beta.0", - "packages": { - "next": { - "version": "12.2.3", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.2.3", - "alwaysAddToPackageJson": false - }, - "sass": { - "version": "1.54.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.3": { - "version": "14.5.3-beta.0", - "packages": { - "@emotion/server": { - "version": "11.10.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.6.0": { - "version": "14.6.0-beta.1", - "packages": { - "next": { - "version": "12.2.5", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.2.5", - "alwaysAddToPackageJson": false - }, - "sass": { - "version": "1.54.5", - "alwaysAddToPackageJson": false - } - } - }, - "14.7.10": { - "version": "14.7.10-beta.1", - "packages": { - "next": { - "version": "12.3.1", - "alwaysAddToPackageJson": false - }, - "eslint-config-next": { - "version": "12.3.1", - "alwaysAddToPackageJson": false - }, - "sass": { - "version": "1.55.0", - "alwaysAddToPackageJson": false - } - } - }, "15.0.4": { "version": "15.0.4-beta.0", "packages": { diff --git a/packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.spec.ts b/packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.spec.ts deleted file mode 100644 index e17593417c9c1..0000000000000 --- a/packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.spec.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import { applicationGenerator } from '../../generators/application/application'; -import { fixPageDirForEslint } from './fix-page-dir-for-eslint'; - -describe('Migration: Fix pages directory for ESLint', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - }); - }); - - it('should fix custom pages path', async () => { - // Config that isn't configured properly - tree.write( - 'apps/demo/.eslintrc.json', - JSON.stringify({ - extends: ['next'], - overrides: [ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - rules: { - 'existing-rule': 'error', - }, - }, - ], - }) - ); - - await fixPageDirForEslint(tree); - - const result = readJson(tree, 'apps/demo/.eslintrc.json'); - expect(result.overrides[0].rules).toEqual({ - 'existing-rule': 'error', - '@next/next/no-html-link-for-pages': ['error', 'apps/demo/pages'], - }); - }); - - it('should leave existing no-html-link-for-pages rule if it exists', async () => { - // Config that isn't configured properly - tree.write( - 'apps/demo/.eslintrc.json', - JSON.stringify({ - extends: ['next'], - overrides: [ - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - rules: { - '@next/next/no-html-link-for-pages': [ - 'error', - 'apps/demo/some/other/path', - ], - }, - }, - ], - }) - ); - - await fixPageDirForEslint(tree); - - const result = readJson(tree, 'apps/demo/.eslintrc.json'); - expect(result.overrides[0].rules).toEqual({ - '@next/next/no-html-link-for-pages': [ - 'error', - 'apps/demo/some/other/path', - ], - }); - }); - - it('should handle custom overrides configuration', async () => { - // Config that isn't configured properly - tree.write( - 'apps/demo/.eslintrc.json', - JSON.stringify({ - extends: ['next', 'plugin:vue/base'], - overrides: [ - { files: ['*.vue'], rule: { 'vue/comment-directive': 'error' } }, - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - rules: { - '@next/next/no-html-link-for-pages': [ - 'error', - 'apps/demo/some/other/path', - ], - }, - }, - ], - }) - ); - - await fixPageDirForEslint(tree); - - const result = readJson(tree, 'apps/demo/.eslintrc.json'); - expect(result.overrides).toEqual([ - { files: ['*.vue'], rule: { 'vue/comment-directive': 'error' } }, - { - files: ['*.ts', '*.tsx', '*.js', '*.jsx'], - rules: { - '@next/next/no-html-link-for-pages': [ - 'error', - 'apps/demo/some/other/path', - ], - }, - }, - ]); - }); -}); diff --git a/packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.ts b/packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.ts deleted file mode 100644 index 159eede8ae8c1..0000000000000 --- a/packages/next/src/migrations/update-12-10-0/fix-page-dir-for-eslint.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - formatFiles, - getProjects, - joinPathFragments, - readJson, - Tree, - writeJson, -} from '@nx/devkit'; - -export async function fixPageDirForEslint(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - const eslintRcJson = joinPathFragments(project.root, '.eslintrc.json'); - if (host.exists(eslintRcJson)) { - const config = readJson(host, eslintRcJson); - // Ignore non-nextjs projects - if (!config?.extends?.includes('next')) return; - - // Find the override that handles both TS and JS files. - const commonOverride = config.overrides?.find((o) => - ['*.ts', '*.tsx', '*.js', '*.jsx'].every((ext) => o.files.includes(ext)) - ); - - if ( - commonOverride && - !commonOverride.rules['@next/next/no-html-link-for-pages'] - ) { - commonOverride.rules = { - ...commonOverride.rules, - '@next/next/no-html-link-for-pages': [ - 'error', - `${project.root}/pages`, - ], - }; - - writeJson(host, eslintRcJson, config); - } - } - }); - - await formatFiles(host); -} - -export default fixPageDirForEslint; diff --git a/packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.spec.ts b/packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.spec.ts deleted file mode 100644 index d3c580dc3c412..0000000000000 --- a/packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { Linter } from '@nx/linter'; -import { libraryGenerator } from '../../generators/library/library'; -import { removeStyledJsxBabelConfig } from './remove-styled-jsx-babel-plugin'; - -describe('Remove styled-jsx babel plugin for Next libs', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - await libraryGenerator(tree, { - name: 'test-lib', - style: 'styled-jsx', - skipFormat: false, - skipTsConfig: false, - linter: Linter.EsLint, - unitTestRunner: 'jest', - }); - }); - - it('should remove styled-jsx babel plugin', async () => { - tree.write( - 'libs/test-lib/.babelrc', - JSON.stringify({ - presets: ['next/babel'], - plugins: ['styled-jsx/babel'], - }) - ); - - await removeStyledJsxBabelConfig(tree); - const result = readJson(tree, 'libs/test-lib/.babelrc'); - expect(result.plugins).toEqual([]); - }); - it('should remove styled-jsx babel plugin but leave potentially other plugins in there', async () => { - tree.write( - 'libs/test-lib/.babelrc', - JSON.stringify({ - presets: ['next/babel'], - plugins: [ - 'some-other/plugin', - 'styled-jsx/babel', - 'some-storybook/plugin', - ], - }) - ); - - await removeStyledJsxBabelConfig(tree); - const result = readJson(tree, 'libs/test-lib/.babelrc'); - expect(result.plugins).toEqual([ - 'some-other/plugin', - 'some-storybook/plugin', - ]); - }); -}); diff --git a/packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.ts b/packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.ts deleted file mode 100644 index 6946922434628..0000000000000 --- a/packages/next/src/migrations/update-12-8-0/remove-styled-jsx-babel-plugin.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - readJson, - joinPathFragments, - writeJson, -} from '@nx/devkit'; - -export async function removeStyledJsxBabelConfig(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - const babelRcPath = joinPathFragments(project.root, '.babelrc'); - if (host.exists(babelRcPath)) { - const babelRcContent = readJson(host, babelRcPath); - - // check whether next.js project - if (babelRcContent.presets.includes('next/babel')) { - babelRcContent.plugins = babelRcContent.plugins.filter( - (x) => x !== 'styled-jsx/babel' - ); - - // update .babelrc - writeJson(host, babelRcPath, babelRcContent); - } - } - }); - - await formatFiles(host); -} - -export default removeStyledJsxBabelConfig; diff --git a/packages/next/src/migrations/update-13-0-0/update-emotion-setup.spec.ts b/packages/next/src/migrations/update-13-0-0/update-emotion-setup.spec.ts deleted file mode 100644 index cf4d5cae1d417..0000000000000 --- a/packages/next/src/migrations/update-13-0-0/update-emotion-setup.spec.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { updateEmotionSetup } from './update-emotion-setup'; - -describe('Update tsconfig config for Emotion', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it(`should add jsxImportSource if it uses @emotion/react`, async () => { - addProjectConfiguration(tree, 'no-emotion-app', { - root: 'apps/no-emotion-app', - projectType: 'application', - }); - addProjectConfiguration(tree, 'plain-next-app', { - root: 'apps/plain-next-app', - projectType: 'application', - }); - addProjectConfiguration(tree, 'emotion-app', { - root: 'apps/emotion-app', - projectType: 'application', - }); - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - 'no-emotion-app': {}, - 'plain-next-app': {}, - 'emotion-app': {}, - }, - }) - ); - tree.write('apps/no-emotion-app/.babelrc', JSON.stringify({})); - tree.write( - 'apps/no-emotion-app/tsconfig.json', - JSON.stringify({ compilerOptions: {} }) - ); - tree.write( - 'apps/plain-next-app/.babelrc', - JSON.stringify({ - presets: ['@nrwl/next/babel'], - plugins: [], - }) - ); - tree.write( - 'apps/plain-next-app/tsconfig.json', - JSON.stringify({ compilerOptions: { jsx: 'preserve' } }) - ); - tree.write( - 'apps/emotion-app/.babelrc', - JSON.stringify({ - presets: [ - [ - '@nrwl/next/babel', - { - 'preset-react': { - runtime: 'automatic', - importSource: '@emotion/react', - }, - }, - ], - ], - plugins: ['@emotion/babel-plugin'], - }) - ); - tree.write( - 'apps/emotion-app/tsconfig.json', - JSON.stringify({ compilerOptions: { jsx: 'preserve' } }) - ); - - await updateEmotionSetup(tree); - - expect(readJson(tree, 'apps/no-emotion-app/tsconfig.json')).toEqual({ - compilerOptions: {}, - }); - expect(readJson(tree, 'apps/plain-next-app/tsconfig.json')).toEqual({ - compilerOptions: { jsx: 'preserve' }, - }); - expect(readJson(tree, 'apps/emotion-app/tsconfig.json')).toEqual({ - compilerOptions: { jsx: 'preserve', jsxImportSource: '@emotion/react' }, - }); - }); -}); diff --git a/packages/next/src/migrations/update-13-0-0/update-emotion-setup.ts b/packages/next/src/migrations/update-13-0-0/update-emotion-setup.ts deleted file mode 100644 index 09e09a1d09ac3..0000000000000 --- a/packages/next/src/migrations/update-13-0-0/update-emotion-setup.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - readJson, - updateJson, -} from '@nx/devkit'; - -export async function updateEmotionSetup(host: Tree) { - const projects = getProjects(host); - - projects.forEach((p) => { - let hasEmotion = false; - const babelrcPath = `${p.root}/.babelrc`; - const tsConfigPath = `${p.root}/tsconfig.json`; - - if (host.exists(babelrcPath)) { - const babelrc = readJson(host, babelrcPath); - if (babelrc.presets) { - for (const [idx, preset] of babelrc.presets.entries()) { - if (Array.isArray(preset)) { - if (!preset[0].includes('@nrwl/next/babel')) continue; - const emotionOptions = preset[1]['preset-react']; - hasEmotion = emotionOptions?.importSource === '@emotion/react'; - break; - } - } - } - } - - if (hasEmotion && host.exists(tsConfigPath)) { - updateJson(host, tsConfigPath, (json) => { - json.compilerOptions.jsxImportSource = '@emotion/react'; - return json; - }); - } - }); - - await formatFiles(host); -} - -export default updateEmotionSetup; diff --git a/packages/next/src/migrations/update-13-0-0/update-to-webpack-5.spec.ts b/packages/next/src/migrations/update-13-0-0/update-to-webpack-5.spec.ts deleted file mode 100644 index 2f2689002b355..0000000000000 --- a/packages/next/src/migrations/update-13-0-0/update-to-webpack-5.spec.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import { applicationGenerator } from '../../generators/application/application'; -import { update } from './update-to-webpack-5'; - -describe('Migration: enable webpack 5', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should set webpack5 to true', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - }); - - // Config that isn't configured properly - tree.write( - 'apps/demo/next.config.js', - `const withNx = require('@nx/next/plugins/with-nx'); -const nextConfig = { - webpack5: false, -}; - -module.exports = withNx(nextConfig); -` - ); - - await update(tree); - - const result = tree.read('apps/demo/next.config.js').toString(); - - expect(result).toMatch(/webpack5: true/); - }); - - it('should fix stylus support', async () => { - await applicationGenerator(tree, { - style: 'styl', - name: 'demo', - skipFormat: false, - }); - - // Config that isn't configured properly - tree.write( - 'apps/demo/next.config.js', - `const withNx = require('@nx/next/plugins/with-nx'); -const withStylus = require('@zeit/next-stylus'); - -const nextConfig = { - webpack5: false, -}; - -module.exports = withNx(withStylus(nextConfig)); -` - ); - - await update(tree); - - const result = tree.read('apps/demo/next.config.js').toString(); - - expect(result).toMatch(/@nrwl\/next\/plugins\/with-stylus/); - expect(result).not.toMatch(/@zeit\/next-stylus/); - }); - - it('should fix less support', async () => { - await applicationGenerator(tree, { - style: 'less', - name: 'demo', - skipFormat: false, - }); - - // Config that isn't configured properly - tree.write( - 'apps/demo/next.config.js', - `const withNx = require('@nx/next/plugins/with-nx'); -const withLess = require('@zeit/next-less'); - -const nextConfig = { - webpack5: false, -}; - -module.exports = withNx(withLess(nextConfig)); -` - ); - - await update(tree); - - const result = tree.read('apps/demo/next.config.js').toString(); - - expect(result).toMatch(/next-with-less/); - expect(result).not.toMatch(/@zeit\/next-less/); - }); -}); diff --git a/packages/next/src/migrations/update-13-0-0/update-to-webpack-5.ts b/packages/next/src/migrations/update-13-0-0/update-to-webpack-5.ts deleted file mode 100644 index 4b6d045c7543f..0000000000000 --- a/packages/next/src/migrations/update-13-0-0/update-to-webpack-5.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - addDependenciesToPackageJson, - formatFiles, - GeneratorCallback, - getProjects, - joinPathFragments, - Tree, -} from '@nx/devkit'; - -export async function update(host: Tree) { - const projects = getProjects(host); - let task: undefined | GeneratorCallback = undefined; - - projects.forEach((project) => { - const configPath = joinPathFragments(project.root, 'next.config.js'); - - if (!host.exists(configPath)) return; - - const content = host.read(configPath).toString(); - let updated = content.replace(/webpack5: false/, 'webpack5: true'); - - if (content.match(/@zeit\/next-less/)) { - updated = updated.replace('@zeit/next-less', 'next-with-less'); - task = addDependenciesToPackageJson( - host, - { 'next-with-less': '1.0.1' }, - {} - ); - } - - if (content.match(/@zeit\/next-stylus/)) { - updated = updated.replace( - '@zeit/next-stylus', - '@nrwl/next/plugins/with-stylus' - ); - task = addDependenciesToPackageJson( - host, - { 'stylus-loader': '6.2.0' }, - {} - ); - } - - host.write(configPath, updated); - }); - - await formatFiles(host); - - return task; -} - -export default update; diff --git a/packages/next/src/migrations/update-13-0-3/fix-less.ts b/packages/next/src/migrations/update-13-0-3/fix-less.ts deleted file mode 100644 index f381cf847f114..0000000000000 --- a/packages/next/src/migrations/update-13-0-3/fix-less.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - addDependenciesToPackageJson, - formatFiles, - GeneratorCallback, - getProjects, - joinPathFragments, - Tree, -} from '@nx/devkit'; - -export async function update(host: Tree) { - const projects = getProjects(host); - let task: undefined | GeneratorCallback = undefined; - - projects.forEach((project) => { - const configPath = joinPathFragments(project.root, 'next.config.js'); - - if (!host.exists(configPath)) return; - - const content = host.read(configPath).toString(); - - if (content.match(/next-with-less/)) { - const updated = content.replace( - 'next-with-less', - '@nrwl/next/plugins/with-less' - ); - task = addDependenciesToPackageJson( - host, - { 'less-loader': '10.2.0' }, - {} - ); - host.write(configPath, updated); - } - }); - - await formatFiles(host); - - return task; -} - -export default update; diff --git a/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts b/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts deleted file mode 100644 index d6fa07ed81ed1..0000000000000 --- a/packages/next/src/migrations/update-13-1-1/enable-swc.spec.ts +++ /dev/null @@ -1,203 +0,0 @@ -import { - readProjectConfiguration, - Tree, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import { applicationGenerator } from '../../generators/application/application'; -import { update } from './enable-swc'; - -describe('Migration: enable SWC', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should remove .babelrc file and fix jest config', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: false, - }); - - updateJson(tree, 'apps/demo/.babelrc', (json) => { - json.presets[0] = '@nrwl/next/babel'; - - return json; - }); - - // rename jest config to js as that was standard at this version of nx - tree.delete('apps/demo/jest.config.ts'); - updateProjectConfiguration(tree, 'demo', { - ...readProjectConfiguration(tree, 'demo'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/demo/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - - // Config that isn't configured properly - tree.write( - 'apps/demo/jest.config.js', - ` -module.exports = { - displayName: 'napp4', - preset: '../../jest.preset.js', - transform: { - '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest', - '^.+\\\\.[tj]sx?$': 'babel-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/apps/demo', -}; - -` - ); - - await update(tree); - - const result = tree.read('apps/demo/jest.config.js').toString(); - - expect(result).toMatch(`['babel-jest', { presets: ['@nrwl/next/babel'] }]`); - - expect(tree.exists('apps/demo/.babelrc')).toBe(false); - }); - - it('should still fix jest config when babelrc is missing', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: true, - }); - // rename jest config to js as that was standard at this version of nx - tree.delete('apps/demo/jest.config.ts'); - updateProjectConfiguration(tree, 'demo', { - ...readProjectConfiguration(tree, 'demo'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/demo/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - // Config that isn't configured properly - tree.write( - 'apps/demo/jest.config.js', - ` -module.exports = { - displayName: 'napp4', - preset: '../../jest.preset.js', - transform: { - '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest', - '^.+\\\\.[tj]sx?$': 'babel-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/apps/demo', -}; - -` - ); - - await update(tree); - - const result = tree.read('apps/demo/jest.config.js').toString(); - - expect(result).toMatch(`['babel-jest', { presets: ['@nrwl/next/babel'] }]`); - }); - it('should skip migration if the babelrc has been customized', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: false, - }); - // rename jest config to js as that was standard at this version of nx - tree.rename('apps/demo/jest.config.ts', 'apps/demo/jest.config.js'); - updateProjectConfiguration(tree, 'demo', { - ...readProjectConfiguration(tree, 'demo'), - targets: { - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/demo/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel", "something-else"], - "plugins": [] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(true); - - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel"], - "plugins": ["some-plugin"] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(true); - - // No custom plugins, can migrate. - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel"] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(false); - }); - - it('should skip migration if storybook configuration is detected', async () => { - await applicationGenerator(tree, { - style: 'none', - name: 'demo', - skipFormat: false, - swc: false, - }); - - tree.write( - 'apps/demo/.babelrc', - `{ - "presets": ["@nrwl/next/babel"] - }` - ); - tree.write( - 'apps/demo/.storybook/main.js', - `module.exports = { - stories: [] - }` - ); - - await update(tree); - - expect(tree.exists('apps/demo/.babelrc')).toBe(true); - }); -}); diff --git a/packages/next/src/migrations/update-13-1-1/enable-swc.ts b/packages/next/src/migrations/update-13-1-1/enable-swc.ts deleted file mode 100644 index 2b544e57416a8..0000000000000 --- a/packages/next/src/migrations/update-13-1-1/enable-swc.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - formatFiles, - getProjects, - joinPathFragments, - logger, - readJson, - Tree, -} from '@nx/devkit'; - -export async function update(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - const nextConfigPath = joinPathFragments(project.root, 'next.config.js'); - const jestConfigPath = joinPathFragments(project.root, 'jest.config.js'); - const babelConfigPath = joinPathFragments(project.root, '.babelrc'); - const storybookMainPath = joinPathFragments( - project.root, - '.storybook/main.js' - ); - - if (!host.exists(nextConfigPath) || !host.exists(jestConfigPath)) return; - - if (host.exists(babelConfigPath)) { - if (customBabelConfig(host, babelConfigPath)) { - logger.info( - `NX Custom .babelrc file detected, skipping deletion. You can delete this file yourself to enable SWC: ${babelConfigPath}` - ); - } else if (host.exists(storybookMainPath)) { - logger.info( - `NX Storybook configuration for project "${project.name}" detected, skipping deletion of .babelrc` - ); - } else { - // Deleting custom babel config enables SWC - host.delete(babelConfigPath); - } - } - - const content = host.read(jestConfigPath).toString(); - - if (content.match(/:\s+'babel-jest'/)) { - const updated = content.replace( - /:\s+'babel-jest'/, - `: ['babel-jest', { presets: ['@nrwl/next/babel'] }]` - ); - host.write(jestConfigPath, updated); - } - }); - - await formatFiles(host); -} - -function customBabelConfig(host, configPath) { - const json = readJson(host, configPath); - return !( - json.presets?.length === 1 && - json.presets?.[0] === '@nrwl/next/babel' && - (json.plugins?.length === 0 || !json.plugins) - ); -} - -export default update; diff --git a/packages/next/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts b/packages/next/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts deleted file mode 100644 index 519d25ed5edcd..0000000000000 --- a/packages/next/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; -import update from './add-default-development-configurations'; - -describe('React default development configuration', () => { - it('should add development configuration if it does not exist', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - configurations: {}, - }, - serve: { - executor: '@nrwl/next:server', - configurations: {}, - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.defaultConfiguration).toEqual('production'); - expect(config.targets.build.configurations.development).toEqual({}); - - expect(config.targets.serve.defaultConfiguration).toEqual('development'); - expect(config.targets.serve.configurations.development).toEqual({ - buildTarget: `example:build:development`, - dev: true, - }); - }); - - it('should add development configuration if no configurations at all', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - defaultConfiguration: 'production', - configurations: { production: {} }, - }, - serve: { - executor: '@nrwl/next:server', - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.defaultConfiguration).toEqual('production'); - expect(config.targets.build.configurations.production).toEqual({}); - expect(config.targets.build.configurations.development).toEqual({}); - - expect(config.targets.serve.defaultConfiguration).toEqual('development'); - expect(config.targets.serve.configurations.development).toEqual({ - buildTarget: `example:build:development`, - dev: true, - }); - }); - - it('should work without targets', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - projectType: 'application', - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - expect(config).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'example', - root: 'apps/example', - projectType: 'application', - }); - }); -}); diff --git a/packages/next/src/migrations/update-14-0-0/add-default-development-configurations.ts b/packages/next/src/migrations/update-14-0-0/add-default-development-configurations.ts deleted file mode 100644 index 7c47adf2fd2d8..0000000000000 --- a/packages/next/src/migrations/update-14-0-0/add-default-development-configurations.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((config, name) => { - let shouldUpdate = false; - if (config.targets?.build?.executor === '@nrwl/next:build') { - shouldUpdate = true; - config.targets.build.defaultConfiguration ??= 'production'; - config.targets.build.configurations ??= {}; - config.targets.build.configurations.development ??= {}; - } - - if (config.targets?.serve?.executor === '@nrwl/next:server') { - shouldUpdate = true; - config.targets.serve.defaultConfiguration ??= 'development'; - config.targets.serve.configurations ??= {}; - config.targets.serve.configurations.development ??= { - buildTarget: `${name}:build:development`, - dev: true, - }; - } - - if (shouldUpdate) updateProjectConfiguration(tree, name, config); - }); - - await formatFiles(tree); -} - -export default update; diff --git a/packages/next/src/migrations/update-14-4-3/add-dev-output-path.spec.ts b/packages/next/src/migrations/update-14-4-3/add-dev-output-path.spec.ts deleted file mode 100644 index 9742c753d2ad0..0000000000000 --- a/packages/next/src/migrations/update-14-4-3/add-dev-output-path.spec.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; -import update from './add-dev-output-path'; - -describe('React default development configuration', () => { - it('should add output path if it does not alreayd exist', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - configurations: { - development: {}, - }, - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.configurations.development.outputPath).toEqual( - 'tmp/apps/example' - ); - }); - - it('should skip update if outputPath already exists for development', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - configurations: { - development: { outputPath: '/tmp/some/custom/path' }, - }, - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.configurations.development.outputPath).toEqual( - '/tmp/some/custom/path' - ); - }); -}); diff --git a/packages/next/src/migrations/update-14-4-3/add-dev-output-path.ts b/packages/next/src/migrations/update-14-4-3/add-dev-output-path.ts deleted file mode 100644 index d526c2e31e53a..0000000000000 --- a/packages/next/src/migrations/update-14-4-3/add-dev-output-path.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { - formatFiles, - getProjects, - joinPathFragments, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((config, name) => { - if (config.targets?.build?.executor === '@nrwl/next:build') { - config.targets.build.configurations ??= {}; - config.targets.build.configurations.development ??= {}; - config.targets.build.configurations.development.outputPath ??= - joinPathFragments('tmp', config.sourceRoot); - updateProjectConfiguration(tree, name, config); - } - }); - - await formatFiles(tree); -} - -export default update; diff --git a/packages/next/src/migrations/update-14-5-3/add-gitignore-entry.ts b/packages/next/src/migrations/update-14-5-3/add-gitignore-entry.ts deleted file mode 100644 index 7975167533ee9..0000000000000 --- a/packages/next/src/migrations/update-14-5-3/add-gitignore-entry.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { formatFiles, Tree } from '@nx/devkit'; -import { addGitIgnoreEntry } from '../../utils/add-gitignore-entry'; - -export async function update(tree: Tree) { - addGitIgnoreEntry(tree); - await formatFiles(tree); -} - -export default update; diff --git a/packages/next/src/migrations/update-14-5-3/update-dev-output-path.spec.ts b/packages/next/src/migrations/update-14-5-3/update-dev-output-path.spec.ts deleted file mode 100644 index 756aee37d4ed1..0000000000000 --- a/packages/next/src/migrations/update-14-5-3/update-dev-output-path.spec.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; -import update from './update-dev-output-path'; - -describe('React default development configuration', () => { - it('should add output path if it does not alreayd exist', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - configurations: { - development: {}, - }, - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.configurations.development.outputPath).toEqual( - 'apps/example' - ); - }); - - it('should add output path is default generated pat', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - configurations: { - development: { outputPath: 'tmp/apps/example' }, - }, - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.configurations.development.outputPath).toEqual( - 'apps/example' - ); - }); - - it('should skip update if outputPath already exists for development and does not match expected path', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/next:build', - configurations: { - development: { outputPath: '.tmp/custom' }, - }, - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.configurations.development.outputPath).toEqual( - '.tmp/custom' - ); - }); -}); diff --git a/packages/next/src/migrations/update-14-5-3/update-dev-output-path.ts b/packages/next/src/migrations/update-14-5-3/update-dev-output-path.ts deleted file mode 100644 index ceea57814365d..0000000000000 --- a/packages/next/src/migrations/update-14-5-3/update-dev-output-path.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { - formatFiles, - getProjects, - joinPathFragments, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((config, name) => { - if (config.targets?.build?.executor === '@nrwl/next:build') { - config.targets.build.configurations ??= {}; - config.targets.build.configurations.development ??= {}; - if ( - !config.targets.build.configurations.development.outputPath || - config.targets.build.configurations.development.outputPath === - joinPathFragments('tmp', config.root) - ) { - config.targets.build.configurations.development.outputPath = - config.root; - updateProjectConfiguration(tree, name, config); - } - } - }); - - await formatFiles(tree); -} - -export default update; diff --git a/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts b/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts deleted file mode 100644 index e3387e4263930..0000000000000 --- a/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { updateNextEslint } from './update-next-eslint'; - -describe('Add next eslint 14.5.7', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'app1', { - root: 'apps/app1', - targets: { - build: { - executor: '@nrwl/next:build', - }, - }, - }); - - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - app1: {}, - }, - }) - ); - }); - - it('should update "next" config ignorePattern', async () => { - tree.write( - 'apps/app1/.eslintrc.json', - JSON.stringify({ - extends: ['../../.eslintrc.json'], - ignorePatterns: ['!**/*'], - }) - ); - - await updateNextEslint(tree); - - const result = readJson(tree, 'apps/app1/.eslintrc.json'); - expect(result.ignorePatterns).toContain('.next/**/*'); - }); - - it('should not update "next" config ignorePattern if .next pattern already exists', async () => { - tree.write( - 'apps/app1/.eslintrc.json', - JSON.stringify({ - extends: ['../../.eslintrc.json'], - ignorePatterns: ['!**/*', '.next/**/*', '/foo/bar'], - }) - ); - const before = readJson(tree, 'apps/app1/.eslintrc.json'); - - await updateNextEslint(tree); - - const result = readJson(tree, 'apps/app1/.eslintrc.json'); - expect(result.ignorePatterns).toEqual(before.ignorePatterns); - }); -}); diff --git a/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts b/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts deleted file mode 100644 index 3abb242c4b210..0000000000000 --- a/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { formatFiles, getProjects, Tree, updateJson } from '@nx/devkit'; - -export async function updateNextEslint(host: Tree) { - const projects = getProjects(host); - - projects.forEach((project) => { - if (project.targets?.build?.executor !== '@nrwl/next:build') return; - - const eslintPath = `${project.root}/.eslintrc.json`; - - if (!host.exists(eslintPath)) return; - - updateJson(host, eslintPath, (eslintConfig) => { - const nextIgnorePattern = '.next/**/*'; - - if (eslintConfig.ignorePatterns.indexOf(nextIgnorePattern) < 0) { - eslintConfig.ignorePatterns = [ - ...eslintConfig.ignorePatterns, - nextIgnorePattern, - ]; - } - return eslintConfig; - }); - }); - await formatFiles(host); -} - -export default updateNextEslint; diff --git a/packages/node/migrations.json b/packages/node/migrations.json index 4fb569ca35ee0..89963d817c4db 100644 --- a/packages/node/migrations.json +++ b/packages/node/migrations.json @@ -1,35 +1,5 @@ { "generators": { - "remove-webpack-5-packages": { - "cli": "nx", - "version": "13.0.0-beta.1", - "description": "Remove packages installed by Nx 12's `@nrwl/node:webpack5` generator.", - "factory": "./src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0" - }, - "rename-build-to-webpack": { - "cli": "nx", - "version": "13.8.5-beta.1", - "description": "Renames @nrwl/node:build to @nrwl/node:webpack", - "factory": "./src/migrations/update-13-8-5/rename-build-to-webpack" - }, - "rename-execute-to-node": { - "cli": "nx", - "version": "13.8.5-beta.1", - "description": "Renames @nrwl/node:execute to @nrwl/node:node", - "factory": "./src/migrations/update-13-8-5/rename-execute-to-node" - }, - "update-package-to-tsc": { - "cli": "nx", - "version": "13.8.5-beta.1", - "description": "Renames @nrwl/node:package to @nrwl/js:tsc", - "factory": "./src/migrations/update-13-8-5/update-package-to-tsc" - }, - "update-webpack-executor": { - "cli": "nx", - "version": "14.7.6-beta.1", - "description": "Update usages of webpack executors to @nrwl/webpack", - "factory": "./src/migrations/update-14-7-6/update-webpack-executor" - }, "update-16-0-0-add-nx-packages": { "cli": "nx", "version": "16.0.0-beta.1", @@ -55,24 +25,5 @@ "implementation": "./src/migrations/update-16-4-0/replace-node-executor" } }, - "packageJsonUpdates": { - "14.3.7": { - "version": "14.3.7-beta.0", - "packages": { - "@types/node": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.5": { - "version": "14.5.5-beta.0", - "packages": { - "@types/node": { - "version": "18.7.1", - "alwaysAddToPackageJson": false - } - } - } - } + "packageJsonUpdates": {} } diff --git a/packages/node/package.json b/packages/node/package.json index e7d94a1a382d4..46385595acadf 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -34,8 +34,7 @@ "@nx/devkit": "file:../devkit", "@nx/jest": "file:../jest", "@nx/js": "file:../js", - "@nx/linter": "file:../linter", - "@nx/workspace": "file:../workspace" + "@nx/linter": "file:../linter" }, "publishConfig": { "access": "public" diff --git a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts b/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts deleted file mode 100644 index 433db02429f76..0000000000000 --- a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import subject from './remove-deprecated-options-13-0-0'; - -describe('Migration: Remove deprecated options', () => { - it(`should remove deprecated node build options`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:build', - options: { - showCircularDependencies: false, - }, - configurations: { - production: { - showCircularDependencies: true, - }, - }, - }, - }, - }); - - await subject(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:build', - options: {}, - configurations: { - production: {}, - }, - }, - }, - }); - }); -}); diff --git a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts b/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts deleted file mode 100644 index 0eae99eefc1b2..0000000000000 --- a/packages/node/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - if (config.targets.build.executor !== '@nrwl/node:build') return; - - let updated = false; - - if ( - typeof config.targets.build?.configurations?.production?.[ - 'showCircularDependencies' - ] !== 'undefined' - ) { - delete config.targets.build.configurations.production[ - 'showCircularDependencies' - ]; - updated = true; - } - - if ( - typeof config.targets.build?.options?.['showCircularDependencies'] !== - 'undefined' - ) { - delete config.targets.build.options['showCircularDependencies']; - updated = true; - } - - if (updated) { - updateProjectConfiguration(host, name, config); - logger.info( - `NX Removed legacy build option from "${name}": showCircularDependencies` - ); - } - } - - await formatFiles(host); -} diff --git a/packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts b/packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts deleted file mode 100644 index a84c5800ae2fb..0000000000000 --- a/packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { readJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import subject from './remove-webpack-5-packages-13-0-0'; - -describe('Migration: Remove webpack 5 packages from Nx12', () => { - const webpack5Packages = { - webpack: '^5.0.0', - 'copy-webpack-plugin': '1.0.0', - 'webpack-merge': '1.0.0', - 'webpack-node-externals': '1.0.0', - 'mini-css-extract-plugin': '1.0.0', - 'source-map-loader': '1.0.0', - 'terser-webpack-plugin': '1.0.0', - 'webpack-dev-server': '1.0.0', - 'webpack-sources': '1.0.0', - 'react-refresh': '1.0.0', - '@pmmmwh/react-refresh-webpack-plugin': '1.0.0', - }; - - it.each` - version - ${'5.0.0'} - ${'~5.0.0'} - ${'^5.0.0'} - `( - `should remove packages installed via webpack5 generator`, - async ({ version }) => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - ...webpack5Packages, - webpack: version, - }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - }, - }); - } - ); - - it.each` - version - ${'4.0.0'} - ${'50.0.0'} - `( - `should not do anything if the webpack version is not 5`, - async ({ version }) => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - ...webpack5Packages, - webpack: version, - }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - ...webpack5Packages, - webpack: version, - }, - }); - } - ); - - it(`should not remove packages not every expected package is installed`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - webpack: '^5.0.0', - 'copy-webpack-plugin': '1.0.0', - }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - webpack: '^5.0.0', - 'copy-webpack-plugin': '1.0.0', - }, - }); - }); -}); diff --git a/packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts b/packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts deleted file mode 100644 index 353b4810e7ed0..0000000000000 --- a/packages/node/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { - formatFiles, - GeneratorCallback, - readJson, - removeDependenciesFromPackageJson, - Tree, -} from '@nx/devkit'; - -const packages = [ - 'webpack', - 'copy-webpack-plugin', - 'webpack-merge', - 'webpack-node-externals', - 'mini-css-extract-plugin', - 'source-map-loader', - 'terser-webpack-plugin', - 'webpack-dev-server', - 'webpack-sources', - 'react-refresh', - '@pmmmwh/react-refresh-webpack-plugin', -]; - -export default async function update(tree: Tree) { - const packageJson = readJson(tree, 'package.json'); - let task: undefined | GeneratorCallback = undefined; - - // Undo the install by `nx g @nrwl/web:webpack5` in Nx 12. - if ( - packageJson.devDependencies['webpack']?.match(/^([\^~])?5\./) && - packages.every((p) => packageJson.devDependencies[p]) - ) { - task = removeDependenciesFromPackageJson(tree, [], packages); - await formatFiles(tree); - } - - return task; -} diff --git a/packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.spec.ts b/packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.spec.ts deleted file mode 100644 index ce7e2bf6d6e0c..0000000000000 --- a/packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import rename from './rename-build-to-webpack'; - -describe('Migration: rename build to webpack', () => { - it(`should rename the "build" executor to "webpack"`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:build', - options: {}, - }, - }, - }); - - await rename(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:webpack', - options: {}, - }, - }, - }); - }); -}); diff --git a/packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.ts b/packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.ts deleted file mode 100644 index c9a3d803ba83e..0000000000000 --- a/packages/node/src/migrations/update-13-8-5/rename-build-to-webpack.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { - formatFiles, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; - -export default async function update(host: Tree) { - forEachExecutorOptions( - host, - '@nrwl/node:build', - (_, projectName, targetName) => { - const projectConfiguration = readProjectConfiguration(host, projectName); - projectConfiguration.targets[targetName].executor = '@nrwl/node:webpack'; - updateProjectConfiguration(host, projectName, projectConfiguration); - } - ); - - await formatFiles(host); -} diff --git a/packages/node/src/migrations/update-13-8-5/rename-execute-to-node.spec.ts b/packages/node/src/migrations/update-13-8-5/rename-execute-to-node.spec.ts deleted file mode 100644 index a59f09f23f428..0000000000000 --- a/packages/node/src/migrations/update-13-8-5/rename-execute-to-node.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import rename from './rename-execute-to-node'; - -describe('Migration: rename execute to node', () => { - it(`should rename the "execute" executor to "node"`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - serve: { - executor: '@nrwl/node:execute', - options: {}, - }, - }, - }); - - await rename(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - serve: { - executor: '@nrwl/node:node', - options: {}, - }, - }, - }); - }); -}); diff --git a/packages/node/src/migrations/update-13-8-5/rename-execute-to-node.ts b/packages/node/src/migrations/update-13-8-5/rename-execute-to-node.ts deleted file mode 100644 index 44492a3f0f82a..0000000000000 --- a/packages/node/src/migrations/update-13-8-5/rename-execute-to-node.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { - formatFiles, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; - -export default async function update(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/node:execute', - (_, projectName, targetName) => { - const projectConfiguration = readProjectConfiguration(tree, projectName); - projectConfiguration.targets[targetName].executor = '@nrwl/node:node'; - updateProjectConfiguration(tree, projectName, projectConfiguration); - } - ); - - await formatFiles(tree); -} diff --git a/packages/node/src/migrations/update-13-8-5/update-package-to-tsc.spec.ts b/packages/node/src/migrations/update-13-8-5/update-package-to-tsc.spec.ts deleted file mode 100644 index 20faacd62488a..0000000000000 --- a/packages/node/src/migrations/update-13-8-5/update-package-to-tsc.spec.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './update-package-to-tsc'; - -describe('Migration: rename package to tsc', () => { - it(`should rename the "package" executor to "tsc"`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:package', - options: {}, - }, - }, - }); - - await update(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/js:tsc', - options: {}, - }, - }, - }); - }); - - it(`should skip migration if no projects use @nrwl/js:node`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - const tasks = await update(tree); - - expect(tasks).toBeUndefined(); - }); - - it('should migrate srcRootForCompilationRoot option to rootDir', async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:package', - options: { - srcRootForCompilationRoot: '.', - }, - }, - }, - }); - - await update(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/js:tsc', - options: { - rootDir: '.', - }, - }, - }, - }); - }); -}); diff --git a/packages/node/src/migrations/update-13-8-5/update-package-to-tsc.ts b/packages/node/src/migrations/update-13-8-5/update-package-to-tsc.ts deleted file mode 100644 index 302ae27f2a225..0000000000000 --- a/packages/node/src/migrations/update-13-8-5/update-package-to-tsc.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { - addDependenciesToPackageJson, - formatFiles, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { nxVersion } from '@nx/workspace/src/utils/versions'; - -export default async function update(host: Tree) { - let installNeeded = false; - - forEachExecutorOptions( - host, - '@nrwl/node:package', - (_, projectName, targetName) => { - installNeeded = true; - const projectConfiguration = readProjectConfiguration(host, projectName); - - projectConfiguration.targets[targetName].executor = '@nrwl/js:tsc'; - - const transformers = - projectConfiguration.targets[targetName].options?.tsPlugins; - if (transformers) { - delete projectConfiguration.targets[targetName].options.tsPlugins; - projectConfiguration.targets[targetName].options.transformers = - transformers; - } - - if ( - projectConfiguration.targets[targetName].options - ?.srcRootForCompilationRoot - ) { - projectConfiguration.targets[targetName].options.rootDir = - projectConfiguration.targets[ - targetName - ].options.srcRootForCompilationRoot; - delete projectConfiguration.targets[targetName].options - .srcRootForCompilationRoot; - } - - updateProjectConfiguration(host, projectName, projectConfiguration); - } - ); - - const task = installNeeded - ? addDependenciesToPackageJson( - host, - {}, - { - '@nrwl/js': nxVersion, - } - ) - : undefined; - - await formatFiles(host); - - return task; -} diff --git a/packages/node/src/migrations/update-14-7-6/update-webpack-executor.spec.ts b/packages/node/src/migrations/update-14-7-6/update-webpack-executor.spec.ts deleted file mode 100644 index f96f2b5783ba4..0000000000000 --- a/packages/node/src/migrations/update-14-7-6/update-webpack-executor.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './update-webpack-executor'; - -describe('Migration: @nrwl/webpack', () => { - it(`should update usage of webpack executor`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/node:webpack', - options: {}, - }, - }, - }); - - await update(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/webpack:webpack', - options: { - compiler: 'tsc', - target: 'node', - }, - }, - }, - }); - }); -}); diff --git a/packages/node/src/migrations/update-14-7-6/update-webpack-executor.ts b/packages/node/src/migrations/update-14-7-6/update-webpack-executor.ts deleted file mode 100644 index 4f5579a3e679b..0000000000000 --- a/packages/node/src/migrations/update-14-7-6/update-webpack-executor.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { - formatFiles, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; - -export default async function update(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/node:webpack', - (options, projectName, targetName) => { - const projectConfig = readProjectConfiguration(tree, projectName); - projectConfig.targets[targetName].executor = '@nrwl/webpack:webpack'; - projectConfig.targets[targetName].options.compiler = 'tsc'; - projectConfig.targets[targetName].options.target = 'node'; - updateProjectConfiguration(tree, projectName, projectConfig); - } - ); - - await formatFiles(tree); -} diff --git a/packages/nx/migrations.json b/packages/nx/migrations.json index f3dddf4f46893..b0a038c80ade6 100644 --- a/packages/nx/migrations.json +++ b/packages/nx/migrations.json @@ -1,35 +1,5 @@ { "generators": { - "14-0-6-remove-root": { - "cli": "nx", - "version": "14.0.6", - "description": "Remove root property from project.json files", - "implementation": "./src/migrations/update-14-0-6/remove-roots" - }, - "14-2-0-add-json-schema": { - "cli": "nx", - "version": "14.2.0-beta.0", - "description": "Add JSON Schema to Nx configuration files", - "implementation": "./src/migrations/update-14-2-0/add-json-schema" - }, - "14-2-0-remove-default-collection": { - "cli": "nx", - "version": "14.2.0-beta.0", - "description": "Remove default collection from configuration to switch to prompts for collection", - "implementation": "./src/migrations/update-14-2-0/remove-default-collection" - }, - "14-2-0-replace-relative-outputs-with-absolute": { - "cli": "nx", - "version": "14.2.0-beta.5", - "description": "Replace all ./ and ../ in outputs with absolute paths", - "implementation": "./src/migrations/update-14-2-0/replace-all-relative-outputs-with-absolute" - }, - "14.3.4-create-target-defaults": { - "cli": "nx", - "version": "14.3.4-beta.1", - "description": "Replace targetDependencies with targetDefaults", - "implementation": "./src/migrations/update-14-3-4/create-target-defaults" - }, "15.0.0-migrate-to-inputs": { "cli": "nx", "version": "15.0.0-beta.1", diff --git a/packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts b/packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts deleted file mode 100644 index 21759e2a7f0ce..0000000000000 --- a/packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Tree } from '../../generators/tree'; -import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; -import { addProjectConfiguration } from '../../generators/utils/project-configuration'; -import { readJson, updateJson, writeJson } from '../../generators/utils/json'; -import removeRoots from './remove-roots'; -import { assertRunsAgainstNxRepo } from '../../internal-testing-utils/run-migration-against-this-workspace'; - -describe('remove-roots >', () => { - let tree: Tree; - - describe('projects with project.json configs', () => { - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should remove the root property', async () => { - addProjectConfiguration(tree, 'proj1', { - root: 'proj1', - }); - - updateJson(tree, 'proj1/project.json', (config) => ({ - ...config, - root: 'proj1', - })); - - await removeRoots(tree); - - expect(readJson(tree, 'proj1/project.json').root).toBeUndefined(); - }); - }); - - describe('projects with package.json configs', () => { - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - tree.delete('workspace.json'); - }); - - it('should remove the root property', async () => { - writeJson(tree, 'proj1/package.json', { - name: 'proj1', - }); - - await removeRoots(tree); - - expect(readJson(tree, 'proj1/package.json')).toEqual({ - name: 'proj1', - }); - }); - }); - - assertRunsAgainstNxRepo(removeRoots); -}); diff --git a/packages/nx/src/migrations/update-14-0-6/remove-roots.ts b/packages/nx/src/migrations/update-14-0-6/remove-roots.ts deleted file mode 100644 index 1b8e1a6b143ed..0000000000000 --- a/packages/nx/src/migrations/update-14-0-6/remove-roots.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Tree } from '../../generators/tree'; -import { - getProjects, - updateProjectConfiguration, -} from '../../generators/utils/project-configuration'; -import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; -import { join } from 'path'; - -export default async function (tree: Tree) { - // This looks like it does nothing, but this will actually effectively migrate over all the configs that need to be moved over, but won't touch configs that don't need to be moved - for (const [projName, projConfig] of getProjects(tree)) { - if (tree.exists(join(projConfig.root, 'project.json'))) { - updateProjectConfiguration(tree, projName, projConfig); - } - } - - await formatChangedFilesWithPrettierIfAvailable(tree); -} diff --git a/packages/nx/src/migrations/update-14-2-0/add-json-schema.spec.ts b/packages/nx/src/migrations/update-14-2-0/add-json-schema.spec.ts deleted file mode 100644 index c55b52742b3ee..0000000000000 --- a/packages/nx/src/migrations/update-14-2-0/add-json-schema.spec.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { assertRunsAgainstNxRepo } from '../../internal-testing-utils/run-migration-against-this-workspace'; -import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; -import type { Tree } from '../../generators/tree'; -import { readJson, writeJson } from '../../generators/utils/json'; -import { addProjectConfiguration } from '../../generators/utils/project-configuration'; -import addJsonSchema from './add-json-schema'; - -describe('add-json-schema >', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should update nx.json $schema', async () => { - const nxJson = readJson(tree, 'nx.json'); - delete nxJson['$schema']; - - await addJsonSchema(tree); - expect(readJson(tree, 'nx.json')['$schema']).toEqual( - './node_modules/nx/schemas/nx-schema.json' - ); - }); - - it('should update workspace.json $schema', async () => { - writeJson(tree, 'workspace.json', { version: 2, projects: {} }); - const workspaceJson = readJson(tree, 'workspace.json'); - delete workspaceJson['$schema']; - - await addJsonSchema(tree); - expect(readJson(tree, 'workspace.json')['$schema']).toEqual( - './node_modules/nx/schemas/workspace-schema.json' - ); - }); - - it('should update project.json $schema', async () => { - addProjectConfiguration( - tree, - 'test', - { root: 'libs/test', sourceRoot: 'libs/test/src', targets: {} }, - true - ); - addProjectConfiguration( - tree, - 'test-two', - { - root: 'libs/nested/test-two', - sourceRoot: 'libs/nested/test-two/src', - targets: {}, - }, - true - ); - - await addJsonSchema(tree); - expect(readJson(tree, 'libs/test/project.json')['$schema']).toEqual( - '../../node_modules/nx/schemas/project-schema.json' - ); - expect( - readJson(tree, 'libs/nested/test-two/project.json')['$schema'] - ).toEqual('../../../node_modules/nx/schemas/project-schema.json'); - }); - - assertRunsAgainstNxRepo(addJsonSchema); -}); diff --git a/packages/nx/src/migrations/update-14-2-0/add-json-schema.ts b/packages/nx/src/migrations/update-14-2-0/add-json-schema.ts deleted file mode 100644 index 6bdc49254a6ca..0000000000000 --- a/packages/nx/src/migrations/update-14-2-0/add-json-schema.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; -import { ProjectConfiguration } from '../../config/workspace-json-project-json'; -import type { Tree } from '../../generators/tree'; -import { updateJson } from '../../generators/utils/json'; -import { - getProjects, - getRelativeProjectJsonSchemaPath, - updateProjectConfiguration, -} from '../../generators/utils/project-configuration'; -import { logger } from '../../utils/logger'; -import { join } from 'path'; - -export default async function (tree: Tree) { - // update nx.json $schema - const isNxJsonExist = tree.exists('nx.json'); - if (isNxJsonExist) { - updateJson(tree, 'nx.json', (json) => { - if (!json['$schema']) { - json['$schema'] = './node_modules/nx/schemas/nx-schema.json'; - } - return json; - }); - } - - // update workspace.json $schema - const isWorkspaceJsonExist = tree.exists('workspace.json'); - if (isWorkspaceJsonExist) { - updateJson(tree, 'workspace.json', (json) => { - if (!json['$schema']) { - json['$schema'] = './node_modules/nx/schemas/workspace-schema.json'; - } - return json; - }); - } - - // update projects $schema - for (const [projName, projConfig] of getProjects(tree)) { - if ( - projConfig['$schema'] || - !tree.exists(join(projConfig.root, 'project.json')) - ) - continue; - - try { - const relativeProjectJsonSchemaPath = getRelativeProjectJsonSchemaPath( - tree, - projConfig - ); - updateProjectConfiguration(tree, projName, { - $schema: relativeProjectJsonSchemaPath, - ...projConfig, - } as ProjectConfiguration); - } catch (e) { - logger.warn(`Could not add schema for "${projName}": ${e.message}`); - } - } - - await formatChangedFilesWithPrettierIfAvailable(tree); -} diff --git a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts deleted file mode 100644 index cb01bdcdb216e..0000000000000 --- a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; -import type { Tree } from '../../generators/tree'; -import { - readNxJson, - updateNxJson, -} from '../../generators/utils/project-configuration'; -import { assertRunsAgainstNxRepo } from '../../internal-testing-utils/run-migration-against-this-workspace'; -import removeDefaultCollection from './remove-default-collection'; - -describe('remove-default-collection', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should remove default collection from nx.json', async () => { - const config = readNxJson(tree); - config.cli = { - defaultCollection: 'default-collection', - defaultProjectName: 'default-project', - }; - updateNxJson(tree, config); - - await removeDefaultCollection(tree); - - expect(readNxJson(tree).cli).toEqual({ - defaultProjectName: 'default-project', - }); - }); - - it('should remove cli entirely if defaultCollection was the only setting', async () => { - const config = readNxJson(tree); - config.cli = { - defaultCollection: 'default-collection', - }; - updateNxJson(tree, config); - - await removeDefaultCollection(tree); - - expect(readNxJson(tree).cli?.defaultCollection).toBeUndefined(); - }); - - it('should not error when "cli" is not defined', async () => { - const config = readNxJson(tree); - delete config.cli; - updateNxJson(tree, config); - - await expect(removeDefaultCollection(tree)).resolves.not.toThrow(); - }); - - it('should not error when nxJson does not exist', async () => { - tree.delete('nx.json'); - await expect(removeDefaultCollection(tree)).resolves.not.toThrow(); - }); - - assertRunsAgainstNxRepo(removeDefaultCollection); -}); diff --git a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts deleted file mode 100644 index ce5bbc235441f..0000000000000 --- a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Tree } from '../../generators/tree'; -import { readNxJson, updateNxJson } from '../../generators/utils/nx-json'; -import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; - -export default async function (tree: Tree) { - // If the workspace doesn't have a nx.json, don't make any changes - if (!tree.exists('nx.json')) { - return; - } - - const nxJson = readNxJson(tree); - - delete nxJson.cli?.defaultCollection; - if (nxJson.cli && Object.keys(nxJson.cli).length === 0) { - delete nxJson.cli; - } - - updateNxJson(tree, nxJson); - - await formatChangedFilesWithPrettierIfAvailable(tree); -} diff --git a/packages/nx/src/migrations/update-14-2-0/replace-all-relative-outputs-with-absolute.ts b/packages/nx/src/migrations/update-14-2-0/replace-all-relative-outputs-with-absolute.ts deleted file mode 100644 index 17af41ff8c3ee..0000000000000 --- a/packages/nx/src/migrations/update-14-2-0/replace-all-relative-outputs-with-absolute.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Tree } from '../../generators/tree'; -import { - getProjects, - updateProjectConfiguration, -} from '../../generators/utils/project-configuration'; -import { isRelativePath } from '../../utils/fileutils'; -import { joinPathFragments } from '../../utils/path'; -import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; - -export default async function (tree: Tree) { - for (const [name, value] of getProjects(tree).entries()) { - if (!value.targets) { - continue; - } - for (const t of Object.values(value.targets)) { - if (t.outputs) { - t.outputs = t.outputs.map((o) => - isRelativePath(o) ? joinPathFragments(value.root, o) : o - ); - } - } - updateProjectConfiguration(tree, name, value); - } - await formatChangedFilesWithPrettierIfAvailable(tree); -} diff --git a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts deleted file mode 100644 index 4207ae6ea9914..0000000000000 --- a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.spec.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { assertRunsAgainstNxRepo } from '../../internal-testing-utils/run-migration-against-this-workspace'; -import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; -import type { Tree } from '../../generators/tree'; -import { - readNxJson, - updateNxJson, -} from '../../generators/utils/project-configuration'; -import createTargetDefaults from './create-target-defaults'; - -describe('createTargetDefaults', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should work', async () => { - const nxJson = readNxJson(tree); - (nxJson as any).targetDependencies = { - a: [], - b: [ - 'bb', - { target: 'bbb', projects: 'self' }, - { target: 'c', projects: 'dependencies' }, - ], - }; - updateNxJson(tree, nxJson); - await createTargetDefaults(tree); - - const updated = readNxJson(tree); - expect(updated.targetDefaults).toEqual({ - a: { dependsOn: [] }, - b: { - dependsOn: ['bb', 'bbb', '^c'], - }, - }); - expect((updated as any).targetDependencies).toBeUndefined(); - }); - - it('should not error when nxJson does not exist', async () => { - tree.delete('nx.json'); - await expect(createTargetDefaults(tree)).resolves.not.toThrow(); - }); - - assertRunsAgainstNxRepo(createTargetDefaults); -}); diff --git a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts b/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts deleted file mode 100644 index 3e8cf737f1c86..0000000000000 --- a/packages/nx/src/migrations/update-14-3-4/create-target-defaults.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { TargetDependencyConfig } from '../../config/workspace-json-project-json'; -import { NxJsonConfiguration } from '../../config/nx-json'; -import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; -import { Tree } from '../../generators/tree'; -import { readNxJson, updateNxJson } from '../../generators/utils/nx-json'; - -export default async function (tree: Tree) { - // If the workspace doesn't have a nx.json, don't make any changes - if (!tree.exists('nx.json')) { - return; - } - - const nxJson: NxJsonConfiguration & { - targetDependencies?: Record; - } = readNxJson(tree); - - if (nxJson.targetDependencies) { - nxJson.targetDefaults = {}; - for (const targetName of Object.keys(nxJson.targetDependencies)) { - const dependsOn = []; - - for (const c of nxJson.targetDependencies[targetName]) { - if (typeof c === 'string') { - dependsOn.push(c); - } else if (c.projects === 'self') { - dependsOn.push(c.target); - } else { - dependsOn.push(`^${c.target}`); - } - } - - nxJson.targetDefaults[targetName] = { - dependsOn, - }; - } - } - delete nxJson.targetDependencies; - updateNxJson(tree, nxJson); - - await formatChangedFilesWithPrettierIfAvailable(tree); -} diff --git a/packages/plugin/migrations.json b/packages/plugin/migrations.json index 17a4c8cd19b39..6519989e617bf 100644 --- a/packages/plugin/migrations.json +++ b/packages/plugin/migrations.json @@ -1,17 +1,5 @@ { "generators": { - "add-swc-deps": { - "cli": "nx", - "version": "14.1.9-beta.0", - "description": "Adds @swc/core and @swc-node as a dev dep if you are using them", - "factory": "./src/migrations/update-14-1-9/add-swc-deps-if-needed" - }, - "add-swc-deps-again": { - "cli": "nx", - "version": "14.2.3-beta.0", - "description": "Adds @swc/core and @swc-node as a dev dep if you are using them (repeated due to bad version on earlier migration)", - "factory": "./src/migrations/update-14-1-9/add-swc-deps-if-needed" - }, "update-15-0-0": { "cli": "nx", "version": "15.0.0-beta.0", diff --git a/packages/plugin/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts b/packages/plugin/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts deleted file mode 100644 index c08a636953bd5..0000000000000 --- a/packages/plugin/src/migrations/update-14-1-9/add-swc-deps-if-needed.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { formatFiles, installPackagesTask, Tree } from '@nx/devkit'; -import { addSwcRegisterDependencies } from '@nx/js/src/utils/swc/add-swc-dependencies'; - -export default async function addSwcNodeIfNeeded(tree: Tree) { - addSwcRegisterDependencies(tree); - await formatFiles(tree); - return installPackagesTask(tree); -} diff --git a/packages/react-native/migrations.json b/packages/react-native/migrations.json index dcd9e42510c70..b902c4b33451d 100644 --- a/packages/react-native/migrations.json +++ b/packages/react-native/migrations.json @@ -1,71 +1,5 @@ { "generators": { - "update-jest-for-react-native": { - "version": "12.5.0-beta.0", - "cli": "nx", - "description": "Update jest for react native", - "factory": "./src/migrations/update-12-5-0/update-jest-for-react-native" - }, - "add-react-native-svg-12-10-0": { - "version": "12.10.0-beta.1", - "cli": "nx", - "description": "Add support to display svg in react native", - "factory": "./src/migrations/update-12-10-0/add-react-native-svg-12-10-0" - }, - "update-react-native-typing-svg-13-5-0": { - "version": "13.5.0-beta.0", - "cli": "nx", - "description": "Update typing for svg in react native", - "factory": "./src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0" - }, - "add-babel-config-root-13-5-0": { - "version": "13.5.0-beta.0", - "cli": "nx", - "description": "Add babel.config.json at root for react native workspace if it does not exist", - "factory": "./src/migrations/update-13-5-0/add-babel-config-root-13-5-0" - }, - "update-entry-file-bundle-14-0-0": { - "version": "14.0.0-beta.0", - "cli": "nx", - "description": "Udpate the entry file option under bundle target", - "factory": "./src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0" - }, - "add-project-root-metro-config-14-0-0": { - "version": "14.0.0-beta.0", - "cli": "nx", - "description": "Add projectRoot option in metro.config.js", - "factory": "./src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0" - }, - "change-main-to-class-name-14-0-2": { - "version": "14.0.3-beta.0", - "cli": "nx", - "description": "changes 'main' tag to project's className", - "factory": "./src/migrations/update-14-0-2/change-main-to-class-name-14-0-2" - }, - "rename-blockList-metro-config-14-2-1": { - "version": "14.2.1-beta.0", - "cli": "nx", - "description": "Rename blacklistRE to blockList in metro.config.js", - "factory": "./src/migrations/update-14-2-1/rename-blockList-metro-config" - }, - "add-exclude-sync-deps-14-5-5": { - "version": "14.5.5-beta.0", - "cli": "nx", - "description": "Change include field from string to array for sync-deps target", - "factory": "./src/migrations/update-14-5-5/add-exclude-sync-deps" - }, - "change-searchDir-storybook-14-5-8": { - "version": "14.5.8-beta.0", - "cli": "nx", - "description": "Change searchDir field from string to array for storybook target", - "factory": "./src/migrations/update-14-5-8/change-searchDir-storybook" - }, - "rename-jest-preprocessor-14-6-0": { - "version": "14.6.0-beta.0", - "cli": "nx", - "description": "Remove transform in jest.config", - "factory": "./src/migrations/update-14-6-0/remove-jest-transform" - }, "add-babel-inputs": { "cli": "nx", "version": "15.0.0-beta.0", @@ -110,912 +44,6 @@ } }, "packageJsonUpdates": { - "11.4.0": { - "version": "11.4.0-beta.0", - "packages": { - "metro": { - "version": "0.59.0", - "addToPackageJson": "devDependencies", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.59.0", - "addToPackageJson": "devDependencies", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "4.14.0", - "addToPackageJson": "devDependencies", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "4.14.0", - "addToPackageJson": "devDependencies", - "alwaysAddToPackageJson": false - }, - "react": { - "version": "17.0.1", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "16.9.56", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.63.4", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.63.18", - "alwaysAddToPackageJson": false - } - } - }, - "12.3.6": { - "version": "12.3.6-beta.0", - "packages": { - "react-native": { - "version": "0.64.1", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "17.0.6", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.64.5", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "5.0.1-alpha.2", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "5.0.1-alpha.1", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "5.0.1-alpha.2", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.66.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "7.2.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.1", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.66.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.66.0", - "alwaysAddToPackageJson": false - } - } - }, - "12.5.0": { - "version": "12.5.0-beta.0", - "packages": { - "react": { - "version": "17.0.2", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.65.0-rc.2", - "alwaysAddToPackageJson": false - }, - "react-test-renderer": { - "version": "17.0.2", - "alwaysAddToPackageJson": false - }, - "react-native-codegen": { - "version": "0.0.7", - "addToPackageJson": "devDependencies", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.64.10", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "6.0.0-rc.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "6.0.0-rc.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "6.0.0-rc.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "8.0.0-rc.0", - "alwaysAddToPackageJson": false - } - } - }, - "12.8.0": { - "version": "12.8.0-beta.0", - "packages": { - "react-native": { - "version": "0.65.1", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.64.13", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "17.0.19", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "6.0.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "6.0.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "6.0.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.2", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.66.2", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.66.2", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.66.2", - "alwaysAddToPackageJson": false - } - } - }, - "12.10.0-beta.1": { - "version": "12.10.0-beta.1", - "packages": { - "react-native-svg-transformer": { - "version": "0.14.3", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - }, - "react-native-svg": { - "version": "12.1.1", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - }, - "react-native": { - "version": "0.66.0", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.65.3", - "alwaysAddToPackageJson": false - } - } - }, - "13.0.0": { - "version": "13.0.0-beta.1", - "packages": { - "react-native": { - "version": "0.66.1", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.65.8", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "6.1.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "6.1.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "6.1.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "8.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "13.2.0": { - "version": "13.2.0-beta.0", - "packages": { - "react-native": { - "version": "0.66.2", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.66.2", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.4", - "alwaysAddToPackageJson": false - } - } - }, - "13.5.0": { - "version": "13.5.0-beta.0", - "packages": { - "react-native": { - "version": "0.66.4", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.66.11", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "6.3.1", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "6.3.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "6.2.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "9.0.0", - "alwaysAddToPackageJson": false - }, - "react-native-svg-transformer": { - "version": "1.0.0", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.16.7", - "alwaysAddToPackageJson": false - }, - "react-native-config": { - "version": "1.4.5", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - } - } - }, - "13.8.2": { - "version": "13.8.2-beta.0", - "packages": { - "react-native": { - "version": "0.67.2", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.66.15", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "7.0.1", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "7.0.1", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "7.0.1", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.67.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.67.0", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.67.0", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.17.2", - "alwaysAddToPackageJson": false - } - } - }, - "13.8.6": { - "version": "13.8.6-beta.0", - "packages": { - "react-native": { - "version": "0.67.3", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.67.2", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.69.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.69.0", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.69.0", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "12.3.0", - "alwaysAddToPackageJson": false - }, - "@react-native-async-storage/async-storage": { - "version": "1.16.1", - "alwaysAddToPackageJson": false - } - } - }, - "13.9.3": { - "version": "13.9.3-beta.0", - "packages": { - "@types/react-native": { - "version": "0.67.3", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.69.1", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.69.1", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.69.1", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.69.1", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.17.7", - "alwaysAddToPackageJson": false - }, - "@react-native-async-storage/async-storage": { - "version": "1.16.3", - "alwaysAddToPackageJson": false - } - } - }, - "13.10.0": { - "version": "13.10.0-beta.1", - "packages": { - "react-native": { - "version": "0.67.4", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.70.0", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "17.0.43", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.70.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "9.1.0", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.17.8", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.0-beta.0": { - "version": "14.0.0-beta.0", - "packages": { - "react-native": { - "version": "0.68.1", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.67.4", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.70.1", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.70.1", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.70.1", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - }, - "metro-config": { - "version": "0.70.1", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "7.0.3", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.70.1", - "alwaysAddToPackageJson": false - }, - "react-test-renderer": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.17.9", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.3": { - "version": "14.0.3-beta.0", - "packages": { - "@types/react-native": { - "version": "0.67.6", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.70.2", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.70.2", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.70.2", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.70.2", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.70.2", - "alwaysAddToPackageJson": false - } - } - }, - "14.1.8": { - "version": "14.1.8-beta.0", - "packages": { - "react-native": { - "version": "0.68.2", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.70.3", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.70.3", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.70.3", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.70.3", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.70.3", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.67.7", - "alwaysAddToPackageJson": false - }, - "react-test-renderer": { - "version": "18.1.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.1": { - "version": "14.2.1-beta.0", - "packages": { - "metro": { - "version": "0.71.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.71.0", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.71.0", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.71.0", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.71.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.5", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.18.3", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.67.8", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.5": { - "version": "14.2.5-beta.0", - "packages": { - "react-native-config": { - "version": "1.4.6", - "alwaysAddToPackageJson": false - }, - "@react-native-async-storage/async-storage": { - "version": "1.17.6", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.71.1", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.71.1", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.71.1", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.71.1", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.71.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.4.3": { - "version": "14.4.3-beta.0", - "packages": { - "metro": { - "version": "0.71.2", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.71.2", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.71.2", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.71.2", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.71.2", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "8.0.2", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "8.0.2", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "8.0.2", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.69.1", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.69.2", - "alwaysAddToPackageJson": false - }, - "@react-native-async-storage/async-storage": { - "version": "1.17.7", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "7.2.0", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.18.6", - "alwaysAddToPackageJson": false - } - } - }, - "14.4.4": { - "version": "14.4.4-beta.0", - "packages": { - "@types/react-native": { - "version": "0.69.3", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.71.3", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.71.3", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.71.3", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.71.3", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.71.3", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "8.0.3", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.0": { - "version": "14.5.0-beta.0", - "packages": { - "react-native": { - "version": "0.69.3", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "11.0.0", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "12.4.3", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.18.9", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "8.0.4", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "8.0.4", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "8.0.4", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.7": { - "version": "14.5.7-beta.0", - "packages": { - "@types/react-native": { - "version": "0.69.5", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.72.0", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.72.0", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.72.0", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.72.0", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.72.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "8.0.5", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "8.0.5", - "alwaysAddToPackageJson": false - }, - "react-native": { - "version": "0.69.4", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.11", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "12.4.4", - "alwaysAddToPackageJson": false - } - } - }, - "14.6.1": { - "version": "14.6.1-beta.0", - "packages": { - "metro": { - "version": "0.72.1", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.72.1", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.72.1", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.72.1", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.72.1", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "9.0.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "9.0.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "9.0.0", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "13.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.7.4-beta.0": { - "version": "14.7.4-beta.0", - "packages": { - "react-native": { - "version": "0.70.0", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.70.0", - "alwaysAddToPackageJson": false - }, - "metro": { - "version": "0.72.2", - "alwaysAddToPackageJson": false - }, - "metro-resolver": { - "version": "0.72.2", - "alwaysAddToPackageJson": false - }, - "metro-babel-register": { - "version": "0.72.2", - "alwaysAddToPackageJson": false - }, - "metro-config": { - "version": "0.72.2", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-preset": { - "version": "0.72.2", - "alwaysAddToPackageJson": false - }, - "metro-react-native-babel-transformer": { - "version": "0.72.2", - "alwaysAddToPackageJson": false, - "addToPackageJson": "devDependencies" - }, - "react-native-svg": { - "version": "13.1.0", - "alwaysAddToPackageJson": false - }, - "@babel/runtime": { - "version": "7.19.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli": { - "version": "9.1.1", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-android": { - "version": "9.1.0", - "alwaysAddToPackageJson": false - }, - "@react-native-community/cli-platform-ios": { - "version": "9.1.0", - "alwaysAddToPackageJson": false - }, - "@react-native-async-storage/async-storage": { - "version": "1.17.10", - "alwaysAddToPackageJson": false - } - } - }, - "14.7.13": { - "version": "14.7.13-beta.0", - "packages": { - "react-native": { - "version": "0.70.1", - "alwaysAddToPackageJson": false - }, - "@types/react-native": { - "version": "0.70.3", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-native": { - "version": "11.1.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/jest-native": { - "version": "4.0.12", - "alwaysAddToPackageJson": false - }, - "react-native-svg": { - "version": "13.2.0", - "alwaysAddToPackageJson": false - } - } - }, "15.0.0": { "version": "15.0.0-beta.0", "packages": { diff --git a/packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.spec.ts b/packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.spec.ts deleted file mode 100644 index 05478802349fa..0000000000000 --- a/packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.spec.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { - reactNativeSvgTransformerVersion, - reactNativeSvgVersion, -} from '../../utils/versions'; -import update from './add-react-native-svg-12-10-0'; - -describe('Add react-native-svg to dev dependencies', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/products/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - }); - - it(`should add react-native-svg to app's tsconfig.json and package.json`, async () => { - tree.write('apps/products/tsconfig.json', '{}'); - tree.write( - 'apps/products/package.json', - JSON.stringify({ - dependencies: {}, - }) - ); - tree.write( - 'apps/products/jest.config.js', - `module.exports = { - preset: 'react-native', - };` - ); - await update(tree); - - const tsconfig = readJson(tree, 'apps/products/tsconfig.json'); - expect(tsconfig.files).toEqual([ - '../../node_modules/@nrwl/react-native/typings/svg.d.ts', - ]); - - const packageJson = readJson(tree, 'apps/products/package.json'); - expect(packageJson.dependencies).toEqual({ 'react-native-svg': '*' }); - - const jestConfig = tree.read('apps/products/jest.config.js', 'utf-8'); - expect(jestConfig).toContain( - `moduleNameMapper: { '.svg': '@nrwl/react-native/plugins/jest/svg-mock' },` - ); - }); - - it(`should not add react-native-svg to app's tsconfig.json and package.json if files do not exist`, async () => { - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { 'react-native': '*' }, - devDependencies: {}, - }) - ); - - await update(tree); - - expect(() => readJson(tree, 'apps/products/tsconfig.json')).toThrow(); - expect(() => readJson(tree, 'apps/products/package.json')).toThrow(); - }); -}); diff --git a/packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.ts b/packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.ts deleted file mode 100644 index 077767ba04165..0000000000000 --- a/packages/react-native/src/migrations/update-12-10-0/add-react-native-svg-12-10-0.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - Tree, - formatFiles, - getProjects, - updateJson, - offsetFromRoot, - ProjectConfiguration, - logger, - stripIndents, -} from '@nx/devkit'; - -/** - * Add support to display svg in react native: - * - Add react-native-svg-transform and react-native-svg packages to workspace's package.json. - * - Add typing to app's tsconfig.json. - * - Add react-native-svg to app's package.json. - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((project) => { - if (project.targets?.start?.executor !== '@nrwl/react-native:start') return; - - addReactNativeSvgToAppPackageJson(tree, project); - addReactNativeSvgToTsconfig(tree, project); - mockSvgInJestConfig(tree, project); - }); - - await formatFiles(tree); -} - -function addReactNativeSvgToAppPackageJson( - host: Tree, - project: ProjectConfiguration -) { - const packageJSonPath = `${project.root}/package.json`; - if (!host.exists(packageJSonPath)) return; - updateJson(host, packageJSonPath, (json) => { - const dependencies = json.dependencies || {}; - dependencies['react-native-svg'] = '*'; - return json; - }); -} - -function addReactNativeSvgToTsconfig( - host: Tree, - project: ProjectConfiguration -) { - const tsconfigPath = `${project.root}/tsconfig.json`; - if (!host.exists(tsconfigPath)) return; - const offset = offsetFromRoot(project.root); - updateJson(host, tsconfigPath, (json) => { - const files = json.files || []; - files.push(`${offset}node_modules/@nrwl/react-native/typings/svg.d.ts`); - json.files = files; - return json; - }); -} - -function mockSvgInJestConfig(host: Tree, project: ProjectConfiguration) { - const jestConfigPath = project.targets?.test?.options?.jestConfig; - if (!jestConfigPath || !host.exists(jestConfigPath)) return; - try { - const contents = host.read(jestConfigPath, 'utf-8'); - if (contents.includes('moduleNameMapper')) return; - host.write( - jestConfigPath, - contents.replace( - /,([^,]*)$/, - `, moduleNameMapper: {'\\.svg': '@nrwl/react-native/plugins/jest/svg-mock'}, $1` - ) - ); - } catch { - logger.error( - stripIndents`Unable to update ${jestConfigPath} for project ${project.root}.` - ); - } -} diff --git a/packages/react-native/src/migrations/update-12-5-0/update-jest-for-react-native.ts b/packages/react-native/src/migrations/update-12-5-0/update-jest-for-react-native.ts deleted file mode 100644 index 18ce967355f4f..0000000000000 --- a/packages/react-native/src/migrations/update-12-5-0/update-jest-for-react-native.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { - formatFiles, - logger, - readProjectConfiguration, - stripIndents, - Tree, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { join } from 'path'; -import { JestExecutorOptions } from '@nx/jest/src/executors/jest/schema'; - -/** - * This function update jest.config.js and test.setup.ts for react native project for Jest 27. - * Inside jest.config.js, remove ...workspacePreset because it has testEnvironment set as jsdom. - * Just set preset as react-native is sufficient. - * Also remove the jest.useFakeTimers() in test.setup.ts. - */ -function updateJestConfig(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, project) => { - if (!options.jestConfig) { - return; - } - - const jestConfigPath = options.jestConfig; - const jestConfig = require(join(tree.root, jestConfigPath)); - const testEnvironment = jestConfig.testEnvironment; - const preset = jestConfig.preset; - - if (testEnvironment === 'node' || preset !== 'react-native') { - return; - } - - try { - const contents = tree.read(jestConfigPath, 'utf-8'); - tree.write( - jestConfigPath, - contents - .replace( - `...workspacePreset,`, - "resolver: '@nrwl/jest/plugins/resolver'," - ) - .replace( - `const workspacePreset = require('../../jest.preset');`, - '' - ) - ); - } catch { - logger.error( - stripIndents`Unable to update jest.config.js for project ${project}.` - ); - } - - try { - const { root } = readProjectConfiguration(tree, project); - let setupTestPath: string; - if (tree.exists(join(root, `test-setup.ts`))) { - setupTestPath = join(root, `test-setup.ts`); - } else if (tree.exists(join(root, `test-setup.js`))) { - setupTestPath = join(root, `test-setup.js`); - } - - if (setupTestPath) { - const contents = tree.read(setupTestPath, 'utf-8'); - tree.write( - setupTestPath, - contents - .replace(`jest.useFakeTimers();`, '') - .replace(`import { jest } from '@jest/globals';`, '') - ); - } - } catch { - logger.error( - stripIndents`Unable to update test-setup for project ${project}.` - ); - } - } - ); -} - -export default async function update(tree: Tree) { - updateJestConfig(tree); - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.spec.ts b/packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.spec.ts deleted file mode 100644 index 2a4d0484de158..0000000000000 --- a/packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.spec.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './add-babel-config-root-13-5-0'; - -describe('Add react-native-svg to dev dependencies', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/products/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - }); - - it(`should add babel.config.json at root`, async () => { - await update(tree); - - const babelConfigJson = readJson(tree, 'babel.config.json'); - expect(babelConfigJson).toEqual({ - babelrcRoots: ['*'], - }); - }); - - it(`should not change babel.config.json if it already exists`, async () => { - tree.write('babel.config.json', '{}'); - - await update(tree); - - const babelConfigJson = readJson(tree, 'babel.config.json'); - expect(babelConfigJson).toEqual({}); - }); -}); diff --git a/packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.ts b/packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.ts deleted file mode 100644 index a8363a3539876..0000000000000 --- a/packages/react-native/src/migrations/update-13-5-0/add-babel-config-root-13-5-0.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { formatFiles, getProjects, Tree } from '@nx/devkit'; -import { addBabelInputs } from '@nx/js/src/utils/add-babel-inputs'; - -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - if (tree.exists('/babel.config.json') || tree.exists('/babel.config.js')) { - return; - } - - const hasReactNaiveProject = Array.from(projects) - .map(([_, project]) => project) - .some( - (project) => - project.targets?.start?.executor === '@nrwl/react-native:start' - ); - - if (hasReactNaiveProject) { - addBabelInputs(tree); - } - - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.spec.ts b/packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.spec.ts deleted file mode 100644 index 3ec1e7e9f8508..0000000000000 --- a/packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './update-react-native-typing-svg-13-5-0'; - -describe('Update svg typings in tsconfig for react native app', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/products/jest.config.js', - passWithNoTests: true, - }, - }, - }, - }); - }); - - it(`should add svg typing to tsconfig.json`, async () => { - tree.write('apps/products/tsconfig.json', '{}'); - await update(tree); - - const tsconfig = readJson(tree, 'apps/products/tsconfig.json'); - expect(tsconfig.files).toEqual([ - '../../node_modules/@nrwl/react-native/typings/svg.d.ts', - ]); - }); - - it(`should update to svg typing in tsconfig.json if image typing from react exists`, async () => { - tree.write( - 'apps/products/tsconfig.json', - `{ - "files": ["../../node_modules/@nrwl/react/typings/image.d.ts"] - }` - ); - await update(tree); - - const tsconfig = readJson(tree, 'apps/products/tsconfig.json'); - expect(tsconfig.files).toEqual([ - '../../node_modules/@nrwl/react-native/typings/svg.d.ts', - ]); - }); - - it(`should update app's tsconfig.json and package.json if file does not exist`, async () => { - await update(tree); - - expect(() => readJson(tree, 'apps/products/tsconfig.json')).toThrow(); - }); -}); diff --git a/packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.ts b/packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.ts deleted file mode 100644 index fd1972f2c788d..0000000000000 --- a/packages/react-native/src/migrations/update-13-5-0/update-react-native-typing-svg-13-5-0.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - Tree, - formatFiles, - getProjects, - updateJson, - offsetFromRoot, - ProjectConfiguration, -} from '@nx/devkit'; - -/** - * Update svg typings in tsconfig for react native app - * Replace node_modules/@nrwl/react/typings/image.d.ts with node_modules/@nrwl/react-native/typings/svg.d.ts - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((project) => { - if (project.targets?.start?.executor !== '@nrwl/react-native:start') return; - updateReactNativeSvgTypingInTsconfig(tree, project); - }); - - await formatFiles(tree); -} - -function updateReactNativeSvgTypingInTsconfig( - host: Tree, - project: ProjectConfiguration -) { - const tsconfigPath = `${project.root}/tsconfig.json`; - if (!host.exists(tsconfigPath)) return; - const offset = offsetFromRoot(project.root); - updateJson(host, tsconfigPath, (json) => { - const files = json.files || []; - const imageTypingIndex = files.findIndex( - (file) => file === `${offset}node_modules/@nrwl/react/typings/image.d.ts` - ); - const reactNativeSvgTypingPath = `${offset}node_modules/@nrwl/react-native/typings/svg.d.ts`; - if (imageTypingIndex === -1) { - files.push(reactNativeSvgTypingPath); - } else { - files[imageTypingIndex] = reactNativeSvgTypingPath; - } - json.files = files; - return json; - }); -} diff --git a/packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts b/packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts deleted file mode 100644 index 5ca8fecf60365..0000000000000 --- a/packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.spec.ts +++ /dev/null @@ -1,192 +0,0 @@ -import { addProjectConfiguration, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './add-project-root-metro-config-14-0-0'; - -describe('Add projectRoot option in metro.config.js', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - }, - }); - }); - - it(`should update metro.config.js and add key projectRoot`, async () => { - tree.write( - 'apps/products/metro.config.js', - ` -const { withNxMetro } = require('@nx/react-native'); -const { getDefaultConfig } = require('metro-config'); - -module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); -})(); -` - ); - await update(tree); - - expect(tree.read('apps/products/metro.config.js', 'utf-8')) - .toMatchInlineSnapshot(` - "const { withNxMetro } = require('@nx/react-native'); - const { getDefaultConfig } = require('metro-config'); - - module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - projectRoot: __dirname, - watchFolders: [], - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); - })(); - " - `); - }); - - it(`should not udpate metro.config.js if projectRoot already exists`, async () => { - tree.write( - 'apps/products/metro.config.js', - ` -const { withNxMetro } = require('@nx/react-native'); -const { getDefaultConfig } = require('metro-config'); - -module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - projectRoot: __dirname, - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); -})(); -` - ); - await update(tree); - - expect(tree.read('apps/products/metro.config.js', 'utf-8')) - .toMatchInlineSnapshot(` - "const { withNxMetro } = require('@nx/react-native'); - const { getDefaultConfig } = require('metro-config'); - - module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - projectRoot: __dirname, - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); - })(); - " - `); - }); -}); diff --git a/packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts b/packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts deleted file mode 100644 index d50532537cc07..0000000000000 --- a/packages/react-native/src/migrations/update-14-0-0/add-project-root-metro-config-14-0-0.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - stripIndents, - Tree, -} from '@nx/devkit'; - -/** - * Add projectRoot and watchFolders options in metro.config.js - * @param tree - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((project) => { - const metroConfigPath = `${project.root}/metro.config.js`; - if ( - project.targets?.start?.executor !== '@nrwl/react-native:start' || - !tree.exists(metroConfigPath) - ) - return; - try { - const metroConfigContent = tree.read(metroConfigPath, 'utf-8'); - if (metroConfigContent.includes('projectRoot: __dirname')) { - return; - } - tree.write( - metroConfigPath, - metroConfigContent.replace( - 'debug: ', - 'projectRoot: __dirname, watchFolders: [], debug: ' - ) - ); - } catch { - logger.error( - stripIndents`Unable to update ${metroConfigPath} for project ${project.root}.` - ); - } - }); - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.spec.ts b/packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.spec.ts deleted file mode 100644 index f550d26fb0467..0000000000000 --- a/packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.spec.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { addProjectConfiguration, Tree, getProjects } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './update-entry-file-bundle-14-0-0'; - -describe('Update entryFile for bundle target for react native apps', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - 'bundle-ios': { - executor: '@nrwl/react-native:bundle', - options: { - entryFile: 'apps/mobile/src/main.tsx', - platform: 'ios', - bundleOutput: 'dist/apps/mobile/ios/main.jsbundle', - }, - }, - 'bundle-android': { - executor: '@nrwl/react-native:bundle', - options: { - entryFile: 'apps/mobile/src/main.tsx', - platform: 'android', - bundleOutput: 'dist/apps/mobile/android/main.jsbundle', - }, - }, - }, - }); - }); - - it(`should update entryFile option`, async () => { - tree.write('apps/products/src/main.tsx', ''); - - await update(tree); - - getProjects(tree).forEach((project) => { - expect(project.targets['bundle-ios']).toEqual({ - executor: '@nrwl/react-native:bundle', - options: { - entryFile: 'src/main.tsx', - platform: 'ios', - bundleOutput: 'dist/apps/mobile/ios/main.jsbundle', - }, - }); - - expect(project.targets['bundle-android']).toEqual({ - executor: '@nrwl/react-native:bundle', - options: { - entryFile: 'src/main.tsx', - platform: 'android', - bundleOutput: 'dist/apps/mobile/android/main.jsbundle', - }, - }); - }); - }); - - it(`should not update entryFile option if the file does not exist`, async () => { - await update(tree); - - getProjects(tree).forEach((project) => { - expect(project.targets['bundle-ios']).toEqual({ - executor: '@nrwl/react-native:bundle', - options: { - entryFile: 'apps/mobile/src/main.tsx', - platform: 'ios', - bundleOutput: 'dist/apps/mobile/ios/main.jsbundle', - }, - }); - - expect(project.targets['bundle-android']).toEqual({ - executor: '@nrwl/react-native:bundle', - options: { - entryFile: 'apps/mobile/src/main.tsx', - platform: 'android', - bundleOutput: 'dist/apps/mobile/android/main.jsbundle', - }, - }); - }); - }); -}); diff --git a/packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.ts b/packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.ts deleted file mode 100644 index b353e2c547917..0000000000000 --- a/packages/react-native/src/migrations/update-14-0-0/update-entry-file-bundle-14-0-0.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { join } from 'path'; - -/** - * This function udpate the entry file option under bundle target for react native apps - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - const updateTargetEntryFile = (target: string, config) => { - if (!config.targets?.[target]?.options?.entryFile) { - return; - } - if (tree.exists(join(config.root, 'src/main.tsx'))) { - config.targets[target].options.entryFile = `src/main.tsx`; - } - if (tree.exists(join(config.root, 'src/main.js'))) { - config.targets[target].options.entryFile = `src/main.js`; - } - }; - - for (const [name, config] of projects.entries()) { - if ( - config.targets?.['bundle-ios']?.executor === '@nrwl/react-native:bundle' - ) { - updateTargetEntryFile('bundle-ios', config); - } - - if ( - config.targets?.['bundle-android']?.executor === - '@nrwl/react-native:bundle' - ) { - updateTargetEntryFile('bundle-android', config); - } - - updateProjectConfiguration(tree, name, config); - } - - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.spec.ts b/packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.spec.ts deleted file mode 100644 index 4aa0a71aee436..0000000000000 --- a/packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.spec.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { addProjectConfiguration, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './change-main-to-class-name-14-0-2'; - -describe('Change from main tag to className tag', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - }, - }); - }); - - it(`should udpate main file to registerComponent className`, async () => { - tree.write( - 'apps/products/src/main.tsx', - `AppRegistry.registerComponent('main', () => App);` - ); - await update(tree); - - expect(tree.read('apps/products/src/main.tsx', 'utf-8')).toEqual( - `AppRegistry.registerComponent('Products', () => App);\n` - ); - }); - - it(`should not udpate main file to registerComponent className if it does not exists`, async () => { - tree.write( - 'apps/products/src/main.tsx', - `AppRegistry.registerComponent('otherTagName', () => App);` - ); - await update(tree); - - expect(tree.read('apps/products/src/main.tsx', 'utf-8')).toEqual( - `AppRegistry.registerComponent('otherTagName', () => App);` - ); - }); -}); diff --git a/packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.ts b/packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.ts deleted file mode 100644 index 0579cca832a04..0000000000000 --- a/packages/react-native/src/migrations/update-14-0-2/change-main-to-class-name-14-0-2.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - names, - stripIndents, - Tree, -} from '@nx/devkit'; -import { join } from 'path'; - -/** - * This function changes "main" tag to project's className - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - for (const [name, config] of projects.entries()) { - if (config.targets?.start?.executor !== '@nrwl/react-native:start') - continue; - let mailFilePath; - if (tree.exists(join(config.root, 'src/main.tsx'))) { - mailFilePath = join(config.root, 'src/main.tsx'); - } - if (tree.exists(join(config.root, 'src/main.js'))) { - mailFilePath = join(config.root, 'src/main.js'); - } - if (!mailFilePath) { - continue; - } - try { - const { className } = names(name); - const content = tree.read(mailFilePath, 'utf-8'); - if (!content.includes(`'main'`)) { - return; - } - tree.write(mailFilePath, content.replace(`'main'`, `'${className}'`)); - } catch { - logger.error( - stripIndents`Unable to update ${mailFilePath} for project ${name}.` - ); - } - } - - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.spec.ts b/packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.spec.ts deleted file mode 100644 index 3ef5749c3cd90..0000000000000 --- a/packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.spec.ts +++ /dev/null @@ -1,190 +0,0 @@ -import { addProjectConfiguration, Tree, getProjects } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './rename-blockList-metro-config'; - -describe('Rename blacklistRE to blockList in metro.config.js for react native apps', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - }, - }); - }); - - it(`should udpate metro.config.js and Rename blacklistRE to blockList`, async () => { - tree.write( - 'apps/products/metro.config.js', - ` -const { withNxMetro } = require('@nx/react-native'); -const { getDefaultConfig } = require('metro-config'); - -module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - blacklistRE: exclusionList([/\.\/dist\/.*/]), - }, - }, - { - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); -})(); -` - ); - await update(tree); - - expect(tree.read('apps/products/metro.config.js', 'utf-8')).toEqual(` -const { withNxMetro } = require('@nx/react-native'); -const { getDefaultConfig } = require('metro-config'); - -module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - blockList: exclusionList([/\.\/dist\/.*/]), - }, - }, - { - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); -})(); -`); - }); - - it(`should not udpate metro.config.js if blacklistRE does not exist`, async () => { - tree.write( - 'apps/products/metro.config.js', - ` -const { withNxMetro } = require('@nx/react-native'); -const { getDefaultConfig } = require('metro-config'); - -module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - projectRoot: __dirname, - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); -})(); -` - ); - await update(tree); - - expect(tree.read('apps/products/metro.config.js', 'utf-8')) - .toMatchInlineSnapshot(` - "const { withNxMetro } = require('@nx/react-native'); - const { getDefaultConfig } = require('metro-config'); - - module.exports = (async () => { - const { - resolver: { sourceExts, assetExts }, - } = await getDefaultConfig(); - // console.log(getModulesRunBeforeMainModule); - return withNxMetro( - { - transformer: { - getTransformOptions: async () => ({ - transform: { - experimentalImportSupport: false, - inlineRequires: true, - }, - }), - babelTransformerPath: require.resolve('react-native-svg-transformer'), - }, - resolver: { - assetExts: assetExts.filter((ext) => ext !== 'svg'), - sourceExts: [...sourceExts, 'svg'], - resolverMainFields: ['sbmodern', 'browser', 'main'], - }, - }, - { - projectRoot: __dirname, - // Change this to true to see debugging info. - // Useful if you have issues resolving modules - debug: false, - // all the file extensions used for imports other than 'ts', 'tsx', 'js', 'jsx' - extensions: [], - } - ); - })(); - " - `); - }); -}); diff --git a/packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.ts b/packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.ts deleted file mode 100644 index f383bfe6287d0..0000000000000 --- a/packages/react-native/src/migrations/update-14-2-1/rename-blockList-metro-config.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - stripIndents, - Tree, -} from '@nx/devkit'; - -/** - * Rename blacklistRE to blockList in metro.config.js - * @param tree - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((project) => { - const metroConfigPath = `${project.root}/metro.config.js`; - if ( - project.targets?.start?.executor !== '@nrwl/react-native:start' || - !tree.exists(metroConfigPath) - ) - return; - - try { - const metroConfigContent = tree.read(metroConfigPath, 'utf-8'); - if (!metroConfigContent.includes('blacklistRE:')) { - return; - } - tree.write( - metroConfigPath, - metroConfigContent.replace('blacklistRE:', 'blockList:') - ); - } catch { - logger.error( - stripIndents`Unable to update ${metroConfigPath} for project ${project.root}.` - ); - } - }); - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.spec.ts b/packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.spec.ts deleted file mode 100644 index 5cc579354ad03..0000000000000 --- a/packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - addProjectConfiguration, - readProjectConfiguration, - Tree, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './add-exclude-sync-deps'; - -describe('add-exclude-sync-deps', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - 'sync-deps': { - executor: '@nrwl/react-native:sync-deps', - options: { - include: 'react-native-reanmiated,react-native-screens', - }, - }, - }, - }); - }); - - it(`should change include from string to array`, async () => { - await update(tree); - - const projectConfig = readProjectConfiguration(tree, 'products'); - expect(projectConfig.targets['sync-deps']).toEqual({ - executor: '@nrwl/react-native:sync-deps', - options: { - include: ['react-native-reanmiated', 'react-native-screens'], - }, - }); - }); -}); diff --git a/packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.ts b/packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.ts deleted file mode 100644 index d41f60da8d439..0000000000000 --- a/packages/react-native/src/migrations/update-14-5-5/add-exclude-sync-deps.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -/** - * This function changes include field from string to array for sync-deps target - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - for (const [name, config] of projects.entries()) { - if ( - config.targets?.['sync-deps']?.executor !== '@nrwl/react-native:sync-deps' - ) - continue; - const include = config.targets?.['sync-deps']?.options?.include; - if (!include || !include.length) { - continue; - } - config.targets['sync-deps'].options.include = include.split(','); - updateProjectConfiguration(tree, name, config); - } - - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.spec.ts b/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.spec.ts deleted file mode 100644 index 1fba4f3de1ef5..0000000000000 --- a/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - addProjectConfiguration, - readProjectConfiguration, - Tree, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './change-searchDir-storybook'; - -describe('change-searchDir-storybook', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - storybook: { - executor: '@nrwl/react-native:storybook', - options: { - searchDir: 'apps/products', - }, - }, - }, - }); - }); - - it(`should change searchDir from string to array`, async () => { - await update(tree); - - const projectConfig = readProjectConfiguration(tree, 'products'); - expect(projectConfig.targets['storybook']).toEqual({ - executor: '@nrwl/react-native:storybook', - options: { - searchDir: ['apps/products'], - }, - }); - }); -}); diff --git a/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts b/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts deleted file mode 100644 index e643841124b14..0000000000000 --- a/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -/** - * This function changes searchDir field from string to array for storybook target - */ -export default async function update(tree: Tree) { - const projects = getProjects(tree); - - for (const [name, config] of projects.entries()) { - if ( - config.targets?.['storybook']?.executor !== '@nrwl/react-native:storybook' - ) - continue; - const searchDir = config.targets?.['storybook']?.options?.searchDir; - if (!searchDir || !searchDir.length || Array.isArray(searchDir)) { - continue; - } - config.targets['storybook'].options.searchDir = searchDir.split(','); - updateProjectConfiguration(tree, name, config); - } - - await formatFiles(tree); -} diff --git a/packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.spec.ts b/packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.spec.ts deleted file mode 100644 index 7e1785c227687..0000000000000 --- a/packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.spec.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './remove-jest-transform'; - -describe('Rename jest preprocessor', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'products', { - root: 'apps/products', - sourceRoot: 'apps/products/src', - targets: { - start: { - executor: '@nrwl/react-native:start', - options: { - port: 8081, - }, - }, - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'apps/products/jest.config.ts', - passWithNoTests: true, - }, - }, - }, - }); - }); - - it(`should not remove transfrom if the code does not contain existing preprocessor`, async () => { - tree.write( - 'apps/products/jest.config.ts', - `module.exports = { - preset: 'react-native', - };` - ); - await update(tree); - - const jestConfig = tree.read('apps/products/jest.config.ts', 'utf-8'); - expect(jestConfig).not.toContain(`transform`); - }); - - it(`should remove transform if the code contains existing preprocessor`, async () => { - tree.write( - 'apps/products/jest.config.ts', - `module.exports = { - preset: 'react-native', - testRunner: 'jest-jasmine2', - transform: { - '\\.(js|ts|tsx)$': require.resolve('react-native/jest/preprocessor.js'), - '^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve( - 'react-native/jest/assetFileTransformer.js' - ), - } - };` - ); - await update(tree); - - const jestConfig = tree.read('apps/products/jest.config.ts', 'utf-8'); - expect(jestConfig).not.toContain('transfrom: {'); - expect(jestConfig).not.toContain(`testRunner: 'jest-jasmine2',`); - }); - - it(`should rename .babelrc to babel.config.json`, async () => { - tree.write( - 'apps/products/jest.config.ts', - `module.exports = { - preset: 'react-native', - };` - ); - tree.write( - 'apps/products/.babelrc', - `{ - "presets": ["module:metro-react-native-babel-preset"] - }` - ); - await update(tree); - - expect(tree.exists('apps/products/.babelrc')).toBeFalsy(); - expect(tree.exists('apps/products/babel.config.json')).toBeTruthy(); - const babelConfigJson = tree.read( - 'apps/products/babel.config.json', - 'utf-8' - ); - expect(babelConfigJson).toContain( - `"presets": ["module:metro-react-native-babel-preset"]` - ); - }); - - it(`should not rename .babelrc to babel.config.json if app is not react native`, async () => { - tree.write( - 'apps/products/jest.config.ts', - `module.exports = { - preset: 'other', - };` - ); - tree.write( - 'apps/products/.babelrc', - `{ - "presets": ["module:metro-react-native-babel-preset"] - }` - ); - await update(tree); - - expect(tree.exists('apps/products/.babelrc')).toBeTruthy(); - expect(tree.exists('apps/products/babel.config.json')).toBeFalsy(); - }); -}); diff --git a/packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.ts b/packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.ts deleted file mode 100644 index 178087068427e..0000000000000 --- a/packages/react-native/src/migrations/update-14-6-0/remove-jest-transform.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { - formatFiles, - logger, - ProjectConfiguration, - readProjectConfiguration, - stripIndents, - Tree, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import { removePropertyFromJestConfig } from '@nx/jest'; -import { JestExecutorOptions } from '@nx/jest/src/executors/jest/schema'; -import { join } from 'path'; - -/** - * Remove transfrom and testRunner in jest - */ -export default async function update(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, projectName) => { - if (options.jestConfig && tree.exists(options.jestConfig)) { - const jestConfig = tree.read(options.jestConfig, 'utf-8'); - - if (jestConfig.includes(`preset: 'react-native'`)) { - const project = readProjectConfiguration(tree, projectName); - removeTransform(tree, project); - renameBabelJson(tree, project); - } - } - } - ); - - await formatFiles(tree); -} - -function removeTransform(host: Tree, project: ProjectConfiguration) { - const jestConfigPath = project.targets?.test?.options?.jestConfig; - if (!jestConfigPath || !host.exists(jestConfigPath)) return; - try { - removePropertyFromJestConfig(host, jestConfigPath, 'transform'); - removePropertyFromJestConfig(host, jestConfigPath, 'testRunner'); - } catch { - logger.error( - stripIndents`Unable to update ${jestConfigPath} for project ${project.root}.` - ); - } -} - -function renameBabelJson(host: Tree, project: ProjectConfiguration) { - const babelrcPath = join(project.root, '.babelrc'); - const babelJsonPath = join(project.root, 'babel.config.json'); - if (!host.exists(babelrcPath)) { - return; - } - try { - const buffer = host.read(babelrcPath); - if (!buffer) { - return; - } - host.write(babelJsonPath, buffer); - host.delete(babelrcPath); - } catch { - logger.error( - stripIndents`Unable to rename from ${babelrcPath} to ${babelJsonPath} for project ${project.root}.` - ); - } -} diff --git a/packages/react/migrations.json b/packages/react/migrations.json index cca71870a8639..c56469e204578 100644 --- a/packages/react/migrations.json +++ b/packages/react/migrations.json @@ -1,71 +1,5 @@ { "generators": { - "use-react-jsx-in-tsconfig-12.0.0": { - "cli": "nx", - "version": "12.0.0-beta.0", - "description": "Migrate tsconfig.json to allow new jsx transform to be used. Removes the need for `import React from 'react'`", - "factory": "./src/migrations/update-12-0-0/use-react-jsx-in-tsconfig" - }, - "update-emotion-setup-12.0.0": { - "cli": "nx", - "version": "12.0.0-beta.0", - "description": "Update workspace to use `@emotion/babel-plugin` instead of `@emotion/babel-preset-css-prop` to support new jsx transform", - "factory": "./src/migrations/update-12-0-0/update-emotion-setup" - }, - "remove-react-redux-types-package-12.0.0": { - "cli": "nx", - "version": "12.0.0-beta.0", - "description": "Remove @types/react-redux from package.json since react-redux installs the package automatically now", - "factory": "./src/migrations/update-12-0-0/remove-react-redux-types-package" - }, - "update-emotion-setup-13.0.0": { - "cli": "nx", - "version": "13.0.0-beta.0", - "description": "Update tsconfig.json to use `jsxImportSource` to support css prop", - "factory": "./src/migrations/update-13-0-0/update-emotion-setup" - }, - "migrate-storybook-to-webpack-5-13.0.0": { - "cli": "nx", - "version": "13.0.0-beta.0", - "description": "Migrate Storybook to use webpack 5", - "factory": "./src/migrations/update-13-0-0/migrate-storybook-to-webpack-5" - }, - "update-react-18-13.10.0": { - "cli": "nx", - "version": "13.10.0-beta.0", - "description": "Update to React 18", - "factory": "./src/migrations/update-13-10-0/update-13-10-0" - }, - "update-react-dom-render-14.0.0": { - "cli": "nx", - "version": "14.0.0-beta.0", - "description": "Update to React DOM render call to React 18 API.", - "factory": "./src/migrations/update-14-0-0/update-react-dom-render-for-v18" - }, - "replace-testing-library-react-hook-14.0.0": { - "cli": "nx", - "version": "14.0.0-beta.0", - "description": "Replace deprecated '@testing-library/react-hook' package with `renderHook` from '@testing-library/react'.", - "factory": "./src/migrations/update-14-0-0/replace-testing-library-react-hook" - }, - "add-default-development-configurations-14.0.0": { - "cli": "nx", - "version": "14.0.0-beta.0", - "description": "Add a default development configuration for build and serve targets.", - "factory": "./src/migrations/update-14-0-0/add-default-development-configurations" - }, - "update-external-emotion-jsx-runtime-14.1.0": { - "cli": "nx", - "version": "14.1.0-beta.0", - "description": "Update external option in projects for Emotion", - "factory": "./src/migrations/update-14-1-0/update-external-emotion-jsx-runtime" - }, - "update-babel-jest-transform-option": { - "cli": "nx", - "version": "14.6.0-beta.0", - "description": "Update babel-jest to include the @nrwl/react/babel preset in project jest config", - "factory": "./src/migrations/update-14-6-0/add-preset-jest-config" - }, "update-rollup-executor": { "cli": "nx", "version": "15.3.0-beta.0", @@ -116,638 +50,6 @@ } }, "packageJsonUpdates": { - "12.0.0": { - "version": "12.0.0-beta.0", - "packages": { - "react": { - "version": "17.0.2", - "alwaysAddToPackageJson": false - }, - "react-dom": { - "version": "17.0.2", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "17.0.3", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "17.0.3", - "alwaysAddToPackageJson": false - }, - "@types/styled-components": { - "version": "5.1.9", - "alwaysAddToPackageJson": false - }, - "react-is": { - "version": "17.0.2", - "alwaysAddToPackageJson": false - }, - "@types/react-is": { - "version": "17.0.0", - "alwaysAddToPackageJson": false - }, - "@emotion/styled": { - "version": "11.1.5", - "alwaysAddToPackageJson": false - }, - "@emotion/react": { - "version": "11.1.5", - "alwaysAddToPackageJson": false - }, - "styled-jsx": { - "version": "3.4.4", - "alwaysAddToPackageJson": false - }, - "@types/react-router-dom": { - "version": "5.1.7", - "alwaysAddToPackageJson": false - }, - "@testing-library/react": { - "version": "11.2.5", - "alwaysAddToPackageJson": false - }, - "@reduxjs/toolkit": { - "version": "1.6.1", - "alwaysAddToPackageJson": false - }, - "react-redux": { - "version": "7.2.3", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.23.1", - "alwaysAddToPackageJson": false - } - } - }, - "12.10.0": { - "version": "12.10.0-beta.2", - "packages": { - "@testing-library/react": { - "version": "11.2.6", - "alwaysAddToPackageJson": false - } - } - }, - "13.0.0": { - "version": "13.0.0-beta.2", - "packages": { - "@types/react": { - "version": "17.0.30", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "17.0.9", - "alwaysAddToPackageJson": false - }, - "@types/react-is": { - "version": "17.0.2", - "alwaysAddToPackageJson": false - }, - "styled-components": { - "version": "5.3.3", - "alwaysAddToPackageJson": false - }, - "@types/styled-components": { - "version": "5.1.15", - "alwaysAddToPackageJson": false - }, - "@emotion/styled": { - "version": "11.3.0", - "alwaysAddToPackageJson": false - }, - "@emotion/react": { - "version": "11.5.0", - "alwaysAddToPackageJson": false - }, - "@emotion/babel-plugin": { - "version": "11.3.0", - "alwaysAddToPackageJson": false - }, - "styled-jsx": { - "version": "4.0.1", - "alwaysAddToPackageJson": false - }, - "@types/styled-jsx": { - "version": "3.4.4", - "alwaysAddToPackageJson": false - }, - "react-router-dom": { - "version": "5.3.0", - "alwaysAddToPackageJson": false - }, - "@types/react-router-dom": { - "version": "5.3.1", - "alwaysAddToPackageJson": false - }, - "@testing-library/react": { - "version": "12.1.2", - "alwaysAddToPackageJson": false - }, - "@testing-library/react-hooks": { - "version": "7.0.2", - "alwaysAddToPackageJson": false - }, - "@reduxjs/toolkit": { - "version": "1.6.2", - "alwaysAddToPackageJson": false - }, - "react-redux": { - "version": "7.2.5", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-import": { - "version": "2.25.2", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.26.1", - "alwaysAddToPackageJson": false - } - } - }, - "13.7.0": { - "version": "13.7.0-beta.9", - "packages": { - "eslint-plugin-react-hooks": { - "version": "4.3.0", - "alwaysAddToPackageJson": false - } - } - }, - "13.8.8": { - "version": "13.8.8-beta.1", - "packages": { - "@types/react": { - "version": "17.0.40", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "17.0.13", - "alwaysAddToPackageJson": false - }, - "@types/react-is": { - "version": "17.0.3", - "alwaysAddToPackageJson": false - }, - "@types/styled-components": { - "version": "5.1.24", - "alwaysAddToPackageJson": false - }, - "@emotion/styled": { - "version": "11.8.1", - "alwaysAddToPackageJson": false - }, - "@emotion/react": { - "version": "11.8.2", - "alwaysAddToPackageJson": false - }, - "@emotion/babel-plugin": { - "version": "11.7.2", - "alwaysAddToPackageJson": false - }, - "styled-jsx": { - "version": "5.0.0", - "alwaysAddToPackageJson": false - }, - "@types/react-router-dom": { - "version": "5.3.3", - "alwaysAddToPackageJson": false - }, - "@testing-library/react": { - "version": "12.1.4", - "alwaysAddToPackageJson": false - }, - "@reduxjs/toolkit": { - "version": "1.8.0", - "alwaysAddToPackageJson": false - }, - "react-redux": { - "version": "7.2.6", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-import": { - "version": "2.25.4", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.29.3", - "alwaysAddToPackageJson": false - } - } - }, - "13.10.0": { - "version": "13.10.0-beta.1", - "packages": { - "@types/react": { - "version": "17.0.43", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "17.0.14", - "alwaysAddToPackageJson": false - }, - "styled-components": { - "version": "5.3.5", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.29.4", - "alwaysAddToPackageJson": false - }, - "styled-jsx": { - "version": "5.0.1", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react-hooks": { - "version": "4.4.0", - "alwaysAddToPackageJson": false - } - } - }, - "13.10.1": { - "version": "13.10.1-beta.1", - "packages": { - "@types/react": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "@types/styled-components": { - "version": "5.1.25", - "alwaysAddToPackageJson": false - }, - "@emotion/react": { - "version": "11.9.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react": { - "version": "13.0.0", - "alwaysAddToPackageJson": false - }, - "@reduxjs/toolkit": { - "version": "1.8.1", - "alwaysAddToPackageJson": false - }, - "react-redux": { - "version": "7.2.8", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-import": { - "version": "2.26.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.0": { - "version": "14.0.0-beta.1", - "packages": { - "react": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "react-dom": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "react-is": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "react-test-renderer": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "18.0.1", - "alwaysAddToPackageJson": false - }, - "@emotion/babel-plugin": { - "version": "11.9.2", - "alwaysAddToPackageJson": false - }, - "react-router-dom": { - "version": "6.3.0", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "@testing-library/react": { - "version": "13.1.1", - "alwaysAddToPackageJson": false - }, - "react-redux": { - "version": "8.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.0.6": { - "version": "14.0.6-beta.0", - "packages": { - "react": { - "version": "18.1.0", - "alwaysAddToPackageJson": false - }, - "react-dom": { - "version": "18.1.0", - "alwaysAddToPackageJson": false - }, - "react-is": { - "version": "18.1.0", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "18.0.8", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "18.0.3", - "alwaysAddToPackageJson": false - }, - "react-redux": { - "version": "8.0.1", - "alwaysAddToPackageJson": false - }, - "react-test-renderer": { - "version": "18.1.0", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react-hooks": { - "version": "4.5.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.3": { - "version": "14.2.3-beta.0", - "packages": { - "@types/react": { - "version": "18.0.12", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "18.0.5", - "alwaysAddToPackageJson": false - }, - "@types/node": { - "version": "17.0.41", - "alwaysAddToPackageJson": false - }, - "styled-jsx": { - "version": "5.0.2", - "alwaysAddToPackageJson": false - }, - "@testing-library/react": { - "version": "13.3.0", - "alwaysAddToPackageJson": false - }, - "@reduxjs/toolkit": { - "version": "1.8.2", - "alwaysAddToPackageJson": false - }, - "react-redux": { - "version": "8.0.2", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.30.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.3.2": { - "version": "14.3.2-beta.0", - "packages": { - "@types/node": { - "version": "17.0.42", - "alwaysAddToPackageJson": false - }, - "@emotion/styled": { - "version": "11.9.3", - "alwaysAddToPackageJson": false - }, - "@emotion/react": { - "version": "11.9.3", - "alwaysAddToPackageJson": false - } - } - }, - "14.3.6": { - "version": "14.3.6-beta.0", - "packages": { - "react": { - "version": "18.2.0", - "alwaysAddToPackageJson": false - }, - "react-dom": { - "version": "18.2.0", - "alwaysAddToPackageJson": false - }, - "react-is": { - "version": "18.2.0", - "alwaysAddToPackageJson": false - }, - "@types/react": { - "version": "18.0.13", - "alwaysAddToPackageJson": false - }, - "@types/node": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - }, - "react-test-renderer": { - "version": "18.2.0", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react-hooks": { - "version": "4.6.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.3.7": { - "version": "14.3.7-beta.0", - "packages": { - "@types/react": { - "version": "18.0.14", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-jsx-a11y": { - "version": "6.6.0", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.30.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.4.3": { - "version": "14.4.3-beta.0", - "packages": { - "@types/react": { - "version": "18.0.15", - "alwaysAddToPackageJson": false - }, - "@types/react-dom": { - "version": "18.0.6", - "alwaysAddToPackageJson": false - }, - "@types/node": { - "version": "18.0.4", - "alwaysAddToPackageJson": false - }, - "@reduxjs/toolkit": { - "version": "1.8.3", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.0": { - "version": "14.5.0-beta.0", - "packages": { - "eslint-plugin-jsx-a11y": { - "version": "6.6.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.3": { - "version": "14.5.3-beta.0", - "packages": { - "@types/node": { - "version": "18.6.3", - "alwaysAddToPackageJson": false - }, - "@emotion/styled": { - "version": "11.10.0", - "alwaysAddToPackageJson": false - }, - "@emotion/react": { - "version": "11.10.0", - "alwaysAddToPackageJson": false - }, - "@emotion/babel-plugin": { - "version": "11.10.0", - "alwaysAddToPackageJson": false - }, - "tailwindcss": { - "version": "3.1.7", - "alwaysAddToPackageJson": false - }, - "autoprefixer": { - "version": "10.4.8", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.5": { - "version": "14.5.5-beta.0", - "packages": { - "@types/react": { - "version": "18.0.17", - "alwaysAddToPackageJson": false - }, - "@types/node": { - "version": "18.6.5", - "alwaysAddToPackageJson": false - }, - "postcss": { - "version": "8.4.16", - "alwaysAddToPackageJson": false - }, - "tailwindcss": { - "version": "3.1.8", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.7": { - "version": "14.5.7-beta.0", - "packages": { - "@types/node": { - "version": "18.7.5", - "alwaysAddToPackageJson": false - }, - "@types/styled-components": { - "version": "5.1.26", - "alwaysAddToPackageJson": false - }, - "styled-jsx": { - "version": "5.0.4", - "alwaysAddToPackageJson": false - }, - "@reduxjs/toolkit": { - "version": "1.8.4", - "alwaysAddToPackageJson": false - } - } - }, - "14.6.0": { - "version": "14.6.0-beta.0", - "packages": { - "@types/react": { - "version": "18.0.18", - "alwaysAddToPackageJson": false - }, - "@types/node": { - "version": "18.7.14", - "alwaysAddToPackageJson": false - }, - "@emotion/styled": { - "version": "11.10.4", - "alwaysAddToPackageJson": false - }, - "@emotion/react": { - "version": "11.10.4", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.31.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.7.10": { - "version": "14.7.10-beta.1", - "packages": { - "@types/react": { - "version": "18.0.20", - "alwaysAddToPackageJson": false - }, - "@types/node": { - "version": "18.7.18", - "alwaysAddToPackageJson": false - }, - "styled-jsx": { - "version": "5.0.7", - "alwaysAddToPackageJson": false - }, - "react-router-dom": { - "version": "6.4.1", - "alwaysAddToPackageJson": false - }, - "@testing-library/react": { - "version": "13.4.0", - "alwaysAddToPackageJson": false - }, - "eslint-plugin-react": { - "version": "7.31.8", - "alwaysAddToPackageJson": false - }, - "autoprefixer": { - "version": "10.4.12", - "alwaysAddToPackageJson": false - } - } - }, "15.2.2-beta.0": { "version": "15.2.2-beta.0", "packages": { diff --git a/packages/react/src/migrations/update-12-0-0/remove-react-redux-types-package.ts b/packages/react/src/migrations/update-12-0-0/remove-react-redux-types-package.ts deleted file mode 100644 index 8985b1af77ef9..0000000000000 --- a/packages/react/src/migrations/update-12-0-0/remove-react-redux-types-package.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { removeDependenciesFromPackageJson, Tree } from '@nx/devkit'; - -export async function removeReactReduxTypesFromPackageJson(host: Tree) { - return removeDependenciesFromPackageJson( - host, - ['@types/react-redux'], - ['@types/react-redux'] - ); -} - -export default removeReactReduxTypesFromPackageJson; diff --git a/packages/react/src/migrations/update-12-0-0/update-emotion-setup.spec.ts b/packages/react/src/migrations/update-12-0-0/update-emotion-setup.spec.ts deleted file mode 100644 index 230a9b19acf11..0000000000000 --- a/packages/react/src/migrations/update-12-0-0/update-emotion-setup.spec.ts +++ /dev/null @@ -1,118 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { updateEmotionSetup } from './update-emotion-setup'; - -describe('Update babel config for emotion', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it(`should add web babel preset if it does not exist`, async () => { - addProjectConfiguration(tree, 'no-emotion-app', { - root: 'apps/no-emotion-app', - projectType: 'application', - }); - addProjectConfiguration(tree, 'plain-react-app', { - root: 'apps/plain-react-app', - projectType: 'application', - }); - addProjectConfiguration(tree, 'emotion-app', { - root: 'apps/emotion-app', - projectType: 'application', - }); - addProjectConfiguration(tree, 'emotion-with-options-app', { - root: 'apps/emotion-with-options-app', - projectType: 'application', - }); - - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - 'no-emotion-app': {}, - 'plain-react-app': {}, - 'emotion-app': {}, - 'emotion-with-options-app': {}, - }, - }) - ); - tree.write('apps/no-emotion-app/.babelrc', JSON.stringify({})); - tree.write( - 'apps/plain-react-app/.babelrc', - JSON.stringify({ - presets: ['@nrwl/react/babel'], - plugins: ['@babel/whatever'], - }) - ); - tree.write( - 'apps/emotion-app/.babelrc', - JSON.stringify({ presets: ['@emotion/babel-preset-css-prop'] }) - ); - tree.write( - 'apps/emotion-with-options-app/.babelrc', - JSON.stringify({ - presets: [ - ['@emotion/babel-preset-css-prop', { autoLabel: 'dev-only' }], - ], - }) - ); - - await updateEmotionSetup(tree); - - expect(readJson(tree, 'apps/no-emotion-app/.babelrc')).toEqual({}); - expect(readJson(tree, 'apps/plain-react-app/.babelrc')).toEqual({ - presets: ['@nrwl/react/babel'], - plugins: ['@babel/whatever'], - }); - expect(readJson(tree, 'apps/emotion-app/.babelrc')).toEqual({ - presets: [], - plugins: ['@emotion/babel-plugin'], - }); - expect(readJson(tree, 'apps/emotion-with-options-app/.babelrc')).toEqual({ - presets: [], - plugins: [['@emotion/babel-plugin', { autoLabel: 'dev-only' }]], - }); - }); - - it('should remove `@emotion/babel-preset-css-prop` and add `@emotion/babel-plugin@11.2.0` in `devDependencies', async () => { - tree.write( - 'package.json', - JSON.stringify({ - devDependencies: { - '@emotion/babel-preset-css-prop': '11.0.0', - }, - }) - ); - - await updateEmotionSetup(tree); - - const json = JSON.parse(tree.read('package.json').toString()); - expect(json).toEqual({ - devDependencies: { - '@emotion/babel-plugin': '11.2.0', - }, - }); - }); - - it('should remove `@emotion/babel-preset-css-prop` and add `@emotion/babel-plugin@11.2.0` in `dependencies', async () => { - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { - '@emotion/babel-preset-css-prop': '11.0.0', - }, - }) - ); - - await updateEmotionSetup(tree); - - const json = JSON.parse(tree.read('package.json').toString()); - expect(json).toEqual({ - dependencies: { - '@emotion/babel-plugin': '11.2.0', - }, - }); - }); -}); diff --git a/packages/react/src/migrations/update-12-0-0/update-emotion-setup.ts b/packages/react/src/migrations/update-12-0-0/update-emotion-setup.ts deleted file mode 100644 index f1554ff178d07..0000000000000 --- a/packages/react/src/migrations/update-12-0-0/update-emotion-setup.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { formatFiles, getProjects, Tree, updateJson } from '@nx/devkit'; - -export async function updateEmotionSetup(host: Tree) { - const projects = getProjects(host); - - projects.forEach((p) => { - const babelrcPath = `${p.root}/.babelrc`; - const oldPreset = '@emotion/babel-preset-css-prop'; - const newPlugin = '@emotion/babel-plugin'; - - if (host.exists(babelrcPath)) { - updateJson(host, babelrcPath, (json) => { - if (!json.presets) return json; - - let emotionPresetIdx = -1; - let emotionOptions: null | {} = null; - - for (const [idx, preset] of json.presets.entries()) { - if (Array.isArray(preset)) { - if (!preset[0].includes(oldPreset)) continue; - emotionOptions = preset[1]; - emotionPresetIdx = idx; - break; - } else { - if (!preset.includes(oldPreset)) continue; - emotionPresetIdx = idx; - break; - } - } - - if (emotionPresetIdx !== -1) { - // Remove preset - json.presets.splice(emotionPresetIdx, 1); - - // Add new plugin - json.plugins ??= []; - json.plugins.push( - emotionOptions ? [newPlugin, emotionOptions] : newPlugin - ); - - return json; - } else { - return json; - } - }); - } - }); - - updateJson(host, 'package.json', (json) => { - if (json.devDependencies?.['@emotion/babel-preset-css-prop']) { - delete json.devDependencies['@emotion/babel-preset-css-prop']; - json.devDependencies['@emotion/babel-plugin'] = '11.2.0'; - } - // Just in case someone moved it to `dependencies` - else if (json.dependencies?.['@emotion/babel-preset-css-prop']) { - delete json.dependencies['@emotion/babel-preset-css-prop']; - json.dependencies['@emotion/babel-plugin'] = '11.2.0'; - } - return json; - }); - - await formatFiles(host); -} - -export default updateEmotionSetup; diff --git a/packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.spec.ts b/packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.spec.ts deleted file mode 100644 index b647652fb1f09..0000000000000 --- a/packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { useReactJsxInTsconfig } from './use-react-jsx-in-tsconfig'; - -describe('Update tsconfig for React apps', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it(`should add web babel preset if it does not exist`, async () => { - addProjectConfiguration(tree, 'web-app', { - root: 'apps/web-app', - projectType: 'application', - }); - - addProjectConfiguration(tree, 'react-app', { - root: 'apps/react-app', - projectType: 'application', - }); - - addProjectConfiguration(tree, 'preserve-jsx-app', { - root: 'apps/preserve-jsx-app', - projectType: 'application', - }); - - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - 'web-app': {}, - 'react-app': {}, - 'preserve-jsx-app': {}, - }, - }) - ); - tree.write('apps/web-app/tsconfig.json', JSON.stringify({})); - tree.write( - 'apps/react-app/tsconfig.json', - JSON.stringify({ compilerOptions: { jsx: 'react' } }) - ); - tree.write( - 'apps/preserve-jsx-app/tsconfig.json', - JSON.stringify({ compilerOptions: { jsx: 'preserve' } }) - ); - - await useReactJsxInTsconfig(tree); - - expect(readJson(tree, 'apps/web-app/tsconfig.json')).toEqual({}); - expect(readJson(tree, 'apps/react-app/tsconfig.json')).toMatchObject({ - compilerOptions: { jsx: 'react-jsx' }, - }); - expect(readJson(tree, 'apps/preserve-jsx-app/tsconfig.json')).toMatchObject( - { - compilerOptions: { jsx: 'preserve' }, - } - ); - }); -}); diff --git a/packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.ts b/packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.ts deleted file mode 100644 index d2b8ba57a19c2..0000000000000 --- a/packages/react/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { formatFiles, getProjects, Tree, updateJson } from '@nx/devkit'; - -export async function useReactJsxInTsconfig(host: Tree) { - const projects = getProjects(host); - - projects.forEach((p) => { - const tsConfigPath = `${p.root}/tsconfig.json`; - - if (host.exists(tsConfigPath)) { - updateJson(host, tsConfigPath, (json) => { - if (json.compilerOptions?.jsx === 'react') { - // JSX is handled by babel - json.compilerOptions.jsx = 'react-jsx'; - } - return json; - }); - } - }); - - await formatFiles(host); -} - -export default useReactJsxInTsconfig; diff --git a/packages/react/src/migrations/update-12-8-0/update-12-8-0.ts b/packages/react/src/migrations/update-12-8-0/update-12-8-0.ts deleted file mode 100644 index 03a416eef3160..0000000000000 --- a/packages/react/src/migrations/update-12-8-0/update-12-8-0.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { addDependenciesToPackageJson, Tree } from '@nx/devkit'; - -export async function removeReactReduxTypesFromPackageJson(host: Tree) { - return addDependenciesToPackageJson( - host, - {}, - { - '@testing-library/react-hooks': '^7.0.1', - } - ); -} - -export default removeReactReduxTypesFromPackageJson; diff --git a/packages/react/src/migrations/update-13-0-0/__snapshots__/webpack5-changes-utils.spec.ts.snap b/packages/react/src/migrations/update-13-0-0/__snapshots__/webpack5-changes-utils.spec.ts.snap deleted file mode 100644 index bf2e020110b3e..0000000000000 --- a/packages/react/src/migrations/update-13-0-0/__snapshots__/webpack5-changes-utils.spec.ts.snap +++ /dev/null @@ -1,14 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`webpack5ChangesUtils should get project name and storybook configuration for all react projects 1`] = ` -[ - { - "projectName": "test-one", - "storybookConfigPath": "libs/test-one/.storybook", - }, - { - "projectName": "test-two", - "storybookConfigPath": "libs/test-two/.storybook", - }, -] -`; diff --git a/packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.spec.ts b/packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.spec.ts deleted file mode 100644 index 14672a7fca487..0000000000000 --- a/packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.spec.ts +++ /dev/null @@ -1,360 +0,0 @@ -import { - addProjectConfiguration, - readJson, - Tree, - updateJson, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { migrateStorybookToWebPack5 } from './migrate-storybook-to-webpack-5'; - -describe('migrateStorybookToWebPack5', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should add packages needed by Storybook if workspace has the @storybook/react package', async () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies = { - '@storybook/react': '~6.3.0', - }; - return json; - }); - - await migrateStorybookToWebPack5(tree); - - const json = readJson(tree, '/package.json'); - - expect(json.devDependencies['@storybook/builder-webpack5']).toBe('~6.3.0'); - expect(json.devDependencies['@storybook/manager-webpack5']).toBe('~6.3.0'); - }); - - it('should not add the webpack Storybook packages again if they already exist', async () => { - let newTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(newTree, 'package.json', (json) => { - json.dependencies = { - '@storybook/react': '~6.3.0', - '@storybook/builder-webpack5': '~6.3.0', - '@storybook/manager-webpack5': '~6.3.0', - }; - return json; - }); - await migrateStorybookToWebPack5(newTree); - const json = readJson(newTree, '/package.json'); - expect(json.devDependencies['@storybook/builder-webpack5']).toBeUndefined(); - expect(json.devDependencies['@storybook/manager-webpack5']).toBeUndefined(); - }); - - it('should not add Storybook packages if @storybook/react does not exist', async () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies = { - '@storybook/angular': '~6.3.0', - }; - return json; - }); - await migrateStorybookToWebPack5(tree); - const json = readJson(tree, '/package.json'); - expect(json.devDependencies['@storybook/builder-webpack5']).toBeUndefined(); - expect(json.devDependencies['@storybook/manager-webpack5']).toBeUndefined(); - }); - - describe('updating project-level .storybook/main.js configurations for webpack 5', () => { - beforeEach(async () => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies = { - '@storybook/react': '~6.3.0', - }; - return json; - }); - - addProjectConfiguration(tree, 'test-one', { - root: 'libs/test-one', - targets: { - storybook: { - options: { - uiFramework: '@storybook/react', - config: { - configFolder: 'libs/test-one/.storybook', - }, - }, - }, - }, - }); - - addProjectConfiguration(tree, 'test-two', { - root: 'libs/test-two', - targets: { - storybook: { - options: { - uiFramework: '@storybook/react', - config: { - configFolder: 'libs/test-two/.storybook', - }, - }, - }, - }, - }); - - tree.write( - `.storybook/main.js`, - `module.exports = { - stories: [], - addons: ['@storybook/addon-essentials'], - // uncomment the property below if you want to apply some webpack config globally - // webpackFinal: async (config, { configType }) => { - // // Make whatever fine-grained changes you need that should apply to all storybook configs - - // // Return the altered config - // return config; - // }, - }; - ` - ); - }); - - describe('when main.js uses new syntax', () => { - it('should update the project-level .storybook/main.js if there is a core object', async () => { - tree.write( - `libs/test-one/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - module.exports = { - ...rootMain, - - core: { ...rootMain.core }, - stories: [ - ...rootMain.stories, - '../src/lib/**/*.stories.mdx', - '../src/lib/**/*.stories.@(js|jsx|ts|tsx)', - ], - addons: [...rootMain.addons, '@nrwl/react/plugins/storybook'], - webpackFinal: async (config, { configType }) => { - // apply any global webpack configs that might have been specified in .storybook/main.js - if (rootMain.webpackFinal) { - config = await rootMain.webpackFinal(config, { configType }); - } - - // add your own webpack tweaks if needed - - return config; - }, - };` - ); - - tree.write( - `libs/test-two/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - module.exports = { - ...rootMain, - core: { ...rootMain.core }, - stories: [ - ...rootMain.stories, - '../src/lib/**/*.stories.mdx', - '../src/lib/**/*.stories.@(js|jsx|ts|tsx)', - ], - addons: [...rootMain.addons, '@nrwl/react/plugins/storybook'], - webpackFinal: async (config, { configType }) => { - // apply any global webpack configs that might have been specified in .storybook/main.js - if (rootMain.webpackFinal) { - config = await rootMain.webpackFinal(config, { configType }); - } - - // add your own webpack tweaks if needed - - return config; - }, - };` - ); - - await migrateStorybookToWebPack5(tree); - - const projectOne = tree.read( - `libs/test-one/.storybook/main.js`, - 'utf-8' - ); - expect(projectOne).toContain(`builder: 'webpack5'`); - const projectTwo = tree.read( - `libs/test-two/.storybook/main.js`, - 'utf-8' - ); - expect(projectTwo).toContain(`builder: 'webpack5'`); - }); - - it('should update the project-level .storybook/main.js if there is not a core object', async () => { - tree.write( - `libs/test-one/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - module.exports = { - ...rootMain, - - stories: [ - ...rootMain.stories, - '../src/lib/**/*.stories.mdx', - '../src/lib/**/*.stories.@(js|jsx|ts|tsx)', - ], - addons: [...rootMain.addons, '@nrwl/react/plugins/storybook'], - webpackFinal: async (config, { configType }) => { - // apply any global webpack configs that might have been specified in .storybook/main.js - if (rootMain.webpackFinal) { - config = await rootMain.webpackFinal(config, { configType }); - } - - // add your own webpack tweaks if needed - - return config; - }, - };` - ); - - tree.write( - `libs/test-two/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - module.exports = { - ...rootMain, - - stories: [ - ...rootMain.stories, - '../src/lib/**/*.stories.mdx', - '../src/lib/**/*.stories.@(js|jsx|ts|tsx)', - ], - addons: [...rootMain.addons, '@nrwl/react/plugins/storybook'], - webpackFinal: async (config, { configType }) => { - // apply any global webpack configs that might have been specified in .storybook/main.js - if (rootMain.webpackFinal) { - config = await rootMain.webpackFinal(config, { configType }); - } - - // add your own webpack tweaks if needed - - return config; - }, - };` - ); - - await migrateStorybookToWebPack5(tree); - const projectOne = tree.read( - `libs/test-one/.storybook/main.js`, - 'utf-8' - ); - expect(projectOne).toContain(`builder: 'webpack5'`); - const projectTwo = tree.read( - `libs/test-two/.storybook/main.js`, - 'utf-8' - ); - expect(projectTwo).toContain(`builder: 'webpack5'`); - }); - - it('should not do anything if project-level .storybook/main.js is invalid', async () => { - tree.write( - `libs/test-one/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - module.exports = { - };` - ); - - tree.write( - `libs/test-two/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - module.exports = { - ...rootMain, - }, - };` - ); - - await migrateStorybookToWebPack5(tree); - const projectOne = tree.read( - `libs/test-one/.storybook/main.js`, - 'utf-8' - ); - expect(projectOne).not.toContain(`builder: 'webpack5'`); - const projectTwo = tree.read( - `libs/test-two/.storybook/main.js`, - 'utf-8' - ); - expect(projectTwo).not.toContain(`builder: 'webpack5'`); - }); - }); - - describe('when main.js uses old syntax', () => { - it('should update the project-level .storybook/main.js if there is a core object', async () => { - tree.write( - `libs/test-one/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - - rootMain.core = { - ...rootMain.core - }; - // Use the following syntax to add addons! - // rootMain.addons.push(''); - rootMain.stories.push( - ...['../src/lib/**/*.stories.mdx', '../src/lib/**/*.stories.@(js|jsx|ts|tsx)'] - ); - module.exports = rootMain;` - ); - - tree.write( - `libs/test-two/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - - rootMain.core = { ...rootMain.core, builder: 'webpack5' }; - // Use the following syntax to add addons! - // rootMain.addons.push(''); - rootMain.stories.push( - ...['../src/lib/**/*.stories.mdx', '../src/lib/**/*.stories.@(js|jsx|ts|tsx)'] - ); - module.exports = rootMain;` - ); - - await migrateStorybookToWebPack5(tree); - - const projectOne = tree.read( - `libs/test-one/.storybook/main.js`, - 'utf-8' - ); - expect(projectOne).toContain(`builder: 'webpack5'`); - const projectTwo = tree.read( - `libs/test-two/.storybook/main.js`, - 'utf-8' - ); - expect(projectTwo).toContain(`builder: 'webpack5'`); - }); - - it('should update the project-level .storybook/main.js if there is not a core object', async () => { - tree.write( - `libs/test-one/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - - // Use the following syntax to add addons! - // rootMain.addons.push(''); - rootMain.stories.push( - ...['../src/lib/**/*.stories.mdx', '../src/lib/**/*.stories.@(js|jsx|ts|tsx)'] - ); - module.exports = rootMain;` - ); - - tree.write( - `libs/test-two/.storybook/main.js`, - `const rootMain = require('../../../.storybook/main'); - - // Use the following syntax to add addons! - // rootMain.addons.push(''); - rootMain.stories.push( - ...['../src/lib/**/*.stories.mdx', '../src/lib/**/*.stories.@(js|jsx|ts|tsx)'] - ); - module.exports = rootMain;` - ); - - await migrateStorybookToWebPack5(tree); - const projectOne = tree.read( - `libs/test-one/.storybook/main.js`, - 'utf-8' - ); - expect(projectOne).toContain(`builder: 'webpack5'`); - const projectTwo = tree.read( - `libs/test-two/.storybook/main.js`, - 'utf-8' - ); - expect(projectTwo).toContain(`builder: 'webpack5'`); - }); - }); - }); -}); diff --git a/packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.ts b/packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.ts deleted file mode 100644 index 3cc9b990fb6d4..0000000000000 --- a/packages/react/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Tree, logger, updateJson, readJson } from '@nx/devkit'; -import { - migrateToWebPack5, - workspaceHasStorybookForReact, -} from './webpack5-changes-utils'; - -let needsInstall = false; - -export async function migrateStorybookToWebPack5(tree: Tree) { - const packageJson = readJson(tree, 'package.json'); - if (workspaceHasStorybookForReact(packageJson)) { - updateJson(tree, 'package.json', (json) => { - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - if ( - !json.dependencies['@storybook/builder-webpack5'] && - !json.devDependencies['@storybook/builder-webpack5'] - ) { - needsInstall = true; - json.devDependencies['@storybook/builder-webpack5'] = - workspaceHasStorybookForReact(packageJson); - } - - if ( - !json.dependencies['@storybook/manager-webpack5'] && - !json.devDependencies['@storybook/manager-webpack5'] - ) { - needsInstall = true; - json.devDependencies['@storybook/manager-webpack5'] = - workspaceHasStorybookForReact(packageJson); - } - - return json; - }); - await migrateToWebPack5(tree); - - if (needsInstall) { - logger.info( - 'Please make sure to run npm install or yarn install to get the latest packages added by this migration' - ); - } - } -} - -export default migrateStorybookToWebPack5; diff --git a/packages/react/src/migrations/update-13-0-0/update-emotion-setup.spec.ts b/packages/react/src/migrations/update-13-0-0/update-emotion-setup.spec.ts deleted file mode 100644 index 76f3bfec3f4bc..0000000000000 --- a/packages/react/src/migrations/update-13-0-0/update-emotion-setup.spec.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readJson, Tree } from '@nx/devkit'; -import { updateEmotionSetup } from './update-emotion-setup'; - -describe('Update tsconfig config for Emotion', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it(`should add jsxImportSource if it uses @emotion/react`, async () => { - addProjectConfiguration(tree, 'no-emotion-app', { - root: 'apps/no-emotion-app', - projectType: 'application', - }); - addProjectConfiguration(tree, 'plain-react-app', { - root: 'apps/plain-react-app', - projectType: 'application', - }); - addProjectConfiguration(tree, 'emotion-app', { - root: 'apps/emotion-app', - projectType: 'application', - }); - tree.write( - 'nx.json', - JSON.stringify({ - projects: { - 'no-emotion-app': {}, - 'plain-react-app': {}, - 'emotion-app': {}, - }, - }) - ); - tree.write('apps/no-emotion-app/.babelrc', JSON.stringify({})); - tree.write( - 'apps/no-emotion-app/tsconfig.json', - JSON.stringify({ compilerOptions: {} }) - ); - tree.write( - 'apps/plain-react-app/.babelrc', - JSON.stringify({ - presets: ['@nrwl/react/babel'], - plugins: [], - }) - ); - tree.write( - 'apps/plain-react-app/tsconfig.json', - JSON.stringify({ compilerOptions: { jsx: 'react-jsx' } }) - ); - tree.write( - 'apps/emotion-app/.babelrc', - JSON.stringify({ - presets: [ - [ - '@nrwl/react/babel', - { - runtime: 'automatic', - importSource: '@emotion/react', - }, - ], - ], - plugins: ['@emotion/babel-plugin'], - }) - ); - tree.write( - 'apps/emotion-app/tsconfig.json', - JSON.stringify({ compilerOptions: { jsx: 'react-jsx' } }) - ); - - await updateEmotionSetup(tree); - - expect(readJson(tree, 'apps/no-emotion-app/tsconfig.json')).toEqual({ - compilerOptions: {}, - }); - expect(readJson(tree, 'apps/plain-react-app/tsconfig.json')).toEqual({ - compilerOptions: { jsx: 'react-jsx' }, - }); - expect(readJson(tree, 'apps/emotion-app/tsconfig.json')).toEqual({ - compilerOptions: { jsx: 'react-jsx', jsxImportSource: '@emotion/react' }, - }); - }); -}); diff --git a/packages/react/src/migrations/update-13-0-0/update-emotion-setup.ts b/packages/react/src/migrations/update-13-0-0/update-emotion-setup.ts deleted file mode 100644 index c78099d8e2c4d..0000000000000 --- a/packages/react/src/migrations/update-13-0-0/update-emotion-setup.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - readJson, - updateJson, -} from '@nx/devkit'; - -export async function updateEmotionSetup(host: Tree) { - const projects = getProjects(host); - - projects.forEach((p) => { - let hasEmotion = false; - const babelrcPath = `${p.root}/.babelrc`; - const tsConfigPath = `${p.root}/tsconfig.json`; - - if (host.exists(babelrcPath)) { - const babelrc = readJson(host, babelrcPath); - if (babelrc.presets) { - for (const [idx, preset] of babelrc.presets.entries()) { - if (Array.isArray(preset)) { - if (!preset[0].includes('@nrwl/react/babel')) continue; - const emotionOptions = preset[1]; - hasEmotion = emotionOptions.importSource === '@emotion/react'; - break; - } - } - } - } - - if (hasEmotion && host.exists(tsConfigPath)) { - updateJson(host, tsConfigPath, (json) => { - json.compilerOptions.jsxImportSource = '@emotion/react'; - return json; - }); - } - }); - - await formatFiles(host); -} - -export default updateEmotionSetup; diff --git a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts b/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts deleted file mode 100644 index 0a3dc242406c7..0000000000000 --- a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { addProjectConfiguration, Tree, updateJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { allReactProjectsWithStorybookConfiguration } from './webpack5-changes-utils'; - -describe('webpack5ChangesUtils', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should get project name and storybook configuration for all react projects', () => { - addProjectConfiguration(tree, 'test-one', { - root: 'libs/test-one', - targets: { - storybook: { - options: { - uiFramework: '@storybook/react', - config: { - configFolder: 'libs/test-one/.storybook', - }, - }, - }, - }, - }); - addProjectConfiguration(tree, 'test-two', { - root: 'libs/test-two', - targets: { - storybook: { - options: { - uiFramework: '@storybook/react', - config: { - configFolder: 'libs/test-two/.storybook', - }, - }, - }, - }, - }); - const allReactProjects = allReactProjectsWithStorybookConfiguration(tree); - - expect(allReactProjects).toMatchSnapshot(); - }); - - it('should ignore non-react projects with storybook configuration', () => { - addProjectConfiguration(tree, 'test-one', { - root: 'libs/test-one', - targets: { - storybook: { - options: { - uiFramework: '@storybook/angular', - config: { - configFolder: 'libs/test-one/.storybook', - }, - }, - }, - }, - }); - - const allReactProjects = allReactProjectsWithStorybookConfiguration(tree); - expect(allReactProjects.length).toBe(0); - }); -}); diff --git a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts b/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts deleted file mode 100644 index 7a644be0a334d..0000000000000 --- a/packages/react/src/migrations/update-13-0-0/webpack5-changes-utils.ts +++ /dev/null @@ -1,330 +0,0 @@ -import { getProjects, Tree } from '@nx/devkit'; -import { - logger, - formatFiles, - applyChangesToString, - ChangeType, -} from '@nx/devkit'; - -import ts = require('typescript'); -import { findNodes } from '@nx/js'; - -export async function migrateToWebPack5(tree: Tree) { - allReactProjectsWithStorybookConfiguration(tree).forEach((project) => { - let storybookConfigFile = `${project.storybookConfigPath}/main.js`; - if (!tree.exists(storybookConfigFile)) { - // try to see whether there's a main.ts file - storybookConfigFile = `${project.storybookConfigPath}/main.ts`; - } - - if (!tree.exists(storybookConfigFile)) { - // ok...give up - return; - } - - editProjectMainJs(tree, storybookConfigFile, project.projectName); - }); - await formatFiles(tree); -} - -export function workspaceHasStorybookForReact( - packageJson: any -): string | undefined { - return ( - packageJson.dependencies['@storybook/react'] || - packageJson.devDependencies['@storybook/react'] - ); -} - -export function allReactProjectsWithStorybookConfiguration(tree: Tree): { - projectName: string; - storybookConfigPath: string; -}[] { - const projects = getProjects(tree); - const reactProjectsThatHaveStorybookConfiguration: { - projectName: string; - storybookConfigPath: string; - }[] = [...projects.entries()] - ?.filter( - ([_, projectConfig]) => - projectConfig.targets && - projectConfig.targets.storybook && - projectConfig.targets.storybook.options - ) - ?.map(([projectName, projectConfig]) => { - if ( - projectConfig.targets && - projectConfig.targets.storybook && - projectConfig.targets.storybook.options?.config?.configFolder && - projectConfig.targets.storybook.options?.uiFramework === - '@storybook/react' - ) { - return { - projectName, - storybookConfigPath: - projectConfig.targets.storybook.options.config.configFolder, - }; - } - }) - ?.filter((entry) => !!entry); - return reactProjectsThatHaveStorybookConfiguration; -} - -export function editProjectMainJs( - tree: Tree, - projectMainJsFile: string, - projectName: string -) { - let newContents: string; - let moduleExportsIsEmptyOrNonExistentOrInvalid = false; - let alreadyHasBuilder: any; - const rootMainJsExists = tree.exists(projectMainJsFile); - let moduleExportsFull: ts.Node[] = []; - - if (rootMainJsExists) { - const file = getTsSourceFile(tree, projectMainJsFile); - const appFileContent = tree.read(projectMainJsFile, 'utf-8'); - newContents = appFileContent; - moduleExportsFull = findNodes(file, [ts.SyntaxKind.ExpressionStatement]); - - if (moduleExportsFull && moduleExportsFull[0]) { - const moduleExports = moduleExportsFull[0]; - - const listOfStatements = findNodes(moduleExports, [ - ts.SyntaxKind.SyntaxList, - ]); - - /** - * Keep the index of the stories node - * to put the core object before it - * if it does not exist already - */ - - let indexOfStoriesNode = -1; - - const hasCoreObject = listOfStatements[0]?.getChildren()?.find((node) => { - if ( - node && - node.getText().length > 0 && - indexOfStoriesNode < 0 && - node?.getText().startsWith('stories') - ) { - indexOfStoriesNode = node.getStart(); - } - return ( - node?.kind === ts.SyntaxKind.PropertyAssignment && - node?.getText().startsWith('core') - ); - }); - - if (hasCoreObject) { - const contentsOfCoreNode = hasCoreObject.getChildren().find((node) => { - return node.kind === ts.SyntaxKind.ObjectLiteralExpression; - }); - const everyAttributeInsideCoreNode = contentsOfCoreNode - .getChildren() - .find((node) => node.kind === ts.SyntaxKind.SyntaxList); - - alreadyHasBuilder = everyAttributeInsideCoreNode - .getChildren() - .find((node) => node.getText() === "builder: 'webpack5'"); - - if (!alreadyHasBuilder) { - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Insert, - index: contentsOfCoreNode.getEnd() - 1, - text: ", builder: 'webpack5'", - }, - ]); - } - } else if (indexOfStoriesNode >= 0) { - /** - * Does not have core object, - * so just write one, at the start. - */ - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Insert, - index: indexOfStoriesNode - 1, - text: "core: { ...rootMain.core, builder: 'webpack5' }, ", - }, - ]); - } else { - /** - * Module exports is empty or does not - * contain stories - most probably invalid - */ - moduleExportsIsEmptyOrNonExistentOrInvalid = true; - } - } else { - /** - * module.exports does not exist - */ - moduleExportsIsEmptyOrNonExistentOrInvalid = true; - } - } else { - moduleExportsIsEmptyOrNonExistentOrInvalid = true; - } - - if (moduleExportsIsEmptyOrNonExistentOrInvalid) { - const usesOldSyntax = checkMainJsForOldSyntax( - moduleExportsFull, - newContents - ); - if (moduleExportsFull.length > 0 && usesOldSyntax) { - newContents = usesOldSyntax; - tree.write(projectMainJsFile, newContents); - return; - } else { - logger.info( - `Please configure Storybook for project "${projectName}"", since it has not been configured properly.` - ); - return; - } - } - - if (!alreadyHasBuilder) { - tree.write(projectMainJsFile, newContents); - } -} - -export function checkMainJsForOldSyntax( - nodeList: ts.Node[], - fileContent: string -): string | undefined { - let alreadyContainsBuilder = false; - let coreNode: ts.Node | undefined; - let hasCoreNode = false; - const lastIndexOfFirstNode = nodeList[0].getEnd(); - - if (!fileContent.includes('stories.push') || nodeList.length === 0) { - return undefined; - } - - // Go through the node list and find if the core object exists - // If it does, then we need to check if it has the builder property - // If it does not, then we need to add it - for (let topNode of nodeList) { - if ( - topNode.kind === ts.SyntaxKind.ExpressionStatement && - topNode.getChildren()?.length > 0 - ) { - for (let node of topNode.getChildren()) { - if ( - node.kind === ts.SyntaxKind.BinaryExpression && - node.getChildren()?.length - ) { - for (let childNode of node.getChildren()) { - if ( - childNode.kind === ts.SyntaxKind.PropertyAccessExpression && - childNode.getChildren()?.length - ) { - for (let grandChildNode of childNode.getChildren()) { - if ( - grandChildNode.kind === ts.SyntaxKind.Identifier && - grandChildNode.getText() === 'core' - ) { - coreNode = node; - hasCoreNode = true; - break; - } - } - } - if (hasCoreNode) { - break; - } - } - } - if (hasCoreNode) { - if (coreNode.getChildren()?.length) { - for (let coreChildNode of coreNode.getChildren()) { - if ( - coreChildNode.kind === ts.SyntaxKind.ObjectLiteralExpression && - coreChildNode.getChildren()?.length - ) { - for (let coreChildNodeChild of coreChildNode.getChildren()) { - if (coreChildNodeChild.kind === ts.SyntaxKind.SyntaxList) { - for (let coreChildNodeGrandChild of coreChildNodeChild.getChildren()) { - if ( - coreChildNodeGrandChild.kind === - ts.SyntaxKind.PropertyAssignment && - coreChildNodeGrandChild.getText().startsWith('builder') - ) { - for (let coreChildNodeGrandChildChild of coreChildNodeGrandChild.getChildren()) { - if ( - coreChildNodeGrandChildChild.kind === - ts.SyntaxKind.StringLiteral && - coreChildNodeGrandChildChild.getText() === - 'webpack5' - ) { - alreadyContainsBuilder = true; - break; - } - } - } - if (alreadyContainsBuilder) { - break; - } - } - } - if (alreadyContainsBuilder) { - break; - } - } - } - if (alreadyContainsBuilder) { - break; - } - } - } - break; - } - } - } - if (hasCoreNode) { - if (alreadyContainsBuilder) { - break; - } else { - // Add builder - const indexOfCoreNodeEnd = coreNode.getEnd(); - fileContent = applyChangesToString(fileContent, [ - { - type: ChangeType.Insert, - index: indexOfCoreNodeEnd - 1, - text: ", builder: 'webpack5'", - }, - ]); - break; - } - } - } - - if (!hasCoreNode) { - fileContent = applyChangesToString(fileContent, [ - { - type: ChangeType.Insert, - index: lastIndexOfFirstNode + 1, - text: "rootMain.core = { ...rootMain.core, builder: 'webpack5' };\n", - }, - ]); - } - - return fileContent; -} - -export function getTsSourceFile(host: Tree, path: string): ts.SourceFile { - const buffer = host.read(path); - if (!buffer) { - throw new Error(`Could not read TS file (${path}).`); - } - const content = buffer.toString(); - const source = ts.createSourceFile( - path, - content, - ts.ScriptTarget.Latest, - true - ); - - return source; -} diff --git a/packages/react/src/migrations/update-13-10-0/update-13-10-0.spec.ts b/packages/react/src/migrations/update-13-10-0/update-13-10-0.spec.ts deleted file mode 100644 index 787c2e05f4c4f..0000000000000 --- a/packages/react/src/migrations/update-13-10-0/update-13-10-0.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { writeJson, readJson, Tree } from '@nx/devkit'; -import migrate from './update-13-10-0'; - -describe('Update tsconfig for React apps', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should update to React 18 if React Native is not installed', async () => { - writeJson(tree, 'package.json', { - dependencies: { - react: '17.0.2', - }, - }); - - const installTask = await migrate(tree); - expect(installTask).toBeDefined(); - }); - - it('should update to React 18 if React Native 0.68.0-rc.4 is installed', async () => { - writeJson(tree, 'package.json', { - dependencies: { - react: '17.0.2', - 'react-native': '0.68.0-rc.4', - }, - }); - - await migrate(tree); - - const installTask = await migrate(tree); - expect(installTask).toBeDefined(); - }); - - it('should skip update to React 18 if React Native 0.67.0 is installed', async () => { - writeJson(tree, 'package.json', { - dependencies: { - react: '17.0.2', - 'react-native': '0.67.0', - }, - }); - - await migrate(tree); - - const installTask = await migrate(tree); - expect(installTask).not.toBeDefined(); - }); -}); diff --git a/packages/react/src/migrations/update-13-10-0/update-13-10-0.ts b/packages/react/src/migrations/update-13-10-0/update-13-10-0.ts deleted file mode 100644 index 7658ba64e85d1..0000000000000 --- a/packages/react/src/migrations/update-13-10-0/update-13-10-0.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - addDependenciesToPackageJson, - logger, - readJson, - Tree, -} from '@nx/devkit'; - -// Putting this here because React Native 0.67 is incompatible with React 18. -// Waiting for 0.68 to come out with support for React 18. -// TODO(jack): For Nx 14 let's add another migration for React 18 in migrations.json because by then React Native 0.68.0 should be released. -export async function updateToReact18(host: Tree) { - const { dependencies } = readJson(host, 'package.json'); - if ( - dependencies['react-native'] && - !dependencies['react-native'].match(/[\^~]?0.68/) - ) { - logger.info( - `React Native ${dependencies['react-native']} is incompatible with React 18. Skipping update until React Native 0.68.0 is released.` - ); - } else { - return addDependenciesToPackageJson( - host, - { - react: '18.0.0', - 'react-dom': '18.0.0', - 'react-is': '18.0.0', - }, - { - 'react-test-renderer': '18.0.0', - } - ); - } -} - -export default updateToReact18; diff --git a/packages/react/src/migrations/update-14-0-0/__snapshots__/update-react-dom-render-for-v18.spec.ts.snap b/packages/react/src/migrations/update-14-0-0/__snapshots__/update-react-dom-render-for-v18.spec.ts.snap deleted file mode 100644 index 8e52fd468ebce..0000000000000 --- a/packages/react/src/migrations/update-14-0-0/__snapshots__/update-react-dom-render-for-v18.spec.ts.snap +++ /dev/null @@ -1,45 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`React update for Nx 14 should update react-dom render call if it exists 1`] = ` -"import { Strict } from 'react'; -import * as ReactDOM from 'react-dom/client'; -import App from './app/app'; - -const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( - - - -); -" -`; - -exports[`React update for Nx 14 should update react-dom render call if it exists 2`] = ` -"import { Strict } from 'react'; -import * as ReactDOM from 'react-dom/client'; -import App from './app/app'; - -const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( - - - -); -" -`; - -exports[`React update for Nx 14 should update react-dom render call if it exists 3`] = ` -"import { Strict } from 'react'; -import * as ReactDOM from 'react-dom/client'; -import App from './app/app'; - -const root = ReactDOM.createRoot( - document.getElementById('root') as HTMLElement -); -root.render( - - - -); -" -`; diff --git a/packages/react/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts b/packages/react/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts deleted file mode 100644 index 305c0f17634e5..0000000000000 --- a/packages/react/src/migrations/update-14-0-0/add-default-development-configurations.spec.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; -import update from './add-default-development-configurations'; - -describe('React default development configuration', () => { - it('should add development configuration if it does not exist', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - configurations: {}, - }, - serve: { - executor: '@nrwl/web:dev-server', - configurations: {}, - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.defaultConfiguration).toEqual('production'); - expect(config.targets.build.configurations.development).toEqual({ - extractLicenses: false, - optimization: false, - sourceMap: true, - vendorChunk: true, - }); - - expect(config.targets.serve.defaultConfiguration).toEqual('development'); - expect(config.targets.serve.configurations.development).toEqual({ - buildTarget: `example:build:development`, - }); - }); - - it('should add development configuration if no configurations at all', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - defaultConfiguration: 'production', - configurations: { production: { sourceMap: false } }, - }, - serve: { - executor: '@nrwl/web:dev-server', - }, - }, - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - - expect(config.targets.build.defaultConfiguration).toEqual('production'); - expect(config.targets.build.configurations.production).toEqual({ - sourceMap: false, - }); - expect(config.targets.build.configurations.development).toEqual({ - extractLicenses: false, - optimization: false, - sourceMap: true, - vendorChunk: true, - }); - - expect(config.targets.serve.defaultConfiguration).toEqual('development'); - expect(config.targets.serve.configurations.development).toEqual({ - buildTarget: `example:build:development`, - }); - }); - - it('should work without targets', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - projectType: 'application', - }, - true - ); - - await update(tree); - - const config = readProjectConfiguration(tree, 'example'); - expect(config).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'example', - root: 'apps/example', - projectType: 'application', - }); - }); -}); diff --git a/packages/react/src/migrations/update-14-0-0/add-default-development-configurations.ts b/packages/react/src/migrations/update-14-0-0/add-default-development-configurations.ts deleted file mode 100644 index 955705183d78c..0000000000000 --- a/packages/react/src/migrations/update-14-0-0/add-default-development-configurations.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((config, name) => { - let shouldUpdate = false; - if (config.targets?.build?.executor === '@nrwl/web:webpack') { - shouldUpdate = true; - config.targets.build.defaultConfiguration ??= 'production'; - config.targets.build.configurations ??= {}; - config.targets.build.configurations.development ??= { - extractLicenses: false, - optimization: false, - sourceMap: true, - vendorChunk: true, - }; - } - - if (config.targets?.serve?.executor === '@nrwl/web:dev-server') { - shouldUpdate = true; - config.targets.serve.defaultConfiguration ??= 'development'; - config.targets.serve.configurations ??= {}; - config.targets.serve.configurations.development ??= { - buildTarget: `${name}:build:development`, - }; - } - - if (shouldUpdate) updateProjectConfiguration(tree, name, config); - }); - - await formatFiles(tree); -} - -export default update; diff --git a/packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.spec.ts b/packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.spec.ts deleted file mode 100644 index 51fe9e8381692..0000000000000 --- a/packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { - addProjectConfiguration, - readJson, - stripIndents, - writeJson, -} from '@nx/devkit'; -import update from './replace-testing-library-react-hook'; - -describe('Remove deprecated hook testing package', () => { - it('should replace imports for packages that has jest test target', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example/src', - projectType: 'application', - targets: { - test: { - executor: '@nrwl/jest:jest', - }, - }, - }, - true - ); - - tree.write( - `apps/example/src/lib/use-example.spec.ts`, - `import { renderHook } from '@testing-library/react';` - ); - - await update(tree); - - expect( - tree.read('apps/example/src/lib/use-example.spec.ts').toString() - ).toEqual(`import { renderHook } from '@testing-library/react';`); - }); -}); diff --git a/packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.ts b/packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.ts deleted file mode 100644 index ba42fceca8279..0000000000000 --- a/packages/react/src/migrations/update-14-0-0/replace-testing-library-react-hook.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { - visitNotIgnoredFiles, - Tree, - getProjects, - removeDependenciesFromPackageJson, -} from '@nx/devkit'; - -export async function update(tree: Tree) { - const projects = getProjects(tree); - projects.forEach((config) => { - if (config.targets?.test?.executor !== '@nrwl/jest:jest') return; - - visitNotIgnoredFiles(tree, config.sourceRoot, (file) => { - if (!file.endsWith('.spec.ts')) return; - - const content = tree.read(file).toString(); - if (content.includes('@testing-library/react-hooks')) { - tree.write( - file, - content.replace( - /@testing-library\/react-hooks/g, - '@testing-library/react' - ) - ); - } - }); - }); - - removeDependenciesFromPackageJson( - tree, - ['@testing-library/react-hooks'], - ['@testing-library/react-hooks'] - ); -} - -export default update; diff --git a/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.spec.ts b/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.spec.ts deleted file mode 100644 index fe5bcbcc2806e..0000000000000 --- a/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.spec.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { - addProjectConfiguration, - readJson, - stripIndents, - writeJson, -} from '@nx/devkit'; -import update from './update-react-dom-render-for-v18'; - -describe('React update for Nx 14', () => { - it('should remove deprecated @testing-library/react package', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - writeJson(tree, 'package.json', { - devDependencies: { - '@testing-library/react': '0.0.0', - }, - }); - - await update(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - devDependencies: { - '@testing-library/react': '0.0.0', - }, - }); - }); - - it.each` - ext - ${'js'} - ${'jsx'} - ${'tsx'} - `('should update react-dom render call if it exists', async ({ ext }) => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: { - main: `apps/example/src/main.${ext}`, - }, - }, - }, - }, - true - ); - tree.write( - `apps/example/src/main.${ext}`, - stripIndents` - import { Strict } from 'react'; - import * as ReactDOM from 'react-dom'; - import App from './app/app'; - - ReactDOM.render( - - - , - document.getElementById('root') - ); - ` - ); - - await update(tree); - - expect( - tree.read(`apps/example/src/main.${ext}`).toString() - ).toMatchSnapshot(); - }); - - it('should skip update if main file does not contain react-dom', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration( - tree, - 'example', - { - root: 'apps/example', - sourceRoot: 'apps/example/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: { - main: `apps/example/src/main.tsx`, - }, - }, - }, - }, - true - ); - tree.write( - `apps/example/src/main.tsx`, - stripIndents` - import { AppRegistry } from 'react-native'; - import App from './app/App'; - - AppRegistry.registerComponent('main', () => App); - ` - ); - - await update(tree); - - expect(tree.read(`apps/example/src/main.tsx`).toString()) - .toMatchInlineSnapshot(` - "import { AppRegistry } from 'react-native'; - import App from './app/App'; - - AppRegistry.registerComponent('main', () => App); - " - `); - }); -}); diff --git a/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts b/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts deleted file mode 100644 index 2f240036fb481..0000000000000 --- a/packages/react/src/migrations/update-14-0-0/update-react-dom-render-for-v18.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { - applyChangesToString, - ChangeType, - getProjects, - StringChange, - stripIndents, - Tree, - formatFiles, -} from '@nx/devkit'; -import { findNodes } from '@nx/js'; -import * as ts from 'typescript'; - -export async function update(tree: Tree) { - const projects = getProjects(tree); - - projects.forEach((config, name) => { - const isReactProject = - config.targets?.build?.executor === '@nrwl/web:webpack' && - /main\.(t|j)sx?$/.test(config.targets.build.options.main); - - if (isReactProject) { - const sourcePath = config.targets.build.options.main; - const sourceCode = tree.read(sourcePath).toString(); - const source = ts.createSourceFile( - sourcePath, - sourceCode, - ts.ScriptTarget.Latest, - true - ); - const result = applyChangesToString( - sourceCode, - migrateReactDomRender(sourcePath, source) - ); - tree.write(sourcePath, result); - } - }); - - await formatFiles(tree); -} - -export function migrateReactDomRender( - sourcePath: string, - source: ts.SourceFile -): StringChange[] { - const allImports = findNodes( - source, - ts.SyntaxKind.ImportDeclaration - ) as ts.ImportDeclaration[]; - const reactDomImport = allImports.find( - (x) => x.moduleSpecifier.getText() === "'react-dom'" - ); - const changes = [] as StringChange[]; - - if (reactDomImport) { - changes.push({ - type: ChangeType.Insert, - index: reactDomImport.moduleSpecifier.end - 1, - text: '/client', - }); - } - - const calls = findNodes( - source, - ts.SyntaxKind.CallExpression - ) as ts.CallExpression[]; - const renderCall = calls.find((x) => { - if (x.expression.kind !== ts.SyntaxKind.PropertyAccessExpression) - return false; - const expr = x.expression as ts.PropertyAccessExpression; - return ( - expr.expression.getText() === 'ReactDOM' && - expr.name.getText() === 'render' - ); - }); - - if (renderCall) { - const [element, querySelector] = renderCall.arguments; - changes.push( - { - type: ChangeType.Delete, - start: renderCall.getStart(), - length: renderCall.end, - }, - { - type: ChangeType.Insert, - index: renderCall.getStart(), - text: stripIndents` - const root = ReactDOM.createRoot( - ${querySelector.getText()}${ - sourcePath.endsWith('.tsx') ? ' as HTMLElement' : '' - } - ); - root.render( - ${element.getText()} - ); - `, - } - ); - } - - return changes; -} - -export default update; diff --git a/packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.spec.ts b/packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.spec.ts deleted file mode 100644 index 77dcb48c6a3ee..0000000000000 --- a/packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.spec.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import { updateExternalEmotionJsxRuntime } from './update-external-emotion-jsx-runtime'; - -describe('updateExternalEmotionJsxRuntime', () => { - it('should update external for Emotion', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'components', { - root: 'libs/components', - targets: { - build: { - executor: '@nrwl/web:rollup', - options: { - external: ['@emotion/styled/base', 'react/jsx-runtime'], - }, - }, - }, - }); - tree.write( - 'libs/components/.babelrc', - JSON.stringify({ - presets: [ - [ - '@nrwl/react/babel', - { - runtime: 'automatic', - importSource: '@emotion/react', - }, - ], - ], - plugins: ['@emotion/babel-plugin'], - }) - ); - - // ACT - await updateExternalEmotionJsxRuntime(tree); - - // ASSERT - const { targets } = readProjectConfiguration(tree, 'components'); - expect(targets.build.options.external).toEqual([ - '@emotion/react/jsx-runtime', - ]); - }); - - it('should not fail for projects with no targets', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'components', { - root: 'apps/components', - }); - - // ACT - await updateExternalEmotionJsxRuntime(tree); - - // ASSERT - const { targets } = readProjectConfiguration(tree, 'components'); - expect(targets).toBeUndefined(); - }); -}); diff --git a/packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.ts b/packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.ts deleted file mode 100644 index e64860333429e..0000000000000 --- a/packages/react/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; - -export async function updateExternalEmotionJsxRuntime(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/web:rollup', - (options: any, projectName, targetName, configurationName) => { - const projectConfiguration = readProjectConfiguration(tree, projectName); - const config = configurationName - ? projectConfiguration.targets[targetName].configurations[ - configurationName - ] - : projectConfiguration.targets[targetName].options; - - if (config.external && config.external.length > 0) { - const hasEmotionStyledBase = config.external.includes( - '@emotion/styled/base' - ); - const hasReactJsxRuntime = - config.external.includes('react/jsx-runtime'); - - if (hasEmotionStyledBase && hasReactJsxRuntime) { - // Replace 'react/jsx-runtime' with '@emotion/react/jsx-runtime' - config.external.forEach((value, index) => { - if (value === 'react/jsx-runtime') { - config.external.splice(index, 1, '@emotion/react/jsx-runtime'); - } - }); - - // Remove '@emotion/styled/base' - config.external.forEach((value, index) => { - if (value === '@emotion/styled/base') { - config.external.splice(index, 1); - } - }); - } - - updateProjectConfiguration(tree, projectName, projectConfiguration); - } - } - ); -} - -export default updateExternalEmotionJsxRuntime; diff --git a/packages/react/src/migrations/update-14-6-0/add-preset-jest-config.spec.ts b/packages/react/src/migrations/update-14-6-0/add-preset-jest-config.spec.ts deleted file mode 100644 index 86cb3a29a01e6..0000000000000 --- a/packages/react/src/migrations/update-14-6-0/add-preset-jest-config.spec.ts +++ /dev/null @@ -1,195 +0,0 @@ -import { - addProjectConfiguration, - ProjectConfiguration, - Tree, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { addBabelJestPresetTransformerOption } from './add-preset-jest-config'; - -function setup( - tree: Tree, - options: { buildName?: string; jestConfigContent: string } -) { - const pc: ProjectConfiguration = { - root: 'projects/my-proj', - sourceRoot: 'projects/my-proj/src', - targets: { - ...(options.buildName - ? { - build: { - executor: options.buildName, - options: {}, - }, - } - : {}), - test: { - executor: '@nrwl/jest:jest', - options: { - jestConfig: 'projects/my-proj/jest.config.ts', - }, - }, - }, - }; - tree.write('projects/my-proj/jest.config.ts', options.jestConfigContent); - addProjectConfiguration(tree, 'my-proj', pc); -} - -describe('addBabelJestPresetTransformerOption', () => { - let tree: Tree; - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - it('should add react preset to babel-jest transformer', () => { - setup(tree, { - jestConfigContent: `/* eslint-disable */ -export default { - displayName: 'my-proj', - preset: '../../jest.preset.js', - transform: { - '^(?!.*\\\\\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest', - '^.+\\\\\\\\.[tj]sx?$': 'babel-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/projects/my-proj', -};`, - }); - - addBabelJestPresetTransformerOption(tree); - expect(tree.read('projects/my-proj/jest.config.ts', 'utf-8')).toContain( - `['babel-jest', { presets: ['@nrwl/react/babel'] }],` - ); - }); - - it('should not update if babel-jest is not being used', () => { - setup(tree, { - jestConfigContent: `/* eslint-disable */ -export default { - displayName: 'my-proj', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - testEnvironment: 'node', - transform: { - '^.+\\\\\\\\.[tj]s$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../coverage/projects/my-proj', -};`, - }); - - addBabelJestPresetTransformerOption(tree); - expect(tree.read('projects/my-proj/jest.config.ts', 'utf-8')).not.toContain( - 'babel-jest' - ); - }); - - it('should not update if next project', () => { - setup(tree, { - buildName: '@nrwl/next:build', - jestConfigContent: ` -/* eslint-disable */ -export default { - displayName: 'my-proj', - preset: '../../jest.preset.js', - transform: { - '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest', - '^.+\\\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/next/babel'] }], - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/apps/my-proj', -}; -`, - }); - addBabelJestPresetTransformerOption(tree); - expect(tree.read('projects/my-proj/jest.config.ts', 'utf-8')).toContain( - `'^.+\\\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/next/babel'] }],` - ); - }); - - it('should not update if js project', () => { - setup(tree, { - buildName: '@nrwl/js:tsc', - jestConfigContent: `/* eslint-disable */ -export default { - displayName: 'my-proj', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - transform: { - '^.+\\\\.[tj]s$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../coverage/projects/my-proj', -};`, - }); - - addBabelJestPresetTransformerOption(tree); - expect(tree.read('projects/my-proj/jest.config.ts', 'utf-8')).not.toContain( - 'babel-jest' - ); - }); - - it('should not update if a angular project', () => { - setup(tree, { - buildName: '@angular-devkit/build-angular:browser', - jestConfigContent: `/* eslint-disable */ -export default { - displayName: 'my-proj', - preset: '../../jest.preset.js', - setupFilesAfterEnv: ['/src/test-setup.ts'], - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - stringifyContentPathRegex: '\\\\.(html|svg)$', - }, - }, - coverageDirectory: '../../coverage/projects/my-proj', - transform: { - '^.+\\\\.(ts|mjs|js|html)$': 'jest-preset-angular', - }, - transformIgnorePatterns: ['node_modules/(?!.*\\\\.mjs$|nanoid)'], - snapshotSerializers: [ - 'jest-preset-angular/build/serializers/no-ng-attributes', - 'jest-preset-angular/build/serializers/ng-snapshot', - 'jest-preset-angular/build/serializers/html-comment', - ], -};`, - }); - addBabelJestPresetTransformerOption(tree); - expect(tree.read('projects/my-proj/jest.config.ts', 'utf-8')).not.toContain( - 'babel-jest' - ); - }); - - it('should not update if workspace project', () => { - setup(tree, { - buildName: '@nrwl/node:webpack', - jestConfigContent: `/* eslint-disable */ -export default { - displayName: 'my-proj', - preset: '../../jest.preset.js', - globals: { - 'ts-jest': { - tsconfig: '/tsconfig.spec.json', - }, - }, - transform: { - '^.+\\\\.[tj]sx?$': 'ts-jest', - }, - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], - coverageDirectory: '../../coverage/projects/my-proj', -};`, - }); - - addBabelJestPresetTransformerOption(tree); - expect(tree.read('projects/my-proj/jest.config.ts', 'utf-8')).not.toContain( - 'babel-jest' - ); - }); -}); diff --git a/packages/react/src/migrations/update-14-6-0/add-preset-jest-config.ts b/packages/react/src/migrations/update-14-6-0/add-preset-jest-config.ts deleted file mode 100644 index b71d9f3fcb303..0000000000000 --- a/packages/react/src/migrations/update-14-6-0/add-preset-jest-config.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { - joinPathFragments, - ProjectConfiguration, - readProjectConfiguration, - Tree, -} from '@nx/devkit'; -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; -import type { JestExecutorOptions } from '@nx/jest/src/executors/jest/schema'; -import { tsquery } from '@phenomnomnominal/tsquery'; -import { StringLiteral } from 'typescript'; - -export function addBabelJestPresetTransformerOption(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/jest:jest', - (options, project, target, configuration) => { - if ( - options.jestConfig && - tree.exists(options.jestConfig) && - isReactProject(tree, readProjectConfiguration(tree, project)) - ) { - const oldConfig = tree.read(options.jestConfig, 'utf-8'); - const updatedConfig = tsquery.replace( - oldConfig, - 'PropertyAssignment > StringLiteral[value="babel-jest"]', - (node: StringLiteral) => { - return `['babel-jest', { presets: ['@nrwl/react/babel'] }]`; - } - ); - tree.write(options.jestConfig, updatedConfig); - } - } - ); -} - -function isReactProject(tree: Tree, projectConfig: ProjectConfiguration) { - const knownInvalidExecutors = [ - '@nrwl/next:build', - '@nrwl/angular', - '@angular-devkit/build-angular:browser', - '@nrwl/js:tsc', - '@nrwl/js:swc', - '@nrwl/workspace:run-commands', - 'nx:run-commands', - '@nrwl/node:webpack', - ]; - if ( - knownInvalidExecutors.includes(projectConfig?.targets?.build?.executor) || - tree.exists(joinPathFragments(projectConfig.root, 'next.config.js')) - ) { - return false; - } - return true; -} - -export default addBabelJestPresetTransformerOption; diff --git a/packages/rollup/migrations.json b/packages/rollup/migrations.json index cfd0ba1e6e6fe..0034ebb306565 100644 --- a/packages/rollup/migrations.json +++ b/packages/rollup/migrations.json @@ -14,7 +14,7 @@ }, "update-16-3-3-add-babel-upward-root-mode-flag": { "cli": "nx", - "version": "16-3-3-beta.0", + "version": "16.3.3-beta.0", "description": "Add babelUpwardRootMode if not already defined", "implementation": "./src/migrations/update-16-3-3-add-babel-upward-root-mode-flag/update-16-3-3-add-babel-upward-root-mode-flag" }, diff --git a/packages/storybook/migrations.json b/packages/storybook/migrations.json index 57010862620b3..a7bd7095ab009 100644 --- a/packages/storybook/migrations.json +++ b/packages/storybook/migrations.json @@ -1,23 +1,5 @@ { "generators": { - "update-13.4.6": { - "version": "13.4.6-beta.1", - "cli": "nx", - "description": "Add projectBuildConfig option to project's Storybook config.", - "factory": "./src/migrations/update-13-4-6/set-project-build-config" - }, - "update-14.0.0": { - "version": "14.0.0", - "cli": "nx", - "description": "Migrate Storybook to v6", - "factory": "./src/migrations/update-14-0-0/migrate-to-storybook-6" - }, - "update-14.1.8": { - "version": "14.1.8", - "cli": "nx", - "description": "Change storybook targets for Angular projects to use @storybook/angular executors", - "factory": "./src/migrations/update-14-1-8/change-storybook-targets" - }, "update-15.0.8-add-storybook-inputs": { "cli": "nx", "version": "15.0.0-beta.0", @@ -741,159 +723,6 @@ "alwaysAddToPackageJson": false } } - }, - "14.3.2": { - "version": "14.3.2-beta.1", - "packages": { - "@storybook/core-server": { - "version": "~6.5.9", - "alwaysAddToPackageJson": true - }, - "@storybook/angular": { - "version": "~6.5.9", - "alwaysAddToPackageJson": false - }, - "@storybook/react": { - "version": "~6.5.9", - "alwaysAddToPackageJson": false - }, - "@storybook/web": { - "version": "~6.5.9", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-essentials": { - "version": "~6.5.9", - "alwaysAddToPackageJson": false - }, - "@storybook/builder-webpack5": { - "version": "~6.5.9", - "alwaysAddToPackageJson": true - }, - "@storybook/manager-webpack5": { - "version": "~6.5.9", - "alwaysAddToPackageJson": true - } - } - }, - "14.2.0": { - "version": "14.2.0-beta.6", - "packages": { - "@storybook/core-server": { - "version": "~6.5.4", - "alwaysAddToPackageJson": true - }, - "@storybook/angular": { - "version": "~6.5.4", - "alwaysAddToPackageJson": false - }, - "@storybook/react": { - "version": "~6.5.4", - "alwaysAddToPackageJson": false - }, - "@storybook/web": { - "version": "~6.5.4", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-essentials": { - "version": "~6.5.4", - "alwaysAddToPackageJson": false - }, - "@storybook/builder-webpack5": { - "version": "~6.5.4", - "alwaysAddToPackageJson": true - }, - "@storybook/manager-webpack5": { - "version": "~6.5.4", - "alwaysAddToPackageJson": true - } - } - }, - "13.10.0": { - "version": "13.10.0-beta.0", - "packages": { - "@storybook/core-server": { - "version": "~6.4.12", - "alwaysAddToPackageJson": true - }, - "@storybook/react-native": { - "version": "^6.0.1-beta.5", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-ondevice-actions": { - "version": "^6.0.1-beta.5", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-ondevice-backgrounds": { - "version": "^6.0.1-beta.5", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-ondevice-controls": { - "version": "^6.0.1-beta.5", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-ondevice-notes": { - "version": "^6.0.1-beta.5", - "alwaysAddToPackageJson": false - } - } - }, - "13.4.5": { - "version": "13.4.5-beta.1", - "packages": { - "@storybook/angular": { - "version": "~6.4.12", - "alwaysAddToPackageJson": false - }, - "@storybook/react": { - "version": "~6.4.12", - "alwaysAddToPackageJson": false - }, - "@storybook/web": { - "version": "~6.4.12", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-essentials": { - "version": "~6.4.12", - "alwaysAddToPackageJson": false - }, - "@storybook/builder-webpack5": { - "version": "~6.4.12", - "alwaysAddToPackageJson": true - }, - "@storybook/manager-webpack5": { - "version": "~6.4.12", - "alwaysAddToPackageJson": true - } - } - }, - "13.3.0": { - "version": "13.3.0-beta.3", - "packages": { - "@storybook/angular": { - "version": "~6.4.5", - "alwaysAddToPackageJson": false - }, - "@storybook/react": { - "version": "~6.4.5", - "alwaysAddToPackageJson": false - }, - "@storybook/web": { - "version": "~6.4.5", - "alwaysAddToPackageJson": false - }, - "@storybook/addon-essentials": { - "version": "~6.4.5", - "alwaysAddToPackageJson": false - }, - "@storybook/builder-webpack5": { - "version": "~6.4.5", - "alwaysAddToPackageJson": true - }, - "@storybook/manager-webpack5": { - "version": "~6.4.5", - "alwaysAddToPackageJson": true - } - } } } } diff --git a/packages/storybook/package.json b/packages/storybook/package.json index 7828c521f8c09..bcf6a7f76af9c 100644 --- a/packages/storybook/package.json +++ b/packages/storybook/package.json @@ -36,8 +36,7 @@ "@nx/cypress": "file:../cypress", "@nx/devkit": "file:../devkit", "@nx/js": "file:../js", - "@nx/linter": "file:../linter", - "@nx/workspace": "file:../workspace" + "@nx/linter": "file:../linter" }, "publishConfig": { "access": "public" diff --git a/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts b/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts deleted file mode 100644 index 5ae34163b54e9..0000000000000 --- a/packages/storybook/src/migrations/update-13-4-6/set-project-build-config.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { - logger, - Tree, - formatFiles, - updateProjectConfiguration, - getProjects, -} from '@nx/devkit'; -import { findStorybookAndBuildTargetsAndCompiler } from '../../utils/utilities'; - -export default async function setProjectBuildConfig(tree: Tree) { - let changesMade = false; - const projects = getProjects(tree); - [...projects.entries()].forEach(([projectName, projectConfiguration]) => { - if (!projectConfiguration.targets) { - return; - } - const { storybookBuildTarget, storybookTarget, ngBuildTarget } = - findStorybookAndBuildTargetsAndCompiler(projectConfiguration.targets); - if ( - projectName && - storybookTarget && - projectConfiguration?.targets?.[storybookTarget]?.options?.uiFramework === - '@storybook/angular' - ) { - if (ngBuildTarget) { - if ( - !projectConfiguration.targets[storybookTarget].options - .projectBuildConfig - ) { - projectConfiguration.targets[ - storybookTarget - ].options.projectBuildConfig = projectName; - changesMade = true; - } - if ( - storybookBuildTarget && - !projectConfiguration.targets[storybookBuildTarget].options - .projectBuildConfig - ) { - projectConfiguration.targets[ - storybookBuildTarget - ].options.projectBuildConfig = projectName; - changesMade = true; - } - } else { - if (storybookBuildTarget) { - if ( - !projectConfiguration.targets[storybookTarget].options - .projectBuildConfig - ) { - projectConfiguration.targets[ - storybookTarget - ].options.projectBuildConfig = `${projectName}:${storybookBuildTarget}`; - changesMade = true; - } - if ( - !projectConfiguration.targets[storybookBuildTarget].options - .projectBuildConfig - ) { - projectConfiguration.targets[ - storybookBuildTarget - ].options.projectBuildConfig = `${projectName}:${storybookBuildTarget}`; - changesMade = true; - } - } else { - logger.warn(`Could not find a build target for ${projectName}.`); - } - } - - if (changesMade) { - updateProjectConfiguration(tree, projectName, projectConfiguration); - } - } - }); - - if (changesMade) { - await formatFiles(tree); - } -} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json deleted file mode 100644 index 492fb8d1cd54f..0000000000000 --- a/packages/storybook/src/migrations/update-13-4-6/test-configs/custom-names-config.json +++ /dev/null @@ -1,146 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "trthrngb": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "asdgsdfg": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "sdft": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - } - } - }, - "thjkkb": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "nmkgd": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - } - } - }, - "aaaa": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "architect": { - "njdfvndfjnv": { - "builder": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "lmfkcn": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "odmwjbc": { - "builder": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json deleted file mode 100644 index 439d649ab4604..0000000000000 --- a/packages/storybook/src/migrations/update-13-4-6/test-configs/default-config.json +++ /dev/null @@ -1,146 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "architect": { - "build": { - "builder": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "build-storybook": { - "builder": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json b/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json deleted file mode 100644 index db81e6f301526..0000000000000 --- a/packages/storybook/src/migrations/update-13-4-6/test-configs/non-angular.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "architect": { - "storybook": { - "builder": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts deleted file mode 100644 index dce09acf85934..0000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.spec.ts +++ /dev/null @@ -1,165 +0,0 @@ -import { - readJson, - readProjectConfiguration, - Tree, - updateJson, - updateProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { storybookVersion } from '../../../utils/versions'; -import configurationGenerator from '../../../generators/configuration/configuration'; -import { - createTestUILibNoNgDevkit, - deleteNewConfigurationAndCreateNew, -} from '../../../utils/testing'; -import { migrateDefaultsGenerator } from './migrate-defaults-5-to-6'; - -// nested code imports graph from the repo, which might have innacurate graph version -jest.mock('nx/src/project-graph/project-graph', () => ({ - ...jest.requireActual('nx/src/project-graph/project-graph'), - createProjectGraphAsync: jest - .fn() - .mockImplementation(async () => ({ nodes: {}, dependencies: {} })), -})); - -describe('migrate-defaults-5-to-6 Generator', () => { - let appTree: Tree; - - beforeEach(async () => { - appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(appTree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@nrwl/storybook': '10.4.0', - '@nrwl/workspace': '10.4.0', - '@storybook/addon-knobs': '^5.3.8', - '@storybook/angular': '^5.3.8', - '@storybook/addon-notes': '5.3.21', - '@storybook/addon-postcss': '2.0.0', - }, - }; - }); - await createTestUILibNoNgDevkit(appTree, 'test-ui-lib1'); - await createTestUILibNoNgDevkit(appTree, 'test-ui-lib2'); - - await configurationGenerator(appTree, { - name: 'test-ui-lib1', - uiFramework: '@storybook/react' as any, - }); - - const lib1Configuration = readProjectConfiguration(appTree, 'test-ui-lib1'); - - updateProjectConfiguration(appTree, 'test-ui-lib1', { - ...lib1Configuration, - targets: { - ...lib1Configuration.targets, - storybook: { - ...lib1Configuration.targets.storybook, - options: { - ...lib1Configuration.targets.storybook.options, - config: { - configFolder: - lib1Configuration.targets.storybook.options.configDir, - }, - }, - }, - }, - }); - - appTree = deleteNewConfigurationAndCreateNew( - appTree, - 'libs/test-ui-lib1/.storybook' - ); - - await configurationGenerator(appTree, { - name: 'test-ui-lib2', - uiFramework: '@storybook/react' as any, - }); - - const lib2Configuration = readProjectConfiguration(appTree, 'test-ui-lib2'); - - updateProjectConfiguration(appTree, 'test-ui-lib2', { - ...lib2Configuration, - targets: { - ...lib2Configuration.targets, - storybook: { - ...lib2Configuration.targets.storybook, - options: { - ...lib2Configuration.targets.storybook.options, - config: { - configFolder: - lib2Configuration.targets.storybook.options.configDir, - }, - }, - }, - }, - }); - - appTree = deleteNewConfigurationAndCreateNew( - appTree, - 'libs/test-ui-lib2/.storybook' - ); - - updateJson(appTree, 'package.json', (json) => { - return { - ...json, - devDependencies: { - ...json.devDependencies, - '@storybook/addon-knobs': '^5.3.8', - '@storybook/angular': '^5.3.8', - }, - }; - }); - }); - - it('should update Storybook packages to latest version and ignore the ones to be ignored', async () => { - migrateDefaultsGenerator(appTree); - - const packageJson = readJson(appTree, 'package.json'); - expect(packageJson.devDependencies['@storybook/angular']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-knobs']).toEqual( - storybookVersion - ); - expect(packageJson.devDependencies['@storybook/addon-notes']).toEqual( - '5.3.21' - ); - expect(packageJson.devDependencies['@storybook/addon-postcss']).toEqual( - '2.0.0' - ); - }); - - it('should update configuration of all projects', async () => { - migrateDefaultsGenerator(appTree); - - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') - ).toBeTruthy(); - - expect(appTree.exists('libs/test-ui-lib1/.storybook/main.js')).toBeTruthy(); - expect(appTree.exists('libs/test-ui-lib2/.storybook/main.js')).toBeTruthy(); - }); - - it('should keep old files and put them in .old_storybook directory', async () => { - migrateDefaultsGenerator(appTree); - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib1/.old_storybook/config.js') - ).toBeTruthy(); - - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/addons.js') - ).toBeTruthy(); - expect( - appTree.exists('libs/test-ui-lib2/.old_storybook/config.js') - ).toBeTruthy(); - }); -}); diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts deleted file mode 100644 index 6d20313448739..0000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-defaults-5-to-6/migrate-defaults-5-to-6.ts +++ /dev/null @@ -1,210 +0,0 @@ -import { - GeneratorCallback, - getProjects, - installPackagesTask, - logger, - readProjectConfiguration, - Tree, - updateJson, - visitNotIgnoredFiles, -} from '@nx/devkit'; -import { lte } from 'semver'; -import { checkAndCleanWithSemver } from '@nx/devkit/src/utils/semver'; -import { storybookVersion } from '../../../utils/versions'; -import { createProjectStorybookDir } from '../../../generators/configuration/lib/util-functions'; -import { StorybookConfigureSchema } from '../../../generators/configuration/schema'; -import { findStorybookAndBuildTargetsAndCompiler } from '../../../utils/utilities'; - -export function migrateDefaultsGenerator(tree: Tree) { - migrateAllStorybookInstances(tree); - return upgradeStorybookPackagesInPackageJson(tree); -} - -export function migrateAllStorybookInstances(tree: Tree) { - logger.debug('adding .storybook folder to project'); - const projects = getProjects(tree); - const projectsThatHaveStorybookConfiguration: { - name: string; - uiFramework: StorybookConfigureSchema['uiFramework']; - configFolder: string; - }[] = [...projects.entries()] - .filter( - ([_, projectConfig]) => - projectConfig?.targets?.storybook && - projectConfig?.targets?.storybook?.executor !== - '@nrwl/react-native:storybook' - ) - .map(([projectName, projectConfig]) => { - return { - name: projectName, - uiFramework: projectConfig?.targets?.storybook?.options?.uiFramework, - configFolder: - projectConfig?.targets?.storybook?.options?.config?.configFolder ?? - '', - }; - }); - - for (const projectWithStorybook of projectsThatHaveStorybookConfiguration) { - migrateStorybookInstance( - tree, - projectWithStorybook.name, - projectWithStorybook.uiFramework, - projectWithStorybook.configFolder - ); - } -} - -export function migrateStorybookInstance( - tree: Tree, - projectName: string, - uiFramework: StorybookConfigureSchema['uiFramework'], - configFolder?: string -) { - migrateProjectLevelStorybookInstance( - tree, - projectName, - uiFramework, - configFolder - ); -} - -function maybeUpdateVersion(tree: Tree): GeneratorCallback { - let needsInstall = false; - updateJson(tree, 'package.json', (json) => { - const ignoredStorybookPackages = [ - '@storybook/builder-vite', - '@storybook/jest', - '@storybook/react-native', - '@storybook/storybook-deployer', - '@storybook/test-runner', - '@storybook/testing-library', - '@storybook/testing-angular', - '@storybook/testing-react', - '@storybook/testing-vue', - '@storybook/testing-vue3', - '@storybook/addon-notes', - '@storybook/addon-postcss', - ]; - - json.dependencies = json.dependencies || {}; - json.devDependencies = json.devDependencies || {}; - - const allStorybookPackagesInDependencies = Object.keys( - json.dependencies - ).filter( - (packageName: string) => - packageName.startsWith('@storybook/') && - !ignoredStorybookPackages.includes(packageName) - ); - - const allStorybookPackagesInDevDependencies = Object.keys( - json.devDependencies - ).filter( - (packageName: string) => - packageName.startsWith('@storybook/') && - !ignoredStorybookPackages.includes(packageName) - ); - - const storybookPackages = [ - ...allStorybookPackagesInDependencies, - ...allStorybookPackagesInDevDependencies, - ]; - - storybookPackages.forEach((storybookPackageName) => { - if (json.dependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.dependencies[storybookPackageName] - ); - if (lte(version, '6.0.0')) { - json.dependencies[storybookPackageName] = storybookVersion; - needsInstall = true; - } - } - if (json.devDependencies[storybookPackageName]) { - const version = checkAndCleanWithSemver( - storybookPackageName, - json.devDependencies[storybookPackageName] - ); - if (lte(version, '6.0.0')) { - json.devDependencies[storybookPackageName] = storybookVersion; - needsInstall = true; - } - } - }); - return json; - }); - - if (needsInstall) { - return () => installPackagesTask(tree); - } -} - -function upgradeStorybookPackagesInPackageJson(tree: Tree) { - /** - * Should upgrade all @storybook/* packages in package.json - */ - - return maybeUpdateVersion(tree); -} - -function moveOldFiles(tree: Tree, configFolderDir: string) { - moveDirectory( - tree, - configFolderDir, - configFolderDir.replace('.storybook', '.old_storybook') - ); -} - -function migrateProjectLevelStorybookInstance( - tree: Tree, - projectName: string, - uiFramework: StorybookConfigureSchema['uiFramework'], - configFolder: string -) { - const old_folder_exists_already = tree.exists( - configFolder?.replace('.storybook', '.old_storybook') - ); - const new_config_exists_already = tree.exists(`${configFolder}/main.js`); - - if (old_folder_exists_already || new_config_exists_already) { - return; - } - - moveOldFiles(tree, configFolder); - - if (tree.exists(configFolder)) { - return; - } - - const { projectType, targets, root } = readProjectConfiguration( - tree, - projectName - ); - const { nextBuildTarget, compiler } = - findStorybookAndBuildTargetsAndCompiler(targets); - - const mainDir = - !!nextBuildTarget && projectType === 'application' ? 'components' : 'src'; - - createProjectStorybookDir( - tree, - projectName, - uiFramework, - false, - false, - root, - projectType, - false, - false, - mainDir, - !!nextBuildTarget, - compiler === 'swc' - ); -} - -export function moveDirectory(tree: Tree, from: string, to: string) { - visitNotIgnoredFiles(tree, from, (file) => { - tree.rename(file, file.replace(from, to)); - }); -} diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts deleted file mode 100644 index 22276edc06006..0000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.spec.ts +++ /dev/null @@ -1,171 +0,0 @@ -import { - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { joinPathFragments, writeJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { storybookVersion } from '../../../utils/versions'; -import { findNodes } from '@nx/js'; -import * as ts from 'typescript'; -import { SyntaxKind } from 'typescript'; -import { nxVersion } from '../../../utils/versions'; -import { migrateStoriesTo62Generator } from './migrate-stories-to-6-2'; -import { - overrideCollectionResolutionForTesting, - wrapAngularDevkitSchematic, -} from '@nx/devkit/ngcli-adapter'; -import { getTsSourceFile } from '../../../utils/utilities'; - -// nested code imports graph from the repo, which might have innacurate graph version -jest.mock('nx/src/project-graph/project-graph', () => ({ - ...jest.requireActual('nx/src/project-graph/project-graph'), - createProjectGraphAsync: jest - .fn() - .mockImplementation(async () => ({ nodes: {}, dependencies: {} })), -})); - -const componentSchematic = wrapAngularDevkitSchematic( - '@schematics/angular', - 'component' -); -const runAngularLibrarySchematic = wrapAngularDevkitSchematic( - '@schematics/angular', - 'library' -); - -const runAngularStorybookSchematic = wrapAngularDevkitSchematic( - '@nx/angular', - 'storybook-configuration' -); - -describe('migrate-stories-to-6-2 schematic', () => { - let appTree: Tree; - - describe('angular project', () => { - beforeEach(async () => { - overrideCollectionResolutionForTesting({ - '@nx/storybook': joinPathFragments( - __dirname, - '../../../../generators.json' - ), - }); - - appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - await runAngularLibrarySchematic(appTree, { - name: 'test-ui-lib', - }); - - await componentSchematic(appTree, { - name: 'test-button', - project: 'test-ui-lib', - }); - - writeJson(appTree, 'package.json', { - devDependencies: { - '@nx/storybook': nxVersion, - '@storybook/addon-knobs': storybookVersion, - '@storybook/angular': storybookVersion, - }, - }); - writeJson(appTree, 'test-ui-lib/tsconfig.json', {}); - - await runAngularStorybookSchematic(appTree, { - name: 'test-ui-lib', - configureCypress: true, - configureStaticServe: false, - }); - - appTree.write( - `test-ui-lib/src/lib/test-button/test-button.component.stories.ts`, - ` - import { text, number, boolean } from '@storybook/addon-knobs'; - import { TestButtonComponent } from './test-button.component'; - - export default { - title: 'TestButtonComponent', - }; - - export const primary = () => ({ - component: TestButtonComponent, - moduleMetadata: { - imports: [], - }, - props: { - buttonType: text('buttonType', 'button'), - style: text('style', 'default'), - age: number('age', 0), - isOn: boolean('isOn', false), - }, - }); - - export const secondary = () => ({ - component: TestButtonComponent, - moduleMetadata: { - imports: [], - }, - props: {}, - }); - ` - ); - - /** - * This needs to be updated for the following reason: - * - runAngularStorybookSchematic now generates the Storybook targets in - * the project configuration using the @storybook/angular executors - * - this means that the uiFramework property is not used any more - * - that property was used in versions before that so the migration script looks for it - * - the migrate-stories-to-6-2 migrator should have already taken effect in previous versions - * so there is no need to update the generator to look for the new executor as well - */ - const projectConfig = readProjectConfiguration(appTree, 'test-ui-lib'); - projectConfig.targets.storybook.options.uiFramework = - '@storybook/angular'; - projectConfig.targets.storybook.options.config = { - configFolder: projectConfig.targets.storybook.options.configDir, - }; - updateProjectConfiguration(appTree, 'test-ui-lib', projectConfig); - }); - - it('should move the component from the story to parameters.component', async () => { - await migrateStoriesTo62Generator(appTree); - const storyFilePath = - 'test-ui-lib/src/lib/test-button/test-button.component.stories.ts'; - const file = getTsSourceFile(appTree, storyFilePath); - const storiesExportDefault = findNodes(file, [ - ts.SyntaxKind.ExportAssignment, - ]); - const defaultExportNode = storiesExportDefault[0]; - const defaultExportObject = defaultExportNode - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.ObjectLiteralExpression; - }); - const defaultPropertiesList = defaultExportObject - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - - const hasTitle = defaultPropertiesList?.getChildren()?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('title') - ); - }); - const hasComponent = defaultPropertiesList - ?.getChildren() - ?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('component') - ); - }); - - expect(appTree.exists(storyFilePath)).toBeTruthy(); - expect(hasTitle).toBeTruthy(); - expect(hasComponent).toBeTruthy(); - }); - }); -}); 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 deleted file mode 100644 index 912a9a9088775..0000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-stories-to-6-2/migrate-stories-to-6-2.ts +++ /dev/null @@ -1,406 +0,0 @@ -import { - applyChangesToString, - ChangeType, - formatFiles, - getProjects, - logger, - stripIndents, - Tree, - visitNotIgnoredFiles, -} from '@nx/devkit'; -import { fileExists } from '@nx/workspace/src/utilities/fileutils'; -import { findNodes } from '@nx/js'; -import { join, normalize } from 'path'; -import { SyntaxKind } from 'typescript'; -import { getTsSourceFile } from '../../../utils/utilities'; -import ts = require('typescript'); - -export async function migrateStoriesTo62Generator(tree: Tree) { - let allComponentsWithStories: { - componentName: string; - componentPath: any; - componentFileName: any; - componentStoryPath: string; - }[] = []; - const result: { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; - }[] = findAllAngularProjectsWithStorybookConfiguration(tree); - result?.forEach( - (angularProjectWithStorybook: { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; - }) => { - const componentResult = findAllComponentsWithStoriesForSpecificProject( - tree, - angularProjectWithStorybook.projectRoot - ); - allComponentsWithStories = [ - ...allComponentsWithStories, - ...componentResult, - ]; - } - ); - allComponentsWithStories?.forEach((componentInfo) => { - changeSyntaxOfStory(tree, componentInfo.componentStoryPath); - }); - await formatFiles(tree); -} - -export function findAllAngularProjectsWithStorybookConfiguration(tree: Tree): { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; -}[] { - const projects = getProjects(tree); - const projectsThatHaveStorybookConfiguration: { - name: string; - configFolder: string; - projectRoot: string; - projectSrc: string; - }[] = [...projects.entries()] - ?.filter( - ([_, projectConfig]) => - projectConfig?.targets?.storybook?.options?.uiFramework === - '@storybook/angular' - ) - ?.map(([projectName, projectConfig]) => { - return { - name: projectName, - configFolder: - projectConfig.targets.storybook?.options?.config?.configFolder, - projectRoot: projectConfig.root, - projectSrc: projectConfig.sourceRoot, - }; - }); - return projectsThatHaveStorybookConfiguration; -} - -function findAllComponentsWithStoriesForSpecificProject( - tree: Tree, - projectPath: string -): { - componentName: string; - componentPath: any; - componentFileName: any; - componentStoryPath: string; -}[] { - let moduleFilePaths = [] as string[]; - visitNotIgnoredFiles(tree, projectPath, (filePath) => { - if (filePath?.endsWith('.module.ts')) { - moduleFilePaths.push(filePath); - } - }); - let componentFileInfos = []; - moduleFilePaths?.map((moduleFilePath) => { - const file = getTsSourceFile(tree, moduleFilePath); - const ngModuleDecorators = findNodes(file, ts.SyntaxKind.Decorator); - if (ngModuleDecorators.length === 0) { - return; - } - const ngModuleDecorator = ngModuleDecorators[0]; - const ngModuleNode = ngModuleDecorator?.getChildren()?.find((node) => { - return node?.getText()?.startsWith('NgModule'); - }); - const ngModulePropertiesObject = ngModuleNode - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - const ngModuleProperties = ngModulePropertiesObject - ?.getChildren()[0] - ?.getChildren() - ?.find((node) => { - return node?.getText()?.includes('declarations'); - }); - - const declarationsPropertyAssignment = ngModuleProperties - ?.getChildren() - ?.find((node) => { - return node?.getText()?.startsWith('declarations'); - }); - - if (!declarationsPropertyAssignment) { - logger.warn(stripIndents`No components declared in ${moduleFilePath}.`); - } - let declarationArray = declarationsPropertyAssignment - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.ArrayLiteralExpression); - if (!declarationArray) { - // Attempt to follow a variable instead of the literal - const declarationVariable = declarationsPropertyAssignment - ?.getChildren() - ?.filter((node) => node.kind === SyntaxKind.Identifier)[1]; - const variableName = declarationVariable?.getText(); - const variableDeclaration = findNodes( - file, - SyntaxKind.VariableDeclaration - )?.find((variableDeclaration) => { - const identifier = variableDeclaration - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.Identifier); - return identifier?.getText() === variableName; - }); - if (variableDeclaration) { - declarationArray = variableDeclaration - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.ArrayLiteralExpression); - } - } - const declaredComponents = declarationArray - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.SyntaxList) - ?.getChildren() - ?.filter((node) => node.kind === SyntaxKind.Identifier) - ?.map((node) => node?.getText()) - ?.filter((name) => name?.endsWith('Component')); - const imports = file.statements?.filter( - (statement) => statement.kind === SyntaxKind.ImportDeclaration - ); - const modulePath = moduleFilePath.slice( - 0, - moduleFilePath?.lastIndexOf('/') - ); - let componentInfo = declaredComponents?.map((componentName) => { - try { - const importStatement = imports?.find((statement) => { - const namedImports = statement - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.ImportClause) - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.NamedImports); - if (namedImports === undefined) return false; - const importedIdentifiers = namedImports - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.SyntaxList) - ?.getChildren() - ?.filter((node) => node.kind === SyntaxKind.ImportSpecifier) - ?.map((node) => node?.getText()); - return importedIdentifiers?.includes(componentName); - }); - - const fullPath = importStatement - ?.getChildren() - ?.find((node) => node.kind === SyntaxKind.StringLiteral) - ?.getText() - ?.slice(1, -1); - - // if it is a directory, search recursively for the component - let fullCmpImportPath = moduleFilePath?.slice( - 0, - moduleFilePath?.lastIndexOf('/') - ); - if (fullCmpImportPath?.startsWith('/')) { - fullCmpImportPath = fullCmpImportPath?.slice( - 1, - fullCmpImportPath.length - ); - } - let componentImportPath = join(normalize(fullCmpImportPath), fullPath); - - let path = null; - let componentFileName = null; - let componentStoryPath = null; - let storyExists = false; - let componentExists = false; - /** - * Here we want to remove the .component - * part of the path, to just keep the - * apps//src/app/ - * or - * libs//src/lib/ - * part of the path - */ - componentImportPath = componentImportPath.slice( - 0, - componentImportPath.lastIndexOf('/') - ); - visitNotIgnoredFiles(tree, componentImportPath, (componentFilePath) => { - if (componentFilePath?.endsWith('.ts')) { - const content = tree.read(componentFilePath).toString('utf-8'); - - if (content?.indexOf(`class ${componentName}`) > -1) { - componentExists = true; - path = componentFilePath; - componentFileName = - componentFilePath?.slice( - componentFilePath?.lastIndexOf('/') + 1, - componentFilePath?.lastIndexOf('.') - ) + '.ts'; - } - - if (componentFilePath?.endsWith('.stories.ts')) { - componentStoryPath = componentFilePath; - storyExists = true; - } - } - }); - if (!storyExists || !componentExists) { - path = null; - componentFileName = null; - componentStoryPath = null; - } - if (path !== null) { - return { - componentName: componentName, - componentPath: path, - componentFileName, - componentStoryPath: componentStoryPath, - }; - } else { - const path = fullPath?.slice(0, fullPath?.lastIndexOf('/')); - const componentFileName = - fullPath?.slice(fullPath?.lastIndexOf('/') + 1) + '.ts'; - - componentStoryPath = fullPath + '.stories.ts'; - if (fileExists(componentStoryPath)) { - return { - componentName: componentName, - componentPath: path + componentFileName, - componentFileName, - componentStoryPath: componentStoryPath, - }; - } else { - return undefined; - } - } - } catch (e) { - logger.warn(`Could not find file for ${componentName}. Error: ${e}`); - return undefined; - } - }); - if (componentInfo) { - componentInfo = componentInfo?.filter((info) => info !== undefined); - componentFileInfos = [...componentFileInfos, ...componentInfo]; - } - }); - return componentFileInfos; -} - -async function changeSyntaxOfStory(tree: Tree, storyFilePath: string) { - const file = getTsSourceFile(tree, storyFilePath); - const appFileContent = tree.read(storyFilePath, 'utf-8'); - let newContents = appFileContent; - const storiesVariableDeclaration = findNodes(file, [ - ts.SyntaxKind.VariableDeclaration, - ]); - const storiesExportDefault = findNodes(file, [ - ts.SyntaxKind.ExportAssignment, - ]); - - const defaultExportNode = storiesExportDefault[0]; - const defaultExportObject = defaultExportNode?.getChildren()?.find((node) => { - return node.kind === SyntaxKind.ObjectLiteralExpression; - }); - const defaultPropertiesList = defaultExportObject - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - const hasTitle = defaultPropertiesList?.getChildren()?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('title') - ); - }); - - /** - * A component node will look like this: - * - * component: MyTestComponent - * - * And this is what we need to remove. - */ - let firstComponentNode: ts.Node; - - /** - * The result of ts.Node.getStart() will give us the index - * of that node in the whole original file. - * While we're editing that file, the getStart() will - * still reference the original file. So, during deletion, - * it would go and delete characters using the original index. - * - * We need to save the length of the characters that have been removed - * so far, so that we can substract it from the index. - * Since it's parsing the file linearly and in order, then this - * logic works. - * */ - - let lengthOfRemovalsSoFar = 0; - - storiesVariableDeclaration?.forEach((oneStory) => { - const oneExportedStoryArrowFunction = oneStory - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.ArrowFunction; - }); - const inParenthesis = oneExportedStoryArrowFunction - ?.getChildren() - ?.find((node) => { - return node.kind === SyntaxKind.ParenthesizedExpression; - }); - const objectLiteralOfStory = inParenthesis?.getChildren()?.find((node) => { - return node.kind === SyntaxKind.ObjectLiteralExpression; - }); - const propertiesList = objectLiteralOfStory?.getChildren()?.find((node) => { - return node.kind === SyntaxKind.SyntaxList; - }); - - const hasComponentDeclared = propertiesList?.getChildren()?.find((node) => { - return ( - node.kind === SyntaxKind.PropertyAssignment && - node.getText().startsWith('component') - ); - }); - - if (hasComponentDeclared) { - /** - * Here I am saving the first component to appear - * in the case where we have multiple stories - */ - if (!firstComponentNode) { - firstComponentNode = hasComponentDeclared; - } - - /** - * Here we are performing the following check: - * If the component we will be adding in the default declaration - * which is the first component that we find - * is the same for this story as well, - * then remove it. - */ - - if (hasComponentDeclared.getText() === firstComponentNode.getText()) { - const indexOfPropertyName = hasComponentDeclared.getStart(); - const lengthOfRemoval = hasComponentDeclared?.getText()?.length + 1; - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Delete, - start: indexOfPropertyName - lengthOfRemovalsSoFar, - length: lengthOfRemoval, - }, - ]); - lengthOfRemovalsSoFar = lengthOfRemovalsSoFar + lengthOfRemoval; - } - } - }); - - if (hasTitle && firstComponentNode) { - const indexOfPropertyName = hasTitle.getEnd(); - newContents = applyChangesToString(newContents, [ - { - type: ChangeType.Insert, - index: indexOfPropertyName + 2, - text: firstComponentNode.getText() + ',', - }, - ]); - tree.write(storyFilePath, newContents); - } - - await formatFiles(tree); -} diff --git a/packages/storybook/src/migrations/update-14-0-0/migrate-to-storybook-6.ts b/packages/storybook/src/migrations/update-14-0-0/migrate-to-storybook-6.ts deleted file mode 100644 index c6af606dd3770..0000000000000 --- a/packages/storybook/src/migrations/update-14-0-0/migrate-to-storybook-6.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Tree } from '@nx/devkit'; -import { migrateDefaultsGenerator } from './migrate-defaults-5-to-6/migrate-defaults-5-to-6'; -import { migrateStoriesTo62Generator } from './migrate-stories-to-6-2/migrate-stories-to-6-2'; - -export default async function migrateToStorybook6(tree: Tree) { - migrateStoriesTo62Generator(tree); - return migrateDefaultsGenerator(tree); -} diff --git a/packages/storybook/src/migrations/update-14-1-8/__snapshots__/change-storybook-targets-generator.spec.ts.snap b/packages/storybook/src/migrations/update-14-1-8/__snapshots__/change-storybook-targets-generator.spec.ts.snap deleted file mode 100644 index 7b458ed4051fe..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/__snapshots__/change-storybook-targets-generator.spec.ts.snap +++ /dev/null @@ -1,133 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Change the Storybook targets for Angular projects to use native Storybooke executor for all types of angular projects - non-buildable and buildable libs/apps should keep any extra options added in the target 1`] = ` -{ - "affected": { - "defaultBase": "main", - }, - "npmScope": "proj", - "tasksRunnerOptions": { - "default": { - "options": { - "cacheableOperations": [ - "build", - "lint", - "test", - "e2e", - ], - }, - "runner": "nx/tasks-runners/default", - }, - }, -} -`; - -exports[`Change the Storybook targets for Angular projects to use native Storybooke executor for all types of angular projects - non-buildable and buildable libs/apps should not throw an error if no Storybook exists 1`] = ` -{ - "affected": { - "defaultBase": "main", - }, - "npmScope": "proj", - "tasksRunnerOptions": { - "default": { - "options": { - "cacheableOperations": [ - "build", - "lint", - "test", - "e2e", - ], - }, - "runner": "nx/tasks-runners/default", - }, - }, -} -`; - -exports[`Change the Storybook targets for Angular projects to use native Storybooke executor for all types of angular projects - non-buildable and buildable libs/apps should set the browserTarget correctly even if target names are not the default 1`] = ` -{ - "affected": { - "defaultBase": "main", - }, - "npmScope": "proj", - "tasksRunnerOptions": { - "default": { - "options": { - "cacheableOperations": [ - "build", - "lint", - "test", - "e2e", - ], - }, - "runner": "nx/tasks-runners/default", - }, - }, -} -`; - -exports[`Change the Storybook targets for Angular projects to use native Storybooke executor for all types of angular projects - non-buildable and buildable libs/apps should set the browserTarget correctly in the Storybook config according to the type of project 1`] = ` -{ - "affected": { - "defaultBase": "main", - }, - "npmScope": "proj", - "tasksRunnerOptions": { - "default": { - "options": { - "cacheableOperations": [ - "build", - "lint", - "test", - "e2e", - ], - }, - "runner": "nx/tasks-runners/default", - }, - }, -} -`; - -exports[`Change the Storybook targets for Angular projects to use native Storybooke executor for all types of angular projects - non-buildable and buildable libs/apps should work even if build-storybook does not exist 1`] = ` -{ - "affected": { - "defaultBase": "main", - }, - "npmScope": "proj", - "tasksRunnerOptions": { - "default": { - "options": { - "cacheableOperations": [ - "build", - "lint", - "test", - "e2e", - ], - }, - "runner": "nx/tasks-runners/default", - }, - }, -} -`; - -exports[`Change the Storybook targets for Angular projects to use native Storybooke executor for non-angular projects should not change their Storybook targets 1`] = ` -{ - "affected": { - "defaultBase": "main", - }, - "npmScope": "proj", - "tasksRunnerOptions": { - "default": { - "options": { - "cacheableOperations": [ - "build", - "lint", - "test", - "e2e", - ], - }, - "runner": "nx/tasks-runners/default", - }, - }, -} -`; diff --git a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts b/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts deleted file mode 100644 index 892d0b1579ec0..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { addProjectConfiguration, readNxJson, Tree } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import changeStorybookTargetsGenerator from './change-storybook-targets-generator'; -import * as defaultConfig from './test-configs/default-config.json'; -import * as customNames from './test-configs/custom-names-config.json'; -import * as nonAngular from './test-configs/non-angular.json'; -import * as extraOptions from './test-configs/extra-options-for-storybook.json'; -import * as noStorybookBuildTarget from './test-configs/no-build-storybook-target.json'; -import * as noStorybook from './test-configs/no-storybook-targets.json'; - -describe('Change the Storybook targets for Angular projects to use native Storybooke executor', () => { - let tree: Tree; - - describe('for all types of angular projects - non-buildable and buildable libs/apps', () => { - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it(`should set the browserTarget correctly in the Storybook config according to the type of project`, async () => { - writeConfig(tree, defaultConfig); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - - it(`should set the browserTarget correctly even if target names are not the default`, async () => { - writeConfig(tree, customNames); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - - it(`should keep any extra options added in the target`, async () => { - writeConfig(tree, extraOptions); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - it(`should work even if build-storybook does not exist`, async () => { - writeConfig(tree, noStorybookBuildTarget); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - - it(`should not throw an error if no Storybook exists`, async () => { - writeConfig(tree, noStorybook); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - }); - - describe('for non-angular projects', () => { - it(`should not change their Storybook targets`, async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - writeConfig(tree, nonAngular); - await changeStorybookTargetsGenerator(tree); - expect(readNxJson(tree)).toMatchSnapshot(); - }); - }); -}); - -function writeConfig(tree: Tree, config: any) { - Object.keys(config.projects).forEach((project) => { - addProjectConfiguration(tree, project, config.projects[project]); - }); -} diff --git a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts b/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts deleted file mode 100644 index e02e94ac7e86f..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets-generator.ts +++ /dev/null @@ -1,173 +0,0 @@ -import { - logger, - Tree, - formatFiles, - updateProjectConfiguration, - getProjects, - TargetConfiguration, - ProjectConfiguration, - Target, - convertNxGenerator, -} from '@nx/devkit'; -import { findStorybookAndBuildTargetsAndCompiler } from '../../utils/utilities'; - -export async function changeStorybookTargetsGenerator(tree: Tree) { - let changesMade = false; - let changesMadeToAtLeastOne = false; - const projects = getProjects(tree); - [...projects.entries()].forEach(([projectName, projectConfiguration]) => { - changesMade = false; - const { storybookBuildTarget, storybookTarget, ngBuildTarget } = - findStorybookAndBuildTargetsAndCompiler(projectConfiguration.targets); - if ( - projectName && - storybookTarget && - projectConfiguration?.targets?.[storybookTarget]?.options?.uiFramework === - '@storybook/angular' - ) { - projectConfiguration.targets[storybookTarget] = updateStorybookTarget( - projectConfiguration, - storybookTarget, - projectName, - ngBuildTarget, - storybookBuildTarget - ); - changesMade = true; - changesMadeToAtLeastOne = true; - if (storybookBuildTarget) { - projectConfiguration.targets[storybookBuildTarget] = - updateStorybookBuildTarget( - projectConfiguration, - projectName, - ngBuildTarget, - storybookBuildTarget - ); - } else { - logger.info( - `Project ${projectName} does not have a build target configured for Storybook.` - ); - } - } else { - logger.warn(`Could not find a Storybook target for ${projectName}.`); - } - if (changesMade) { - updateProjectConfiguration(tree, projectName, projectConfiguration); - } - }); - - if (changesMadeToAtLeastOne) { - await formatFiles(tree); - } -} - -function updateStorybookTarget( - projectConfiguration: ProjectConfiguration, - storybookTarget: string, - projectName: string, - buildTarget: string, - storybookBuildTarget: string -): TargetConfiguration { - const oldStorybookTargetConfig: TargetConfiguration = - projectConfiguration.targets[storybookTarget]; - - const newStorybookTargetConfig: TargetConfiguration = { - executor: '@storybook/angular:start-storybook', - options: { - port: oldStorybookTargetConfig.options.port, - configDir: oldStorybookTargetConfig.options.config?.configFolder, - browserTarget: undefined, - compodoc: false, - }, - configurations: oldStorybookTargetConfig.configurations, - }; - - const { project, target } = parseTargetStringCustom( - oldStorybookTargetConfig.options.projectBuildConfig - ); - if (project && target) { - newStorybookTargetConfig.options.browserTarget = - oldStorybookTargetConfig.options.projectBuildConfig; - } else { - newStorybookTargetConfig.options.browserTarget = `${projectName}:${ - buildTarget ? buildTarget : storybookBuildTarget - }`; - } - - const { - uiFramework, - outputPath, - config, - projectBuildConfig, - ...optionsToCopy - } = oldStorybookTargetConfig.options; - - newStorybookTargetConfig.options = { - ...optionsToCopy, - ...newStorybookTargetConfig.options, - }; - - return newStorybookTargetConfig; -} - -function updateStorybookBuildTarget( - projectConfiguration: ProjectConfiguration, - projectName: string, - buildTarget: string, - storybookBuildTarget: string -): TargetConfiguration { - const oldStorybookBuildTargetConfig: TargetConfiguration = - projectConfiguration.targets[storybookBuildTarget]; - const newStorybookBuildTargetConfig: TargetConfiguration = { - executor: '@storybook/angular:build-storybook', - outputs: oldStorybookBuildTargetConfig.outputs, - options: { - outputDir: oldStorybookBuildTargetConfig.options.outputPath, - configDir: oldStorybookBuildTargetConfig.options.config?.configFolder, - browserTarget: undefined, - compodoc: false, - }, - configurations: oldStorybookBuildTargetConfig.configurations, - }; - - const { project, target } = parseTargetStringCustom( - oldStorybookBuildTargetConfig.options.projectBuildConfig - ); - if (project && target) { - newStorybookBuildTargetConfig.options.browserTarget = - oldStorybookBuildTargetConfig.options.projectBuildConfig; - } else { - newStorybookBuildTargetConfig.options.browserTarget = `${projectName}:${ - buildTarget ? buildTarget : storybookBuildTarget - }`; - } - - const { - uiFramework, - outputPath, - config, - projectBuildConfig, - ...optionsToCopy - } = oldStorybookBuildTargetConfig.options; - - newStorybookBuildTargetConfig.options = { - ...optionsToCopy, - ...newStorybookBuildTargetConfig.options, - }; - - return newStorybookBuildTargetConfig; -} - -function parseTargetStringCustom(targetString: string): Target { - const [project, target, configuration] = targetString.split(':'); - - return { - project, - target, - configuration, - }; -} - -export default changeStorybookTargetsGenerator; -export const changeStorybookTargetsSchematic = convertNxGenerator( - changeStorybookTargetsGenerator -); diff --git a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets.ts b/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets.ts deleted file mode 100644 index a754d7c897c2c..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/change-storybook-targets.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Tree } from '@nx/devkit'; -import { changeStorybookTargetsGenerator } from './change-storybook-targets-generator'; - -export default async function changeStorybookTargets(tree: Tree) { - return changeStorybookTargetsGenerator(tree); -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json deleted file mode 100644 index 87a662bc001fa..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/custom-names-config.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "trthrngb": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:asdgsdfg" - } - }, - "asdgsdfg": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:asdgsdfg" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "sdft": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:thjkkb" - } - }, - "thjkkb": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:thjkkb" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "nmkgd": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:aaaa" - } - }, - "aaaa": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:aaaa" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "njdfvndfjnv": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "lmfkcn": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "odmwjbc": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json deleted file mode 100644 index 19be537bd91a4..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/default-config.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook" - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook" - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook" - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json deleted file mode 100644 index 7badb6b8e0058..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/extra-options-for-storybook.json +++ /dev/null @@ -1,222 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - }, - "projectBuildConfig": "ui-one:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/two", - "config": { - "configFolder": "libs/ui/two/.storybook" - }, - "projectBuildConfig": "ui-two:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/three", - "config": { - "configFolder": "libs/ui/three/.storybook" - }, - "projectBuildConfig": "ui-three:build-storybook", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false - }, - "configurations": { - "ci": { - "quiet": true - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/main-app", - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app", - "stylePreprocessorOptions": { - "includePaths": [ - "node_modules/@storybook/addon-storysource/node_modules/highlight.js/styles/github.css" - ] - }, - "styles": ["apps/webng/src/styles.css"], - "compodocArgs": ["-e", "json"], - "docsMode": false, - "loglevel": "info" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json deleted file mode 100644 index 921b0aba4887c..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-build-storybook-target.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "projects": { - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - }, - "projectBuildConfig": "main-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "other-app": { - "projectType": "application", - "root": "apps/other-app", - "sourceRoot": "apps/other-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - }, - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/angular", - "port": 4400, - "config": { - "configFolder": "apps/other-app/.storybook" - }, - "projectBuildConfig": "other-app" - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json deleted file mode 100644 index 5d53bd22c3f3a..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/no-storybook-targets.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": {} - }, - "ui-two": { - "projectType": "library", - "root": "libs/ui/two", - "sourceRoot": "libs/ui/two/src", - "targets": {} - }, - "ui-three": { - "projectType": "library", - "root": "libs/ui/three", - "sourceRoot": "libs/ui/three/src", - "targets": {} - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "build": { - "executor": "@angular-devkit/build-angular:browser", - "outputs": ["{options.outputPath}"] - } - } - } - } -} diff --git a/packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json b/packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json deleted file mode 100644 index edd7136372f91..0000000000000 --- a/packages/storybook/src/migrations/update-14-1-8/test-configs/non-angular.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "projects": { - "ui-one": { - "projectType": "library", - "root": "libs/ui/one", - "sourceRoot": "libs/ui/one/src", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "libs/ui/one/.storybook" - } - } - }, - "build-storybook": { - "executor": "@nrwl/storybook:build", - "outputs": ["{options.outputPath}"], - "options": { - "uiFramework": "@storybook/angular", - "outputPath": "dist/storybook/ui/one", - "config": { - "configFolder": "libs/ui/one/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - }, - "main-app": { - "projectType": "application", - "root": "apps/main-app", - "sourceRoot": "apps/main-app/src", - "prefix": "katst", - "targets": { - "storybook": { - "executor": "@nrwl/storybook:storybook", - "options": { - "uiFramework": "@storybook/react", - "port": 4400, - "config": { - "configFolder": "apps/main-app/.storybook" - } - }, - "configurations": { - "ci": { - "quiet": true - } - } - } - } - } - } -} diff --git a/packages/web/migrations.json b/packages/web/migrations.json index 84c2150e77d84..1217a63a33e33 100644 --- a/packages/web/migrations.json +++ b/packages/web/migrations.json @@ -1,41 +1,5 @@ { "generators": { - "remove-node-sass-13-0-0": { - "cli": "nx", - "version": "13.0.0-beta.1", - "description": "Removes deprecated node-sass package (sass is already a dependency of @nrwl/web).", - "factory": "./src/migrations/update-13-0-0/remove-node-sass-13-0-0" - }, - "remove-webpack-5-packages": { - "cli": "nx", - "version": "13.0.0-beta.1", - "description": "Remove packages installed by Nx 12's `@nrwl/web:webpack5` generator.", - "factory": "./src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0" - }, - "rename-build-to-webpack": { - "cli": "nx", - "version": "13.3.0-beta.1", - "description": "Rename the 'build' executor to 'webpack'", - "factory": "./src/migrations/update-13-3-0/rename-build-to-webpack" - }, - "rename-package-to-rollup": { - "cli": "nx", - "version": "13.3.0-beta.1", - "description": "Rename the 'package' executor to 'rollup'", - "factory": "./src/migrations/update-13-3-0/rename-package-to-rollup" - }, - "add-postcss-config-option": { - "cli": "nx", - "version": "13.8.0-beta.1", - "description": "Add a postcss config option to apps to load a single config file for all libs", - "factory": "./src/migrations/update-13-8-0/add-postcss-config-option" - }, - "update-webpack-executor": { - "cli": "nx", - "version": "14.7.6-beta.1", - "description": "Update usages of webpack executors to @nrwl/webpack", - "factory": "./src/migrations/update-14-7-6/update-webpack-executor" - }, "add-babel-inputs": { "cli": "nx", "version": "15.0.0-beta.0", @@ -73,24 +37,5 @@ "implementation": "./src/migrations/update-16-0-0-update-executors/update-16-0-0-update-executors" } }, - "packageJsonUpdates": { - "14.3.7": { - "version": "14.3.7-beta.0", - "packages": { - "@types/node": { - "version": "18.0.0", - "alwaysAddToPackageJson": false - } - } - }, - "14.5.5": { - "version": "14.5.5-beta.0", - "packages": { - "@types/node": { - "version": "18.7.1", - "alwaysAddToPackageJson": false - } - } - } - } + "packageJsonUpdates": {} } diff --git a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts b/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts deleted file mode 100644 index 9e3286936b9ea..0000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import subject from './remove-deprecated-options-13-0-0'; - -describe('Migration: Remove deprecated options', () => { - it(`should remove deprecated web build options`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:build', - options: { - showCircularDependencies: false, - budgets: [], - }, - configurations: { - production: { - showCircularDependencies: true, - budgets: [], - }, - }, - }, - }, - }); - - await subject(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:build', - options: {}, - configurations: { - production: {}, - }, - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts b/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts deleted file mode 100644 index b768690433da7..0000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-deprecated-options-13-0-0.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - formatFiles, - getProjects, - logger, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -const deprecatedOptions = ['showCircularDependencies', 'budgets']; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - if (config.targets.build.executor !== '@nrwl/web:build') return; - - for (const opt of deprecatedOptions) { - let updated = false; - if ( - typeof config.targets.build?.configurations?.production?.[opt] !== - 'undefined' - ) { - delete config.targets.build.configurations.production[opt]; - updated = true; - } - if (typeof config.targets.build.options[opt] !== 'undefined') { - delete config.targets.build.options[opt]; - updated = true; - } - - if (updated) { - updateProjectConfiguration(host, name, config); - logger.info(`NX Removed legacy build option from "${name}": ${opt}`); - } - } - } - - await formatFiles(host); -} diff --git a/packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.spec.ts b/packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.spec.ts deleted file mode 100644 index 58cc864bc59a4..0000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { readJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import subject from './remove-node-sass-13-0-0'; - -describe('Migration: node-sass to sass', () => { - it(`should remove node-sass if present in devDependencies or dependencies`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { a: '1.0.0' }, - devDependencies: { b: '1.0.0', 'node-sass': '1.0.0' }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { a: '1.0.0' }, - devDependencies: { b: '1.0.0' }, - }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { a: '1.0.0', 'node-sass': '1.0.0' }, - devDependencies: { b: '1.0.0' }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { a: '1.0.0' }, - devDependencies: { b: '1.0.0' }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.ts b/packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.ts deleted file mode 100644 index 7792a558cdc56..0000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-node-sass-13-0-0.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { - formatFiles, - GeneratorCallback, - readJson, - removeDependenciesFromPackageJson, - Tree, -} from '@nx/devkit'; - -/** - * For web/react apps with style scss option, remove node-sass sine it is deprecated. - * We already include sass package in `@nrwl/web` deps so no need to install anything extra. - */ -export default async function update(tree: Tree) { - const packageJson = readJson(tree, 'package.json'); - let task: undefined | GeneratorCallback = undefined; - - if (packageJson.devDependencies['node-sass']) { - task = removeDependenciesFromPackageJson(tree, [], ['node-sass']); - } - - if (packageJson.dependencies['node-sass']) { - task = removeDependenciesFromPackageJson(tree, ['node-sass'], []); - } - - if (task) await formatFiles(tree); - - return task; -} diff --git a/packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts b/packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts deleted file mode 100644 index a84c5800ae2fb..0000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.spec.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { readJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import subject from './remove-webpack-5-packages-13-0-0'; - -describe('Migration: Remove webpack 5 packages from Nx12', () => { - const webpack5Packages = { - webpack: '^5.0.0', - 'copy-webpack-plugin': '1.0.0', - 'webpack-merge': '1.0.0', - 'webpack-node-externals': '1.0.0', - 'mini-css-extract-plugin': '1.0.0', - 'source-map-loader': '1.0.0', - 'terser-webpack-plugin': '1.0.0', - 'webpack-dev-server': '1.0.0', - 'webpack-sources': '1.0.0', - 'react-refresh': '1.0.0', - '@pmmmwh/react-refresh-webpack-plugin': '1.0.0', - }; - - it.each` - version - ${'5.0.0'} - ${'~5.0.0'} - ${'^5.0.0'} - `( - `should remove packages installed via webpack5 generator`, - async ({ version }) => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - ...webpack5Packages, - webpack: version, - }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - }, - }); - } - ); - - it.each` - version - ${'4.0.0'} - ${'50.0.0'} - `( - `should not do anything if the webpack version is not 5`, - async ({ version }) => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - ...webpack5Packages, - webpack: version, - }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - ...webpack5Packages, - webpack: version, - }, - }); - } - ); - - it(`should not remove packages not every expected package is installed`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - tree.write( - 'package.json', - JSON.stringify({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - webpack: '^5.0.0', - 'copy-webpack-plugin': '1.0.0', - }, - }) - ); - - await subject(tree); - - expect(readJson(tree, 'package.json')).toEqual({ - dependencies: { - react: '17.0.0', - }, - devDependencies: { - lodash: '1.0.0', - webpack: '^5.0.0', - 'copy-webpack-plugin': '1.0.0', - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts b/packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts deleted file mode 100644 index 353b4810e7ed0..0000000000000 --- a/packages/web/src/migrations/update-13-0-0/remove-webpack-5-packages-13-0-0.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { - formatFiles, - GeneratorCallback, - readJson, - removeDependenciesFromPackageJson, - Tree, -} from '@nx/devkit'; - -const packages = [ - 'webpack', - 'copy-webpack-plugin', - 'webpack-merge', - 'webpack-node-externals', - 'mini-css-extract-plugin', - 'source-map-loader', - 'terser-webpack-plugin', - 'webpack-dev-server', - 'webpack-sources', - 'react-refresh', - '@pmmmwh/react-refresh-webpack-plugin', -]; - -export default async function update(tree: Tree) { - const packageJson = readJson(tree, 'package.json'); - let task: undefined | GeneratorCallback = undefined; - - // Undo the install by `nx g @nrwl/web:webpack5` in Nx 12. - if ( - packageJson.devDependencies['webpack']?.match(/^([\^~])?5\./) && - packages.every((p) => packageJson.devDependencies[p]) - ) { - task = removeDependenciesFromPackageJson(tree, [], packages); - await formatFiles(tree); - } - - return task; -} diff --git a/packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.spec.ts b/packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.spec.ts deleted file mode 100644 index d8c4d585a1d5b..0000000000000 --- a/packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import rename from './rename-build-to-webpack'; - -describe('Migration: rename build to webpack', () => { - it(`should rename the "build" executor to "webpack"`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:build', - options: {}, - }, - }, - }); - - await rename(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: {}, - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.ts b/packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.ts deleted file mode 100644 index 03a04047903bd..0000000000000 --- a/packages/web/src/migrations/update-13-3-0/rename-build-to-webpack.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - if (config?.targets?.build?.executor !== '@nrwl/web:build') continue; - - config.targets.build.executor = '@nrwl/web:webpack'; - - updateProjectConfiguration(host, name, config); - } - - await formatFiles(host); -} diff --git a/packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.spec.ts b/packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.spec.ts deleted file mode 100644 index 4a627b5e687e9..0000000000000 --- a/packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import renamePackageToRollup from './rename-package-to-rollup'; - -describe('Migration: rename package to rollup', () => { - it(`should rename the "package" executor to "rollup"`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:package', - options: {}, - }, - }, - }); - - await renamePackageToRollup(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:rollup', - options: {}, - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.ts b/packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.ts deleted file mode 100644 index c4ea0a48d3357..0000000000000 --- a/packages/web/src/migrations/update-13-3-0/rename-package-to-rollup.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - if (config?.targets?.build?.executor !== '@nrwl/web:package') continue; - - config.targets.build.executor = '@nrwl/web:rollup'; - - updateProjectConfiguration(host, name, config); - } - - await formatFiles(host); -} diff --git a/packages/web/src/migrations/update-13-8-0/add-postcss-config-option.spec.ts b/packages/web/src/migrations/update-13-8-0/add-postcss-config-option.spec.ts deleted file mode 100644 index 769924a650efd..0000000000000 --- a/packages/web/src/migrations/update-13-8-0/add-postcss-config-option.spec.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import migrate from './add-postcss-config-option'; - -describe('Migration: add PostCSS config option', () => { - it(`should add postcssConfig option if file exists`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: {}, - }, - }, - }); - tree.write('apps/myapp/postcss.config.js', `module.exports = {};`); - - await migrate(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: { - postcssConfig: 'apps/myapp/postcss.config.js', - }, - }, - }, - }); - }); - - it(`should not add postcssConfig option if file does not exist`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: {}, - }, - }, - }); - - await migrate(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: {}, - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-13-8-0/add-postcss-config-option.ts b/packages/web/src/migrations/update-13-8-0/add-postcss-config-option.ts deleted file mode 100644 index fd37969356e14..0000000000000 --- a/packages/web/src/migrations/update-13-8-0/add-postcss-config-option.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -/* - * This migration ensures that the previous behavior of applying the app postcss config - * is carried over to Nx 13.8.0. - */ -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - if (config?.targets?.build?.executor !== '@nrwl/web:webpack') continue; - const configPath = `${config.root}/postcss.config.js`; - - if (host.exists(configPath)) { - config.targets.build.options.postcssConfig = configPath; - } - - updateProjectConfiguration(host, name, config); - } - - await formatFiles(host); -} diff --git a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts b/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts deleted file mode 100644 index f060c07194c2e..0000000000000 --- a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.spec.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { addProjectConfiguration, readJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import update from './rollup-format-backwards-compatibility'; - -describe('rollup-format-backwards-compatibility', () => { - it('should add format options to match previous behavior if it does not exist', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'proj1', { - root: 'proj1', - targets: { - build: { - executor: '@nrwl/web:rollup', - }, - }, - }); - - await update(tree); - - expect(readJson(tree, 'proj1/project.json').targets).toEqual({ - build: { - executor: '@nrwl/web:rollup', - options: { - format: ['esm', 'cjs'], - }, - }, - }); - }); - - it('should skip update if format exists', async () => { - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - addProjectConfiguration(tree, 'proj1', { - root: 'proj1', - targets: { - build: { - executor: '@nrwl/web:rollup', - options: { - format: ['esm'], - }, - }, - }, - }); - - await update(tree); - - expect(readJson(tree, 'proj1/project.json').targets).toEqual({ - build: { - executor: '@nrwl/web:rollup', - options: { - format: ['esm'], - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts b/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts deleted file mode 100644 index 9ea5111b2e3c3..0000000000000 --- a/packages/web/src/migrations/update-14-1-7/rollup-format-backwards-compatibility.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -/* - * - */ -export default async function update(tree: Tree) { - for (const [name, config] of getProjects(tree)) { - if (config.targets?.build?.executor !== '@nrwl/web:rollup') continue; - if (Array.isArray(config.targets.build.options?.format)) continue; - - config.targets.build.options = { - ...config.targets.build.options, - format: ['esm', 'cjs'], - }; - - updateProjectConfiguration(tree, name, config); - } - await formatFiles(tree); -} diff --git a/packages/web/src/migrations/update-14-7-6/update-webpack-executor.spec.ts b/packages/web/src/migrations/update-14-7-6/update-webpack-executor.spec.ts deleted file mode 100644 index 074cf9872bc59..0000000000000 --- a/packages/web/src/migrations/update-14-7-6/update-webpack-executor.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { - addProjectConfiguration, - readJson, - readProjectConfiguration, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; - -import update from './update-webpack-executor'; - -describe('Migration: @nrwl/webpack', () => { - it(`should update usage of webpack executor`, async () => { - let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'myapp', { - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/web:webpack', - options: {}, - }, - serve: { - executor: '@nrwl/web:dev-server', - options: {}, - }, - }, - }); - - await update(tree); - - expect(readProjectConfiguration(tree, 'myapp')).toEqual({ - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'myapp', - root: 'apps/myapp', - sourceRoot: 'apps/myapp/src', - projectType: 'application', - targets: { - build: { - executor: '@nrwl/webpack:webpack', - options: {}, - }, - serve: { - executor: '@nrwl/webpack:dev-server', - options: {}, - }, - }, - }); - }); -}); diff --git a/packages/web/src/migrations/update-14-7-6/update-webpack-executor.ts b/packages/web/src/migrations/update-14-7-6/update-webpack-executor.ts deleted file mode 100644 index 216ff3f86c783..0000000000000 --- a/packages/web/src/migrations/update-14-7-6/update-webpack-executor.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - formatFiles, - getProjects, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -export default async function update(host: Tree) { - const projects = getProjects(host); - - for (const [name, config] of projects.entries()) { - let updated = false; - if (config?.targets?.build?.executor === '@nrwl/web:webpack') { - config.targets.build.executor = '@nrwl/webpack:webpack'; - updated = true; - } - if (config?.targets?.serve?.executor === '@nrwl/web:dev-server') { - config.targets.serve.executor = '@nrwl/webpack:dev-server'; - updated = true; - } - if (updated) { - updateProjectConfiguration(host, name, config); - } - } - - await formatFiles(host); -} diff --git a/packages/workspace/migrations.json b/packages/workspace/migrations.json index 977ba055c24e2..f9acf4aee3640 100644 --- a/packages/workspace/migrations.json +++ b/packages/workspace/migrations.json @@ -1,83 +1,5 @@ { "generators": { - "add-target-dependencies": { - "version": "12.5.0-beta.1", - "description": "Rename the workspace-schematic script into workspace-generator script", - "factory": "./src/migrations/update-12-5-0/add-target-dependencies", - "cli": "nx" - }, - "set-default-base-if-not-set": { - "version": "13.0.0-beta.1", - "description": "Add default base to nx.json if its not currently set", - "factory": "./src/migrations/update-13-0-0/set-default-base-if-not-set", - "cli": "nx" - }, - "13-0-0-config-locations": { - "version": "13.0.0-beta.4", - "description": "Move global settings into nx.json, and project specific settings into workspace.json", - "cli": "nx", - "implementation": "./src/migrations/update-13-0-0/config-locations/config-locations" - }, - "set-parallel-default": { - "version": "13.2.0", - "description": "Set --parallel=1 for existing repos to preserve the existing behavior", - "cli": "nx", - "implementation": "./src/migrations/update-13-2-0/set-parallel-default" - }, - "13-3-0-tsc-location": { - "version": "13.3.0-beta.0", - "description": "@nrwl/workspace:tsc is now @nrwl/js:tsc", - "cli": "nx", - "implementation": "./src/migrations/update-13-3-0/update-tsc-executor-location" - }, - "13-6-0-remove-old-task-runner-options": { - "version": "13.6.0-beta.0", - "description": "Remove old options that are no longer used", - "cli": "nx", - "implementation": "./src/migrations/update-13-6-0/remove-old-task-runner-options" - }, - "13-9-0-replace-tao-with-nx": { - "version": "13.9.0-beta.0", - "description": "Replace @nrwl/tao with nx", - "cli": "nx", - "implementation": "./src/migrations/update-13-9-0/replace-tao-with-nx" - }, - "13-10-0-update-decorate-cli": { - "version": "13.10.0-beta.0", - "description": "Update the decorate-angular-cli script to require nx instead of @nrwl/cli", - "cli": "nx", - "implementation": "./src/migrations/update-13-10-0/update-decorate-cli" - }, - "13-10-0-update-tasks-runner": { - "version": "13.10.0-beta.0", - "description": "Update the tasks runner property to import it from the nx package instead of @nrwl/workspace", - "cli": "nx", - "implementation": "./src/migrations/update-13-10-0/update-tasks-runner" - }, - "14-0-0-change-nx-json-presets": { - "version": "14.0.0-beta.0", - "description": "Changes the presets in nx.json to come from the nx package", - "cli": "nx", - "implementation": "./src/migrations/update-14-0-0/change-nx-json-presets" - }, - "14-0-0-change-npm-script-executor": { - "version": "14.0.0-beta.0", - "description": "Migrates from @nrwl/workspace:run-script to nx:run-script", - "cli": "nx", - "implementation": "./src/migrations/update-14-0-0/change-npm-script-executor" - }, - "14-2-0-enable-source-analysis": { - "version": "14.2.0", - "description": "Explicitly enable sourceAnalysis for all workspaces extending from npm.json or core.json (this was default behavior prior to 14.2)", - "cli": "nx", - "implementation": "./src/migrations/update-14-2-0/enable-source-analysis" - }, - "14-8-0-change-run-commands-executor": { - "version": "14.8.0-beta.0", - "description": "Migrates from @nrwl/workspace:run-commands to nx:run-commands", - "cli": "nx", - "implementation": "./src/migrations/update-14-8-0/change-run-commands-executor" - }, "15-7-0-split-configuration-into-project-json-files": { "version": "15.7.0-beta.0", "description": "Split global configuration files (e.g., workspace.json) into individual project.json files.", @@ -104,63 +26,6 @@ } }, "packageJsonUpdates": { - "12.5.0": { - "version": "12.5.0", - "packages": { - "prettier": { - "version": "^2.3.1", - "alwaysAddToPackageJson": false - } - } - }, - "12.6.0": { - "version": "12.6.0-beta.8", - "packages": { - "typescript": { - "version": "~4.3.5" - } - } - }, - "12.7.0": { - "version": "12.7.0-beta.0", - "packages": { - "dotenv": { - "version": "~10.0.0" - } - } - }, - "13.5.0": { - "version": "13.5.0", - "packages": { - "prettier": { - "version": "^2.5.1", - "alwaysAddToPackageJson": false - } - } - }, - "14.2.0": { - "version": "14.2.0-beta.4", - "packages": { - "typescript": { - "version": "~4.7.2", - "alwaysAddToPackageJson": false - }, - "prettier": { - "version": "^2.6.2", - "alwaysAddToPackageJson": false - } - } - }, - "14.8.0": { - "version": "14.8.0-beta.0", - "x-prompt": "Do you want to update to TypeScript v4.8?", - "packages": { - "typescript": { - "version": "~4.8.2", - "alwaysAddToPackageJson": false - } - } - }, "15.8.0": { "version": "15.8.0-beta.2", "x-prompt": "Do you want to update to TypeScript v4.9?", diff --git a/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts b/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts deleted file mode 100644 index eac1cf226dd99..0000000000000 --- a/packages/workspace/src/migrations/update-12-5-0/add-target-dependencies.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { - formatFiles, - NxJsonConfiguration, - readNxJson, - TargetDependencyConfig, - Tree, - updateNxJson, -} from '@nx/devkit'; -import { output } from '../../utilities/output'; - -export async function setTargetDependencies(host: Tree) { - const config: NxJsonConfiguration & { - targetDependencies?: Record; - } = readNxJson(host); - - const strictlyOrderedTargets = config.tasksRunnerOptions?.['default']?.options - ?.strictlyOrderedTargets || ['build']; - delete config.tasksRunnerOptions?.['default']?.options - ?.strictlyOrderedTargets; - config.targetDependencies = config.targetDependencies ?? {}; - - const updatedStrictlyOrderedTargets = []; - strictlyOrderedTargets.forEach((target) => { - if (!config.targetDependencies[target]) { - config.targetDependencies[target] = [ - { target, projects: 'dependencies' }, - ]; - updatedStrictlyOrderedTargets.push(target); - } - }); - updateNxJson(host, config); - - if (updatedStrictlyOrderedTargets.length > 0) { - output.note({ - title: 'Target dependencies have been updated in nx.json', - bodyLines: [ - `Nx has deprecated strictlyOrderedTargets in favour of targetDependencies.`, - `Based on your configuration the migration has configured targetDependencies for the following targets: ${updatedStrictlyOrderedTargets.join( - ', ' - )}.`, - `Read more here: https://nx.dev/reference/project-configuration`, - ], - }); - } - - await formatFiles(host); -} - -export default setTargetDependencies; diff --git a/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts b/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts deleted file mode 100644 index 113fca24a8b08..0000000000000 --- a/packages/workspace/src/migrations/update-13-0-0/config-locations/config-locations.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { - formatFiles, - NxJsonConfiguration, - ProjectConfiguration, - readJson, - readProjectConfiguration, - Tree, - updateProjectConfiguration, - writeJson, -} from '@nx/devkit'; - -export default async function update(tree: Tree) { - const nxJson = readJson(tree, 'nx.json') as NxJsonConfiguration & { - projects: Record< - string, - Pick - > | null; - }; - // updateProjectConfiguration automatically saves the project opts into workspace/project.json - if (nxJson.projects) { - Object.entries(nxJson.projects).forEach(([p, nxJsonConfiguration]) => { - const configuration = readProjectConfiguration(tree, p); - configuration.tags ??= nxJsonConfiguration.tags; - configuration.implicitDependencies ??= - nxJsonConfiguration.implicitDependencies; - updateProjectConfiguration(tree, p, configuration); - }); - delete nxJson.projects; - } - - writeJson(tree, 'nx.json', nxJson); - - movePropertiesAreInNewLocations(tree); // move config options to new spots. - - await formatFiles(tree); -} - -/** - * `updateWorkspaceConfiguration` already handles - * placing properties in their new locations, so - * reading + updating it ensures that props are placed - * correctly. - */ -function movePropertiesAreInNewLocations(tree: Tree) { - return; -} diff --git a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts b/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts deleted file mode 100644 index ea8f60811d2af..0000000000000 --- a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { readNxJson, Tree, writeJson } from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { setDefaultBaseIfNotSet } from './set-default-base-if-not-set'; - -describe('add `defaultBase` in nx.json', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should set defaultBase to master if not present', async () => { - writeJson(tree, 'nx.json', { npmScope: 'unitTests' }); - await setDefaultBaseIfNotSet(tree); - - const config = readNxJson(tree); - expect(config.affected.defaultBase).toEqual('master'); - }); - - it('should not update defaultBase if present', async () => { - writeJson(tree, 'nx.json', { - npmScope: 'unitTests', - affected: { defaultBase: 'main' }, - }); - await setDefaultBaseIfNotSet(tree); - - const config = readNxJson(tree); - expect(config.affected.defaultBase).toEqual('main'); - }); -}); diff --git a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts b/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts deleted file mode 100644 index 77d4e1fbc24ec..0000000000000 --- a/packages/workspace/src/migrations/update-13-0-0/set-default-base-if-not-set.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { formatFiles, readNxJson, Tree, updateNxJson } from '@nx/devkit'; -import { output } from '../../utilities/output'; - -export async function setDefaultBaseIfNotSet(host: Tree) { - const config = readNxJson(host); - if (!config.affected?.defaultBase) { - config.affected ??= {}; - config.affected.defaultBase ??= 'master'; - - output.note({ - title: 'Default Base has been set in nx.json', - bodyLines: [ - `Nx is moving to "main" as the default branch.`, - `To avoid your current defaults changing, defaultBase has been set to "master" in nx.json`, - `Read more here: https://nx.dev/using-nx/affected`, - ], - }); - } - updateNxJson(host, config); - await formatFiles(host); -} - -export default setDefaultBaseIfNotSet; diff --git a/packages/workspace/src/migrations/update-13-10-0/update-decorate-cli.ts b/packages/workspace/src/migrations/update-13-10-0/update-decorate-cli.ts deleted file mode 100644 index e9ece2e06038a..0000000000000 --- a/packages/workspace/src/migrations/update-13-10-0/update-decorate-cli.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Tree } from '@nx/devkit'; - -export function updateDecorateAngularCLI(host: Tree) { - const decorate = host.read('decorate-angular-cli.js')?.toString(); - if (decorate) { - host.write( - 'decorate-angular-cli.js', - decorate.replace( - '@nrwl/cli/lib/decorate-cli', - 'nx/src/adapter/decorate-cli' - ) - ); - host.write( - 'decorate-angular-cli.js', - decorate.replace('nx/src/cli/decorate-cli', 'nx/src/adapter/decorate-cli') - ); - } -} - -export default updateDecorateAngularCLI; 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 deleted file mode 100644 index 8df9fdf31ff12..0000000000000 --- a/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { readNxJson, Tree, updateNxJson } from '@nx/devkit'; - -export function updateTasksRunner(host: Tree) { - const config = readNxJson(host); - if ( - config?.tasksRunnerOptions?.['default'] && - config?.tasksRunnerOptions['default'].runner == - '@nrwl/workspace/tasks-runners/default' - ) { - config.tasksRunnerOptions['default'].runner = 'nx/tasks-runners/default'; - } - updateNxJson(host, config); -} - -export default updateTasksRunner; diff --git a/packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts b/packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts deleted file mode 100644 index 3550fa30cd48b..0000000000000 --- a/packages/workspace/src/migrations/update-13-2-0/set-parallel-default.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { formatFiles, readNxJson, Tree, updateNxJson } from '@nx/devkit'; - -export async function setParallelDefault(host: Tree) { - const config = readNxJson(host); - const defaultTaskRunnerOptions = - config.tasksRunnerOptions?.['default']?.options; - if (defaultTaskRunnerOptions) { - if (defaultTaskRunnerOptions.parallel) { - defaultTaskRunnerOptions.parallel = - defaultTaskRunnerOptions.maxParallel || 3; - delete defaultTaskRunnerOptions.maxParallel; - } else { - defaultTaskRunnerOptions.parallel = 1; - } - updateNxJson(host, config); - } - await formatFiles(host); -} - -export default setParallelDefault; diff --git a/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.spec.ts b/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.spec.ts deleted file mode 100644 index 820c6043c4aa0..0000000000000 --- a/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.spec.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { - Tree, - addProjectConfiguration, - getProjects, - readJson, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import { updateTscExecutorLocation } from './update-tsc-executor-location'; - -describe('add `defaultBase` in nx.json', () => { - let tree: Tree; - - beforeEach(async () => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should update @nrwl/workspace:tsc -> @nrwl/js:tsc', async () => { - addProjectConfiguration(tree, 'tsc-project', { - root: 'projects/tsc-project', - targets: { - build: { - executor: '@nrwl/workspace:tsc', - }, - test: { - executor: '@nrwl/jest:jest', - }, - }, - }); - addProjectConfiguration(tree, 'other-project', { - root: 'projects/other-project', - targets: { - build: { - executor: '@nrwl/react:build', - }, - test: { - executor: '@nrwl/jest:jest', - }, - }, - }); - await updateTscExecutorLocation(tree); - const projects = Object.fromEntries(getProjects(tree).entries()); - expect(projects).toEqual({ - 'tsc-project': { - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'tsc-project', - root: 'projects/tsc-project', - targets: { - build: { - executor: '@nrwl/js:tsc', - }, - test: { - executor: '@nrwl/jest:jest', - }, - }, - }, - 'other-project': { - $schema: '../../node_modules/nx/schemas/project-schema.json', - name: 'other-project', - root: 'projects/other-project', - targets: { - build: { - executor: '@nrwl/react:build', - }, - test: { - executor: '@nrwl/jest:jest', - }, - }, - }, - }); - }); - - it('should add @nrwl/js dependency', async () => { - addProjectConfiguration(tree, 'tsc-project', { - root: 'projects/tsc-project', - targets: { - build: { - executor: '@nrwl/workspace:tsc', - }, - }, - }); - await updateTscExecutorLocation(tree); - const packageJson = readJson(tree, 'package.json'); - expect(packageJson.devDependencies).toMatchObject({ - '@nrwl/js': expect.anything(), - }); - }); -}); diff --git a/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.ts b/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.ts deleted file mode 100644 index 36473a695e82e..0000000000000 --- a/packages/workspace/src/migrations/update-13-3-0/update-tsc-executor-location.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - addDependenciesToPackageJson, - formatFiles, - GeneratorCallback, - getProjects, - installPackagesTask, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; -import { nxVersion } from '../../utils/versions'; - -export async function updateTscExecutorLocation( - host: Tree -): Promise { - const projects = getProjects(host); - let used = false; - for (const [project, projectConfig] of projects.entries()) { - for (const [target, targetConfig] of Object.entries( - projectConfig.targets || {} - )) { - if (targetConfig.executor === '@nrwl/workspace:tsc') { - projectConfig.targets[target].executor = '@nrwl/js:tsc'; - updateProjectConfiguration(host, project, projectConfig); - used = true; - } - } - } - if (used) { - addDependenciesToPackageJson( - host, - {}, - { - '@nrwl/js': nxVersion, - } - ); - } - await formatFiles(host); - return () => installPackagesTask(host); -} - -export default updateTscExecutorLocation; diff --git a/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.spec.ts b/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.spec.ts deleted file mode 100644 index 335ff8673177d..0000000000000 --- a/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { NxJsonConfiguration, readJson, Tree, writeJson } from '@nx/devkit'; -import { createTree } from '@nx/devkit/testing'; -import removeOldTaskRunnerOptions from './remove-old-task-runner-options'; - -describe('removeOldTaskRunnerOptions', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTree(); - }); - - it('should remove scan and analytics', () => { - writeJson(tree, 'nx.json', { - npmScope: 'scope', - tasksRunnerOptions: { - default: { - runner: 'runner', - options: { - scan: true, - analytics: 'hi', - }, - }, - }, - }); - removeOldTaskRunnerOptions(tree); - const result = readJson(tree, 'nx.json'); - expect(result).toEqual({ - npmScope: 'scope', - tasksRunnerOptions: { - default: { - runner: 'runner', - options: {}, - }, - }, - }); - }); - - it("should not fail if nx.json doesn't have taskRunnerOptions", () => { - writeJson(tree, 'nx.json', {}); - removeOldTaskRunnerOptions(tree); - const result = readJson(tree, 'nx.json'); - expect(result).toEqual({}); - }); -}); diff --git a/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts b/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts deleted file mode 100644 index 301cbbccaf5bf..0000000000000 --- a/packages/workspace/src/migrations/update-13-6-0/remove-old-task-runner-options.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { readNxJson, Tree, updateNxJson } from '@nx/devkit'; - -export function removeOldTaskRunnerOptions(host: Tree) { - const nxJson = readNxJson(host); - const options = nxJson.tasksRunnerOptions?.['default']?.options; - if (options) { - delete options.scan; - delete options.analytics; - updateNxJson(host, nxJson); - } -} - -export default removeOldTaskRunnerOptions; diff --git a/packages/workspace/src/migrations/update-13-9-0/replace-tao-with-nx.ts b/packages/workspace/src/migrations/update-13-9-0/replace-tao-with-nx.ts deleted file mode 100644 index f23e265a018cf..0000000000000 --- a/packages/workspace/src/migrations/update-13-9-0/replace-tao-with-nx.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { getPackageManagerCommand, logger, Tree, updateJson } from '@nx/devkit'; - -export function replaceTaoWithNx(host: Tree) { - updateJson(host, 'package.json', (json: any) => { - if (json.dependencies?.['@nrwl/workspace']) { - json.dependencies['nx'] = json.dependencies['@nrwl/workspace']; - } else if (json.devDependencies?.['@nrwl/workspace']) { - json.devDependencies['nx'] = json.devDependencies['@nrwl/workspace']; - } - removeTao(json.dependencies); - removeTao(json.devDependencies); - return json; - }); - const pmc = getPackageManagerCommand(); - logger.info( - `Please run ${pmc.install} to ensure the correct version of Nx is installed.` - ); -} - -function removeTao(json: any) { - if (!json) return; - json['@nrwl/tao'] = undefined; -} - -export default replaceTaoWithNx; diff --git a/packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts b/packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts deleted file mode 100644 index 0d2699667d1bb..0000000000000 --- a/packages/workspace/src/migrations/update-13-9-0/update-decorate-cli.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Tree } from '@nx/devkit'; - -export function updateDecorateAngularCLI(host: Tree) { - const decorate = host.read('decorate-angular-cli.js')?.toString(); - if (decorate) { - host.write( - 'decorate-angular-cli.js', - decorate.replace('@nrwl/cli/lib/decorate-cli', 'nx/src/cli/decorate-cli') - ); - } -} - -export default updateDecorateAngularCLI; diff --git a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts b/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts deleted file mode 100644 index 45b61263b51ca..0000000000000 --- a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - addProjectConfiguration, - readProjectConfiguration, - Tree, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import changeNpmScriptExecutor from './change-npm-script-executor'; - -describe('changeNxJsonPresets', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'proj1', { - root: 'proj1', - targets: { - scriptTarget: { - executor: '@nrwl/workspace:run-script', - options: {}, - }, - notScriptTarget: { - executor: '@nrwl/workspace:something', - options: {}, - }, - }, - }); - }); - - it('should change the npm script executor to nx:npm-script', async () => { - await changeNpmScriptExecutor(tree); - - expect(readProjectConfiguration(tree, 'proj1')).toMatchInlineSnapshot(` - { - "$schema": "../node_modules/nx/schemas/project-schema.json", - "name": "proj1", - "root": "proj1", - "targets": { - "notScriptTarget": { - "executor": "@nrwl/workspace:something", - "options": {}, - }, - "scriptTarget": { - "executor": "nx:run-script", - "options": {}, - }, - }, - } - `); - }); -}); diff --git a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts b/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts deleted file mode 100644 index 744a0f5a7d8ef..0000000000000 --- a/packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - formatFiles, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; - -export async function changeNpmScriptExecutor(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/workspace:run-script', - (currentValue, project, target) => { - const projectConfig = readProjectConfiguration(tree, project); - const targetConfig = projectConfig.targets[target]; - - targetConfig.executor = 'nx:run-script'; - - updateProjectConfiguration(tree, project, projectConfig); - } - ); - - await formatFiles(tree); -} - -export default changeNpmScriptExecutor; diff --git a/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts b/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts deleted file mode 100644 index 461afc1e7beb4..0000000000000 --- a/packages/workspace/src/migrations/update-14-0-0/change-nx-json-presets.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { formatFiles, readNxJson, Tree, updateNxJson } from '@nx/devkit'; - -export async function changeNxJsonPresets(tree: Tree) { - const nxJson = readNxJson(tree); - const replacements = { - '@nrwl/workspace/presets/npm.json': 'nx/presets/npm.json', - '@nrwl/workspace/presets/core.json': 'nx/presets/core.json', - }; - if (nxJson.extends && replacements[nxJson.extends]) { - updateNxJson(tree, { - ...nxJson, - extends: replacements[nxJson.extends], - }); - } - - await formatFiles(tree); -} - -export default changeNxJsonPresets; diff --git a/packages/workspace/src/migrations/update-14-2-0/enable-source-analysis.ts b/packages/workspace/src/migrations/update-14-2-0/enable-source-analysis.ts deleted file mode 100644 index b356211c557ef..0000000000000 --- a/packages/workspace/src/migrations/update-14-2-0/enable-source-analysis.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { formatFiles, NxJsonConfiguration, Tree, updateJson } from '@nx/devkit'; - -export async function enableSourceAnalysis(tree: Tree) { - updateJson(tree, 'nx.json', (config) => { - if ( - config.extends === 'nx/presets/core.json' || - config.extends === 'nx/presets/npm.json' - ) { - const explicitlyDisabled = - config.pluginsConfig && - config.pluginsConfig['@nrwl/js'] && - (config.pluginsConfig['@nrwl/js'] as any).analyzeSourceFiles === false; - - if (!explicitlyDisabled) { - config.pluginsConfig ||= {}; - config.pluginsConfig['@nrwl/js'] ||= {}; - (config.pluginsConfig['@nrwl/js'] as any).analyzeSourceFiles = true; - } - } - return config; - }); - await formatFiles(tree); -} - -export default enableSourceAnalysis; diff --git a/packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.spec.ts b/packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.spec.ts deleted file mode 100644 index 92d625b1230be..0000000000000 --- a/packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.spec.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - addProjectConfiguration, - readProjectConfiguration, - Tree, -} from '@nx/devkit'; -import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; -import changeRunCommandsExecutor from './change-run-commands-executor'; - -describe('changeRunCommandsExecutor', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - - addProjectConfiguration(tree, 'proj1', { - root: 'proj1', - targets: { - scriptTarget: { - executor: '@nrwl/workspace:run-commands', - options: {}, - }, - notScriptTarget: { - executor: '@nrwl/workspace:something', - options: {}, - }, - }, - }); - }); - - it('should change the npm script executor to nx:npm-script', async () => { - await changeRunCommandsExecutor(tree); - - expect(readProjectConfiguration(tree, 'proj1')).toMatchInlineSnapshot(` - { - "$schema": "../node_modules/nx/schemas/project-schema.json", - "name": "proj1", - "root": "proj1", - "targets": { - "notScriptTarget": { - "executor": "@nrwl/workspace:something", - "options": {}, - }, - "scriptTarget": { - "executor": "nx:run-commands", - "options": {}, - }, - }, - } - `); - }); -}); diff --git a/packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.ts b/packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.ts deleted file mode 100644 index f638f35cc1cb8..0000000000000 --- a/packages/workspace/src/migrations/update-14-8-0/change-run-commands-executor.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - formatFiles, - readProjectConfiguration, - Tree, - updateProjectConfiguration, -} from '@nx/devkit'; - -import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils'; - -export async function changeRunCommandsExecutor(tree: Tree) { - forEachExecutorOptions( - tree, - '@nrwl/workspace:run-commands', - (currentValue, project, target) => { - const projectConfig = readProjectConfiguration(tree, project); - const targetConfig = projectConfig.targets[target]; - - targetConfig.executor = 'nx:run-commands'; - - updateProjectConfiguration(tree, project, projectConfig); - } - ); - - await formatFiles(tree); -} - -export default changeRunCommandsExecutor; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 651b61e7876f9..b4b7614d3ec2f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,8 +28,8 @@ dependencies: specifier: ^0.1.19 version: 0.1.30 '@swc/helpers': - specifier: 0.5.0 - version: 0.5.0 + specifier: ~0.5.2 + version: 0.5.3 '@tailwindcss/aspect-ratio': specifier: ^0.4.2 version: 0.4.2(tailwindcss@3.2.4) @@ -370,7 +370,7 @@ devDependencies: version: 7.2.2(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3) '@storybook/react-webpack5': specifier: 7.2.2 - version: 7.2.2(@babel/core@7.22.9)(@swc/core@1.3.86)(@swc/helpers@0.5.0)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3)(webpack-dev-server@4.11.1) + version: 7.2.2(@babel/core@7.22.9)(@swc/core@1.3.86)(@swc/helpers@0.5.3)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3)(webpack-dev-server@4.11.1) '@storybook/types': specifier: ^7.1.1 version: 7.1.1 @@ -391,7 +391,7 @@ devDependencies: version: 0.1.62(@swc/core@1.3.86) '@swc/core': specifier: ^1.3.85 - version: 1.3.86(@swc/helpers@0.5.0) + version: 1.3.86(@swc/helpers@0.5.3) '@swc/jest': specifier: ^0.2.20 version: 0.2.23(@swc/core@1.3.86) @@ -8380,7 +8380,7 @@ packages: - supports-color dev: true - /@storybook/builder-webpack5@7.2.2(@swc/helpers@0.5.0)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3): + /@storybook/builder-webpack5@7.2.2(@swc/helpers@0.5.3)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3): resolution: {integrity: sha512-+f2H3tXPZfn3q/eruXCmWPVAopd1MMEAAvneZ4iqlSHPC5HK2dcX/zj3yPar6rjfHHvZBXNm5sSi4WuD5Pw9MA==} peerDependencies: react: ^16.8.0 || ^17.0.0 || ^18.0.0 @@ -8407,7 +8407,7 @@ packages: '@storybook/router': 7.2.2(react-dom@18.2.0)(react@18.2.0) '@storybook/store': 7.2.2 '@storybook/theming': 7.2.2(react-dom@18.2.0)(react@18.2.0) - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) '@types/node': 16.18.36 '@types/semver': 7.5.2 babel-loader: 9.1.2(@babel/core@7.22.9)(webpack@5.88.0) @@ -8926,7 +8926,7 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: true - /@storybook/react-webpack5@7.2.2(@babel/core@7.22.9)(@swc/core@1.3.86)(@swc/helpers@0.5.0)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3)(webpack-dev-server@4.11.1): + /@storybook/react-webpack5@7.2.2(@babel/core@7.22.9)(@swc/core@1.3.86)(@swc/helpers@0.5.3)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3)(webpack-dev-server@4.11.1): resolution: {integrity: sha512-VBFOO4LUuX/DVqaVBHpSTNT1NcIUlt1RpHX371NM0IcPSAj4EjHu3fLK4GjPMNJSqjnT7i6cthwPPe4hATTldg==} engines: {node: '>=16.0.0'} peerDependencies: @@ -8941,7 +8941,7 @@ packages: optional: true dependencies: '@babel/core': 7.22.9 - '@storybook/builder-webpack5': 7.2.2(@swc/helpers@0.5.0)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3) + '@storybook/builder-webpack5': 7.2.2(@swc/helpers@0.5.3)(@types/react-dom@18.2.6)(@types/react@18.2.14)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3) '@storybook/preset-react-webpack': 7.2.2(@babel/core@7.22.9)(@swc/core@1.3.86)(esbuild@0.19.2)(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3)(webpack-dev-server@4.11.1) '@storybook/react': 7.2.2(react-dom@18.2.0)(react@18.2.0)(typescript@5.1.3) '@types/node': 16.18.36 @@ -9343,7 +9343,7 @@ packages: peerDependencies: '@swc/core': '>= 1.3' dependencies: - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) dev: true /@swc-node/register@1.6.8(@swc/core@1.3.86)(typescript@5.1.3): @@ -9354,7 +9354,7 @@ packages: dependencies: '@swc-node/core': 1.10.6(@swc/core@1.3.86) '@swc-node/sourcemap-support': 0.3.0 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) colorette: 2.0.19 debug: 4.3.4(supports-color@5.5.0) pirates: 4.0.5 @@ -9383,7 +9383,7 @@ packages: optional: true dependencies: '@mole-inc/bin-wrapper': 8.0.1 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) commander: 7.2.0 fast-glob: 3.2.12 semver: 7.5.3 @@ -9471,7 +9471,7 @@ packages: requiresBuild: true optional: true - /@swc/core@1.3.86(@swc/helpers@0.5.0): + /@swc/core@1.3.86(@swc/helpers@0.5.3): resolution: {integrity: sha512-bEXUtm37bcmJ3q+geG7Zy4rJNUzpxalXQUrrqX1ZoGj3HRtzdeVZ0L/um3fG2j16qe61t8TX/OIZ2G6j6dkG/w==} engines: {node: '>=10'} requiresBuild: true @@ -9481,7 +9481,7 @@ packages: '@swc/helpers': optional: true dependencies: - '@swc/helpers': 0.5.0 + '@swc/helpers': 0.5.3 '@swc/types': 0.1.5 optionalDependencies: '@swc/core-darwin-arm64': 1.3.86 @@ -9495,16 +9495,16 @@ packages: '@swc/core-win32-ia32-msvc': 1.3.86 '@swc/core-win32-x64-msvc': 1.3.86 - /@swc/helpers@0.5.0: - resolution: {integrity: sha512-SjY/p4MmECVVEWspzSRpQEM3sjR17sP8PbGxELWrT+YZMBfiUyt1MRUNjMV23zohwlG2HYtCQOsCwsTHguXkyg==} - dependencies: - tslib: 2.5.0 - /@swc/helpers@0.5.1: resolution: {integrity: sha512-sJ902EfIzn1Fa+qYmjdQqh8tPsoxyBz+8yBKC2HKUxyezKJFwPGOn7pv4WY6QuQW//ySQi5lJjA/ZT9sNWWNTg==} dependencies: tslib: 2.6.1 + /@swc/helpers@0.5.3: + resolution: {integrity: sha512-FaruWX6KdudYloq1AHD/4nU+UsMTdNE8CKyrseXWEcgjDAbvkwJg2QGPAnfIJLIWsjZOSPLOAykK6fuYp4vp4A==} + dependencies: + tslib: 2.6.1 + /@swc/jest@0.2.23(@swc/core@1.3.86): resolution: {integrity: sha512-ZLj17XjHbPtNsgqjm83qizENw05emLkKGu3WuPUttcy9hkngl0/kcc7fDbcSBpADS0GUtsO+iKPjZFWVAtJSlA==} engines: {npm: '>= 7.0.0'} @@ -9512,7 +9512,7 @@ packages: '@swc/core': '*' dependencies: '@jest/create-cache-key-function': 27.5.1 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) jsonc-parser: 3.2.0 dev: true @@ -20835,7 +20835,7 @@ packages: '@nrwl/tao': 15.8.0(@swc-node/register@1.6.8)(@swc/core@1.3.86) '@parcel/watcher': 2.0.4 '@swc-node/register': 1.6.8(@swc/core@1.3.86)(typescript@5.1.3) - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) '@yarnpkg/lockfile': 1.1.0 '@yarnpkg/parsers': 3.0.0-rc.46 '@zkochan/js-yaml': 0.0.6 @@ -20898,7 +20898,7 @@ packages: '@nrwl/tao': 16.10.0-beta.1(@swc-node/register@1.6.8)(@swc/core@1.3.86) '@parcel/watcher': 2.0.4 '@swc-node/register': 1.6.8(@swc/core@1.3.86)(typescript@5.1.3) - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) '@yarnpkg/lockfile': 1.1.0 '@yarnpkg/parsers': 3.0.0-rc.46 '@zkochan/js-yaml': 0.0.6 @@ -25412,7 +25412,7 @@ packages: '@swc/core': ^1.2.147 webpack: '>=2' dependencies: - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) webpack: 5.88.0(@swc/core@1.3.86)(esbuild@0.19.2) dev: true @@ -25610,7 +25610,7 @@ packages: optional: true dependencies: '@jridgewell/trace-mapping': 0.3.18 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) esbuild: 0.19.2 jest-worker: 27.5.1 schema-utils: 3.1.2 @@ -25636,7 +25636,7 @@ packages: optional: true dependencies: '@jridgewell/trace-mapping': 0.3.18 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) esbuild: 0.18.17 jest-worker: 27.5.1 schema-utils: 3.2.0 @@ -25662,7 +25662,7 @@ packages: optional: true dependencies: '@jridgewell/trace-mapping': 0.3.18 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) esbuild: 0.19.2 jest-worker: 27.5.1 schema-utils: 3.2.0 @@ -25688,7 +25688,7 @@ packages: optional: true dependencies: '@jridgewell/trace-mapping': 0.3.18 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) esbuild: 0.19.2 jest-worker: 27.5.1 schema-utils: 3.2.0 @@ -26053,7 +26053,7 @@ packages: optional: true dependencies: '@cspotcode/source-map-support': 0.8.1 - '@swc/core': 1.3.86(@swc/helpers@0.5.0) + '@swc/core': 1.3.86(@swc/helpers@0.5.3) '@tsconfig/node10': 1.0.9 '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 diff --git a/tools/workspace-plugin/.eslintrc.json b/tools/workspace-plugin/.eslintrc.json new file mode 100644 index 0000000000000..d7164738870cf --- /dev/null +++ b/tools/workspace-plugin/.eslintrc.json @@ -0,0 +1,32 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/dependency-checks": "error" + } + }, + { + "files": ["./package.json", "./generators.json"], + "parser": "jsonc-eslint-parser", + "rules": { + "@nx/nx-plugin-checks": "error" + } + } + ] +} diff --git a/tools/workspace-plugin/README.md b/tools/workspace-plugin/README.md new file mode 100644 index 0000000000000..ef8636c4aba27 --- /dev/null +++ b/tools/workspace-plugin/README.md @@ -0,0 +1,11 @@ +# workspace-plugin + +This library was generated with [Nx](https://nx.dev). + +## Building + +Run `nx build workspace-plugin` to build the library. + +## Running unit tests + +Run `nx test workspace-plugin` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/tools/workspace-plugin/generators.json b/tools/workspace-plugin/generators.json new file mode 100644 index 0000000000000..cbb3d893ae946 --- /dev/null +++ b/tools/workspace-plugin/generators.json @@ -0,0 +1,9 @@ +{ + "generators": { + "remove-migrations": { + "factory": "./src/generators/remove-migrations/generator", + "schema": "./src/generators/remove-migrations/schema.json", + "description": "remove-migrations generator" + } + } +} diff --git a/tools/workspace-plugin/jest.config.ts b/tools/workspace-plugin/jest.config.ts new file mode 100644 index 0000000000000..946685cfeee00 --- /dev/null +++ b/tools/workspace-plugin/jest.config.ts @@ -0,0 +1,10 @@ +/* eslint-disable */ +export default { + displayName: 'workspace-plugin', + preset: '../../jest.preset.js', + transform: { + '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../coverage/tools/workspace-plugin', +}; diff --git a/tools/workspace-plugin/package.json b/tools/workspace-plugin/package.json new file mode 100644 index 0000000000000..44447ab0c89ce --- /dev/null +++ b/tools/workspace-plugin/package.json @@ -0,0 +1,12 @@ +{ + "name": "@nx/workspace-plugin", + "version": "0.0.1", + "private": true, + "generators": "./generators.json", + "dependencies": { + "tslib": "^2.3.0" + }, + "type": "commonjs", + "main": "./src/index.js", + "typings": "./src/index.d.ts" +} diff --git a/tools/workspace-plugin/project.json b/tools/workspace-plugin/project.json new file mode 100644 index 0000000000000..44f682764bc80 --- /dev/null +++ b/tools/workspace-plugin/project.json @@ -0,0 +1,33 @@ +{ + "name": "workspace-plugin", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "tools/workspace-plugin/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "tools/workspace-plugin/**/*.ts", + "tools/workspace-plugin/package.json" + ] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "tools/workspace-plugin/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + } + }, + "tags": [] +} diff --git a/tools/workspace-plugin/src/generators/remove-migrations/generator.ts b/tools/workspace-plugin/src/generators/remove-migrations/generator.ts new file mode 100644 index 0000000000000..5ccbdb67bb6a5 --- /dev/null +++ b/tools/workspace-plugin/src/generators/remove-migrations/generator.ts @@ -0,0 +1,101 @@ +import { + formatFiles, + readJson, + Tree, + updateJson, + visitNotIgnoredFiles, +} from '@nx/devkit'; +import { basename, dirname, join } from 'path'; +import { lte, major } from 'semver'; + +export interface RemoveMigrationsGeneratorSchema { + v: number; +} + +export async function removeMigrationsGenerator( + tree: Tree, + { v }: RemoveMigrationsGeneratorSchema +) { + visitNotIgnoredFiles(tree, '', (path) => { + // Ignore angular migrations because angular needs to support migrations until LTS support is dropped + if (['packages/angular/package.json'].includes(path)) { + return; + } + + if (basename(path) !== 'package.json') { + return; + } + + const packageJson = readJson(tree, path); + + const migrations = + packageJson?.['nx-migrations']?.migrations ?? + packageJson?.['ng-update']?.migrations; + if (!migrations) { + return; + } + + if (migrations.startsWith('.')) { + const migrationsPath = join(dirname(path), migrations); + + updateJson(tree, migrationsPath, (migrationsJson) => { + const { generators, packageJsonUpdates } = migrationsJson; + for (const [migrationName, m] of Object.entries(generators)) { + if (major(m.version) < v) { + const implFile = getImplFile(tree, migrationsPath, m); + + const specFile = implFile.replace('.ts', '.spec.ts'); + const snapshotsPath = join(dirname(specFile), '__snapshots__'); + try { + tree.delete(implFile); + tree.delete(specFile); + tree.delete(snapshotsPath); + } catch (e) { + console.log(e); + } + + delete migrationsJson.generators[migrationName]; + } + } + + for (const [updateName, packageJsonUpdate] of Object.entries( + packageJsonUpdates ?? {} + )) { + if (major(packageJsonUpdate.version) < v) { + delete packageJsonUpdates[updateName]; + } + } + + return migrationsJson; + }); + } + }); + await formatFiles(tree); +} + +export default removeMigrationsGenerator; + +function getImplFile( + tree: Tree, + migrationsFilePath: string, + { + implementation, + factory, + }: { + implementation?: string; + factory?: string; + } +) { + const rawPath = implementation ?? factory; + + const fullPath = join(dirname(migrationsFilePath), rawPath); + + if (tree.exists(fullPath)) { + return fullPath; + } + if (tree.exists(fullPath + '.ts')) { + return fullPath + '.ts'; + } + + return fullPath; +} diff --git a/tools/workspace-plugin/src/generators/remove-migrations/schema.json b/tools/workspace-plugin/src/generators/remove-migrations/schema.json new file mode 100644 index 0000000000000..180d6fa12dcbf --- /dev/null +++ b/tools/workspace-plugin/src/generators/remove-migrations/schema.json @@ -0,0 +1,12 @@ +{ + "$schema": "http://json-schema.org/schema", + "$id": "RemoveMigrations", + "title": "", + "type": "object", + "properties": { + "v": { + "type": "number" + } + }, + "required": [] +} diff --git a/tools/workspace-plugin/src/index.ts b/tools/workspace-plugin/src/index.ts new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/tools/workspace-plugin/tsconfig.json b/tools/workspace-plugin/tsconfig.json new file mode 100644 index 0000000000000..19b9eece4df14 --- /dev/null +++ b/tools/workspace-plugin/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs" + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/tools/workspace-plugin/tsconfig.lib.json b/tools/workspace-plugin/tsconfig.lib.json new file mode 100644 index 0000000000000..33eca2c2cdf8c --- /dev/null +++ b/tools/workspace-plugin/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "include": ["src/**/*.ts"], + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] +} diff --git a/tools/workspace-plugin/tsconfig.spec.json b/tools/workspace-plugin/tsconfig.spec.json new file mode 100644 index 0000000000000..9b2a121d114b6 --- /dev/null +++ b/tools/workspace-plugin/tsconfig.spec.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.d.ts" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index 70fccbc9599e6..95835fbbb1283 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -110,6 +110,7 @@ "@nx/webpack": ["packages/webpack"], "@nx/webpack/*": ["packages/webpack/*"], "@nx/workspace": ["packages/workspace"], + "@nx/workspace-plugin": ["tools/workspace-plugin/src/index.ts"], "@nx/workspace/*": ["packages/workspace/*"], "@nx/workspace/testing": ["packages/workspace/testing"], "create-nx-workspace": ["packages/create-nx-workspace/index.ts"],