fix(angular): fix missing null checks in v13 migrations (#7790)

This commit is contained in:
Craigory Coppola 2021-11-18 10:52:04 -06:00 committed by GitHub
parent fbeb6ef121
commit 57bf28bfbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 23 deletions

View File

@ -49,6 +49,15 @@ describe('update-angular-jest-config migration', () => {
const updatedJestFile = tree.read('apps/testing/jest.config.js', 'utf-8'); const updatedJestFile = tree.read('apps/testing/jest.config.js', 'utf-8');
expect(updatedJestFile).toMatchSnapshot(); expect(updatedJestFile).toMatchSnapshot();
}); });
it("shouldn't error on null targets", async () => {
const tree = createTreeWithEmptyWorkspace(2);
addProjectConfiguration(tree, 'app', {
root: 'apps/testing',
});
const promise = updateAngularJestConfig(tree);
await expect(promise).resolves.not.toThrow();
});
}); });
describe('ast transformations', () => { describe('ast transformations', () => {

View File

@ -11,8 +11,8 @@ export default async function (tree: Tree) {
for (const [projectName, project] of projects.entries()) { for (const [projectName, project] of projects.entries()) {
if ( if (
project.targets.test && project.targets?.test &&
project.targets.test.executor === '@nrwl/jest:jest' project.targets?.test.executor === '@nrwl/jest:jest'
) { ) {
const jestConfigPath = const jestConfigPath =
project.targets.test.options && project.targets.test.options.jestConfig; project.targets.test.options && project.targets.test.options.jestConfig;

View File

@ -11,6 +11,7 @@ describe('update-libraries migration', () => {
targets: { targets: {
build: { build: {
executor: '@nrwl/angular:ng-packagr-lite', executor: '@nrwl/angular:ng-packagr-lite',
options: {},
}, },
}, },
}); });
@ -47,6 +48,7 @@ describe('update-libraries migration', () => {
targets: { targets: {
build: { build: {
executor: '@nrwl/angular:ng-packagr-lite', executor: '@nrwl/angular:ng-packagr-lite',
options: {},
}, },
}, },
}); });
@ -74,4 +76,13 @@ describe('update-libraries migration', () => {
expect(tsconfigFile.includes('amdId')).toBeFalsy(); expect(tsconfigFile.includes('amdId')).toBeFalsy();
expect(tsconfigFile.includes('umdId')).toBeFalsy(); expect(tsconfigFile.includes('umdId')).toBeFalsy();
}); });
it("shouldn't error on null targets", async () => {
const tree = createTreeWithEmptyWorkspace(2);
addProjectConfiguration(tree, 'app', {
root: 'apps/testing',
});
const promise = updateLibraries(tree);
await expect(promise).resolves.not.toThrow();
});
}); });

View File

@ -1,5 +1,6 @@
import type { Tree } from '@nrwl/devkit'; import type { Tree } from '@nrwl/devkit';
import { getProjects, joinPathFragments, updateJson } from '@nrwl/devkit'; import { getProjects, joinPathFragments, updateJson } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
export default async function (tree: Tree) { export default async function (tree: Tree) {
const LIBRARY_EXECUTORS = [ const LIBRARY_EXECUTORS = [
@ -10,28 +11,27 @@ export default async function (tree: Tree) {
const tsConfigFilesToUpdate = new Set<string>(); const tsConfigFilesToUpdate = new Set<string>();
const ngPackageFilesToUpdate = new Set<string>(); const ngPackageFilesToUpdate = new Set<string>();
for (const [projectName, project] of projects.entries()) { LIBRARY_EXECUTORS.forEach((executor) => {
for (const [targetName, target] of Object.entries(project.targets)) { forEachExecutorOptions(tree, executor, (opts, projectName) => {
if (LIBRARY_EXECUTORS.includes(target.executor)) { const project = projects.get(projectName);
// UPDATE THE TSCONFIG JSON // UPDATE THE TSCONFIG JSON
const tsConfigPath = joinPathFragments( const tsConfigPath = joinPathFragments(
project.root, project.root,
'tsconfig.lib.prod.json' 'tsconfig.lib.prod.json'
); );
if (tree.exists(tsConfigPath)) { if (tree.exists(tsConfigPath)) {
tsConfigFilesToUpdate.add(tsConfigPath); tsConfigFilesToUpdate.add(tsConfigPath);
}
const ngPackageFilePath = joinPathFragments(
project.root,
'ng-package.json'
);
if (tree.exists(ngPackageFilePath)) {
ngPackageFilesToUpdate.add(ngPackageFilePath);
}
} }
}
} const ngPackageFilePath = joinPathFragments(
project.root,
'ng-package.json'
);
if (tree.exists(ngPackageFilePath)) {
ngPackageFilesToUpdate.add(ngPackageFilePath);
}
});
});
for (const tsConfigPath of tsConfigFilesToUpdate) { for (const tsConfigPath of tsConfigFilesToUpdate) {
updateJson(tree, tsConfigPath, (json) => { updateJson(tree, tsConfigPath, (json) => {