fix(angular): handle projects with no targets in angular 13 migration (#7719)

This commit is contained in:
Jason Jean 2021-11-12 14:19:53 -05:00 committed by GitHub
parent 9fbd99700d
commit a6085a9e97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 42 deletions

View File

@ -19,7 +19,7 @@ import { switchMap } from 'rxjs/operators';
import { existsSync } from 'fs'; import { existsSync } from 'fs';
import { merge } from 'webpack-merge'; import { merge } from 'webpack-merge';
type BrowserBuilderSchema = Schema & { export type BrowserBuilderSchema = Schema & {
customWebpackConfig?: { customWebpackConfig?: {
path: string; path: string;
}; };

View File

@ -75,4 +75,19 @@ describe('update-angular-config migration', () => {
expect(targets.build.options.somethingThatShouldNotBeRemoved).toBeDefined(); expect(targets.build.options.somethingThatShouldNotBeRemoved).toBeDefined();
expect(targets.build.options.extractCss).toBeUndefined(); expect(targets.build.options.extractCss).toBeUndefined();
}); });
it('should not fail for projects with no targets', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace(2);
addProjectConfiguration(tree, 'testing', {
root: 'apps/testing',
});
// ACT
await updateAngularConfig(tree);
// ASSERT
const { targets } = readProjectConfiguration(tree, 'testing');
expect(targets).toBeUndefined();
});
}); });

View File

@ -1,46 +1,50 @@
import type { Tree } from '@nrwl/devkit'; import type { Tree } from '@nrwl/devkit';
import { getProjects, updateProjectConfiguration } from '@nrwl/devkit'; import {
readProjectConfiguration,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { Schema as WebpackServerOptions } from '../../builders/webpack-server/schema';
import { BrowserBuilderSchema as WebpackBrowserOptions } from '../../builders/webpack-browser/webpack-browser.impl';
export default async function (tree: Tree) { export default async function (tree: Tree) {
const projects = getProjects(tree); forEachExecutorOptions<WebpackServerOptions>(
for (const [projectName, project] of projects.entries()) { tree,
for (const [targetName, target] of Object.entries(project.targets)) { '@nrwl/angular:webpack-server',
if (target.executor === '@nrwl/angular:webpack-server') { (options: any, projectName, targetName, configurationName) => {
updateProjectConfiguration(tree, projectName, { const projectConfiguration = readProjectConfiguration(tree, projectName);
...project, const config = configurationName
targets: { ? projectConfiguration.targets[targetName].configurations[
...project.targets, configurationName
[targetName]: { ]
...target, : projectConfiguration.targets[targetName].options;
options: { delete config.optimization;
...target.options, delete config.aot;
optimization: undefined, delete config.progress;
aot: undefined, delete config.deployUrl;
progress: undefined, delete config.sourceMap;
deployUrl: undefined, delete config.vendorChunk;
sourceMap: undefined, delete config.commonChunk;
vendorChunk: undefined, delete config.baseHref;
commonChunk: undefined, delete config.servePathDefaultWarning;
baseHref: undefined, delete config.hmrWarning;
servePathDefaultWarning: undefined, delete config.extractCss;
hmrWarning: undefined, updateProjectConfiguration(tree, projectName, projectConfiguration);
extractCss: undefined,
},
},
},
});
} else if (target.executor === '@nrwl/angular:webpack-browser') {
updateProjectConfiguration(tree, projectName, {
...project,
[targetName]: {
...target,
options: {
...target.options,
extractCss: undefined,
},
},
});
}
} }
} );
forEachExecutorOptions<WebpackBrowserOptions>(
tree,
'@nrwl/angular:webpack-browser',
(options: any, projectName, targetName, configurationName) => {
const projectConfiguration = readProjectConfiguration(tree, projectName);
const config = configurationName
? projectConfiguration.targets[targetName].configurations[
configurationName
]
: projectConfiguration.targets[targetName];
delete config.extractCss;
updateProjectConfiguration(tree, projectName, projectConfiguration);
}
);
} }