Skip to content

Add "exports" field to use-sync-external-store's package.json #24440

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/use-sync-external-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

'use strict';

export {useSyncExternalStore} from './src/useSyncExternalStore';
Copy link
Collaborator

@eps1lon eps1lon Sep 10, 2022

Choose a reason for hiding this comment

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

This file is used internally. The published entrypoints are in npm/ which can continue using relative imports.

export {useSyncExternalStore} from 'use-sync-external-store/src/useSyncExternalStore';
9 changes: 9 additions & 0 deletions packages/use-sync-external-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"shim/",
"cjs/"
],
"exports": {
".": "./index.js",
"./with-selector": "./with-selector.js",
"./shim": "./shim/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on

Suggested change
"./shim": "./shim/index.js",
"./shim": {
"react-native": "./shim/index.native.js",
"default": "./shim/index.js"
},

?

That way all code can just be use-sync-external-store/shim.

note that this relies on the bundler actually supporting exports and supplying react-native condition (which I'm guessing metro at least doesn't do), but it seems more future-proof than these (seemingly) somewhat random exports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

facebook/metro#670
Metro doesn't respect exports field at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, so no issue.

This stanza should still work for any modern bundler, and metro whenever it enters the future

Copy link
Collaborator

Choose a reason for hiding this comment

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

There's Repack to consider (basically Webpack for react-native) so we might as well get this in now. Doing it in the future might be considered another breaking change.

"./shim/index.native": "./shim/index.native.js",
"./shim/with-selector": "./shim/with-selector.js",
"./src/*": "./src/*",
Copy link
Collaborator

@eps1lon eps1lon Sep 10, 2022

Choose a reason for hiding this comment

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

Wouldn't this require changing the publish script? The latest version of uSES publishes no src folder (see https://unpkg.com/browse/use-sync-external-store@1.2.0/). What are you currently importing with use-sync-external-store/src/??

Copy link
Contributor Author

@latin-1 latin-1 Sep 11, 2022

Choose a reason for hiding this comment

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

It seems that the react package has this line.

"./src/*": "./src/*"

"./package.json": "./package.json"
},
"license": "MIT",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
Expand Down