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');
|
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', () => {
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user