unbuild
unbuild copied to clipboard
fix(cjs): include `d.ts` cjs transformation when cjs package
Right now, we're generating wrong CJS d.ts files based on declaration option and we shoud check the package is NOT ESM ; we only need to transform d.ts files when type !== module.
/cc @pio
Check unjs/destr below and this gh repro: https://github.com/userquin/destr-consola-test
unjs/destr
unjs/destr
unjs/destr at arethetypeswrong
unjs/destr/package.json
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
unjs/destr exports
Some problems when using require, looks like we need the namespace creation. I'm going to check esm, but it should work (creating esm branch in the gh repo).
Arrrgg, it is working, I need to run tsc && node ./src/index.cjs:
node ./src/index.cjs
{ foo: 'bar' }
Works with both, node and node16 module resolution:
"module": "Node16",
"moduleResolution": "node16",
and
"module": "CommonJS",
"moduleResolution": "node",
NOTE: added build, build:node16 and typecheck:node16 script in the gh repro.