tsdown 0.14.2 → 0.15.0

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/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2025-present VoidZero Inc. & Contributors
4
- Copyright (c) 2024 三咲智子 Kevin Deng (https://github.com/sxzz)
4
+ Copyright (c) 2024 Kevin Deng (https://github.com/sxzz)
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
package/client.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ interface ImportGlobOptions<Eager extends boolean> {
2
+ /**
3
+ * Import as static or dynamic
4
+ *
5
+ * @default false
6
+ */
7
+ eager?: Eager
8
+ /**
9
+ * Import only the specific named export. Set to `default` to import the default export.
10
+ */
11
+ import?: string
12
+ /**
13
+ * Custom queries
14
+ */
15
+ query?: string | Record<string, string | number | boolean>
16
+ /**
17
+ * Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
18
+ *
19
+ * @default false
20
+ */
21
+ exhaustive?: boolean
22
+ /**
23
+ * Base path to resolve relative paths.
24
+ */
25
+ base?: string
26
+ }
27
+
28
+ type GeneralImportGlobOptions = ImportGlobOptions<boolean>
29
+
30
+ interface KnownAsTypeMap {
31
+ raw: string
32
+ url: string
33
+ }
34
+
35
+ interface ImportGlobFunction {
36
+ /**
37
+ * Import a list of files with a glob pattern.
38
+ *
39
+ * Overload 1: Module generic provided, infer the type from `eager: false`
40
+ */
41
+ <M>(
42
+ glob: string | string[],
43
+ options?: ImportGlobOptions<false>,
44
+ ): Record<string, () => Promise<M>>
45
+ /**
46
+ * Import a list of files with a glob pattern.
47
+ *
48
+ * Overload 2: Module generic provided, infer the type from `eager: true`
49
+ */
50
+ <M>(
51
+ glob: string | string[],
52
+ options: ImportGlobOptions<true>,
53
+ ): Record<string, M>
54
+ }
55
+
56
+ interface ImportMeta {
57
+ glob: ImportGlobFunction
58
+ }
@@ -1,4 +1,4 @@
1
- import { UserConfig, UserConfigFn } from "./types-cXo_SNGd.mjs";
1
+ import { UserConfig, UserConfigFn } from "./types-CrxW0Y6g.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-cXo_SNGd.mjs";
2
- import { defineConfig } from "./config-DwMASPo6.mjs";
1
+ import { UserConfig, UserConfigFn } from "./types-CrxW0Y6g.mjs";
2
+ import { defineConfig } from "./config-Dk5Fszoy.mjs";
3
3
  export { UserConfig, UserConfigFn, defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
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-cXo_SNGd.mjs";
2
- import { defineConfig } from "./config-DwMASPo6.mjs";
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-CrxW0Y6g.mjs";
2
+ import { defineConfig } from "./config-Dk5Fszoy.mjs";
3
3
 
4
4
  //#region src/index.d.ts
5
5
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from "./config-CCGWF4al.mjs";
2
- import { build, buildSingle, shimFile } from "./src-BhIGOkxO.mjs";
3
- import { globalLogger } from "./logger-CGMSjTLn.mjs";
2
+ import { build, buildSingle, shimFile } from "./src-DecVfDJY.mjs";
3
+ import { globalLogger } from "./logger-C09npKHT.mjs";
4
4
 
5
5
  export { build, buildSingle, defineConfig, globalLogger, shimFile };
@@ -45,10 +45,8 @@ const warnedMessages = /* @__PURE__ */ new Set();
45
45
  function createLogger(level = "info", { customLogger, console = globalThis.console, failOnWarn = false } = {}) {
46
46
  if (customLogger) return customLogger;
47
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);
48
+ if (LogLevels[logger.level] < LogLevels[type]) return;
49
+ console[type === "info" ? "log" : type](msg);
52
50
  }
53
51
  const logger = {
54
52
  level,
@@ -104,9 +102,7 @@ function generateColor(name = "default") {
104
102
  let hash = 0;
105
103
  for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash);
106
104
  const hue = hash % 360;
107
- const saturation = 35;
108
- const lightness = 55;
109
- color = rgb(...hslToRgb(hue, saturation, lightness));
105
+ color = rgb(...hslToRgb(hue, 35, 55));
110
106
  }
111
107
  colors.set(name, color);
112
108
  return color;
@@ -1,5 +1,5 @@
1
- import { globalLogger } from "./logger-CGMSjTLn.mjs";
2
- import { version } from "./package-DOwY1eta.mjs";
1
+ import { globalLogger } from "./logger-C09npKHT.mjs";
2
+ import { version } from "./package-BCet0jau.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";
@@ -17,8 +17,7 @@ async function migrate({ cwd, dryRun }) {
17
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
- const confirm = input.toLowerCase() === "y" || input === "";
21
- if (!confirm) {
20
+ if (!(input.toLowerCase() === "y" || input === "")) {
22
21
  globalLogger.error("Migration cancelled.");
23
22
  process.exitCode = 1;
24
23
  return;
@@ -0,0 +1,5 @@
1
+ //#region package.json
2
+ var version = "0.15.0";
3
+
4
+ //#endregion
5
+ export { version };
@@ -1,4 +1,4 @@
1
- import { Logger, ReportPlugin, ResolvedOptions } from "./types-cXo_SNGd.mjs";
1
+ import { Logger, ReportPlugin, ResolvedOptions } from "./types-CrxW0Y6g.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
package/dist/plugins.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./config-CCGWF4al.mjs";
2
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-BhIGOkxO.mjs";
3
- import "./logger-CGMSjTLn.mjs";
2
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-DecVfDJY.mjs";
3
+ import "./logger-C09npKHT.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 { globalLogger, resolveComma, toArray } from "./logger-CGMSjTLn.mjs";
3
- import { version } from "./package-DOwY1eta.mjs";
2
+ import { globalLogger, resolveComma, toArray } from "./logger-C09npKHT.mjs";
3
+ import { version } from "./package-BCet0jau.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-DQpxfr1J.mjs");
25
+ const { migrate } = await import("./migrate-Di69B4rp.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();
@@ -1,4 +1,4 @@
1
- import { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-CGMSjTLn.mjs";
1
+ import { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-C09npKHT.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,12 +11,13 @@ 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";
18
18
  import { RE_CSS, RE_DTS, RE_JS } from "rolldown-plugin-dts/filename";
19
19
  import { createHooks } from "hookable";
20
+ import { importGlobPlugin } from "rolldown/experimental";
20
21
  import minVersion from "semver/ranges/min-version.js";
21
22
  import { up } from "empathic/find";
22
23
  import { up as up$1 } from "empathic/package";
@@ -66,7 +67,7 @@ function lowestCommonAncestor(...filepaths) {
66
67
 
67
68
  //#endregion
68
69
  //#region src/features/attw.ts
69
- const debug$7 = Debug("tsdown:attw");
70
+ const debug$8 = debug("tsdown:attw");
70
71
  const exec$1 = promisify(child_process.exec);
71
72
  /**
72
73
  * ATTW profiles.
@@ -93,8 +94,7 @@ function formatProblem(problem) {
93
94
  case "CJSResolvesToESM": return ` ⚡ CJS resolves to ESM${resolutionKind}${entrypoint}`;
94
95
  case "NamedExports": {
95
96
  const missingExports = problem.missing?.length > 0 ? ` Missing: ${problem.missing.join(", ")}` : "";
96
- const allMissing = problem.isMissingAllNamed ? " (all named exports missing)" : "";
97
- return ` 📤 Named exports problem${allMissing}${missingExports}\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
97
+ return ` 📤 Named exports problem${problem.isMissingAllNamed ? " (all named exports missing)" : ""}${missingExports}\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
98
98
  }
99
99
  case "FallbackCondition": return ` 🎯 Fallback condition used${resolutionKind}${entrypoint}`;
100
100
  case "FalseExportDefault": return ` 🎭 False export default\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
@@ -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$7("Running attw check");
116
+ debug$8("Running attw check");
117
117
  const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
118
118
  let attwCore;
119
119
  try {
@@ -139,15 +139,14 @@ async function attw(options) {
139
139
  return true;
140
140
  });
141
141
  if (problems.length) {
142
- const problemList = problems.map(formatProblem).join("\n");
143
- const problemMessage = `Are the types wrong problems found:\n${problemList}`;
142
+ const problemMessage = `Are the types wrong problems found:\n${problems.map(formatProblem).join("\n")}`;
144
143
  if (level === "error") throw new Error(problemMessage);
145
144
  options.logger.warn(problemMessage);
146
145
  }
147
146
  } else options.logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
148
147
  } catch (error) {
149
148
  options.logger.error("ATTW check failed:", error);
150
- debug$7("Found errors, setting exit code to 1");
149
+ debug$8("Found errors, setting exit code to 1");
151
150
  process.exitCode = 1;
152
151
  } finally {
153
152
  await fsRemove(tempDir);
@@ -163,16 +162,15 @@ async function attw(options) {
163
162
  */
164
163
  function warnLegacyCJS(config) {
165
164
  if (!config.format.includes("cjs") || !config.target) return;
166
- const legacy = config.target.some((t) => {
165
+ if (config.target.some((t) => {
167
166
  const version = coerce(t.split("node")[1]);
168
167
  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");
168
+ })) 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
169
  }
172
170
 
173
171
  //#endregion
174
172
  //#region src/features/clean.ts
175
- const debug$6 = Debug("tsdown:clean");
173
+ const debug$7 = debug("tsdown:clean");
176
174
  const RE_LAST_SLASH = /[/\\]$/;
177
175
  async function cleanOutDir(configs) {
178
176
  const removes = /* @__PURE__ */ new Set();
@@ -184,18 +182,15 @@ async function cleanOutDir(configs) {
184
182
  onlyFiles: false
185
183
  });
186
184
  const normalizedOutDir = config.outDir.replace(RE_LAST_SLASH, "");
187
- for (const file of files) {
188
- const normalizedFile = file.replace(RE_LAST_SLASH, "");
189
- if (normalizedFile !== normalizedOutDir) removes.add(file);
190
- }
185
+ for (const file of files) if (file.replace(RE_LAST_SLASH, "") !== normalizedOutDir) removes.add(file);
191
186
  }
192
187
  if (!removes.size) return;
193
188
  globalLogger.info(`Cleaning ${removes.size} files`);
194
189
  await Promise.all([...removes].map(async (file) => {
195
- debug$6("Removing", file);
190
+ debug$7("Removing", file);
196
191
  await fsRemove(file);
197
192
  }));
198
- debug$6("Removed %d files", removes.size);
193
+ debug$7("Removed %d files", removes.size);
199
194
  }
200
195
  function resolveClean(clean, outDir, cwd) {
201
196
  if (clean === true) clean = [slash(outDir)];
@@ -263,10 +258,7 @@ async function generateExports(pkg, outDir, chunks, { devExports, all, customExp
263
258
  else main = distFile;
264
259
  else if (format === "es") if (isDts) esmTypes = distFile;
265
260
  else module$1 = distFile;
266
- } else {
267
- const isDirIndex = name.endsWith("/index");
268
- name = isDirIndex ? `./${name.slice(0, -6)}` : `./${name}`;
269
- }
261
+ } else name = name.endsWith("/index") ? `./${name.slice(0, -6)}` : `./${name}`;
270
262
  let subExport = exportsMap.get(name);
271
263
  if (!subExport) {
272
264
  subExport = {};
@@ -345,19 +337,18 @@ async function createHooks$1(options) {
345
337
  const hooks = createHooks();
346
338
  if (typeof options.hooks === "object") hooks.addHooks(options.hooks);
347
339
  else if (typeof options.hooks === "function") await options.hooks(hooks);
348
- const context = {
349
- options,
350
- hooks
351
- };
352
340
  return {
353
341
  hooks,
354
- context
342
+ context: {
343
+ options,
344
+ hooks
345
+ }
355
346
  };
356
347
  }
357
348
 
358
349
  //#endregion
359
350
  //#region src/features/publint.ts
360
- const debug$5 = Debug("tsdown:publint");
351
+ const debug$6 = debug("tsdown:publint");
361
352
  async function publint(options) {
362
353
  if (!options.publint) return;
363
354
  if (!options.pkg) {
@@ -365,11 +356,11 @@ async function publint(options) {
365
356
  return;
366
357
  }
367
358
  const t = performance.now();
368
- debug$5("Running publint");
359
+ debug$6("Running publint");
369
360
  const { publint: publint$1 } = await import("publint");
370
361
  const { formatMessage } = await import("publint/utils");
371
362
  const { messages } = await publint$1(options.publint === true ? {} : options.publint);
372
- debug$5("Found %d issues", messages.length);
363
+ debug$6("Found %d issues", messages.length);
373
364
  if (!messages.length) options.logger.success(`No publint issues found`, dim`(${Math.round(performance.now() - t)}ms)`);
374
365
  let hasError = false;
375
366
  for (const message of messages) {
@@ -383,7 +374,7 @@ async function publint(options) {
383
374
  options.logger[logType](formattedMessage);
384
375
  }
385
376
  if (hasError) {
386
- debug$5("Found errors, setting exit code to 1");
377
+ debug$6("Found errors, setting exit code to 1");
387
378
  process.exitCode = 1;
388
379
  }
389
380
  }
@@ -494,11 +485,11 @@ async function resolveTsconfig(logger, tsconfig, cwd, name) {
494
485
 
495
486
  //#endregion
496
487
  //#region src/utils/package.ts
497
- const debug$4 = Debug("tsdown:package");
488
+ const debug$5 = debug("tsdown:package");
498
489
  async function readPackageJson(dir) {
499
490
  const packageJsonPath = up$1({ cwd: dir });
500
491
  if (!packageJsonPath) return;
501
- debug$4("Reading package.json:", packageJsonPath);
492
+ debug$5("Reading package.json:", packageJsonPath);
502
493
  const contents = await readFile(packageJsonPath, "utf8");
503
494
  return {
504
495
  ...JSON.parse(contents),
@@ -589,8 +580,7 @@ async function loadConfigFile(options, workspace) {
589
580
  ],
590
581
  parser: loaded || !nativeTS ? "auto" : async (filepath) => {
591
582
  const mod = await import(pathToFileURL(filepath).href);
592
- const config$1 = mod.default || mod;
593
- return config$1;
583
+ return mod.default || mod;
594
584
  }
595
585
  }, {
596
586
  files: "package.json",
@@ -614,7 +604,7 @@ async function loadConfigFile(options, workspace) {
614
604
 
615
605
  //#endregion
616
606
  //#region src/options/index.ts
617
- const debug$3 = Debug("tsdown:options");
607
+ const debug$4 = debug("tsdown:options");
618
608
  const DEFAULT_EXCLUDE_WORKSPACE = [
619
609
  "**/node_modules/**",
620
610
  "**/dist/**",
@@ -622,20 +612,20 @@ const DEFAULT_EXCLUDE_WORKSPACE = [
622
612
  "**/t?(e)mp/**"
623
613
  ];
624
614
  async function resolveOptions(options) {
625
- debug$3("options %O", options);
615
+ debug$4("options %O", options);
626
616
  const { configs: rootConfigs, file } = await loadConfigFile(options);
627
617
  const files = [];
628
618
  if (file) {
629
619
  files.push(file);
630
- debug$3("loaded root config file %s", file);
631
- debug$3("root configs %O", rootConfigs);
632
- } else debug$3("no root config file found");
620
+ debug$4("loaded root config file %s", file);
621
+ debug$4("root configs %O", rootConfigs);
622
+ } else debug$4("no root config file found");
633
623
  const configs = (await Promise.all(rootConfigs.map(async (rootConfig) => {
634
624
  const { configs: workspaceConfigs, files: workspaceFiles } = await resolveWorkspace(rootConfig, options);
635
625
  if (workspaceFiles) files.push(...workspaceFiles);
636
626
  return Promise.all(workspaceConfigs.filter((config) => !config.workspace || config.entry).map((config) => resolveConfig(config)));
637
627
  }))).flat();
638
- debug$3("resolved configs %O", configs);
628
+ debug$4("resolved configs %O", configs);
639
629
  return {
640
630
  configs,
641
631
  files
@@ -676,25 +666,24 @@ async function resolveWorkspace(config, options) {
676
666
  if (packages.length === 0) throw new Error("No packages matched the filters");
677
667
  }
678
668
  const files = [];
679
- const configs = (await Promise.all(packages.map(async (cwd) => {
680
- debug$3("loading workspace config %s", cwd);
681
- const { configs: configs$1, file } = await loadConfigFile({
682
- ...options,
683
- config: workspaceConfig,
684
- cwd
685
- }, cwd);
686
- if (file) {
687
- debug$3("loaded workspace config file %s", file);
688
- files.push(file);
689
- } else debug$3("no workspace config file found in %s", cwd);
690
- return configs$1.map((config$1) => ({
691
- ...normalized,
692
- cwd,
693
- ...config$1
694
- }));
695
- }))).flat();
696
669
  return {
697
- configs,
670
+ configs: (await Promise.all(packages.map(async (cwd) => {
671
+ debug$4("loading workspace config %s", cwd);
672
+ const { configs, file } = await loadConfigFile({
673
+ ...options,
674
+ config: workspaceConfig,
675
+ cwd
676
+ }, cwd);
677
+ if (file) {
678
+ debug$4("loaded workspace config file %s", file);
679
+ files.push(file);
680
+ } else debug$4("no workspace config file found in %s", cwd);
681
+ return configs.map((config$1) => ({
682
+ ...normalized,
683
+ cwd,
684
+ ...config$1
685
+ }));
686
+ }))).flat(),
698
687
  files
699
688
  };
700
689
  }
@@ -705,6 +694,7 @@ async function resolveConfig(userConfig) {
705
694
  failOnWarn
706
695
  });
707
696
  if (typeof bundle === "boolean") logger.warn("`bundle` option is deprecated. Use `unbundle` instead.");
697
+ if (removeNodeProtocol && nodeProtocol) throw new TypeError("`removeNodeProtocol` is deprecated. Please only use `nodeProtocol` instead.");
708
698
  nodeProtocol = nodeProtocol ?? (removeNodeProtocol ? "strip" : false);
709
699
  outDir = path.resolve(cwd, outDir);
710
700
  clean = resolveClean(clean, outDir, cwd);
@@ -735,7 +725,7 @@ async function resolveConfig(userConfig) {
735
725
  if (typeof ignore === "string") return path.resolve(cwd, ignore);
736
726
  return ignore;
737
727
  });
738
- const config = {
728
+ return {
739
729
  ...userConfig,
740
730
  entry,
741
731
  plugins,
@@ -771,7 +761,6 @@ async function resolveConfig(userConfig) {
771
761
  nodeProtocol,
772
762
  cjsDefault
773
763
  };
774
- return config;
775
764
  }
776
765
  async function mergeUserOptions(defaults, user, args) {
777
766
  const userOutputOptions = typeof user === "function" ? await user(defaults, ...args) : user;
@@ -783,7 +772,7 @@ async function mergeUserOptions(defaults, user, args) {
783
772
 
784
773
  //#endregion
785
774
  //#region src/features/external.ts
786
- const debug$2 = Debug("tsdown:external");
775
+ const debug$3 = debug("tsdown:external");
787
776
  function ExternalPlugin(options) {
788
777
  const deps = options.pkg && Array.from(getProductionDeps(options.pkg));
789
778
  return {
@@ -794,8 +783,7 @@ function ExternalPlugin(options) {
794
783
  const { noExternal } = options;
795
784
  if (typeof noExternal === "function" && noExternal(id, importer)) return;
796
785
  if (noExternal) {
797
- const noExternalPatterns = toArray(noExternal);
798
- if (noExternalPatterns.some((pattern) => {
786
+ if (toArray(noExternal).some((pattern) => {
799
787
  if (pattern instanceof RegExp) {
800
788
  pattern.lastIndex = 0;
801
789
  return pattern.test(id);
@@ -811,7 +799,7 @@ function ExternalPlugin(options) {
811
799
  }
812
800
  if (deps) shouldExternal ||= deps.some((dep) => id === dep || id.startsWith(`${dep}/`));
813
801
  if (shouldExternal) {
814
- debug$2("External dependency:", id);
802
+ debug$3("External dependency:", id);
815
803
  return {
816
804
  id,
817
805
  external: shouldExternal,
@@ -836,8 +824,7 @@ function getProductionDeps(pkg) {
836
824
  */
837
825
  function esbuildTargetToLightningCSS(target) {
838
826
  let targets;
839
- const targetString = target.join(" ").toLowerCase();
840
- const matches = [...targetString.matchAll(TARGET_REGEX)];
827
+ const matches = [...target.join(" ").toLowerCase().matchAll(TARGET_REGEX)];
841
828
  for (const match of matches) {
842
829
  const name = match[1];
843
830
  const browser = ESBUILD_LIGHTNINGCSS_MAPPING[name];
@@ -878,6 +865,7 @@ async function LightningCSSPlugin(options) {
878
865
 
879
866
  //#endregion
880
867
  //#region src/features/node-protocol.ts
868
+ const modulesWithoutProtocol = builtinModules.filter((mod) => !mod.startsWith("node:"));
881
869
  /**
882
870
  * The `node:` protocol was added in Node.js v14.18.0.
883
871
  * @see https://nodejs.org/api/esm.html#node-imports
@@ -887,7 +875,7 @@ function NodeProtocolPlugin(nodeProtocolOption) {
887
875
  name: "tsdown:node-protocol:strip",
888
876
  resolveId: {
889
877
  order: "pre",
890
- filter: { id: /^node:/ },
878
+ filter: { id: /* @__PURE__ */ new RegExp(`^node:(${modulesWithoutProtocol.join("|")})$`) },
891
879
  handler(id) {
892
880
  return {
893
881
  id: id.slice(5),
@@ -897,12 +885,11 @@ function NodeProtocolPlugin(nodeProtocolOption) {
897
885
  }
898
886
  }
899
887
  };
900
- const builtinModulesRegex = /* @__PURE__ */ new RegExp(`^(${builtinModules.join("|")})$`);
901
888
  return {
902
889
  name: "tsdown:node-protocol:add",
903
890
  resolveId: {
904
891
  order: "pre",
905
- filter: { id: builtinModulesRegex },
892
+ filter: { id: /* @__PURE__ */ new RegExp(`^(${modulesWithoutProtocol.join("|")})$`) },
906
893
  handler(id) {
907
894
  return {
908
895
  id: `node:${id}`,
@@ -968,7 +955,7 @@ function formatBytes(bytes) {
968
955
 
969
956
  //#endregion
970
957
  //#region src/features/report.ts
971
- const debug$1 = Debug("tsdown:report");
958
+ const debug$2 = debug("tsdown:report");
972
959
  const brotliCompressAsync = promisify(brotliCompress);
973
960
  const gzipAsync = promisify(gzip);
974
961
  function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
@@ -1009,19 +996,19 @@ function ReportPlugin(options, logger, cwd, cjsDts, name, isMultiFormat) {
1009
996
  };
1010
997
  }
1011
998
  async function calcSize(options, chunk) {
1012
- debug$1(`Calculating size for`, chunk.fileName);
999
+ debug$2(`Calculating size for`, chunk.fileName);
1013
1000
  const content = chunk.type === "chunk" ? chunk.code : chunk.source;
1014
1001
  const raw = Buffer.byteLength(content, "utf8");
1015
- debug$1("[size]", chunk.fileName, raw);
1002
+ debug$2("[size]", chunk.fileName, raw);
1016
1003
  let gzip$1 = Infinity;
1017
1004
  let brotli = Infinity;
1018
- if (raw > (options.maxCompressSize ?? 1e6)) debug$1(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
1005
+ if (raw > (options.maxCompressSize ?? 1e6)) debug$2(chunk.fileName, "file size exceeds limit, skip gzip/brotli");
1019
1006
  else {
1020
1007
  gzip$1 = (await gzipAsync(content)).length;
1021
- debug$1("[gzip]", chunk.fileName, gzip$1);
1008
+ debug$2("[gzip]", chunk.fileName, gzip$1);
1022
1009
  if (options.brotli) {
1023
1010
  brotli = (await brotliCompressAsync(content)).length;
1024
- debug$1("[brotli]", chunk.fileName, brotli);
1011
+ debug$2("[brotli]", chunk.fileName, brotli);
1025
1012
  }
1026
1013
  }
1027
1014
  return {
@@ -1068,7 +1055,7 @@ function getShimsInject(format, platform) {
1068
1055
 
1069
1056
  //#endregion
1070
1057
  //#region src/features/rolldown.ts
1071
- const debug = Debug("tsdown:rolldown");
1058
+ const debug$1 = debug("tsdown:rolldown");
1072
1059
  async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
1073
1060
  const inputOptions = await resolveInputOptions(config, format, cjsDts, isMultiFormat);
1074
1061
  const outputOptions = await resolveOutputOptions(inputOptions, config, format, cjsDts);
@@ -1076,7 +1063,7 @@ async function getBuildOptions(config, format, isMultiFormat, cjsDts = false) {
1076
1063
  ...inputOptions,
1077
1064
  output: outputOptions
1078
1065
  };
1079
- debug("rolldown config with format \"%s\" %O", cjsDts ? "cjs dts" : format, rolldownConfig);
1066
+ debug$1("rolldown config with format \"%s\" %O", cjsDts ? "cjs dts" : format, rolldownConfig);
1080
1067
  return rolldownConfig;
1081
1068
  }
1082
1069
  async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
@@ -1103,11 +1090,11 @@ async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
1103
1090
  plugins.push(Unused.rolldown(unused === true ? {} : unused));
1104
1091
  }
1105
1092
  if (target) plugins.push(RuntimeHelperCheckPlugin(logger, target), await LightningCSSPlugin({ target }));
1106
- plugins.push(ShebangPlugin(logger, cwd, name, isMultiFormat));
1093
+ plugins.push(ShebangPlugin(logger, cwd, name, isMultiFormat), importGlobPlugin());
1107
1094
  }
1108
1095
  if (report && LogLevels[logger.level] >= 3) plugins.push(ReportPlugin(report, logger, cwd, cjsDts, name, isMultiFormat));
1109
1096
  if (!cjsDts) plugins.push(userPlugins);
1110
- const inputOptions = await mergeUserOptions({
1097
+ return await mergeUserOptions({
1111
1098
  input: entry,
1112
1099
  cwd,
1113
1100
  external,
@@ -1133,12 +1120,11 @@ async function resolveInputOptions(config, format, cjsDts, isMultiFormat) {
1133
1120
  defaultHandler(level, log);
1134
1121
  } : void 0
1135
1122
  }, config.inputOptions, [format, { cjsDts }]);
1136
- return inputOptions;
1137
1123
  }
1138
1124
  async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
1139
1125
  const { entry, outDir, sourcemap, minify, unbundle, banner, footer, cjsDefault } = config;
1140
1126
  const [entryFileNames, chunkFileNames] = resolveChunkFilename(config, inputOptions, format);
1141
- const outputOptions = await mergeUserOptions({
1127
+ return await mergeUserOptions({
1142
1128
  format: cjsDts ? "es" : format,
1143
1129
  name: config.globalName,
1144
1130
  sourcemap,
@@ -1152,7 +1138,6 @@ async function resolveOutputOptions(inputOptions, config, format, cjsDts) {
1152
1138
  banner: resolveChunkAddon(banner, format),
1153
1139
  footer: resolveChunkAddon(footer, format)
1154
1140
  }, config.outputOptions, [format, { cjsDts }]);
1155
- return outputOptions;
1156
1141
  }
1157
1142
 
1158
1143
  //#endregion
@@ -209,8 +209,9 @@ interface Options {
209
209
  *
210
210
  * Determines the JavaScript version or runtime(s) for which the code should be compiled.
211
211
  * If not set, defaults to the value of `engines.node` in your project's `package.json`.
212
+ * If no `engines.node` field exists, no syntax transformations are applied.
212
213
  *
213
- * Accepts a single target (e.g., `'es2020'`, `'node18'`) or an array of targets.
214
+ * Accepts a single target (e.g., `'es2020'`, `'node18'`), an array of targets, or `false` to disable all transformations.
214
215
  *
215
216
  * @see {@link https://tsdown.dev/options/target#supported-targets} for a list of valid targets and more details.
216
217
  *
@@ -225,6 +226,12 @@ interface Options {
225
226
  * // Target multiple environments
226
227
  * { "target": ["node18", "es2020"] }
227
228
  * ```
229
+ *
230
+ * @example
231
+ * ```jsonc
232
+ * // Disable all syntax transformations
233
+ * { "target": false }
234
+ * ```
228
235
  */
229
236
  target?: string | string[] | false;
230
237
  /**
@@ -267,9 +274,9 @@ interface Options {
267
274
  */
268
275
  removeNodeProtocol?: boolean;
269
276
  /**
270
- * - If true, add `node:` prefix to built-in modules.
271
- * - If 'strip', strips the `node:` protocol prefix from import source.
272
- * - If false, does not modify the import source.
277
+ * - If `true`, add `node:` prefix to built-in modules.
278
+ * - If `'strip'`, strips the `node:` protocol prefix from import source.
279
+ * - If `false`, does not modify the import source.
273
280
  *
274
281
  * @default false
275
282
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -12,9 +12,10 @@
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/rolldown/tsdown.git"
14
14
  },
15
- "author": "三咲智子 Kevin Deng <sxzz@sxzz.moe>",
15
+ "author": "Kevin Deng <sxzz@sxzz.moe>",
16
16
  "funding": "https://github.com/sponsors/sxzz",
17
17
  "files": [
18
+ "client.d.ts",
18
19
  "dist",
19
20
  "esm-shims.js"
20
21
  ],
@@ -26,7 +27,8 @@
26
27
  "./config": "./dist/config.mjs",
27
28
  "./plugins": "./dist/plugins.mjs",
28
29
  "./run": "./dist/run.mjs",
29
- "./package.json": "./package.json"
30
+ "./package.json": "./package.json",
31
+ "./client": "./client.d.ts"
30
32
  },
31
33
  "typesVersions": {
32
34
  "*": {
@@ -75,10 +77,10 @@
75
77
  "empathic": "^2.0.0",
76
78
  "hookable": "^5.5.3",
77
79
  "rolldown": "latest",
78
- "rolldown-plugin-dts": "^0.15.8",
80
+ "rolldown-plugin-dts": "^0.16.1",
79
81
  "semver": "^7.7.2",
80
82
  "tinyexec": "^1.0.1",
81
- "tinyglobby": "^0.2.14",
83
+ "tinyglobby": "^0.2.15",
82
84
  "tree-kill": "^1.2.2",
83
85
  "unconfig": "^7.3.3"
84
86
  },
@@ -88,19 +90,19 @@
88
90
  "@sxzz/prettier-config": "^2.2.4",
89
91
  "@sxzz/test-utils": "^0.5.10",
90
92
  "@types/debug": "^4.1.12",
91
- "@types/node": "^24.3.0",
92
- "@types/semver": "^7.7.0",
93
- "@unocss/eslint-plugin": "^66.4.2",
94
- "@vueuse/core": "^13.7.0",
93
+ "@types/node": "^24.3.1",
94
+ "@types/semver": "^7.7.1",
95
+ "@unocss/eslint-plugin": "^66.5.1",
96
+ "@vueuse/core": "^13.9.0",
95
97
  "bumpp": "^10.2.3",
96
- "eslint": "^9.34.0",
98
+ "eslint": "^9.35.0",
97
99
  "lightningcss": "^1.30.1",
98
100
  "pkg-types": "^2.3.0",
99
101
  "prettier": "^3.6.2",
100
102
  "publint": "^0.3.12",
101
103
  "tsx": "^4.20.5",
102
104
  "typescript": "~5.9.2",
103
- "unocss": "^66.4.2",
105
+ "unocss": "^66.5.1",
104
106
  "unplugin-lightningcss": "^0.4.2",
105
107
  "unplugin-unused": "^0.5.2",
106
108
  "vite": "npm:rolldown-vite@latest",
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.14.2";
3
-
4
- //#endregion
5
- export { version };