-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: generate barrel entrypoints for cjs / node module resolutions #435
Comments
Yea that's possible. however it's also emitting the code change that might need to be added into Before we can handle that you can use sth like this to configure your package.json ".": {
"import": {
"types": "./dist/es/index.d.mts",
"default": "./dist/es/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"./subpath": {
"import": {
"types": "./subpath/index.d.mts",
"default": "./subpath/index.mjs"
},
"require": {
"types": "./subpath/index.d.ts",
"default": "./subpath/index.js"
}
} Then add |
Not sure i understand. Users should be able to import from like I encountered this yesterday when consuming a package in expo |
If you look at the case of "./subpath": {
"import": {
"types": "./subpath/index.d.mts",
"default": "./subpath/index.mjs"
},
"require": {
"types": "./subpath/index.d.ts",
"default": "./subpath/index.js"
}
} It's able to extend to |
I dont think thats correct. Node10 module resolution doesnt look at package.json#exports, so the files have to exist from root. This is not the case when files are bundled in ./dist/** |
Oh i see now you're not proposing bundling in dist... |
Yeah if the dist files are existing in subdirectory, and those can also be used for exports field to referring to, also directly accessing by directory path |
Still feel like there's some DX optimizations to be made here, since now it's a lot of stuff that must be setup each time I need to make changes here:
The attached script i've written for trpc handles all of these, all I need to do is to add the new entrypoint in the # Ignore all folders except `src/` in every published package
packages/*/*/
!packages/*/src/
!packages/*/test/ Last step is obviously not related to bunchee, but it'd be cool if it could somehow perform some of these steps for me. Could {
"./foo": {
"import": {
"types": "./foo/index.d.mts",
"default": "./foo/index.mjs",
},
"require": { ... }
}
} as well as adding |
when using the node module resolution, it's "hard" to support multiple entrypoints. The
main/module/types
field in package json may point to a dist file, but any other entrypoints must be relative to pacakge root. ( this is solved in modern configurations using the package.json#exports that's supported with moduleResolution >= Node16 )in trpc, we have this script that generates these entrypoints based on the package.json#exports field, for example:
given
the following files will be generated (see trpc bundled code here: https://www.npmjs.com/package/@trpc/server/v/11.0.0-next-beta.242?activeTab=code):
to support older module resolutions
what do you think of
bunchee --prepare
would generate these files?The text was updated successfully, but these errors were encountered: