diff --git a/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.spec.ts b/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.spec.ts index f06ec09021..c5d33b033a 100644 --- a/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.spec.ts +++ b/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.spec.ts @@ -49,6 +49,15 @@ describe('update-angular-jest-config migration', () => { const updatedJestFile = tree.read('apps/testing/jest.config.js', 'utf-8'); 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', () => { diff --git a/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.ts b/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.ts index 3fb8eb829b..f5ebd4de02 100644 --- a/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.ts +++ b/packages/angular/src/migrations/update-13-2-0/update-angular-jest-config.ts @@ -11,8 +11,8 @@ export default async function (tree: Tree) { for (const [projectName, project] of projects.entries()) { if ( - project.targets.test && - project.targets.test.executor === '@nrwl/jest:jest' + project.targets?.test && + project.targets?.test.executor === '@nrwl/jest:jest' ) { const jestConfigPath = project.targets.test.options && project.targets.test.options.jestConfig; diff --git a/packages/angular/src/migrations/update-13-2-0/update-libraries.spec.ts b/packages/angular/src/migrations/update-13-2-0/update-libraries.spec.ts index 96e7eb1655..2806248e63 100644 --- a/packages/angular/src/migrations/update-13-2-0/update-libraries.spec.ts +++ b/packages/angular/src/migrations/update-13-2-0/update-libraries.spec.ts @@ -11,6 +11,7 @@ describe('update-libraries migration', () => { targets: { build: { executor: '@nrwl/angular:ng-packagr-lite', + options: {}, }, }, }); @@ -47,6 +48,7 @@ describe('update-libraries migration', () => { targets: { build: { executor: '@nrwl/angular:ng-packagr-lite', + options: {}, }, }, }); @@ -74,4 +76,13 @@ describe('update-libraries migration', () => { expect(tsconfigFile.includes('amdId')).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(); + }); }); diff --git a/packages/angular/src/migrations/update-13-2-0/update-libraries.ts b/packages/angular/src/migrations/update-13-2-0/update-libraries.ts index 55a45e3eff..f754853e77 100644 --- a/packages/angular/src/migrations/update-13-2-0/update-libraries.ts +++ b/packages/angular/src/migrations/update-13-2-0/update-libraries.ts @@ -1,5 +1,6 @@ import type { Tree } 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) { const LIBRARY_EXECUTORS = [ @@ -10,28 +11,27 @@ export default async function (tree: Tree) { const tsConfigFilesToUpdate = new Set(); const ngPackageFilesToUpdate = new Set(); - for (const [projectName, project] of projects.entries()) { - for (const [targetName, target] of Object.entries(project.targets)) { - if (LIBRARY_EXECUTORS.includes(target.executor)) { - // UPDATE THE TSCONFIG JSON - const tsConfigPath = joinPathFragments( - project.root, - 'tsconfig.lib.prod.json' - ); - if (tree.exists(tsConfigPath)) { - tsConfigFilesToUpdate.add(tsConfigPath); - } - - const ngPackageFilePath = joinPathFragments( - project.root, - 'ng-package.json' - ); - if (tree.exists(ngPackageFilePath)) { - ngPackageFilesToUpdate.add(ngPackageFilePath); - } + LIBRARY_EXECUTORS.forEach((executor) => { + forEachExecutorOptions(tree, executor, (opts, projectName) => { + const project = projects.get(projectName); + // UPDATE THE TSCONFIG JSON + const tsConfigPath = joinPathFragments( + project.root, + 'tsconfig.lib.prod.json' + ); + if (tree.exists(tsConfigPath)) { + tsConfigFilesToUpdate.add(tsConfigPath); } - } - } + + const ngPackageFilePath = joinPathFragments( + project.root, + 'ng-package.json' + ); + if (tree.exists(ngPackageFilePath)) { + ngPackageFilesToUpdate.add(ngPackageFilePath); + } + }); + }); for (const tsConfigPath of tsConfigFilesToUpdate) { updateJson(tree, tsConfigPath, (json) => {