Skip to content

fix(@schematics/angular): show better error when non existing project is passed to the component schematic #21007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2021
Merged
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
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