Skip to content

Commit

Permalink
fix(angular): handle projects with no targets in angular 13 migration (
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Nov 12, 2021
1 parent 9fbd997 commit a6085a9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -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);
}
}
);
}

0 comments on commit a6085a9

Please sign in to comment.