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

Closes: #21003
This commit is contained in:
Alan Agius 2021-06-01 10:24:35 +02:00
parent f9657bc919
commit 7cd801eb06
4 changed files with 10 additions and 6 deletions

View File

@ -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);
}

View File

@ -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) {

View File

@ -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,
@ -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) => {

View File

@ -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);