huozhi / bunchee

Zero config bundler for ECMAScript and TypeScript packages
https://npmjs.com/bunchee
926 stars 29 forks source link

`export { version } from "pkg/package.json"` results in invalid d.ts files #467

Closed juliusmarminge closed 7 months ago

juliusmarminge commented 7 months ago

Repro: https://github.com/juliusmarminge/bunchee-export-pkgjson

export { version } from "../package.json";

generates the following d.ts files:

var version = "1.0.0";

export { version };

which is invalid: CleanShot 2024-02-28 at 13 48 58@2x

I think it should be

declare const version = "1.0.0";

export { version };

?

juliusmarminge commented 7 months ago

Somewhat workaround:

import * as pkgJson from "../package.json";

export const version = pkgJson.version;

which generates

// .js
var version$1 = "1.0.0";

const version = version$1;

export { version };

// .d.ts
declare const version: string;

export { version };
huozhi commented 7 months ago

Looks like because you put "module": "index.ts", in the package.json and it's being picked up as ESM output, which breaks the code. I rewrote the exports handling and added a test in #470 , it looks good. Let's verify it with incoming release 🙏

huozhi commented 7 months ago

Fixed in 5.0.0-beta.1