Skip to content

Commit b36c0c9

Browse files
committed
fix(@schematics/angular): show better error when non existing project is passed to the component schematic
Closes: #21003 (cherry picked from commit 7cd801e)
1 parent b8c5d56 commit b36c0c9

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

packages/schematics/angular/component/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ export default function (options: ComponentOptions): Rule {
116116
const workspace = await getWorkspace(host);
117117
const project = workspace.projects.get(options.project as string);
118118

119-
if (options.path === undefined && project) {
119+
if (!project) {
120+
throw new SchematicsException(`Project "${options.project}" does not exist.`);
121+
}
122+
123+
if (options.path === undefined) {
120124
options.path = buildDefaultPath(project);
121125
}
122126

packages/schematics/angular/directive/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default function (options: DirectiveOptions): Rule {
110110
const workspace = await getWorkspace(host);
111111
const project = workspace.projects.get(options.project as string);
112112
if (!project) {
113-
throw new SchematicsException(`Invalid project name (${options.project})`);
113+
throw new SchematicsException(`Project "${options.project}" does not exist.`);
114114
}
115115

116116
if (options.path === undefined) {

packages/schematics/angular/library/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export default function (options: LibraryOptions): Rule {
179179
commonModule: false,
180180
flat: true,
181181
path: sourceDir,
182-
project: options.name,
182+
project: projectName,
183183
}),
184184
schematic('component', {
185185
name: options.name,
@@ -189,13 +189,13 @@ export default function (options: LibraryOptions): Rule {
189189
flat: true,
190190
path: sourceDir,
191191
export: true,
192-
project: options.name,
192+
project: projectName,
193193
}),
194194
schematic('service', {
195195
name: options.name,
196196
flat: true,
197197
path: sourceDir,
198-
project: options.name,
198+
project: projectName,
199199
}),
200200
options.lintFix ? applyLintFix(sourceDir) : noop(),
201201
(_tree: Tree, context: SchematicContext) => {

packages/schematics/angular/utility/workspace.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function createDefaultPath(tree: Tree, projectName: string): Promis
8585
const workspace = await getWorkspace(tree);
8686
const project = workspace.projects.get(projectName);
8787
if (!project) {
88-
throw new Error('Specified project does not exist.');
88+
throw new Error(`Project "${projectName}" does not exist.`);
8989
}
9090

9191
return buildDefaultPath(project);

0 commit comments

Comments
 (0)