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

Remove global babelHelpers and regenerator #21283

Closed

Conversation

janicduplessis
Copy link
Contributor

@janicduplessis janicduplessis commented Sep 24, 2018

Follow up to facebook/metro@8932a9c

Babel helpers and regenerator runtime will be imported automatically from @babel/runtime. We still need to add the global regeneratorRuntime for jest tests since we disable babel-runtime currently.

Test Plan:

  • Run RN tester and make sure it works fine for screens using async functions.
  • Inspect the generated bundle to make sure helpers and regenerator are imported from @babel/runtime
  • Made sure the global babelHelpers and the old regenerator-runtime are not in the generated bundle.
  • Run jest tests

Release Notes:

Help reviewers and the release process by writing your own release notes. See below for an example.

[GENERAL] [ENHANCEMENT] [polyfills] - Remove global babelHelpers and regenerator

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 24, 2018
@pull-bot

This comment has been minimized.

janicduplessis referenced this pull request in facebook/metro Sep 24, 2018
…erator (#198)

Summary:
**Summary**

The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app.

This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package.

This will solve issues like this facebook/react-native#20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before.

**Test plan**

- Updated tests so they all pass.
- Tested that it actually works by applying the changes locally in an RN app.
- Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global.
- Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file).
Pull Request resolved: #198

Reviewed By: mjesun

Differential Revision: D8833903

Pulled By: rafeca

fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
@rafeca
Copy link
Contributor

rafeca commented Sep 24, 2018

Thanks @janicduplessis for the PR! I'm planning to release a new version of Metro later today (it's going to be v0.46.0 since the babel runtime change is breaking.

With this you're going to be able to test it locally and afterwards I can import it 😄

@rafeca
Copy link
Contributor

rafeca commented Sep 24, 2018

I've just published metro@0.46.0 with the change. Can you test that things are working fine? In the meantime I'm importing the PR to do the internal checks

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

rafeca has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
require('regenerator-runtime/runtime');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also remove regenerator-runtime from the dependencies in package.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still need it for jest tests, I guess I could move it to dev deps

@janicduplessis janicduplessis changed the title [DONTMERGE] Remove global babelHelpers and regenerator Remove global babelHelpers and regenerator Sep 24, 2018
@janicduplessis
Copy link
Contributor Author

@rafeca I was able to tests it, the only change missing was to add @babel/runtime to RN deps.

@janicduplessis
Copy link
Contributor Author

@rafeca I also didn't update the yarn.lock file, for some reason I couldn't generate a clean set of changes to it. It might be out of date already or a different version of yarn was used to generate it.

@janicduplessis
Copy link
Contributor Author

Also CI seems to be failling because of metro package that isn't published properly

error Couldn't find any versions for "metro-cache" that matches "0.46.0"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: Couldn't find any versions for "metro-cache" that matches "0.46.0"
    at MessageError.ExtendableBuiltin (/opt/yarn-v1.9.4/lib/cli.js:243:66)
    at new MessageError (/opt/yarn-v1.9.4/lib/cli.js:272:123)
    at Function.<anonymous> (/opt/yarn-v1.9.4/lib/cli.js:51264:13)
    at Generator.next (<anonymous>)
    at step (/opt/yarn-v1.9.4/lib/cli.js:92:30)
    at /opt/yarn-v1.9.4/lib/cli.js:103:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
Exited with code 1

@kelset
Copy link
Contributor

kelset commented Sep 25, 2018

@janicduplessis I think it has been published now (or, at least, running npm view metro-cache says that 0.46.0 is out), could you re-trigger the CI (maybe via a new commit?).

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

rafeca has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@janicduplessis
Copy link
Contributor Author

This might conflict with 1323acd, I think @babel/runtime should be a dependency and not devDependency.

@kelset
Copy link
Contributor

kelset commented Sep 26, 2018

Yeha I agree, may be worth reversing that in favour of this (which I guess may also just happen during the internal importing, right?)

cc @RSNara

@react-native-bot
Copy link
Collaborator

@janicduplessis merged commit 458d56c into facebook:master.


Once this commit is added to a release, you will see the corresponding version tag below the description at 458d56c. If the commit has a single master tag, it is not yet part of a release.

@facebook facebook locked as resolved and limited conversation to collaborators Sep 26, 2018
@react-native-bot react-native-bot added the Merged This PR has been merged. label Sep 26, 2018
grabbou pushed a commit that referenced this pull request Oct 2, 2018
Summary:
Follow up to facebook/metro@8932a9c

Babel helpers and regenerator runtime will be imported automatically from `babel/runtime`. We still need to add the global regeneratorRuntime for jest tests since we disable babel-runtime currently.
Pull Request resolved: #21283

Reviewed By: mjesun

Differential Revision: D10010963

Pulled By: rafeca

fbshipit-source-id: da5e23dd901f8f8940d46816b4fc9290d0e28c76
shimpeiws pushed a commit to shimpeiws/react-native that referenced this pull request Oct 12, 2018
Summary:
Follow up to facebook/metro@8932a9c

Babel helpers and regenerator runtime will be imported automatically from `babel/runtime`. We still need to add the global regeneratorRuntime for jest tests since we disable babel-runtime currently.
Pull Request resolved: facebook#21283

Reviewed By: mjesun

Differential Revision: D10010963

Pulled By: rafeca

fbshipit-source-id: da5e23dd901f8f8940d46816b4fc9290d0e28c76
aleclarson pushed a commit to aleclarson/react-native-macos that referenced this pull request Mar 26, 2019
Summary:
Follow up to facebook/metro@8932a9c

Babel helpers and regenerator runtime will be imported automatically from `babel/runtime`. We still need to add the global regeneratorRuntime for jest tests since we disable babel-runtime currently.
Pull Request resolved: facebook/react-native#21283

Reviewed By: mjesun

Differential Revision: D10010963

Pulled By: rafeca

fbshipit-source-id: da5e23dd901f8f8940d46816b4fc9290d0e28c76
t-nanava pushed a commit to microsoft/react-native-macos that referenced this pull request Jun 17, 2019
Summary:
Follow up to facebook/metro@8932a9c

Babel helpers and regenerator runtime will be imported automatically from `babel/runtime`. We still need to add the global regeneratorRuntime for jest tests since we disable babel-runtime currently.
Pull Request resolved: facebook#21283

Reviewed By: mjesun

Differential Revision: D10010963

Pulled By: rafeca

fbshipit-source-id: da5e23dd901f8f8940d46816b4fc9290d0e28c76
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants