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(js): add --includeBabelRc
flag for @nrwl/js:library generator (#8793, #8600)
#10055
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
E2E seems to have passed correctly: https://app.circleci.com/pipelines/github/nrwl/nx/17064/workflows/ee98bcea-88f3-4640-90cc-7220d6f1eb80/jobs/168611 However there is a timeout in the It seems I don't have permission to re-run the pipeline, so will wait for some input about my PR before pushing a reset commit :) |
@floroz Thank you for your contribution. I'm wondering if this is more suitable under a flag in the generator schema instead of making it the default. If I was just building a CLI with different buildable js libs, I wouldn't need |
Hey @nartc thanks for your feedback! I guess having the option for a flag would make sense, however, I would argue that the flag should only be used to disable the creation of the It is a far more common use case to create an NX library within a workspace for consumption within other web-apps, and I feel having to ask developers to remember to add a flag, without which they would not be able to bundle their app, could still create friction.
|
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.
Just one quick question
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.
LGTM
Edit: I dismissed the review as I think we can make it a little less awkward for people who don't use/care about babel (web)
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.
guard the PR from being merged prematurely
I wanted to take some time to investigate the issue a bit more in-depth, before jumping to another implementation. SetupI have created this repository to reproduce the issue. The repo contains 5 NX workspaces (using the latest NX package version) and each of them contains an application, and a Each application has been generated through its corresponding NX CLI (
Testing the compilation of each application
For the React application, we encounter the error highlighted in the open issues: ERROR in ../../libs/my-lib/src/lib/my-lib.ts
Module build failed (from ../../node_modules/@nrwl/web/src/utils/web-babel-loader.js):
SyntaxError: /Users/danieletortora/Repository/nrwl-js-babel-config/react/libs/my-lib/src/lib/my-lib.ts: Missing semicolon. (1:4)
> 1 | type Custom = void;
| ^
2 |
3 | export function myLib(): Custom {
4 | console.log('my-lib hello world');
at instantiate (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:72:32)
at constructor (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:358:12)
at Parser.raise (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:3335:19)
at Parser.semicolon (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:3996:10)
at Parser.parseExpressionStatement (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:15134:10)
at Parser.parseStatementContent (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:14681:19)
at Parser.parseStatement (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:14533:17)
at Parser.parseBlockOrModuleBlockBody (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:15176:25)
at Parser.parseBlockBody (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:15167:10)
at Parser.parseProgram (/Users/danieletortora/Repository/nrwl-js-babel-config/react/node_modules/@babel/parser/lib/index.js:14451:10) ConclusionIt's interesting to notice that
@nartc it's starting to look like the issue is within the What do you think? |
Thanks for digging in @floroz. Out of all 5 cases you're testing, only
That said, I think checking for |
--includeBabelRc
flag for @nrwl/js:library generator (#8793, #8600)
* You can find more details on why this is necessary here: | ||
* https://github.com/nrwl/nx/pull/10055 | ||
*/ | ||
function shouldAddBabelRc(tree: Tree, options: NormalizedSchema) { |
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.
question: what if I have nrwl/web
installed and I want to generate a nrwl/js:lib
BUT I do not want to have .babelrc
generated by explicitly use --includeBabelRc=false
?
Thinking of a monorepo with both web
and an api
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.
@nartc good point, I just pushed a refactor and added unit tests to cover that scenario, so that now we correctly handle
- user explicitly setting the flag to
true
- user explicitly setting the flag to
false
- user not setting the flag
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.
You can just remove the default
in the schema and it will come through as undefined
(as long as the flag isn't in the required
array in the schema)
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.
LGTM! Thank you for your contribution
forgot a typo in a test name and did quick amend 😄 |
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. |
Current Behavior
When generating a new TypeScript library using
@nrwl/js:library
and not using swc, a.babelrc
configuration is not generated by default.This behaviour conflicts when importing such libraries within application that require the compilation step to have occurred, throwing errors for unsupported syntax (TS syntax when expecting JS).
Expected Behavior
With this PR, the new
--includeBabelRc
flag is introduced when using the@nrwl/js:library
generator.swc
as compiler, this flag won't affect the output..babelrc
.babelrc
@nrwl/web
installed, and if so, automatically generates a.babelrc
for your new libraryRelated Issue(s)
Fixes #8600
Fixes #8793