Skip to content
Open
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
11 changes: 6 additions & 5 deletions packages/schematics/angular/environments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`),
);
}

Expand Down Expand Up @@ -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.',
);
}
Expand Down
44 changes: 44 additions & 0 deletions packages/schematics/angular/environments/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
});
});
Loading