From 07a6f76ccc61d9ccc5068f36a343dc5d594a2141 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Thu, 4 May 2023 17:31:54 -0600 Subject: [PATCH] fix(nextjs): remove outdated packages The features should be available by default closed #11882 --- packages/react/migrations.json | 6 +++++ packages/react/src/generators/init/init.ts | 2 -- .../update-16-1-0-remove-package.spec.ts | 23 ++++++++++++++++ .../update-16-1-0-remove-package.ts | 10 +++++++ packages/react/src/utils/versions.ts | 1 - packages/web/migrations.json | 6 +++++ packages/web/src/generators/init/init.ts | 2 -- .../update-16-1-0-remove-packages.spec.ts | 27 +++++++++++++++++++ .../update-16-1-0-remove-packages.ts | 15 +++++++++++ 9 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.spec.ts create mode 100644 packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.ts create mode 100644 packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.spec.ts create mode 100644 packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.ts diff --git a/packages/react/migrations.json b/packages/react/migrations.json index bdeeca3c2af3fa..818d063a85ff54 100644 --- a/packages/react/migrations.json +++ b/packages/react/migrations.json @@ -89,6 +89,12 @@ "version": "16.0.0-beta.1", "description": "Replace @nrwl/react with @nx/react", "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages" + }, + "update-16-1-0-remove-package": { + "cli": "nx", + "version": "16.1.0", + "description": "Remove react-test-renderer from package.json", + "implementation": "./src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package" } }, "packageJsonUpdates": { diff --git a/packages/react/src/generators/init/init.ts b/packages/react/src/generators/init/init.ts index 59aa332673f192..dee9e57e2ad757 100755 --- a/packages/react/src/generators/init/init.ts +++ b/packages/react/src/generators/init/init.ts @@ -16,7 +16,6 @@ import { babelPresetReactVersion, nxVersion, reactDomVersion, - reactTestRendererVersion, reactVersion, testingLibraryReactVersion, tsLibVersion, @@ -63,7 +62,6 @@ function updateDependencies(host: Tree, schema: InitSchema) { '@types/react': typesReactVersion, '@types/react-dom': typesReactDomVersion, '@testing-library/react': testingLibraryReactVersion, - 'react-test-renderer': reactTestRendererVersion, }); } diff --git a/packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.spec.ts b/packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.spec.ts new file mode 100644 index 00000000000000..9aae51ba1fb7b0 --- /dev/null +++ b/packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.spec.ts @@ -0,0 +1,23 @@ +import { Tree, readJson, updateJson } from '@nx/devkit'; +import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; +import removePackage from './update-16-1-0-remove-package'; + +describe('update-16-1-0-remove-package', () => { + let tree: Tree; + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + + updateJson(tree, 'package.json', (json) => { + json.devDependencies['react-test-renderer'] = '18.2.0'; + return json; + }); + }); + + it('should remove react-test-renderer from package.json', async () => { + await removePackage(tree); + + expect( + readJson(tree, 'package.json').devDependencies['react-test-renderer'] + ).not.toBeDefined(); + }); +}); diff --git a/packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.ts b/packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.ts new file mode 100644 index 00000000000000..00b761a1855088 --- /dev/null +++ b/packages/react/src/migrations/update-16-1-0-remove-package/update-16-1-0-remove-package.ts @@ -0,0 +1,10 @@ +import { + Tree, + formatFiles, + removeDependenciesFromPackageJson, +} from '@nx/devkit'; + +export default async function removePackage(tree: Tree): Promise { + removeDependenciesFromPackageJson(tree, [], ['react-test-renderer']); + await formatFiles(tree); +} diff --git a/packages/react/src/utils/versions.ts b/packages/react/src/utils/versions.ts index c3d7cc00be1287..a15e5254bf35d8 100755 --- a/packages/react/src/utils/versions.ts +++ b/packages/react/src/utils/versions.ts @@ -33,7 +33,6 @@ export const testingLibraryReactVersion = '14.0.0'; export const reduxjsToolkitVersion = '1.9.3'; export const reactReduxVersion = '8.0.5'; -export const reactTestRendererVersion = '18.2.0'; export const eslintPluginImportVersion = '2.27.5'; export const eslintPluginJsxA11yVersion = '6.7.1'; diff --git a/packages/web/migrations.json b/packages/web/migrations.json index 84c2150e77d844..6f89156c135fac 100644 --- a/packages/web/migrations.json +++ b/packages/web/migrations.json @@ -71,6 +71,12 @@ "version": "16.0.0-beta.4", "description": "Replace @nrwl/web executors with @nx/webpack and @nx/rollup", "implementation": "./src/migrations/update-16-0-0-update-executors/update-16-0-0-update-executors" + }, + "update-16-1-0-remove-packages": { + "cli": "nx", + "version": "16.1.0", + "description": "Remove core-js and regenerator-runtime packages", + "implementation": "./src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages" } }, "packageJsonUpdates": { diff --git a/packages/web/src/generators/init/init.ts b/packages/web/src/generators/init/init.ts index 4b3f1e804c7466..a703a0cac0e653 100644 --- a/packages/web/src/generators/init/init.ts +++ b/packages/web/src/generators/init/init.ts @@ -29,8 +29,6 @@ function updateDependencies(tree: Tree, schema: Schema) { return addDependenciesToPackageJson( tree, { - 'core-js': '^3.6.5', - 'regenerator-runtime': '0.13.7', tslib: tsLibVersion, }, devDependencies diff --git a/packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.spec.ts b/packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.spec.ts new file mode 100644 index 00000000000000..d27bbe97d9e2be --- /dev/null +++ b/packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.spec.ts @@ -0,0 +1,27 @@ +import { Tree, readJson, updateJson } from '@nx/devkit'; +import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; +import removePackages from './update-16-1-0-remove-packages'; + +describe('update-16-1-0-remove-packages', () => { + let tree: Tree; + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + + updateJson(tree, 'package.json', (json) => { + json.dependencies['core-js'] = '3.6.5'; + json.dependencies['regenerator-runtime'] = '0.13.7'; + return json; + }); + }); + + it('should remove core-js & regenerator-runtime packages', async () => { + await removePackages(tree); + + expect( + readJson(tree, 'package.json').dependencies['core-js'] + ).not.toBeDefined(); + expect( + readJson(tree, 'package.json').dependencies['regenerator-runtime'] + ).not.toBeDefined(); + }); +}); diff --git a/packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.ts b/packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.ts new file mode 100644 index 00000000000000..ae9653465ca1f8 --- /dev/null +++ b/packages/web/src/migrations/update-16-1-0-remove-packages/update-16-1-0-remove-packages.ts @@ -0,0 +1,15 @@ +import { + Tree, + formatFiles, + removeDependenciesFromPackageJson, +} from '@nx/devkit'; + +export default async function removePackages(tree: Tree): Promise { + removeDependenciesFromPackageJson( + tree, + ['core-js', 'regenerator-runtime'], + [] + ); + + await formatFiles(tree); +}