bunchee icon indicating copy to clipboard operation
bunchee copied to clipboard

feat: no-dts option

Open hyoban opened this issue 2 years ago • 5 comments

fix #454

hyoban avatar Feb 18 '24 14:02 hyoban

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.

hyoban avatar Feb 19 '24 06:02 hyoban

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.

devjiwonchoi avatar Feb 19 '24 17:02 devjiwonchoi

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

hyoban avatar Feb 20 '24 01:02 hyoban

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.

devjiwonchoi avatar Feb 20 '24 01:02 devjiwonchoi

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

hyoban avatar Feb 20 '24 01:02 hyoban

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!

huozhi avatar Mar 03 '24 20:03 huozhi