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 workspace = await getWorkspace(host);
const project = workspace.projects.get(options.project as string); 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); options.path = buildDefaultPath(project);
} }

View File

@ -110,7 +110,7 @@ export default function (options: DirectiveOptions): Rule {
const workspace = await getWorkspace(host); const workspace = await getWorkspace(host);
const project = workspace.projects.get(options.project as string); const project = workspace.projects.get(options.project as string);
if (!project) { if (!project) {
throw new SchematicsException(`Invalid project name (${options.project})`); throw new SchematicsException(`Project "${options.project}" does not exist.`);
} }
if (options.path === undefined) { if (options.path === undefined) {

View File

@ -179,7 +179,7 @@ export default function (options: LibraryOptions): Rule {
commonModule: false, commonModule: false,
flat: true, flat: true,
path: sourceDir, path: sourceDir,
project: options.name, project: projectName,
}), }),
schematic('component', { schematic('component', {
name: options.name, name: options.name,
@ -189,13 +189,13 @@ export default function (options: LibraryOptions): Rule {
flat: true, flat: true,
path: sourceDir, path: sourceDir,
export: true, export: true,
project: options.name, project: projectName,
}), }),
schematic('service', { schematic('service', {
name: options.name, name: options.name,
flat: true, flat: true,
path: sourceDir, path: sourceDir,
project: options.name, project: projectName,
}), }),
options.lintFix ? applyLintFix(sourceDir) : noop(), options.lintFix ? applyLintFix(sourceDir) : noop(),
(_tree: Tree, context: SchematicContext) => { (_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 workspace = await getWorkspace(tree);
const project = workspace.projects.get(projectName); const project = workspace.projects.get(projectName);
if (!project) { if (!project) {
throw new Error('Specified project does not exist.'); throw new Error(`Project "${projectName}" does not exist.`);
} }
return buildDefaultPath(project); return buildDefaultPath(project);