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

Add undefined export definitions to make rollup happy #1300

Closed
wants to merge 1 commit into from

Conversation

gaberudy
Copy link

To fix #1293

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@acoreyj
Copy link

acoreyj commented Mar 28, 2018

Can confirm this fixes my issue with using graphql and rollup (as part of Stenciljs project)

@gaberudy
Copy link
Author

@acoreyj I'm curious if you also had this issue (which I can't tell whether its a problem with graphql, rollup or the rollup-commonjs-plugin):

rollup/rollup#1859

@acoreyj
Copy link

acoreyj commented Mar 28, 2018

@gaberudy

Hmm no I haven't had that issue in my project

Copy link
Contributor

@leebyron leebyron left a comment

Choose a reason for hiding this comment

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

The npm branch is automatically maintained as the compiled output of the source master branch. Please make changes against the master branch.

@gaberudy
Copy link
Author

@leebyron that may be the case, but the transpiling is incorrect in this case.

For some reason, the validation sub-module gets correct codegen (that's what I used as a template to fix the other sub-modules).

My only guess is that it pulls in a default import, which may anchor the transpiler to enumerate in that scope all the export variables instead of doing just the Object.defineProperty on them.

I suspect that:

import ValidationContext from './ValidationContext';

Maybe be responsible for having the correct transpiled code. Not sure if there is a way to fake this in the other sub-modules..

@leebyron
Copy link
Contributor

I'm not sure I understand why the compiled output is incorrect - do you have a test case that fails when loading it in? In the node repl I can require the module and submodules and get access to all exported values.

I believe Babel adds additional code to the validation submodule due to require statements being interleaved in the result. The additional code just initializes the export as undefined before the call to Object.defineProperty in case any interleaved require statement happens to cause a circular require, then the property will be defined on the exported object. The submodules that don't have this pattern don't have that additional code since the property cannot be accessed before Object.defineProperty. If I recall, Babel v7 changed that behavior slightly - so we may expect the compiled output to change when adopting Babel v7, however the runtime behavior should be identical.

@gaberudy
Copy link
Author

Yea, I see it's a what you are saying ,and man, your knowledge of Babel internal transpiling behavior is impressive.

Anyway, this shouldn't be accepted, and hopefully the rollup upstream maintainers see the shiny new way of the mjs side-by-side modules definitions and then dealing with the transpiled files becomes mute.

@gaberudy gaberudy closed this Mar 30, 2018
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.

None yet

4 participants