Skip to content

RFC: Add @react-native/metro-config package - #36502

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692
Closed

RFC: Add @react-native/metro-config package#36502
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692

Conversation

@huntie

@huntiehuntie commented Mar 16, 2023

Copy link
Copy Markdown
Collaborator

Summary:

Context

React Native Metro config → React Native repo

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.

Motivation

Today, the Metro config required to use React Native is entangled within react-native-community/cli-plugin-metro and is not readable from within a project. We instead want to relocate the default Metro config into the React Native repo and have users explicitly inherit this config in their projects.

BeforeAfter
imageimage
Note: CLI change will be breaking, to explicitly target React Native 0.72 and onwards

Benefits

  • Allows projects to clearly understand, extend, and override options within their metro.config.js file as the source of truth.
  • Logically, locates the config for using Metro with React Native within the React Native repo — where we can set baseline defaults that are inherited by other tooling (e.g. both RN CLI and Expo).
  • The previous setup meant that the resolved Metro configuration was hidden, preventing standalone Metro CLI commands from being runnable.
  • Removes existing noise from the template config.
  • Moves us closer to shipping Metro updates and bugfixes independent of the CLI.

User-side change: Default metro.config.js file in a new React Native project

We will also signal the need to update existing metro.config.js files in the release blog post.

BeforeAfter
imageimage
⚠️ Config contains user overrides only, will be overridden by defaults set by React Native CLI.✅ Complete Metro config is defined by extending react-native/metro-config.
⚠️ Config contains stale defaults that were split across the template and RN CLI.✅ Both RN CLI and metro CLI will read the same config.
✅ Dynamic/extended config will continue to be applied by RN CLI on top of these.
✅ User-defined config object is cleaned up.

Plan

  1. ➡️ This PR: Create a new package within facebook/react-native, @react-native/metro-config, to contain the default Metro config for React Native projects going forward.
  2. Update React Native app template to define an updated metro.config.js extending the new config package.
  3. (Depends on the above two changes) breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72) react-native-community/cli#1875

Note: Changes in this repo (1, 2) will be compatible with the current version of RN CLI on main — the only breaking change is that the new CLI will not be able to support RN projects without these changes.

Changes

  • This PR adds the new @react-native/metro-config package which reproduces all static values previously defined in RN CLI.
    • The values not included, which remain in RN CLI, are dynamic values derived from CLI options passed by the user.

Test Plan (all PRs + incoming changes)

E2E expectation: The new config is non-breaking against old CLI, the new CLI is breaking against old config.

Pre-steps

With the relevant repos cloned:

.
└── Development/forks
├── react-native # huntie/react-native@export-D44099692
└── react-native-cli # huntie/react-native-cli@c53e49b
  1. cd Development/forks/react-native/packages/rn-tester/
  2. Copy over metro.config.js and package.json changes from react-native/template/ (next commit in stack).
  3. Run yarn.

[Base case] React Native @ main (this stack, before new CLI is merged — non-breaking)
(template = new, CLI = old)

yarn start

✅ Works (new complete Metro config is read into RN CLI, and overridden by its previous defaults — for this reason we can't delete ./rn-get-polyfills.js yet!)

yarn metro get-dependencies --entry-file js/RNTesterApp.android.js --platform android

✅ Works (new complete Metro config is available to Metro CLI)

[Release state] React Native 0.72 (new CLI, new config required)
(template = new, CLI = new)

  1. Use (cd ../..; yarn link @react-native-community/cli-plugin-metro) to substitute version of @react-native-community/cli-plugin-metro using cloned react-native-cli directory.
  2. Run yarn.
  3. Update watchFolders (see Metro Local Development Setup).
yarn start

image

✅ Works (new complete Metro config is read into RN CLI, and merged with sparser defaults in react-native-community/cli#1875)
- (Note console logs)
- Note: At the point this test was run, found a small unrelated bug (post monorepo land) where rn-tester would look for a metro.config.js at the repo root and not inside packages/rn-tester/ — hence an extra /metro.config.js file was added in the above screenshot. This will be re-tested in the commit when we bump RN CLI.

Changelog:
[General][Added] Add react-native/metro-config package

Differential Revision: D44099692

@facebook-github-botfacebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 16, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@analysis-bot

analysis-bot commented Mar 16, 2023

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,519,193+0
androidhermesarmeabi-v7a7,834,776+0
androidhermesx868,999,081+0
androidhermesx86_648,854,121+0
androidjscarm64-v8a9,141,838+0
androidjscarmeabi-v7a8,333,472+0
androidjscx869,196,418+0
androidjscx86_649,454,245+0

Base commit: 0eff8d6
Branch: main

Comment threadpackages/metro-config/index.js Outdated

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is the only base config divergence: ['android', 'ios'] here matches the default RN repo setup. As before, this will be overridden by RN CLI based on the platforms CLI argument.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 399bfb21b49200e7d53c9d358c64607f4091847d
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@huntie

Copy link
Copy Markdown
CollaboratorAuthor

Changes to metro.config.js files within the template and rn-tester are prepared and will be shipped shortly after this PR (as we need to publish the new package first).

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM on the React Native side of things

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Mar 21, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 745cdb1.

cipolleschi pushed a commit that referenced this pull request Mar 28, 2023
Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 672a67e19d866ac2c64fc84983b5d82c604918c6
cipolleschi added a commit that referenced this pull request Mar 28, 2023
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
Co-authored-by: Alex Hunt <alexeh@meta.com>
resolved: #36502
facebook-github-bot pushed a commit that referenced this pull request Mar 30, 2023
Summary:
Pull Request resolved: #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 (#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: #36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2024
…41836)
Summary:
This adds `react-native/metro-config` to the monorepo build tool and emits the missing typescript declarations.
Right now, we do have typescript declarations on `metro-config`, but not `react-native/metro-config`. Which makes everything a bit harder extend from "[the default React Native metro config](#36502)" in Expo.
> Note, I also added the same `exports` block from `react-native/dev-middleware` for conformity.
One open question here is, why aren't we exporting _all_ helper functions from `metro-config`? To me, its a bit weird that we need both `metro-config` _and_ `react-native/metro-config` as `loadConfig` isn't exported.
## Changelog:
[INTERNAL] [FIXED] - Emit typescript declaration files for `react-native/metro-config`
Pull Request resolved: #41836
Test Plan:
Run the build tool, and check if the typescript declarations are emitted for `react-native/metro-config`.
```
yarn build metro-config
```
Reviewed By: hoxyq
Differential Revision: D51943453
Pulled By: huntie
fbshipit-source-id: cfaffe5660053fc9a9fcbe3dacf7f6ccc2bde01b
blakef pushed a commit to blakef/template that referenced this pull request Feb 28, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huntie@facebook-github-bot@analysis-bot@cortinico
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
RFC: Add @react-native/metro-config package by huntie · Pull Request #36502 · react/react-native · GitHub
Skip to content

RFC: Add @react-native/metro-config package - #36502

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692
Closed

RFC: Add @react-native/metro-config package#36502
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692

Conversation

@huntie

@huntiehuntie commented Mar 16, 2023

Copy link
Copy Markdown
Collaborator

Summary:

Context

React Native Metro config → React Native repo

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.

Motivation

Today, the Metro config required to use React Native is entangled within react-native-community/cli-plugin-metro and is not readable from within a project. We instead want to relocate the default Metro config into the React Native repo and have users explicitly inherit this config in their projects.

BeforeAfter
imageimage
Note: CLI change will be breaking, to explicitly target React Native 0.72 and onwards

Benefits

  • Allows projects to clearly understand, extend, and override options within their metro.config.js file as the source of truth.
  • Logically, locates the config for using Metro with React Native within the React Native repo — where we can set baseline defaults that are inherited by other tooling (e.g. both RN CLI and Expo).
  • The previous setup meant that the resolved Metro configuration was hidden, preventing standalone Metro CLI commands from being runnable.
  • Removes existing noise from the template config.
  • Moves us closer to shipping Metro updates and bugfixes independent of the CLI.

User-side change: Default metro.config.js file in a new React Native project

We will also signal the need to update existing metro.config.js files in the release blog post.

BeforeAfter
imageimage
⚠️ Config contains user overrides only, will be overridden by defaults set by React Native CLI.✅ Complete Metro config is defined by extending react-native/metro-config.
⚠️ Config contains stale defaults that were split across the template and RN CLI.✅ Both RN CLI and metro CLI will read the same config.
✅ Dynamic/extended config will continue to be applied by RN CLI on top of these.
✅ User-defined config object is cleaned up.

Plan

  1. ➡️ This PR: Create a new package within facebook/react-native, @react-native/metro-config, to contain the default Metro config for React Native projects going forward.
  2. Update React Native app template to define an updated metro.config.js extending the new config package.
  3. (Depends on the above two changes) breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72) react-native-community/cli#1875

Note: Changes in this repo (1, 2) will be compatible with the current version of RN CLI on main — the only breaking change is that the new CLI will not be able to support RN projects without these changes.

Changes

  • This PR adds the new @react-native/metro-config package which reproduces all static values previously defined in RN CLI.
    • The values not included, which remain in RN CLI, are dynamic values derived from CLI options passed by the user.

Test Plan (all PRs + incoming changes)

E2E expectation: The new config is non-breaking against old CLI, the new CLI is breaking against old config.

Pre-steps

With the relevant repos cloned:

.
└── Development/forks
├── react-native # huntie/react-native@export-D44099692
└── react-native-cli # huntie/react-native-cli@c53e49b
  1. cd Development/forks/react-native/packages/rn-tester/
  2. Copy over metro.config.js and package.json changes from react-native/template/ (next commit in stack).
  3. Run yarn.

[Base case] React Native @ main (this stack, before new CLI is merged — non-breaking)
(template = new, CLI = old)

yarn start

✅ Works (new complete Metro config is read into RN CLI, and overridden by its previous defaults — for this reason we can't delete ./rn-get-polyfills.js yet!)

yarn metro get-dependencies --entry-file js/RNTesterApp.android.js --platform android

✅ Works (new complete Metro config is available to Metro CLI)

[Release state] React Native 0.72 (new CLI, new config required)
(template = new, CLI = new)

  1. Use (cd ../..; yarn link @react-native-community/cli-plugin-metro) to substitute version of @react-native-community/cli-plugin-metro using cloned react-native-cli directory.
  2. Run yarn.
  3. Update watchFolders (see Metro Local Development Setup).
yarn start

image

✅ Works (new complete Metro config is read into RN CLI, and merged with sparser defaults in react-native-community/cli#1875)
- (Note console logs)
- Note: At the point this test was run, found a small unrelated bug (post monorepo land) where rn-tester would look for a metro.config.js at the repo root and not inside packages/rn-tester/ — hence an extra /metro.config.js file was added in the above screenshot. This will be re-tested in the commit when we bump RN CLI.

Changelog:
[General][Added] Add react-native/metro-config package

Differential Revision: D44099692

@facebook-github-botfacebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 16, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@analysis-bot

analysis-bot commented Mar 16, 2023

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,519,193+0
androidhermesarmeabi-v7a7,834,776+0
androidhermesx868,999,081+0
androidhermesx86_648,854,121+0
androidjscarm64-v8a9,141,838+0
androidjscarmeabi-v7a8,333,472+0
androidjscx869,196,418+0
androidjscx86_649,454,245+0

Base commit: 0eff8d6
Branch: main

Comment threadpackages/metro-config/index.js Outdated

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is the only base config divergence: ['android', 'ios'] here matches the default RN repo setup. As before, this will be overridden by RN CLI based on the platforms CLI argument.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 399bfb21b49200e7d53c9d358c64607f4091847d
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@huntie

Copy link
Copy Markdown
CollaboratorAuthor

Changes to metro.config.js files within the template and rn-tester are prepared and will be shipped shortly after this PR (as we need to publish the new package first).

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM on the React Native side of things

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Mar 21, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 745cdb1.

cipolleschi pushed a commit that referenced this pull request Mar 28, 2023
Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 672a67e19d866ac2c64fc84983b5d82c604918c6
cipolleschi added a commit that referenced this pull request Mar 28, 2023
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
Co-authored-by: Alex Hunt <alexeh@meta.com>
resolved: #36502
facebook-github-bot pushed a commit that referenced this pull request Mar 30, 2023
Summary:
Pull Request resolved: #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 (#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: #36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2024
…41836)
Summary:
This adds `react-native/metro-config` to the monorepo build tool and emits the missing typescript declarations.
Right now, we do have typescript declarations on `metro-config`, but not `react-native/metro-config`. Which makes everything a bit harder extend from "[the default React Native metro config](#36502)" in Expo.
> Note, I also added the same `exports` block from `react-native/dev-middleware` for conformity.
One open question here is, why aren't we exporting _all_ helper functions from `metro-config`? To me, its a bit weird that we need both `metro-config` _and_ `react-native/metro-config` as `loadConfig` isn't exported.
## Changelog:
[INTERNAL] [FIXED] - Emit typescript declaration files for `react-native/metro-config`
Pull Request resolved: #41836
Test Plan:
Run the build tool, and check if the typescript declarations are emitted for `react-native/metro-config`.
```
yarn build metro-config
```
Reviewed By: hoxyq
Differential Revision: D51943453
Pulled By: huntie
fbshipit-source-id: cfaffe5660053fc9a9fcbe3dacf7f6ccc2bde01b
blakef pushed a commit to blakef/template that referenced this pull request Feb 28, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huntie@facebook-github-bot@analysis-bot@cortinico
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' RFC: Add @react-native/metro-config package by huntie · Pull Request #36502 · react/react-native · GitHub
Skip to content

RFC: Add @react-native/metro-config package - #36502

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692
Closed

RFC: Add @react-native/metro-config package#36502
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692

Conversation

@huntie

@huntiehuntie commented Mar 16, 2023

Copy link
Copy Markdown
Collaborator

Summary:

Context

React Native Metro config → React Native repo

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.

Motivation

Today, the Metro config required to use React Native is entangled within react-native-community/cli-plugin-metro and is not readable from within a project. We instead want to relocate the default Metro config into the React Native repo and have users explicitly inherit this config in their projects.

BeforeAfter
imageimage
Note: CLI change will be breaking, to explicitly target React Native 0.72 and onwards

Benefits

  • Allows projects to clearly understand, extend, and override options within their metro.config.js file as the source of truth.
  • Logically, locates the config for using Metro with React Native within the React Native repo — where we can set baseline defaults that are inherited by other tooling (e.g. both RN CLI and Expo).
  • The previous setup meant that the resolved Metro configuration was hidden, preventing standalone Metro CLI commands from being runnable.
  • Removes existing noise from the template config.
  • Moves us closer to shipping Metro updates and bugfixes independent of the CLI.

User-side change: Default metro.config.js file in a new React Native project

We will also signal the need to update existing metro.config.js files in the release blog post.

BeforeAfter
imageimage
⚠️ Config contains user overrides only, will be overridden by defaults set by React Native CLI.✅ Complete Metro config is defined by extending react-native/metro-config.
⚠️ Config contains stale defaults that were split across the template and RN CLI.✅ Both RN CLI and metro CLI will read the same config.
✅ Dynamic/extended config will continue to be applied by RN CLI on top of these.
✅ User-defined config object is cleaned up.

Plan

  1. ➡️ This PR: Create a new package within facebook/react-native, @react-native/metro-config, to contain the default Metro config for React Native projects going forward.
  2. Update React Native app template to define an updated metro.config.js extending the new config package.
  3. (Depends on the above two changes) breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72) react-native-community/cli#1875

Note: Changes in this repo (1, 2) will be compatible with the current version of RN CLI on main — the only breaking change is that the new CLI will not be able to support RN projects without these changes.

Changes

  • This PR adds the new @react-native/metro-config package which reproduces all static values previously defined in RN CLI.
    • The values not included, which remain in RN CLI, are dynamic values derived from CLI options passed by the user.

Test Plan (all PRs + incoming changes)

E2E expectation: The new config is non-breaking against old CLI, the new CLI is breaking against old config.

Pre-steps

With the relevant repos cloned:

.
└── Development/forks
├── react-native # huntie/react-native@export-D44099692
└── react-native-cli # huntie/react-native-cli@c53e49b
  1. cd Development/forks/react-native/packages/rn-tester/
  2. Copy over metro.config.js and package.json changes from react-native/template/ (next commit in stack).
  3. Run yarn.

[Base case] React Native @ main (this stack, before new CLI is merged — non-breaking)
(template = new, CLI = old)

yarn start

✅ Works (new complete Metro config is read into RN CLI, and overridden by its previous defaults — for this reason we can't delete ./rn-get-polyfills.js yet!)

yarn metro get-dependencies --entry-file js/RNTesterApp.android.js --platform android

✅ Works (new complete Metro config is available to Metro CLI)

[Release state] React Native 0.72 (new CLI, new config required)
(template = new, CLI = new)

  1. Use (cd ../..; yarn link @react-native-community/cli-plugin-metro) to substitute version of @react-native-community/cli-plugin-metro using cloned react-native-cli directory.
  2. Run yarn.
  3. Update watchFolders (see Metro Local Development Setup).
yarn start

image

✅ Works (new complete Metro config is read into RN CLI, and merged with sparser defaults in react-native-community/cli#1875)
- (Note console logs)
- Note: At the point this test was run, found a small unrelated bug (post monorepo land) where rn-tester would look for a metro.config.js at the repo root and not inside packages/rn-tester/ — hence an extra /metro.config.js file was added in the above screenshot. This will be re-tested in the commit when we bump RN CLI.

Changelog:
[General][Added] Add react-native/metro-config package

Differential Revision: D44099692

@facebook-github-botfacebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 16, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@analysis-bot

analysis-bot commented Mar 16, 2023

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,519,193+0
androidhermesarmeabi-v7a7,834,776+0
androidhermesx868,999,081+0
androidhermesx86_648,854,121+0
androidjscarm64-v8a9,141,838+0
androidjscarmeabi-v7a8,333,472+0
androidjscx869,196,418+0
androidjscx86_649,454,245+0

Base commit: 0eff8d6
Branch: main

Comment threadpackages/metro-config/index.js Outdated

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is the only base config divergence: ['android', 'ios'] here matches the default RN repo setup. As before, this will be overridden by RN CLI based on the platforms CLI argument.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 399bfb21b49200e7d53c9d358c64607f4091847d
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@huntie

Copy link
Copy Markdown
CollaboratorAuthor

Changes to metro.config.js files within the template and rn-tester are prepared and will be shipped shortly after this PR (as we need to publish the new package first).

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM on the React Native side of things

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Mar 21, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 745cdb1.

cipolleschi pushed a commit that referenced this pull request Mar 28, 2023
Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 672a67e19d866ac2c64fc84983b5d82c604918c6
cipolleschi added a commit that referenced this pull request Mar 28, 2023
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
Co-authored-by: Alex Hunt <alexeh@meta.com>
resolved: #36502
facebook-github-bot pushed a commit that referenced this pull request Mar 30, 2023
Summary:
Pull Request resolved: #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 (#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: #36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2024
…41836)
Summary:
This adds `react-native/metro-config` to the monorepo build tool and emits the missing typescript declarations.
Right now, we do have typescript declarations on `metro-config`, but not `react-native/metro-config`. Which makes everything a bit harder extend from "[the default React Native metro config](#36502)" in Expo.
> Note, I also added the same `exports` block from `react-native/dev-middleware` for conformity.
One open question here is, why aren't we exporting _all_ helper functions from `metro-config`? To me, its a bit weird that we need both `metro-config` _and_ `react-native/metro-config` as `loadConfig` isn't exported.
## Changelog:
[INTERNAL] [FIXED] - Emit typescript declaration files for `react-native/metro-config`
Pull Request resolved: #41836
Test Plan:
Run the build tool, and check if the typescript declarations are emitted for `react-native/metro-config`.
```
yarn build metro-config
```
Reviewed By: hoxyq
Differential Revision: D51943453
Pulled By: huntie
fbshipit-source-id: cfaffe5660053fc9a9fcbe3dacf7f6ccc2bde01b
blakef pushed a commit to blakef/template that referenced this pull request Feb 28, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huntie@facebook-github-bot@analysis-bot@cortinico
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' RFC: Add @react-native/metro-config package by huntie · Pull Request #36502 · react/react-native · GitHub
Skip to content

RFC: Add @react-native/metro-config package - #36502

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692
Closed

RFC: Add @react-native/metro-config package#36502
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692

Conversation

@huntie

@huntiehuntie commented Mar 16, 2023

Copy link
Copy Markdown
Collaborator

Summary:

Context

React Native Metro config → React Native repo

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.

Motivation

Today, the Metro config required to use React Native is entangled within react-native-community/cli-plugin-metro and is not readable from within a project. We instead want to relocate the default Metro config into the React Native repo and have users explicitly inherit this config in their projects.

BeforeAfter
imageimage
Note: CLI change will be breaking, to explicitly target React Native 0.72 and onwards

Benefits

  • Allows projects to clearly understand, extend, and override options within their metro.config.js file as the source of truth.
  • Logically, locates the config for using Metro with React Native within the React Native repo — where we can set baseline defaults that are inherited by other tooling (e.g. both RN CLI and Expo).
  • The previous setup meant that the resolved Metro configuration was hidden, preventing standalone Metro CLI commands from being runnable.
  • Removes existing noise from the template config.
  • Moves us closer to shipping Metro updates and bugfixes independent of the CLI.

User-side change: Default metro.config.js file in a new React Native project

We will also signal the need to update existing metro.config.js files in the release blog post.

BeforeAfter
imageimage
⚠️ Config contains user overrides only, will be overridden by defaults set by React Native CLI.✅ Complete Metro config is defined by extending react-native/metro-config.
⚠️ Config contains stale defaults that were split across the template and RN CLI.✅ Both RN CLI and metro CLI will read the same config.
✅ Dynamic/extended config will continue to be applied by RN CLI on top of these.
✅ User-defined config object is cleaned up.

Plan

  1. ➡️ This PR: Create a new package within facebook/react-native, @react-native/metro-config, to contain the default Metro config for React Native projects going forward.
  2. Update React Native app template to define an updated metro.config.js extending the new config package.
  3. (Depends on the above two changes) breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72) react-native-community/cli#1875

Note: Changes in this repo (1, 2) will be compatible with the current version of RN CLI on main — the only breaking change is that the new CLI will not be able to support RN projects without these changes.

Changes

  • This PR adds the new @react-native/metro-config package which reproduces all static values previously defined in RN CLI.
    • The values not included, which remain in RN CLI, are dynamic values derived from CLI options passed by the user.

Test Plan (all PRs + incoming changes)

E2E expectation: The new config is non-breaking against old CLI, the new CLI is breaking against old config.

Pre-steps

With the relevant repos cloned:

.
└── Development/forks
├── react-native # huntie/react-native@export-D44099692
└── react-native-cli # huntie/react-native-cli@c53e49b
  1. cd Development/forks/react-native/packages/rn-tester/
  2. Copy over metro.config.js and package.json changes from react-native/template/ (next commit in stack).
  3. Run yarn.

[Base case] React Native @ main (this stack, before new CLI is merged — non-breaking)
(template = new, CLI = old)

yarn start

✅ Works (new complete Metro config is read into RN CLI, and overridden by its previous defaults — for this reason we can't delete ./rn-get-polyfills.js yet!)

yarn metro get-dependencies --entry-file js/RNTesterApp.android.js --platform android

✅ Works (new complete Metro config is available to Metro CLI)

[Release state] React Native 0.72 (new CLI, new config required)
(template = new, CLI = new)

  1. Use (cd ../..; yarn link @react-native-community/cli-plugin-metro) to substitute version of @react-native-community/cli-plugin-metro using cloned react-native-cli directory.
  2. Run yarn.
  3. Update watchFolders (see Metro Local Development Setup).
yarn start

image

✅ Works (new complete Metro config is read into RN CLI, and merged with sparser defaults in react-native-community/cli#1875)
- (Note console logs)
- Note: At the point this test was run, found a small unrelated bug (post monorepo land) where rn-tester would look for a metro.config.js at the repo root and not inside packages/rn-tester/ — hence an extra /metro.config.js file was added in the above screenshot. This will be re-tested in the commit when we bump RN CLI.

Changelog:
[General][Added] Add react-native/metro-config package

Differential Revision: D44099692

@facebook-github-botfacebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 16, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@analysis-bot

analysis-bot commented Mar 16, 2023

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,519,193+0
androidhermesarmeabi-v7a7,834,776+0
androidhermesx868,999,081+0
androidhermesx86_648,854,121+0
androidjscarm64-v8a9,141,838+0
androidjscarmeabi-v7a8,333,472+0
androidjscx869,196,418+0
androidjscx86_649,454,245+0

Base commit: 0eff8d6
Branch: main

Comment threadpackages/metro-config/index.js Outdated

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is the only base config divergence: ['android', 'ios'] here matches the default RN repo setup. As before, this will be overridden by RN CLI based on the platforms CLI argument.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 399bfb21b49200e7d53c9d358c64607f4091847d
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@huntie

Copy link
Copy Markdown
CollaboratorAuthor

Changes to metro.config.js files within the template and rn-tester are prepared and will be shipped shortly after this PR (as we need to publish the new package first).

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM on the React Native side of things

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Mar 21, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 745cdb1.

cipolleschi pushed a commit that referenced this pull request Mar 28, 2023
Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 672a67e19d866ac2c64fc84983b5d82c604918c6
cipolleschi added a commit that referenced this pull request Mar 28, 2023
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
Co-authored-by: Alex Hunt <alexeh@meta.com>
resolved: #36502
facebook-github-bot pushed a commit that referenced this pull request Mar 30, 2023
Summary:
Pull Request resolved: #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 (#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: #36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2024
…41836)
Summary:
This adds `react-native/metro-config` to the monorepo build tool and emits the missing typescript declarations.
Right now, we do have typescript declarations on `metro-config`, but not `react-native/metro-config`. Which makes everything a bit harder extend from "[the default React Native metro config](#36502)" in Expo.
> Note, I also added the same `exports` block from `react-native/dev-middleware` for conformity.
One open question here is, why aren't we exporting _all_ helper functions from `metro-config`? To me, its a bit weird that we need both `metro-config` _and_ `react-native/metro-config` as `loadConfig` isn't exported.
## Changelog:
[INTERNAL] [FIXED] - Emit typescript declaration files for `react-native/metro-config`
Pull Request resolved: #41836
Test Plan:
Run the build tool, and check if the typescript declarations are emitted for `react-native/metro-config`.
```
yarn build metro-config
```
Reviewed By: hoxyq
Differential Revision: D51943453
Pulled By: huntie
fbshipit-source-id: cfaffe5660053fc9a9fcbe3dacf7f6ccc2bde01b
blakef pushed a commit to blakef/template that referenced this pull request Feb 28, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huntie@facebook-github-bot@analysis-bot@cortinico
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' RFC: Add @react-native/metro-config package by huntie · Pull Request #36502 · react/react-native · GitHub
Skip to content

RFC: Add @react-native/metro-config package - #36502

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692
Closed

RFC: Add @react-native/metro-config package#36502
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692

Conversation

@huntie

@huntiehuntie commented Mar 16, 2023

Copy link
Copy Markdown
Collaborator

Summary:

Context

React Native Metro config → React Native repo

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.

Motivation

Today, the Metro config required to use React Native is entangled within react-native-community/cli-plugin-metro and is not readable from within a project. We instead want to relocate the default Metro config into the React Native repo and have users explicitly inherit this config in their projects.

BeforeAfter
imageimage
Note: CLI change will be breaking, to explicitly target React Native 0.72 and onwards

Benefits

  • Allows projects to clearly understand, extend, and override options within their metro.config.js file as the source of truth.
  • Logically, locates the config for using Metro with React Native within the React Native repo — where we can set baseline defaults that are inherited by other tooling (e.g. both RN CLI and Expo).
  • The previous setup meant that the resolved Metro configuration was hidden, preventing standalone Metro CLI commands from being runnable.
  • Removes existing noise from the template config.
  • Moves us closer to shipping Metro updates and bugfixes independent of the CLI.

User-side change: Default metro.config.js file in a new React Native project

We will also signal the need to update existing metro.config.js files in the release blog post.

BeforeAfter
imageimage
⚠️ Config contains user overrides only, will be overridden by defaults set by React Native CLI.✅ Complete Metro config is defined by extending react-native/metro-config.
⚠️ Config contains stale defaults that were split across the template and RN CLI.✅ Both RN CLI and metro CLI will read the same config.
✅ Dynamic/extended config will continue to be applied by RN CLI on top of these.
✅ User-defined config object is cleaned up.

Plan

  1. ➡️ This PR: Create a new package within facebook/react-native, @react-native/metro-config, to contain the default Metro config for React Native projects going forward.
  2. Update React Native app template to define an updated metro.config.js extending the new config package.
  3. (Depends on the above two changes) breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72) react-native-community/cli#1875

Note: Changes in this repo (1, 2) will be compatible with the current version of RN CLI on main — the only breaking change is that the new CLI will not be able to support RN projects without these changes.

Changes

  • This PR adds the new @react-native/metro-config package which reproduces all static values previously defined in RN CLI.
    • The values not included, which remain in RN CLI, are dynamic values derived from CLI options passed by the user.

Test Plan (all PRs + incoming changes)

E2E expectation: The new config is non-breaking against old CLI, the new CLI is breaking against old config.

Pre-steps

With the relevant repos cloned:

.
└── Development/forks
├── react-native # huntie/react-native@export-D44099692
└── react-native-cli # huntie/react-native-cli@c53e49b
  1. cd Development/forks/react-native/packages/rn-tester/
  2. Copy over metro.config.js and package.json changes from react-native/template/ (next commit in stack).
  3. Run yarn.

[Base case] React Native @ main (this stack, before new CLI is merged — non-breaking)
(template = new, CLI = old)

yarn start

✅ Works (new complete Metro config is read into RN CLI, and overridden by its previous defaults — for this reason we can't delete ./rn-get-polyfills.js yet!)

yarn metro get-dependencies --entry-file js/RNTesterApp.android.js --platform android

✅ Works (new complete Metro config is available to Metro CLI)

[Release state] React Native 0.72 (new CLI, new config required)
(template = new, CLI = new)

  1. Use (cd ../..; yarn link @react-native-community/cli-plugin-metro) to substitute version of @react-native-community/cli-plugin-metro using cloned react-native-cli directory.
  2. Run yarn.
  3. Update watchFolders (see Metro Local Development Setup).
yarn start

image

✅ Works (new complete Metro config is read into RN CLI, and merged with sparser defaults in react-native-community/cli#1875)
- (Note console logs)
- Note: At the point this test was run, found a small unrelated bug (post monorepo land) where rn-tester would look for a metro.config.js at the repo root and not inside packages/rn-tester/ — hence an extra /metro.config.js file was added in the above screenshot. This will be re-tested in the commit when we bump RN CLI.

Changelog:
[General][Added] Add react-native/metro-config package

Differential Revision: D44099692

@facebook-github-botfacebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 16, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@analysis-bot

analysis-bot commented Mar 16, 2023

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,519,193+0
androidhermesarmeabi-v7a7,834,776+0
androidhermesx868,999,081+0
androidhermesx86_648,854,121+0
androidjscarm64-v8a9,141,838+0
androidjscarmeabi-v7a8,333,472+0
androidjscx869,196,418+0
androidjscx86_649,454,245+0

Base commit: 0eff8d6
Branch: main

Comment threadpackages/metro-config/index.js Outdated

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is the only base config divergence: ['android', 'ios'] here matches the default RN repo setup. As before, this will be overridden by RN CLI based on the platforms CLI argument.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 399bfb21b49200e7d53c9d358c64607f4091847d
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@huntie

Copy link
Copy Markdown
CollaboratorAuthor

Changes to metro.config.js files within the template and rn-tester are prepared and will be shipped shortly after this PR (as we need to publish the new package first).

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM on the React Native side of things

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Mar 21, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 745cdb1.

cipolleschi pushed a commit that referenced this pull request Mar 28, 2023
Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 672a67e19d866ac2c64fc84983b5d82c604918c6
cipolleschi added a commit that referenced this pull request Mar 28, 2023
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
Co-authored-by: Alex Hunt <alexeh@meta.com>
resolved: #36502
facebook-github-bot pushed a commit that referenced this pull request Mar 30, 2023
Summary:
Pull Request resolved: #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 (#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: #36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2024
…41836)
Summary:
This adds `react-native/metro-config` to the monorepo build tool and emits the missing typescript declarations.
Right now, we do have typescript declarations on `metro-config`, but not `react-native/metro-config`. Which makes everything a bit harder extend from "[the default React Native metro config](#36502)" in Expo.
> Note, I also added the same `exports` block from `react-native/dev-middleware` for conformity.
One open question here is, why aren't we exporting _all_ helper functions from `metro-config`? To me, its a bit weird that we need both `metro-config` _and_ `react-native/metro-config` as `loadConfig` isn't exported.
## Changelog:
[INTERNAL] [FIXED] - Emit typescript declaration files for `react-native/metro-config`
Pull Request resolved: #41836
Test Plan:
Run the build tool, and check if the typescript declarations are emitted for `react-native/metro-config`.
```
yarn build metro-config
```
Reviewed By: hoxyq
Differential Revision: D51943453
Pulled By: huntie
fbshipit-source-id: cfaffe5660053fc9a9fcbe3dacf7f6ccc2bde01b
blakef pushed a commit to blakef/template that referenced this pull request Feb 28, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huntie@facebook-github-bot@analysis-bot@cortinico
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' RFC: Add @react-native/metro-config package by huntie · Pull Request #36502 · react/react-native · GitHub
Skip to content

RFC: Add @react-native/metro-config package - #36502

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692
Closed

RFC: Add @react-native/metro-config package#36502
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692

Conversation

@huntie

@huntiehuntie commented Mar 16, 2023

Copy link
Copy Markdown
Collaborator

Summary:

Context

React Native Metro config → React Native repo

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.

Motivation

Today, the Metro config required to use React Native is entangled within react-native-community/cli-plugin-metro and is not readable from within a project. We instead want to relocate the default Metro config into the React Native repo and have users explicitly inherit this config in their projects.

BeforeAfter
imageimage
Note: CLI change will be breaking, to explicitly target React Native 0.72 and onwards

Benefits

  • Allows projects to clearly understand, extend, and override options within their metro.config.js file as the source of truth.
  • Logically, locates the config for using Metro with React Native within the React Native repo — where we can set baseline defaults that are inherited by other tooling (e.g. both RN CLI and Expo).
  • The previous setup meant that the resolved Metro configuration was hidden, preventing standalone Metro CLI commands from being runnable.
  • Removes existing noise from the template config.
  • Moves us closer to shipping Metro updates and bugfixes independent of the CLI.

User-side change: Default metro.config.js file in a new React Native project

We will also signal the need to update existing metro.config.js files in the release blog post.

BeforeAfter
imageimage
⚠️ Config contains user overrides only, will be overridden by defaults set by React Native CLI.✅ Complete Metro config is defined by extending react-native/metro-config.
⚠️ Config contains stale defaults that were split across the template and RN CLI.✅ Both RN CLI and metro CLI will read the same config.
✅ Dynamic/extended config will continue to be applied by RN CLI on top of these.
✅ User-defined config object is cleaned up.

Plan

  1. ➡️ This PR: Create a new package within facebook/react-native, @react-native/metro-config, to contain the default Metro config for React Native projects going forward.
  2. Update React Native app template to define an updated metro.config.js extending the new config package.
  3. (Depends on the above two changes) breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72) react-native-community/cli#1875

Note: Changes in this repo (1, 2) will be compatible with the current version of RN CLI on main — the only breaking change is that the new CLI will not be able to support RN projects without these changes.

Changes

  • This PR adds the new @react-native/metro-config package which reproduces all static values previously defined in RN CLI.
    • The values not included, which remain in RN CLI, are dynamic values derived from CLI options passed by the user.

Test Plan (all PRs + incoming changes)

E2E expectation: The new config is non-breaking against old CLI, the new CLI is breaking against old config.

Pre-steps

With the relevant repos cloned:

.
└── Development/forks
├── react-native # huntie/react-native@export-D44099692
└── react-native-cli # huntie/react-native-cli@c53e49b
  1. cd Development/forks/react-native/packages/rn-tester/
  2. Copy over metro.config.js and package.json changes from react-native/template/ (next commit in stack).
  3. Run yarn.

[Base case] React Native @ main (this stack, before new CLI is merged — non-breaking)
(template = new, CLI = old)

yarn start

✅ Works (new complete Metro config is read into RN CLI, and overridden by its previous defaults — for this reason we can't delete ./rn-get-polyfills.js yet!)

yarn metro get-dependencies --entry-file js/RNTesterApp.android.js --platform android

✅ Works (new complete Metro config is available to Metro CLI)

[Release state] React Native 0.72 (new CLI, new config required)
(template = new, CLI = new)

  1. Use (cd ../..; yarn link @react-native-community/cli-plugin-metro) to substitute version of @react-native-community/cli-plugin-metro using cloned react-native-cli directory.
  2. Run yarn.
  3. Update watchFolders (see Metro Local Development Setup).
yarn start

image

✅ Works (new complete Metro config is read into RN CLI, and merged with sparser defaults in react-native-community/cli#1875)
- (Note console logs)
- Note: At the point this test was run, found a small unrelated bug (post monorepo land) where rn-tester would look for a metro.config.js at the repo root and not inside packages/rn-tester/ — hence an extra /metro.config.js file was added in the above screenshot. This will be re-tested in the commit when we bump RN CLI.

Changelog:
[General][Added] Add react-native/metro-config package

Differential Revision: D44099692

@facebook-github-botfacebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 16, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@analysis-bot

analysis-bot commented Mar 16, 2023

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,519,193+0
androidhermesarmeabi-v7a7,834,776+0
androidhermesx868,999,081+0
androidhermesx86_648,854,121+0
androidjscarm64-v8a9,141,838+0
androidjscarmeabi-v7a8,333,472+0
androidjscx869,196,418+0
androidjscx86_649,454,245+0

Base commit: 0eff8d6
Branch: main

Comment threadpackages/metro-config/index.js Outdated

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is the only base config divergence: ['android', 'ios'] here matches the default RN repo setup. As before, this will be overridden by RN CLI based on the platforms CLI argument.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 399bfb21b49200e7d53c9d358c64607f4091847d
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@huntie

Copy link
Copy Markdown
CollaboratorAuthor

Changes to metro.config.js files within the template and rn-tester are prepared and will be shipped shortly after this PR (as we need to publish the new package first).

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM on the React Native side of things

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Mar 21, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 745cdb1.

cipolleschi pushed a commit that referenced this pull request Mar 28, 2023
Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 672a67e19d866ac2c64fc84983b5d82c604918c6
cipolleschi added a commit that referenced this pull request Mar 28, 2023
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
Co-authored-by: Alex Hunt <alexeh@meta.com>
resolved: #36502
facebook-github-bot pushed a commit that referenced this pull request Mar 30, 2023
Summary:
Pull Request resolved: #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 (#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: #36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2024
…41836)
Summary:
This adds `react-native/metro-config` to the monorepo build tool and emits the missing typescript declarations.
Right now, we do have typescript declarations on `metro-config`, but not `react-native/metro-config`. Which makes everything a bit harder extend from "[the default React Native metro config](#36502)" in Expo.
> Note, I also added the same `exports` block from `react-native/dev-middleware` for conformity.
One open question here is, why aren't we exporting _all_ helper functions from `metro-config`? To me, its a bit weird that we need both `metro-config` _and_ `react-native/metro-config` as `loadConfig` isn't exported.
## Changelog:
[INTERNAL] [FIXED] - Emit typescript declaration files for `react-native/metro-config`
Pull Request resolved: #41836
Test Plan:
Run the build tool, and check if the typescript declarations are emitted for `react-native/metro-config`.
```
yarn build metro-config
```
Reviewed By: hoxyq
Differential Revision: D51943453
Pulled By: huntie
fbshipit-source-id: cfaffe5660053fc9a9fcbe3dacf7f6ccc2bde01b
blakef pushed a commit to blakef/template that referenced this pull request Feb 28, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huntie@facebook-github-bot@analysis-bot@cortinico
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); RFC: Add @react-native/metro-config package by huntie · Pull Request #36502 · react/react-native · GitHub
Skip to content

RFC: Add @react-native/metro-config package - #36502

Closed
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692
Closed

RFC: Add @react-native/metro-config package#36502
huntie wants to merge 1 commit into
react:mainfrom
huntie:export-D44099692

Conversation

@huntie

@huntiehuntie commented Mar 16, 2023

Copy link
Copy Markdown
Collaborator

Summary:

Context

React Native Metro config → React Native repo

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.

Motivation

Today, the Metro config required to use React Native is entangled within react-native-community/cli-plugin-metro and is not readable from within a project. We instead want to relocate the default Metro config into the React Native repo and have users explicitly inherit this config in their projects.

BeforeAfter
imageimage
Note: CLI change will be breaking, to explicitly target React Native 0.72 and onwards

Benefits

  • Allows projects to clearly understand, extend, and override options within their metro.config.js file as the source of truth.
  • Logically, locates the config for using Metro with React Native within the React Native repo — where we can set baseline defaults that are inherited by other tooling (e.g. both RN CLI and Expo).
  • The previous setup meant that the resolved Metro configuration was hidden, preventing standalone Metro CLI commands from being runnable.
  • Removes existing noise from the template config.
  • Moves us closer to shipping Metro updates and bugfixes independent of the CLI.

User-side change: Default metro.config.js file in a new React Native project

We will also signal the need to update existing metro.config.js files in the release blog post.

BeforeAfter
imageimage
⚠️ Config contains user overrides only, will be overridden by defaults set by React Native CLI.✅ Complete Metro config is defined by extending react-native/metro-config.
⚠️ Config contains stale defaults that were split across the template and RN CLI.✅ Both RN CLI and metro CLI will read the same config.
✅ Dynamic/extended config will continue to be applied by RN CLI on top of these.
✅ User-defined config object is cleaned up.

Plan

  1. ➡️ This PR: Create a new package within facebook/react-native, @react-native/metro-config, to contain the default Metro config for React Native projects going forward.
  2. Update React Native app template to define an updated metro.config.js extending the new config package.
  3. (Depends on the above two changes) breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72) react-native-community/cli#1875

Note: Changes in this repo (1, 2) will be compatible with the current version of RN CLI on main — the only breaking change is that the new CLI will not be able to support RN projects without these changes.

Changes

  • This PR adds the new @react-native/metro-config package which reproduces all static values previously defined in RN CLI.
    • The values not included, which remain in RN CLI, are dynamic values derived from CLI options passed by the user.

Test Plan (all PRs + incoming changes)

E2E expectation: The new config is non-breaking against old CLI, the new CLI is breaking against old config.

Pre-steps

With the relevant repos cloned:

.
└── Development/forks
├── react-native # huntie/react-native@export-D44099692
└── react-native-cli # huntie/react-native-cli@c53e49b
  1. cd Development/forks/react-native/packages/rn-tester/
  2. Copy over metro.config.js and package.json changes from react-native/template/ (next commit in stack).
  3. Run yarn.

[Base case] React Native @ main (this stack, before new CLI is merged — non-breaking)
(template = new, CLI = old)

yarn start

✅ Works (new complete Metro config is read into RN CLI, and overridden by its previous defaults — for this reason we can't delete ./rn-get-polyfills.js yet!)

yarn metro get-dependencies --entry-file js/RNTesterApp.android.js --platform android

✅ Works (new complete Metro config is available to Metro CLI)

[Release state] React Native 0.72 (new CLI, new config required)
(template = new, CLI = new)

  1. Use (cd ../..; yarn link @react-native-community/cli-plugin-metro) to substitute version of @react-native-community/cli-plugin-metro using cloned react-native-cli directory.
  2. Run yarn.
  3. Update watchFolders (see Metro Local Development Setup).
yarn start

image

✅ Works (new complete Metro config is read into RN CLI, and merged with sparser defaults in react-native-community/cli#1875)
- (Note console logs)
- Note: At the point this test was run, found a small unrelated bug (post monorepo land) where rn-tester would look for a metro.config.js at the repo root and not inside packages/rn-tester/ — hence an extra /metro.config.js file was added in the above screenshot. This will be re-tested in the commit when we bump RN CLI.

Changelog:
[General][Added] Add react-native/metro-config package

Differential Revision: D44099692

@facebook-github-botfacebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner fb-exported labels Mar 16, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

1 similar comment
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@analysis-bot

analysis-bot commented Mar 16, 2023

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a8,519,193+0
androidhermesarmeabi-v7a7,834,776+0
androidhermesx868,999,081+0
androidhermesx86_648,854,121+0
androidjscarm64-v8a9,141,838+0
androidjscarmeabi-v7a8,333,472+0
androidjscx869,196,418+0
androidjscx86_649,454,245+0

Base commit: 0eff8d6
Branch: main

Comment threadpackages/metro-config/index.js Outdated

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is the only base config divergence: ['android', 'ios'] here matches the default RN repo setup. As before, this will be overridden by RN CLI based on the platforms CLI argument.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 399bfb21b49200e7d53c9d358c64607f4091847d
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D44099692

@huntie

Copy link
Copy Markdown
CollaboratorAuthor

Changes to metro.config.js files within the template and rn-tester are prepared and will be shipped shortly after this PR (as we need to publish the new package first).

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM on the React Native side of things

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Mar 21, 2023
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 745cdb1.

cipolleschi pushed a commit that referenced this pull request Mar 28, 2023
Summary:
Changelog:
[General][Added] - Add `react-native/metro-config` package
Pull Request resolved: #36502
## Context
### React Native Metro config → React Native repo (#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 here: #36502
## Changes
- This PR adds the new `react-native/metro-config` package, reproduces all static values previously defined in RN CLI. The values which remain in RN CLI are dynamic values derived from CLI options passed by the user.
{F906910591}
Reviewed By: cortinico
Differential Revision: D44099692
fbshipit-source-id: 672a67e19d866ac2c64fc84983b5d82c604918c6
cipolleschi added a commit that referenced this pull request Mar 28, 2023
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
Co-authored-by: Alex Hunt <alexeh@meta.com>
resolved: #36502
facebook-github-bot pushed a commit that referenced this pull request Mar 30, 2023
Summary:
Pull Request resolved: #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 (#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: #36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
facebook-github-bot pushed a commit that referenced this pull request Feb 12, 2024
…41836)
Summary:
This adds `react-native/metro-config` to the monorepo build tool and emits the missing typescript declarations.
Right now, we do have typescript declarations on `metro-config`, but not `react-native/metro-config`. Which makes everything a bit harder extend from "[the default React Native metro config](#36502)" in Expo.
> Note, I also added the same `exports` block from `react-native/dev-middleware` for conformity.
One open question here is, why aren't we exporting _all_ helper functions from `metro-config`? To me, its a bit weird that we need both `metro-config` _and_ `react-native/metro-config` as `loadConfig` isn't exported.
## Changelog:
[INTERNAL] [FIXED] - Emit typescript declaration files for `react-native/metro-config`
Pull Request resolved: #41836
Test Plan:
Run the build tool, and check if the typescript declarations are emitted for `react-native/metro-config`.
```
yarn build metro-config
```
Reviewed By: hoxyq
Differential Revision: D51943453
Pulled By: huntie
fbshipit-source-id: cfaffe5660053fc9a9fcbe3dacf7f6ccc2bde01b
blakef pushed a commit to blakef/template that referenced this pull request Feb 28, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
blakef pushed a commit to react-native-community/template that referenced this pull request Feb 29, 2024
Summary:
Pull Request resolved: react/react-native#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 (react/react-native#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: react/react-native#36502
## Changes
NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#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
Original-Commit: react/react-native@c5a47ab
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.fb-exportedMergedThis PR has been merged.p: FacebookPartner: FacebookPartner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@huntie@facebook-github-bot@analysis-bot@cortinico