tsdown 0.22.3 → 0.22.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1129 @@
1
+ import { a as Arrayable, c as Overwrite, n as LogLevel, o as Awaitable, r as Logger, s as MarkPartial, t as PackageJson } from "./index-4SbnPhas.mjs";
2
+ import { BuildOptions, ChecksOptions, ExternalOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, ModuleTypes, OutputAsset, OutputChunk, OutputOptions, Plugin, RolldownPlugin, TreeshakingOptions } from "rolldown";
3
+ import { Hookable } from "hookable";
4
+ import { Buffer } from "node:buffer";
5
+ import { StartOptions } from "@vitejs/devtools/cli-commands";
6
+ import { ExeExtensionOptions } from "@tsdown/exe";
7
+ import { CheckPackageOptions } from "@arethetypeswrong/core";
8
+ import { Options } from "publint";
9
+ import { CssOptions } from "@tsdown/css";
10
+ import { Options as Options$1 } from "rolldown-plugin-dts";
11
+ import { Options as UnusedOptions } from "unplugin-unused";
12
+ //#region src/features/copy.d.ts
13
+ interface CopyEntry {
14
+ /**
15
+ * Source path or glob pattern.
16
+ */
17
+ from: string | string[];
18
+ /**
19
+ * Destination path.
20
+ * If not specified, defaults to the output directory ("outDir").
21
+ */
22
+ to?: string;
23
+ /**
24
+ * Whether to flatten the copied files (not preserving directory structure).
25
+ *
26
+ * @default true
27
+ */
28
+ flatten?: boolean;
29
+ /**
30
+ * Output copied items to console.
31
+ * @default false
32
+ */
33
+ verbose?: boolean;
34
+ /**
35
+ * Change destination file or folder name.
36
+ */
37
+ rename?: string | ((name: string, extension: string, fullPath: string) => string);
38
+ }
39
+ type CopyOptions = Arrayable<string | CopyEntry>;
40
+ type CopyOptionsFn = (options: ResolvedConfig) => Awaitable<CopyOptions>;
41
+ //#endregion
42
+ //#region src/utils/chunks.d.ts
43
+ type RolldownChunk = (OutputChunk | OutputAsset) & {
44
+ outDir: string;
45
+ };
46
+ type ChunksByFormat = Partial<Record<NormalizedFormat, RolldownChunk[]>>;
47
+ interface TsdownBundle extends AsyncDisposable {
48
+ chunks: RolldownChunk[];
49
+ config: ResolvedConfig;
50
+ inlinedDeps: Map<string, Set<string>>;
51
+ }
52
+ //#endregion
53
+ //#region src/features/deps.d.ts
54
+ type NoExternalFn = (id: string, importer: string | undefined) => boolean | null | undefined | void;
55
+ interface DepsConfig {
56
+ /**
57
+ * Mark dependencies as external (not bundled).
58
+ * Accepts strings, regular expressions, or Rolldown's
59
+ * {@linkcode ExternalOption}.
60
+ */
61
+ neverBundle?: ExternalOption;
62
+ /**
63
+ * Force dependencies to be bundled, even if they are in `dependencies`, `peerDependencies`, or `optionalDependencies`.
64
+ */
65
+ alwaysBundle?: Arrayable<string | RegExp> | NoExternalFn;
66
+ /**
67
+ * Whitelist of dependencies allowed to be bundled from `node_modules`.
68
+ * Throws an error if any unlisted dependency is bundled.
69
+ *
70
+ * - `undefined` (default): Show warnings for bundled dependencies.
71
+ * - `false`: Suppress all warnings about bundled dependencies.
72
+ *
73
+ * Note: Be sure to include all required sub-dependencies as well.
74
+ */
75
+ onlyBundle?: Arrayable<string | RegExp> | false;
76
+ /**
77
+ * @deprecated Use {@linkcode onlyBundle} instead.
78
+ */
79
+ onlyAllowBundle?: Arrayable<string | RegExp> | false;
80
+ /**
81
+ * Skip bundling all `node_modules` dependencies.
82
+ *
83
+ * **Note:** This option cannot be used together with {@linkcode alwaysBundle}.
84
+ *
85
+ * @default false
86
+ */
87
+ skipNodeModulesBundle?: boolean;
88
+ /**
89
+ * Override dependency bundling options for declaration file generation.
90
+ */
91
+ dts?: Pick<DepsConfig, "alwaysBundle" | "neverBundle">;
92
+ }
93
+ interface ResolvedDepsConfig {
94
+ neverBundle?: ExternalOption;
95
+ alwaysBundle?: NoExternalFn;
96
+ onlyBundle?: Array<string | RegExp> | false;
97
+ skipNodeModulesBundle: boolean;
98
+ /**
99
+ * Override dependency bundling options for declaration file generation.
100
+ */
101
+ dts: Pick<ResolvedDepsConfig, "alwaysBundle" | "neverBundle">;
102
+ }
103
+ declare function DepsPlugin({ pkg, deps: { alwaysBundle: jsAlwaysBundle, onlyBundle, skipNodeModulesBundle, dts }, logger, nameLabel }: ResolvedConfig, tsdownBundle: TsdownBundle): Plugin;
104
+ //#endregion
105
+ //#region src/features/devtools.d.ts
106
+ interface DevtoolsOptions extends NonNullable<InputOptions["devtools"]> {
107
+ /**
108
+ * **[experimental]** Enable devtools integration. `@vitejs/devtools` must be installed as a dependency.
109
+ *
110
+ * Defaults to true, if `@vitejs/devtools` is installed.
111
+ */
112
+ ui?: boolean | Partial<StartOptions>;
113
+ /**
114
+ * Clean devtools stale sessions.
115
+ *
116
+ * @default true
117
+ */
118
+ clean?: boolean;
119
+ }
120
+ //#endregion
121
+ //#region src/features/exe.d.ts
122
+ interface ExeOptions extends ExeExtensionOptions {
123
+ seaConfig?: Omit<SeaConfig, "main" | "output" | "mainFormat">;
124
+ /**
125
+ * Output file name without any suffix or extension.
126
+ * For example, do not include `.exe`, platform suffixes, or architecture suffixes.
127
+ */
128
+ fileName?: string | ((chunk: RolldownChunk) => string);
129
+ /**
130
+ * Output directory for executables.
131
+ * @default 'build'
132
+ */
133
+ outDir?: string;
134
+ }
135
+ /**
136
+ * See also [Node.js SEA Documentation](https://nodejs.org/api/single-executable-applications.html#generating-single-executable-applications-with---build-sea)
137
+ *
138
+ * Note some default values are different from Node.js defaults to optimize for typical use cases (e.g. disabling experimental warning, enabling code cache). These can be overridden.
139
+ */
140
+ interface SeaConfig {
141
+ main?: string;
142
+ /**
143
+ * Optional, if not specified, uses the current Node.js binary
144
+ */
145
+ executable?: string;
146
+ output?: string;
147
+ /**
148
+ * @default tsdownConfig.format === 'es' ? 'module' : 'commonjs'
149
+ */
150
+ mainFormat?: "commonjs" | "module";
151
+ /**
152
+ * @default true
153
+ */
154
+ disableExperimentalSEAWarning?: boolean;
155
+ /**
156
+ * @default false
157
+ */
158
+ useSnapshot?: boolean;
159
+ /**
160
+ * @default false
161
+ */
162
+ useCodeCache?: boolean;
163
+ execArgv?: string[];
164
+ /**
165
+ * @default 'env'
166
+ */
167
+ execArgvExtension?: "none" | "env" | "cli";
168
+ assets?: Record<string, string>;
169
+ }
170
+ //#endregion
171
+ //#region src/features/hooks.d.ts
172
+ interface BuildContext {
173
+ options: ResolvedConfig;
174
+ hooks: Hookable<TsdownHooks>;
175
+ }
176
+ interface RolldownContext {
177
+ buildOptions: BuildOptions;
178
+ }
179
+ /**
180
+ * Hooks for tsdown.
181
+ */
182
+ interface TsdownHooks {
183
+ /**
184
+ * Invoked before each tsdown build starts.
185
+ * Use this hook to perform setup or preparation tasks.
186
+ */
187
+ "build:prepare": (ctx: BuildContext) => void | Promise<void>;
188
+ /**
189
+ * Invoked before each Rolldown build.
190
+ * For dual-format builds, this hook is called for each format.
191
+ * Useful for configuring or modifying the build context before bundling.
192
+ */
193
+ "build:before": (ctx: BuildContext & RolldownContext) => void | Promise<void>;
194
+ /**
195
+ * Invoked after each tsdown build completes.
196
+ * Use this hook for cleanup or post-processing tasks.
197
+ */
198
+ "build:done": (ctx: BuildContext & {
199
+ chunks: RolldownChunk[];
200
+ }) => void | Promise<void>;
201
+ }
202
+ //#endregion
203
+ //#region src/utils/package.d.ts
204
+ interface PackageJsonWithPath extends PackageJson {
205
+ packageJsonPath: string;
206
+ }
207
+ type PackageType = "module" | "commonjs" | undefined;
208
+ //#endregion
209
+ //#region src/features/output.d.ts
210
+ interface OutExtensionContext {
211
+ options: InputOptions;
212
+ format: NormalizedFormat;
213
+ /**
214
+ * `"type"` field in project's `package.json`.
215
+ */
216
+ pkgType?: PackageType;
217
+ }
218
+ interface OutExtensionObject {
219
+ js?: string;
220
+ dts?: string;
221
+ }
222
+ type OutExtensionFactory = (context: OutExtensionContext) => OutExtensionObject | undefined;
223
+ interface ChunkAddonObject {
224
+ js?: string;
225
+ css?: string;
226
+ dts?: string;
227
+ }
228
+ type ChunkAddonFunction = (ctx: {
229
+ format: Format;
230
+ fileName: string;
231
+ }) => ChunkAddonObject | string | undefined;
232
+ type ChunkAddon = ChunkAddonObject | ChunkAddonFunction | string;
233
+ //#endregion
234
+ //#region src/features/pkg/attw.d.ts
235
+ interface AttwOptions extends CheckPackageOptions {
236
+ module?: typeof import("@arethetypeswrong/core");
237
+ /**
238
+ * Profiles select a set of resolution modes to require/ignore. All are evaluated but failures outside
239
+ * of those required are ignored.
240
+ *
241
+ * The available profiles are:
242
+ * - `strict`: requires all resolutions
243
+ * - `node16`: ignores node10 resolution failures
244
+ * - `esm-only`: ignores CJS resolution failures
245
+ *
246
+ * @default 'strict'
247
+ */
248
+ profile?: "strict" | "node16" | "esm-only";
249
+ /**
250
+ * The level of the check.
251
+ *
252
+ * The available levels are:
253
+ * - `error`: fails the build
254
+ * - `warn`: warns the build
255
+ *
256
+ * @default 'warn'
257
+ */
258
+ level?: "error" | "warn";
259
+ /**
260
+ * List of problem types to ignore by rule name.
261
+ *
262
+ * The available values are:
263
+ * - `no-resolution`
264
+ * - `untyped-resolution`
265
+ * - `false-cjs`
266
+ * - `false-esm`
267
+ * - `cjs-resolves-to-esm`
268
+ * - `fallback-condition`
269
+ * - `cjs-only-exports-default`
270
+ * - `named-exports`
271
+ * - `false-export-default`
272
+ * - `missing-export-equals`
273
+ * - `unexpected-module-syntax`
274
+ * - `internal-resolution-error`
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * ignoreRules: ['no-resolution', 'false-cjs']
279
+ * ```
280
+ *
281
+ * @default []
282
+ *
283
+ * @uniqueItems
284
+ */
285
+ ignoreRules?: ("no-resolution" | "untyped-resolution" | "false-cjs" | "false-esm" | "cjs-resolves-to-esm" | "fallback-condition" | "cjs-only-exports-default" | "named-exports" | "false-export-default" | "missing-export-equals" | "unexpected-module-syntax" | "internal-resolution-error" | (string & {}))[];
286
+ }
287
+ //#endregion
288
+ //#region src/features/pkg/exports.d.ts
289
+ interface ExportsOptions {
290
+ /**
291
+ * Generate exports that link to source code during development.
292
+ * - `string`: add as a custom condition.
293
+ * - `true`: all conditions point to source files, and add `dist` exports to `publishConfig`.
294
+ */
295
+ devExports?: boolean | string;
296
+ /**
297
+ * Generate `exports` for `package.json` file.
298
+ *
299
+ * @example
300
+ * ```json
301
+ * {
302
+ * "exports": {
303
+ * ".": {
304
+ * "types": "./dist/index.d.mts",
305
+ * "import": "./dist/index.mjs"
306
+ * },
307
+ * "./package.json": "./package.json"
308
+ * }
309
+ * }
310
+ * ```
311
+ *
312
+ * @default true
313
+ */
314
+ packageJson?: boolean;
315
+ /**
316
+ * Generate `exports` for all files.
317
+ *
318
+ * @example
319
+ * ```json
320
+ * {
321
+ * "exports": {
322
+ * "./*": "./*"
323
+ * }
324
+ * }
325
+ * ```
326
+ *
327
+ * @default false
328
+ */
329
+ all?: boolean;
330
+ /**
331
+ * Specifies file patterns (as glob patterns or regular expressions) to exclude from package exports.
332
+ * Use this to prevent certain files from being included in the exported package, such as test files, binaries, or internal utilities.
333
+ *
334
+ * **Note:** Do not include file extensions, and paths should be relative to the dist directory.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * exclude: ['cli', '**\/*.test', /internal/]
339
+ * ```
340
+ */
341
+ exclude?: (RegExp | string)[];
342
+ /**
343
+ * Generate legacy fields (`main` and `module`) for older Node.js and bundlers
344
+ * that do not support package `exports` field.
345
+ *
346
+ * Defaults to false, if only ESM builds are included, true otherwise.
347
+ *
348
+ * @see {@link https://github.com/publint/publint/issues/24}
349
+ */
350
+ legacy?: boolean;
351
+ /**
352
+ * Specifies custom exports to add to the package exports in addition to the ones generated by tsdown.
353
+ * Use this to add additional exports in the exported package, such as workers or assets.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * customExports(exports) {
358
+ * exports['./worker.js'] = './dist/worker.js';
359
+ * return exports;
360
+ * }
361
+ * ```
362
+ *
363
+ * @example
364
+ * ```jsonc
365
+ * {
366
+ * "customExports": {
367
+ * "./worker.js": {
368
+ * "types": "./dist/worker.d.ts",
369
+ * "default": "./dist/worker.js"
370
+ * }
371
+ * }
372
+ * }
373
+ * ```
374
+ */
375
+ customExports?: Record<string, any> | ((exports: Record<string, any>, context: {
376
+ pkg: PackageJson;
377
+ chunks: ChunksByFormat;
378
+ isPublish: boolean;
379
+ }) => Awaitable<Record<string, any>>);
380
+ /**
381
+ * Generate `inlinedDependencies` field in `package.json`.
382
+ * Lists dependencies that are physically inlined into the bundle with their exact versions.
383
+ *
384
+ * @default true
385
+ * @see {@link https://github.com/e18e/ecosystem-issues/issues/237}
386
+ */
387
+ inlinedDependencies?: boolean;
388
+ /**
389
+ * Add file extensions to subpath export keys.
390
+ *
391
+ * When enabled, all subpath exports (except the root `"."`) will include
392
+ * a `.js` extension in the key (e.g., `"./utils.js"` instead of `"./utils"`).
393
+ *
394
+ * This follows the Node.js recommendation for subpath exports:
395
+ * @see {@link https://nodejs.org/api/packages.html#extensions-in-subpaths}
396
+ *
397
+ * @default false
398
+ */
399
+ extensions?: boolean;
400
+ /**
401
+ * Generate the `bin` field in `package.json` for CLI executables.
402
+ *
403
+ * Behavior depends on the value:
404
+ *
405
+ * - *Unset* (default): Soft auto-detect. Scans entry chunks for shebangs
406
+ * (e.g. `#!/usr/bin/env node`). If exactly one is found, it is used as
407
+ * the bin entry. If multiple are found, a warning is shown and no `bin`
408
+ * field is written. If none are found, nothing happens silently.
409
+ * - `true`: Strict auto-detect. Same as the default, but throws if
410
+ * multiple shebang entries are found, and warns if none are found.
411
+ * Use this when your package is known to ship a CLI and you want to
412
+ * fail fast on misconfiguration.
413
+ * - `false`: Disable bin generation entirely, even if shebangs are
414
+ * present.
415
+ * - `string`: Use the given source file path (relative to `cwd`) as the
416
+ * CLI entry. The command name is derived from the package name without
417
+ * its scope. Warns if the source file does not contain a shebang.
418
+ * - `Record<string, string>`: Explicitly map command names to source file
419
+ * paths (relative to `cwd`). Warns for each source file that does not
420
+ * contain a shebang.
421
+ *
422
+ * When {@link ExportsOptions.devExports} is enabled, the `bin` field in
423
+ * `package.json` points to source files during local development, while
424
+ * `publishConfig.bin` points to built output paths for publishing.
425
+ *
426
+ * @example
427
+ * <caption>Auto-detect a CLI entry from a shebang</caption>
428
+ *
429
+ * ```ts
430
+ * {
431
+ * bin: true
432
+ * }
433
+ * ```
434
+ *
435
+ * @example
436
+ * <caption>Single CLI command with an explicit source entry</caption>
437
+ *
438
+ * ```ts
439
+ * {
440
+ * bin: './src/cli.ts'
441
+ * }
442
+ * ```
443
+ *
444
+ * @example
445
+ * <caption>Multiple named CLI commands</caption>
446
+ *
447
+ * ```ts
448
+ * {
449
+ * bin: {
450
+ * tool: './src/cli.ts',
451
+ * serve: './src/cli-extra.ts',
452
+ * },
453
+ * }
454
+ * ```
455
+ *
456
+ * @see {@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin | npm documentation for the `bin` field}
457
+ */
458
+ bin?: boolean | string | Record<string, string>;
459
+ }
460
+ //#endregion
461
+ //#region src/features/pkg/publint.d.ts
462
+ interface PublintOptions extends Omit<Options, "pack" | "pkgDir"> {
463
+ module?: [typeof import("publint"), typeof import("publint/utils")];
464
+ }
465
+ //#endregion
466
+ //#region src/features/plugin.d.ts
467
+ /**
468
+ * A tsdown-aware plugin. Extends Rolldown's {@linkcode Plugin} with
469
+ * tsdown-specific lifecycle hooks.
470
+ *
471
+ * Plugins that only use Rolldown's own lifecycle continue to work unchanged;
472
+ * tsdown detects these optional methods via runtime duck-typing.
473
+ */
474
+ interface TsdownPlugin<A = any> extends Plugin<A> {
475
+ /**
476
+ * Modify tsdown's user config before it is resolved. Analogous to Vite's
477
+ * [`config`](https://vite.dev/guide/api-plugin.html#config) hook.
478
+ *
479
+ * The hook may mutate {@linkcode config} in place, or return a partial
480
+ * {@linkcode UserConfig} that will be deep-merged into the current config.
481
+ * Array fields are replaced (not concatenated) during merging — to append
482
+ * plugins, mutate {@linkcode UserConfig.plugins | config.plugins} in place.
483
+ *
484
+ * The second argument is the original {@linkcode InlineConfig} passed to
485
+ * {@linkcode build | build()} (typically the CLI flags), useful for
486
+ * distinguishing values that came from the command line vs. the config file.
487
+ *
488
+ * Plugins injected via {@linkcode UserConfig.fromVite | fromVite} do not
489
+ * receive this hook, because they are loaded after the
490
+ * {@linkcode tsdownConfig} phase. Likewise, new plugins added by another
491
+ * plugin's {@linkcode tsdownConfig} do not themselves receive this hook
492
+ * (plugins are snapshotted before dispatch).
493
+ */
494
+ tsdownConfig?: (config: UserConfig, inlineConfig: InlineConfig) => Awaitable<UserConfig | void | null>;
495
+ /**
496
+ * Called after tsdown has fully resolved the user config. Analogous to
497
+ * Vite's [`configResolved`](https://vite.dev/guide/api-plugin.html#configresolved)
498
+ * hook.
499
+ *
500
+ * This hook fires once per produced {@linkcode ResolvedConfig} — i.e. once
501
+ * per output format when {@linkcode UserConfig.format | format} is an array.
502
+ * Typical usage is to stash the resolved config for later use in
503
+ * Rolldown hooks. Mutations made to {@linkcode resolvedConfig} here are
504
+ * not supported.
505
+ */
506
+ tsdownConfigResolved?: (resolvedConfig: ResolvedConfig) => Awaitable<void>;
507
+ }
508
+ /**
509
+ * A tsdown plugin slot — accepts tsdown plugins, any Rolldown plugin form,
510
+ * `null`/`undefined`/`false`, {@linkcode Promise | promises}, and
511
+ * nested arrays. Mirrors Rolldown's {@linkcode RolldownPluginOption} but with
512
+ * {@linkcode TsdownPlugin} as the atom so that tsdown-specific hooks are
513
+ * type-checked.
514
+ */
515
+ type TsdownPluginOption<A = any> = Awaitable<TsdownPlugin<A> | RolldownPlugin<A> | {
516
+ name: string;
517
+ } | undefined | null | void | false | TsdownPluginOption<A>[]>;
518
+ //#endregion
519
+ //#region src/features/report.d.ts
520
+ interface ReportOptions {
521
+ /**
522
+ * Enable/disable gzip-compressed size reporting.
523
+ * Compressing large output files can be slow, so disabling this may increase build performance for large projects.
524
+ *
525
+ * @default true
526
+ */
527
+ gzip?: boolean;
528
+ /**
529
+ * Enable/disable brotli-compressed size reporting.
530
+ * Compressing large output files can be slow, so disabling this may increase build performance for large projects.
531
+ *
532
+ * @default false
533
+ */
534
+ brotli?: boolean;
535
+ /**
536
+ * Skip reporting compressed size for files larger than this size.
537
+ * @default 1_000_000 // 1 MB
538
+ */
539
+ maxCompressSize?: number;
540
+ }
541
+ declare function ReportPlugin(config: ResolvedConfig, cjsDts?: boolean, isDualFormat?: boolean): Plugin;
542
+ //#endregion
543
+ //#region src/config/types.d.ts
544
+ interface DtsOptions extends Options$1 {
545
+ /**
546
+ * When building dual ESM+CJS formats, generate a `.d.cts` re-export stub
547
+ * instead of running a full second TypeScript compilation pass.
548
+ *
549
+ * The stub re-exports everything from the corresponding `.d.mts` file,
550
+ * ensuring CJS and ESM consumers share the same type declarations. This
551
+ * eliminates the TypeScript "dual module hazard" where separate `.d.cts`
552
+ * and `.d.mts` declarations cause `TS2352` ("neither type sufficiently
553
+ * overlaps") errors when casting between types derived from the same class.
554
+ *
555
+ * Only applies when building both `esm` and `cjs` formats simultaneously.
556
+ *
557
+ * @remarks
558
+ * The generated `.d.cts` stub uses a relative path to re-export from the
559
+ * corresponding `.d.mts` file, so both formats must be emitted to the
560
+ * **same** `outDir`. Splitting CJS and ESM outputs into separate
561
+ * format-specific directories (e.g. `dist/cjs` and `dist/esm`) is not
562
+ * supported with this option, because the re-export path would be invalid.
563
+ *
564
+ * @default false
565
+ */
566
+ cjsReexport?: boolean;
567
+ }
568
+ type Sourcemap = boolean | "inline" | "hidden";
569
+ type Format = ModuleFormat;
570
+ type NormalizedFormat = InternalModuleFormat;
571
+ /**
572
+ * Extended input option that supports glob negation patterns.
573
+ *
574
+ * When using object form, values can be:
575
+ * - A single glob pattern string
576
+ * - An array of glob patterns, including negation patterns (prefixed with `!`)
577
+ *
578
+ * @example
579
+ * ```ts
580
+ * entry: {
581
+ * // Single pattern
582
+ * "utils/*": "./src/utils/*.ts",
583
+ * // Array with negation pattern to exclude files
584
+ * "hooks/*": ["./src/hooks/*.ts", "!./src/hooks/index.ts"],
585
+ * }
586
+ * ```
587
+ */
588
+ type TsdownInputOption = Arrayable<string | Record<string, Arrayable<string>>>;
589
+ interface Workspace {
590
+ /**
591
+ * Workspace directories. Glob patterns are supported.
592
+ * - `auto`: Automatically detect `package.json` files in the workspace.
593
+ * @default 'auto'
594
+ */
595
+ include?: "auto" | (string & {}) | string[];
596
+ /**
597
+ * Exclude directories from workspace.
598
+ * Defaults to all `node_modules`, `dist`, `test`, `tests`, `temp`, and `tmp` directories.
599
+ *
600
+ * @default ['**\/node_modules/**', '**\/dist/**', '**\/test?(s)/**', '**\/t?(e)mp/**']
601
+ */
602
+ exclude?: Arrayable<string>;
603
+ /**
604
+ * Path to the workspace configuration file.
605
+ */
606
+ config?: boolean | string;
607
+ }
608
+ type CIOption = "ci-only" | "local-only";
609
+ type WithEnabled<T> = boolean | undefined | CIOption | (T & {
610
+ /**
611
+ * @default true
612
+ */
613
+ enabled?: boolean | CIOption;
614
+ });
615
+ /**
616
+ * Options for tsdown.
617
+ */
618
+ interface UserConfig {
619
+ /**
620
+ * Defaults to `'src/index.ts'` if it exists.
621
+ *
622
+ * Supports glob patterns with negation to exclude files:
623
+ * @example
624
+ * ```ts
625
+ * entry: {
626
+ * "hooks/*": ["./src/hooks/*.ts", "!./src/hooks/index.ts"],
627
+ * }
628
+ * ```
629
+ *
630
+ * @default { index: 'src/index.ts'}
631
+ */
632
+ entry?: TsdownInputOption;
633
+ /**
634
+ * Dependency handling options.
635
+ */
636
+ deps?: DepsConfig;
637
+ /**
638
+ * @deprecated Use {@linkcode DepsConfig.neverBundle | deps.neverBundle} instead.
639
+ */
640
+ external?: ExternalOption;
641
+ /**
642
+ * @deprecated Use {@linkcode DepsConfig.alwaysBundle | deps.alwaysBundle} instead.
643
+ */
644
+ noExternal?: Arrayable<string | RegExp> | NoExternalFn;
645
+ /**
646
+ * @deprecated Use {@linkcode DepsConfig.onlyBundle | deps.onlyBundle} instead.
647
+ */
648
+ inlineOnly?: Arrayable<string | RegExp> | false;
649
+ /**
650
+ * @deprecated Use {@linkcode DepsConfig.skipNodeModulesBundle | deps.skipNodeModulesBundle} instead.
651
+ * @default false
652
+ */
653
+ skipNodeModulesBundle?: boolean;
654
+ alias?: Record<string, string>;
655
+ /**
656
+ * @default true
657
+ */
658
+ tsconfig?: string | boolean;
659
+ /**
660
+ * Specifies the target runtime platform for the build.
661
+ *
662
+ * - `node`: Node.js and compatible runtimes (e.g., Deno, Bun).
663
+ * For CJS format, this is always set to `node` and cannot be changed.
664
+ * - `neutral`: A platform-agnostic target with no specific runtime assumptions.
665
+ * - `browser`: Web browsers.
666
+ *
667
+ * @default 'node'
668
+ * @see https://tsdown.dev/options/platform
669
+ */
670
+ platform?: "node" | "neutral" | "browser";
671
+ /**
672
+ * Specifies the compilation target environment(s).
673
+ *
674
+ * Determines the JavaScript version or runtime(s) for which the code should be compiled.
675
+ * If not set, defaults to the value of `engines.node` in your project's `package.json`.
676
+ * If no `engines.node` field exists, no syntax transformations are applied.
677
+ *
678
+ * Accepts a single target (e.g., `'es2020'`, `'node18'`, `'baseline-widely-available'`), an array of targets, or `false` to disable all transformations.
679
+ *
680
+ * @see {@link https://tsdown.dev/options/target#supported-targets} for a list of valid targets and more details.
681
+ *
682
+ * @example
683
+ * ```jsonc
684
+ * // Target a single environment
685
+ * { "target": "node18" }
686
+ * ```
687
+ *
688
+ * @example
689
+ * ```jsonc
690
+ * // Target multiple environments
691
+ * { "target": ["node18", "es2020"] }
692
+ * ```
693
+ *
694
+ * @example
695
+ * ```jsonc
696
+ * // Disable all syntax transformations
697
+ * { "target": false }
698
+ * ```
699
+ */
700
+ target?: string | string[] | false;
701
+ /**
702
+ * Compile-time env variables, which can be accessed via `import.meta.env` or `process.env`.
703
+ * @example
704
+ * ```json
705
+ * {
706
+ * "DEBUG": true,
707
+ * "NODE_ENV": "production"
708
+ * }
709
+ * ```
710
+ *
711
+ * @default {}
712
+ */
713
+ env?: Record<string, any>;
714
+ /**
715
+ * Path to env file providing compile-time env variables.
716
+ * @example
717
+ * `.env`, `.env.production`, etc.
718
+ */
719
+ envFile?: string;
720
+ /**
721
+ * When loading env variables from `envFile`, only include variables with these prefixes.
722
+ * @default 'TSDOWN_'
723
+ */
724
+ envPrefix?: string | string[];
725
+ define?: Record<string, string>;
726
+ /**
727
+ * @default false
728
+ */
729
+ shims?: boolean;
730
+ /**
731
+ * Configure tree shaking options.
732
+ * @see {@link https://rolldown.rs/options/treeshake} for more details.
733
+ * @default true
734
+ */
735
+ treeshake?: boolean | TreeshakingOptions;
736
+ /**
737
+ * Sets how input files are processed.
738
+ * For example, use 'js' to treat files as JavaScript or 'base64' for images.
739
+ * Lets you import or require files like images or fonts.
740
+ * @example
741
+ * ```json
742
+ * { ".jpg": "asset", ".png": "base64" }
743
+ * ```
744
+ */
745
+ loader?: ModuleTypes;
746
+ /**
747
+ * Remove the `node:` prefix from built-in Node.js module imports.
748
+ * When enabled, rewrites import sources like `node:fs` to `fs`.
749
+ *
750
+ * @default false
751
+ * @deprecated Use {@linkcode nodeProtocol | nodeProtocol: 'strip'} instead.
752
+ *
753
+ * @example
754
+ * <caption>`removeNodeProtocol: true` — remove the `node:` prefix</caption>
755
+ *
756
+ * ```ts
757
+ * // Input
758
+ * import 'node:fs'
759
+ *
760
+ * // Output
761
+ * import 'fs'
762
+ * ```
763
+ */
764
+ removeNodeProtocol?: boolean;
765
+ /**
766
+ * Control whether built-in Node.js module imports use the `node:` protocol.
767
+ *
768
+ * - `true`: Add the `node:` prefix to built-in module imports.
769
+ * - `'strip'`: Remove the `node:` prefix from built-in module imports.
770
+ * - `false`: Do not transform built-in module imports.
771
+ *
772
+ * @default false
773
+ *
774
+ * @example
775
+ * <caption>`nodeProtocol: true` — add the `node:` prefix</caption>
776
+ *
777
+ * ```ts
778
+ * // Input
779
+ * import 'fs'
780
+ *
781
+ * // Output
782
+ * import 'node:fs'
783
+ * ```
784
+ *
785
+ * @example
786
+ * <caption>`nodeProtocol: 'strip'` — remove the `node:` prefix</caption>
787
+ *
788
+ * ```ts
789
+ * // Input
790
+ * import 'node:fs'
791
+ *
792
+ * // Output
793
+ * import 'fs'
794
+ * ```
795
+ *
796
+ * @example
797
+ * <caption>`nodeProtocol: false` — do not transform imports</caption>
798
+ *
799
+ * ```ts
800
+ * // Input
801
+ * import 'node:fs'
802
+ *
803
+ * // Output
804
+ * import 'node:fs'
805
+ * ```
806
+ */
807
+ nodeProtocol?: "strip" | boolean;
808
+ /**
809
+ * Controls which warnings are emitted during the build process. Each option can be set to `true` (emit warning) or `false` (suppress warning).
810
+ */
811
+ checks?: ChecksOptions & {
812
+ /**
813
+ * If the config includes the `cjs` format and
814
+ * one of its target >= node 20.19.0 / 22.12.0,
815
+ * warn the user about the deprecation of CommonJS.
816
+ *
817
+ * @default true
818
+ */
819
+ legacyCjs?: boolean;
820
+ };
821
+ plugins?: TsdownPluginOption;
822
+ /**
823
+ * Use with caution; ensure you understand the implications.
824
+ */
825
+ inputOptions?: InputOptions | ((options: InputOptions, format: NormalizedFormat, context: {
826
+ cjsDts: boolean;
827
+ }) => Awaitable<InputOptions | void | null>);
828
+ /**
829
+ * Output format(s). Available formats are
830
+ * - `esm`: ESM
831
+ * - `cjs`: CommonJS
832
+ * - `iife`: IIFE
833
+ * - `umd`: UMD
834
+ *
835
+ * @default 'esm'
836
+ */
837
+ format?: Format | Format[] | Partial<Record<Format, Partial<ResolvedConfig>>>;
838
+ globalName?: string;
839
+ /**
840
+ * @default 'dist'
841
+ */
842
+ outDir?: string;
843
+ /**
844
+ * Whether to write the files to disk.
845
+ * This option is incompatible with watch mode.
846
+ * @default true
847
+ */
848
+ write?: boolean;
849
+ /**
850
+ * Whether to generate source map files.
851
+ *
852
+ * Note that this option will always be `true` if you have
853
+ * {@link https://www.typescriptlang.org/tsconfig/#declarationMap | `declarationMap`}
854
+ * option enabled in your `tsconfig.json`.
855
+ *
856
+ * @default false
857
+ */
858
+ sourcemap?: Sourcemap;
859
+ /**
860
+ * Clean directories before build.
861
+ *
862
+ * Default to output directory.
863
+ * @default true
864
+ */
865
+ clean?: boolean | string[];
866
+ /**
867
+ * @default false
868
+ */
869
+ minify?: boolean | "dce-only" | MinifyOptions;
870
+ footer?: ChunkAddon;
871
+ banner?: ChunkAddon;
872
+ /**
873
+ * Determines whether `unbundle` is enabled.
874
+ * When set to `true`, the output files will mirror the input file structure.
875
+ * @default false
876
+ */
877
+ unbundle?: boolean;
878
+ /**
879
+ * Specifies the root directory of input files, similar to TypeScript's `rootDir`.
880
+ * This determines the output directory structure.
881
+ *
882
+ * By default, the root is computed as the common base directory of all entry files.
883
+ *
884
+ * @see https://www.typescriptlang.org/tsconfig/#rootDir
885
+ */
886
+ root?: string;
887
+ /**
888
+ * @deprecated Use {@linkcode unbundle} instead.
889
+ * @default true
890
+ */
891
+ bundle?: boolean;
892
+ /**
893
+ * Use a fixed extension for output files.
894
+ * The extension will always be `.cjs` or `.mjs`.
895
+ * Otherwise, it will depend on the package type.
896
+ *
897
+ * Defaults to `true` if {@linkcode platform} is set to `node`,
898
+ * `false` otherwise.
899
+ *
900
+ * @default platform === 'node'
901
+ */
902
+ fixedExtension?: boolean;
903
+ /**
904
+ * Custom extensions for output files.
905
+ * {@linkcode fixedExtension} will be overridden by this option.
906
+ */
907
+ outExtensions?: OutExtensionFactory;
908
+ /**
909
+ * @deprecated Use {@linkcode outExtensions} instead.
910
+ */
911
+ outExtension?: OutExtensionFactory;
912
+ /**
913
+ * If enabled, appends hash to chunk filenames.
914
+ * @default true
915
+ */
916
+ hash?: boolean;
917
+ /**
918
+ * @default true
919
+ */
920
+ cjsDefault?: boolean;
921
+ /**
922
+ * Use with caution; ensure you understand the implications.
923
+ */
924
+ outputOptions?: OutputOptions | ((options: OutputOptions, format: NormalizedFormat, context: {
925
+ cjsDts: boolean;
926
+ }) => Awaitable<OutputOptions | void | null>);
927
+ /**
928
+ * The working directory of the config file.
929
+ * - Defaults to {@linkcode process.cwd | process.cwd()} for root config.
930
+ * - Defaults to the package directory for {@linkcode workspace} config.
931
+ *
932
+ * @default process.cwd()
933
+ */
934
+ cwd?: string;
935
+ /**
936
+ * The name to show in CLI output. This is useful for monorepos or workspaces.
937
+ * When using workspace mode, this option defaults to the package name from package.json.
938
+ * In non-workspace mode, this option must be set explicitly for the name to show in the CLI output.
939
+ */
940
+ name?: string;
941
+ /**
942
+ * Log level.
943
+ * @default 'info'
944
+ */
945
+ logLevel?: LogLevel;
946
+ /**
947
+ * If true, fails the build on warnings.
948
+ * @default false
949
+ */
950
+ failOnWarn?: boolean | CIOption;
951
+ /**
952
+ * Custom logger.
953
+ */
954
+ customLogger?: Logger;
955
+ /**
956
+ * Reuse config from Vite or Vitest (experimental)
957
+ * @default false
958
+ */
959
+ fromVite?: boolean | "vitest";
960
+ /**
961
+ * @default false
962
+ */
963
+ watch?: boolean | Arrayable<string>;
964
+ /**
965
+ * Files or patterns to not watch while in watch mode.
966
+ */
967
+ ignoreWatch?: Arrayable<string | RegExp>;
968
+ /**
969
+ * **[experimental]** Enable devtools.
970
+ *
971
+ * DevTools is still under development, and this is for early testers only.
972
+ *
973
+ * This may slow down the build process significantly.
974
+ *
975
+ * @default false
976
+ */
977
+ devtools?: WithEnabled<DevtoolsOptions>;
978
+ /**
979
+ * You can specify command to be executed after a successful build, specially useful for Watch mode
980
+ */
981
+ onSuccess?: string | ((config: ResolvedConfig, signal: AbortSignal) => void | Promise<void>);
982
+ /**
983
+ * Enables generation of TypeScript declaration files (`.d.ts`).
984
+ *
985
+ * By default, this option is auto-detected based on your project's `package.json`:
986
+ * - If {@linkcode exe} is enabled, declaration file generation is disabled by default.
987
+ * - If the `types` field is present, or if the main `exports` contains a `types` entry, declaration file generation is enabled by default.
988
+ * - Otherwise, declaration file generation is disabled by default.
989
+ */
990
+ dts?: WithEnabled<DtsOptions>;
991
+ /**
992
+ * Enable unused dependencies check with `unplugin-unused`
993
+ * Requires `unplugin-unused` to be installed.
994
+ * @default false
995
+ */
996
+ unused?: WithEnabled<UnusedOptions>;
997
+ /**
998
+ * Run `publint` after bundling.
999
+ * Requires `publint` to be installed.
1000
+ * @default false
1001
+ */
1002
+ publint?: WithEnabled<PublintOptions>;
1003
+ /**
1004
+ * Run `arethetypeswrong` after bundling.
1005
+ * Requires `@arethetypeswrong/core` to be installed.
1006
+ *
1007
+ * @default false
1008
+ * @see https://github.com/arethetypeswrong/arethetypeswrong.github.io
1009
+ */
1010
+ attw?: WithEnabled<AttwOptions>;
1011
+ /**
1012
+ * Enable size reporting after bundling.
1013
+ * @default true
1014
+ */
1015
+ report?: WithEnabled<ReportOptions>;
1016
+ /**
1017
+ * `import.meta.glob` support.
1018
+ * @see https://vite.dev/guide/features.html#glob-import
1019
+ * @default true
1020
+ */
1021
+ globImport?: boolean;
1022
+ /**
1023
+ * Generate package exports for `package.json`.
1024
+ *
1025
+ * This will set the `exports` field in `package.json` to point to the
1026
+ * generated files.
1027
+ *
1028
+ * @default false
1029
+ */
1030
+ exports?: WithEnabled<ExportsOptions>;
1031
+ /**
1032
+ * **[experimental]** CSS options.
1033
+ * Requires `@tsdown/css` to be installed.
1034
+ */
1035
+ css?: CssOptions;
1036
+ /**
1037
+ * @deprecated Use {@linkcode CssOptions.inject | css.inject} instead.
1038
+ */
1039
+ injectStyle?: boolean;
1040
+ /**
1041
+ * @alias copy
1042
+ * @deprecated Alias for {@linkcode copy}, will be removed in the future.
1043
+ */
1044
+ publicDir?: CopyOptions | CopyOptionsFn;
1045
+ /**
1046
+ * Copy files to another directory.
1047
+ * @example
1048
+ * ```ts
1049
+ * [
1050
+ * 'src/assets',
1051
+ * 'src/env.d.ts',
1052
+ * 'src/styles/**\/*.css',
1053
+ * { from: 'src/assets', to: 'dist/assets' },
1054
+ * { from: 'src/styles/**\/*.css', to: 'dist', flatten: true },
1055
+ * ]
1056
+ * ```
1057
+ */
1058
+ copy?: CopyOptions | CopyOptionsFn;
1059
+ hooks?: Partial<TsdownHooks> | ((hooks: Hookable<TsdownHooks>) => Awaitable<void>);
1060
+ /**
1061
+ * **[experimental]** Bundle as executable using Node.js SEA (Single Executable Applications).
1062
+ *
1063
+ * This will bundle the output into a single executable file using Node.js SEA.
1064
+ * Note that this is only supported on Node.js 25.7.0 and later, and is not supported in Bun or Deno.
1065
+ *
1066
+ * @default false
1067
+ */
1068
+ exe?: WithEnabled<ExeOptions>;
1069
+ /**
1070
+ * **[experimental]** Enable workspace mode.
1071
+ * This allows you to build multiple packages in a monorepo.
1072
+ */
1073
+ workspace?: Workspace | Arrayable<string> | true;
1074
+ }
1075
+ interface InlineConfig extends UserConfig {
1076
+ /**
1077
+ * Config file path
1078
+ */
1079
+ config?: boolean | string;
1080
+ /**
1081
+ * Config loader to use. It can only be set via CLI or API.
1082
+ * @default 'auto'
1083
+ */
1084
+ configLoader?: "auto" | "native" | "tsx" | "unrun";
1085
+ /**
1086
+ * Filter configs by cwd or name.
1087
+ */
1088
+ filter?: RegExp | Arrayable<string>;
1089
+ }
1090
+ type UserConfigFn = (inlineConfig: InlineConfig, context: {
1091
+ ci: boolean;
1092
+ rootConfig?: UserConfig;
1093
+ }) => Awaitable<Arrayable<UserConfig>>;
1094
+ type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>;
1095
+ type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "fromVite" | "publicDir" | "bundle" | "injectStyle" | "removeNodeProtocol" | "outExtension" | "external" | "noExternal" | "inlineOnly" | "skipNodeModulesBundle" | "logLevel" | "failOnWarn" | "customLogger" | "envFile" | "envPrefix">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "onSuccess" | "outExtensions" | "hooks" | "copy" | "loader" | "name" | "banner" | "footer" | "checks" | "css">, {
1096
+ /**
1097
+ * Resolved entry map (after glob expansion)
1098
+ */
1099
+ entry: Record<string, string>;
1100
+ /**
1101
+ * Original entry config before glob resolution (for watch mode re-globbing)
1102
+ */
1103
+ rawEntry?: TsdownInputOption;
1104
+ nameLabel: string | undefined;
1105
+ format: NormalizedFormat;
1106
+ target?: string[];
1107
+ clean: string[];
1108
+ pkg?: PackageJsonWithPath;
1109
+ nodeProtocol: "strip" | boolean;
1110
+ logger: Logger;
1111
+ ignoreWatch: Array<string | RegExp>;
1112
+ deps: ResolvedDepsConfig;
1113
+ /**
1114
+ * Resolved root directory of input files
1115
+ */
1116
+ root: string;
1117
+ configDeps: Set<string>;
1118
+ dts: false | DtsOptions;
1119
+ report: false | ReportOptions;
1120
+ tsconfig: false | string;
1121
+ exports: false | ExportsOptions;
1122
+ devtools: false | DevtoolsOptions;
1123
+ publint: false | PublintOptions;
1124
+ attw: false | AttwOptions;
1125
+ unused: false | UnusedOptions;
1126
+ exe: false | ExeOptions;
1127
+ }>;
1128
+ //#endregion
1129
+ export { PackageType as A, ResolvedDepsConfig as B, ChunkAddon as C, OutExtensionFactory as D, OutExtensionContext as E, SeaConfig as F, CopyOptionsFn as G, TsdownBundle as H, DevtoolsOptions as I, DepsConfig as L, RolldownContext as M, TsdownHooks as N, OutExtensionObject as O, ExeOptions as P, DepsPlugin as R, AttwOptions as S, ChunkAddonObject as T, CopyEntry as U, RolldownChunk as V, CopyOptions as W, ReportPlugin as _, NormalizedFormat as a, PublintOptions as b, TreeshakingOptions as c, UserConfig as d, UserConfigExport as f, ReportOptions as g, Workspace as h, InlineConfig as i, BuildContext as j, PackageJsonWithPath as k, TsdownInputOption as l, WithEnabled as m, DtsOptions as n, ResolvedConfig as o, UserConfigFn as p, Format as r, Sourcemap as s, CIOption as t, UnusedOptions as u, TsdownPlugin as v, ChunkAddonFunction as w, ExportsOptions as x, TsdownPluginOption as y, NoExternalFn as z };