Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Convert runtime.js to a normal CommonJS module. #353

Merged
merged 3 commits into from
Aug 7, 2018
Merged

Conversation

benjamn
Copy link
Contributor

@benjamn benjamn commented Aug 3, 2018

If this works, then it removes the need for hacks to discover the global object, which continues to be problematic (e.g. #336, #346).

Importantly, the regenerator-runtime/runtime.js module can still be evaluated as a non-CJS script, and it will not pollute the global scope except for defining regeneratorRuntime.

benjamn added 3 commits August 3, 2018 15:41
If this works, then it removes the need for hacks to discover the global
object, which continue to be problematic (e.g. #336, #346).

Importantly, the regenerator-runtime/runtime.js module can still be
evaluated as a non-CJS script, and it will not pollute the global scope
except for defining regeneratorRuntime.
@benjamn
Copy link
Contributor Author

benjamn commented Aug 3, 2018

@Benjamin-Dobell Thoughts on this approach?

@benjamn benjamn merged commit 5703a79 into master Aug 7, 2018
@MattiasBuelens
Copy link

MattiasBuelens commented Oct 26, 2018

@benjamn Any chance you could push out a patch release for this?

@wmertens
Copy link

So - I think this caused my build to fail. Is it Babel's responsibility to make this global?

@MattiasBuelens
Copy link

Thanks for the release! 🙂

Since this is a minor bump on a 0.x release, packages such as @babel/polyfill and @babel/runtime will need to update their dependency versions. Are you going to make a PR for updating Babel, or is it okay if I submit one?

@MattiasBuelens
Copy link

I've opened babel/babel#9442 to update @babel/polyfill, @babel/runtime and @babel/runtime-corejs2 to the latest version of the runtime.

benjamn added a commit that referenced this pull request Mar 7, 2019
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.
benjamn added a commit that referenced this pull request Mar 7, 2019
* Define regeneratorRuntime globally as a side-effect, again.

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.

* Update regenerator/package-lock.json.

* Fix Travis CI tests by running `npm i` instead of `npm ci`.

* Prevent Travis from running `npm ci` by default.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants