Skip to content

fix(@schematics/angular): generate valid artifact names for any entry-point name - #34739

Open
MeAkib wants to merge 2 commits into
angular:mainfrom
MeAkib:fix/entry-point-name-validation
Open

MeAkib wants to merge 2 commits into
angular:mainfrom
MeAkib:fix/entry-point-name-validation

Conversation

@MeAkib

@MeAkib MeAkib commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

The entry-point schematic accepts any name that is a valid npm export subpath, but the final path segment is also used to name the generated class, selector, and source files. A segment that cannot be used that way fails deep inside the component schematic with an error about something the user never provided: ng generate entry-point 3d fails with 'Selector "lib-3d" is invalid.' and ng generate entry-point svg~icons fails with a raw schema validation dump of the internal component options.

Validate the final path segment up front and report the entry point name together with the allowed shape. Dots remain supported, as classify removes them when deriving the class name ('testing.v2' generates the class TestingV2); a test now covers that case to keep it working.

…criptive error

The entry-point schematic accepts any name that is a valid npm export
subpath, but the final path segment is also used to name the generated
class, selector, and source files. A segment that cannot be used that
way fails deep inside the component schematic with an error about
something the user never provided: `ng generate entry-point 3d` fails
with 'Selector "lib-3d" is invalid.' and `ng generate entry-point
svg~icons` fails with a raw schema validation dump of the internal
component options.

Validate the final path segment up front and report the entry point
name together with the allowed shape. Dots remain supported, as
`classify` removes them when deriving the class name ('testing.v2'
generates the class `TestingV2`); a test now covers that case to keep
it working.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces validation for the entry point name in the Angular entry-point schematic. It ensures that the final path segment of the entry point name is a valid identifier (starting with a letter and containing only alphanumeric characters, dots, dashes, and underscores) to prevent downstream failures when naming generated source files. Additionally, unit tests have been added to verify both the error handling for invalid names and the acceptance of valid names containing dots. No review comments were provided, and the changes look solid and well-tested.

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these are valid entry-point names; the bug lies in the artifactName generation.

@MeAkib MeAkib changed the title fix(@schematics/angular): report invalid entry point names with a descriptive error fix(@schematics/angular): generate valid artifact names for any entry-point name Nov 17, 2026
@MeAkib

MeAkib commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

All of these are valid entry-point names; the bug lies in the artifactName generation.

Thanks — reworked in the latest commit. Instead of rejecting these names, the schematic now derives a usable artifact name from them, while the exports entry and directory keep the original name:

  • ~ and / are replaced with dashes: svg~icons → class SvgIcons, selector lib-svg-icons, exports ./svg~icons.
  • A digit-led word is merged into the preceding word, since a class cannot start with a digit and validateHtmlSelector rejects digit-led segments (lib-foo-3d): feature/3d → Feature3d / lib-feature3d. All-digit words stay separate, so foo-2 still generates Foo2 / lib-foo-2 as today.
  • When the final segment alone cannot start the name with a letter, the full name and then the project prefix are used as the basis: 3d → Lib3d / lib-lib3d.

Happy to adjust the fallback naming if you'd prefer a different shape.

@MeAkib
MeAkib requested a review from alan-agius4 November 17, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants