Skip to content

Commit

Permalink
fix(react): migrations should not crash when adding development confi…
Browse files Browse the repository at this point in the history
…guration (#10261)
  • Loading branch information
john-waitforit committed May 12, 2022
1 parent d46e49c commit c35b13d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
Expand Up @@ -42,6 +42,43 @@ describe('React default development configuration', () => {
});
});

it('should add development configuration if no configurations at all', async () => {
const tree = createTreeWithEmptyWorkspace(2);
addProjectConfiguration(
tree,
'example',
{
root: 'apps/example',
projectType: 'application',
targets: {
build: {
executor: '@nrwl/next:build',
defaultConfiguration: 'production',
configurations: { production: {} },
},
serve: {
executor: '@nrwl/next:server',
},
},
},
true
);

await update(tree);

const config = readProjectConfiguration(tree, 'example');

expect(config.targets.build.defaultConfiguration).toEqual('production');
expect(config.targets.build.configurations.production).toEqual({});
expect(config.targets.build.configurations.development).toEqual({});

expect(config.targets.serve.defaultConfiguration).toEqual('development');
expect(config.targets.serve.configurations.development).toEqual({
buildTarget: `example:build:development`,
dev: true,
});
});

it('should work without targets', async () => {
const tree = createTreeWithEmptyWorkspace(2);
addProjectConfiguration(
Expand Down
Expand Up @@ -13,12 +13,14 @@ export async function update(tree: Tree) {
if (config.targets?.build?.executor === '@nrwl/next:build') {
shouldUpdate = true;
config.targets.build.defaultConfiguration ??= 'production';
config.targets.build.configurations ??= {};
config.targets.build.configurations.development ??= {};
}

if (config.targets?.serve?.executor === '@nrwl/next:server') {
shouldUpdate = true;
config.targets.serve.defaultConfiguration ??= 'development';
config.targets.serve.configurations ??= {};
config.targets.serve.configurations.development ??= {
buildTarget: `${name}:build:development`,
dev: true,
Expand Down
Expand Up @@ -46,6 +46,49 @@ describe('React default development configuration', () => {
});
});

it('should add development configuration if no configurations at all', async () => {
const tree = createTreeWithEmptyWorkspace(2);
addProjectConfiguration(
tree,
'example',
{
root: 'apps/example',
projectType: 'application',
targets: {
build: {
executor: '@nrwl/web:webpack',
defaultConfiguration: 'production',
configurations: { production: { sourceMap: false } },
},
serve: {
executor: '@nrwl/web:dev-server',
},
},
},
true
);

await update(tree);

const config = readProjectConfiguration(tree, 'example');

expect(config.targets.build.defaultConfiguration).toEqual('production');
expect(config.targets.build.configurations.production).toEqual({
sourceMap: false,
});
expect(config.targets.build.configurations.development).toEqual({
extractLicenses: false,
optimization: false,
sourceMap: true,
vendorChunk: true,
});

expect(config.targets.serve.defaultConfiguration).toEqual('development');
expect(config.targets.serve.configurations.development).toEqual({
buildTarget: `example:build:development`,
});
});

it('should work without targets', async () => {
const tree = createTreeWithEmptyWorkspace(2);
addProjectConfiguration(
Expand Down
Expand Up @@ -13,6 +13,7 @@ export async function update(tree: Tree) {
if (config.targets?.build?.executor === '@nrwl/web:webpack') {
shouldUpdate = true;
config.targets.build.defaultConfiguration ??= 'production';
config.targets.build.configurations ??= {};
config.targets.build.configurations.development ??= {
extractLicenses: false,
optimization: false,
Expand All @@ -24,6 +25,7 @@ export async function update(tree: Tree) {
if (config.targets?.serve?.executor === '@nrwl/web:dev-server') {
shouldUpdate = true;
config.targets.serve.defaultConfiguration ??= 'development';
config.targets.serve.configurations ??= {};
config.targets.serve.configurations.development ??= {
buildTarget: `${name}:build:development`,
};
Expand Down

0 comments on commit c35b13d

Please sign in to comment.