Skip to content

Commit fca9cbe

Browse files
alan-agius4vikerman
authored andcommitted
feat(@schematics/angular): update browser output path when adding universal
Currently, in the CLI universal schematic we are setting the server output path to `dist/project-server` and not amending the build outputPath Ex: ``` dist/project dist/project-server ``` However, the above paths are being update when adding `nguniversal` to the below: ``` dist/project/browser dist/project/server ``` With this change it is proposed to move that logic to upstream. Related PR to clean up nguniversal schematics angular/universal#1265
1 parent 6525d59 commit fca9cbe

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/schematics/angular/universal/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ function updateConfigFile(options: UniversalOptions, tsConfigDirectory: Path): R
4949
fileReplacements = buildTarget.configurations.production.fileReplacements;
5050
}
5151

52+
if (buildTarget && buildTarget.options) {
53+
buildTarget.options.outputPath = `dist/${options.clientProject}/browser`;
54+
}
55+
5256
const mainPath = options.main as string;
5357
clientProject.targets.add({
5458
name: 'server',
5559
builder: Builders.Server,
5660
options: {
57-
outputPath: `dist/${options.clientProject}-server`,
61+
outputPath: `dist/${options.clientProject}/server`,
5862
main: join(normalize(clientProject.root), 'src', mainPath.endsWith('.ts') ? mainPath : mainPath + '.ts'),
5963
tsConfig: join(tsConfigDirectory, `${options.tsconfigFileName}.json`),
6064
},

packages/schematics/angular/universal/index_spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('Universal Schematic', () => {
149149
expect(targets.server).toBeDefined();
150150
expect(targets.server.builder).toBeDefined();
151151
const opts = targets.server.options;
152-
expect(opts.outputPath).toEqual('dist/bar-server');
152+
expect(opts.outputPath).toEqual('dist/bar/server');
153153
expect(opts.main).toEqual('projects/bar/src/main.server.ts');
154154
expect(opts.tsConfig).toEqual('projects/bar/tsconfig.server.json');
155155
const configurations = targets.server.configurations;
@@ -161,6 +161,16 @@ describe('Universal Schematic', () => {
161161
expect(fileReplacements[0].with).toEqual('projects/bar/src/environments/environment.prod.ts');
162162
});
163163

164+
it('should update workspace with a build target outputPath', async () => {
165+
const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
166+
.toPromise();
167+
const filePath = '/angular.json';
168+
const contents = tree.readContent(filePath);
169+
const config = JSON.parse(contents.toString());
170+
const targets = config.projects.bar.architect;
171+
expect(targets.build.options.outputPath).toEqual('dist/bar/browser');
172+
});
173+
164174
it('should add a server transition to BrowerModule import', async () => {
165175
const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
166176
.toPromise();

tests/legacy-cli/e2e/tests/build/build-app-shell-with-schematic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export default async function () {
1717

1818
await silentNpm('install');
1919
await ng('run', 'test-project:app-shell');
20-
await expectFileToMatch('dist/test-project/index.html', /app-shell works!/);
20+
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
2121

2222
await ng('run', 'test-project:app-shell:production');
23-
await expectFileToMatch('dist/test-project/index.html', /app-shell works!/);
23+
await expectFileToMatch('dist/test-project/browser/index.html', /app-shell works!/);
2424
}

0 commit comments

Comments
 (0)