Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

declaration option is not work when package.json set exports.types #380

Closed
s3xysteak opened this issue Mar 28, 2024 · 1 comment
Closed

Comments

@s3xysteak
Copy link
Contributor

s3xysteak commented Mar 28, 2024

Environment

  • Node.js: v20.10.0
  • pnpm: v8.15.5
  • unbuild: v2.0.0

Reproduction

See minirepo.

Describe the bug

The option declaration do not do anything because in the end it will be set according to exports in package.json.

Describe Bug

declaration: false will not work:

import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
  declaration: false,
})

When in package.json:

{
  "exports": {
    "types": "./dist/index.d.ts",
    "import": "./dist/index.mjs",
    "require": "./dist/index.cjs"
  },
}

The declaration will be set true if the values of exports contains any files named *.d.(m|c)?ts in package.json.

Also, because of the same reason, declaration: 'node16' can not work too, it is same as true instead of the description in comments.

More details refer to:

ctx.options.declaration = res.dts;

dts = true;

Discussion

The problem is whether it is a bug or a deliberate design. I think when declaration is set as false explicitly, it should be false. It is counter-intuitive that set it as false but it still work. So in my option, user-initiated actions should have the highest priority.

Additional context

To fix it, refer to:

ctx.options.declaration = res.dts;

If declaration is not undefined, it should use what user provided.

I am glad to provide a PR for that!

Logs

No response

@s3xysteak
Copy link
Contributor Author

Duplicate #339 #313. Will be fixed in #314 .

@s3xysteak s3xysteak closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant