diff --git a/packages/schematics/angular/environments/index.ts b/packages/schematics/angular/environments/index.ts index 7082689c3348..f32bb850ed3d 100644 --- a/packages/schematics/angular/environments/index.ts +++ b/packages/schematics/angular/environments/index.ts @@ -19,16 +19,17 @@ export default function (options: EnvironmentOptions): Rule { return updateWorkspace((workspace) => { const project = workspace.projects.get(options.project); if (!project) { - throw new SchematicsException(`Project name "${options.project}" doesn't not exist.`); + throw new SchematicsException(`Project name "${options.project}" does not exist.`); } const type = project.extensions['projectType']; if (type !== 'application') { return log( 'error', - 'Only application project types are support by this schematic.' + type - ? ` Project "${options.project}" has a "projectType" of "${type}".` - : ` Project "${options.project}" has no "projectType" defined.`, + 'Only application project types are supported by this schematic.' + + (type + ? ` Project "${options.project}" has a "projectType" of "${type}".` + : ` Project "${options.project}" has no "projectType" defined.`), ); } @@ -89,7 +90,7 @@ function* generateConfigurationEnvironments( if (serverTarget && serverTarget.builder !== AngularBuilder.Server) { yield log( 'warn', - `"server" target found for project "${projectName}" has a third-party builder "${buildTarget.builder}".` + + `"server" target found for project "${projectName}" has a third-party builder "${serverTarget.builder}".` + ' The generated project options may not be compatible with this builder.', ); } diff --git a/packages/schematics/angular/environments/index_spec.ts b/packages/schematics/angular/environments/index_spec.ts index d53026a28a4d..49a249cef715 100644 --- a/packages/schematics/angular/environments/index_spec.ts +++ b/packages/schematics/angular/environments/index_spec.ts @@ -192,4 +192,48 @@ describe('Environments Schematic', () => { }), ); }); + + it('should log an error for non-application projects', async () => { + const config = JSON.parse(applicationTree.readContent('/angular.json')); + config.projects.foo.projectType = 'library'; + applicationTree.overwrite('/angular.json', JSON.stringify(config, undefined, 2)); + + const logs: string[] = []; + const loggerSubscription = schematicRunner.logger.subscribe(({ message }) => + logs.push(message), + ); + + try { + await runEnvironmentsSchematic(); + } finally { + loggerSubscription.unsubscribe(); + } + + expect(logs).toEqual([ + 'Only application project types are supported by this schematic.' + + ' Project "foo" has a "projectType" of "library".', + ]); + }); + + it('should log the builder of a third-party server target', async () => { + const config = JSON.parse(applicationTree.readContent('/angular.json')); + config.projects.foo.architect.server = { builder: 'custom:server' }; + applicationTree.overwrite('/angular.json', JSON.stringify(config, undefined, 2)); + + const logs: string[] = []; + const loggerSubscription = schematicRunner.logger.subscribe(({ message }) => + logs.push(message), + ); + + try { + await runEnvironmentsSchematic(); + } finally { + loggerSubscription.unsubscribe(); + } + + expect(logs).toContain( + '"server" target found for project "foo" has a third-party builder "custom:server".' + + ' The generated project options may not be compatible with this builder.', + ); + }); });