Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: define "react-native" community condition #45367

Merged
merged 1 commit into from
Nov 28, 2022
Merged

doc: define "react-native" community condition #45367

merged 1 commit into from
Nov 28, 2022

Conversation

huntie
Copy link
Contributor

@huntie huntie commented Nov 7, 2022

I'm a React Native maintainer working on Metro, our first-party JavaScript bundler. Here I'm proposing the inclusion of a "react-native" condition under the "Community Conditions Definitions" section of Node's docs.

This is linked to our framework proposal for package exports support: react-native-community/discussions-and-proposals#534.

Why this condition is needed

React Native is a popular platform within the JS ecosystem, where code can be executed in non-browser environments, such as our Hermes JavaScript engine. When package maintainers want to target React Native, we have historically provided a top-level "react-native" root field within package.json — which was an extension of the "browser" field spec (now itself a community condition).

e.g. Used by pusher-js:

image

As with "browser", we are aiming to translate "react-native" to the conditional exports concept.

What the "react-native" condition will represent

These are unchanged from current use of the "react-native" root field.

  • Modules are being required by a React Native app.
  • JavaScript code will be executed under the Hermes or JavaScriptCore runtimes, or a web browser.
  • Modules are most likely being loaded under Metro and babel-preset-react-native.

What will change when this is used as a condition via "exports":

  • Because "exports" allows packages to define the order of conditional exports, package maintainers will have more fine-grained control over what is selected for their package (e.g. matching before, or after, "browser").

Prior usage

Use of "react-native" root field

This is a popular feature and is used by both React Native-specific libraries and larger multiplatform libraries (such as the above pusher-js example). Searching across GitHub, use of the top-level "react-native" field for specifying alternate source files is present in ~20k repositories.

image

Use of "react-native" package exports condition

Webpack already lists "react-native" under its docs for Package exports, which is enabled when configured by the user or in templates under React Native projects.

image

From this we can infer there is independent desire for such a condition, and perhaps limited use today. The definition it provides is "TBD", leaving us to provide the concrete and canonical definition with this PR.

How we teach this

Once "exports" support is ready in Metro:

  • We will update the primary template for new React Native libraries: create-react-native-library.
  • We aim to publish a Metro/React Native website blog post with an upgrade guide for package maintainers.

With the merging of this PR:

  • Package maintainers can optionally get their packages ready for conditional exports in React Native using the documented definition, which we are set on.
    • This will work in Webpack today, but not Metro (until support is shipped).

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/modules

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label Nov 7, 2022
@huntie huntie marked this pull request as ready for review November 7, 2022 18:05
@GeoffreyBooth
Copy link
Member

There’s a spec in progress for this: nodejs/tooling#166. I assume we should defer to that spec? cc @nodejs/tsc @guybedford

@ljharb
Copy link
Member

ljharb commented Nov 8, 2022

+1, but this submission aligns with it so far afaict.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

generically +1, with the WinterCG caveat

@huntie
Copy link
Contributor Author

huntie commented Nov 8, 2022

There’s a spec in progress for this: nodejs/tooling#166. I assume we should defer to that spec? cc @nodejs/tsc @guybedford

@GeoffreyBooth Thanks for raising, we also gave input on the WinterCG spec. Worth noting that "react-native" is subtly different in that context:

  • WinterCG runtime key
    Describes JS runtime environments, therefore represents React Native JS runtimes on native platforms only (Hermes and JavaScriptCore) — and not in browsers via React Native for Web.
  • "exports" condition (this submission)
    Represents React Native projects and matches all runtime platforms (native and web). This is motivated by 1) giving package maintainers control over inclusively matching "react-native" before/after "browser", and 2) consistency with our previous package.json field concept.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@huntie
Copy link
Contributor Author

huntie commented Nov 28, 2022

Hi all, is this good to merge? :)

@RaisinTen RaisinTen added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 28, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 28, 2022
@nodejs-github-bot nodejs-github-bot merged commit d09f0c4 into nodejs:main Nov 28, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in d09f0c4

@huntie huntie deleted the react-native-community-condition branch November 28, 2022 15:50
ErickWendel pushed a commit to ErickWendel/node that referenced this pull request Nov 30, 2022
PR-URL: nodejs#45367
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Dec 12, 2022
PR-URL: #45367
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
PR-URL: #45367
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Dec 30, 2022
PR-URL: #45367
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Jan 3, 2023
PR-URL: #45367
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Jan 4, 2023
PR-URL: #45367
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
danielleadams pushed a commit that referenced this pull request Jan 5, 2023
PR-URL: #45367
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.