Skip to content

Commit 0a4875c

Browse files
AgentEnderFrozenPandaz
authored andcommitted
fix(angular): fix missing null checks in v13 migrations (#7790)
1 parent 220cd01 commit 0a4875c

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ describe('update-angular-jest-config migration', () => {
4949
const updatedJestFile = tree.read('apps/testing/jest.config.js', 'utf-8');
5050
expect(updatedJestFile).toMatchSnapshot();
5151
});
52+
53+
it("shouldn't error on null targets", async () => {
54+
const tree = createTreeWithEmptyWorkspace(2);
55+
addProjectConfiguration(tree, 'app', {
56+
root: 'apps/testing',
57+
});
58+
const promise = updateAngularJestConfig(tree);
59+
await expect(promise).resolves.not.toThrow();
60+
});
5261
});
5362

5463
describe('ast transformations', () => {

packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default async function (tree: Tree) {
1111

1212
for (const [projectName, project] of projects.entries()) {
1313
if (
14-
project.targets.test &&
15-
project.targets.test.executor === '@nrwl/jest:jest'
14+
project.targets?.test &&
15+
project.targets?.test.executor === '@nrwl/jest:jest'
1616
) {
1717
const jestConfigPath =
1818
project.targets.test.options && project.targets.test.options.jestConfig;

packages/angular/src/migrations/update-13-2-0/update-libraries.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('update-libraries migration', () => {
1111
targets: {
1212
build: {
1313
executor: '@nrwl/angular:ng-packagr-lite',
14+
options: {},
1415
},
1516
},
1617
});
@@ -47,6 +48,7 @@ describe('update-libraries migration', () => {
4748
targets: {
4849
build: {
4950
executor: '@nrwl/angular:ng-packagr-lite',
51+
options: {},
5052
},
5153
},
5254
});
@@ -74,4 +76,13 @@ describe('update-libraries migration', () => {
7476
expect(tsconfigFile.includes('amdId')).toBeFalsy();
7577
expect(tsconfigFile.includes('umdId')).toBeFalsy();
7678
});
79+
80+
it("shouldn't error on null targets", async () => {
81+
const tree = createTreeWithEmptyWorkspace(2);
82+
addProjectConfiguration(tree, 'app', {
83+
root: 'apps/testing',
84+
});
85+
const promise = updateLibraries(tree);
86+
await expect(promise).resolves.not.toThrow();
87+
});
7788
});

packages/angular/src/migrations/update-13-2-0/update-libraries.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Tree } from '@nrwl/devkit';
22
import { getProjects, joinPathFragments, updateJson } from '@nrwl/devkit';
3+
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
34

45
export default async function (tree: Tree) {
56
const LIBRARY_EXECUTORS = [
@@ -10,28 +11,27 @@ export default async function (tree: Tree) {
1011

1112
const tsConfigFilesToUpdate = new Set<string>();
1213
const ngPackageFilesToUpdate = new Set<string>();
13-
for (const [projectName, project] of projects.entries()) {
14-
for (const [targetName, target] of Object.entries(project.targets)) {
15-
if (LIBRARY_EXECUTORS.includes(target.executor)) {
16-
// UPDATE THE TSCONFIG JSON
17-
const tsConfigPath = joinPathFragments(
18-
project.root,
19-
'tsconfig.lib.prod.json'
20-
);
21-
if (tree.exists(tsConfigPath)) {
22-
tsConfigFilesToUpdate.add(tsConfigPath);
23-
}
14+
LIBRARY_EXECUTORS.forEach((executor) => {
15+
forEachExecutorOptions(tree, executor, (opts, projectName) => {
16+
const project = projects.get(projectName);
17+
// UPDATE THE TSCONFIG JSON
18+
const tsConfigPath = joinPathFragments(
19+
project.root,
20+
'tsconfig.lib.prod.json'
21+
);
22+
if (tree.exists(tsConfigPath)) {
23+
tsConfigFilesToUpdate.add(tsConfigPath);
24+
}
2425

25-
const ngPackageFilePath = joinPathFragments(
26-
project.root,
27-
'ng-package.json'
28-
);
29-
if (tree.exists(ngPackageFilePath)) {
30-
ngPackageFilesToUpdate.add(ngPackageFilePath);
31-
}
26+
const ngPackageFilePath = joinPathFragments(
27+
project.root,
28+
'ng-package.json'
29+
);
30+
if (tree.exists(ngPackageFilePath)) {
31+
ngPackageFilesToUpdate.add(ngPackageFilePath);
3232
}
33-
}
34-
}
33+
});
34+
});
3535

3636
for (const tsConfigPath of tsConfigFilesToUpdate) {
3737
updateJson(tree, tsConfigPath, (json) => {

0 commit comments

Comments
 (0)