tsdown 0.11.7 → 0.11.9

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,4 +1,4 @@
1
- import { UserConfig, UserConfigFn } from "./index-DSS5MGRw.js";
1
+ import { UserConfig, UserConfigFn } from "./index-B5B9KM9d.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  /**
package/dist/config.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { UserConfig, UserConfigFn } from "./index-DSS5MGRw.js";
2
- import { defineConfig$1 as defineConfig } from "./config-DwXF0PxK.js";
1
+ import { UserConfig, UserConfigFn } from "./index-B5B9KM9d.js";
2
+ import { defineConfig$1 as defineConfig } from "./config-Cyqx6Xup.js";
3
3
  export { UserConfig, UserConfigFn, defineConfig };
@@ -86,7 +86,7 @@ interface ReportOptions {
86
86
  */
87
87
  maxCompressSize?: number;
88
88
  }
89
- declare function ReportPlugin(options: ReportOptions, cwd: string, cjsDts?: boolean): Plugin;
89
+ declare function ReportPlugin(options: ReportOptions, cwd: string, cjsDts?: boolean, name?: string, isMultiFormat?: boolean): Plugin;
90
90
 
91
91
  //#endregion
92
92
  //#region src/options/index.d.ts
@@ -94,6 +94,23 @@ type Sourcemap = boolean | "inline" | "hidden";
94
94
  type Format = Exclude<ModuleFormat, "experimental-app">;
95
95
  type NormalizedFormat = Exclude<InternalModuleFormat, "app">;
96
96
  type ModuleTypes = Record<string, "js" | "jsx" | "ts" | "tsx" | "json" | "text" | "base64" | "dataurl" | "binary" | "empty" | "css" | "asset">;
97
+ interface Workspace {
98
+ /**
99
+ * Workspace directories. Glob patterns are supported.
100
+ * - `auto`: Automatically detect `package.json` files in the workspace.
101
+ * @default 'auto'
102
+ */
103
+ include?: Arrayable<string> | "auto";
104
+ /**
105
+ * Exclude directories from workspace.
106
+ * Defaults to all `node_modules`, `dist`, `test`, `tests`, `temp`, and `tmp` directories.
107
+ */
108
+ exclude?: Arrayable<string>;
109
+ /**
110
+ * Path to the workspace configuration file.
111
+ */
112
+ config?: boolean | string;
113
+ }
97
114
  /**
98
115
  * Options for tsdown.
99
116
  */
@@ -149,6 +166,11 @@ interface Options$3 {
149
166
  /** @default false */
150
167
  shims?: boolean;
151
168
  /**
169
+ * The name to show in CLI output. This is useful for monorepos or workspaces.
170
+ * Defaults to the package name from `package.json`.
171
+ */
172
+ name?: string;
173
+ /**
152
174
  * Use a fixed extension for output files.
153
175
  * The extension will always be `.cjs` or `.mjs`.
154
176
  * Otherwise, it will depend on the package type.
@@ -164,6 +186,16 @@ interface Options$3 {
164
186
  /** @default true */
165
187
  treeshake?: boolean;
166
188
  plugins?: InputOptions["plugins"];
189
+ /**
190
+ * Sets how input files are processed.
191
+ * For example, use 'js' to treat files as JavaScript or 'base64' for images.
192
+ * Lets you import or require files like images or fonts.
193
+ * @example
194
+ * ```json
195
+ * { '.jpg': 'asset', '.png': 'base64' }
196
+ * ```
197
+ */
198
+ loader?: ModuleTypes;
167
199
  /** @default false */
168
200
  silent?: boolean;
169
201
  /**
@@ -255,26 +287,26 @@ interface Options$3 {
255
287
  hash?: boolean;
256
288
  /**
257
289
  * The working directory of the config file.
258
- * @default process.cwd()
290
+ * - Defaults to `process.cwd()` for root config.
291
+ * - Defaults to the package directory for workspace config.
259
292
  */
260
293
  cwd?: string;
261
294
  /**
262
- * Sets how input files are processed.
263
- * For example, use 'js' to treat files as JavaScript or 'base64' for images.
264
- * Lets you import or require files like images or fonts.
265
- * @example
266
- * ```json
267
- * { '.jpg': 'asset', '.png': 'base64' }
268
- * ```
295
+ * **[experimental]** Enable workspace mode.
296
+ * This allows you to build multiple packages in a monorepo.
269
297
  */
270
- loader?: ModuleTypes;
298
+ workspace?: Workspace | Arrayable<string> | true;
299
+ /**
300
+ * Filter workspace packages. This option is only available in workspace mode.
301
+ */
302
+ filter?: RegExp | string | string[];
271
303
  }
272
304
  /**
273
305
  * Options without specifying config file path.
274
306
  */
275
- type UserConfig = Arrayable<Omit<Options$3, "config">>;
307
+ type UserConfig = Arrayable<Omit<Options$3, "config" | "filter">>;
276
308
  type UserConfigFn = (cliOptions: Options$3) => Awaitable<UserConfig>;
277
- type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader">, {
309
+ type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" | "workspace" | "filter">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name">, {
278
310
  format: NormalizedFormat[];
279
311
  target?: string[];
280
312
  clean: string[];
package/dist/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
- import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn } from "./index-DSS5MGRw.js";
2
- import { defineConfig$1 as defineConfig } from "./config-DwXF0PxK.js";
1
+ import { BuildContext, Options, ResolvedOptions, TsdownHooks, UserConfig, UserConfigFn } from "./index-B5B9KM9d.js";
2
+ import { defineConfig$1 as defineConfig } from "./config-Cyqx6Xup.js";
3
+ import "ansis";
4
+ import { InternalModuleFormat } from "rolldown";
3
5
 
4
6
  //#region src/utils/logger.d.ts
5
7
  declare class Logger {
6
8
  silent: boolean;
7
9
  setSilent(value: boolean): void;
10
+ filter(...args: any[]): any[];
8
11
  info(...args: any[]): void;
9
12
  warn(...args: any[]): void;
10
13
  error(...args: any[]): void;
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { defineConfig } from "./config-yiJy1jd0.js";
2
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, getPackageType, lowestCommonAncestor, normalizeFormat, prettyFormat, readPackageJson } from "./plugins-CPt-D0Cs.js";
3
- import { debounce, resolveComma, slash, toArray } from "./general-CPYs4M61.js";
4
- import { logger } from "./logger-DYeY_1KP.js";
2
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, lowestCommonAncestor } from "./plugins-G7Z0rtO5.js";
3
+ import { debounce, generateColor, logger, prettyName, resolveComma, slash, toArray } from "./logger-BdIBA2vO.js";
5
4
  import path from "node:path";
6
5
  import process from "node:process";
7
6
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -11,10 +10,12 @@ import { build as build$1 } from "rolldown";
11
10
  import { transformPlugin } from "rolldown/experimental";
12
11
  import { exec } from "tinyexec";
13
12
  import { glob } from "tinyglobby";
13
+ import { readFile } from "node:fs/promises";
14
14
  import { createHooks } from "hookable";
15
+ import { up } from "empathic/package";
15
16
  import readline from "node:readline";
16
17
  import minVersion from "semver/ranges/min-version.js";
17
- import { up } from "empathic/find";
18
+ import { up as up$1 } from "empathic/find";
18
19
  import { loadConfig } from "unconfig";
19
20
 
20
21
  //#region src/features/clean.ts
@@ -58,10 +59,10 @@ async function copy(options) {
58
59
  await Promise.all(toArray(copy$1).map((dir) => {
59
60
  const from = typeof dir === "string" ? dir : dir.from;
60
61
  const to = typeof dir === "string" ? path.resolve(options.outDir, path.basename(from)) : dir.to;
61
- return cp(options.cwd, from, to);
62
+ return cp$1(options.cwd, from, to);
62
63
  }));
63
64
  }
64
- function cp(cwd, from, to) {
65
+ function cp$1(cwd, from, to) {
65
66
  return fsCopy(path.resolve(cwd, from), path.resolve(cwd, to));
66
67
  }
67
68
 
@@ -133,6 +134,35 @@ async function LightningCSSPlugin(options) {
133
134
  return LightningCSS.default({ options: { targets } });
134
135
  }
135
136
 
137
+ //#endregion
138
+ //#region src/utils/package.ts
139
+ const debug$2 = Debug("tsdown:package");
140
+ async function readPackageJson(dir) {
141
+ const packageJsonPath = up({ cwd: dir });
142
+ if (!packageJsonPath) return;
143
+ debug$2("Reading package.json:", packageJsonPath);
144
+ const contents = await readFile(packageJsonPath, "utf8");
145
+ return JSON.parse(contents);
146
+ }
147
+ function getPackageType(pkg) {
148
+ if (pkg?.type) {
149
+ if (!["module", "commonjs"].includes(pkg.type)) throw new Error(`Invalid package.json type: ${pkg.type}`);
150
+ return pkg.type;
151
+ }
152
+ }
153
+ function normalizeFormat(format) {
154
+ return resolveComma(toArray(format, "es")).map((format$1) => {
155
+ switch (format$1) {
156
+ case "es":
157
+ case "esm":
158
+ case "module": return "es";
159
+ case "cjs":
160
+ case "commonjs": return "cjs";
161
+ default: return format$1;
162
+ }
163
+ });
164
+ }
165
+
136
166
  //#endregion
137
167
  //#region src/features/output.ts
138
168
  function resolveJsOutputExtension(packageType, format, fixedExtension) {
@@ -168,19 +198,20 @@ function createChunkFilename(basename, jsExtension, dtsExtension) {
168
198
 
169
199
  //#endregion
170
200
  //#region src/features/publint.ts
171
- const debug$2 = Debug("tsdown:publint");
201
+ const debug$1 = Debug("tsdown:publint");
172
202
  async function publint(options) {
173
203
  if (!options.publint) return;
174
204
  if (!options.pkg) {
175
205
  logger.warn("publint is enabled but package.json is not found");
176
206
  return;
177
207
  }
178
- debug$2("Running publint");
208
+ const t = performance.now();
209
+ debug$1("Running publint");
179
210
  const { publint: publint$1 } = await import("publint");
180
211
  const { formatMessage } = await import("publint/utils");
181
212
  const { messages } = await publint$1(options.publint === true ? {} : options.publint);
182
- debug$2("Found %d issues", messages.length);
183
- if (!messages.length) logger.success("No publint issues found");
213
+ debug$1("Found %d issues", messages.length);
214
+ if (!messages.length) logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
184
215
  let hasError = false;
185
216
  for (const message of messages) {
186
217
  hasError ||= message.type === "error";
@@ -193,7 +224,7 @@ async function publint(options) {
193
224
  logger[logType](formattedMessage);
194
225
  }
195
226
  if (hasError) {
196
- debug$2("Found errors, setting exit code to 1");
227
+ debug$1("Found errors, setting exit code to 1");
197
228
  process.exitCode = 1;
198
229
  }
199
230
  }
@@ -263,12 +294,12 @@ function shortcuts(restart) {
263
294
 
264
295
  //#endregion
265
296
  //#region src/features/watch.ts
266
- const endsWithPackageJson = /[\\/]package\.json$/;
267
- async function watchBuild(options, configFile, rebuild, restart) {
297
+ const endsWithConfig = /[\\/](?:package\.json|tsdown\.config.*)$/;
298
+ async function watchBuild(options, configFiles, rebuild, restart) {
268
299
  if (typeof options.watch === "boolean" && options.outDir === options.cwd) throw new Error(`Watch is enabled, but output directory is the same as the current working directory.Please specify a different watch directory using ${blue`watch`} option,or set ${blue`outDir`} to a different directory.`);
269
300
  const files = toArray(typeof options.watch === "boolean" ? options.cwd : options.watch);
270
301
  logger.info(`Watching for changes in ${files.join(", ")}`);
271
- if (configFile) files.push(configFile);
302
+ files.push(...configFiles);
272
303
  const { watch } = await import("chokidar");
273
304
  const debouncedRebuild = debounce(rebuild, 100);
274
305
  const watcher = watch(files, {
@@ -281,7 +312,7 @@ async function watchBuild(options, configFile, rebuild, restart) {
281
312
  ]
282
313
  });
283
314
  watcher.on("all", (type, file) => {
284
- if (endsWithPackageJson.test(file) || configFile === file) {
315
+ if (configFiles.includes(file) || endsWithConfig.test(file)) {
285
316
  logger.info(`Reload config: ${file}`);
286
317
  restart();
287
318
  return;
@@ -294,12 +325,13 @@ async function watchBuild(options, configFile, rebuild, restart) {
294
325
 
295
326
  //#endregion
296
327
  //#region src/features/entry.ts
297
- async function resolveEntry(entry, cwd) {
298
- if (!entry || Object.keys(entry).length === 0) throw new Error(`No input files, try "tsdown <your-file>" instead`);
328
+ async function resolveEntry(entry, cwd, name) {
329
+ const nameLabel = name ? `[${name}] ` : "";
330
+ if (!entry || Object.keys(entry).length === 0) throw new Error(`${nameLabel}No input files, try "tsdown <your-file>" instead`);
299
331
  const entryMap = await toObjectEntry(entry, cwd);
300
332
  const entries = Object.values(entryMap);
301
- if (entries.length === 0) throw new Error(`Cannot find entry: ${JSON.stringify(entry)}`);
302
- logger.info(`entry: ${blue(entries.map((entry$1) => path.relative(cwd, entry$1)).join(", "))}`);
333
+ if (entries.length === 0) throw new Error(`${nameLabel}Cannot find entry: ${JSON.stringify(entry)}`);
334
+ logger.info(prettyName(name), `entry: ${generateColor(name)(entries.map((entry$1) => path.relative(cwd, entry$1)).join(", "))}`);
303
335
  return entryMap;
304
336
  }
305
337
  async function toObjectEntry(entry, cwd) {
@@ -318,7 +350,7 @@ async function toObjectEntry(entry, cwd) {
318
350
 
319
351
  //#endregion
320
352
  //#region src/features/target.ts
321
- function resolveTarget(target, pkg) {
353
+ function resolveTarget(target, pkg, name) {
322
354
  if (target === false) return;
323
355
  if (target == null) {
324
356
  const pkgTarget = resolvePackageTarget(pkg);
@@ -326,7 +358,7 @@ function resolveTarget(target, pkg) {
326
358
  else return;
327
359
  }
328
360
  const targets = resolveComma(toArray(target));
329
- if (targets.length) logger.info(`target${targets.length > 1 ? "s" : ""}: ${blue(targets.join(", "))}`);
361
+ if (targets.length) logger.info(prettyName(name), `target${targets.length > 1 ? "s" : ""}: ${generateColor(name)(targets.join(", "))}`);
330
362
  return targets;
331
363
  }
332
364
  function resolvePackageTarget(pkg) {
@@ -341,9 +373,9 @@ function resolvePackageTarget(pkg) {
341
373
  //#endregion
342
374
  //#region src/features/tsconfig.ts
343
375
  function findTsconfig(cwd, name = "tsconfig.json") {
344
- return up(name, { cwd }) || false;
376
+ return up$1(name, { cwd }) || false;
345
377
  }
346
- async function resolveTsconfig(tsconfig, cwd) {
378
+ async function resolveTsconfig(tsconfig, cwd, name) {
347
379
  const original = tsconfig;
348
380
  if (tsconfig !== false) {
349
381
  if (tsconfig === true || tsconfig == null) {
@@ -351,9 +383,9 @@ async function resolveTsconfig(tsconfig, cwd) {
351
383
  if (original && !tsconfig) logger.warn(`No tsconfig found in ${blue(cwd)}`);
352
384
  } else {
353
385
  const tsconfigPath = path.resolve(cwd, tsconfig);
354
- const stat = await fsStat(tsconfigPath);
355
- if (stat?.isFile()) tsconfig = tsconfigPath;
356
- else if (stat?.isDirectory()) {
386
+ const stat$1 = await fsStat(tsconfigPath);
387
+ if (stat$1?.isFile()) tsconfig = tsconfigPath;
388
+ else if (stat$1?.isDirectory()) {
357
389
  tsconfig = findTsconfig(tsconfigPath);
358
390
  if (!tsconfig) logger.warn(`No tsconfig found in ${blue(tsconfigPath)}`);
359
391
  } else {
@@ -361,7 +393,7 @@ async function resolveTsconfig(tsconfig, cwd) {
361
393
  if (!tsconfig) logger.warn(`tsconfig ${blue(original)} doesn't exist`);
362
394
  }
363
395
  }
364
- if (tsconfig) logger.info(`Using tsconfig: ${underline(path.relative(cwd, tsconfig))}`);
396
+ if (tsconfig) logger.info(prettyName(name), `tsconfig: ${generateColor(name)(path.relative(cwd, tsconfig))}`);
365
397
  }
366
398
  return tsconfig;
367
399
  }
@@ -396,11 +428,11 @@ async function loadViteConfig(prefix, cwd) {
396
428
  return resolved;
397
429
  }
398
430
  let loaded = false;
399
- async function loadConfigFile(options) {
431
+ async function loadConfigFile(options, workspace) {
400
432
  let cwd = options.cwd || process.cwd();
401
433
  let overrideConfig = false;
402
434
  let { config: filePath } = options;
403
- if (filePath === false) return { configs: [] };
435
+ if (filePath === false) return { configs: [{}] };
404
436
  if (typeof filePath === "string") {
405
437
  const stats = await fsStat(filePath);
406
438
  if (stats) {
@@ -440,46 +472,117 @@ async function loadConfigFile(options) {
440
472
  rewrite: (config$1) => config$1?.tsdown
441
473
  }],
442
474
  cwd,
475
+ stopAt: workspace && path.dirname(workspace),
443
476
  defaults: {}
444
477
  }).finally(() => loaded = true);
445
478
  const file = sources[0];
446
479
  if (file) logger.info(`Using tsdown config: ${underline(file)}`);
447
480
  if (typeof config === "function") config = await config(options);
481
+ config = toArray(config);
482
+ if (config.length === 0) config.push({});
448
483
  return {
449
- configs: toArray(config),
484
+ configs: config,
450
485
  file
451
486
  };
452
487
  }
453
488
 
454
489
  //#endregion
455
490
  //#region src/options/index.ts
456
- const debug$1 = Debug("tsdown:options");
491
+ const debug = Debug("tsdown:options");
492
+ const DEFAULT_EXCLUDE_WORKSPACE = [
493
+ "**/node_modules/**",
494
+ "**/dist/**",
495
+ "**/test?(s)/**",
496
+ "**/t?(e)mp/**"
497
+ ];
457
498
  async function resolveOptions(options) {
458
- const { configs: userConfigs, file } = await loadConfigFile(options);
459
- if (userConfigs.length === 0) userConfigs.push({});
499
+ const files = [];
500
+ debug("options %O", options);
501
+ debug("loading config file: %s", options.config);
502
+ const { configs: rootConfigs, file } = await loadConfigFile(options);
460
503
  if (file) {
461
- debug$1("Loaded config file %s", file);
462
- debug$1("User configs %o", userConfigs);
463
- }
464
- const configs = await Promise.all(userConfigs.map((userConfig) => resolveConfig(userConfig, options)));
504
+ files.push(file);
505
+ debug("loaded root config file %s", file);
506
+ debug("root configs %o", rootConfigs);
507
+ } else debug("no root config file found");
508
+ const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
509
+ const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
510
+ if (workspaceFiles) files.push(...workspaceFiles);
511
+ return Promise.all(workspaceConfigs.map((config) => resolveConfig(config)));
512
+ }))).flat();
513
+ debug("resolved configs %O", configs);
465
514
  return {
466
515
  configs,
467
- file
516
+ files
468
517
  };
469
518
  }
470
- async function resolveConfig(userConfig, overrides) {
471
- const subOptions = {
472
- ...userConfig,
473
- ...overrides
519
+ async function resolveWorkspace(config, options) {
520
+ const normalized = {
521
+ ...config,
522
+ ...options
523
+ };
524
+ const rootCwd = normalized.cwd || process.cwd();
525
+ let { workspace } = normalized;
526
+ if (!workspace) return {
527
+ configs: [normalized],
528
+ files: []
474
529
  };
475
- let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd() } = subOptions;
530
+ if (workspace === true) workspace = {};
531
+ else if (typeof workspace === "string" || Array.isArray(workspace)) workspace = { include: workspace };
532
+ let { include: packages = "auto", exclude = DEFAULT_EXCLUDE_WORKSPACE, config: workspaceConfig } = workspace;
533
+ if (packages === "auto") packages = (await glob({
534
+ patterns: "**/package.json",
535
+ ignore: exclude,
536
+ cwd: rootCwd
537
+ })).filter((file) => file !== "package.json").map((file) => path.resolve(rootCwd, file, ".."));
538
+ else packages = (await glob({
539
+ patterns: packages,
540
+ ignore: exclude,
541
+ cwd: rootCwd,
542
+ onlyDirectories: true,
543
+ absolute: true
544
+ })).map((file) => path.resolve(file));
545
+ if (packages.length === 0) throw new Error("No workspace packages found, please check your config");
546
+ if (options.filter) {
547
+ if (typeof options.filter === "string" && options.filter.length > 2 && options.filter[0] === "/" && options.filter.at(-1) === "/") options.filter = new RegExp(options.filter.slice(1, -1));
548
+ packages = packages.filter((path$1) => {
549
+ return typeof options.filter === "string" ? path$1.includes(options.filter) : Array.isArray(options.filter) ? options.filter.some((filter) => path$1.includes(filter)) : options.filter.test(path$1);
550
+ });
551
+ if (packages.length === 0) throw new Error("No packages matched the filters");
552
+ }
553
+ const files = [];
554
+ const configs = (await Promise.all(packages.map(async (cwd) => {
555
+ debug("loading workspace config %s", cwd);
556
+ const { configs: configs$1, file } = await loadConfigFile({
557
+ ...options,
558
+ config: workspaceConfig,
559
+ cwd
560
+ }, cwd);
561
+ if (file) {
562
+ debug("loaded workspace config file %s", file);
563
+ files.push(file);
564
+ } else debug("no workspace config file found in %s", cwd);
565
+ return configs$1.map((config$1) => ({
566
+ ...normalized,
567
+ cwd,
568
+ ...config$1
569
+ }));
570
+ }))).flat();
571
+ return {
572
+ configs,
573
+ files
574
+ };
575
+ }
576
+ async function resolveConfig(userConfig) {
577
+ let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, 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 } = userConfig;
476
578
  outDir = path.resolve(cwd, outDir);
477
579
  clean = resolveClean(clean, outDir, cwd);
478
580
  const pkg = await readPackageJson(cwd);
479
- entry = await resolveEntry(entry, cwd);
581
+ if (workspace) name ||= pkg?.name;
582
+ entry = await resolveEntry(entry, cwd, name);
480
583
  if (dts == null) dts = !!(pkg?.types || pkg?.typings);
481
- target = resolveTarget(target, pkg);
482
- tsconfig = await resolveTsconfig(tsconfig, cwd);
584
+ target = resolveTarget(target, pkg, name);
585
+ tsconfig = await resolveTsconfig(tsconfig, cwd, name);
483
586
  if (publint$1 === true) publint$1 = {};
484
587
  if (publicDir) if (copy$1) throw new TypeError("`publicDir` is deprecated. Cannot be used with `copy`");
485
588
  else logger.warn(`${blue`publicDir`} is deprecated. Use ${blue`copy`} instead.`);
@@ -493,7 +596,7 @@ async function resolveConfig(userConfig, overrides) {
493
596
  }
494
597
  }
495
598
  const config = {
496
- ...subOptions,
599
+ ...userConfig,
497
600
  entry,
498
601
  plugins,
499
602
  format: normalizeFormat(format),
@@ -517,7 +620,8 @@ async function resolveConfig(userConfig, overrides) {
517
620
  env,
518
621
  pkg,
519
622
  copy: publicDir || copy$1,
520
- hash: hash ?? true
623
+ hash: hash ?? true,
624
+ name
521
625
  };
522
626
  return config;
523
627
  }
@@ -531,31 +635,24 @@ async function mergeUserOptions(defaults, user, args) {
531
635
 
532
636
  //#endregion
533
637
  //#region src/index.ts
534
- const debug = Debug("tsdown:main");
535
638
  /**
536
639
  * Build with tsdown.
537
640
  */
538
641
  async function build(userOptions = {}) {
539
642
  if (typeof userOptions.silent === "boolean") logger.setSilent(userOptions.silent);
540
- debug("Loading config");
541
- const { configs, file: configFile } = await resolveOptions(userOptions);
542
- if (configFile) {
543
- debug("Loaded config:", configFile);
544
- configs.forEach((config) => {
545
- debug("using resolved config: %O", config);
546
- });
547
- } else debug("No config file found");
643
+ const { configs, files: configFiles } = await resolveOptions(userOptions);
548
644
  let cleanPromise;
549
645
  const clean = () => {
550
646
  if (cleanPromise) return cleanPromise;
551
647
  return cleanPromise = cleanOutDir(configs);
552
648
  };
649
+ logger.info("Build start");
553
650
  const rebuilds = await Promise.all(configs.map((options) => buildSingle(options, clean)));
554
651
  const cleanCbs = [];
555
652
  for (const [i, config] of configs.entries()) {
556
653
  const rebuild = rebuilds[i];
557
654
  if (!rebuild) continue;
558
- const watcher = await watchBuild(config, configFile, rebuild, restart);
655
+ const watcher = await watchBuild(config, configFiles, rebuild, restart);
559
656
  cleanCbs.push(() => watcher.close());
560
657
  }
561
658
  if (cleanCbs.length) shortcuts(restart);
@@ -586,17 +683,16 @@ async function buildSingle(config, clean) {
586
683
  onSuccessCleanup?.();
587
684
  await clean();
588
685
  let hasErrors = false;
686
+ const isMultiFormat = formats.length > 1;
589
687
  await Promise.all(formats.map(async (format) => {
590
688
  try {
591
- const formatLabel = prettyFormat(format);
592
- logger.info(formatLabel, "Build start");
593
- const buildOptions = await getBuildOptions(config, format);
689
+ const buildOptions = await getBuildOptions(config, format, false, isMultiFormat);
594
690
  await hooks.callHook("build:before", {
595
691
  ...context,
596
692
  buildOptions
597
693
  });
598
694
  await build$1(buildOptions);
599
- if (format === "cjs" && dts) await build$1(await getBuildOptions(config, format, true));
695
+ if (format === "cjs" && dts) await build$1(await getBuildOptions(config, format, true, isMultiFormat));
600
696
  } catch (error) {
601
697
  if (watch) {
602
698
  logger.error(error);
@@ -610,7 +706,7 @@ async function buildSingle(config, clean) {
610
706
  await publint(config);
611
707
  await copy(config);
612
708
  await hooks.callHook("build:done", context);
613
- logger.success(`${first ? "Build" : "Rebuild"} complete in ${green(`${Math.round(performance.now() - startTime)}ms`)}`);
709
+ logger.success(prettyName(config.name), `${first ? "Build" : "Rebuild"} complete in ${green(`${Math.round(performance.now() - startTime)}ms`)}`);
614
710
  if (typeof onSuccess === "string") {
615
711
  const p = exec(onSuccess, [], { nodeOptions: {
616
712
  shell: true,
@@ -623,8 +719,8 @@ async function buildSingle(config, clean) {
623
719
  } else await onSuccess?.(config);
624
720
  }
625
721
  }
626
- async function getBuildOptions(config, format, cjsDts) {
627
- const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report, env, removeNodeProtocol, loader } = config;
722
+ async function getBuildOptions(config, format, cjsDts, isMultiFormat) {
723
+ const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report, env, removeNodeProtocol, loader, name } = config;
628
724
  const plugins = [];
629
725
  if (removeNodeProtocol) plugins.push(NodeProtocolPlugin());
630
726
  if (config.pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config));
@@ -650,9 +746,9 @@ async function getBuildOptions(config, format, cjsDts) {
650
746
  exclude: /\.d\.[cm]?ts$/,
651
747
  transformOptions: { target }
652
748
  }));
653
- plugins.push(ShebangPlugin(cwd));
749
+ plugins.push(ShebangPlugin(cwd, name, isMultiFormat));
654
750
  }
655
- if (report && !logger.silent) plugins.push(ReportPlugin(report, cwd, cjsDts));
751
+ if (report && !logger.silent) plugins.push(ReportPlugin(report, cwd, cjsDts, name, isMultiFormat));
656
752
  if (target) plugins.push(
657
753
  // Use Lightning CSS to handle CSS input. This is a temporary solution
658
754
  // until Rolldown supports CSS syntax lowering natively.
@@ -0,0 +1,116 @@
1
+ import { bgRed, bgYellow, blue, green, rgb, yellow } from "ansis";
2
+
3
+ //#region src/utils/general.ts
4
+ function toArray(val, defaultValue) {
5
+ if (Array.isArray(val)) return val;
6
+ else if (val == null) {
7
+ if (defaultValue) return [defaultValue];
8
+ return [];
9
+ } else return [val];
10
+ }
11
+ function resolveComma(arr) {
12
+ return arr.flatMap((format) => format.split(","));
13
+ }
14
+ function debounce(fn, wait) {
15
+ let timeout;
16
+ return function(...args) {
17
+ if (timeout) clearTimeout(timeout);
18
+ timeout = setTimeout(() => {
19
+ timeout = void 0;
20
+ fn.apply(this, args);
21
+ }, wait);
22
+ };
23
+ }
24
+ function slash(string) {
25
+ return string.replaceAll("\\", "/");
26
+ }
27
+ const noop = (v) => v;
28
+
29
+ //#endregion
30
+ //#region src/utils/logger.ts
31
+ var Logger = class {
32
+ silent = false;
33
+ setSilent(value) {
34
+ this.silent = value;
35
+ }
36
+ filter(...args) {
37
+ return args.filter((arg) => arg !== void 0 && arg !== false);
38
+ }
39
+ info(...args) {
40
+ if (!this.silent) console.info(blue`ℹ`, ...this.filter(...args));
41
+ }
42
+ warn(...args) {
43
+ if (!this.silent) console.warn("\n", bgYellow` WARN `, ...this.filter(...args), "\n");
44
+ }
45
+ error(...args) {
46
+ if (!this.silent) console.error("\n", bgRed` ERROR `, ...this.filter(...args), "\n");
47
+ }
48
+ success(...args) {
49
+ if (!this.silent) console.info(green`✔`, ...this.filter(...args));
50
+ }
51
+ };
52
+ const logger = new Logger();
53
+ function prettyName(name) {
54
+ if (!name) return void 0;
55
+ return generateColor(name)(`[${name}]`);
56
+ }
57
+ function prettyFormat(format) {
58
+ const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
59
+ let formatText;
60
+ switch (format) {
61
+ case "es":
62
+ formatText = "ESM";
63
+ break;
64
+ default:
65
+ formatText = format.toUpperCase();
66
+ break;
67
+ }
68
+ return formatColor(`[${formatText}]`);
69
+ }
70
+ const colors = new Map();
71
+ function generateColor(name = "default") {
72
+ if (colors.has(name)) return colors.get(name);
73
+ let color;
74
+ if (name === "default") color = blue;
75
+ else {
76
+ let hash = 0;
77
+ for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash);
78
+ const hue = hash % 360;
79
+ const saturation = 35;
80
+ const lightness = 55;
81
+ color = rgb(...hslToRgb(hue, saturation, lightness));
82
+ }
83
+ colors.set(name, color);
84
+ return color;
85
+ }
86
+ function hslToRgb(h, s, l) {
87
+ h = h % 360;
88
+ h /= 360;
89
+ s /= 100;
90
+ l /= 100;
91
+ let r, g, b;
92
+ if (s === 0) r = g = b = l;
93
+ else {
94
+ const q = l < .5 ? l * (1 + s) : l + s - l * s;
95
+ const p = 2 * l - q;
96
+ r = hue2rgb(p, q, h + 1 / 3);
97
+ g = hue2rgb(p, q, h);
98
+ b = hue2rgb(p, q, h - 1 / 3);
99
+ }
100
+ return [
101
+ Math.max(0, Math.round(r * 255)),
102
+ Math.max(0, Math.round(g * 255)),
103
+ Math.max(0, Math.round(b * 255))
104
+ ];
105
+ }
106
+ function hue2rgb(p, q, t) {
107
+ if (t < 0) t += 1;
108
+ if (t > 1) t -= 1;
109
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
110
+ if (t < 1 / 2) return q;
111
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
112
+ return p;
113
+ }
114
+
115
+ //#endregion
116
+ export { debounce, generateColor, logger, noop, prettyFormat, prettyName, resolveComma, slash, toArray };
@@ -1,5 +1,5 @@
1
- import { logger } from "./logger-DYeY_1KP.js";
2
- import { version } from "./package-DIqr7O5d.js";
1
+ import { logger } from "./logger-BdIBA2vO.js";
2
+ import { version } from "./package-BbnQTn6e.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.11.9";
3
+
4
+ //#endregion
5
+ export { version };
@@ -1,10 +1,8 @@
1
- import { noop, resolveComma, toArray } from "./general-CPYs4M61.js";
2
- import { logger } from "./logger-DYeY_1KP.js";
1
+ import { logger, noop, prettyFormat, prettyName, toArray } from "./logger-BdIBA2vO.js";
3
2
  import path, { dirname, normalize, sep } from "node:path";
4
- import { blue, bold, dim, green, underline, yellow } from "ansis";
3
+ import { bold, dim, green, underline } from "ansis";
5
4
  import Debug from "debug";
6
- import { access, chmod, cp, readFile, rm, stat } from "node:fs/promises";
7
- import { up } from "empathic/package";
5
+ import { access, chmod, cp, rm, stat } from "node:fs/promises";
8
6
  import { Buffer } from "node:buffer";
9
7
  import { promisify } from "node:util";
10
8
  import { brotliCompress, gzip } from "node:zlib";
@@ -49,7 +47,7 @@ function lowestCommonAncestor(...filepaths) {
49
47
 
50
48
  //#endregion
51
49
  //#region src/features/external.ts
52
- const debug$2 = Debug("tsdown:external");
50
+ const debug$1 = Debug("tsdown:external");
53
51
  function ExternalPlugin(options) {
54
52
  const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
55
53
  return {
@@ -72,7 +70,7 @@ function ExternalPlugin(options) {
72
70
  }
73
71
  if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
74
72
  if (shouldExternal) {
75
- debug$2("External dependency:", id);
73
+ debug$1("External dependency:", id);
76
74
  return {
77
75
  id,
78
76
  external: shouldExternal
@@ -108,52 +106,10 @@ function NodeProtocolPlugin() {
108
106
  };
109
107
  }
110
108
 
111
- //#endregion
112
- //#region src/utils/package.ts
113
- const debug$1 = Debug("tsdown:package");
114
- async function readPackageJson(dir) {
115
- const packageJsonPath = up({ cwd: dir });
116
- if (!packageJsonPath) return;
117
- debug$1("Reading package.json:", packageJsonPath);
118
- const contents = await readFile(packageJsonPath, "utf8");
119
- return JSON.parse(contents);
120
- }
121
- function getPackageType(pkg) {
122
- if (pkg?.type) {
123
- if (!["module", "commonjs"].includes(pkg.type)) throw new Error(`Invalid package.json type: ${pkg.type}`);
124
- return pkg.type;
125
- }
126
- }
127
- function normalizeFormat(format) {
128
- return resolveComma(toArray(format, "es")).map((format$1) => {
129
- switch (format$1) {
130
- case "es":
131
- case "esm":
132
- case "module": return "es";
133
- case "cjs":
134
- case "commonjs": return "cjs";
135
- default: return format$1;
136
- }
137
- });
138
- }
139
- function prettyFormat(format) {
140
- const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
141
- let formatText;
142
- switch (format) {
143
- case "es":
144
- formatText = "ESM";
145
- break;
146
- default:
147
- formatText = format.toUpperCase();
148
- break;
149
- }
150
- return formatColor(`[${formatText}]`);
151
- }
152
-
153
109
  //#endregion
154
110
  //#region src/utils/format.ts
155
111
  function formatBytes(bytes) {
156
- if (bytes === Infinity) return "too large";
112
+ if (bytes === Infinity) return void 0;
157
113
  const numberFormatter = new Intl.NumberFormat("en", {
158
114
  maximumFractionDigits: 2,
159
115
  minimumFractionDigits: 2
@@ -167,7 +123,7 @@ const debug = Debug("tsdown:report");
167
123
  const brotliCompressAsync = promisify(brotliCompress);
168
124
  const gzipAsync = promisify(gzip);
169
125
  const RE_DTS = /\.d\.[cm]?ts$/;
170
- function ReportPlugin(options, cwd, cjsDts) {
126
+ function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
171
127
  return {
172
128
  name: "tsdown:report",
173
129
  async writeBundle(outputOptions, bundle) {
@@ -179,13 +135,13 @@ function ReportPlugin(options, cwd, cjsDts) {
179
135
  }
180
136
  const filenameLength = Math.max(...sizes.map((size) => size.filename.length));
181
137
  const rawTextLength = Math.max(...sizes.map((size) => size.rawText.length));
182
- const gzipTextLength = Math.max(...sizes.map((size) => size.gzipText.length));
183
- const brotliTextLength = Math.max(...sizes.map((size) => size.brotliText.length));
138
+ const gzipTextLength = Math.max(...sizes.map((size) => size.gzipText == null ? 0 : size.gzipText.length));
139
+ const brotliTextLength = Math.max(...sizes.map((size) => size.brotliText == null ? 0 : size.brotliText.length));
184
140
  let totalRaw = 0;
185
141
  for (const size of sizes) {
186
142
  size.rawText = size.rawText.padStart(rawTextLength);
187
- size.gzipText = size.gzipText.padStart(gzipTextLength);
188
- size.brotliText = size.brotliText.padStart(brotliTextLength);
143
+ size.gzipText = size.gzipText?.padStart(gzipTextLength);
144
+ size.brotliText = size.brotliText?.padStart(brotliTextLength);
189
145
  totalRaw += size.raw;
190
146
  }
191
147
  sizes.sort((a, b) => {
@@ -193,13 +149,14 @@ function ReportPlugin(options, cwd, cjsDts) {
193
149
  if (a.isEntry !== b.isEntry) return a.isEntry ? -1 : 1;
194
150
  return b.raw - a.raw;
195
151
  });
196
- const formatLabel = prettyFormat(cjsDts ? "cjs" : outputOptions.format);
152
+ const nameLabel = prettyName(name);
153
+ const formatLabel = isMultiFormat && prettyFormat(cjsDts ? "cjs" : outputOptions.format);
197
154
  for (const size of sizes) {
198
155
  const filenameColor = size.dts ? green : noop;
199
- logger.info(formatLabel, dim(`${outDir}/`) + filenameColor((size.isEntry ? bold : noop)(size.filename)), ` `.repeat(filenameLength - size.filename.length), dim`${size.rawText} gzip: ${size.gzipText}`, options.brotli ? dim` brotli: ${size.brotliText}` : "");
156
+ logger.info(nameLabel, formatLabel, dim(`${outDir}/`) + filenameColor((size.isEntry ? bold : noop)(size.filename)), ` `.repeat(filenameLength - size.filename.length), dim(size.rawText), size.gzipText && dim`│ gzip: ${size.gzipText}`, options.brotli && size.brotliText && dim`│ brotli: ${size.brotliText}`);
200
157
  }
201
158
  const totalSizeText = formatBytes(totalRaw);
202
- logger.info(formatLabel, `${sizes.length} files, total: ${totalSizeText}`);
159
+ logger.info(nameLabel, formatLabel, `${sizes.length} files, total: ${totalSizeText}`);
203
160
  }
204
161
  };
205
162
  }
@@ -235,7 +192,7 @@ async function calcSize(options, chunk) {
235
192
  //#endregion
236
193
  //#region src/features/shebang.ts
237
194
  const RE_SHEBANG = /^#!.*/;
238
- function ShebangPlugin(cwd) {
195
+ function ShebangPlugin(cwd, name, isMultiFormat) {
239
196
  return {
240
197
  name: "tsdown:shebang",
241
198
  async writeBundle(options, bundle) {
@@ -244,7 +201,7 @@ function ShebangPlugin(cwd) {
244
201
  if (!RE_SHEBANG.test(chunk.code)) continue;
245
202
  const filepath = path.resolve(cwd, options.file || path.join(options.dir, chunk.fileName));
246
203
  if (await fsExists(filepath)) {
247
- logger.info(prettyFormat(options.format), `Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
204
+ logger.info(prettyName(name), isMultiFormat && prettyFormat(options.format), `Granting execute permission to ${underline(path.relative(cwd, filepath))}`);
248
205
  await chmod(filepath, 493);
249
206
  }
250
207
  }
@@ -253,4 +210,4 @@ function ShebangPlugin(cwd) {
253
210
  }
254
211
 
255
212
  //#endregion
256
- export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, getPackageType, lowestCommonAncestor, normalizeFormat, prettyFormat, readPackageJson };
213
+ export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsRemove, fsStat, lowestCommonAncestor };
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReportPlugin$1 as ReportPlugin, ResolvedOptions } from "./index-DSS5MGRw.js";
1
+ import { ReportPlugin$1 as ReportPlugin, ResolvedOptions } from "./index-B5B9KM9d.js";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
@@ -7,7 +7,7 @@ declare function ExternalPlugin(options: ResolvedOptions): Plugin;
7
7
 
8
8
  //#endregion
9
9
  //#region src/features/shebang.d.ts
10
- declare function ShebangPlugin(cwd: string): Plugin;
10
+ declare function ShebangPlugin(cwd: string, name?: string, isMultiFormat?: boolean): Plugin;
11
11
 
12
12
  //#endregion
13
13
  //#region src/features/node-protocol.d.ts
package/dist/plugins.js CHANGED
@@ -1,5 +1,4 @@
1
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-CPt-D0Cs.js";
2
- import "./general-CPYs4M61.js";
3
- import "./logger-DYeY_1KP.js";
1
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-G7Z0rtO5.js";
2
+ import "./logger-BdIBA2vO.js";
4
3
 
5
4
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
package/dist/run.js CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { resolveComma, toArray } from "./general-CPYs4M61.js";
3
- import { logger } from "./logger-DYeY_1KP.js";
4
- import { version } from "./package-DIqr7O5d.js";
2
+ import { logger, resolveComma, toArray } from "./logger-BdIBA2vO.js";
3
+ import { version } from "./package-BbnQTn6e.js";
5
4
  import module from "node:module";
6
5
  import process from "node:process";
7
6
  import { dim } from "ansis";
@@ -12,7 +11,10 @@ import { cac } from "cac";
12
11
  //#region src/cli.ts
13
12
  const cli = cac("tsdown");
14
13
  cli.help().version(version);
15
- cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).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").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [scope]", "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("--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").action(async (input, flags) => {
14
+ cli.command("[...files]", "Bundle files", {
15
+ ignoreOptionDefaultValue: true,
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").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [scope]", "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("--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) => {
16
18
  logger.setSilent(!!flags.silent);
17
19
  logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
18
20
  const { build: build$1 } = await import("./index.js");
@@ -20,7 +22,7 @@ cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).op
20
22
  await build$1(flags);
21
23
  });
22
24
  cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
23
- const { migrate } = await import("./migrate-iRKeD4mW.js");
25
+ const { migrate } = await import("./migrate-CDIgKGak.js");
24
26
  await migrate(args);
25
27
  });
26
28
  async function runCLI() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,28 +0,0 @@
1
- //#region src/utils/general.ts
2
- function toArray(val, defaultValue) {
3
- if (Array.isArray(val)) return val;
4
- else if (val == null) {
5
- if (defaultValue) return [defaultValue];
6
- return [];
7
- } else return [val];
8
- }
9
- function resolveComma(arr) {
10
- return arr.flatMap((format) => format.split(","));
11
- }
12
- function debounce(fn, wait) {
13
- let timeout;
14
- return function(...args) {
15
- if (timeout) clearTimeout(timeout);
16
- timeout = setTimeout(() => {
17
- timeout = void 0;
18
- fn.apply(this, args);
19
- }, wait);
20
- };
21
- }
22
- function slash(string) {
23
- return string.replaceAll("\\", "/");
24
- }
25
- const noop = (v) => v;
26
-
27
- //#endregion
28
- export { debounce, noop, resolveComma, slash, toArray };
@@ -1,25 +0,0 @@
1
- import { bgRed, bgYellow, blue, green } from "ansis";
2
-
3
- //#region src/utils/logger.ts
4
- var Logger = class {
5
- silent = false;
6
- setSilent(value) {
7
- this.silent = value;
8
- }
9
- info(...args) {
10
- if (!this.silent) console.info(blue`ℹ`, ...args);
11
- }
12
- warn(...args) {
13
- if (!this.silent) console.warn("\n", bgYellow` WARN `, ...args, "\n");
14
- }
15
- error(...args) {
16
- if (!this.silent) console.error("\n", bgRed` ERROR `, ...args, "\n");
17
- }
18
- success(...args) {
19
- if (!this.silent) console.info(green`✔`, ...args);
20
- }
21
- };
22
- const logger = new Logger();
23
-
24
- //#endregion
25
- export { logger };
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.11.7";
3
-
4
- //#endregion
5
- export { version };