Skip to content

Commit

Permalink
fix(angular): fix rxjs package updates and ensure peer deps are insta…
Browse files Browse the repository at this point in the history
…lled before other migrations (#15458)
  • Loading branch information
leosvelperez committed Mar 6, 2023
1 parent 7d52fc7 commit fba34ca
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 99 deletions.
42 changes: 30 additions & 12 deletions packages/angular/migrations.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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
}
}
}
}
}
55 changes: 0 additions & 55 deletions packages/angular/src/migrations/update-14-5-7/update-rxjs.spec.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/angular/src/migrations/update-14-5-7/update-rxjs.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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] });
}

0 comments on commit fba34ca

Please sign in to comment.