unbuild icon indicating copy to clipboard operation
unbuild copied to clipboard

fix(cjs): include `d.ts` cjs transformation when cjs package

Open userquin opened this issue 8 months ago • 1 comments

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

image unjs/destr

image unjs/destr at arethetypeswrong

image 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

userquin avatar Apr 03 '25 22:04 userquin

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.

userquin avatar Apr 03 '25 22:04 userquin