fix(angular): fix missing null checks in v13 migrations (#7790)
This commit is contained in:
parent
fbeb6ef121
commit
57bf28bfbc
@ -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', () => {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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<string>();
|
||||
const ngPackageFilesToUpdate = new Set<string>();
|
||||
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) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user