tsdown 0.22.3 → 0.22.5

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