All files / src/migrations 4.3.0.ts

100% Statements 23/23
100% Branches 0/0
100% Functions 7/7
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 861x 1x   1x 1x 1x   1x                                                                       1x 3x                 3x 3x                           3x 3x 4x 3x 4x 4x   2x     3x       1x 3x    
import { Rule, chain, Tree } from '@angular-devkit/schematics';
import * as path from 'path';
 
import { updatePackageJson, updatePeerDependencyVersionsInLib, PackageJson } from './utils/package-json';
import { tryRule } from './utils/rules';
import { getWorkspace, getLibProjects } from '../utils/backbase/package-utils';
 
const manualProcess = `
## Ensure dependencies are up to date
 
Update Angular dependencies using \`ng update\`. This will allow these packages to
perform any migrations that they deem necessary.
 
    ng update @angular/cli@10.1.0 @angular/core@10.1.0 --force
 
Set @angular/localize version to ~10.1.0 and rxjs version to ~6.6.2:
 
## Update peer dependency versions in all public libs
 
The peerDependencies of all libs in a project should be aligned with the package versions actually
installed in the project. This means that development and tests can be performed against compatible
versions of the target dependencies.
 
Any peerDependencies in package.json files inside libs packages should be updated to be compatible
with the following versions:
 
    @angular/animations: 10.1.0,
    @angular/common: 10.1.0,
    @angular/compiler: 10.1.0,
    @angular/core: 10.1.0,
    @angular/forms: 10.1.0,
    @angular/platform-browser: 10.1.0,
    @angular/platform-browser-dynamic: 10.1.0,
    @angular/router: 10.1.0,
    @ngrx/effects: 10.0.0,
    @ngrx/store: 10.0.0,
    rxjs: 6.6.2
 
Note: This *does not* mean that the version must be locked - the semver range should reflect the
most liberal version(s) the library supports.
 
`;
 
const updateProjectDependencies: Rule = () =>
  updatePackageJson((packageJson: PackageJson) => ({
    ...packageJson,
    dependencies: {
      ...packageJson.dependencies,
      '@angular/localize': '~10.1.0',
      rxjs: '~6.6.2',
    },
  }));
 
const updatePeerDependencyVersionsInAllLibs: Rule = async (tree: Tree) => {
  const targetPackageVersions = {
    '@angular/animations': '10.1.0',
    '@angular/common': '10.1.0',
    '@angular/compiler': '10.1.0',
    '@angular/core': '10.1.0',
    '@angular/forms': '10.1.0',
    '@angular/platform-browser': '10.1.0',
    '@angular/platform-browser-dynamic': '10.1.0',
    '@angular/router': '10.1.0',
    '@ngrx/effects': '10.0.0',
    '@ngrx/store': '10.0.0',
    rxjs: '6.6.2',
  };
 
  const workspace = await getWorkspace(tree);
  return (host: Tree) => {
    const packageJsonPaths = getLibProjects(workspace).map((project) => path.join(project.root, 'package.json'));
    for (const packageJsonPath of packageJsonPaths) {
      try {
        updatePeerDependencyVersionsInLib(host, packageJsonPath, targetPackageVersions);
      } catch (e) {
        continue;
      }
    }
    return host;
  };
};
 
export default function (): Rule {
  return tryRule(chain([updateProjectDependencies, updatePeerDependencyVersionsInAllLibs]), manualProcess);
}