diff --git a/packages/angular/migrations.json b/packages/angular/migrations.json index 3253e7e96a5a0..3cae3a1b2b56b 100644 --- a/packages/angular/migrations.json +++ b/packages/angular/migrations.json @@ -1,5 +1,11 @@ { "schematics": { + "install-required-packages": { + "cli": "nx", + "version": "15.7.0-beta.1", + "description": "Install the required angular-devkit packages as we do not directly depend on them anymore", + "factory": "./src/migrations/update-15-7-0/install-required-packages" + }, "remove-show-circular-dependencies-option": { "cli": "nx", "version": "14.2.0-beta.0", @@ -51,12 +57,6 @@ "description": "Update the @angular/cli package version to ~14.1.0.", "factory": "./src/migrations/update-14-5-2/update-angular-cli" }, - "update-rxjs-7-5-0": { - "cli": "nx", - "version": "14.5.7-beta.0", - "description": "Update the rxjs package version to ~7.5.0 if RxJS 7 is used in workspace.", - "factory": "./src/migrations/update-14-5-7/update-rxjs" - }, "update-angular-cli-version-14-2-0": { "cli": "nx", "version": "14.6.0-beta.0", @@ -147,12 +147,6 @@ "description": "Update the @angular/cli package version to ~15.1.0.", "factory": "./src/migrations/update-15-5-0/update-angular-cli" }, - "install-required-packages": { - "cli": "nx", - "version": "15.7.0-beta.1", - "description": "Install the required angular-devkit packages as we do not directly depend on them anymore", - "factory": "./src/migrations/update-15-7-0/install-required-packages" - }, "update-angular-cli-version-15-2-0": { "cli": "nx", "version": "15.8.0-beta.4", @@ -573,6 +567,18 @@ } } }, + "14.6.0-rxjs": { + "version": "14.6.0-beta.0", + "requires": { + "rxjs": ">=7.0.0 <7.5.0" + }, + "packages": { + "rxjs": { + "version": "~7.5.0", + "alwaysAddToPackageJson": false + } + } + }, "14.8.0-angular-eslint": { "version": "14.8.0-beta.0", "packages": { @@ -918,6 +924,18 @@ "alwaysAddToPackageJson": false } } + }, + "15.8.6-rxjs": { + "version": "15.8.6-beta.0", + "requires": { + "rxjs": ">=7.5.0 <7.6.0" + }, + "packages": { + "rxjs": { + "version": "~7.8.0", + "alwaysAddToPackageJson": false + } + } } } } diff --git a/packages/angular/src/migrations/update-14-5-7/update-rxjs.spec.ts b/packages/angular/src/migrations/update-14-5-7/update-rxjs.spec.ts deleted file mode 100644 index 99a5e2c16b1ef..0000000000000 --- a/packages/angular/src/migrations/update-14-5-7/update-rxjs.spec.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { readJson, Tree, writeJson } from '@nrwl/devkit'; -import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import updateRxjs from './update-rxjs'; - -describe('update-rxjs migration', () => { - let tree: Tree; - - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - }); - - it('should update rxjs version when defined as a dev dependency and greater than 7.0.0', async () => { - writeJson(tree, 'package.json', { - devDependencies: { rxjs: '~7.0.0' }, - }); - - await updateRxjs(tree); - - const { devDependencies } = readJson(tree, 'package.json'); - expect(devDependencies['rxjs']).toEqual('~7.5.0'); - }); - - it('should update rxjs version when defined as a dependency and greater than 7.0.0', async () => { - writeJson(tree, 'package.json', { - dependencies: { rxjs: '~7.0.0' }, - }); - - await updateRxjs(tree); - - const { dependencies } = readJson(tree, 'package.json'); - expect(dependencies['rxjs']).toEqual('~7.5.0'); - }); - - it('should not update rxjs when it is less than 7.0.0', async () => { - writeJson(tree, 'package.json', { - dependencies: { rxjs: '~6.5.0' }, - }); - - await updateRxjs(tree); - - const { dependencies } = readJson(tree, 'package.json'); - expect(dependencies['rxjs']).toEqual('~6.5.0'); - }); - - it('should not update rxjs when it is less than 7.0.0', async () => { - writeJson(tree, 'package.json', { - devDependencies: { rxjs: '~6.5.0' }, - }); - - await updateRxjs(tree); - - const { devDependencies } = readJson(tree, 'package.json'); - expect(devDependencies['rxjs']).toEqual('~6.5.0'); - }); -}); diff --git a/packages/angular/src/migrations/update-14-5-7/update-rxjs.ts b/packages/angular/src/migrations/update-14-5-7/update-rxjs.ts deleted file mode 100644 index 0d85da9841e35..0000000000000 --- a/packages/angular/src/migrations/update-14-5-7/update-rxjs.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { formatFiles, Tree, updateJson } from '@nrwl/devkit'; -import { gte, minVersion } from 'semver'; - -const rxjsVersion = '~7.5.0'; - -export default async function (tree: Tree) { - let shouldFormat = false; - - updateJson(tree, 'package.json', (json) => { - if ( - json.devDependencies?.['rxjs'] && - gte(minVersion(json.devDependencies?.['rxjs']), '7.0.0') - ) { - json.devDependencies['rxjs'] = rxjsVersion; - shouldFormat = true; - } else if ( - json.dependencies?.['rxjs'] && - gte(minVersion(json.dependencies?.['rxjs']), '7.0.0') - ) { - json.dependencies['rxjs'] = rxjsVersion; - shouldFormat = true; - } - - return json; - }); - - if (shouldFormat) { - await formatFiles(tree); - } -} diff --git a/packages/angular/src/migrations/update-15-7-0/install-required-packages.spec.ts b/packages/angular/src/migrations/update-15-7-0/install-required-packages.spec.ts index 5057744ac1365..a28cb34aab768 100644 --- a/packages/angular/src/migrations/update-15-7-0/install-required-packages.spec.ts +++ b/packages/angular/src/migrations/update-15-7-0/install-required-packages.spec.ts @@ -1,3 +1,11 @@ +// mock stuff that relies or make changes to the filesystem +jest.mock('child_process'); +jest.mock('@nrwl/devkit', () => ({ + ...jest.requireActual('@nrwl/devkit'), + getPackageManagerCommand: jest.fn(() => ({ install: '' })), + writeJsonFile: jest.fn(), +})); + import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; import { readJson, updateJson } from '@nrwl/devkit'; import installRequiredPackages from './install-required-packages'; diff --git a/packages/angular/src/migrations/update-15-7-0/install-required-packages.ts b/packages/angular/src/migrations/update-15-7-0/install-required-packages.ts index 5a550303e14cd..9b4da5d65a566 100644 --- a/packages/angular/src/migrations/update-15-7-0/install-required-packages.ts +++ b/packages/angular/src/migrations/update-15-7-0/install-required-packages.ts @@ -1,5 +1,12 @@ import type { Tree } from '@nrwl/devkit'; -import { addDependenciesToPackageJson, readJson } from '@nrwl/devkit'; +import { + addDependenciesToPackageJson, + getPackageManagerCommand, + readJson, + writeJsonFile, +} from '@nrwl/devkit'; +import { execSync } from 'child_process'; +import { join } from 'path'; import { getInstalledAngularMajorVersion } from '../../generators/utils/version-utils'; import { getPkgVersionForAngularMajorVersion } from '../../utils/version-utils'; @@ -27,6 +34,17 @@ export default async function (tree: Tree) { (pkg) => !pkgJson.devDependencies?.[pkg] && !pkgJson.dependencies?.[pkg] ) .reduce((allPkgs, pkg) => ({ ...allPkgs, [pkg]: angularCliVersion }), {}); - + // even though we are going to install the packages directly, we still want + // to add them to the tree so the migrate command knows changes were made addDependenciesToPackageJson(tree, {}, { ...filteredPackages }); + + // we need to install them immediately so the packages are available for + // other migrations that might be using them + pkgJson.devDependencies ??= {}; + Object.entries(filteredPackages).forEach(([pkg, version]) => { + pkgJson.devDependencies[pkg] = version; + }); + writeJsonFile(join(tree.root, 'package.json'), pkgJson); + const pmc = getPackageManagerCommand(); + execSync(pmc.install, { stdio: [0, 1, 2] }); }