huozhi / bunchee

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

feat: no-dts option #458

Closed hyoban closed 9 months ago

hyoban commented 9 months ago

fix #454

hyoban commented 9 months ago

Don't know how to use arg to distinguish between undefined and false. So i keep no-dts option in cli, but merge it with dts.

devjiwonchoi commented 9 months ago

Since for TS projects, currently bunchee is always generating d.ts regardless of CLI args like --dts false. We could check if dts is nullish and set to true if hasTsConfig exists, and make sure to not run the typesJobs if dts is falsy.

// better to use const
dts ??= Boolean(hasTsConfig)

//...

const typesJobs = dts
    ? (await buildEntryConfig(options, buildContext, true)).map(
        (rollupConfig) => bundleOrWatch(rollupConfig),
      )
    : []

In this case we can decide not to generate d.ts on TS projects by --dts false while preserving other behaviors.

hyoban commented 9 months ago

Note that Boolean and [Boolean] have special treatment - an option argument is not consumed or passed, but instead true is returned. These options are called "flags".

It seems we can not let arg to receive --dts false

devjiwonchoi commented 9 months ago

I see.. I was expecting the behavior of --declaration in tsc.

IMO expanding the --no-<arg> family might not be the best option, but seems reasonable at the moment.

hyoban commented 9 months ago

Can i take a look at other cli arg parser? (If we do not want a --no-dts option)

huozhi commented 9 months ago

We already have the --no-dts option value, so we can check it first. I pushed a refactor commit aligning with how we handled others like --no-external.

It looks good now! Thank you both for the PR and the discussion above!