tsdown 0.11.13 → 0.12.1

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,7 +1,8 @@
1
- import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, OutputOptions, Plugin } from "rolldown";
1
+ import "ansis";
2
+ import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, OutputAsset, OutputChunk, OutputOptions, Plugin } from "rolldown";
3
+ import { Options } from "rolldown-plugin-dts";
2
4
  import { Hookable } from "hookable";
3
- import { Options } from "publint";
4
- import { Options as Options$1 } from "rolldown-plugin-dts";
5
+ import { Options as Options$1 } from "publint";
5
6
  import { Options as Options$2 } from "unplugin-unused";
6
7
  import { PackageJson } from "pkg-types";
7
8
 
@@ -12,13 +13,17 @@ type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T,
12
13
  type Arrayable<T> = T | T[];
13
14
 
14
15
  //#endregion
15
- //#region src/features/copy.d.ts
16
- interface CopyEntry {
17
- from: string;
18
- to: string;
16
+ //#region src/utils/logger.d.ts
17
+ declare class Logger {
18
+ silent: boolean;
19
+ setSilent(value: boolean): void;
20
+ filter(...args: any[]): any[];
21
+ info(...args: any[]): void;
22
+ warn(...args: any[]): void;
23
+ error(...args: any[]): void;
24
+ success(...args: any[]): void;
19
25
  }
20
- type CopyOptions = Arrayable<string | CopyEntry>;
21
- type CopyOptionsFn = (options: ResolvedOptions) => Awaitable<CopyOptions>;
26
+ declare const logger: Logger;
22
27
 
23
28
  //#endregion
24
29
  //#region src/features/hooks.d.ts
@@ -52,6 +57,33 @@ interface TsdownHooks {
52
57
  "build:done": (ctx: BuildContext) => void | Promise<void>;
53
58
  }
54
59
 
60
+ //#endregion
61
+ //#region src/index.d.ts
62
+ /**
63
+ * Build with tsdown.
64
+ */
65
+ declare function build$1(userOptions?: Options$3): Promise<void>;
66
+ declare const pkgRoot: string;
67
+ type TsdownChunks = Partial<Record<NormalizedFormat, Array<OutputChunk | OutputAsset>>>;
68
+ /**
69
+ * Build a single configuration, without watch and shortcuts features.
70
+ *
71
+ * Internal API, not for public use
72
+ *
73
+ * @private
74
+ * @param config Resolved options
75
+ */
76
+ declare function buildSingle(config: ResolvedOptions, clean: () => Promise<void>): Promise<(() => Promise<void>) | undefined>;
77
+
78
+ //#endregion
79
+ //#region src/features/copy.d.ts
80
+ interface CopyEntry {
81
+ from: string;
82
+ to: string;
83
+ }
84
+ type CopyOptions = Arrayable<string | CopyEntry>;
85
+ type CopyOptionsFn = (options: ResolvedOptions) => Awaitable<CopyOptions>;
86
+
55
87
  //#endregion
56
88
  //#region src/utils/package.d.ts
57
89
  type PackageType = "module" | "commonjs" | undefined;
@@ -111,6 +143,24 @@ interface Workspace {
111
143
  */
112
144
  config?: boolean | string;
113
145
  }
146
+ interface ExportsOptions {
147
+ /**
148
+ * Generate exports that link to source code during development.
149
+ * - string: add as a custom condition.
150
+ * - true: all conditions point to source files, and add dist exports to `publishConfig`.
151
+ */
152
+ devExports?: boolean | string;
153
+ /**
154
+ * Exports for all files.
155
+ */
156
+ all?: boolean;
157
+ customExports?: (exports: Record<string, any>, context: {
158
+ pkg: PackageJson;
159
+ chunks: TsdownChunks;
160
+ outDir: string;
161
+ isPublish: boolean;
162
+ }) => Awaitable<Record<string, any>>;
163
+ }
114
164
  /**
115
165
  * Options for tsdown.
116
166
  */
@@ -229,7 +279,7 @@ interface Options$3 {
229
279
  * - If the `types` field is present in `package.json`, declaration file emission is enabled.
230
280
  * - If the `types` field is absent, declaration file emission is disabled by default.
231
281
  */
232
- dts?: boolean | Options$1;
282
+ dts?: boolean | Options;
233
283
  /**
234
284
  * Enable unused dependencies check with `unplugin-unused`
235
285
  * Requires `unplugin-unused` to be installed.
@@ -241,13 +291,20 @@ interface Options$3 {
241
291
  * Requires `publint` to be installed.
242
292
  * @default false
243
293
  */
244
- publint?: boolean | Options;
294
+ publint?: boolean | Options$1;
245
295
  /**
246
296
  * Enable size reporting after bundling.
247
297
  * @default true
248
298
  */
249
299
  report?: boolean | ReportOptions;
250
300
  /**
301
+ * **[experimental]** Generate exports map for `package.json`.
302
+ *
303
+ * This will set the `main`, `module`, `types`, `exports` fields in `package.json`
304
+ * to point to the generated files.
305
+ */
306
+ exports?: boolean | ExportsOptions;
307
+ /**
251
308
  * Compile-time env variables.
252
309
  * @example
253
310
  * ```json
@@ -314,9 +371,17 @@ type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" |
314
371
  format: NormalizedFormat[];
315
372
  target?: string[];
316
373
  clean: string[];
317
- dts: false | Options$1;
374
+ dts: false | Options;
318
375
  report: false | ReportOptions;
319
376
  tsconfig: string | false;
320
377
  pkg?: PackageJson;
378
+ exports: false | ExportsOptions;
321
379
  }>, "config" | "fromVite">; //#endregion
322
- export { BuildContext, Options$3 as Options, ReportPlugin as ReportPlugin$1, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn };
380
+ //#region src/config.d.ts
381
+ /**
382
+ * Defines the configuration for tsdown.
383
+ */
384
+ declare function defineConfig(options: UserConfig | UserConfigFn): UserConfig | UserConfigFn;
385
+
386
+ //#endregion
387
+ export { BuildContext, Options$3 as Options, ReportPlugin as ReportPlugin$1, ResolvedOptions, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build$1 as build, buildSingle, defineConfig as defineConfig$1, logger, pkgRoot };
package/dist/config.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { UserConfig, UserConfigFn } from "./types-CsOn0For.js";
2
- import { defineConfig$1 as defineConfig } from "./config-GQTSGL72.js";
1
+ import { UserConfig, UserConfigFn, defineConfig$1 as defineConfig } from "./config-BVsukpAr.js";
3
2
  export { UserConfig, UserConfigFn, defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,34 +1,2 @@
1
- import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn } from "./types-CsOn0For.js";
2
- import { defineConfig$1 as defineConfig } from "./config-GQTSGL72.js";
3
- import "ansis";
4
- import { InternalModuleFormat } from "rolldown";
5
-
6
- //#region src/utils/logger.d.ts
7
- declare class Logger {
8
- silent: boolean;
9
- setSilent(value: boolean): void;
10
- filter(...args: any[]): any[];
11
- info(...args: any[]): void;
12
- warn(...args: any[]): void;
13
- error(...args: any[]): void;
14
- success(...args: any[]): void;
15
- }
16
- declare const logger: Logger; //#endregion
17
- //#region src/index.d.ts
18
- /**
19
- * Build with tsdown.
20
- */
21
- declare function build(userOptions?: Options): Promise<void>;
22
- declare const pkgRoot: string;
23
- /**
24
- * Build a single configuration, without watch and shortcuts features.
25
- *
26
- * Internal API, not for public use
27
- *
28
- * @private
29
- * @param config Resolved options
30
- */
31
- declare function buildSingle(config: ResolvedOptions, clean: () => Promise<void>): Promise<(() => Promise<void>) | undefined>;
32
-
33
- //#endregion
34
- export { BuildContext, Options, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot };
1
+ import { BuildContext, Options, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig$1 as defineConfig, logger, pkgRoot } from "./config-BVsukpAr.js";
2
+ export { BuildContext, Options, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot };
package/dist/index.js CHANGED
@@ -1,15 +1,16 @@
1
1
  import { defineConfig } from "./config-yiJy1jd0.js";
2
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, lowestCommonAncestor } from "./plugins-BV3QPDFO.js";
3
- import { debounce, generateColor, logger, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-DcIo21Wv.js";
2
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, lowestCommonAncestor } from "./plugins-D-fqvWYC.js";
3
+ import { debounce, generateColor, logger$1 as logger, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-CS4H_tpu.js";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
  import { blue, bold, dim, green, underline } from "ansis";
8
8
  import { build as build$1 } from "rolldown";
9
9
  import { exec } from "tinyexec";
10
- import Debug from "debug";
10
+ import debug from "debug";
11
11
  import { glob } from "tinyglobby";
12
- import { readFile } from "node:fs/promises";
12
+ import { readFile, writeFile } from "node:fs/promises";
13
+ import { RE_DTS } from "rolldown-plugin-dts";
13
14
  import { createHooks } from "hookable";
14
15
  import { up } from "empathic/package";
15
16
  import readline from "node:readline";
@@ -18,7 +19,7 @@ import { up as up$1 } from "empathic/find";
18
19
  import { loadConfig } from "unconfig";
19
20
 
20
21
  //#region src/features/clean.ts
21
- const debug$3 = Debug("tsdown:clean");
22
+ const debug$4 = debug("tsdown:clean");
22
23
  const RE_LAST_SLASH = /[/\\]$/;
23
24
  async function cleanOutDir(configs) {
24
25
  const removes = new Set();
@@ -38,10 +39,10 @@ async function cleanOutDir(configs) {
38
39
  if (!removes.size) return;
39
40
  logger.info(`Cleaning ${removes.size} files`);
40
41
  await Promise.all([...removes].map(async (file) => {
41
- debug$3("Removing", file);
42
+ debug$4("Removing", file);
42
43
  await fsRemove(file);
43
44
  }));
44
- debug$3("Removed %d files", removes.size);
45
+ debug$4("Removed %d files", removes.size);
45
46
  }
46
47
  function resolveClean(clean, outDir, cwd) {
47
48
  if (clean === true) clean = [slash(outDir)];
@@ -65,6 +66,112 @@ function cp$1(cwd, from, to) {
65
66
  return fsCopy(path.resolve(cwd, from), path.resolve(cwd, to));
66
67
  }
67
68
 
69
+ //#endregion
70
+ //#region src/features/exports.ts
71
+ async function writeExports(options, chunks) {
72
+ if (!options.exports) return;
73
+ const { outDir, pkg } = options;
74
+ if (!pkg) throw new Error("`package.json` not found, cannot write exports");
75
+ const { publishExports,...generated } = await generateExports(pkg, outDir, chunks, options.exports);
76
+ const updatedPkg = {
77
+ ...pkg,
78
+ ...generated,
79
+ packageJsonPath: void 0
80
+ };
81
+ if (publishExports) {
82
+ updatedPkg.publishConfig ||= {};
83
+ updatedPkg.publishConfig.exports = publishExports;
84
+ }
85
+ await writeFile(pkg.packageJsonPath, `${JSON.stringify({
86
+ ...pkg,
87
+ ...generated,
88
+ packageJsonPath: void 0
89
+ }, null, 2)}\n`);
90
+ }
91
+ async function generateExports(pkg, outDir, chunks, { devExports, all, customExports }) {
92
+ const pkgJsonPath = pkg.packageJsonPath;
93
+ const pkgRoot$1 = path.dirname(pkgJsonPath);
94
+ const outDirRelative = slash(path.relative(pkgRoot$1, outDir));
95
+ let main, module, cjsTypes, esmTypes;
96
+ const exportsMap = new Map();
97
+ for (const [format, chunksByFormat] of Object.entries(chunks)) {
98
+ if (format !== "es" && format !== "cjs") continue;
99
+ const onlyOneEntry = chunksByFormat.filter((chunk) => chunk.type === "chunk" && chunk.isEntry && !RE_DTS.test(chunk.fileName)).length === 1;
100
+ for (const chunk of chunksByFormat) {
101
+ if (chunk.type !== "chunk" || !chunk.isEntry) continue;
102
+ const ext = path.extname(chunk.fileName);
103
+ let name = chunk.fileName.slice(0, -ext.length);
104
+ const isDts = name.endsWith(".d");
105
+ if (isDts) name = name.slice(0, -2);
106
+ const isIndex = onlyOneEntry || name === "index";
107
+ const distFile = `${outDirRelative ? `./${outDirRelative}` : "."}/${chunk.fileName}`;
108
+ if (isIndex) {
109
+ name = ".";
110
+ if (format === "cjs") if (isDts) cjsTypes = distFile;
111
+ else main = distFile;
112
+ else if (format === "es") if (isDts) esmTypes = distFile;
113
+ else module = distFile;
114
+ } else name = `./${name}`;
115
+ let subExport = exportsMap.get(name);
116
+ if (!subExport) {
117
+ subExport = {};
118
+ exportsMap.set(name, subExport);
119
+ }
120
+ if (!isDts) {
121
+ subExport[format] = distFile;
122
+ if (chunk.facadeModuleId && !subExport.src) subExport.src = `./${slash(path.relative(pkgRoot$1, chunk.facadeModuleId))}`;
123
+ }
124
+ }
125
+ }
126
+ const sorttedExportsMap = Array.from(exportsMap.entries()).sort(([a], [b]) => {
127
+ if (a === "index") return -1;
128
+ return a.localeCompare(b);
129
+ });
130
+ let exports = Object.fromEntries(sorttedExportsMap.map(([name, subExport]) => [name, genSubExport(devExports, subExport)]));
131
+ exportMeta(exports, all);
132
+ if (customExports) exports = await customExports(exports, {
133
+ pkg,
134
+ outDir,
135
+ chunks,
136
+ isPublish: false
137
+ });
138
+ let publishExports;
139
+ if (devExports) {
140
+ publishExports = Object.fromEntries(sorttedExportsMap.map(([name, subExport]) => [name, genSubExport(false, subExport)]));
141
+ exportMeta(publishExports, all);
142
+ if (customExports) publishExports = await customExports(publishExports, {
143
+ pkg,
144
+ outDir,
145
+ chunks,
146
+ isPublish: true
147
+ });
148
+ }
149
+ return {
150
+ main: main || module || pkg.main,
151
+ module: module || pkg.module,
152
+ types: cjsTypes || esmTypes || pkg.types,
153
+ exports,
154
+ publishExports
155
+ };
156
+ }
157
+ function genSubExport(devExports, { src, es, cjs }) {
158
+ if (devExports === true) return src;
159
+ let value;
160
+ const dualFormat = es && cjs;
161
+ if (!dualFormat && !devExports) value = cjs || es;
162
+ else {
163
+ value = {};
164
+ if (typeof devExports === "string") value[devExports] = src;
165
+ if (es) value[dualFormat ? "import" : "default"] = es;
166
+ if (cjs) value[dualFormat ? "require" : "default"] = cjs;
167
+ }
168
+ return value;
169
+ }
170
+ function exportMeta(exports, all) {
171
+ if (all) exports["./*"] = "./*";
172
+ else exports["./package.json"] = "./package.json";
173
+ }
174
+
68
175
  //#endregion
69
176
  //#region src/features/hooks.ts
70
177
  async function createHooks$1(options, pkg) {
@@ -135,13 +242,16 @@ async function LightningCSSPlugin(options) {
135
242
 
136
243
  //#endregion
137
244
  //#region src/utils/package.ts
138
- const debug$2 = Debug("tsdown:package");
245
+ const debug$3 = debug("tsdown:package");
139
246
  async function readPackageJson(dir) {
140
247
  const packageJsonPath = up({ cwd: dir });
141
248
  if (!packageJsonPath) return;
142
- debug$2("Reading package.json:", packageJsonPath);
249
+ debug$3("Reading package.json:", packageJsonPath);
143
250
  const contents = await readFile(packageJsonPath, "utf8");
144
- return JSON.parse(contents);
251
+ return {
252
+ ...JSON.parse(contents),
253
+ packageJsonPath
254
+ };
145
255
  }
146
256
  function getPackageType(pkg) {
147
257
  if (pkg?.type) {
@@ -197,7 +307,7 @@ function createChunkFilename(basename, jsExtension, dtsExtension) {
197
307
 
198
308
  //#endregion
199
309
  //#region src/features/publint.ts
200
- const debug$1 = Debug("tsdown:publint");
310
+ const debug$2 = debug("tsdown:publint");
201
311
  async function publint(options) {
202
312
  if (!options.publint) return;
203
313
  if (!options.pkg) {
@@ -205,11 +315,11 @@ async function publint(options) {
205
315
  return;
206
316
  }
207
317
  const t = performance.now();
208
- debug$1("Running publint");
318
+ debug$2("Running publint");
209
319
  const { publint: publint$1 } = await import("publint");
210
320
  const { formatMessage } = await import("publint/utils");
211
321
  const { messages } = await publint$1(options.publint === true ? {} : options.publint);
212
- debug$1("Found %d issues", messages.length);
322
+ debug$2("Found %d issues", messages.length);
213
323
  if (!messages.length) logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
214
324
  let hasError = false;
215
325
  for (const message of messages) {
@@ -223,7 +333,7 @@ async function publint(options) {
223
333
  logger[logType](formattedMessage);
224
334
  }
225
335
  if (hasError) {
226
- debug$1("Found errors, setting exit code to 1");
336
+ debug$2("Found errors, setting exit code to 1");
227
337
  process.exitCode = 1;
228
338
  }
229
339
  }
@@ -513,7 +623,7 @@ async function loadConfigFile(options, workspace) {
513
623
 
514
624
  //#endregion
515
625
  //#region src/options/index.ts
516
- const debug = Debug("tsdown:options");
626
+ const debug$1 = debug("tsdown:options");
517
627
  const DEFAULT_EXCLUDE_WORKSPACE = [
518
628
  "**/node_modules/**",
519
629
  "**/dist/**",
@@ -522,20 +632,20 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
522
632
  ];
523
633
  async function resolveOptions(options) {
524
634
  const files = [];
525
- debug("options %O", options);
526
- debug("loading config file: %s", options.config);
635
+ debug$1("options %O", options);
636
+ debug$1("loading config file: %s", options.config);
527
637
  const { configs: rootConfigs, file } = await loadConfigFile(options);
528
638
  if (file) {
529
639
  files.push(file);
530
- debug("loaded root config file %s", file);
531
- debug("root configs %o", rootConfigs);
532
- } else debug("no root config file found");
640
+ debug$1("loaded root config file %s", file);
641
+ debug$1("root configs %o", rootConfigs);
642
+ } else debug$1("no root config file found");
533
643
  const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
534
644
  const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
535
645
  if (workspaceFiles) files.push(...workspaceFiles);
536
646
  return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveConfig(config)));
537
647
  }))).flat();
538
- debug("resolved configs %O", configs);
648
+ debug$1("resolved configs %O", configs);
539
649
  return {
540
650
  configs,
541
651
  files
@@ -577,16 +687,16 @@ async function resolveWorkspace(config, options) {
577
687
  }
578
688
  const files = [];
579
689
  const configs = (await Promise.all(packages.map(async (cwd) => {
580
- debug("loading workspace config %s", cwd);
690
+ debug$1("loading workspace config %s", cwd);
581
691
  const { configs: configs$1, file } = await loadConfigFile({
582
692
  ...options,
583
693
  config: workspaceConfig,
584
694
  cwd
585
695
  }, cwd);
586
696
  if (file) {
587
- debug("loaded workspace config file %s", file);
697
+ debug$1("loaded workspace config file %s", file);
588
698
  files.push(file);
589
- } else debug("no workspace config file found in %s", cwd);
699
+ } else debug$1("no workspace config file found in %s", cwd);
590
700
  return configs$1.map((config$1) => ({
591
701
  ...normalized,
592
702
  cwd,
@@ -599,7 +709,7 @@ async function resolveWorkspace(config, options) {
599
709
  };
600
710
  }
601
711
  async function resolveConfig(userConfig) {
602
- let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch = [], shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal } = userConfig;
712
+ let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch = [], shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false } = userConfig;
603
713
  outDir = path.resolve(cwd, outDir);
604
714
  clean = resolveClean(clean, outDir, cwd);
605
715
  const pkg = await readPackageJson(cwd);
@@ -611,6 +721,7 @@ async function resolveConfig(userConfig) {
611
721
  if (typeof external === "string") external = resolveRegex(external);
612
722
  if (typeof noExternal === "string") noExternal = resolveRegex(noExternal);
613
723
  if (publint$1 === true) publint$1 = {};
724
+ if (exports === true) exports = {};
614
725
  if (publicDir) if (copy$1) throw new TypeError("`publicDir` is deprecated. Cannot be used with `copy`");
615
726
  else logger.warn(`${blue`publicDir`} is deprecated. Use ${blue`copy`} instead.`);
616
727
  if (fromVite) {
@@ -651,7 +762,8 @@ async function resolveConfig(userConfig) {
651
762
  hash: hash ?? true,
652
763
  name,
653
764
  external,
654
- noExternal
765
+ noExternal,
766
+ exports
655
767
  };
656
768
  return config;
657
769
  }
@@ -714,15 +826,20 @@ async function buildSingle(config, clean) {
714
826
  await clean();
715
827
  let hasErrors = false;
716
828
  const isMultiFormat = formats.length > 1;
829
+ const chunks = {};
717
830
  await Promise.all(formats.map(async (format) => {
718
831
  try {
719
- const buildOptions = await getBuildOptions(config, format, false, isMultiFormat);
832
+ const buildOptions = await getBuildOptions(config, format, isMultiFormat, false);
720
833
  await hooks.callHook("build:before", {
721
834
  ...context,
722
835
  buildOptions
723
836
  });
724
- await build$1(buildOptions);
725
- if (format === "cjs" && dts) await build$1(await getBuildOptions(config, format, true, isMultiFormat));
837
+ const { output } = await build$1(buildOptions);
838
+ chunks[format] = output;
839
+ if (format === "cjs" && dts) {
840
+ const { output: output$1 } = await build$1(await getBuildOptions(config, format, isMultiFormat, true));
841
+ chunks[format].push(...output$1);
842
+ }
726
843
  } catch (error) {
727
844
  if (watch) {
728
845
  logger.error(error);
@@ -733,6 +850,7 @@ async function buildSingle(config, clean) {
733
850
  }
734
851
  }));
735
852
  if (hasErrors) return;
853
+ await writeExports(config, chunks);
736
854
  await publint(config);
737
855
  await copy(config);
738
856
  await hooks.callHook("build:done", context);
@@ -749,7 +867,7 @@ async function buildSingle(config, clean) {
749
867
  } else await onSuccess?.(config);
750
868
  }
751
869
  }
752
- async function getBuildOptions(config, format, cjsDts, isMultiFormat) {
870
+ async function getBuildOptions(config, format, isMultiFormat, cjsDts) {
753
871
  const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report, env, removeNodeProtocol, loader, name } = config;
754
872
  const plugins = [];
755
873
  if (removeNodeProtocol) plugins.push(NodeProtocolPlugin());
@@ -806,7 +924,7 @@ async function getBuildOptions(config, format, cjsDts, isMultiFormat) {
806
924
  sourcemap,
807
925
  dir: outDir,
808
926
  target,
809
- minify,
927
+ minify: !cjsDts && minify,
810
928
  entryFileNames,
811
929
  chunkFileNames
812
930
  }, config.outputOptions, [format]);
@@ -117,4 +117,4 @@ function hue2rgb(p, q, t) {
117
117
  }
118
118
 
119
119
  //#endregion
120
- export { debounce, generateColor, logger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };
120
+ export { debounce, generateColor, logger as logger$1, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };
@@ -1,5 +1,5 @@
1
- import { logger } from "./logger-DcIo21Wv.js";
2
- import { version } from "./package-BjscpG31.js";
1
+ import { logger$1 as logger } from "./logger-CS4H_tpu.js";
2
+ import { version } from "./package-CkWLthTs.js";
3
3
  import process from "node:process";
4
4
  import { bold, green, underline } from "ansis";
5
5
  import { readFile, unlink, writeFile } from "node:fs/promises";
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.12.1";
3
+
4
+ //#endregion
5
+ export { version };
@@ -1,8 +1,9 @@
1
- import { logger, noop, prettyFormat, prettyName, toArray } from "./logger-DcIo21Wv.js";
1
+ import { logger$1 as logger, noop, prettyFormat, prettyName, toArray } from "./logger-CS4H_tpu.js";
2
2
  import path, { dirname, normalize, sep } from "node:path";
3
3
  import { bold, dim, green, underline } from "ansis";
4
- import Debug from "debug";
4
+ import debug from "debug";
5
5
  import { access, chmod, cp, rm, stat } from "node:fs/promises";
6
+ import { RE_DTS } from "rolldown-plugin-dts";
6
7
  import { Buffer } from "node:buffer";
7
8
  import { promisify } from "node:util";
8
9
  import { brotliCompress, gzip } from "node:zlib";
@@ -47,7 +48,7 @@ function lowestCommonAncestor(...filepaths) {
47
48
 
48
49
  //#endregion
49
50
  //#region src/features/external.ts
50
- const debug$1 = Debug("tsdown:external");
51
+ const debug$2 = debug("tsdown:external");
51
52
  function ExternalPlugin(options) {
52
53
  const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
53
54
  return {
@@ -70,7 +71,7 @@ function ExternalPlugin(options) {
70
71
  }
71
72
  if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
72
73
  if (shouldExternal) {
73
- debug$1("External dependency:", id);
74
+ debug$2("External dependency:", id);
74
75
  return {
75
76
  id,
76
77
  external: shouldExternal
@@ -119,10 +120,9 @@ function formatBytes(bytes) {
119
120
 
120
121
  //#endregion
121
122
  //#region src/features/report.ts
122
- const debug = Debug("tsdown:report");
123
+ const debug$1 = debug("tsdown:report");
123
124
  const brotliCompressAsync = promisify(brotliCompress);
124
125
  const gzipAsync = promisify(gzip);
125
- const RE_DTS = /\.d\.[cm]?ts$/;
126
126
  function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
127
127
  return {
128
128
  name: "tsdown:report",
@@ -161,19 +161,19 @@ function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
161
161
  };
162
162
  }
163
163
  async function calcSize(options, chunk) {
164
- debug(`Calculating size for`, chunk.fileName);
164
+ debug$1(`Calculating size for`, chunk.fileName);
165
165
  const content = chunk.type === "chunk" ? chunk.code : chunk.source;
166
166
  const raw = Buffer.byteLength(content, "utf8");
167
- debug("[size]", chunk.fileName, raw);
167
+ debug$1("[size]", chunk.fileName, raw);
168
168
  let gzip$1 = Infinity;
169
169
  let brotli = Infinity;
170
- if (raw > (options.maxCompressSize ?? 1e6)) debug(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
170
+ if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
171
171
  else {
172
172
  gzip$1 = (await gzipAsync(content)).length;
173
- debug("[gzip]", chunk.fileName, gzip$1);
173
+ debug$1("[gzip]", chunk.fileName, gzip$1);
174
174
  if (options.brotli) {
175
175
  brotli = (await brotliCompressAsync(content)).length;
176
- debug("[brotli]", chunk.fileName, brotli);
176
+ debug$1("[brotli]", chunk.fileName, brotli);
177
177
  }
178
178
  }
179
179
  return {
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReportPlugin$1 as ReportPlugin, ResolvedOptions } from "./types-CsOn0For.js";
1
+ import { ReportPlugin$1 as ReportPlugin, ResolvedOptions } from "./config-BVsukpAr.js";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
package/dist/plugins.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-BV3QPDFO.js";
2
- import "./logger-DcIo21Wv.js";
1
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-D-fqvWYC.js";
2
+ import "./logger-CS4H_tpu.js";
3
3
 
4
4
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
package/dist/run.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { logger, resolveComma, toArray } from "./logger-DcIo21Wv.js";
3
- import { version } from "./package-BjscpG31.js";
2
+ import { logger$1 as logger, resolveComma, toArray } from "./logger-CS4H_tpu.js";
3
+ import { version } from "./package-CkWLthTs.js";
4
4
  import module from "node:module";
5
5
  import process from "node:process";
6
6
  import { dim } from "ansis";
7
7
  import { VERSION } from "rolldown";
8
- import Debug from "debug";
8
+ import debug from "debug";
9
9
  import { cac } from "cac";
10
10
 
11
11
  //#region src/cli.ts
@@ -14,7 +14,7 @@ cli.help().version(version);
14
14
  cli.command("[...files]", "Bundle files", {
15
15
  ignoreOptionDefaultValue: true,
16
16
  allowUnknownOptions: true
17
- }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("-W, --workspace [dir]", "Enable workspace mode").option("-f, --filter <pattern>", "Filter workspace packages, e.g. /regex/ or substring").action(async (input, flags) => {
17
+ }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter workspace packages, e.g. /regex/ or substring").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
18
18
  logger.setSilent(!!flags.silent);
19
19
  logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
20
20
  const { build: build$1 } = await import("./index.js");
@@ -22,7 +22,7 @@ cli.command("[...files]", "Bundle files", {
22
22
  await build$1(flags);
23
23
  });
24
24
  cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
25
- const { migrate } = await import("./migrate-hgmWgN5I.js");
25
+ const { migrate } = await import("./migrate-BPmYzyBD.js");
26
26
  await migrate(args);
27
27
  });
28
28
  async function runCLI() {
@@ -31,10 +31,10 @@ async function runCLI() {
31
31
  let namespace;
32
32
  if (cli.options.debug === true) namespace = "tsdown:*";
33
33
  else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
34
- const enabled = Debug.disable();
34
+ const enabled = debug.disable();
35
35
  if (enabled) namespace += `,${enabled}`;
36
- Debug.enable(namespace);
37
- Debug("tsdown:debug")("Debugging enabled", namespace);
36
+ debug.enable(namespace);
37
+ debug("tsdown:debug")("Debugging enabled", namespace);
38
38
  }
39
39
  try {
40
40
  await cli.runMatchedCommand();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.11.13",
3
+ "version": "0.12.1",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -25,6 +25,7 @@
25
25
  ".": "./dist/index.js",
26
26
  "./config": "./dist/config.js",
27
27
  "./plugins": "./dist/plugins.js",
28
+ "./run": "./dist/run.js",
28
29
  "./package.json": "./package.json"
29
30
  },
30
31
  "typesVersions": {
@@ -70,7 +71,7 @@
70
71
  "empathic": "^1.1.0",
71
72
  "hookable": "^5.5.3",
72
73
  "rolldown": "1.0.0-beta.9",
73
- "rolldown-plugin-dts": "^0.13.3",
74
+ "rolldown-plugin-dts": "^0.13.4",
74
75
  "semver": "^7.7.2",
75
76
  "tinyexec": "^1.0.1",
76
77
  "tinyglobby": "^0.2.13",
@@ -1,13 +0,0 @@
1
- import { UserConfig, UserConfigFn } from "./types-CsOn0For.js";
2
-
3
- //#region src/config.d.ts
4
- /**
5
- * Defines the configuration for tsdown.
6
- */
7
- /**
8
- * Defines the configuration for tsdown.
9
- */
10
- declare function defineConfig(options: UserConfig | UserConfigFn): UserConfig | UserConfigFn;
11
-
12
- //#endregion
13
- export { defineConfig as defineConfig$1 };
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.11.13";
3
-
4
- //#endregion
5
- export { version };