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

fix: remove exports["."].module to be compatible with resolution policy of nodejs offical & bundlers like vite #13

Merged
merged 3 commits into from
Feb 2, 2024

Conversation

indooorsman
Copy link
Contributor

@indooorsman indooorsman commented Jan 31, 2024

some build tools like vite would fail if type of package is not explicit declared while file extension is .js:

image

@dai-shi please help review, thanks

Copy link

codesandbox-ci bot commented Jan 31, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 220b353:

Sandbox Source
React Configuration
React TypeScript Configuration

package.json Outdated
@@ -19,7 +19,7 @@
"./package.json": "./package.json",
".": {
"types": "./dist/src/index.d.ts",
"module": "./dist/index.modern.js",
"module": "./dist/index.modern.mjs",
Copy link
Member

Choose a reason for hiding this comment

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

It was intentional to have .js, otherwise it will break in some old bundlers.
Now, time passed. I think if this causes a problem, we should remove it entirely.

Suggested change
"module": "./dist/index.modern.mjs",

Does that fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi yes, it does fix.

Or could we add "type": "module" to package.json? this can also fix this issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was intentional to have .js, otherwise it will break in some old bundlers. Now, time passed. I think if this causes a problem, we should remove it entirely.

does that old bundler consume exports field? what I changed is only the one in exports field, the module field is kept as it is now

Copy link
Member

Choose a reason for hiding this comment

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

"type": "module" might also break old bundlers. We keep cjs default for all jotai packages.

Now, would you be willing to fix more jotaijs/* packages? Some of them are not actively maintained. If the repo is migrated to pnpm from yarn, it means it's maintained.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi I find another solution, we can just reorder the keys of exports["."], please review latest commit

Copy link
Member

Choose a reason for hiding this comment

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

The order was important for a bundler to pick "module" before "import".
So, instead of reordering, let's remove it.

Alright, let's wait for other contributors for other repos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌 I've removed it

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.
Can you also remove "postcompile" script because we no longer need it?

Copy link
Contributor Author

@indooorsman indooorsman Feb 2, 2024

Choose a reason for hiding this comment

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

Thanks. Can you also remove "postcompile" script because we no longer need it?

I don't think so as "module": "./dist/index.modern.js" at Line 16 is not removed

Copy link
Member

Choose a reason for hiding this comment

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

Oh, nice catch. Yeah, that might be good for very old bundlers (though, I'm not sure if we need to keep supporting it.)

@indooorsman indooorsman changed the title fix: change exports[.].module to .mjs as package type is not explicit declared fix: reorder exports["."] to be compatible with resolution policy of nodejs offical & bundlers like vite Jan 31, 2024
@indooorsman indooorsman changed the title fix: reorder exports["."] to be compatible with resolution policy of nodejs offical & bundlers like vite fix: remove exports["."].module to be compatible with resolution policy of nodejs offical & bundlers like vite Feb 1, 2024
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Thanks!

@dai-shi dai-shi merged commit eccd37f into jotaijs:main Feb 2, 2024
2 checks passed
@dai-shi
Copy link
Member

dai-shi commented Feb 2, 2024

Published: https://www.npmjs.com/package/jotai-optics/v/0.3.2

@indooorsman indooorsman deleted the fix_exports_module branch February 2, 2024 04:04
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.

2 participants