tsdown 0.20.0-beta.2 → 0.20.0-beta.3

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,1031 @@
1
+ import { BuildOptions, ChecksOptions, ExternalOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, ModuleTypes, OutputAsset, OutputChunk, OutputOptions, Plugin, TreeshakingOptions } from "rolldown";
2
+ import { Hookable } from "hookable";
3
+ import { Options as DtsOptions } from "rolldown-plugin-dts";
4
+ import { StartOptions } from "@vitejs/devtools/cli-commands";
5
+ import { CheckPackageOptions } from "@arethetypeswrong/core";
6
+ import { Options } from "publint";
7
+ import { Options as UnusedOptions } from "unplugin-unused";
8
+
9
+ //#region src/utils/types.d.ts
10
+ type Overwrite<T, U> = Omit<T, keyof U> & U;
11
+ type Awaitable<T> = T | Promise<T>;
12
+ type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
13
+ type Arrayable<T> = T | T[];
14
+ //#endregion
15
+ //#region src/features/copy.d.ts
16
+ interface CopyEntry {
17
+ /**
18
+ * Source path or glob pattern.
19
+ */
20
+ from: string | string[];
21
+ /**
22
+ * Destination path.
23
+ * If not specified, defaults to the output directory ("outDir").
24
+ */
25
+ to?: string;
26
+ /**
27
+ * Whether to flatten the copied files (not preserving directory structure).
28
+ *
29
+ * @default true
30
+ */
31
+ flatten?: boolean;
32
+ /**
33
+ * Output copied items to console.
34
+ * @default false
35
+ */
36
+ verbose?: boolean;
37
+ /**
38
+ * Change destination file or folder name.
39
+ */
40
+ rename?: string | ((name: string, extension: string, fullPath: string) => string);
41
+ }
42
+ type CopyOptions = Arrayable<string | CopyEntry>;
43
+ type CopyOptionsFn = (options: ResolvedConfig) => Awaitable<CopyOptions>;
44
+ //#endregion
45
+ //#region src/features/css/index.d.ts
46
+ interface CssOptions {
47
+ /**
48
+ * Enable/disable CSS code splitting.
49
+ * When set to `false`, all CSS in the entire project will be extracted into a single CSS file.
50
+ * When set to `true`, CSS imported in async JS chunks will be preserved as chunks.
51
+ * @default true
52
+ */
53
+ splitting?: boolean;
54
+ /**
55
+ * Specify the name of the CSS file.
56
+ * @default 'style.css'
57
+ */
58
+ fileName?: string;
59
+ }
60
+ //#endregion
61
+ //#region src/features/devtools.d.ts
62
+ interface DevtoolsOptions extends NonNullable<InputOptions["devtools"]> {
63
+ /**
64
+ * **[experimental]** Enable devtools integration. `@vitejs/devtools` must be installed as a dependency.
65
+ *
66
+ * Defaults to true, if `@vitejs/devtools` is installed.
67
+ */
68
+ ui?: boolean | Partial<StartOptions>;
69
+ /**
70
+ * Clean devtools stale sessions.
71
+ *
72
+ * @default true
73
+ */
74
+ clean?: boolean;
75
+ }
76
+ //#endregion
77
+ //#region src/features/hooks.d.ts
78
+ interface BuildContext {
79
+ options: ResolvedConfig;
80
+ hooks: Hookable<TsdownHooks>;
81
+ }
82
+ interface RolldownContext {
83
+ buildOptions: BuildOptions;
84
+ }
85
+ /**
86
+ * Hooks for tsdown.
87
+ */
88
+ interface TsdownHooks {
89
+ /**
90
+ * Invoked before each tsdown build starts.
91
+ * Use this hook to perform setup or preparation tasks.
92
+ */
93
+ "build:prepare": (ctx: BuildContext) => void | Promise<void>;
94
+ /**
95
+ * Invoked before each Rolldown build.
96
+ * For dual-format builds, this hook is called for each format.
97
+ * Useful for configuring or modifying the build context before bundling.
98
+ */
99
+ "build:before": (ctx: BuildContext & RolldownContext) => void | Promise<void>;
100
+ /**
101
+ * Invoked after each tsdown build completes.
102
+ * Use this hook for cleanup or post-processing tasks.
103
+ */
104
+ "build:done": (ctx: BuildContext & {
105
+ chunks: RolldownChunk[];
106
+ }) => void | Promise<void>;
107
+ }
108
+ //#endregion
109
+ //#region node_modules/.pnpm/pkg-types@2.3.0/node_modules/pkg-types/dist/index.d.mts
110
+ interface PackageJson {
111
+ /**
112
+ * The name is what your thing is called.
113
+ * Some rules:
114
+ * - The name must be less than or equal to 214 characters. This includes the scope for scoped packages.
115
+ * - The name can’t start with a dot or an underscore.
116
+ * - New packages must not have uppercase letters in the name.
117
+ * - The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can’t contain any non-URL-safe characters.
118
+ */
119
+ name?: string;
120
+ /**
121
+ * Version must be parseable by `node-semver`, which is bundled with npm as a dependency. (`npm install semver` to use it yourself.)
122
+ */
123
+ version?: string;
124
+ /**
125
+ * Put a description in it. It’s a string. This helps people discover your package, as it’s listed in `npm search`.
126
+ */
127
+ description?: string;
128
+ /**
129
+ * Put keywords in it. It’s an array of strings. This helps people discover your package as it’s listed in `npm search`.
130
+ */
131
+ keywords?: string[];
132
+ /**
133
+ * The url to the project homepage.
134
+ */
135
+ homepage?: string;
136
+ /**
137
+ * The url to your project’s issue tracker and / or the email address to which issues should be reported. These are helpful for people who encounter issues with your package.
138
+ */
139
+ bugs?: string | {
140
+ url?: string;
141
+ email?: string;
142
+ };
143
+ /**
144
+ * You should specify a license for your package so that people know how they are permitted to use it, and any restrictions you’re placing on it.
145
+ */
146
+ license?: string;
147
+ /**
148
+ * Specify the place where your code lives. This is helpful for people who want to contribute. If the git repo is on GitHub, then the `npm docs` command will be able to find you.
149
+ * For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same shortcut syntax you use for npm install:
150
+ */
151
+ repository?: string | {
152
+ type: string;
153
+ url: string;
154
+ /**
155
+ * If the `package.json` for your package is not in the root directory (for example if it is part of a monorepo), you can specify the directory in which it lives:
156
+ */
157
+ directory?: string;
158
+ };
159
+ /**
160
+ * The `scripts` field is a dictionary containing script commands that are run at various times in the lifecycle of your package.
161
+ */
162
+ scripts?: PackageJsonScripts;
163
+ /**
164
+ * If you set `"private": true` in your package.json, then npm will refuse to publish it.
165
+ */
166
+ private?: boolean;
167
+ /**
168
+ * The “author” is one person.
169
+ */
170
+ author?: PackageJsonPerson;
171
+ /**
172
+ * “contributors” is an array of people.
173
+ */
174
+ contributors?: PackageJsonPerson[];
175
+ /**
176
+ * An object containing a URL that provides up-to-date information
177
+ * about ways to help fund development of your package,
178
+ * a string URL, or an array of objects and string URLs
179
+ */
180
+ funding?: PackageJsonFunding | PackageJsonFunding[];
181
+ /**
182
+ * The optional `files` field is an array of file patterns that describes the entries to be included when your package is installed as a dependency. File patterns follow a similar syntax to `.gitignore`, but reversed: including a file, directory, or glob pattern (`*`, `**\/*`, and such) will make it so that file is included in the tarball when it’s packed. Omitting the field will make it default to `["*"]`, which means it will include all files.
183
+ */
184
+ files?: string[];
185
+ /**
186
+ * The main field is a module ID that is the primary entry point to your program. That is, if your package is named `foo`, and a user installs it, and then does `require("foo")`, then your main module’s exports object will be returned.
187
+ * This should be a module ID relative to the root of your package folder.
188
+ * For most modules, it makes the most sense to have a main script and often not much else.
189
+ */
190
+ main?: string;
191
+ /**
192
+ * If your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren’t available in Node.js modules. (e.g. window)
193
+ */
194
+ browser?: string | Record<string, string | false>;
195
+ /**
196
+ * The `unpkg` field is used to specify the URL to a UMD module for your package. This is used by default in the unpkg.com CDN service.
197
+ */
198
+ unpkg?: string;
199
+ /**
200
+ * A map of command name to local file name. On install, npm will symlink that file into `prefix/bin` for global installs, or `./node_modules/.bin/` for local installs.
201
+ */
202
+ bin?: string | Record<string, string>;
203
+ /**
204
+ * Specify either a single file or an array of filenames to put in place for the `man` program to find.
205
+ */
206
+ man?: string | string[];
207
+ /**
208
+ * Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.
209
+ */
210
+ dependencies?: Record<string, string>;
211
+ /**
212
+ * If someone is planning on downloading and using your module in their program, then they probably don’t want or need to download and build the external test or documentation framework that you use.
213
+ * In this case, it’s best to map these additional items in a `devDependencies` object.
214
+ */
215
+ devDependencies?: Record<string, string>;
216
+ /**
217
+ * If a dependency can be used, but you would like npm to proceed if it cannot be found or fails to install, then you may put it in the `optionalDependencies` object. This is a map of package name to version or url, just like the `dependencies` object. The difference is that build failures do not cause installation to fail.
218
+ */
219
+ optionalDependencies?: Record<string, string>;
220
+ /**
221
+ * In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a `require` of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation.
222
+ */
223
+ peerDependencies?: Record<string, string>;
224
+ /**
225
+ * TypeScript typings, typically ending by `.d.ts`.
226
+ */
227
+ types?: string;
228
+ /**
229
+ * This field is synonymous with `types`.
230
+ */
231
+ typings?: string;
232
+ /**
233
+ * Non-Standard Node.js alternate entry-point to main.
234
+ * An initial implementation for supporting CJS packages (from main), and use module for ESM modules.
235
+ */
236
+ module?: string;
237
+ /**
238
+ * Make main entry-point be loaded as an ESM module, support "export" syntax instead of "require"
239
+ *
240
+ * Docs:
241
+ * - https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_package_json_type_field
242
+ *
243
+ * @default 'commonjs'
244
+ * @since Node.js v14
245
+ */
246
+ type?: "module" | "commonjs";
247
+ /**
248
+ * Alternate and extensible alternative to "main" entry point.
249
+ *
250
+ * When using `{type: "module"}`, any ESM module file MUST end with `.mjs` extension.
251
+ *
252
+ * Docs:
253
+ * - https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_exports_sugar
254
+ *
255
+ * @since Node.js v12.7
256
+ */
257
+ exports?: PackageJsonExports;
258
+ /**
259
+ * Docs:
260
+ * - https://nodejs.org/api/packages.html#imports
261
+ */
262
+ imports?: Record<string, string | Record<string, string>>;
263
+ /**
264
+ * The field is used to define a set of sub-packages (or workspaces) within a monorepo.
265
+ *
266
+ * This field is an array of glob patterns or an object with specific configurations for managing
267
+ * multiple packages in a single repository.
268
+ */
269
+ workspaces?: string[] | {
270
+ /**
271
+ * Workspace package paths. Glob patterns are supported.
272
+ */
273
+ packages?: string[];
274
+ /**
275
+ * Packages to block from hoisting to the workspace root.
276
+ * Uses glob patterns to match module paths in the dependency tree.
277
+ *
278
+ * Docs:
279
+ * - https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
280
+ */
281
+ nohoist?: string[];
282
+ };
283
+ /**
284
+ * The field is used to specify different TypeScript declaration files for
285
+ * different versions of TypeScript, allowing for version-specific type definitions.
286
+ */
287
+ typesVersions?: Record<string, Record<string, string[]>>;
288
+ /**
289
+ * You can specify which operating systems your module will run on:
290
+ * ```json
291
+ * {
292
+ * "os": ["darwin", "linux"]
293
+ * }
294
+ * ```
295
+ * You can also block instead of allowing operating systems, just prepend the blocked os with a '!':
296
+ * ```json
297
+ * {
298
+ * "os": ["!win32"]
299
+ * }
300
+ * ```
301
+ * The host operating system is determined by `process.platform`
302
+ * It is allowed to both block and allow an item, although there isn't any good reason to do this.
303
+ */
304
+ os?: string[];
305
+ /**
306
+ * If your code only runs on certain cpu architectures, you can specify which ones.
307
+ * ```json
308
+ * {
309
+ * "cpu": ["x64", "ia32"]
310
+ * }
311
+ * ```
312
+ * Like the `os` option, you can also block architectures:
313
+ * ```json
314
+ * {
315
+ * "cpu": ["!arm", "!mips"]
316
+ * }
317
+ * ```
318
+ * The host architecture is determined by `process.arch`
319
+ */
320
+ cpu?: string[];
321
+ /**
322
+ * This is a set of config values that will be used at publish-time.
323
+ */
324
+ publishConfig?: {
325
+ /**
326
+ * The registry that will be used if the package is published.
327
+ */
328
+ registry?: string;
329
+ /**
330
+ * The tag that will be used if the package is published.
331
+ */
332
+ tag?: string;
333
+ /**
334
+ * The access level that will be used if the package is published.
335
+ */
336
+ access?: "public" | "restricted";
337
+ /**
338
+ * **pnpm-only**
339
+ *
340
+ * By default, for portability reasons, no files except those listed in
341
+ * the bin field will be marked as executable in the resulting package
342
+ * archive. The executableFiles field lets you declare additional fields
343
+ * that must have the executable flag (+x) set even if
344
+ * they aren't directly accessible through the bin field.
345
+ */
346
+ executableFiles?: string[];
347
+ /**
348
+ * **pnpm-only**
349
+ *
350
+ * You also can use the field `publishConfig.directory` to customize
351
+ * the published subdirectory relative to the current `package.json`.
352
+ *
353
+ * It is expected to have a modified version of the current package in
354
+ * the specified directory (usually using third party build tools).
355
+ */
356
+ directory?: string;
357
+ /**
358
+ * **pnpm-only**
359
+ *
360
+ * When set to `true`, the project will be symlinked from the
361
+ * `publishConfig.directory` location during local development.
362
+ * @default true
363
+ */
364
+ linkDirectory?: boolean;
365
+ } & Pick<PackageJson, "bin" | "main" | "exports" | "types" | "typings" | "module" | "browser" | "unpkg" | "typesVersions" | "os" | "cpu">;
366
+ /**
367
+ * See: https://nodejs.org/api/packages.html#packagemanager
368
+ * This field defines which package manager is expected to be used when working on the current project.
369
+ * Should be of the format: `<name>@<version>[#hash]`
370
+ */
371
+ packageManager?: string;
372
+ [key: string]: any;
373
+ }
374
+ /**
375
+ * See: https://docs.npmjs.com/cli/v11/using-npm/scripts#pre--post-scripts
376
+ */
377
+ type PackageJsonScriptWithPreAndPost<S extends string> = S | `${"pre" | "post"}${S}`;
378
+ /**
379
+ * See: https://docs.npmjs.com/cli/v11/using-npm/scripts#life-cycle-operation-order
380
+ */
381
+ type PackageJsonNpmLifeCycleScripts = "dependencies" | "prepublishOnly" | PackageJsonScriptWithPreAndPost<"install" | "pack" | "prepare" | "publish" | "restart" | "start" | "stop" | "test" | "version">;
382
+ /**
383
+ * See: https://pnpm.io/scripts#lifecycle-scripts
384
+ */
385
+ type PackageJsonPnpmLifeCycleScripts = "pnpm:devPreinstall";
386
+ type PackageJsonCommonScripts = "build" | "coverage" | "deploy" | "dev" | "format" | "lint" | "preview" | "release" | "typecheck" | "watch";
387
+ type PackageJsonScriptName = PackageJsonCommonScripts | PackageJsonNpmLifeCycleScripts | PackageJsonPnpmLifeCycleScripts | (string & {});
388
+ type PackageJsonScripts = { [P in PackageJsonScriptName]?: string };
389
+ /**
390
+ * A “person” is an object with a “name” field and optionally “url” and “email”. Or you can shorten that all into a single string, and npm will parse it for you.
391
+ */
392
+ type PackageJsonPerson = string | {
393
+ name: string;
394
+ email?: string;
395
+ url?: string;
396
+ };
397
+ type PackageJsonFunding = string | {
398
+ url: string;
399
+ type?: string;
400
+ };
401
+ type PackageJsonExportKey = "." | "import" | "require" | "types" | "node" | "browser" | "default" | (string & {});
402
+ type PackageJsonExportsObject = { [P in PackageJsonExportKey]?: string | PackageJsonExportsObject | Array<string | PackageJsonExportsObject> };
403
+ type PackageJsonExports = string | PackageJsonExportsObject | Array<string | PackageJsonExportsObject>;
404
+ /**
405
+ * Defines a PackageJson structure.
406
+ * @param pkg - The `package.json` content as an object. See {@link PackageJson}.
407
+ * @returns the same `package.json` object.
408
+ */
409
+ //#endregion
410
+ //#region src/utils/package.d.ts
411
+ interface PackageJsonWithPath extends PackageJson {
412
+ packageJsonPath: string;
413
+ }
414
+ type PackageType = "module" | "commonjs" | undefined;
415
+ //#endregion
416
+ //#region src/features/output.d.ts
417
+ interface OutExtensionContext {
418
+ options: InputOptions;
419
+ format: NormalizedFormat;
420
+ /** "type" field in project's package.json */
421
+ pkgType?: PackageType;
422
+ }
423
+ interface OutExtensionObject {
424
+ js?: string;
425
+ dts?: string;
426
+ }
427
+ type OutExtensionFactory = (context: OutExtensionContext) => OutExtensionObject | undefined;
428
+ interface ChunkAddonObject {
429
+ js?: string;
430
+ css?: string;
431
+ dts?: string;
432
+ }
433
+ type ChunkAddonFunction = (ctx: {
434
+ format: Format;
435
+ fileName: string;
436
+ }) => ChunkAddonObject | string | undefined;
437
+ type ChunkAddon = ChunkAddonObject | ChunkAddonFunction | string;
438
+ //#endregion
439
+ //#region src/features/pkg/attw.d.ts
440
+ interface AttwOptions extends CheckPackageOptions {
441
+ /**
442
+ * Profiles select a set of resolution modes to require/ignore. All are evaluated but failures outside
443
+ * of those required are ignored.
444
+ *
445
+ * The available profiles are:
446
+ * - `strict`: requires all resolutions
447
+ * - `node16`: ignores node10 resolution failures
448
+ * - `esm-only`: ignores CJS resolution failures
449
+ *
450
+ * @default 'strict'
451
+ */
452
+ profile?: "strict" | "node16" | "esm-only";
453
+ /**
454
+ * The level of the check.
455
+ *
456
+ * The available levels are:
457
+ * - `error`: fails the build
458
+ * - `warn`: warns the build
459
+ *
460
+ * @default 'warn'
461
+ */
462
+ level?: "error" | "warn";
463
+ /**
464
+ * List of problem types to ignore by rule name.
465
+ *
466
+ * The available values are:
467
+ * - `no-resolution`
468
+ * - `untyped-resolution`
469
+ * - `false-cjs`
470
+ * - `false-esm`
471
+ * - `cjs-resolves-to-esm`
472
+ * - `fallback-condition`
473
+ * - `cjs-only-exports-default`
474
+ * - `named-exports`
475
+ * - `false-export-default`
476
+ * - `missing-export-equals`
477
+ * - `unexpected-module-syntax`
478
+ * - `internal-resolution-error`
479
+ *
480
+ * @example
481
+ * ```ts
482
+ * ignoreRules: ['no-resolution', 'false-cjs']
483
+ * ```
484
+ */
485
+ ignoreRules?: string[];
486
+ }
487
+ //#endregion
488
+ //#region src/utils/chunks.d.ts
489
+ type RolldownChunk = (OutputChunk | OutputAsset) & {
490
+ outDir: string;
491
+ };
492
+ type ChunksByFormat = Partial<Record<NormalizedFormat, RolldownChunk[]>>;
493
+ interface TsdownBundle extends AsyncDisposable {
494
+ chunks: RolldownChunk[];
495
+ config: ResolvedConfig;
496
+ }
497
+ //#endregion
498
+ //#region src/features/pkg/exports.d.ts
499
+ interface ExportsOptions {
500
+ /**
501
+ * Generate exports that link to source code during development.
502
+ * - string: add as a custom condition.
503
+ * - true: all conditions point to source files, and add dist exports to `publishConfig`.
504
+ */
505
+ devExports?: boolean | string;
506
+ /**
507
+ * Exports for package.json file.
508
+ * @default true
509
+ */
510
+ packageJson?: boolean;
511
+ /**
512
+ * Exports for all files.
513
+ */
514
+ all?: boolean;
515
+ /**
516
+ * Specifies file patterns (as glob patterns or regular expressions) to exclude from package exports.
517
+ * Use this to prevent certain files from being included in the exported package, such as test files, binaries, or internal utilities.
518
+ *
519
+ * **Note:** Do not include file extensions, and paths should be relative to the dist directory.
520
+ *
521
+ * @example
522
+ * exclude: ['cli', '**\/*.test', /internal/]
523
+ */
524
+ exclude?: (RegExp | string)[];
525
+ /**
526
+ * Generate legacy fields (`main` and `module`) for older Node.js and bundlers
527
+ * that do not support package `exports` field.
528
+ *
529
+ * Defaults to false, if only ESM builds are included, true otherwise.
530
+ *
531
+ * @see {@link https://github.com/publint/publint/issues/24}
532
+ */
533
+ legacy?: boolean;
534
+ customExports?: (exports: Record<string, any>, context: {
535
+ pkg: PackageJson;
536
+ chunks: ChunksByFormat;
537
+ isPublish: boolean;
538
+ }) => Awaitable<Record<string, any>>;
539
+ }
540
+ //#endregion
541
+ //#region src/features/pkg/publint.d.ts
542
+ interface PublintOptions extends Options {}
543
+ //#endregion
544
+ //#region src/utils/logger.d.ts
545
+ type LogType = "error" | "warn" | "info";
546
+ type LogLevel = LogType | "silent";
547
+ interface Logger {
548
+ level: LogLevel;
549
+ info: (...args: any[]) => void;
550
+ warn: (...args: any[]) => void;
551
+ warnOnce: (...args: any[]) => void;
552
+ error: (...args: any[]) => void;
553
+ success: (...args: any[]) => void;
554
+ clearScreen: (type: LogType) => void;
555
+ }
556
+ declare const globalLogger: Logger;
557
+ //#endregion
558
+ //#region src/features/report.d.ts
559
+ interface ReportOptions {
560
+ /**
561
+ * Enable/disable gzip-compressed size reporting.
562
+ * Compressing large output files can be slow, so disabling this may increase build performance for large projects.
563
+ *
564
+ * @default true
565
+ */
566
+ gzip?: boolean;
567
+ /**
568
+ * Enable/disable brotli-compressed size reporting.
569
+ * Compressing large output files can be slow, so disabling this may increase build performance for large projects.
570
+ *
571
+ * @default false
572
+ */
573
+ brotli?: boolean;
574
+ /**
575
+ * Skip reporting compressed size for files larger than this size.
576
+ * @default 1_000_000 // 1MB
577
+ */
578
+ maxCompressSize?: number;
579
+ }
580
+ declare function ReportPlugin(userOptions: ReportOptions, logger: Logger, cwd: string, cjsDts?: boolean, nameLabel?: string, isDualFormat?: boolean): Plugin;
581
+ //#endregion
582
+ //#region src/config/types.d.ts
583
+ type Sourcemap = boolean | "inline" | "hidden";
584
+ type Format = ModuleFormat;
585
+ type NormalizedFormat = InternalModuleFormat;
586
+ /**
587
+ * Extended input option that supports glob negation patterns.
588
+ *
589
+ * When using object form, values can be:
590
+ * - A single glob pattern string
591
+ * - An array of glob patterns, including negation patterns (prefixed with `!`)
592
+ *
593
+ * @example
594
+ * ```ts
595
+ * entry: {
596
+ * // Single pattern
597
+ * "utils/*": "./src/utils/*.ts",
598
+ * // Array with negation pattern to exclude files
599
+ * "hooks/*": ["./src/hooks/*.ts", "!./src/hooks/index.ts"],
600
+ * }
601
+ * ```
602
+ */
603
+ type TsdownInputOption = Arrayable<string | Record<string, Arrayable<string>>>;
604
+ interface Workspace {
605
+ /**
606
+ * Workspace directories. Glob patterns are supported.
607
+ * - `auto`: Automatically detect `package.json` files in the workspace.
608
+ * @default 'auto'
609
+ */
610
+ include?: Arrayable<string> | "auto";
611
+ /**
612
+ * Exclude directories from workspace.
613
+ * Defaults to all `node_modules`, `dist`, `test`, `tests`, `temp`, and `tmp` directories.
614
+ */
615
+ exclude?: Arrayable<string>;
616
+ /**
617
+ * Path to the workspace configuration file.
618
+ */
619
+ config?: boolean | string;
620
+ }
621
+ type NoExternalFn = (id: string, importer: string | undefined) => boolean | null | undefined | void;
622
+ type CIOption = "ci-only" | "local-only";
623
+ type WithEnabled<T> = boolean | undefined | CIOption | (T & {
624
+ /** @default true */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
+ entry?: TsdownInputOption;
642
+ external?: ExternalOption;
643
+ noExternal?: Arrayable<string | RegExp> | NoExternalFn;
644
+ /**
645
+ * Bundle only the dependencies listed here; throw an error if any others are missing.
646
+ *
647
+ * Note: Be sure to include all required sub-dependencies as well.
648
+ */
649
+ inlineOnly?: Arrayable<string | RegExp>;
650
+ /**
651
+ * Skip bundling `node_modules`.
652
+ * @default false
653
+ */
654
+ skipNodeModulesBundle?: boolean;
655
+ alias?: Record<string, string>;
656
+ tsconfig?: string | boolean;
657
+ /**
658
+ * Specifies the target runtime platform for the build.
659
+ *
660
+ * - `node`: Node.js and compatible runtimes (e.g., Deno, Bun).
661
+ * For CJS format, this is always set to `node` and cannot be changed.
662
+ * - `neutral`: A platform-agnostic target with no specific runtime assumptions.
663
+ * - `browser`: Web browsers.
664
+ *
665
+ * @default 'node'
666
+ * @see https://tsdown.dev/options/platform
667
+ */
668
+ platform?: "node" | "neutral" | "browser";
669
+ /**
670
+ * Specifies the compilation target environment(s).
671
+ *
672
+ * Determines the JavaScript version or runtime(s) for which the code should be compiled.
673
+ * If not set, defaults to the value of `engines.node` in your project's `package.json`.
674
+ * If no `engines.node` field exists, no syntax transformations are applied.
675
+ *
676
+ * Accepts a single target (e.g., `'es2020'`, `'node18'`), an array of targets, or `false` to disable all transformations.
677
+ *
678
+ * @see {@link https://tsdown.dev/options/target#supported-targets} for a list of valid targets and more details.
679
+ *
680
+ * @example
681
+ * ```jsonc
682
+ * // Target a single environment
683
+ * { "target": "node18" }
684
+ * ```
685
+ *
686
+ * @example
687
+ * ```jsonc
688
+ * // Target multiple environments
689
+ * { "target": ["node18", "es2020"] }
690
+ * ```
691
+ *
692
+ * @example
693
+ * ```jsonc
694
+ * // Disable all syntax transformations
695
+ * { "target": false }
696
+ * ```
697
+ */
698
+ target?: string | string[] | false;
699
+ /**
700
+ * Compile-time env variables, which can be accessed via `import.meta.env` or `process.env`.
701
+ * @example
702
+ * ```json
703
+ * {
704
+ * "DEBUG": true,
705
+ * "NODE_ENV": "production"
706
+ * }
707
+ * ```
708
+ */
709
+ env?: Record<string, any>;
710
+ /**
711
+ * Path to env file providing compile-time env variables.
712
+ * @example
713
+ * `.env`, `.env.production`, etc.
714
+ */
715
+ envFile?: string;
716
+ /**
717
+ * When loading env variables from `envFile`, only include variables with these prefixes.
718
+ * @default 'TSDOWN_'
719
+ */
720
+ envPrefix?: string | string[];
721
+ define?: Record<string, string>;
722
+ /** @default false */
723
+ shims?: boolean;
724
+ /**
725
+ * Configure tree shaking options.
726
+ * @see {@link https://rolldown.rs/options/treeshake} for more details.
727
+ * @default true
728
+ */
729
+ treeshake?: boolean | TreeshakingOptions;
730
+ /**
731
+ * Sets how input files are processed.
732
+ * For example, use 'js' to treat files as JavaScript or 'base64' for images.
733
+ * Lets you import or require files like images or fonts.
734
+ * @example
735
+ * ```json
736
+ * { '.jpg': 'asset', '.png': 'base64' }
737
+ * ```
738
+ */
739
+ loader?: ModuleTypes;
740
+ /**
741
+ * If enabled, strips the `node:` protocol prefix from import source.
742
+ *
743
+ * @default false
744
+ * @deprecated Use `nodeProtocol: 'strip'` instead.
745
+ *
746
+ * @example
747
+ * // With removeNodeProtocol enabled:
748
+ * import('node:fs'); // becomes import('fs')
749
+ */
750
+ removeNodeProtocol?: boolean;
751
+ /**
752
+ * - If `true`, add `node:` prefix to built-in modules.
753
+ * - If `'strip'`, strips the `node:` protocol prefix from import source.
754
+ * - If `false`, does not modify the import source.
755
+ *
756
+ * @default false
757
+ *
758
+ * @example
759
+ * // With nodeProtocol enabled:
760
+ * import('fs'); // becomes import('node:fs')
761
+ * // With nodeProtocol set to 'strip':
762
+ * import('node:fs'); // becomes import('fs')
763
+ * // With nodeProtocol set to false:
764
+ * import('node:fs'); // remains import('node:fs')
765
+ *
766
+ */
767
+ nodeProtocol?: "strip" | boolean;
768
+ /**
769
+ * Controls which warnings are emitted during the build process. Each option can be set to `true` (emit warning) or `false` (suppress warning).
770
+ */
771
+ checks?: ChecksOptions & {
772
+ /**
773
+ * If the config includes the `cjs` format and
774
+ * one of its target >= node 20.19.0 / 22.12.0,
775
+ * warn the user about the deprecation of CommonJS.
776
+ *
777
+ * @default true
778
+ */
779
+ legacyCjs?: boolean;
780
+ };
781
+ plugins?: InputOptions["plugins"];
782
+ /**
783
+ * Use with caution; ensure you understand the implications.
784
+ */
785
+ inputOptions?: InputOptions | ((options: InputOptions, format: NormalizedFormat, context: {
786
+ cjsDts: boolean;
787
+ }) => Awaitable<InputOptions | void | null>);
788
+ /** @default 'es' */
789
+ format?: Format | Format[] | Partial<Record<Format, Partial<ResolvedConfig>>>;
790
+ globalName?: string;
791
+ /** @default 'dist' */
792
+ outDir?: string;
793
+ /**
794
+ * Whether to write the files to disk.
795
+ * This option is incompatible with watch mode.
796
+ * @default true
797
+ */
798
+ write?: boolean;
799
+ /**
800
+ * Whether to generate source map files.
801
+ *
802
+ * Note that this option will always be `true` if you have
803
+ * [`declarationMap`](https://www.typescriptlang.org/tsconfig/#declarationMap)
804
+ * option enabled in your `tsconfig.json`.
805
+ *
806
+ * @default false
807
+ */
808
+ sourcemap?: Sourcemap;
809
+ /**
810
+ * Clean directories before build.
811
+ *
812
+ * Default to output directory.
813
+ * @default true
814
+ */
815
+ clean?: boolean | string[];
816
+ /**
817
+ * @default false
818
+ */
819
+ minify?: boolean | "dce-only" | MinifyOptions;
820
+ footer?: ChunkAddon;
821
+ banner?: ChunkAddon;
822
+ /**
823
+ * Determines whether unbundle mode is enabled.
824
+ * When set to true, the output files will mirror the input file structure.
825
+ * @default false
826
+ */
827
+ unbundle?: boolean;
828
+ /**
829
+ * @deprecated Use `unbundle` instead.
830
+ * @default true
831
+ */
832
+ bundle?: boolean;
833
+ /**
834
+ * Use a fixed extension for output files.
835
+ * The extension will always be `.cjs` or `.mjs`.
836
+ * Otherwise, it will depend on the package type.
837
+ *
838
+ * Defaults to `true` if `platform` is set to `node`, `false` otherwise.
839
+ */
840
+ fixedExtension?: boolean;
841
+ /**
842
+ * Custom extensions for output files.
843
+ * `fixedExtension` will be overridden by this option.
844
+ */
845
+ outExtensions?: OutExtensionFactory;
846
+ /**
847
+ * If enabled, appends hash to chunk filenames.
848
+ * @default true
849
+ */
850
+ hash?: boolean;
851
+ /**
852
+ * @default true
853
+ */
854
+ cjsDefault?: boolean;
855
+ /**
856
+ * Use with caution; ensure you understand the implications.
857
+ */
858
+ outputOptions?: OutputOptions | ((options: OutputOptions, format: NormalizedFormat, context: {
859
+ cjsDts: boolean;
860
+ }) => Awaitable<OutputOptions | void | null>);
861
+ /**
862
+ * The working directory of the config file.
863
+ * - Defaults to `process.cwd()` for root config.
864
+ * - Defaults to the package directory for workspace config.
865
+ */
866
+ cwd?: string;
867
+ /**
868
+ * The name to show in CLI output. This is useful for monorepos or workspaces.
869
+ * When using workspace mode, this option defaults to the package name from package.json.
870
+ * In non-workspace mode, this option must be set explicitly for the name to show in the CLI output.
871
+ */
872
+ name?: string;
873
+ /**
874
+ * Log level.
875
+ * @default 'info'
876
+ */
877
+ logLevel?: LogLevel;
878
+ /**
879
+ * If true, fails the build on warnings.
880
+ * @default 'ci-only'
881
+ */
882
+ failOnWarn?: boolean | CIOption;
883
+ /**
884
+ * Custom logger.
885
+ */
886
+ customLogger?: Logger;
887
+ /**
888
+ * Reuse config from Vite or Vitest (experimental)
889
+ * @default false
890
+ */
891
+ fromVite?: boolean | "vitest";
892
+ /**
893
+ * @default false
894
+ */
895
+ watch?: boolean | Arrayable<string>;
896
+ /**
897
+ * Files or patterns to not watch while in watch mode.
898
+ */
899
+ ignoreWatch?: Arrayable<string | RegExp>;
900
+ /**
901
+ * **[experimental]** Enable devtools.
902
+ *
903
+ *DevTools is still under development, and this is for early testers only.
904
+ *
905
+ * This may slow down the build process significantly.
906
+ *
907
+ * @default false
908
+ */
909
+ devtools?: WithEnabled<DevtoolsOptions>;
910
+ /**
911
+ * You can specify command to be executed after a successful build, specially useful for Watch mode
912
+ */
913
+ onSuccess?: string | ((config: ResolvedConfig, signal: AbortSignal) => void | Promise<void>);
914
+ /**
915
+ * Enables generation of TypeScript declaration files (`.d.ts`).
916
+ *
917
+ * By default, this option is auto-detected based on your project's `package.json`:
918
+ * - If the `types` field is present, or if the main `exports` contains a `types` entry, declaration file generation is enabled by default.
919
+ * - Otherwise, declaration file generation is disabled by default.
920
+ */
921
+ dts?: WithEnabled<DtsOptions>;
922
+ /**
923
+ * Enable unused dependencies check with `unplugin-unused`
924
+ * Requires `unplugin-unused` to be installed.
925
+ * @default false
926
+ */
927
+ unused?: WithEnabled<UnusedOptions>;
928
+ /**
929
+ * Run publint after bundling.
930
+ * Requires `publint` to be installed.
931
+ * @default false
932
+ */
933
+ publint?: WithEnabled<PublintOptions>;
934
+ /**
935
+ * Run `arethetypeswrong` after bundling.
936
+ * Requires `@arethetypeswrong/core` to be installed.
937
+ *
938
+ * @default false
939
+ * @see https://github.com/arethetypeswrong/arethetypeswrong.github.io
940
+ */
941
+ attw?: WithEnabled<AttwOptions>;
942
+ /**
943
+ * Enable size reporting after bundling.
944
+ * @default true
945
+ */
946
+ report?: WithEnabled<ReportOptions>;
947
+ /**
948
+ * `import.meta.glob` support.
949
+ * @see https://vite.dev/guide/features.html#glob-import
950
+ * @default true
951
+ */
952
+ globImport?: boolean;
953
+ /**
954
+ * Generate package exports for `package.json`.
955
+ *
956
+ * This will set the `main`, `module`, `types`, `exports` fields in `package.json`
957
+ * to point to the generated files.
958
+ */
959
+ exports?: WithEnabled<ExportsOptions>;
960
+ /**
961
+ * **[experimental]** CSS options.
962
+ */
963
+ css?: CssOptions;
964
+ /**
965
+ * @deprecated Alias for `copy`, will be removed in the future.
966
+ */
967
+ publicDir?: CopyOptions | CopyOptionsFn;
968
+ /**
969
+ * Copy files to another directory.
970
+ * @example
971
+ * ```ts
972
+ * [
973
+ * 'src/assets',
974
+ * 'src/env.d.ts',
975
+ * 'src/styles/**\/*.css',
976
+ * { from: 'src/assets', to: 'dist/assets' },
977
+ * { from: 'src/styles/**\/*.css', to: 'dist', flatten: true },
978
+ * ]
979
+ * ```
980
+ */
981
+ copy?: CopyOptions | CopyOptionsFn;
982
+ hooks?: Partial<TsdownHooks> | ((hooks: Hookable<TsdownHooks>) => Awaitable<void>);
983
+ /**
984
+ * **[experimental]** Enable workspace mode.
985
+ * This allows you to build multiple packages in a monorepo.
986
+ */
987
+ workspace?: Workspace | Arrayable<string> | true;
988
+ }
989
+ interface InlineConfig extends UserConfig {
990
+ /**
991
+ * Config file path
992
+ */
993
+ config?: boolean | string;
994
+ /**
995
+ * Config loader to use. It can only be set via CLI or API.
996
+ * @default 'auto'
997
+ */
998
+ configLoader?: "auto" | "native" | "unrun";
999
+ /**
1000
+ * Filter configs by cwd or name.
1001
+ */
1002
+ filter?: RegExp | Arrayable<string>;
1003
+ }
1004
+ type UserConfigFn = (inlineConfig: InlineConfig, context: {
1005
+ ci: boolean;
1006
+ }) => Awaitable<Arrayable<UserConfig>>;
1007
+ type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>;
1008
+ type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "fromVite" | "publicDir" | "bundle" | "removeNodeProtocol" | "logLevel" | "failOnWarn" | "customLogger" | "envFile" | "envPrefix">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "onSuccess" | "outExtensions" | "hooks" | "copy" | "loader" | "name" | "banner" | "footer" | "checks">, {
1009
+ /** Resolved entry map (after glob expansion) */entry: Record<string, string>;
1010
+ nameLabel: string | undefined;
1011
+ format: NormalizedFormat;
1012
+ target?: string[];
1013
+ clean: string[];
1014
+ pkg?: PackageJsonWithPath;
1015
+ nodeProtocol: "strip" | boolean;
1016
+ logger: Logger;
1017
+ ignoreWatch: Array<string | RegExp>;
1018
+ noExternal?: NoExternalFn;
1019
+ inlineOnly?: Array<string | RegExp>;
1020
+ css: Required<CssOptions>;
1021
+ dts: false | DtsOptions;
1022
+ report: false | ReportOptions;
1023
+ tsconfig: false | string;
1024
+ exports: false | ExportsOptions;
1025
+ devtools: false | DevtoolsOptions;
1026
+ publint: false | PublintOptions;
1027
+ attw: false | AttwOptions;
1028
+ unused: false | UnusedOptions;
1029
+ }>;
1030
+ //#endregion
1031
+ export { OutExtensionFactory as A, CopyOptions as B, RolldownChunk as C, ChunkAddonFunction as D, ChunkAddon as E, RolldownContext as F, Arrayable as H, TsdownHooks as I, DevtoolsOptions as L, PackageJsonWithPath as M, PackageType as N, ChunkAddonObject as O, BuildContext as P, CssOptions as R, ExportsOptions as S, AttwOptions as T, CopyOptionsFn as V, ReportOptions as _, NoExternalFn as a, globalLogger as b, Sourcemap as c, UnusedOptions as d, UserConfig as f, Workspace as g, WithEnabled as h, InlineConfig as i, OutExtensionObject as j, OutExtensionContext as k, TreeshakingOptions as l, UserConfigFn as m, DtsOptions as n, NormalizedFormat as o, UserConfigExport as p, Format as r, ResolvedConfig as s, CIOption as t, TsdownInputOption as u, ReportPlugin as v, TsdownBundle as w, PublintOptions as x, Logger as y, CopyEntry as z };