Skip to content

Custom option to specify destinations of inlined deps #902

@fuma-nama

Description

@fuma-nama

Clear and concise description of the problem

Currently, the inlined deps under unbundle mode will be transpiled to dist/node_modules/.... If not taken extra care when specifying the files field in package.json, npm pack may omit the nested node_modules.

e.g.

import { defineConfig } from 'tsdown';

export default defineConfig({
  format: 'esm',
  target: 'es2023',
  platform: 'browser',
  unbundle: true,
  dts: true,
  deps: {
    onlyBundle: ['react-medium-image-zoom'],
  },
});

if the files field is defined as follows:

{
  "files": [
    "dist/*"
  ]
}

When running npm pack, the node_modules folder containing react-medium-image-zoom will be omitted. It must be dist (without the glob) to avoid the original issue.

It would be great to allow custom destination paths for the inlined deps, this makes tsdown more customisable and allows cleaner & safer output.

Suggested solution

A deps.outDirs option with [dep_name: string] : string pairs, like:

{ "react-medium-image-zoom": "./dist/react-medium-image-zoom" }

It allows developers to specify a output directory for inlined deps.

Alternative

No response

Additional context

I was surprised to know glob in files field will make a difference in npm pack, I think the default can be adjusted to avoid special folder names like node_modules, although probably need extra discussions on this.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions