Skip to content

Commit

Permalink
fix(@schematics/angular): show better error when non existing project…
Browse files Browse the repository at this point in the history
… is passed to the component schematic

Closes: #21003
(cherry picked from commit 7cd801e)
  • Loading branch information
alan-agius4 committed Jun 2, 2021
1 parent b8c5d56 commit b36c0c9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/schematics/angular/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ export default function (options: ComponentOptions): Rule {
const workspace = await getWorkspace(host);
const project = workspace.projects.get(options.project as string);

if (options.path === undefined && project) {
if (!project) {
throw new SchematicsException(`Project "${options.project}" does not exist.`);
}

if (options.path === undefined) {
options.path = buildDefaultPath(project);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function (options: DirectiveOptions): Rule {
const workspace = await getWorkspace(host);
const project = workspace.projects.get(options.project as string);
if (!project) {
throw new SchematicsException(`Invalid project name (${options.project})`);
throw new SchematicsException(`Project "${options.project}" does not exist.`);
}

if (options.path === undefined) {
Expand Down
6 changes: 3 additions & 3 deletions packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default function (options: LibraryOptions): Rule {
commonModule: false,
flat: true,
path: sourceDir,
project: options.name,
project: projectName,
}),
schematic('component', {
name: options.name,
Expand All @@ -189,13 +189,13 @@ export default function (options: LibraryOptions): Rule {
flat: true,
path: sourceDir,
export: true,
project: options.name,
project: projectName,
}),
schematic('service', {
name: options.name,
flat: true,
path: sourceDir,
project: options.name,
project: projectName,
}),
options.lintFix ? applyLintFix(sourceDir) : noop(),
(_tree: Tree, context: SchematicContext) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/utility/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function createDefaultPath(tree: Tree, projectName: string): Promis
const workspace = await getWorkspace(tree);
const project = workspace.projects.get(projectName);
if (!project) {
throw new Error('Specified project does not exist.');
throw new Error(`Project "${projectName}" does not exist.`);
}

return buildDefaultPath(project);
Expand Down

0 comments on commit b36c0c9

Please sign in to comment.