tsdown 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from "./config-CCGWF4al.mjs";
2
- import { build, buildSingle, shimFile } from "./src-D_PDH4ZS.mjs";
2
+ import { build, buildSingle, shimFile } from "./src-XtWW9dvn.mjs";
3
3
  import { globalLogger } from "./logger-CGMSjTLn.mjs";
4
4
 
5
5
  export { build, buildSingle, defineConfig, globalLogger, shimFile };
@@ -1,5 +1,5 @@
1
1
  import { globalLogger } from "./logger-CGMSjTLn.mjs";
2
- import { version } from "./package-TDRl9aMv.mjs";
2
+ import { version } from "./package-hNMMm6hX.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";
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.14.1";
3
+
4
+ //#endregion
5
+ export { version };
package/dist/plugins.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./config-CCGWF4al.mjs";
2
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-D_PDH4ZS.mjs";
2
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-XtWW9dvn.mjs";
3
3
  import "./logger-CGMSjTLn.mjs";
4
4
 
5
5
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
package/dist/run.d.mts CHANGED
@@ -1 +1 @@
1
- export { };
1
+ export {};
package/dist/run.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { globalLogger, resolveComma, toArray } from "./logger-CGMSjTLn.mjs";
3
- import { version } from "./package-DOiAuQ-5.mjs";
3
+ import { version } from "./package-hNMMm6hX.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
@@ -22,7 +22,7 @@ cli.command("[...files]", "Bundle files", {
22
22
  await build$1(flags);
23
23
  });
24
24
  cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
25
- const { migrate } = await import("./migrate-Cl62m5IG.mjs");
25
+ const { migrate } = await import("./migrate-ByqyzNKc.mjs");
26
26
  await migrate(args);
27
27
  });
28
28
  async function runCLI() {
@@ -31,10 +31,10 @@ async function runCLI() {
31
31
  let namespace;
32
32
  if (cli.options.debug === true) namespace = "tsdown:*";
33
33
  else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
34
- const enabled = debug.disable();
34
+ const enabled = Debug.disable();
35
35
  if (enabled) namespace += `,${enabled}`;
36
- debug.enable(namespace);
37
- debug("tsdown:debug")("Debugging enabled", namespace);
36
+ Debug.enable(namespace);
37
+ Debug("tsdown:debug")("Debugging enabled", namespace);
38
38
  }
39
39
  try {
40
40
  await cli.runMatchedCommand();
@@ -51,4 +51,5 @@ try {
51
51
  } catch {}
52
52
  runCLI();
53
53
 
54
- //#endregion
54
+ //#endregion
55
+ export { };
@@ -11,7 +11,7 @@ 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
15
  import coerce from "semver/functions/coerce.js";
16
16
  import satisfies from "semver/functions/satisfies.js";
17
17
  import { glob } from "tinyglobby";
@@ -66,7 +66,7 @@ function lowestCommonAncestor(...filepaths) {
66
66
 
67
67
  //#endregion
68
68
  //#region src/features/attw.ts
69
- const debug$8 = debug("tsdown:attw");
69
+ const debug$7 = Debug("tsdown:attw");
70
70
  const exec$1 = promisify(child_process.exec);
71
71
  /**
72
72
  * ATTW profiles.
@@ -113,7 +113,7 @@ async function attw(options) {
113
113
  }
114
114
  const { profile = "strict", level = "warn",...attwOptions } = options.attw === true ? {} : options.attw;
115
115
  const t = performance.now();
116
- debug$8("Running attw check");
116
+ debug$7("Running attw check");
117
117
  const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
118
118
  let attwCore;
119
119
  try {
@@ -147,7 +147,7 @@ async function attw(options) {
147
147
  } else options.logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
148
148
  } catch (error) {
149
149
  options.logger.error("ATTW check failed:", error);
150
- debug$8("Found errors, setting exit code to 1");
150
+ debug$7("Found errors, setting exit code to 1");
151
151
  process.exitCode = 1;
152
152
  } finally {
153
153
  await fsRemove(tempDir);
@@ -172,7 +172,7 @@ function warnLegacyCJS(config) {
172
172
 
173
173
  //#endregion
174
174
  //#region src/features/clean.ts
175
- const debug$7 = debug("tsdown:clean");
175
+ const debug$6 = Debug("tsdown:clean");
176
176
  const RE_LAST_SLASH = /[/\\]$/;
177
177
  async function cleanOutDir(configs) {
178
178
  const removes = /* @__PURE__ */ new Set();
@@ -181,8 +181,7 @@ async function cleanOutDir(configs) {
181
181
  const files = await glob(config.clean, {
182
182
  cwd: config.cwd,
183
183
  absolute: true,
184
- onlyFiles: false,
185
- expandDirectories: false
184
+ onlyFiles: false
186
185
  });
187
186
  const normalizedOutDir = config.outDir.replace(RE_LAST_SLASH, "");
188
187
  for (const file of files) {
@@ -193,10 +192,10 @@ async function cleanOutDir(configs) {
193
192
  if (!removes.size) return;
194
193
  globalLogger.info(`Cleaning ${removes.size} files`);
195
194
  await Promise.all([...removes].map(async (file) => {
196
- debug$7("Removing", file);
195
+ debug$6("Removing", file);
197
196
  await fsRemove(file);
198
197
  }));
199
- debug$7("Removed %d files", removes.size);
198
+ debug$6("Removed %d files", removes.size);
200
199
  }
201
200
  function resolveClean(clean, outDir, cwd) {
202
201
  if (clean === true) clean = [slash(outDir)];
@@ -346,7 +345,7 @@ async function createHooks$1(options) {
346
345
 
347
346
  //#endregion
348
347
  //#region src/features/publint.ts
349
- const debug$6 = debug("tsdown:publint");
348
+ const debug$5 = Debug("tsdown:publint");
350
349
  async function publint(options) {
351
350
  if (!options.publint) return;
352
351
  if (!options.pkg) {
@@ -354,11 +353,11 @@ async function publint(options) {
354
353
  return;
355
354
  }
356
355
  const t = performance.now();
357
- debug$6("Running publint");
356
+ debug$5("Running publint");
358
357
  const { publint: publint$1 } = await import("publint");
359
358
  const { formatMessage } = await import("publint/utils");
360
359
  const { messages } = await publint$1(options.publint === true ? {} : options.publint);
361
- debug$6("Found %d issues", messages.length);
360
+ debug$5("Found %d issues", messages.length);
362
361
  if (!messages.length) options.logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
363
362
  let hasError = false;
364
363
  for (const message of messages) {
@@ -372,7 +371,7 @@ async function publint(options) {
372
371
  options.logger[logType](formattedMessage);
373
372
  }
374
373
  if (hasError) {
375
- debug$6("Found errors, setting exit code to 1");
374
+ debug$5("Found errors, setting exit code to 1");
376
375
  process.exitCode = 1;
377
376
  }
378
377
  }
@@ -483,11 +482,11 @@ async function resolveTsconfig(logger, tsconfig, cwd, name) {
483
482
 
484
483
  //#endregion
485
484
  //#region src/utils/package.ts
486
- const debug$5 = debug("tsdown:package");
485
+ const debug$4 = Debug("tsdown:package");
487
486
  async function readPackageJson(dir) {
488
487
  const packageJsonPath = up$1({ cwd: dir });
489
488
  if (!packageJsonPath) return;
490
- debug$5("Reading package.json:", packageJsonPath);
489
+ debug$4("Reading package.json:", packageJsonPath);
491
490
  const contents = await readFile(packageJsonPath, "utf8");
492
491
  return {
493
492
  ...JSON.parse(contents),
@@ -603,7 +602,7 @@ async function loadConfigFile(options, workspace) {
603
602
 
604
603
  //#endregion
605
604
  //#region src/options/index.ts
606
- const debug$4 = debug("tsdown:options");
605
+ const debug$3 = Debug("tsdown:options");
607
606
  const DEFAULT_EXCLUDE_WORKSPACE = [
608
607
  "**/node_modules/**",
609
608
  "**/dist/**",
@@ -611,20 +610,20 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
611
610
  "**/t?(e)mp/**"
612
611
  ];
613
612
  async function resolveOptions(options) {
614
- debug$4("options %O", options);
613
+ debug$3("options %O", options);
615
614
  const { configs: rootConfigs, file } = await loadConfigFile(options);
616
615
  const files = [];
617
616
  if (file) {
618
617
  files.push(file);
619
- debug$4("loaded root config file %s", file);
620
- debug$4("root configs %O", rootConfigs);
621
- } else debug$4("no root config file found");
618
+ debug$3("loaded root config file %s", file);
619
+ debug$3("root configs %O", rootConfigs);
620
+ } else debug$3("no root config file found");
622
621
  const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
623
622
  const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
624
623
  if (workspaceFiles) files.push(...workspaceFiles);
625
624
  return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveConfig(config)));
626
625
  }))).flat();
627
- debug$4("resolved configs %O", configs);
626
+ debug$3("resolved configs %O", configs);
628
627
  return {
629
628
  configs,
630
629
  files
@@ -644,14 +643,12 @@ async function resolveWorkspace(config, options) {
644
643
  if (workspace === true) workspace = {};
645
644
  else if (typeof workspace === "string" || Array.isArray(workspace)) workspace = { include: workspace };
646
645
  let { include: packages = "auto", exclude = DEFAULT_EXCLUDE_WORKSPACE, config: workspaceConfig } = workspace;
647
- if (packages === "auto") packages = (await glob({
648
- patterns: "**/package.json",
646
+ if (packages === "auto") packages = (await glob("**/package.json", {
649
647
  ignore: exclude,
650
648
  cwd: rootCwd,
651
649
  expandDirectories: false
652
650
  })).filter((file) => file !== "package.json").map((file) => slash(path.resolve(rootCwd, file, "..")));
653
- else packages = (await glob({
654
- patterns: packages,
651
+ else packages = (await glob(packages, {
655
652
  ignore: exclude,
656
653
  cwd: rootCwd,
657
654
  onlyDirectories: true,
@@ -668,16 +665,16 @@ async function resolveWorkspace(config, options) {
668
665
  }
669
666
  const files = [];
670
667
  const configs = (await Promise.all(packages.map(async (cwd) => {
671
- debug$4("loading workspace config %s", cwd);
668
+ debug$3("loading workspace config %s", cwd);
672
669
  const { configs: configs$1, file } = await loadConfigFile({
673
670
  ...options,
674
671
  config: workspaceConfig,
675
672
  cwd
676
673
  }, cwd);
677
674
  if (file) {
678
- debug$4("loaded workspace config file %s", file);
675
+ debug$3("loaded workspace config file %s", file);
679
676
  files.push(file);
680
- } else debug$4("no workspace config file found in %s", cwd);
677
+ } else debug$3("no workspace config file found in %s", cwd);
681
678
  return configs$1.map((config$1) => ({
682
679
  ...normalized,
683
680
  cwd,
@@ -774,7 +771,7 @@ async function mergeUserOptions(defaults, user, args) {
774
771
 
775
772
  //#endregion
776
773
  //#region src/features/external.ts
777
- const debug$3 = debug("tsdown:external");
774
+ const debug$2 = Debug("tsdown:external");
778
775
  function ExternalPlugin(options) {
779
776
  const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
780
777
  return {
@@ -802,7 +799,7 @@ function ExternalPlugin(options) {
802
799
  }
803
800
  if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
804
801
  if (shouldExternal) {
805
- debug$3("External dependency:", id);
802
+ debug$2("External dependency:", id);
806
803
  return {
807
804
  id,
808
805
  external: shouldExternal,
@@ -959,7 +956,7 @@ function formatBytes(bytes) {
959
956
 
960
957
  //#endregion
961
958
  //#region src/features/report.ts
962
- const debug$2 = debug("tsdown:report");
959
+ const debug$1 = Debug("tsdown:report");
963
960
  const brotliCompressAsync = promisify(brotliCompress);
964
961
  const gzipAsync = promisify(gzip);
965
962
  function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
@@ -1000,19 +997,19 @@ function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
1000
997
  };
1001
998
  }
1002
999
  async function calcSize(options, chunk) {
1003
- debug$2(`Calculating size for`, chunk.fileName);
1000
+ debug$1(`Calculating size for`, chunk.fileName);
1004
1001
  const content = chunk.type === "chunk" ? chunk.code : chunk.source;
1005
1002
  const raw = Buffer.byteLength(content, "utf8");
1006
- debug$2("[size]", chunk.fileName, raw);
1003
+ debug$1("[size]", chunk.fileName, raw);
1007
1004
  let gzip$1 = Infinity;
1008
1005
  let brotli = Infinity;
1009
- if (raw > (options.maxCompressSize ?? 1e6)) debug$2(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
1006
+ if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
1010
1007
  else {
1011
1008
  gzip$1 = (await gzipAsync(content)).length;
1012
- debug$2("[gzip]", chunk.fileName, gzip$1);
1009
+ debug$1("[gzip]", chunk.fileName, gzip$1);
1013
1010
  if (options.brotli) {
1014
1011
  brotli = (await brotliCompressAsync(content)).length;
1015
- debug$2("[brotli]", chunk.fileName, brotli);
1012
+ debug$1("[brotli]", chunk.fileName, brotli);
1016
1013
  }
1017
1014
  }
1018
1015
  return {
@@ -1059,7 +1056,7 @@ function getShimsInject(format, platform) {
1059
1056
 
1060
1057
  //#endregion
1061
1058
  //#region src/features/rolldown.ts
1062
- const debug$1 = debug("tsdown:rolldown");
1059
+ const debug = Debug("tsdown:rolldown");
1063
1060
  async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
1064
1061
  const inputOptions = await resolveInputOptions(config, format, cjsDts, isMultiFormat);
1065
1062
  const outputOptions = await resolveOutputOptions(inputOptions, config, format, cjsDts);
@@ -1067,7 +1064,7 @@ async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
1067
1064
  ...inputOptions,
1068
1065
  output: outputOptions
1069
1066
  };
1070
- debug$1("rolldown config with format \"%s\" %O", cjsDts ? "cjs dts" : format, rolldownConfig);
1067
+ debug("rolldown config with format \"%s\" %O", cjsDts ? "cjs dts" : format, rolldownConfig);
1071
1068
  return rolldownConfig;
1072
1069
  }
1073
1070
  async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -100,7 +100,7 @@
100
100
  "prettier": "^3.6.2",
101
101
  "publint": "^0.3.12",
102
102
  "tsx": "^4.20.3",
103
- "typedoc": "^0.28.9",
103
+ "typedoc": "^0.28.10",
104
104
  "typedoc-plugin-markdown": "^4.8.0",
105
105
  "typedoc-vitepress-theme": "^1.1.2",
106
106
  "typescript": "~5.9.2",
@@ -126,7 +126,7 @@
126
126
  "test": "vitest",
127
127
  "typecheck": "tsc --noEmit",
128
128
  "format": "prettier --cache --write .",
129
- "release": "bumpp && pnpm publish",
129
+ "release": "bumpp",
130
130
  "docs:dev": "vitepress dev docs",
131
131
  "docs:build": "vitepress build docs",
132
132
  "docs:preview": "vitepress preview docs",
@@ -1,46 +0,0 @@
1
- import { version } from "./package-DwljelGW.mjs";
2
- import { globalLogger, resolveComma, toArray } from "./logger-YArsxPto.mjs";
3
- import process from "node:process";
4
- import { dim } from "ansis";
5
- import { cac } from "cac";
6
- import debug from "debug";
7
- import { VERSION } from "rolldown";
8
-
9
- //#region src/cli.ts
10
- const cli = cac("tsdown");
11
- cli.help().version(version);
12
- cli.command("[...files]", "Bundle files", {
13
- ignoreOptionDefaultValue: true,
14
- allowUnknownOptions: true
15
- }).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("--fail-on-warn", "Fail on warnings", { default: true }).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) => {
16
- globalLogger.level = flags.logLevel || (flags.silent ? "silent" : "info");
17
- globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
18
- const { build: build$1 } = await import("./index.mjs");
19
- if (input.length > 0) flags.entry = input;
20
- await build$1(flags);
21
- });
22
- 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.mjs");
24
- await migrate(args);
25
- });
26
- async function runCLI() {
27
- cli.parse(process.argv, { run: false });
28
- if (cli.options.debug) {
29
- let namespace;
30
- if (cli.options.debug === true) namespace = "tsdown:*";
31
- else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
32
- const enabled = debug.disable();
33
- if (enabled) namespace += `,${enabled}`;
34
- debug.enable(namespace);
35
- debug("tsdown:debug")("Debugging enabled", namespace);
36
- }
37
- try {
38
- await cli.runMatchedCommand();
39
- } catch (error) {
40
- globalLogger.error(error);
41
- process.exit(1);
42
- }
43
- }
44
-
45
- //#endregion
46
- export { runCLI };
package/dist/cli.d.mts DELETED
@@ -1,4 +0,0 @@
1
- //#region src/cli.d.ts
2
- declare function runCLI(): Promise<void>;
3
- //#endregion
4
- export { runCLI };
package/dist/cli.mjs DELETED
@@ -1,5 +0,0 @@
1
- import "./package-DwljelGW.mjs";
2
- import "./logger-YArsxPto.mjs";
3
- import { runCLI } from "./cli-BwOoKKTM.mjs";
4
-
5
- export { runCLI };
@@ -1,7 +0,0 @@
1
- //#region src/config.ts
2
- function defineConfig(options) {
3
- return options;
4
- }
5
-
6
- //#endregion
7
- export { defineConfig };
@@ -1,144 +0,0 @@
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$1) => format$1.split(","));
13
- }
14
- function resolveRegex(str) {
15
- if (typeof str === "string" && str.length > 2 && str[0] === "/" && str.at(-1) === "/") return new RegExp(str.slice(1, -1));
16
- return str;
17
- }
18
- function debounce(fn, wait) {
19
- let timeout;
20
- return function(...args) {
21
- if (timeout) clearTimeout(timeout);
22
- timeout = setTimeout(() => {
23
- timeout = void 0;
24
- fn.apply(this, args);
25
- }, wait);
26
- };
27
- }
28
- function slash(string) {
29
- return string.replaceAll("\\", "/");
30
- }
31
- const noop = (v) => v;
32
-
33
- //#endregion
34
- //#region src/utils/logger.ts
35
- const LogLevels = {
36
- silent: 0,
37
- error: 1,
38
- warn: 2,
39
- info: 3
40
- };
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, failOnWarn = false } = {}) {
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
- if (failOnWarn) throw new Error(message);
61
- warnedMessages.add(message);
62
- output("warn", `\n${bgYellow` WARN `} ${message}\n`);
63
- },
64
- warnOnce(...msgs) {
65
- const message = format(msgs);
66
- if (warnedMessages.has(message)) return;
67
- if (failOnWarn) throw new Error(message);
68
- warnedMessages.add(message);
69
- output("warn", `\n${bgYellow` WARN `} ${message}\n`);
70
- },
71
- error(...msgs) {
72
- output("error", `\n${bgRed` ERROR `} ${format(msgs)}\n`);
73
- },
74
- success(...msgs) {
75
- output("info", `${green`✔`} ${format(msgs)}`);
76
- }
77
- };
78
- return logger;
79
- }
80
- const globalLogger = createLogger();
81
- function prettyName(name) {
82
- if (!name) return void 0;
83
- return generateColor(name)(`[${name}]`);
84
- }
85
- function prettyFormat(format$1) {
86
- const formatColor = format$1 === "es" ? blue : format$1 === "cjs" ? yellow : noop;
87
- let formatText;
88
- switch (format$1) {
89
- case "es":
90
- formatText = "ESM";
91
- break;
92
- default:
93
- formatText = format$1.toUpperCase();
94
- break;
95
- }
96
- return formatColor(`[${formatText}]`);
97
- }
98
- const colors = /* @__PURE__ */ new Map();
99
- function generateColor(name = "default") {
100
- if (colors.has(name)) return colors.get(name);
101
- let color;
102
- if (name === "default") color = blue;
103
- else {
104
- let hash = 0;
105
- for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash);
106
- const hue = hash % 360;
107
- const saturation = 35;
108
- const lightness = 55;
109
- color = rgb(...hslToRgb(hue, saturation, lightness));
110
- }
111
- colors.set(name, color);
112
- return color;
113
- }
114
- function hslToRgb(h, s, l) {
115
- h = h % 360;
116
- h /= 360;
117
- s /= 100;
118
- l /= 100;
119
- let r, g, b;
120
- if (s === 0) r = g = b = l;
121
- else {
122
- const q = l < .5 ? l * (1 + s) : l + s - l * s;
123
- const p = 2 * l - q;
124
- r = hue2rgb(p, q, h + 1 / 3);
125
- g = hue2rgb(p, q, h);
126
- b = hue2rgb(p, q, h - 1 / 3);
127
- }
128
- return [
129
- Math.max(0, Math.round(r * 255)),
130
- Math.max(0, Math.round(g * 255)),
131
- Math.max(0, Math.round(b * 255))
132
- ];
133
- }
134
- function hue2rgb(p, q, t) {
135
- if (t < 0) t += 1;
136
- if (t > 1) t -= 1;
137
- if (t < 1 / 6) return p + (q - p) * 6 * t;
138
- if (t < 1 / 2) return q;
139
- if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
140
- return p;
141
- }
142
-
143
- //#endregion
144
- export { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };