fix(angular): handle projects with no targets in angular 13 migration (#7719)
This commit is contained in:
parent
9fbd99700d
commit
a6085a9e97
@ -19,7 +19,7 @@ import { switchMap } from 'rxjs/operators';
|
||||
import { existsSync } from 'fs';
|
||||
import { merge } from 'webpack-merge';
|
||||
|
||||
type BrowserBuilderSchema = Schema & {
|
||||
export type BrowserBuilderSchema = Schema & {
|
||||
customWebpackConfig?: {
|
||||
path: string;
|
||||
};
|
||||
|
||||
@ -75,4 +75,19 @@ describe('update-angular-config migration', () => {
|
||||
expect(targets.build.options.somethingThatShouldNotBeRemoved).toBeDefined();
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,46 +1,50 @@
|
||||
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) {
|
||||
const projects = getProjects(tree);
|
||||
for (const [projectName, project] of projects.entries()) {
|
||||
for (const [targetName, target] of Object.entries(project.targets)) {
|
||||
if (target.executor === '@nrwl/angular:webpack-server') {
|
||||
updateProjectConfiguration(tree, projectName, {
|
||||
...project,
|
||||
targets: {
|
||||
...project.targets,
|
||||
[targetName]: {
|
||||
...target,
|
||||
options: {
|
||||
...target.options,
|
||||
optimization: undefined,
|
||||
aot: undefined,
|
||||
progress: undefined,
|
||||
deployUrl: undefined,
|
||||
sourceMap: undefined,
|
||||
vendorChunk: undefined,
|
||||
commonChunk: undefined,
|
||||
baseHref: undefined,
|
||||
servePathDefaultWarning: undefined,
|
||||
hmrWarning: undefined,
|
||||
extractCss: undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (target.executor === '@nrwl/angular:webpack-browser') {
|
||||
updateProjectConfiguration(tree, projectName, {
|
||||
...project,
|
||||
[targetName]: {
|
||||
...target,
|
||||
options: {
|
||||
...target.options,
|
||||
extractCss: undefined,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
forEachExecutorOptions<WebpackServerOptions>(
|
||||
tree,
|
||||
'@nrwl/angular:webpack-server',
|
||||
(options: any, projectName, targetName, configurationName) => {
|
||||
const projectConfiguration = readProjectConfiguration(tree, projectName);
|
||||
const config = configurationName
|
||||
? projectConfiguration.targets[targetName].configurations[
|
||||
configurationName
|
||||
]
|
||||
: projectConfiguration.targets[targetName].options;
|
||||
delete config.optimization;
|
||||
delete config.aot;
|
||||
delete config.progress;
|
||||
delete config.deployUrl;
|
||||
delete config.sourceMap;
|
||||
delete config.vendorChunk;
|
||||
delete config.commonChunk;
|
||||
delete config.baseHref;
|
||||
delete config.servePathDefaultWarning;
|
||||
delete config.hmrWarning;
|
||||
delete config.extractCss;
|
||||
updateProjectConfiguration(tree, projectName, projectConfiguration);
|
||||
}
|
||||
);
|
||||
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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user