Skip to content

Commit b91ba17

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): Restrict some schematics to type of application
fixes angular#789
1 parent 3ba2580 commit b91ba17

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

packages/angular/pwa/pwa/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Path, join } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
12+
SchematicsException,
1213
Tree,
1314
apply,
1415
branchAndMerge,
@@ -36,6 +37,9 @@ export default function (options: PwaOptions): Rule {
3637
return (host: Tree, context: SchematicContext) => {
3738
const workspace = getWorkspace(host);
3839
const project = workspace.projects[options.project];
40+
if (project.projectType !== 'application') {
41+
throw new SchematicsException(`PWA requires a project type of "application".`);
42+
}
3943

4044
const assetPath = join(project.root as Path, 'src', 'assets');
4145

packages/schematics/angular/app-shell/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ function validateProject(options: AppShellOptions): Rule {
144144
const routerOutletCheckRegex = /<router\-outlet.*?>([\s\S]*?)<\/router\-outlet>/;
145145

146146
const clientProject = getClientProject(host, options);
147+
if (clientProject.projectType !== 'application') {
148+
throw new SchematicsException(`App shell requires a project type of "application".`);
149+
}
147150
const componentPath = getBootstrapComponentPath(host, clientProject);
148151
const tmpl = getComponentTemplateInfo(host, componentPath);
149152
const template = getComponentTemplate(host, componentPath, tmpl);

packages/schematics/angular/service-worker/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ export default function (options: ServiceWorkerOptions): Rule {
232232
if (!project) {
233233
throw new SchematicsException(`Invalid project name (${options.project})`);
234234
}
235+
if (project.projectType !== 'application') {
236+
throw new SchematicsException(`Service worker requires a project type of "application".`);
237+
}
235238

236239
const templateSource = apply(url('./files'), [
237240
template({...options}),

packages/schematics/angular/universal/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ function getTsConfigOutDir(host: Tree, architect: experimental.workspace.Workspa
208208
export default function (options: UniversalOptions): Rule {
209209
return (host: Tree, context: SchematicContext) => {
210210
const clientProject = getClientProject(host, options);
211+
if (clientProject.projectType !== 'application') {
212+
throw new SchematicsException(`Universal requires a project type of "application".`);
213+
}
211214
const clientArchitect = getClientArchitect(host, options);
212215
const outDir = getTsConfigOutDir(host, clientArchitect);
213216
const tsConfigExtends = basename(clientArchitect.build.options.tsConfig);

0 commit comments

Comments
 (0)