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
Optionally output eager es modules #2781
Conversation
Hi @josephsavona. What do you think about this change? |
0078c6f
to
b18b721
Compare
Hi @kassens Could you take look? |
This will be very useful for people who use |
6e81bfd
to
84558cc
Compare
PR resolves the following issue: #2445 P.S.: I linked the related issue to help people like me find a solution and of course would be great to get this feature accepted. |
84558cc
to
e8e1542
Compare
Friendly ping @kassens @josephsavona |
/cc @jstejada |
Any update on this? |
@kassens Do you mind to review this PR? Any changes required to move it forward? |
This would be a really great addition. |
I just published this feature under |
Inspired by: - facebook/relay#2445 - facebook/relay#2781 - facebook/relay#2841 kiwicom-source-id: a0181e85ec323a361502ef8275739cf18ef114ac
Inspired by: - facebook/relay#2445 - facebook/relay#2781 - facebook/relay#2841 kiwicom-source-id: a0181e85ec323a361502ef8275739cf18ef114ac
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.
@jstejada has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Hi @jstejada. Any news on this? Do you want me to assist with something? |
Friendly ping @jstejada |
I would like to release v8, but need to resolve conflicts first, it is quite complex now after so radical changes. @TrySound can you please update your PR (rebase on master)? |
im out of computer til 5 jan, sorry |
Just released @frenzzy/babel-plugin-relay |
dd89233
to
4388788
Compare
I have two problem which can be solved with this change 1. Rollup handles only es modules. To handle commonjs there is a plugin which converts it into esm. Though it always skips module if import/export statements are found. As a result I get runtime error: "require is not defined". To workaround this I wrote custom plugin. Though it would be cool to have proper solution out of the box. ```js { name: 'relay-generated', transform(code) { // convert __generated__ requires into imports // remove after relay-compiler will be able to emit esm if (code.includes('__generated__')) { let i = -1; const paths = []; const processed = code.replace( /require\((.+__generated__.+)\)/g, (req, pathString) => { i += 1; paths.push(pathString); return `__generated__${i}`; }, ); const imports = paths.map( (p, i) => `import __generated__${i} from ${p};\n`, ); return { code: imports.join('') + processed, }; } }, }, ``` 2. Another problem is flow bug (facebook/flow#7444) which treats all not existent types as any. This leads to many type unsafe places. ```js import type {NotExistentType} from './__generated__/MyQuery.graphql'; type Props = {| my: NotExistentType |} ```
4388788
to
05f4b02
Compare
@jstejada @kassens @alunyov @josephsavona I updated esm output considering recent thunks removal. Tests are much smaller now too. |
Friendly ping @jstejada @kassens @josephsavona |
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.
@tyao1 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Yay! |
Summary: In this PR I added `eagerESModules` option to `relay-runtime` and `babel-plugin-relay`. I have two problem which can be solved with this change 1. Rollup handles only es modules. To handle commonjs there is a plugin which converts it into esm. Though it always skips module if import/export statements are found. As a result I get runtime error: "require is not defined". To workaround this I wrote custom plugin. Though it would be cool to have proper solution out of the box. ```js { name: 'relay-generated', transform(code) { // convert __generated__ requires into imports // remove after relay-compiler will be able to emit esm if (code.includes('__generated__')) { let i = -1; const paths = []; const processed = code.replace( /require\((.+__generated__.+)\)/g, (req, pathString) => { i += 1; paths.push(pathString); return `__generated__${i}`; }, ); const imports = paths.map( (p, i) => `import __generated__${i} from ${p};\n`, ); return { code: imports.join('') + processed, }; } }, }, ``` 2. Another problem is flow bug (facebook/flow#7444) which treats all not existent types as any. This leads to many type unsafe places. ```js import type {NotExistentType} from './__generated__/MyQuery.graphql'; type Props = {| my: NotExistentType |} ``` Pull Request resolved: #2781 Reviewed By: jstejada Differential Revision: D17385417 Pulled By: tyao1 fbshipit-source-id: dfa031412666b8afcac4cbae4678f64abbbe5ec9
In this PR I added
eagerESModules
option torelay-runtime
andbabel-plugin-relay
. I have two problem which can be solved with this changewhich converts it into esm. Though it always skips module if
import/export statements are found. As a result I get runtime error:
"require is not defined".
To workaround this I wrote custom plugin. Though it would be cool to
have proper solution out of the box.
This leads to many type unsafe places.