Skip to content
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

fix(angular): throw error when npmScope is incorrect #10366

Merged
merged 2 commits into from
May 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/angular/src/generators/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,20 @@ export function normalizePrefix(
// https://github.com/angular/angular-cli/blob/1c634cd327e5a850553b258aa2d5e6a6b2c75c65/packages/schematics/angular/component/index.ts#L130
const htmlSelectorRegex =
/^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/;
return npmScope && htmlSelectorRegex.test(npmScope) ? npmScope : undefined;
const normalizedPrefix =
npmScope && htmlSelectorRegex.test(npmScope) ? npmScope : undefined;

if (!normalizedPrefix) {
throw new Error(`The "--prefix" option was not provided, therefore attempted to use the "npmScope" defined in "nx.json" to set the application's selector prefix, but it is invalid.

There are two options that can be followed to resolve this issue:
- Pass a valid "--prefix" option.
- Update the "npmScope" in "nx.json" (Note: this can be an involved process, as other libraries and applications may need to be updated to match the new scope).

If you encountered this error when creating a new Nx Workspace, the workspace name or "npmScope" is invalid to use as the selector prefix for the application being generated.

Valid selector prefixes must start with a letter, and must contain only alphanumeric characters or dashes. When adding a dash the segment after the dash must also start with a letter.`);
}

return normalizedPrefix;
Coly010 marked this conversation as resolved.
Show resolved Hide resolved
}