Skip to content

Detect 'types' fields nested in "exports" #885

@dmurvihill

Description

@dmurvihill

Reproduction link or steps

import { defineConfig } from "tsdown";

export default defineConfig({
  entry: "index.ts",
  fixedExtension: false,
  format: {
    esm: {
      outDir: "esm/",
    },
    cjs: {
      outDir: "cjs/",
    },
  },
});

package.json:

{
  "exports": {
    ".": {
      "import": {
        "default": "./esm/index.js",
        "types": "./esm/index.d.ts"
      },
      "require": {
        "default": "./cjs/index.cjs",
        "types": "./cjs/index.d.cts"
      }
    }
  }
}

What is expected?

The construct above should be enough for tsdown to generate types.

What is actually happening?

Types are not generated, since it only looks for types or typings at the top level.

Any additional comments?

One subtlety: if the "." entry contains a "types" field, but the "require" entry does not contain a "types" field, the types should be generated for one module but not the other. Tricky tricky.

Metadata

Metadata

Assignees

No one assigned

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions