tsdown 0.13.2 → 0.13.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.
@@ -1,4 +1,4 @@
1
- import { UserConfig, UserConfigFn } from "./types-DIH2hGTd.mjs";
1
+ import { UserConfig, UserConfigFn } from "./types-DahUJE7h.mjs";
2
2
 
3
3
  //#region src/config.d.ts
4
4
 
package/dist/config.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { UserConfig, UserConfigFn } from "./types-DIH2hGTd.mjs";
2
- import { defineConfig } from "./config-CZj6NGiw.mjs";
1
+ import { UserConfig, UserConfigFn } from "./types-DahUJE7h.mjs";
2
+ import { defineConfig } from "./config-aSq_QiwF.mjs";
3
3
  export { UserConfig, UserConfigFn, defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,21 +1,8 @@
1
- import { AttwOptions, BuildContext, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, DtsOptions, ExportsOptions, Format, ModuleTypes, NormalizedFormat, NormalizedUserConfig, Options, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageType, PublintOptions, ReportOptions, ResolvedOptions, RolldownContext, Sourcemap, TsdownChunks, TsdownHooks, UnusedOptions, UserConfig, UserConfigFn, Workspace } from "./types-DIH2hGTd.mjs";
2
- import { defineConfig } from "./config-CZj6NGiw.mjs";
3
- import "ansis";
4
- import { InternalModuleFormat } from "rolldown";
1
+ import { AttwOptions, BuildContext, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, DtsOptions, ExportsOptions, Format, Logger, ModuleTypes, NormalizedFormat, NormalizedUserConfig, Options, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageType, PublintOptions, ReportOptions, ResolvedOptions, RolldownContext, Sourcemap, TsdownChunks, TsdownHooks, UnusedOptions, UserConfig, UserConfigFn, Workspace, globalLogger } from "./types-DahUJE7h.mjs";
2
+ import { defineConfig } from "./config-aSq_QiwF.mjs";
5
3
 
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;
17
- //#endregion
18
4
  //#region src/index.d.ts
5
+
19
6
  /**
20
7
  * Build with tsdown.
21
8
  */
@@ -32,4 +19,4 @@ declare const shimFile: string;
32
19
  */
33
20
  declare function buildSingle(config: ResolvedOptions, clean: () => Promise<void>): Promise<(() => Promise<void>) | undefined>;
34
21
  //#endregion
35
- export { AttwOptions, BuildContext, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, DtsOptions, ExportsOptions, Format, type Logger, ModuleTypes, NormalizedFormat, NormalizedUserConfig, type Options, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageType, PublintOptions, ReportOptions, type ResolvedOptions, RolldownContext, Sourcemap, TsdownChunks, TsdownHooks, UnusedOptions, type UserConfig, type UserConfigFn, Workspace, build, buildSingle, defineConfig, logger, shimFile };
22
+ export { AttwOptions, BuildContext, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, DtsOptions, ExportsOptions, Format, type Logger, ModuleTypes, NormalizedFormat, NormalizedUserConfig, type Options, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageType, PublintOptions, ReportOptions, type ResolvedOptions, RolldownContext, Sourcemap, TsdownChunks, TsdownHooks, UnusedOptions, type UserConfig, type UserConfigFn, Workspace, build, buildSingle, defineConfig, globalLogger, shimFile };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from "./config-CCGWF4al.mjs";
2
- import { build, buildSingle, shimFile } from "./src-C8dUJ_Mj.mjs";
3
- import { logger } from "./logger-6IV2T7t1.mjs";
2
+ import { build, buildSingle, shimFile } from "./src-BaOLpcFF.mjs";
3
+ import { globalLogger } from "./logger-DScmoUke.mjs";
4
4
 
5
- export { build, buildSingle, defineConfig, logger, shimFile };
5
+ export { build, buildSingle, defineConfig, globalLogger, shimFile };
@@ -9,7 +9,7 @@ function toArray(val, defaultValue) {
9
9
  } else return [val];
10
10
  }
11
11
  function resolveComma(arr) {
12
- return arr.flatMap((format) => format.split(","));
12
+ return arr.flatMap((format$1) => format$1.split(","));
13
13
  }
14
14
  function resolveRegex(str) {
15
15
  if (typeof str === "string" && str.length > 2 && str[0] === "/" && str.at(-1) === "/") return new RegExp(str.slice(1, -1));
@@ -32,41 +32,63 @@ const noop = (v) => v;
32
32
 
33
33
  //#endregion
34
34
  //#region src/utils/logger.ts
35
- var Logger = class {
36
- silent = false;
37
- setSilent(value) {
38
- this.silent = value;
39
- }
40
- filter(...args) {
41
- return args.filter((arg) => arg !== void 0 && arg !== false);
42
- }
43
- info(...args) {
44
- if (!this.silent) console.info(blue`ℹ`, ...this.filter(...args));
45
- }
46
- warn(...args) {
47
- if (!this.silent) console.warn("\n", bgYellow` WARN `, ...this.filter(...args), "\n");
48
- }
49
- error(...args) {
50
- if (!this.silent) console.error("\n", bgRed` ERROR `, ...this.filter(...args), "\n");
51
- }
52
- success(...args) {
53
- if (!this.silent) console.info(green`✔`, ...this.filter(...args));
54
- }
35
+ const LogLevels = {
36
+ silent: 0,
37
+ error: 1,
38
+ warn: 2,
39
+ info: 3
55
40
  };
56
- const logger = new Logger();
41
+ function format(msgs) {
42
+ return msgs.filter((arg) => arg !== void 0 && arg !== false).join(" ");
43
+ }
44
+ const warnedMessages = /* @__PURE__ */ new Set();
45
+ function createLogger(level = "info", { customLogger, console = globalThis.console } = {}) {
46
+ if (customLogger) return customLogger;
47
+ function output(type, msg) {
48
+ const thresh = LogLevels[logger.level];
49
+ if (thresh < LogLevels[type]) return;
50
+ const method = type === "info" ? "log" : type;
51
+ console[method](msg);
52
+ }
53
+ const logger = {
54
+ level,
55
+ info(...msgs) {
56
+ output("info", `${blue`ℹ`} ${format(msgs)}`);
57
+ },
58
+ warn(...msgs) {
59
+ const message = format(msgs);
60
+ warnedMessages.add(message);
61
+ output("warn", `\n${bgYellow` WARN `} ${message}\n`);
62
+ },
63
+ warnOnce(...msgs) {
64
+ const message = format(msgs);
65
+ if (warnedMessages.has(message)) return;
66
+ warnedMessages.add(message);
67
+ output("warn", `\n${bgYellow` WARN `} ${message}\n`);
68
+ },
69
+ error(...msgs) {
70
+ output("error", `\n${bgRed` ERROR `} ${format(msgs)}\n`);
71
+ },
72
+ success(...msgs) {
73
+ output("info", `${green`✔`} ${format(msgs)}`);
74
+ }
75
+ };
76
+ return logger;
77
+ }
78
+ const globalLogger = createLogger();
57
79
  function prettyName(name) {
58
80
  if (!name) return void 0;
59
81
  return generateColor(name)(`[${name}]`);
60
82
  }
61
- function prettyFormat(format) {
62
- const formatColor = format === "es" ? blue : format === "cjs" ? yellow : noop;
83
+ function prettyFormat(format$1) {
84
+ const formatColor = format$1 === "es" ? blue : format$1 === "cjs" ? yellow : noop;
63
85
  let formatText;
64
- switch (format) {
86
+ switch (format$1) {
65
87
  case "es":
66
88
  formatText = "ESM";
67
89
  break;
68
90
  default:
69
- formatText = format.toUpperCase();
91
+ formatText = format$1.toUpperCase();
70
92
  break;
71
93
  }
72
94
  return formatColor(`[${formatText}]`);
@@ -117,4 +139,4 @@ function hue2rgb(p, q, t) {
117
139
  }
118
140
 
119
141
  //#endregion
120
- export { debounce, generateColor, logger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };
142
+ export { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };
@@ -1,5 +1,5 @@
1
- import { logger } from "./logger-6IV2T7t1.mjs";
2
- import { version } from "./package-Dg3yzWpE.mjs";
1
+ import { globalLogger } from "./logger-DScmoUke.mjs";
2
+ import { version } from "./package-Celz_JJW.mjs";
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";
@@ -8,18 +8,18 @@ import { createInterface } from "node:readline/promises";
8
8
 
9
9
  //#region src/migrate.ts
10
10
  async function migrate({ cwd, dryRun }) {
11
- if (dryRun) logger.info("Dry run enabled. No changes were made.");
11
+ if (dryRun) globalLogger.info("Dry run enabled. No changes were made.");
12
12
  else {
13
13
  const rl = createInterface({
14
14
  input: process.stdin,
15
15
  output: process.stdout
16
16
  });
17
- logger.warn(`\n\nBefore proceeding, review the migration guide at ${underline`https://tsdown.dev/guide/migrate-from-tsup`}, as this process will modify your files.\nUncommitted changes will be lost. Use the ${green`--dry-run`} flag to preview changes without applying them.`);
17
+ globalLogger.warn(`\n\nBefore proceeding, review the migration guide at ${underline`https://tsdown.dev/guide/migrate-from-tsup`}, as this process will modify your files.\nUncommitted changes will be lost. Use the ${green`--dry-run`} flag to preview changes without applying them.`);
18
18
  const input = await rl.question(bold`Continue? (Y/n) `);
19
19
  rl.close();
20
20
  const confirm = input.toLowerCase() === "y" || input === "";
21
21
  if (!confirm) {
22
- logger.error("Migration cancelled.");
22
+ globalLogger.error("Migration cancelled.");
23
23
  process.exitCode = 1;
24
24
  return;
25
25
  }
@@ -27,15 +27,15 @@ async function migrate({ cwd, dryRun }) {
27
27
  if (cwd) process.chdir(cwd);
28
28
  let migrated = await migratePackageJson(dryRun);
29
29
  if (await migrateTsupConfig(dryRun)) migrated = true;
30
- if (migrated) logger.success("Migration completed. Remember to run install command with your package manager.");
30
+ if (migrated) globalLogger.success("Migration completed. Remember to run install command with your package manager.");
31
31
  else {
32
- logger.error("No migration performed.");
32
+ globalLogger.error("No migration performed.");
33
33
  process.exitCode = 1;
34
34
  }
35
35
  }
36
36
  async function migratePackageJson(dryRun) {
37
37
  if (!existsSync("package.json")) {
38
- logger.error("No package.json found");
38
+ globalLogger.error("No package.json found");
39
39
  return false;
40
40
  }
41
41
  const pkgRaw = await readFile("package.json", "utf-8");
@@ -43,44 +43,44 @@ async function migratePackageJson(dryRun) {
43
43
  const semver = `^${version}`;
44
44
  let found = false;
45
45
  if (pkg.dependencies?.tsup) {
46
- logger.info("Migrating `dependencies` to tsdown.");
46
+ globalLogger.info("Migrating `dependencies` to tsdown.");
47
47
  found = true;
48
48
  pkg.dependencies = renameKey(pkg.dependencies, "tsup", "tsdown", semver);
49
49
  }
50
50
  if (pkg.devDependencies?.tsup) {
51
- logger.info("Migrating `devDependencies` to tsdown.");
51
+ globalLogger.info("Migrating `devDependencies` to tsdown.");
52
52
  found = true;
53
53
  pkg.devDependencies = renameKey(pkg.devDependencies, "tsup", "tsdown", semver);
54
54
  }
55
55
  if (pkg.peerDependencies?.tsup) {
56
- logger.info("Migrating `peerDependencies` to tsdown.");
56
+ globalLogger.info("Migrating `peerDependencies` to tsdown.");
57
57
  found = true;
58
58
  pkg.peerDependencies = renameKey(pkg.peerDependencies, "tsup", "tsdown", "*");
59
59
  }
60
60
  if (pkg.scripts) {
61
61
  for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
62
- logger.info(`Migrating \`${key}\` script to tsdown`);
62
+ globalLogger.info(`Migrating \`${key}\` script to tsdown`);
63
63
  found = true;
64
64
  pkg.scripts[key] = pkg.scripts[key].replaceAll(/tsup(?:-node)?/g, "tsdown");
65
65
  }
66
66
  }
67
67
  if (pkg.tsup) {
68
- logger.info("Migrating `tsup` field in package.json to `tsdown`.");
68
+ globalLogger.info("Migrating `tsup` field in package.json to `tsdown`.");
69
69
  found = true;
70
70
  pkg = renameKey(pkg, "tsup", "tsdown");
71
71
  }
72
72
  if (!found) {
73
- logger.warn("No tsup-related fields found in package.json");
73
+ globalLogger.warn("No tsup-related fields found in package.json");
74
74
  return false;
75
75
  }
76
76
  const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
77
77
  if (dryRun) {
78
78
  const { createPatch } = await import("diff");
79
- logger.info("[dry-run] package.json:");
79
+ globalLogger.info("[dry-run] package.json:");
80
80
  console.info(createPatch("package.json", pkgRaw, pkgStr));
81
81
  } else {
82
82
  await writeFile("package.json", pkgStr);
83
- logger.success("Migrated `package.json`");
83
+ globalLogger.success("Migrated `package.json`");
84
84
  }
85
85
  return true;
86
86
  }
@@ -97,22 +97,22 @@ async function migrateTsupConfig(dryRun) {
97
97
  let found = false;
98
98
  for (const file of TSUP_FILES) {
99
99
  if (!existsSync(file)) continue;
100
- logger.info(`Found \`${file}\``);
100
+ globalLogger.info(`Found \`${file}\``);
101
101
  found = true;
102
102
  const tsupConfigRaw = await readFile(file, "utf-8");
103
103
  const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replaceAll(/\bTSUP\b/g, "TSDOWN");
104
104
  const renamed = file.replaceAll("tsup", "tsdown");
105
105
  if (dryRun) {
106
106
  const { createTwoFilesPatch } = await import("diff");
107
- logger.info(`[dry-run] ${file} -> ${renamed}:`);
107
+ globalLogger.info(`[dry-run] ${file} -> ${renamed}:`);
108
108
  console.info(createTwoFilesPatch(file, renamed, tsupConfigRaw, tsupConfig));
109
109
  } else {
110
110
  await writeFile(renamed, tsupConfig, "utf8");
111
111
  await unlink(file);
112
- logger.success(`Migrated \`${file}\` to \`${renamed}\``);
112
+ globalLogger.success(`Migrated \`${file}\` to \`${renamed}\``);
113
113
  }
114
114
  }
115
- if (!found) logger.warn("No tsup config found");
115
+ if (!found) globalLogger.warn("No tsup config found");
116
116
  return found;
117
117
  }
118
118
  function renameKey(obj, oldKey, newKey, newValue) {
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.13.3";
3
+
4
+ //#endregion
5
+ export { version };
@@ -1,4 +1,4 @@
1
- import { ReportPlugin, ResolvedOptions } from "./types-DIH2hGTd.mjs";
1
+ import { Logger, ReportPlugin, ResolvedOptions } from "./types-DahUJE7h.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
@@ -6,7 +6,7 @@ import { PackageJson } from "pkg-types";
6
6
  declare function ExternalPlugin(options: ResolvedOptions): Plugin;
7
7
  //#endregion
8
8
  //#region src/features/shebang.d.ts
9
- declare function ShebangPlugin(cwd: string, name?: string, isMultiFormat?: boolean): Plugin;
9
+ declare function ShebangPlugin(logger: Logger, cwd: string, name?: string, isMultiFormat?: boolean): Plugin;
10
10
  //#endregion
11
11
  //#region src/features/node-protocol.d.ts
12
12
  /**
package/dist/plugins.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./config-CCGWF4al.mjs";
2
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-C8dUJ_Mj.mjs";
3
- import "./logger-6IV2T7t1.mjs";
2
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-BaOLpcFF.mjs";
3
+ import "./logger-DScmoUke.mjs";
4
4
 
5
5
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
package/dist/run.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { logger, resolveComma, toArray } from "./logger-6IV2T7t1.mjs";
3
- import { version } from "./package-Dg3yzWpE.mjs";
2
+ import { globalLogger, resolveComma, toArray } from "./logger-DScmoUke.mjs";
3
+ import { version } from "./package-Celz_JJW.mjs";
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,15 +14,15 @@ 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("-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("--attw", "Enable Are the types wrong integration", { 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("--unbundle", "Unbundle mode").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
- logger.setSilent(!!flags.silent);
19
- logger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
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, umd", { 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("-l, --logLevel <level>", "Set log level: info, warn, error, silent").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("--attw", "Enable Are the types wrong integration", { 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("--unbundle", "Unbundle mode").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
+ globalLogger.level = flags.logLevel || (flags.silent ? "silent" : "info");
19
+ globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
20
20
  const { build: build$1 } = await import("./index.mjs");
21
21
  if (input.length > 0) flags.entry = input;
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-mIs6mjET.mjs");
25
+ const { migrate } = await import("./migrate-DSSpr3yy.mjs");
26
26
  await migrate(args);
27
27
  });
28
28
  async function runCLI() {
@@ -31,15 +31,15 @@ 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();
41
41
  } catch (error) {
42
- logger.error(error);
42
+ globalLogger.error(error);
43
43
  process.exit(1);
44
44
  }
45
45
  }
@@ -1,4 +1,4 @@
1
- import { debounce, generateColor, logger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-6IV2T7t1.mjs";
1
+ import { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-DScmoUke.mjs";
2
2
  import { builtinModules } from "node:module";
3
3
  import path, { dirname, normalize, sep } from "node:path";
4
4
  import process from "node:process";
@@ -11,7 +11,9 @@ import child_process from "node:child_process";
11
11
  import { access, chmod, cp, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
12
12
  import { tmpdir } from "node:os";
13
13
  import { promisify } from "node:util";
14
- import Debug from "debug";
14
+ import debug from "debug";
15
+ import coerce from "semver/functions/coerce.js";
16
+ import satisfies from "semver/functions/satisfies.js";
15
17
  import { glob } from "tinyglobby";
16
18
  import { RE_CSS, RE_DTS, RE_JS } from "rolldown-plugin-dts/filename";
17
19
  import { createHooks } from "hookable";
@@ -64,7 +66,7 @@ function lowestCommonAncestor(...filepaths) {
64
66
 
65
67
  //#endregion
66
68
  //#region src/features/attw.ts
67
- const debug$6 = Debug("tsdown:attw");
69
+ const debug$7 = debug("tsdown:attw");
68
70
  const exec$1 = promisify(child_process.exec);
69
71
  /**
70
72
  * ATTW profiles.
@@ -106,18 +108,18 @@ function formatProblem(problem) {
106
108
  async function attw(options) {
107
109
  if (!options.attw) return;
108
110
  if (!options.pkg) {
109
- logger.warn("attw is enabled but package.json is not found");
111
+ options.logger.warn("attw is enabled but package.json is not found");
110
112
  return;
111
113
  }
112
114
  const { profile = "strict", level = "warn",...attwOptions } = options.attw === true ? {} : options.attw;
113
115
  const t = performance.now();
114
- debug$6("Running attw check");
116
+ debug$7("Running attw check");
115
117
  const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
116
118
  let attwCore;
117
119
  try {
118
120
  attwCore = await import("@arethetypeswrong/core");
119
121
  } catch {
120
- logger.error(`ATTW check requires ${blue`@arethetypeswrong/core`} to be installed.`);
122
+ options.logger.error(`ATTW check requires ${blue`@arethetypeswrong/core`} to be installed.`);
121
123
  return;
122
124
  }
123
125
  try {
@@ -140,21 +142,37 @@ async function attw(options) {
140
142
  const problemList = problems.map(formatProblem).join("\n");
141
143
  const problemMessage = `Are the types wrong problems found:\n${problemList}`;
142
144
  if (level === "error") throw new Error(problemMessage);
143
- logger.warn(problemMessage);
145
+ options.logger.warn(problemMessage);
144
146
  }
145
- } else logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
147
+ } else options.logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
146
148
  } catch (error) {
147
- logger.error("ATTW check failed:", error);
148
- debug$6("Found errors, setting exit code to 1");
149
+ options.logger.error("ATTW check failed:", error);
150
+ debug$7("Found errors, setting exit code to 1");
149
151
  process.exitCode = 1;
150
152
  } finally {
151
153
  await fsRemove(tempDir);
152
154
  }
153
155
  }
154
156
 
157
+ //#endregion
158
+ //#region src/features/cjs.ts
159
+ /**
160
+ * If the config includes the `cjs` format and
161
+ * one of its target >= node 23.0.0 / 22.12.0,
162
+ * warn the user about the deprecation of CommonJS.
163
+ */
164
+ function warnLegacyCJS(config) {
165
+ if (!config.format.includes("cjs") || !config.target) return;
166
+ const legacy = config.target.some((t) => {
167
+ const version = coerce(t.split("node")[1]);
168
+ return version && satisfies(version, ">=23.0.0 || >=22.12.0");
169
+ });
170
+ if (legacy) config.logger.warnOnce("We recommend using the ESM format instead of CommonJS.\nThe ESM format is compatible with modern platforms and runtimes, and most new libraries are now distributed only in ESM format.\nLearn more at https://nodejs.org/en/learn/modules/publishing-a-package#how-did-we-get-here");
171
+ }
172
+
155
173
  //#endregion
156
174
  //#region src/features/clean.ts
157
- const debug$5 = Debug("tsdown:clean");
175
+ const debug$6 = debug("tsdown:clean");
158
176
  const RE_LAST_SLASH = /[/\\]$/;
159
177
  async function cleanOutDir(configs) {
160
178
  const removes = /* @__PURE__ */ new Set();
@@ -172,12 +190,12 @@ async function cleanOutDir(configs) {
172
190
  }
173
191
  }
174
192
  if (!removes.size) return;
175
- logger.info(`Cleaning ${removes.size} files`);
193
+ globalLogger.info(`Cleaning ${removes.size} files`);
176
194
  await Promise.all([...removes].map(async (file) => {
177
- debug$5("Removing", file);
195
+ debug$6("Removing", file);
178
196
  await fsRemove(file);
179
197
  }));
180
- debug$5("Removed %d files", removes.size);
198
+ debug$6("Removed %d files", removes.size);
181
199
  }
182
200
  function resolveClean(clean, outDir, cwd) {
183
201
  if (clean === true) clean = [slash(outDir)];
@@ -311,7 +329,7 @@ function exportMeta(exports, all) {
311
329
 
312
330
  //#endregion
313
331
  //#region src/features/external.ts
314
- const debug$4 = Debug("tsdown:external");
332
+ const debug$5 = debug("tsdown:external");
315
333
  function ExternalPlugin(options) {
316
334
  const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
317
335
  return {
@@ -339,7 +357,7 @@ function ExternalPlugin(options) {
339
357
  }
340
358
  if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
341
359
  if (shouldExternal) {
342
- debug$4("External dependency:", id);
360
+ debug$5("External dependency:", id);
343
361
  return {
344
362
  id,
345
363
  external: shouldExternal,
@@ -460,11 +478,11 @@ function NodeProtocolPlugin(nodeProtocolOption) {
460
478
 
461
479
  //#endregion
462
480
  //#region src/utils/package.ts
463
- const debug$3 = Debug("tsdown:package");
481
+ const debug$4 = debug("tsdown:package");
464
482
  async function readPackageJson(dir) {
465
483
  const packageJsonPath = up({ cwd: dir });
466
484
  if (!packageJsonPath) return;
467
- debug$3("Reading package.json:", packageJsonPath);
485
+ debug$4("Reading package.json:", packageJsonPath);
468
486
  const contents = await readFile(packageJsonPath, "utf8");
469
487
  return {
470
488
  ...JSON.parse(contents),
@@ -537,20 +555,20 @@ function resolveChunkAddon(chunkAddon, format) {
537
555
 
538
556
  //#endregion
539
557
  //#region src/features/publint.ts
540
- const debug$2 = Debug("tsdown:publint");
558
+ const debug$3 = debug("tsdown:publint");
541
559
  async function publint(options) {
542
560
  if (!options.publint) return;
543
561
  if (!options.pkg) {
544
- logger.warn("publint is enabled but package.json is not found");
562
+ options.logger.warn("publint is enabled but package.json is not found");
545
563
  return;
546
564
  }
547
565
  const t = performance.now();
548
- debug$2("Running publint");
566
+ debug$3("Running publint");
549
567
  const { publint: publint$1 } = await import("publint");
550
568
  const { formatMessage } = await import("publint/utils");
551
569
  const { messages } = await publint$1(options.publint === true ? {} : options.publint);
552
- debug$2("Found %d issues", messages.length);
553
- if (!messages.length) logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
570
+ debug$3("Found %d issues", messages.length);
571
+ if (!messages.length) options.logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
554
572
  let hasError = false;
555
573
  for (const message of messages) {
556
574
  hasError ||= message.type === "error";
@@ -560,10 +578,10 @@ async function publint(options) {
560
578
  warning: "warn",
561
579
  suggestion: "info"
562
580
  }[message.type];
563
- logger[logType](formattedMessage);
581
+ options.logger[logType](formattedMessage);
564
582
  }
565
583
  if (hasError) {
566
- debug$2("Found errors, setting exit code to 1");
584
+ debug$3("Found errors, setting exit code to 1");
567
585
  process.exitCode = 1;
568
586
  }
569
587
  }
@@ -577,10 +595,10 @@ function formatBytes(bytes) {
577
595
 
578
596
  //#endregion
579
597
  //#region src/features/report.ts
580
- const debug$1 = Debug("tsdown:report");
598
+ const debug$2 = debug("tsdown:report");
581
599
  const brotliCompressAsync = promisify(brotliCompress);
582
600
  const gzipAsync = promisify(gzip);
583
- function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
601
+ function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
584
602
  return {
585
603
  name: "tsdown:report",
586
604
  async writeBundle(outputOptions, bundle) {
@@ -618,19 +636,19 @@ function ReportPlugin(options, cwd, cjsDts, name, isMultiFormat) {
618
636
  };
619
637
  }
620
638
  async function calcSize(options, chunk) {
621
- debug$1(`Calculating size for`, chunk.fileName);
639
+ debug$2(`Calculating size for`, chunk.fileName);
622
640
  const content = chunk.type === "chunk" ? chunk.code : chunk.source;
623
641
  const raw = Buffer.byteLength(content, "utf8");
624
- debug$1("[size]", chunk.fileName, raw);
642
+ debug$2("[size]", chunk.fileName, raw);
625
643
  let gzip$1 = Infinity;
626
644
  let brotli = Infinity;
627
- if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
645
+ if (raw > (options.maxCompressSize ?? 1e6)) debug$2(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
628
646
  else {
629
647
  gzip$1 = (await gzipAsync(content)).length;
630
- debug$1("[gzip]", chunk.fileName, gzip$1);
648
+ debug$2("[gzip]", chunk.fileName, gzip$1);
631
649
  if (options.brotli) {
632
650
  brotli = (await brotliCompressAsync(content)).length;
633
- debug$1("[brotli]", chunk.fileName, brotli);
651
+ debug$2("[brotli]", chunk.fileName, brotli);
634
652
  }
635
653
  }
636
654
  return {
@@ -687,12 +705,12 @@ function shortcuts(restart) {
687
705
  ];
688
706
  if (input === "h") {
689
707
  const loggedKeys = /* @__PURE__ */ new Set();
690
- logger.info(" Shortcuts");
708
+ globalLogger.info(" Shortcuts");
691
709
  for (const shortcut$1 of SHORTCUTS) {
692
710
  if (loggedKeys.has(shortcut$1.key)) continue;
693
711
  loggedKeys.add(shortcut$1.key);
694
712
  if (shortcut$1.action == null) continue;
695
- logger.info(dim` press ` + bold`${shortcut$1.key} + enter` + dim` to ${shortcut$1.description}`);
713
+ globalLogger.info(dim` press ` + bold`${shortcut$1.key} + enter` + dim` to ${shortcut$1.description}`);
696
714
  }
697
715
  return;
698
716
  }
@@ -708,7 +726,7 @@ function shortcuts(restart) {
708
726
 
709
727
  //#endregion
710
728
  //#region src/features/target.ts
711
- function resolveTarget(target, pkg, name) {
729
+ function resolveTarget(logger, target, pkg, name) {
712
730
  if (target === false) return;
713
731
  if (target == null) {
714
732
  const pkgTarget = resolvePackageTarget(pkg);
@@ -728,7 +746,7 @@ function resolvePackageTarget(pkg) {
728
746
  return `node${nodeMinVersion.version}`;
729
747
  }
730
748
  let warned = false;
731
- function RuntimeHelperCheckPlugin(targets) {
749
+ function RuntimeHelperCheckPlugin(logger, targets) {
732
750
  return {
733
751
  name: "tsdown:runtime-helper-check",
734
752
  resolveId: {
@@ -759,7 +777,7 @@ const endsWithConfig = /[\\/](?:package\.json|tsdown\.config.*)$/;
759
777
  async function watchBuild(options, configFiles, rebuild, restart) {
760
778
  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.`);
761
779
  const files = toArray(typeof options.watch === "boolean" ? options.cwd : options.watch);
762
- logger.info(`Watching for changes in ${files.join(", ")}`);
780
+ options.logger.info(`Watching for changes in ${files.join(", ")}`);
763
781
  files.push(...configFiles);
764
782
  const { watch } = await import("chokidar");
765
783
  const debouncedRebuild = debounce(rebuild, 100);
@@ -770,16 +788,16 @@ async function watchBuild(options, configFiles, rebuild, restart) {
770
788
  /[\\/]\.git[\\/]/,
771
789
  /[\\/]node_modules[\\/]/,
772
790
  options.outDir,
773
- ...toArray(options.ignoreWatch)
791
+ ...options.ignoreWatch
774
792
  ]
775
793
  });
776
794
  watcher.on("all", (type, file) => {
777
795
  if (configFiles.includes(file) || endsWithConfig.test(file)) {
778
- logger.info(`Reload config: ${file}`);
796
+ options.logger.info(`Reload config: ${file}`);
779
797
  restart();
780
798
  return;
781
799
  }
782
- logger.info(`Change detected: ${type} ${file}`);
800
+ options.logger.info(`Change detected: ${type} ${file}`);
783
801
  invalidateContextFile(globalContext, file);
784
802
  debouncedRebuild();
785
803
  });
@@ -788,7 +806,7 @@ async function watchBuild(options, configFiles, rebuild, restart) {
788
806
 
789
807
  //#endregion
790
808
  //#region src/features/entry.ts
791
- async function resolveEntry(entry, cwd, name) {
809
+ async function resolveEntry(logger, entry, cwd, name) {
792
810
  const nameLabel = name ? `[${name}] ` : "";
793
811
  if (!entry || Object.keys(entry).length === 0) {
794
812
  const defaultEntry = path.resolve(cwd, "src/index.ts");
@@ -817,7 +835,7 @@ async function toObjectEntry(entry, cwd) {
817
835
  function findTsconfig(cwd, name = "tsconfig.json") {
818
836
  return up$1(name, { cwd }) || false;
819
837
  }
820
- async function resolveTsconfig(tsconfig, cwd, name) {
838
+ async function resolveTsconfig(logger, tsconfig, cwd, name) {
821
839
  const original = tsconfig;
822
840
  if (tsconfig !== false) {
823
841
  if (tsconfig === true || tsconfig == null) {
@@ -861,7 +879,7 @@ async function loadViteConfig(prefix, cwd) {
861
879
  defaults: {}
862
880
  });
863
881
  if (!source) return;
864
- logger.info(`Using Vite config: ${underline(source)}`);
882
+ globalLogger.info(`Using Vite config: ${underline(source)}`);
865
883
  const resolved = await config;
866
884
  if (typeof resolved === "function") return resolved({
867
885
  command: "build",
@@ -921,7 +939,7 @@ async function loadConfigFile(options, workspace) {
921
939
  config = toArray(config);
922
940
  if (config.length === 0) config.push({});
923
941
  const file = sources[0];
924
- if (file) logger.info(`Using tsdown config: ${underline(file)}`);
942
+ if (file) globalLogger.info(`Using tsdown config: ${underline(file)}`);
925
943
  return {
926
944
  configs: config,
927
945
  file
@@ -930,7 +948,7 @@ async function loadConfigFile(options, workspace) {
930
948
 
931
949
  //#endregion
932
950
  //#region src/options/index.ts
933
- const debug = Debug("tsdown:options");
951
+ const debug$1 = debug("tsdown:options");
934
952
  const DEFAULT_EXCLUDE_WORKSPACE = [
935
953
  "**/node_modules/**",
936
954
  "**/dist/**",
@@ -939,20 +957,20 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
939
957
  ];
940
958
  async function resolveOptions(options) {
941
959
  const files = [];
942
- debug("options %O", options);
943
- debug("loading config file: %s", options.config);
960
+ debug$1("options %O", options);
961
+ debug$1("loading config file: %s", options.config);
944
962
  const { configs: rootConfigs, file } = await loadConfigFile(options);
945
963
  if (file) {
946
964
  files.push(file);
947
- debug("loaded root config file %s", file);
948
- debug("root configs %o", rootConfigs);
949
- } else debug("no root config file found");
965
+ debug$1("loaded root config file %s", file);
966
+ debug$1("root configs %o", rootConfigs);
967
+ } else debug$1("no root config file found");
950
968
  const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
951
969
  const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
952
970
  if (workspaceFiles) files.push(...workspaceFiles);
953
971
  return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveConfig(config)));
954
972
  }))).flat();
955
- debug("resolved configs %O", configs);
973
+ debug$1("resolved configs %O", configs);
956
974
  return {
957
975
  configs,
958
976
  files
@@ -994,16 +1012,16 @@ async function resolveWorkspace(config, options) {
994
1012
  }
995
1013
  const files = [];
996
1014
  const configs = (await Promise.all(packages.map(async (cwd) => {
997
- debug("loading workspace config %s", cwd);
1015
+ debug$1("loading workspace config %s", cwd);
998
1016
  const { configs: configs$1, file } = await loadConfigFile({
999
1017
  ...options,
1000
1018
  config: workspaceConfig,
1001
1019
  cwd
1002
1020
  }, cwd);
1003
1021
  if (file) {
1004
- debug("loaded workspace config file %s", file);
1022
+ debug$1("loaded workspace config file %s", file);
1005
1023
  files.push(file);
1006
- } else debug("no workspace config file found in %s", cwd);
1024
+ } else debug$1("no workspace config file found in %s", cwd);
1007
1025
  return configs$1.map((config$1) => ({
1008
1026
  ...normalized,
1009
1027
  cwd,
@@ -1016,18 +1034,18 @@ async function resolveWorkspace(config, options) {
1016
1034
  };
1017
1035
  }
1018
1036
  async function resolveConfig(userConfig) {
1019
- 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, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol } = userConfig;
1020
- if (silent) logger.setSilent(true);
1037
+ let { entry, format = ["es"], plugins = [], clean = true, silent = false, logLevel = silent ? "silent" : "info", customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch = [], shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, removeNodeProtocol, nodeProtocol } = userConfig;
1038
+ const logger = createLogger(logLevel, { customLogger });
1021
1039
  if (typeof bundle === "boolean") logger.warn("`bundle` option is deprecated. Use `unbundle` instead.");
1022
1040
  nodeProtocol = nodeProtocol ?? (removeNodeProtocol ? "strip" : false);
1023
1041
  outDir = path.resolve(cwd, outDir);
1024
1042
  clean = resolveClean(clean, outDir, cwd);
1025
1043
  const pkg = await readPackageJson(cwd);
1026
1044
  if (workspace) name ||= pkg?.name;
1027
- entry = await resolveEntry(entry, cwd, name);
1045
+ entry = await resolveEntry(logger, entry, cwd, name);
1028
1046
  if (dts == null) dts = !!(pkg?.types || pkg?.typings);
1029
- target = resolveTarget(target, pkg, name);
1030
- tsconfig = await resolveTsconfig(tsconfig, cwd, name);
1047
+ target = resolveTarget(logger, target, pkg, name);
1048
+ tsconfig = await resolveTsconfig(logger, tsconfig, cwd, name);
1031
1049
  if (typeof external === "string") external = resolveRegex(external);
1032
1050
  if (typeof noExternal === "string") noExternal = resolveRegex(noExternal);
1033
1051
  if (publint$1 === true) publint$1 = {};
@@ -1044,6 +1062,11 @@ async function resolveConfig(userConfig) {
1044
1062
  if (viteAlias && !Array.isArray(viteAlias)) alias = viteAlias;
1045
1063
  }
1046
1064
  }
1065
+ ignoreWatch = toArray(ignoreWatch).map((ignore) => {
1066
+ ignore = resolveRegex(ignore);
1067
+ if (typeof ignore === "string") return path.resolve(cwd, ignore);
1068
+ return ignore;
1069
+ });
1047
1070
  const config = {
1048
1071
  ...userConfig,
1049
1072
  entry,
@@ -1052,7 +1075,7 @@ async function resolveConfig(userConfig) {
1052
1075
  target,
1053
1076
  outDir,
1054
1077
  clean,
1055
- silent,
1078
+ logger,
1056
1079
  treeshake,
1057
1080
  platform,
1058
1081
  sourcemap,
@@ -1092,7 +1115,7 @@ async function mergeUserOptions(defaults, user, args) {
1092
1115
  //#endregion
1093
1116
  //#region src/features/shebang.ts
1094
1117
  const RE_SHEBANG = /^#!.*/;
1095
- function ShebangPlugin(cwd, name, isMultiFormat) {
1118
+ function ShebangPlugin(logger, cwd, name, isMultiFormat) {
1096
1119
  return {
1097
1120
  name: "tsdown:shebang",
1098
1121
  async writeBundle(options, bundle) {
@@ -1115,13 +1138,14 @@ function ShebangPlugin(cwd, name, isMultiFormat) {
1115
1138
  * Build with tsdown.
1116
1139
  */
1117
1140
  async function build$1(userOptions = {}) {
1141
+ globalLogger.level = userOptions.logLevel || (userOptions.silent ? "silent" : "info");
1118
1142
  const { configs, files: configFiles } = await resolveOptions(userOptions);
1119
1143
  let cleanPromise;
1120
1144
  const clean = () => {
1121
1145
  if (cleanPromise) return cleanPromise;
1122
1146
  return cleanPromise = cleanOutDir(configs);
1123
1147
  };
1124
- logger.info("Build start");
1148
+ globalLogger.info("Build start");
1125
1149
  const rebuilds = await Promise.all(configs.map((options) => buildSingle(options, clean)));
1126
1150
  const disposeCbs = [];
1127
1151
  for (const [i, config] of configs.entries()) {
@@ -1149,9 +1173,10 @@ const shimFile = path.resolve(pkgRoot, "esm-shims.js");
1149
1173
  * @param config Resolved options
1150
1174
  */
1151
1175
  async function buildSingle(config, clean) {
1152
- const { format: formats, dts, watch, onSuccess } = config;
1176
+ const { format: formats, dts, watch, onSuccess, logger } = config;
1153
1177
  let ab;
1154
1178
  const { hooks, context } = await createHooks$1(config);
1179
+ warnLegacyCJS(config);
1155
1180
  await rebuild(true);
1156
1181
  if (watch) return () => rebuild();
1157
1182
  async function rebuild(first) {
@@ -1206,7 +1231,7 @@ async function buildSingle(config, clean) {
1206
1231
  }
1207
1232
  }
1208
1233
  async function getBuildOptions(config, format, isMultiFormat, cjsDts) {
1209
- const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report, env, nodeProtocol, loader, name, unbundle, banner, footer } = config;
1234
+ const { entry, external, plugins: userPlugins, outDir, platform, alias, treeshake, sourcemap, dts, minify, unused, target, define, shims, tsconfig, cwd, report, env, nodeProtocol, loader, name, unbundle, banner, footer, logger } = config;
1210
1235
  const plugins = [];
1211
1236
  if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
1212
1237
  if (config.pkg || config.skipNodeModulesBundle) plugins.push(ExternalPlugin(config));
@@ -1227,10 +1252,10 @@ async function getBuildOptions(config, format, isMultiFormat, cjsDts) {
1227
1252
  const { Unused } = await import("unplugin-unused");
1228
1253
  plugins.push(Unused.rolldown(unused === true ? {} : unused));
1229
1254
  }
1230
- if (target) plugins.push(RuntimeHelperCheckPlugin(target), await LightningCSSPlugin({ target }));
1231
- plugins.push(ShebangPlugin(cwd, name, isMultiFormat));
1255
+ if (target) plugins.push(RuntimeHelperCheckPlugin(logger, target), await LightningCSSPlugin({ target }));
1256
+ plugins.push(ShebangPlugin(logger, cwd, name, isMultiFormat));
1232
1257
  }
1233
- if (report && !logger.silent) plugins.push(ReportPlugin(report, cwd, cjsDts, name, isMultiFormat));
1258
+ if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(report, logger, cwd, cjsDts, name, isMultiFormat));
1234
1259
  if (!cjsDts) plugins.push(userPlugins);
1235
1260
  cjsDts = !!cjsDts;
1236
1261
  const inputOptions = await mergeUserOptions({
@@ -1,3 +1,4 @@
1
+ import "ansis";
1
2
  import { BuildOptions, ExternalOption, InputOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, OutputAsset, OutputChunk, OutputOptions, Plugin } from "rolldown";
2
3
  import { Hookable } from "hookable";
3
4
  import { CheckPackageOptions } from "@arethetypeswrong/core";
@@ -122,6 +123,19 @@ type ChunkAddonFunction = (ctx: {
122
123
  }) => ChunkAddonObject | undefined;
123
124
  type ChunkAddon = ChunkAddonObject | ChunkAddonFunction;
124
125
  //#endregion
126
+ //#region src/utils/logger.d.ts
127
+ type LogType = "error" | "warn" | "info";
128
+ type LogLevel = LogType | "silent";
129
+ interface Logger {
130
+ level: LogLevel;
131
+ info: (...args: any[]) => void;
132
+ warn: (...args: any[]) => void;
133
+ warnOnce: (...args: any[]) => void;
134
+ error: (...args: any[]) => void;
135
+ success: (...args: any[]) => void;
136
+ }
137
+ declare const globalLogger: Logger;
138
+ //#endregion
125
139
  //#region src/features/report.d.ts
126
140
  interface ReportOptions {
127
141
  /**
@@ -137,7 +151,7 @@ interface ReportOptions {
137
151
  */
138
152
  maxCompressSize?: number;
139
153
  }
140
- declare function ReportPlugin(options: ReportOptions, cwd: string, cjsDts?: boolean, name?: string, isMultiFormat?: boolean): Plugin;
154
+ declare function ReportPlugin(options: ReportOptions, logger: Logger, cwd: string, cjsDts?: boolean, name?: string, isMultiFormat?: boolean): Plugin;
141
155
  //#endregion
142
156
  //#region src/options/types.d.ts
143
157
  type Sourcemap = boolean | "inline" | "hidden";
@@ -275,15 +289,27 @@ interface Options {
275
289
  * ```
276
290
  */
277
291
  loader?: ModuleTypes;
278
- /** @default false */
292
+ /**
293
+ * @default false
294
+ * @deprecated Use `logLevel` instead.
295
+ */
279
296
  silent?: boolean;
280
297
  /**
298
+ * Log level.
299
+ * @default 'info'
300
+ */
301
+ logLevel?: LogLevel;
302
+ /**
303
+ * Custom logger.
304
+ */
305
+ customLogger?: Logger;
306
+ /**
281
307
  * Config file path
282
308
  */
283
309
  config?: boolean | string;
284
310
  /** @default false */
285
- watch?: boolean | string | string[];
286
- ignoreWatch?: string | string[];
311
+ watch?: boolean | Arrayable<string>;
312
+ ignoreWatch?: Arrayable<string | RegExp>;
287
313
  /**
288
314
  * You can specify command to be executed after a successful build, specially useful for Watch mode
289
315
  */
@@ -422,7 +448,7 @@ interface Options {
422
448
  type UserConfig = Arrayable<Omit<Options, "config" | "filter">>;
423
449
  type UserConfigFn = (cliOptions: Options) => Awaitable<UserConfig>;
424
450
  type NormalizedUserConfig = Exclude<UserConfig, any[]>;
425
- type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options, "publicDir" | "workspace" | "filter">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name" | "bundle" | "banner" | "footer">, {
451
+ type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options, "publicDir" | "workspace" | "filter" | "silent" | "logLevel" | "customLogger">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name" | "bundle" | "banner" | "footer">, {
426
452
  format: NormalizedFormat[];
427
453
  target?: string[];
428
454
  clean: string[];
@@ -432,6 +458,8 @@ type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options, "publicDir" | "w
432
458
  pkg?: PackageJson;
433
459
  exports: false | ExportsOptions;
434
460
  nodeProtocol: "strip" | boolean;
461
+ logger: Logger;
462
+ ignoreWatch: Array<string | RegExp>;
435
463
  }>, "config" | "fromVite">;
436
464
  //#endregion
437
- export { type AttwOptions, type BuildContext, type ChunkAddon, type ChunkAddonFunction, type ChunkAddonObject, type CopyEntry, type CopyOptions, type CopyOptionsFn, type DtsOptions, type ExportsOptions, Format, ModuleTypes, NormalizedFormat, NormalizedUserConfig, Options, type OutExtensionContext, type OutExtensionFactory, type OutExtensionObject, type PackageType, type PublintOptions, type ReportOptions, ReportPlugin, ResolvedOptions, type RolldownContext, Sourcemap, type TsdownChunks, type TsdownHooks, type UnusedOptions, UserConfig, UserConfigFn, Workspace };
465
+ export { type AttwOptions, type BuildContext, type ChunkAddon, type ChunkAddonFunction, type ChunkAddonObject, type CopyEntry, type CopyOptions, type CopyOptionsFn, type DtsOptions, type ExportsOptions, Format, Logger, ModuleTypes, NormalizedFormat, NormalizedUserConfig, Options, type OutExtensionContext, type OutExtensionFactory, type OutExtensionObject, type PackageType, type PublintOptions, type ReportOptions, ReportPlugin, ResolvedOptions, type RolldownContext, Sourcemap, type TsdownChunks, type TsdownHooks, type UnusedOptions, UserConfig, UserConfigFn, Workspace, globalLogger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -74,8 +74,8 @@
74
74
  "diff": "^8.0.2",
75
75
  "empathic": "^2.0.0",
76
76
  "hookable": "^5.5.3",
77
- "rolldown": "^1.0.0-beta.30",
78
- "rolldown-plugin-dts": "^0.15.0",
77
+ "rolldown": "^1.0.0-beta.31",
78
+ "rolldown-plugin-dts": "^0.15.3",
79
79
  "semver": "^7.7.2",
80
80
  "tinyexec": "^1.0.1",
81
81
  "tinyglobby": "^0.2.14",
@@ -88,14 +88,14 @@
88
88
  "@sxzz/prettier-config": "^2.2.3",
89
89
  "@sxzz/test-utils": "^0.5.9",
90
90
  "@types/debug": "^4.1.12",
91
- "@types/node": "^24.1.0",
91
+ "@types/node": "^24.2.0",
92
92
  "@types/semver": "^7.7.0",
93
- "@unocss/eslint-plugin": "^66.4.0",
93
+ "@unocss/eslint-plugin": "^66.4.1",
94
94
  "@vueuse/core": "^13.6.0",
95
95
  "bumpp": "^10.2.2",
96
96
  "eslint": "^9.32.0",
97
97
  "lightningcss": "^1.30.1",
98
- "oxc-minify": "^0.79.1",
98
+ "oxc-minify": "^0.80.0",
99
99
  "pkg-types": "^2.2.0",
100
100
  "prettier": "^3.6.2",
101
101
  "publint": "^0.3.12",
@@ -104,7 +104,7 @@
104
104
  "typedoc-plugin-markdown": "^4.8.0",
105
105
  "typedoc-vitepress-theme": "^1.1.2",
106
106
  "typescript": "~5.9.2",
107
- "unocss": "^66.4.0",
107
+ "unocss": "^66.4.1",
108
108
  "unplugin-lightningcss": "^0.4.1",
109
109
  "unplugin-unused": "^0.5.1",
110
110
  "vite": "npm:rolldown-vite@latest",
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.13.2";
3
-
4
- //#endregion
5
- export { version };