-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(devkit): prefer strings over Linter enum #27209
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 6db094f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 5 targets
Sent with 💌 from NxCloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me. It makes the generators more straightforward to extend.
We'll need to make a similar change in many other generators from other plugins, and we probably want to deprecate the Linter
enum. Could you expand this PR with those changes? Let me know if you're busy with other things and I can help.
a01f75f
to
b47c47d
Compare
8334476
to
a13bf49
Compare
We should be consistent about how options are defined in our plugins. Currently, there are some options that use `enum`s and some that use typed strings. I think typed strings are preferable because someone extending a generator only needs to import the main generator that they're extending, not all the transitive dependencies of that generator. Current extending code: ``` // ... import { applicationGenerator as reactApplicationGenerator } from '@nx/react'; import { Linter } from '@nx/eslint'; export async function applicationGenerator( tree: Tree, options: ApplicationGeneratorSchema ) { reactApplicationGenerator(tree, { ...options, linter: Linter.EsLint, }); } ``` Desired extending code: ``` // ... import { applicationGenerator as reactApplicationGenerator } from '@nx/react'; export async function applicationGenerator( tree: Tree, options: ApplicationGeneratorSchema ) { reactApplicationGenerator(tree, { ...options, linter: 'eslint', }); } ``` The problem is not just an extra line of code, the person extending the `reactApplicationGenerator` has to dig into the implementation details of the generator itself in order to know where to find the `Linter` enum. The `e2eTestRunner` is already a typed string and is easily extended. The solution I'm proposing in this PR would define a typed string in the same file as the existing enum. None of the implementations need to change. No community plugin code will be broken. (cherry picked from commit 839dc15)
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
We should be consistent about how options are defined in our plugins. Currently, there are some options that use
enum
s and some that use typed strings. I think typed strings are preferable because someone extending a generator only needs to import the main generator that they're extending, not all the transitive dependencies of that generator.Current extending code:
Desired extending code:
The problem is not just an extra line of code, the person extending the
reactApplicationGenerator
has to dig into the implementation details of the generator itself in order to know where to find theLinter
enum. Thee2eTestRunner
is already a typed string and is easily extended.The solution I'm proposing in this PR would define a typed string in the same file as the existing enum. None of the implementations need to change. No community plugin code will be broken.