All files / src/migrations 5.3.1.ts

94.73% Statements 18/19
66.66% Branches 2/3
100% Functions 5/5
94.11% Lines 16/17

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 421x   1x   1x                       1x 3x 3x       3x   3x       3x 3x   3x 2x 2x 2x 2x 1x          
import { JSONFile } from '../utils/angular/json-utils';
import { Rule, Tree } from '@angular-devkit/schematics';
import { tryRule } from './utils/rules';
 
const manualProcess = `## This migrates sets only libs/*/public_api.ts to the default scope path.
 
to apply this changes apply the following steps:
 
#### Update project \`tsconfig.json\` to include the following configration
 
inside \`compilerOptions\`, \`path\` set public_api libs:
\`
+    libs/*/public_api.ts
\`
`;
 
export default function (): Rule {
  return tryRule(async (tree: Tree) => {
    updatetsConfigCompilerOptions(tree);
  }, manualProcess);
 
  function updatetsConfigCompilerOptions(tree: Tree) {
    const packageJsonPath = './package.json';
 
    Iif (!tree.exists(packageJsonPath)) {
      return;
    }
 
    const packageJson = new JSONFile(tree, packageJsonPath);
    const defaultScope = packageJson.get(['backbase', 'defaultScope']);
 
    if (defaultScope) {
      const tsconfig = new JSONFile(tree, './tsconfig.json');
      let paths = tsconfig.get(['compilerOptions', 'paths', `@${defaultScope}/*`]) as Array<string>;
      if (Array.isArray(paths)) {
        paths = paths.filter((item) => item.trim() !== `node_modules/@${defaultScope}/*`);
        tsconfig.modify(['compilerOptions', 'paths', `@${defaultScope}/*`], paths);
      }
    }
  }
}