-
Notifications
You must be signed in to change notification settings - Fork 343
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(package.json): Provide correct types for moduleResolution: node, node10, and node16 #16
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This is actually intended behavior. (exports will be overriden when it is packed into a tarball) Closing this pull request for the reason. |
@raon0211 because of this point, I made this Pull Request. I want to check why we need to override exports field with publishConfig. For testing or developing this package correctly, if we should use this package in another workspace in this repo or any other places, In my opinion, we should use built JavaScript files, not TypeScript files, to use same files with library users. because TypeScript file can be transpiled differently depending on the user's environment. so I want to ensure that library maintainer and library users use same files, and I believe that is an important point in the process of developing a library. |
In my opinion, when this package is published, library users only see the built JavaScript file, not the TypeScript code. Therefore, all library users interact with the JavaScript code, not the TypeScript. I believe the issue arises only when we use the es-toolkit library within this workspace. However, the TypeScript files will be transpiled consistently, and they cannot be transpiled differently across user environments, since we control all the compile options within this workspace. Additionally, using TypeScript directly greatly simplifies the development process. For instance, we don't have to build JavaScript every time we change the source code. Personally, I think this is the direction the JavaScript ecosystem is heading. We have the types as comments proposal in TC39 (as a language spec), and some JavaScript runtimes like Deno natively support TypeScript. What do you think? |
Thanks, I understood why you want to override exports field with publishConfig. I reverted it in 3281a7a but we should fix these errors https://arethetypeswrong.github.io/?p=es-toolkit%401.0.2. types field is required in my opinion to support TypeScript users. |
Thanks for your recommendation for arethetypeswrong.io! I nearly fixed our type imports as the following image. However it is notoriously difficult to fix the "masquerading as CJS" part (since the dual package itself is difficult and adding TypeScript greatly messes it up); I guess this should be fixed with either we integrate tshy (which is not PnP ready) or we go ESM only (after the release of Node.js 22). |
Co-authored-by: Jonghyeon Ko <jonghyeon@toss.im>
Co-authored-by: Jonghyeon Ko <jonghyeon@toss.im>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
Wait a moment! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raon0211 Let's fix attw errors..!
"types": "./dist/index.d.ts", | ||
"import": "./esm/index.mjs", | ||
"require": "./dist/index.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However it is notoriously difficult to fix the "masquerading as CJS" part; I guess this should be fixed with either we integrate tshy (which is not PnP ready) or we go ESM only (after the release of Node.js 22).
In my opnion, this may fix our errors. I learned this way fixing from maintaining @suspensive/react to support cjs, esm for all environments
"types": "./dist/index.d.ts", | |
"import": "./esm/index.mjs", | |
"require": "./dist/index.js" | |
"import": { | |
"types": "./dist/index.d.ts", | |
"default": "./esm/index.mjs" | |
}, | |
"require": { | |
"types": "./dist/index.d.ts", | |
"default": "./dist/index.js" | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it doesn't, because in order to be a "ESM" declaration,
- The type's extension should be
.mts
(and TypeScript's cli does not support changing extensions of declarations) - And for each type declaration (e.g. in
./esm/index.d.mts
), we have to specify extensions in its type.
-export * from './array';
+export * from './array/index.mjs';
However this is notoriously difficult in current TypeScript environments unless we introduce some good libraries like tshy. Meanwhile tshy does not support Yarn PnP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then How about using tsup? I think tsup support this quite easily!
https://github.com/suspensive/react/blob/main/packages/react/package.json#L28-L36
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@raon0211 Fast merging to fix TypeScript error and next Pull Request for tsup is also good for me. If you agree tsup way, I'll make new Pull Request for this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually tsup does not support our usecase neither.
In order to be tree-shaken well, it is necessary for us to use code splitting. However I find that tsup (and its internal implemenation, esbuild) does not support code splitting properly as rollup's preserveModules
.
For example, while rollup completely splits our JavaScript files like this:
esbuild's splitting
option only makes some chunks and does not split our project files completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we might try just using tsup's declaration generation...
Will merge this pull request, and will handle integration of tsup as a seperate one. Thanks for your contribution! |
Hello @raon0211 ! |
I left comments to share intentions