-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Define regeneratorRuntime globally as a side-effect, again. #369
Conversation
In #353, I simplified the implementation of regenerator-runtime by converting runtime.js to a normal CommonJS module. No more global object detection, and no more sneaky capture/deletion of regeneratorRuntime. Unfortunately, folks who use only @babel/polyfill and not @babel/transform-runtime may have existing code that relies on a global regeneratorRuntime variable. That code will eventually disappear (:crossed-fingers:), but in the meantime we can continue supporting it by simply ensuring that regeneratorRuntime is defined globally as a side-effect of importing regenerator-runtime. This turns out to be much easier than detecting the global object, as long as runtime.js runs as a non-strict CommonJS module. See my code comments for another fallback solution that should cover all remaining cases. Background discussion: babel/babel#7646 (comment) Fixes #363. Fixes #337. Fixes #367.
@@ -10,6 +10,7 @@ | |||
"generator", | |||
"async" | |||
], | |||
"sideEffects": true, |
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 is to keep Webpack from removing import … from "regenerator-runtime"
, since the package now has an important side-effect.
I can't understand, why you against simple global object detection like this? With this code, you will have fewer issues than with code from this PR - now someone definitely will try to load it in strict mode. |
You're throwing around words like "simple" and "definitely" based on your intuition, and I think you reasoning may be biased because you have your own implementation. I prefer this approach because it doesn't involve obtaining a reference to the global object. I've been down that road before (e.g. #336), and I don't care to go there again. All the identifiers you're checking in If someone happens to load this code in strict mode, that's fine. It will fall back to If you're wondering why I didn't just depend on |
It's based on the experience of support modules which need the same functionality and many issues in the
And will cause a CSP issue in strict mode.
I understand it and I do not insist - This PR is a solution to my issue, but I told about global object since just wanted to prevent some future issues. |
With this change, I think we should go back to having two versions: What if we turned it around?
Usage:
|
@OurMajesty That's right, I didn't want people updating to this version accidentally before we were sure the changes worked. @MattiasBuelens With that solution, I would be worried that people would end up bundling both |
Well, the documentation for
Sure, an extra global variable doesn't matter when you're bundling a web app. However, if you're bundling a web library, and users use your library inside their own web app that uses Of course, in this case there's also the problem of bundling the runtime twice (once in the library, once in the app), so I guess library developers should recommend their users to bundle the library's dependencies themselves...? 😕 Either way, I understand you don't want to risk bundling the runtime twice. I think it's unfortunate for library developers, but I guess that's the trade-off we have to make. |
@benjamn could you publish a release with those changes as |
Well, Babel downloads the correct version anyway because it uses |
@nicolo-ribaudo I mean the case of separate usage of |
I just set 0.13.2 to be npm dist-tag add regenerator-runtime@0.13.2 latest The |
Seeing a lot of: _Object$defineProperty is not a function Scanning the release notes: https://github.com/babel/babel/releases This one stands out: https://github.com/babel/babel/releases/tag/v7.4.0 Specifically, "Update to core-js@3": babel/babel#7646 There are 133 comments which I confess to not having read, and various offshoots to places like: babel/babel#9442 and: facebook/regenerator#369 I did find this enormous update doc, but haven't found the answer in there yet and the Babel docs themselves don't appear to have been updated: https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md Although this blog post is briefer and covers a few things: https://babeljs.io/blog/2019/03/19/7.4.0 In the end the build works if I get rid of `@babel/plugin-transform-runtime`, which doesn't seem to play too well in conjunction with `@babel/preset-env`, at least in this set-up.
facebook/regenerator#369 hopefully this doesn't bite us
In #353, I simplified the implementation of
regenerator-runtime
by convertingruntime.js
to a normal CommonJS module. No more global object detection, and no more sneaky capture/deletion ofregeneratorRuntime
.Unfortunately, folks who use only
@babel/polyfill
and not@babel/transform-runtime
may have existing code that relies on a globalregeneratorRuntime
variable. That code will eventually disappear (🤞), but in the meantime we can continue supporting it by simply ensuring thatregeneratorRuntime
is defined globally as a side-effect of importingregenerator-runtime
.This turns out to be much easier than detecting the global object, as long as
runtime.js
runs as a non-strict CommonJS module. See my code comments for another fallback solution that should cover all remaining cases.Background discussion: babel/babel#7646 (comment)
Fixes #363.
Fixes #337.
Fixes #367.