Skip to content

Commit 32dd079

Browse files
MeAkibclydin
authored andcommitted
fix(@schematics/angular): correct error and warning messages in environments schematic
The error for non-application projects concatenated the first sentence with the project type before evaluating the ternary, so the "Only application project types are supported" sentence was never printed and projects without a `projectType` were reported as having a "projectType" of "undefined". The third-party `server` builder warning also printed the `build` target's builder instead of the `server` target's builder. Wrap the ternary in parentheses, use the `server` target's builder in the warning, and fix the typos in both error messages.
1 parent 41b54ec commit 32dd079

2 files changed

Lines changed: 50 additions & 5 deletions

File tree

‎packages/schematics/angular/environments/index.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ export default function (options: EnvironmentOptions): Rule {
1919
return updateWorkspace((workspace) => {
2020
const project = workspace.projects.get(options.project);
2121
if (!project) {
22-
throw new SchematicsException(`Project name "${options.project}" doesn't not exist.`);
22+
throw new SchematicsException(`Project name "${options.project}" does not exist.`);
2323
}
2424

2525
const type = project.extensions['projectType'];
2626
if (type !== 'application') {
2727
return log(
2828
'error',
29-
'Only application project types are support by this schematic.' + type
30-
? ` Project "${options.project}" has a "projectType" of "${type}".`
31-
: ` Project "${options.project}" has no "projectType" defined.`,
29+
'Only application project types are supported by this schematic.' +
30+
(type
31+
? ` Project "${options.project}" has a "projectType" of "${type}".`
32+
: ` Project "${options.project}" has no "projectType" defined.`),
3233
);
3334
}
3435

@@ -89,7 +90,7 @@ function* generateConfigurationEnvironments(
8990
if (serverTarget && serverTarget.builder !== AngularBuilder.Server) {
9091
yield log(
9192
'warn',
92-
`"server" target found for project "${projectName}" has a third-party builder "${buildTarget.builder}".` +
93+
`"server" target found for project "${projectName}" has a third-party builder "${serverTarget.builder}".` +
9394
' The generated project options may not be compatible with this builder.',
9495
);
9596
}

‎packages/schematics/angular/environments/index_spec.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,48 @@ describe('Environments Schematic', () => {
192192
}),
193193
);
194194
});
195+
196+
it('should log an error for non-application projects', async () => {
197+
const config = JSON.parse(applicationTree.readContent('/angular.json'));
198+
config.projects.foo.projectType = 'library';
199+
applicationTree.overwrite('/angular.json', JSON.stringify(config, undefined, 2));
200+
201+
const logs: string[] = [];
202+
const loggerSubscription = schematicRunner.logger.subscribe(({ message }) =>
203+
logs.push(message),
204+
);
205+
206+
try {
207+
await runEnvironmentsSchematic();
208+
} finally {
209+
loggerSubscription.unsubscribe();
210+
}
211+
212+
expect(logs).toEqual([
213+
'Only application project types are supported by this schematic.' +
214+
' Project "foo" has a "projectType" of "library".',
215+
]);
216+
});
217+
218+
it('should log the builder of a third-party server target', async () => {
219+
const config = JSON.parse(applicationTree.readContent('/angular.json'));
220+
config.projects.foo.architect.server = { builder: 'custom:server' };
221+
applicationTree.overwrite('/angular.json', JSON.stringify(config, undefined, 2));
222+
223+
const logs: string[] = [];
224+
const loggerSubscription = schematicRunner.logger.subscribe(({ message }) =>
225+
logs.push(message),
226+
);
227+
228+
try {
229+
await runEnvironmentsSchematic();
230+
} finally {
231+
loggerSubscription.unsubscribe();
232+
}
233+
234+
expect(logs).toContain(
235+
'"server" target found for project "foo" has a third-party builder "custom:server".' +
236+
' The generated project options may not be compatible with this builder.',
237+
);
238+
});
195239
});

0 commit comments

Comments
 (0)