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

Implement require.unstable_importMaybeSync and use it in JSResource #1296

Closed
wants to merge 1 commit into from

Conversation

rubennorte
Copy link
Contributor

Summary:
This implements require.unstable_importMaybeSync, a new API to avoid having to wait for the next tick when importing a value using dynamic import() in bundles that don't use bundle splitting.

This API behaves this way:

  • If the app is using bundle splitting, require.unstable_importMaybeSync() behaves exactly like import(). It always returns a promise and it marks a split point for the bundle.
  • If the app isn't using bundle splitting, it behaves like a static import (e.g.: import * as module from 'module') and returns the exports for that module synchronously.

This isn't meant to be used by users directly but to build other more specific APIs on top of this.

It includes a small refactor to asyncRequire.js.

Differential Revision: D58873729

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 21, 2024
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

rubennorte added a commit to rubennorte/metro that referenced this pull request Jun 21, 2024
…acebook#1296)

Summary:
Pull Request resolved: facebook#1296

This implements `require.unstable_importMaybeSync`, a new API to avoid having to wait for the next tick when importing a value using dynamic `import()` in bundles that don't use bundle splitting.

This API behaves this way:
* If the app is using bundle splitting, `require.unstable_importMaybeSync()` behaves exactly like `import()`. It always returns a promise and it marks a split point for the bundle.
* If the app isn't using bundle splitting, it behaves like a static import (e.g.: `import * as module from 'module'`) and returns the exports for that module synchronously.

This isn't meant to be used by users directly but to build other more specific APIs on top of this.

It includes a small refactor to `asyncRequire.js`.

Differential Revision: D58873729
@facebook-github-bot
Copy link
Contributor

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

rubennorte added a commit to rubennorte/metro that referenced this pull request Jun 21, 2024
…acebook#1296)

Summary:
Pull Request resolved: facebook#1296

This implements `require.unstable_importMaybeSync`, a new API to avoid having to wait for the next tick when importing a value using dynamic `import()` in bundles that don't use bundle splitting.

This API behaves this way:
* If the app is using bundle splitting, `require.unstable_importMaybeSync()` behaves exactly like `import()`. It always returns a promise and it marks a split point for the bundle.
* If the app isn't using bundle splitting, it behaves like a static import (e.g.: `import * as module from 'module'`) and returns the exports for that module synchronously.

This isn't meant to be used by users directly but to build other more specific APIs on top of this.

It includes a small refactor to `asyncRequire.js`.

Differential Revision: D58873729
@codecov-commenter
Copy link

codecov-commenter commented Jun 21, 2024

Codecov Report

Attention: Patch coverage is 83.78378% with 6 lines in your changes missing coverage. Please review.

Project coverage is 83.83%. Comparing base (28e7ac2) to head (86ecf52).

Files Patch % Lines
...etro/src/ModuleGraph/worker/collectDependencies.js 86.11% 5 Missing ⚠️
packages/metro-transform-worker/src/index.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1296      +/-   ##
==========================================
- Coverage   83.83%   83.83%   -0.01%     
==========================================
  Files         207      207              
  Lines       10847    10880      +33     
  Branches     2716     2731      +15     
==========================================
+ Hits         9094     9121      +27     
- Misses       1753     1759       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@facebook-github-bot
Copy link
Contributor

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

rubennorte added a commit to rubennorte/metro that referenced this pull request Jun 21, 2024
…acebook#1296)

Summary:
Pull Request resolved: facebook#1296

This implements `require.unstable_importMaybeSync`, a new API to avoid having to wait for the next tick when importing a value using dynamic `import()` in bundles that don't use bundle splitting.

This API behaves this way:
* If the app is using bundle splitting, `require.unstable_importMaybeSync()` behaves exactly like `import()`. It always returns a promise and it marks a split point for the bundle.
* If the app isn't using bundle splitting, it behaves like a static import (e.g.: `import * as module from 'module'`) and returns the exports for that module synchronously.

This isn't meant to be used by users directly but to build other more specific APIs on top of this.

It includes a small refactor to `asyncRequire.js`.

Differential Revision: D58873729
rubennorte added a commit to rubennorte/metro that referenced this pull request Jun 24, 2024
…acebook#1296)

Summary:
Pull Request resolved: facebook#1296

This implements `require.unstable_importMaybeSync`, a new API to avoid having to wait for the next tick when importing a value using dynamic `import()` in bundles that don't use bundle splitting.

This API behaves this way:
* If the app is using bundle splitting, `require.unstable_importMaybeSync()` behaves exactly like `import()`. It always returns a promise and it marks a split point for the bundle.
* If the app isn't using bundle splitting, it behaves like a static import (e.g.: `import * as module from 'module'`) and returns the exports for that module synchronously.

This isn't meant to be used by users directly but to build other more specific APIs on top of this.

It includes a small refactor to `asyncRequire.js`.

Reviewed By: motiz88

Differential Revision: D58873729
@facebook-github-bot
Copy link
Contributor

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

1 similar comment
@facebook-github-bot
Copy link
Contributor

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

rubennorte added a commit to rubennorte/metro that referenced this pull request Jun 24, 2024
…acebook#1296)

Summary:
Pull Request resolved: facebook#1296

This implements `require.unstable_importMaybeSync`, a new API to avoid having to wait for the next tick when importing a value using dynamic `import()` in bundles that don't use bundle splitting.

This API behaves this way:
* If the app is using bundle splitting, `require.unstable_importMaybeSync()` behaves exactly like `import()`. It always returns a promise and it marks a split point for the bundle.
* If the app isn't using bundle splitting, it behaves like a static import (e.g.: `import * as module from 'module'`) and returns the exports for that module synchronously.

This isn't meant to be used by users directly but to build other more specific APIs on top of this.

It includes a small refactor to `asyncRequire.js`.

Reviewed By: motiz88

Differential Revision: D58873729
…acebook#1296)

Summary:
Pull Request resolved: facebook#1296

This implements `require.unstable_importMaybeSync`, a new API to avoid having to wait for the next tick when importing a value using dynamic `import()` in bundles that don't use bundle splitting.

This API behaves this way:
* If the app is using bundle splitting, `require.unstable_importMaybeSync()` behaves exactly like `import()`. It always returns a promise and it marks a split point for the bundle.
* If the app isn't using bundle splitting, it behaves like a static import (e.g.: `import * as module from 'module'`) and returns the exports for that module synchronously.

This isn't meant to be used by users directly but to build other more specific APIs on top of this.

It includes a small refactor to `asyncRequire.js`.

Reviewed By: motiz88

Differential Revision: D58873729
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 7b2ca5e.

@rubennorte rubennorte deleted the export-D58873729 branch June 26, 2024 23:22
EvanBacon added a commit to expo/expo that referenced this pull request Aug 1, 2024
…e it in JSResource (#30703)

# Why

- Mirror feature from metro facebook/metro#1296

# Test Plan

- Pulled in upstream tests.
- Tree shaking tests should also continue to work.

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
amandeepmittal pushed a commit to expo/expo that referenced this pull request Aug 5, 2024
…e it in JSResource (#30703)

# Why

- Mirror feature from metro facebook/metro#1296

# Test Plan

- Pulled in upstream tests.
- Tree shaking tests should also continue to work.

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants