Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 10d68fc

Browse files
Alan Agiusvikerman
authored andcommitted
fix(schematics): ng add removes options from browser builder (#1190)
* fix(express-engine): ng add removes options from browser builder This fixes a couple of regressions in the latest version. Were running `ng add` would cause configuration from the browser builder to be deleted instead of updated Fixes #1189 * fix(hapi-engine): ng add removes options from browser builder This fixes a couple of regressions in the latest version. Were running `ng add` would cause configuration from the browser builder to be deleted instead of updated Fixes #1189
1 parent 75d59c3 commit 10d68fc

4 files changed

Lines changed: 36 additions & 26 deletions

File tree

modules/express-engine/schematics/install/index.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,23 @@ describe('Universal Schematic', () => {
131131
.toPromise();
132132
const filePath = '/projects/bar/src/main.server.ts';
133133
const contents = tree.readContent(filePath);
134-
console.log({contents});
135134
expect(contents).toContain('ngExpressEngine');
136135
expect(contents).toContain('provideModuleMap');
137136
});
137+
138+
it('should update angular.json', async () => {
139+
const tree = await schematicRunner
140+
.runSchematicAsync('ng-add', defaultOptions, appTree)
141+
.toPromise();
142+
const contents = JSON.parse(tree.readContent('angular.json'));
143+
const architect = contents.projects.bar.architect;
144+
expect(architect.build.configurations.production).toBeDefined();
145+
expect(architect.build.options.outputPath).toBe('dist/browser');
146+
expect(architect.server.options.outputPath).toBe('dist/server');
147+
148+
const productionConfig = architect.server.configurations.production;
149+
expect(productionConfig.fileReplacements).toBeDefined();
150+
expect(productionConfig.optimization).toBeDefined();
151+
expect(productionConfig.sourceMap).toBeDefined();
152+
});
138153
});

modules/express-engine/schematics/install/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function updateConfigFile(options: UniversalOptions) {
116116
const clientProject = workspace.projects.get(options.clientProject);
117117
if (clientProject) {
118118
const buildTarget = clientProject.targets.get('build');
119-
const serverTarget = clientProject.targets.get('build');
119+
const serverTarget = clientProject.targets.get('server');
120120

121121
// We have to check if the project config has a server target, because
122122
// if the Universal step in this schematic isn't run, it can't be guaranteed
@@ -125,23 +125,13 @@ function updateConfigFile(options: UniversalOptions) {
125125
return;
126126
}
127127

128-
serverTarget.configurations = {
129-
production: {
130-
fileReplacements: [
131-
{
132-
replace: 'src/environments/environment.ts',
133-
with: 'src/environments/environment.prod.ts'
134-
}
135-
]
136-
}
137-
};
138-
139128
serverTarget.options = {
140129
...serverTarget.options,
141130
outputPath: SERVER_DIST,
142131
};
143132

144133
buildTarget.options = {
134+
...buildTarget.options,
145135
outputPath: BROWSER_DIST,
146136
};
147137
}

modules/hapi-engine/schematics/install/index.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,23 @@ describe('Universal Schematic', () => {
131131
.toPromise();
132132
const filePath = '/projects/bar/src/main.server.ts';
133133
const contents = tree.readContent(filePath);
134-
console.log({contents});
135134
expect(contents).toContain('ngHapiEngine');
136135
expect(contents).toContain('provideModuleMap');
137136
});
137+
138+
it('should update angular.json', async () => {
139+
const tree = await schematicRunner
140+
.runSchematicAsync('ng-add', defaultOptions, appTree)
141+
.toPromise();
142+
const contents = JSON.parse(tree.readContent('angular.json'));
143+
const architect = contents.projects.bar.architect;
144+
expect(architect.build.configurations.production).toBeDefined();
145+
expect(architect.build.options.outputPath).toBe('dist/browser');
146+
expect(architect.server.options.outputPath).toBe('dist/server');
147+
148+
const productionConfig = architect.server.configurations.production;
149+
expect(productionConfig.fileReplacements).toBeDefined();
150+
expect(productionConfig.sourceMap).toBeDefined();
151+
expect(productionConfig.optimization).toBeDefined();
152+
});
138153
});

modules/hapi-engine/schematics/install/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function updateConfigFile(options: UniversalOptions) {
121121
const clientProject = workspace.projects.get(options.clientProject);
122122
if (clientProject) {
123123
const buildTarget = clientProject.targets.get('build');
124-
const serverTarget = clientProject.targets.get('build');
124+
const serverTarget = clientProject.targets.get('server');
125125

126126
// We have to check if the project config has a server target, because
127127
// if the Universal step in this schematic isn't run, it can't be guaranteed
@@ -130,23 +130,13 @@ function updateConfigFile(options: UniversalOptions) {
130130
return;
131131
}
132132

133-
serverTarget.configurations = {
134-
production: {
135-
fileReplacements: [
136-
{
137-
replace: 'src/environments/environment.ts',
138-
with: 'src/environments/environment.prod.ts'
139-
}
140-
]
141-
}
142-
};
143-
144133
serverTarget.options = {
145134
...serverTarget.options,
146135
outputPath: SERVER_DIST,
147136
};
148137

149138
buildTarget.options = {
139+
...buildTarget.options,
150140
outputPath: BROWSER_DIST,
151141
};
152142
}

0 commit comments

Comments
 (0)