Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('Migration to version 9', () => {
tree,
)
.toPromise();

tree = await schematicRunner
.runExternalSchematicAsync(
require.resolve('../../collection.json'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export function updateWorkspaceConfig(): Rule {
updateStyleOrScriptOption('scripts', recorder, target);
}

for (const { target } of getTargets(workspace, 'server', Builders.Server)) {
updateOptimizationOption(recorder, target);
}

tree.commitUpdate(recorder);

return tree;
Expand Down Expand Up @@ -139,3 +143,22 @@ function addAnyComponentStyleBudget(recorder: UpdateRecorder, builderConfig: Jso
}
}
}

function updateOptimizationOption(recorder: UpdateRecorder, builderConfig: JsonAstObject) {
const options = getAllOptions(builderConfig, true);

for (const option of options) {
const optimizationOption = findPropertyInAstObject(option, 'optimization');
if (!optimizationOption) {
// add
insertPropertyInAstObjectInOrder(recorder, option, 'optimization', true, 14);
continue;
}

if (optimizationOption.kind !== 'true') {
const { start, end } = optimizationOption;
recorder.remove(start.offset, end.offset - start.offset);
recorder.insertLeft(start.offset, 'true');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,53 @@ describe('Migration to version 9', () => {
expect(config.configurations.production.aot).toBeUndefined();
});
});

describe('server optimization option', () => {
beforeEach(async () => {
tree = await schematicRunner
.runExternalSchematicAsync(
require.resolve('../../collection.json'),
'universal',
{
clientProject: 'migration-test',
},
tree,
)
.toPromise();
});

it('should add optimization option when not defined', async () => {
let config = getWorkspaceTargets(tree);
config.server.configurations.production.optimization = undefined;
updateWorkspaceTargets(tree, config);

const tree2 = await schematicRunner.runSchematicAsync('migration-09', {}, tree.branch()).toPromise();
config = getWorkspaceTargets(tree2).server.configurations;
expect(config.production.optimization).toBe(true);
});

it('should set optimization to true when false', async () => {
let config = getWorkspaceTargets(tree);
config.server.configurations.production.optimization = false;
updateWorkspaceTargets(tree, config);

const tree2 = await schematicRunner.runSchematicAsync('migration-09', {}, tree.branch()).toPromise();
config = getWorkspaceTargets(tree2).server.configurations;
expect(config.production.optimization).toBe(true);
});

it('should set optimization to true when optimization is fine grained', async () => {
let config = getWorkspaceTargets(tree);
config.server.configurations.production.optimization = {
scripts: false,
styles: true,
};
updateWorkspaceTargets(tree, config);

const tree2 = await schematicRunner.runSchematicAsync('migration-09', {}, tree.branch()).toPromise();
config = getWorkspaceTargets(tree2).server.configurations;
expect(config.production.optimization).toBe(true);
});
});
});
});
5 changes: 1 addition & 4 deletions packages/schematics/angular/universal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R
production: {
fileReplacements,
sourceMap: false,
optimization: {
scripts: false,
styles: true,
},
optimization: true,
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/build/platform-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default async function () {
}


await ng('run', 'test-project:server:production');
await ng('run', 'test-project:server:production', '--optimization', 'false');

await expectFileToMatch('dist/server/main.js', veEnabled ? /exports.*AppServerModuleNgFactory/ : /exports.*AppServerModule/);
await exec(normalize('node'), 'index.js');
Expand Down