Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47109
Fixes the `lint/sort-imports` errors that are now surfaced after fixing the lint configuration.
For a couple files, I added lint suppressions instead because the unsorted import ordering is important due to interleaved calls with side effects.
Changelog:
[Internal]
Reviewed By: GijsWeterings
Differential Revision: D64569485
fbshipit-source-id: 26415d792e2b9efe08c05d1436f723faae549882
Summary:
this PR fixes a few small ESLint issues that were showing up under PR diffs.
## Changelog:
[INTERNAL] [FIXED] - Fix various ESLint issues
Pull Request resolved: https://github.com/facebook/react-native/pull/46379
Test Plan: ran JS tests + linter; all passing
Reviewed By: cipolleschi
Differential Revision: D62385788
Pulled By: NickGerleman
fbshipit-source-id: b33d7ade4696bbaed2ac1a3fc2e0b3dff9bb04b7
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42690
Issues triggered by `InspectorProxy*` tests under `packages/dev-middleware` (T169943794) can be root-caused to `dev-middleware` performing Babel registration within a test run, after Jest has hooked its own transformer.
Babel registration is only required when running this code (`dev-middleware`, etc) directly from source - we already have the `BUILD_EXCLUDE_BABEL_REGISTER` mechanism to strip it out from production builds, but we currently don't prevent registration under tests, where Jest's transformer should be allowed to do its work.
This adds the same `babel-plugin-transform-define` mechanism that we use for production builds to the Jest transformer.
Changelog:
[Internal] Prevent inadvertent Babel registration during running of repo tests
Reviewed By: huntie
Differential Revision: D53125777
fbshipit-source-id: 1f0a20315c96edaf79054e29a80c7a9561e5b352
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39251
As `react-native/babel-preset` is extended to include parts of codegen (written in Flow) via `react-native/babel-plugin-codegen`, we need to register Babel (with a Node JS config) in order to load the `react-native/babel-transformer` that Jest needs to transform RN code when running from source.
(This is *only* relevant to running from source, ie internally at Meta or when developing on a clone of the OSS repo)
Changelog: [Internal]
Reviewed By: huntie
Differential Revision: D48871440
fbshipit-source-id: 2f206b2380d67007e37782f211a6e831b35291f8
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38771
Changelog: [Internal]
Metro has been passing `inlineRequires: false` to Babel transformers for the last 5 years (D9636747), as the inline requires transform had been hoisted into the transform worker. Here we clean up the unused code paths in React Native's implementations of the Metro Babel transformer API, and the unused properties in the API itself.
Reviewed By: GijsWeterings
Differential Revision: D48034441
fbshipit-source-id: d24a793962942a3c87461ffbade847ea749dac95
Summary:
X-link: https://github.com/facebook/metro/pull/1024
Pull Request resolved: https://github.com/facebook/react-native/pull/38228
Changelog: [General][Changed] - Move react-native-babel-transformer and react-native-babel-preset from Metro to React Native repo.
Metro Changelog: **[Breaking]** - Remove `metro-react-native-babel-transformer` and `metro-react-native-babel-preset`, to be published as `react-native/metro-babel-transformer` and `react-native/babel-preset` instead.
This diff does the following:
- Move `metro/packages/metro-react-native-babel-preset` to `react-native/packages/react-native-babel-preset`.
- Rename `metro-react-native-babel-preset` package to `react-native/babel-preset`.
- Move `metro/packages/metro-react-native-babel-transformer` to `react-native/packages/react-native-babel-transformer`.
- Rename `metro-react-native-babel-transformer` package to `react-native/metro-babel-transformer`.
- Upadate dependencies.
Reviewed By: robhogan
Differential Revision: D46977466
fbshipit-source-id: 32478f63a0442b61a1804f12ef814c8b29d7f8bb
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38554
@public
Upgrades React Native, Relay, and Metro to use `hermes-parser@0.14.0`.
This also changes the repository's Jest configuration to now use `hermes-parser`.
Changelog:
[Internal]
Reviewed By: SamChou19815
Differential Revision: D47522140
fbshipit-source-id: 207ccd0c4e4489d486731d0c847d8089abc1cc72
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38146
Now that `metro-react-native-babel-transformer` may be loaded from source without transformation, we can remove this workaround / potential footgun.
Jest uses Babel imperatively and doesn't rely on registration (require hooks), so registering within the preprocessor potentially conflicts and has caused problems before. This just tidies up some complexity we don't need.
Changelog: [Internal]
Reviewed By: christophpurrer
Differential Revision: D47162728
fbshipit-source-id: 06215f9bb7b8e71bcca0429d0bae9f20a22f45a8
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37915
Enable the `prettier-plugin-hermes-parser` in xplat. This plugin enables the use of `hermes-parser` which is significantly faster than the current flow parser prettier bundles (improves formatting time by ~50%) and also brings support for the latest Prettier 3.0.0 printing logic for JS. This upgrade is required in order to enable upcoming Flow features that add new syntax.
Changelog: [Internal]
Reviewed By: SamChou19815
Differential Revision: D46748891
fbshipit-source-id: 3775ef9afa7c04e565fa4fcf8ca5b410f49d35a1
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36623
Changelog:
[General][Changed] - The default `metro.config.js` in apps now extends `react-native/metro-config`, and should be updated in existing apps.
~~`react-native/rn-get-polyfills.js` is removed and should be updated to `react-native/js-polyfills` in existing apps (this is part of the new default config).~~
#publish-packages-to-npm
## Context
### React Native Metro config → React Native repo (https://github.com/facebook/react-native/pull/36502)
We (the React Native team) are aiming to relocate the default Metro config for React Native out of `react-native-community/cli-plugin-metro` and **into the React Native repo + app template** as a new `react-native/metro-config` package.
This is the first (and minimum viable) phase we can ship to separate the release process of Metro from RN CLI in order to reduce coupling and iterate faster for our users.
**See full motivation, design, and test plan (which previewed the CLI bump) here: https://github.com/facebook/react-native/pull/36502**
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after https://github.com/react-native-community/cli/pull/1875 is merged.
- Upgrade `react-native-community/cli` to `11.0.0`, upgrade all `metro` packages to `0.76.0` (version distributed in this CLI release).
- Update the `metro.config.js` file in `packages/react-native/template/`.
- Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0.
- Update the `metro.config.js` files for `packages/react-native/` and `packages/rn-tester/` (these are integration test locations).
- Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0.
Changes to `react-native/metro-config` — `0.72.1` (prepared but not depended on yet):
- Export `mergeConfig` util (removing direct `metro-config` dependency in consuming projects).
- Explicitly depend on `metro-react-native-babel-transformer` and `metro-runtime` (transitively included today).
Reviewed By: cortinico, blakef
Differential Revision: D44099691
fbshipit-source-id: 405635dd69fd50a1e9548279eaeda3c932b5b167
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36523
`jest/private/preprocessor.js` is only used to run tests on the workspace itself, it's not part of our exported Jest preset and is specifically excluded from publication in the `react-native` package.
Now that we have the monorepo setup, this belongs at the workspace root.
- `metro-react-native-babel-transformer` moved from RN `dependencies` to root `devDependencies` because it's only used by the preprocessor
- `jest/create-cache-key-function` added to `devDependencies` - it's also used by the `assetTransformer` in the public preset.
Changelog: [Internal]
Reviewed By: hoxyq
Differential Revision: D44197879
fbshipit-source-id: 0bbd9e2f500f53fa4f16562f05374dc601b67df6
Summary:
Changelog:
[Breaking][General] Remove jest/preprocessor from the react-native package
Using `react-native/jest/preprocessor` outside of the React Native repo has been deprecated since D34820086 (c1e9aa9a27). Here, we make this file private and stop publishing it to npm.
The supported method of using Jest in React Native projects is using the [Jest preset](https://jestjs.io/docs/tutorial-react-native) shipped as part of the `react-native` package.
NOTE: We could probably make some of the other files under `jest/` private as well, but we should go through a separate deprecation cycle with those, in case they are also being used externally by some projects. I'm leaving that for future followup at the moment.
Reviewed By: GijsWeterings
Differential Revision: D36132939
fbshipit-source-id: 300ffa6cf16232573cd3a79a34c14daaafd7aa43
Summary:
Changelog:
[General][Deprecated] Deprecate the use of `react-native/jest/preprocessor.js` by external projects
The supported method of using Jest in React Native projects is using the [Jest preset](https://jestjs.io/docs/tutorial-react-native) shipped as part of the `react-native` package. Some projects are directly using `preprocessor.js` which is part of the testing setup for the React Native repo itself.
In a future release of React Native, we will stop publishing this file to npm and require projects to switch to the supported preset (or a custom Jest config if necessary).
Reviewed By: GijsWeterings
Differential Revision: D34820086
fbshipit-source-id: 197c33726639e66c6916a244117252e6af11f2f6
Summary:
React Native has an *implicit* dev dependency on this transform via `metro-react-native-babel-transformer`. The transform replaces `Object.assign` with `babelHelpers.extend`, but `Object.assign` has been available natively since node 4.
We intend remove it from metro (https://github.com/facebook/metro/pull/745) as it's no longer needed by any supported runtime - removing RN's small dependency in advance so RN's tests won't break when we do.
Changelog:
[Internal][Changed] - Remove `babel/plugin-transform-object-assign` from jest preprocessor
Reviewed By: motiz88
Differential Revision: D34110208
fbshipit-source-id: 064f8241461fb338de1cd8b53077e8660301aa77
Summary:
This fixes how ES modules are handled in Jest tests in the react-native codebase.
They caused some problems before because `import` statements weren't inlined as `require` calls were, so there were some errors in tests when migrating from CommonJS to ESM.
This changes the transform that Jest uses to inline import statements the same way, so we can migrate everything without issues in tests.
Changelog: [Internal]
Reviewed By: kacieb
Differential Revision: D28899692
fbshipit-source-id: 027690f57ca3b5613c261a1089c0635af76662b2
Summary:
The current version of Flow fails to report some errors in library definitions. I'm
working on a Flow fix that would surface these errors. In preparation for this, this diff:
* replaces `FbtErrorListener` (missing) with `IFbtErrorListener` in fbt.js
* fixes typos in several files
* suppresses missing names with `[cannot-resolve-name]`
* adds `sourceMapTarget` option in babel-generator
Changelog: [Internal]
Reviewed By: jbrown215
Differential Revision: D25839533
fbshipit-source-id: 947207db9238aa10663616d59080440d2ac6f243
Summary:
Passes the `globalPrefix` option from the Metro config object into `metro-babel-transformer`. This currently has no effect in OSS.
Changelog: [Internal]
Reviewed By: cpojer
Differential Revision: D22594663
fbshipit-source-id: 668b71cd6bec988313e9286b316f9006d61ad871
Summary:
Turns on the exact-by-default flag in xplat/js and gets rid of the implicit inexact object lint, which has no effect when exact-by-default is on.
Will land this on Monday along with an announcement post.
Changelog: [Internal]
Reviewed By: gkz
Differential Revision: D18863276
fbshipit-source-id: 07a31e957bea1d1e053e8fa5975fdb1b6da1bdc4
Summary:
This updates React Native to use latest CLI. We also create Metro configuration, because CLI looks for React Native in "node_modules" by default. Since we are running React Native from source, it will fail to find required files.
To avoid hacky logic to detect if we are running from source backed into the CLI, I decided to leverage the Metro configuration instead.
Pull Request resolved: https://github.com/facebook/react-native/pull/23052
Reviewed By: rickhanlonii
Differential Revision: D13719938
Pulled By: cpojer
fbshipit-source-id: 1f40a40b3cdbb07ccd42daf75feb457556d3e40f
Summary:
This diff removes the dependency of `metro` on `react-native` by using the newly created `metro-react-native-babel-transformer` package.
This package does not depend on any other internal metro logic and this will decouple RN from metro a bit more.
Reviewed By: cpojer
Differential Revision: D13434949
fbshipit-source-id: a02a3b327c71cef53111514b797f7d6bc9f9d71c
Summary: This removes the remaining references to `local-cli`. We already have a `cli.js` file on the root that was just forwarding to the local-cli folder, so I removed that. It also seems that `setupBabel.js` is no longer necessary in RN.
Reviewed By: TheSavior
Differential Revision: D13396218
fbshipit-source-id: a945cb91dae39c4b58c5cabcca6b0f0328fc4717
Summary:
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. -->
**Summary**
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->
This is an updated followup from https://github.com/facebook/metro/pull/280, which we would still need to address the following assumptions about `/assets/`:
e7deea1900/packages/metro/src/Server.js (L332)e7deea1900/packages/metro/src/Server.js (L379)e7deea1900/packages/metro/src/Server.js (L385)
As pointed out by gdborton, there isn't currently a way to make this a configurable option. I am not certain how to find a proper workaround for `processRequest`.
We found a temporary solution to have our express app pick up serving the assets from a publicPath as a middleware. But the change in this PR is still necessary to get it working fully.
**Test plan**
<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->
- Will add tests once we figure out a comprehensive solution
Pull Request resolved: https://github.com/facebook/metro/pull/299
Reviewed By: rafeca
Differential Revision: D12939229
Pulled By: mjesun
fbshipit-source-id: 769c23468c5ac434f8319e5e7caaf46dd6453f2d
Summary:
Up until now the `enableBabelRuntime` option in the `metro-react-native-preset` package was hardcoded in the transformer: our internal transformer set it to `false` and the opensource one was `true`.
This diff now exposes this param out to the config of Metro (now that it's quite easy to expose things) so anybody can set it to false or true.
This allows our end to end tests to set it to false to not have to deal with requires to `babel/runtime`.
Reviewed By: davidaurelio
Differential Revision: D10123776
fbshipit-source-id: 97e744eeb567c8e86ab3c613ac71970d226ed2ca
Summary:
Since the options that are passed to the `babelTransformer` are not exactly the same ones as the `transformer` receives, we need to have a specific object for them.
This allows us to make the transformer options object strict (since unfortunately the `babeltransformer` options object comes from many places and needs a bit of work to be able to be strict...
Reviewed By: mjesun
Differential Revision: D9309173
fbshipit-source-id: 0a92381968f17e5eb6c4740c1ca89580fa7ee4d3
Summary:
Up until now, transformers in Metro received the absolute path of a file, the relative path of a file and the projectRoot.
This diff gets rid of the absolute path sent to the worker, since by having the projectRoot and the relative path, the absolute path can be easily calculated.
This has been done to avoid having absolute paths as transform options, since we need to have custom logic to filter them out from the cache key generation, which is dangerous.
Reviewed By: mjesun
Differential Revision: D9195147
fbshipit-source-id: e95c5c29272eec7f1a48af7cede4c6d6b4a8ffb7
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 https://github.com/facebook/react-native/issues/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: https://github.com/facebook/metro/pull/198
Reviewed By: mjesun
Differential Revision: D8833903
Pulled By: rafeca
fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
Summary: This change drops the year from the copyright headers and the LICENSE file.
Reviewed By: yungsters
Differential Revision: D9727774
fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
Summary:
This is the first step to make transformers fully customizable (and not be tied to JS, or RN). In order to do that, I'm changing the signature of the transformers, which currently is:
```
function transformCode(
filename: string,
localPath: LocalPath,
transformerPath: string,
options: WorkerOptions,
assetExts: $ReadOnlyArray<string>,
assetRegistryPath: string,
minifierPath: string,
asyncRequireModulePath: string,
dynamicDepsInPackages: DynamicRequiresBehavior,
)
```
to be:
```
async function transformCode(
filename: string,
localPath: LocalPath,
options: WorkerOptions,
)
```
(so basically, all the RN-custom properties are moved to `WorkerOptions`, which in the future will be a generic to allow anybody pass any random option to their transformers).
In order to make all this work, I've had to get rid of the logic that calculates the base cache key hash based on a subset of worker options (the ones that Metro knows that are not going to change between runs).
This could potentially cause a perf regression (since we're now making the hash calculation a bit more costly), and in fact I could measure a ~400ms regression on the worse case scenario (which happens when restarting Metro and re-transforming a Wilde from a warm local cache).
I've benchmarked this regression and could find that it's caused by the array of `assetExtensions` (which is potentially large). I have a followup diff to improve this, which is able to remove the regression completely.
Reviewed By: pvdz
Differential Revision: D8695766
fbshipit-source-id: eccd18a4cbc91854f34d5c9ba7f95088f19483a1
Summary: Adds missing comma, following up on https://github.com/facebook/react-native/pull/20178. Thanks to LinusU for pointing out the error.
Reviewed By: TheSavior
Differential Revision: D9242887
fbshipit-source-id: 4b547396722d0e37dc5c8eb3439b9a441c3c0ac2
Summary:
Upgrade Babel from beta.40 to beta.47
There are two important breaking changes here.
- If you want an AST from the Babel `transform` functions you must pass on `ast:true` in the options.
- The `sourceType` is now the only source of truth on whether to parse with the Script or Module goal. It defaults to `script` and can also be `module` or `unambiguous`. In the `unambiguous` case it will first try to parse with the Module goal and only if it crashes it will try again with the Script goal.
Beyond that there were some fixes and some smaller changes that may affect you. See the Babel changelogs for details (https://github.com/babel/babel/tags).
Also updated the way we generate the babel helpers file.
Reviewed By: rubennorte
Differential Revision: D8075280
fbshipit-source-id: 2bb902690e8a4b19d9cada2b7b0c94812b3d4f0f