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

[BREAKING] feat: make resolver preset follow Metro defaults closely #525

Merged
merged 11 commits into from
Apr 4, 2024

Conversation

jbroma
Copy link
Member

@jbroma jbroma commented Mar 18, 2024

Summary

BREAKING CHANGE:

getResolveOptions is now way more compatible with metro-resolver and @react-native/metro-config

  1. getResolveOptions now accepts a second optional parameter called options with the following properties:
    • enablePackageExports - defaults to false
    • preferNativePlatform - defaults to true
  2. Order of extensions was changed to match the order from @react-native/metro-config.
  3. Resolution via Package Exports (exports field in package.json) is now optional and disabled by default.
    It can now be enabled via getResolveOptions options parameter. This change was introduced to match metro defaults.
  4. Default conditionNames are now: ['require', 'import', 'react-native'] and match @react-native/metro-config defaults.

Remarks

Implementation passes every metro-compat test with the following exceptions in package-exports-test:

  • should resolve "exports" target directly > without expanding sourceExts - test should be marked as [nonstrict] as it relies on unsupported fallback mechanism
  • should resolve "exports" target directly > without expanding platform-specific extensions - test should be marked as [nonstrict] as it relies on unsupported fallback mechanism
  • subpath exports > should expand array of strings as subpath mapping (root shorthand) - this spec is not compliant with Node spec and should be fixed upstream as it's original purpose was to match Node spec.
  • subpath patterns > should resolve subpath patterns in "exports" matching import specifier - one of the examples in the test is bad - Bar.js should not be exposed by the package according to the Node spec, but instead fallback to using less specific specifier. This mechanism is used to restrict imports in packages and should be fixed upstream

Checklist

  • - rework implementation of getResolveOptions
  • - adjust JSDoc
  • - ensure TypeDoc compiles and displays new descriptions properly
  • - add tests from Remarks to skipped ones

Test plan

  • - pass selected metro-compat tests

Copy link

changeset-bot bot commented Mar 18, 2024

🦋 Changeset detected

Latest commit: 930a9a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@callstack/repack Major
testerapp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jbroma jbroma changed the base branch from v4 to fix-resolution-setup March 18, 2024 16:52
@jbroma jbroma force-pushed the fix/resolve-options branch from 230bb31 to b06e469 Compare March 18, 2024 17:26
@jbroma jbroma requested a review from RafikiTiki March 20, 2024 13:09
Base automatically changed from fix-resolution-setup to v4 April 2, 2024 13:35
@jbroma jbroma force-pushed the fix/resolve-options branch from b06e469 to 4ecf0cc Compare April 2, 2024 14:08
@jbroma jbroma marked this pull request as ready for review April 2, 2024 14:08
@thymikee
Copy link
Member

thymikee commented Apr 4, 2024

What are possible migration paths, or differences in resolve behaviors that users could bump into unintentionally? This also shows some promise to remove now unnecessary webpack config overrides, can we provide some examples of what this means for the users in regards what can possibly change in their config?

@jbroma
Copy link
Member Author

jbroma commented Apr 4, 2024

What are possible migration paths, or differences in resolve behaviours that users could bump into unintentionally?

The only real difference is that Package Exports support is now disabled by default. There might be packages out there that don't declare main field and only use exports field, but it's super rare (e.g. @react-native/dev-middleware). In this case this could be a breaking change. Until now users needed to override resolution via alias to get it to work (or disabling usage of package exports), or they relied on exports entrypoint.

This also shows some promise to remove now unnecessary webpack config overrides, can we provide some examples of what this means for the users in regards what can possibly change in their config?

We still need to override the webpack config defaults, nothing changes in this regard. The API of getResolveOptions is extended in a non-breaking way, with proper defaults in place 👍

@jbroma
Copy link
Member Author

jbroma commented Apr 4, 2024

Order of extensions now matches @react-native/metro-config 1:1, updated PR description & changeset to reflect that, thanks @thymikee for spotting this 👍

@thymikee thymikee changed the title [BREAKING] fix: resolve options [BREAKING] fix: make resolver more compatible with Metro defaults Apr 4, 2024
@jbroma jbroma changed the title [BREAKING] fix: make resolver more compatible with Metro defaults [BREAKING] feat: make resolver preset follow Metro defaults closely Apr 4, 2024
@jbroma jbroma merged commit 0ca2d97 into v4 Apr 4, 2024
3 checks passed
@jbroma jbroma deleted the fix/resolve-options branch April 4, 2024 14:10
jbroma added a commit that referenced this pull request Apr 5, 2024
…525)

* fix: getResolveOptions implementation

* chore: add some additional descriptions

* refactor: don't use default initializer, improve JSDoc

* chore: make sure typedoc/jsdoc looks good

* chore: add descriptive changeset

* fix: mark options as optional

* fix: align behaviour of conditions by platform in tests

* refactor: add more tests to skip in metro-compat-test

* test: enable metro-compat-test on CI

* feat: use the same order of extensions as metro

* chore: update changeset
jbroma added a commit that referenced this pull request Apr 5, 2024
…525)

* fix: getResolveOptions implementation

* chore: add some additional descriptions

* refactor: don't use default initializer, improve JSDoc

* chore: make sure typedoc/jsdoc looks good

* chore: add descriptive changeset

* fix: mark options as optional

* fix: align behaviour of conditions by platform in tests

* refactor: add more tests to skip in metro-compat-test

* test: enable metro-compat-test on CI

* feat: use the same order of extensions as metro

* chore: update changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants