tsdown 0.22.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  import { createRequire as __cjs_createRequire } from "node:module";
2
2
  const __cjs_require = __cjs_createRequire(import.meta.url);
3
- import { a as getPackageType, c as isGlobEntry, d as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, t as mergeConfig, u as cleanChunks } from "./options-DUthngzZ.mjs";
4
- import { r as fsRemove } from "./fs-Dd6Htx2P.mjs";
5
- import { a as pkgExists, l as slash, n as importWithError, o as promiseWithResolvers, t as debounce } from "./general-D3muxt2f.mjs";
6
- import { a as globalLogger, t as LogLevels } from "./logger-uV8l1UFa.mjs";
7
- import { i as getShimsInject, n as DepsPlugin } from "./format-CajNSstg.mjs";
8
- import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, s as copy, t as WatchPlugin } from "./watch-B659_4oi.mjs";
9
- import { t as version } from "./package-Dzmmm_a2.mjs";
3
+ import { a as getPackageType, c as isGlobEntry, d as cleanOutDir, i as loadConfigFile, l as toObjectEntry, n as mergeUserOptions, o as writeExports, r as resolveUserConfig, s as buildExe, t as mergeConfig, u as cleanChunks } from "./options-DWGUHu4D.mjs";
4
+ import { r as fsRemove } from "./fs-qxJxxoCE.mjs";
5
+ import { a as pkgExists, l as slash, n as importWithError, o as promiseWithResolvers, t as debounce, u as toArray } from "./general-Cp4NiJNK.mjs";
6
+ import { a as globalLogger, t as LogLevels } from "./logger-BxuhTmAE.mjs";
7
+ import { a as shimsDefine, i as getShimsInject, n as DepsPlugin, o as shimsPlugin } from "./format-DMceewlS.mjs";
8
+ import { a as ReportPlugin, i as ShebangPlugin, n as endsWithConfig, o as NodeProtocolPlugin, r as addOutDirToChunks, s as copy, t as WatchPlugin } from "./watch-C3ocHLCt.mjs";
9
+ import { n as version } from "./debug-CiHXNOc4.mjs";
10
10
  import { mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
11
11
  import path from "node:path";
12
12
  import process from "node:process";
@@ -340,13 +340,14 @@ async function bundleDone(bundleByPkg, bundle) {
340
340
  }
341
341
  } catch (error) {
342
342
  configs[0].logger.error("Pack failed:", error);
343
+ debug$1("Pack failed for %s: %O", pkg.packageJsonPath, error);
343
344
  }
344
345
  ctx.resolve();
345
346
  }
346
347
  async function packTarball(packageJsonPath) {
347
348
  const pkgDir = path.dirname(packageJsonPath);
348
349
  const destination = await mkdtemp(path.join(tmpdir(), "tsdown-pack-"));
349
- const { detect } = await import("./detect-DN3DXXYt.mjs");
350
+ const { detect } = await import("./detect-B97OSl92.mjs");
350
351
  try {
351
352
  const detected = await detect({ cwd: pkgDir });
352
353
  debug$1("Detected package manager: %o", detected);
@@ -485,7 +486,7 @@ async function getBuildOptions(config, format, configDeps, bundle, cjsDts = fals
485
486
  return rolldownConfig;
486
487
  }
487
488
  async function resolveInputOptions(config, format, configDeps, bundle, cjsDts, isDualFormat) {
488
- const { alias, checks: { legacyCjs, ...checks } = {}, cjsDefault, cwd, deps: { neverBundle }, devtools, dts, entry, env, globImport, loader, logger, nameLabel, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unused, watch } = config;
489
+ const { alias, checks: { legacyCjs, ...checks } = {}, cjsDefault, cwd, deps, devtools, dts, entry, env, globImport, loader, logger, nameLabel, nodeProtocol, platform, plugins: userPlugins, report, shims, target, treeshake, tsconfig, unbundle, unused, watch } = config;
489
490
  const plugins = [];
490
491
  if (nodeProtocol) plugins.push(NodeProtocolPlugin(nodeProtocol));
491
492
  if (config.pkg || config.deps.skipNodeModulesBundle) plugins.push(DepsPlugin(config, bundle));
@@ -526,7 +527,7 @@ async function resolveInputOptions(config, format, configDeps, bundle, cjsDts, i
526
527
  if (watch) plugins.push(WatchPlugin(configDeps, bundle));
527
528
  if (!cjsDts) plugins.push(userPlugins);
528
529
  if (cssPostPlugins) plugins.push(...cssPostPlugins);
529
- const define = {
530
+ let define = {
530
531
  ...config.define,
531
532
  ...Object.keys(env).reduce((acc, key) => {
532
533
  const value = JSON.stringify(env[key]);
@@ -535,11 +536,29 @@ async function resolveInputOptions(config, format, configDeps, bundle, cjsDts, i
535
536
  return acc;
536
537
  }, Object.create(null))
537
538
  };
538
- const inject = shims && !cjsDts ? getShimsInject(format, platform) : void 0;
539
+ let inject;
540
+ if (shims && !cjsDts) if (unbundle) {
541
+ define = {
542
+ ...define,
543
+ ...shimsDefine
544
+ };
545
+ plugins.push(shimsPlugin);
546
+ } else inject = getShimsInject(format, platform);
547
+ const dtsExternal = deps.dts.neverBundle ? functionifyExternal(deps.dts.neverBundle) : void 0;
548
+ let external;
549
+ if (deps.neverBundle && dtsExternal) {
550
+ const jsExternal = functionifyExternal(deps.neverBundle);
551
+ external = (id, importer, ...args) => {
552
+ return ((importer ? RE_DTS.test(importer) : false) ? dtsExternal : jsExternal)(id, importer, ...args);
553
+ };
554
+ } else if (dtsExternal) external = (id, importer, ...args) => {
555
+ return (importer ? RE_DTS.test(importer) : false) ? dtsExternal(id, importer, ...args) : void 0;
556
+ };
557
+ else external = deps.neverBundle;
539
558
  return await mergeUserOptions({
540
559
  input: entry,
541
560
  cwd,
542
- external: neverBundle,
561
+ external,
543
562
  resolve: { alias },
544
563
  tsconfig: tsconfig || void 0,
545
564
  treeshake,
@@ -626,6 +645,13 @@ function CssGuardPlugin() {
626
645
  }
627
646
  };
628
647
  }
648
+ function functionifyExternal(external) {
649
+ if (typeof external === "function") return external;
650
+ external = toArray(external);
651
+ return (id) => {
652
+ return external.some((item) => item instanceof RegExp ? item.test(id) : item === id);
653
+ };
654
+ }
629
655
  //#endregion
630
656
  //#region src/features/shortcuts.ts
631
657
  function shortcuts(restart) {
@@ -1,4 +1,4 @@
1
- import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-CQaSBA5U.mjs";
1
+ import { d as UserConfig, f as UserConfigExport, i as InlineConfig, o as ResolvedConfig, p as UserConfigFn } from "./types-BezgYwPk.mjs";
2
2
 
3
3
  //#region src/config/options.d.ts
4
4
  /**
package/dist/config.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-CQaSBA5U.mjs";
2
- import { n as mergeConfig, t as defineConfig } from "./config-BWeUm0f3.mjs";
3
- export { UserConfig, UserConfigExport, UserConfigFn, defineConfig, mergeConfig };
1
+ import { d as UserConfig, f as UserConfigExport, p as UserConfigFn } from "./types-BezgYwPk.mjs";
2
+ import { n as mergeConfig, t as defineConfig } from "./config-CeytBssC.mjs";
3
+ export { type UserConfig, type UserConfigExport, type UserConfigFn, defineConfig, mergeConfig };
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as mergeConfig } from "./options-DUthngzZ.mjs";
1
+ import { t as mergeConfig } from "./options-DWGUHu4D.mjs";
2
2
  //#region src/config.ts
3
3
  function defineConfig(options) {
4
4
  return options;
@@ -1,5 +1,8 @@
1
- import { s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
1
+ import { s as resolveComma, u as toArray } from "./general-Cp4NiJNK.mjs";
2
2
  import { createDebug, enable, namespaces } from "obug";
3
+ //#region package.json
4
+ var version = "0.22.1";
5
+ //#endregion
3
6
  //#region src/features/debug.ts
4
7
  const debugLog = createDebug("tsdown:debug");
5
8
  function enableDebug(debug) {
@@ -13,4 +16,4 @@ function enableDebug(debug) {
13
16
  debugLog("Debugging enabled", namespace);
14
17
  }
15
18
  //#endregion
16
- export { enableDebug as t };
19
+ export { version as n, enableDebug as t };
@@ -1,4 +1,4 @@
1
- import { c as resolveRegex, l as slash, r as matchPattern, u as toArray } from "./general-D3muxt2f.mjs";
1
+ import { c as resolveRegex, l as slash, r as matchPattern, u as toArray } from "./general-Cp4NiJNK.mjs";
2
2
  import { isBuiltin } from "node:module";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import path from "node:path";
@@ -8,6 +8,20 @@ import { RE_DTS, RE_NODE_MODULES } from "rolldown-plugin-dts/internal";
8
8
  import { and, id, importerId, include } from "rolldown/filter";
9
9
  //#region src/features/shims.ts
10
10
  const shimFile = path.resolve(import.meta.dirname, "..", "esm-shims.js");
11
+ const shimsDefine = {
12
+ __dirname: "__TSDOWN_SHIM_DIRNAME__",
13
+ __filename: "__TSDOWN_SHIM_FILENAME__"
14
+ };
15
+ const shimsPlugin = {
16
+ name: "tsdown:shims-banner",
17
+ banner: `
18
+ import __tsdown_shims_path from 'node:path'
19
+ import __tsdown_shims_url from 'node:url'
20
+
21
+ const __TSDOWN_SHIM_FILENAME__ = /* @__PURE__ */ __tsdown_shims_url.fileURLToPath(import.meta.url)
22
+ const __TSDOWN_SHIM_DIRNAME__ = /* @__PURE__ */ __tsdown_shims_path.dirname(__TSDOWN_SHIM_FILENAME__)
23
+ `
24
+ };
11
25
  function getShimsInject(format, platform) {
12
26
  if (format === "es" && platform === "node") return {
13
27
  __dirname: [shimFile, "__dirname"],
@@ -44,22 +58,26 @@ function resolveDepsConfig(config, logger) {
44
58
  logger?.warn("`skipNodeModulesBundle` is deprecated. Use `deps.skipNodeModulesBundle` instead.");
45
59
  skipNodeModulesBundle = config.skipNodeModulesBundle;
46
60
  }
47
- if (typeof neverBundle === "string") neverBundle = resolveRegex(neverBundle);
48
- if (typeof alwaysBundle === "string") alwaysBundle = resolveRegex(alwaysBundle);
61
+ if (skipNodeModulesBundle && alwaysBundle != null) throw new TypeError("`deps.skipNodeModulesBundle` and `deps.alwaysBundle` are mutually exclusive options and cannot be used together.");
62
+ if (onlyBundle != null && onlyBundle !== false) onlyBundle = toArray(onlyBundle);
63
+ return {
64
+ ...normalizeDepsOptions(alwaysBundle, neverBundle),
65
+ onlyBundle,
66
+ skipNodeModulesBundle,
67
+ dts: normalizeDepsOptions(config.deps?.dts?.alwaysBundle, config.deps?.dts?.neverBundle)
68
+ };
69
+ }
70
+ function normalizeDepsOptions(alwaysBundle, neverBundle) {
49
71
  if (alwaysBundle != null && typeof alwaysBundle !== "function") {
50
72
  const alwaysBundlePatterns = toArray(alwaysBundle);
51
73
  alwaysBundle = (id) => matchPattern(id, alwaysBundlePatterns);
52
74
  }
53
- if (skipNodeModulesBundle && alwaysBundle != null) throw new TypeError("`deps.skipNodeModulesBundle` and `deps.alwaysBundle` are mutually exclusive options and cannot be used together.");
54
- if (onlyBundle != null && onlyBundle !== false) onlyBundle = toArray(onlyBundle);
55
75
  return {
56
- neverBundle,
57
76
  alwaysBundle,
58
- onlyBundle,
59
- skipNodeModulesBundle
77
+ neverBundle: resolveRegex(neverBundle)
60
78
  };
61
79
  }
62
- function DepsPlugin({ pkg, deps: { alwaysBundle, onlyBundle, skipNodeModulesBundle }, logger, nameLabel }, tsdownBundle) {
80
+ function DepsPlugin({ pkg, deps: { alwaysBundle: jsAlwaysBundle, onlyBundle, skipNodeModulesBundle, dts }, logger, nameLabel }, tsdownBundle) {
63
81
  const deps = pkg && Array.from(getProductionDeps(pkg));
64
82
  return {
65
83
  name: "tsdown:deps",
@@ -127,7 +145,7 @@ function DepsPlugin({ pkg, deps: { alwaysBundle, onlyBundle, skipNodeModulesBund
127
145
  */
128
146
  async function externalStrategy(id, importer, resolved) {
129
147
  if (id === shimFile) return false;
130
- if (alwaysBundle?.(id, importer)) return "no-external";
148
+ if (((importer ? RE_DTS.test(importer) : false) && dts?.alwaysBundle || jsAlwaysBundle)?.(id, importer)) return "no-external";
131
149
  if (skipNodeModulesBundle && resolved && (resolved.external || RE_NODE_MODULES.test(resolved.id))) {
132
150
  const resolvedDep = await resolveDepSubpath(id, resolved);
133
151
  return resolvedDep ? [true, resolvedDep] : true;
@@ -213,4 +231,4 @@ function formatBytes(bytes) {
213
231
  return `${(bytes / 1e3).toFixed(2)} kB`;
214
232
  }
215
233
  //#endregion
216
- export { getShimsInject as i, DepsPlugin as n, resolveDepsConfig as r, formatBytes as t };
234
+ export { shimsDefine as a, getShimsInject as i, DepsPlugin as n, shimsPlugin as o, resolveDepsConfig as r, formatBytes as t };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as Arrayable, i as globalLogger, r as Logger } from "./index-CTZ4qxd_.mjs";
2
- import { A as PackageType, B as ResolvedDepsConfig, C as ChunkAddon, D as OutExtensionFactory, E as OutExtensionContext, F as SeaConfig, G as CopyOptionsFn, H as TsdownBundle, I as DevtoolsOptions, L as DepsConfig, M as RolldownContext, N as TsdownHooks, O as OutExtensionObject, P as ExeOptions, S as AttwOptions, T as ChunkAddonObject, U as CopyEntry, V as RolldownChunk, W as CopyOptions, a as NormalizedFormat, b as PublintOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as BuildContext, k as PackageJsonWithPath, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as TsdownPlugin, w as ChunkAddonFunction, x as ExportsOptions, y as TsdownPluginOption, z as NoExternalFn } from "./types-CQaSBA5U.mjs";
3
- import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-BWeUm0f3.mjs";
1
+ import { a as Arrayable, i as globalLogger, r as Logger } from "./index-C0LaRpVv.mjs";
2
+ import { A as PackageType, B as ResolvedDepsConfig, C as ChunkAddon, D as OutExtensionFactory, E as OutExtensionContext, F as SeaConfig, G as CopyOptionsFn, H as TsdownBundle, I as DevtoolsOptions, L as DepsConfig, M as RolldownContext, N as TsdownHooks, O as OutExtensionObject, P as ExeOptions, S as AttwOptions, T as ChunkAddonObject, U as CopyEntry, V as RolldownChunk, W as CopyOptions, a as NormalizedFormat, b as PublintOptions, c as TreeshakingOptions, d as UserConfig, f as UserConfigExport, g as ReportOptions, h as Workspace, i as InlineConfig, j as BuildContext, k as PackageJsonWithPath, l as TsdownInputOption, m as WithEnabled, n as DtsOptions, o as ResolvedConfig, p as UserConfigFn, r as Format, s as Sourcemap, t as CIOption, u as UnusedOptions, v as TsdownPlugin, w as ChunkAddonFunction, x as ExportsOptions, y as TsdownPluginOption, z as NoExternalFn } from "./types-BezgYwPk.mjs";
3
+ import { n as mergeConfig, r as resolveUserConfig, t as defineConfig } from "./config-CeytBssC.mjs";
4
4
  import * as Rolldown from "rolldown";
5
5
 
6
6
  //#region src/build.d.ts
@@ -19,4 +19,4 @@ declare function buildWithConfigs(configs: ResolvedConfig[], configDeps: Set<str
19
19
  //#region src/features/debug.d.ts
20
20
  declare function enableDebug(debug?: boolean | Arrayable<string>): void;
21
21
  //#endregion
22
- export { AttwOptions, BuildContext, CIOption, ChunkAddon, ChunkAddonFunction, ChunkAddonObject, CopyEntry, CopyOptions, CopyOptionsFn, DepsConfig, DevtoolsOptions, DtsOptions, ExeOptions, ExportsOptions, Format, InlineConfig, type Logger, NoExternalFn, NormalizedFormat, OutExtensionContext, OutExtensionFactory, OutExtensionObject, PackageJsonWithPath, PackageType, PublintOptions, ReportOptions, ResolvedConfig, ResolvedDepsConfig, Rolldown, RolldownChunk, RolldownContext, SeaConfig, Sourcemap, TreeshakingOptions, TsdownBundle, TsdownHooks, TsdownInputOption, TsdownPlugin, TsdownPluginOption, UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
22
+ export { type AttwOptions, type BuildContext, CIOption, type ChunkAddon, type ChunkAddonFunction, type ChunkAddonObject, type CopyEntry, type CopyOptions, type CopyOptionsFn, type DepsConfig, type DevtoolsOptions, DtsOptions, type ExeOptions, type ExportsOptions, Format, InlineConfig, type Logger, type NoExternalFn, NormalizedFormat, type OutExtensionContext, type OutExtensionFactory, type OutExtensionObject, type PackageJsonWithPath, type PackageType, type PublintOptions, type ReportOptions, ResolvedConfig, type ResolvedDepsConfig, Rolldown, type RolldownChunk, type RolldownContext, type SeaConfig, Sourcemap, type TreeshakingOptions, type TsdownBundle, type TsdownHooks, TsdownInputOption, type TsdownPlugin, type TsdownPluginOption, type UnusedOptions, UserConfig, UserConfigExport, UserConfigFn, WithEnabled, Workspace, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { n as buildWithConfigs, t as build } from "./build-5FURNVr0.mjs";
2
- import { r as resolveUserConfig, t as mergeConfig } from "./options-DUthngzZ.mjs";
3
- import { a as globalLogger } from "./logger-uV8l1UFa.mjs";
1
+ import { n as buildWithConfigs, t as build } from "./build-BZshaq8i.mjs";
2
+ import { r as resolveUserConfig, t as mergeConfig } from "./options-DWGUHu4D.mjs";
3
+ import { a as globalLogger } from "./logger-BxuhTmAE.mjs";
4
4
  import { defineConfig } from "./config.mjs";
5
- import { t as enableDebug } from "./debug-CLlnG64L.mjs";
5
+ import { t as enableDebug } from "./debug-CiHXNOc4.mjs";
6
6
  import * as Rolldown from "rolldown";
7
7
  export { Rolldown, build, buildWithConfigs, defineConfig, enableDebug, globalLogger, mergeConfig, resolveUserConfig };
@@ -1,4 +1,4 @@
1
- import { c as Overwrite, r as Logger, s as MarkPartial } from "./index-CTZ4qxd_.mjs";
1
+ import { c as Overwrite, r as Logger, s as MarkPartial } from "./index-C0LaRpVv.mjs";
2
2
 
3
3
  //#region src/features/target.d.ts
4
4
  declare function expandBaselineTarget(targets: string[]): string[];
package/dist/internal.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as fsExists, r as fsRemove } from "./fs-Dd6Htx2P.mjs";
2
- import { n as importWithError, s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
3
- import { t as expandBaselineTarget } from "./target-s30wya8e.mjs";
1
+ import { n as fsExists, r as fsRemove } from "./fs-qxJxxoCE.mjs";
2
+ import { n as importWithError, s as resolveComma, u as toArray } from "./general-Cp4NiJNK.mjs";
3
+ import { t as expandBaselineTarget } from "./target-CqeSqtms.mjs";
4
4
  export { expandBaselineTarget, fsExists, fsRemove, importWithError, resolveComma, toArray };
@@ -1,4 +1,4 @@
1
- import { i as noop } from "./general-D3muxt2f.mjs";
1
+ import { i as noop } from "./general-Cp4NiJNK.mjs";
2
2
  import process from "node:process";
3
3
  import { bgRed, bgYellow, blue, green, rgb, yellow } from "ansis";
4
4
  import readline from "node:readline";
@@ -34,11 +34,13 @@ function createLogger(level = "info", options = {}) {
34
34
  console[type === "info" ? "log" : type](msg);
35
35
  }
36
36
  const clear = allowClearScreen && process.stdout.isTTY && !process.env.CI ? clearScreen : () => {};
37
+ const isWindowsTerminal = !!process.env.WT_SESSION;
38
+ const emojiDivier = " ".repeat(isWindowsTerminal ? 2 : 1);
37
39
  const logger = {
38
40
  level,
39
41
  options: resolvedOptions,
40
42
  info(...msgs) {
41
- output("info", `${blue`ℹ`} ${format(msgs)}`);
43
+ output("info", `${blue`ℹ`}${emojiDivier}${format(msgs)}`);
42
44
  },
43
45
  warn(...msgs) {
44
46
  if (failOnWarn) return this.error(...msgs);
@@ -48,8 +50,8 @@ function createLogger(level = "info", options = {}) {
48
50
  },
49
51
  warnOnce(...msgs) {
50
52
  const message = format(msgs);
51
- if (warnedMessages.has(message)) return;
52
53
  if (failOnWarn) return this.error(...msgs);
54
+ if (warnedMessages.has(message)) return;
53
55
  warnedMessages.add(message);
54
56
  output("warn", `\n${bgYellow` WARN `} ${message}\n`);
55
57
  },
@@ -58,7 +60,7 @@ function createLogger(level = "info", options = {}) {
58
60
  process.exitCode = 1;
59
61
  },
60
62
  success(...msgs) {
61
- output("info", `${green`✔`} ${format(msgs)}`);
63
+ output("info", `${green`✔`}${emojiDivier}${format(msgs)}`);
62
64
  },
63
65
  clearScreen(type) {
64
66
  if (LogLevels[logger.level] >= LogLevels[type]) clear();
@@ -1,10 +1,10 @@
1
1
  import { createRequire as __cjs_createRequire } from "node:module";
2
2
  const __cjs_require = __cjs_createRequire(import.meta.url);
3
- import { a as lowestCommonAncestor, i as fsStat, n as fsExists, o as stripExtname, r as fsRemove } from "./fs-Dd6Htx2P.mjs";
4
- import { a as pkgExists, c as resolveRegex, l as slash, n as importWithError, r as matchPattern, s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
5
- import { a as globalLogger, i as getNameLabel, n as createLogger, r as generateColor } from "./logger-uV8l1UFa.mjs";
6
- import { r as resolveDepsConfig, t as formatBytes } from "./format-CajNSstg.mjs";
7
- import { n as resolveTarget } from "./target-s30wya8e.mjs";
3
+ import { a as lowestCommonAncestor, i as fsStat, n as fsExists, o as stripExtname, r as fsRemove } from "./fs-qxJxxoCE.mjs";
4
+ import { a as pkgExists, c as resolveRegex, l as slash, n as importWithError, r as matchPattern, s as resolveComma, u as toArray } from "./general-Cp4NiJNK.mjs";
5
+ import { a as globalLogger, i as getNameLabel, n as createLogger, r as generateColor } from "./logger-BxuhTmAE.mjs";
6
+ import { r as resolveDepsConfig, t as formatBytes } from "./format-DMceewlS.mjs";
7
+ import { n as resolveTarget } from "./target-CqeSqtms.mjs";
8
8
  import { mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";
9
9
  import path from "node:path";
10
10
  import process, { env } from "node:process";
@@ -681,6 +681,7 @@ async function nativeImport(id) {
681
681
  } else if (!isBun) url.searchParams.set("no-cache", crypto.randomUUID());
682
682
  const mod = await depsStore.run(deps, () => import(url.href, { with: importAttributes }).catch((error) => {
683
683
  if (error?.message?.includes?.("Cannot find module")) throw new Error(`Failed to load the config file. Try setting the --config-loader CLI flag to \`tsx\` or \`unrun\`.\n\n${error.message}`, { cause: error });
684
+ if (String(error).includes("not supported in strip-only mode")) throw new Error(`Failed to load the config file because it contains TypeScript-specific syntax that Node.js cannot execute directly. Please set the --config-loader CLI flag to \`tsx\` or \`unrun\`.\n\n${error.message}`, { cause: error });
684
685
  if (typeof error?.stack === "string" && error.stack.includes("node:internal/modules/esm/translators")) throw new Error(`Failed to load the config file due to a known Node.js bug. Try setting the --config-loader CLI flag to \`tsx\` or \`unrun\`, or upgrading Node.js to v24.11.1 or later.\n\n${error.message}`, { cause: error });
685
686
  throw error;
686
687
  }));
@@ -714,7 +715,7 @@ async function resolveUserConfig(userConfig, inlineConfig, configDeps) {
714
715
  if (result) userConfig = mergeConfig(userConfig, result);
715
716
  }
716
717
  }
717
- let { entry, format, plugins = [], clean = true, logLevel = "info", failOnWarn = false, customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, root, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, css, injectStyle, fixedExtension = platform === "node", devtools = false, write = true, exe = false } = userConfig;
718
+ let { entry, format, plugins = [], clean = true, logLevel = "info", failOnWarn = false, customLogger, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch, shims = false, publint = false, attw = false, fromVite, alias, tsconfig, report = true, target, env = {}, envFile, envPrefix = "TSDOWN_", copy, publicDir, hash = true, cwd = process.cwd(), name, workspace, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false, root, removeNodeProtocol, nodeProtocol, cjsDefault = true, globImport = true, css, injectStyle, outExtension, outExtensions, fixedExtension = platform === "node", devtools = false, write = true, exe = false } = userConfig;
718
719
  const pkg = await readPackageJson(cwd);
719
720
  if (workspace) name ||= pkg?.name;
720
721
  const color = generateColor(name);
@@ -766,6 +767,11 @@ async function resolveUserConfig(userConfig, inlineConfig, configDeps) {
766
767
  } else throw new TypeError("`injectStyle` is deprecated. Cannot be used with `css.inject`");
767
768
  if (publicDir) if (copy) throw new TypeError("`publicDir` is deprecated. Cannot be used with `copy`");
768
769
  else logger.warn(`${blue`publicDir`} is deprecated. Use ${blue`copy`} instead.`);
770
+ if (outExtension) {
771
+ if (outExtensions) throw new TypeError("`outExtension` is deprecated. Cannot be used with `outExtensions`");
772
+ logger.warn(`${blue`outExtension`} is deprecated. Use ${blue`outExtensions`} instead.`);
773
+ outExtensions = outExtension;
774
+ }
769
775
  envPrefix = toArray(envPrefix);
770
776
  if (envPrefix.includes("")) logger.warn("`envPrefix` includes an empty string; filtering is disabled. All environment variables from the env file and process.env will be injected into the build. Ensure this is intended to avoid accidental leakage of sensitive information.");
771
777
  const envFromProcess = filterEnv(process.env, envPrefix);
@@ -835,6 +841,7 @@ async function resolveUserConfig(userConfig, inlineConfig, configDeps) {
835
841
  nameLabel,
836
842
  nodeProtocol,
837
843
  outDir,
844
+ outExtensions,
838
845
  pkg,
839
846
  platform,
840
847
  plugins,
@@ -1,5 +1,5 @@
1
- import { r as Logger } from "./index-CTZ4qxd_.mjs";
2
- import { H as TsdownBundle, R as DepsPlugin, _ as ReportPlugin } from "./types-CQaSBA5U.mjs";
1
+ import { r as Logger } from "./index-C0LaRpVv.mjs";
2
+ import { H as TsdownBundle, R as DepsPlugin, _ as ReportPlugin } from "./types-BezgYwPk.mjs";
3
3
  import { Plugin } from "rolldown";
4
4
 
5
5
  //#region src/features/node-protocol.d.ts
package/dist/plugins.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as DepsPlugin } from "./format-CajNSstg.mjs";
2
- import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-B659_4oi.mjs";
1
+ import { n as DepsPlugin } from "./format-DMceewlS.mjs";
2
+ import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, t as WatchPlugin } from "./watch-C3ocHLCt.mjs";
3
3
  export { DepsPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, WatchPlugin };
package/dist/run.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { a as globalLogger } from "./logger-uV8l1UFa.mjs";
3
- import { t as version } from "./package-Dzmmm_a2.mjs";
4
- import { t as enableDebug } from "./debug-CLlnG64L.mjs";
2
+ import { a as globalLogger } from "./logger-BxuhTmAE.mjs";
3
+ import { n as version, t as enableDebug } from "./debug-CiHXNOc4.mjs";
5
4
  import module from "node:module";
6
5
  import process from "node:process";
7
6
  import { blue, hex } from "ansis";
@@ -17,7 +16,7 @@ cli.command("[...files]", "Bundle files", {
17
16
  }).option("-c, --config <filename>", "Use a custom config file").option("--config-loader <loader>", "Config loader to use: auto, native, tsx, unrun", { default: "auto" }).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("--deps.never-bundle <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--devtools", "Enable devtools integration").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("--no-write", "Disable writing files to disk, incompatible with watch mode").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("--env-file <file>", "Load environment variables from a file, when used together with --env, variables in --env take precedence").option("--env-prefix <prefix>", "Prefix for env variables to inject into the bundle", { default: "TSDOWN_" }).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("--root <dir>", "Root directory of input files").option("--exe", "Bundle as executable").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter configs (cwd or name), e.g. /pkg-name$/ or pkg-name").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
18
17
  globalLogger.level = flags.logLevel || "info";
19
18
  globalLogger.info(`${blue`tsdown v${version}`} powered by ${hex("#ff7e17")`rolldown v${VERSION}`}`);
20
- const { build } = await import("./build-5FURNVr0.mjs").then((n) => n.r);
19
+ const { build } = await import("./build-BZshaq8i.mjs").then((n) => n.r);
21
20
  if (input.length > 0) flags.entry = input;
22
21
  await build(flags);
23
22
  });
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __cjs_createRequire } from "node:module";
2
2
  const __cjs_require = __cjs_createRequire(import.meta.url);
3
- import { s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
3
+ import { s as resolveComma, u as toArray } from "./general-Cp4NiJNK.mjs";
4
4
  const minVersion = __cjs_require("semver/ranges/min-version.js");
5
5
  //#region src/features/target.ts
6
6
  const BASELINE_WIDELY_AVAILABLE_TARGET = [
@@ -1,14 +1,11 @@
1
- import { a as Arrayable, c as Overwrite, n as LogLevel, o as Awaitable, r as Logger, s as MarkPartial, t as PackageJson } from "./index-CTZ4qxd_.mjs";
1
+ import { a as Arrayable, c as Overwrite, n as LogLevel, o as Awaitable, r as Logger, s as MarkPartial, t as PackageJson } from "./index-C0LaRpVv.mjs";
2
2
  import { BuildOptions, ChecksOptions, ExternalOption, InputOptions, InternalModuleFormat, MinifyOptions, ModuleFormat, ModuleTypes, OutputAsset, OutputChunk, OutputOptions, Plugin, RolldownPlugin, TreeshakingOptions } from "rolldown";
3
3
  import { Hookable } from "hookable";
4
4
  import { Buffer } from "node:buffer";
5
5
  import { StartOptions } from "@vitejs/devtools/cli-commands";
6
6
  import { ExeExtensionOptions } from "@tsdown/exe";
7
- import * as _$_arethetypeswrong_core0 from "@arethetypeswrong/core";
8
7
  import { CheckPackageOptions } from "@arethetypeswrong/core";
9
- import * as _$publint from "publint";
10
8
  import { Options } from "publint";
11
- import * as _$publint_utils0 from "publint/utils";
12
9
  import { CssOptions } from "@tsdown/css";
13
10
  import { Options as Options$1 } from "rolldown-plugin-dts";
14
11
  import { Options as UnusedOptions } from "unplugin-unused";
@@ -89,19 +86,28 @@ interface DepsConfig {
89
86
  * @default false
90
87
  */
91
88
  skipNodeModulesBundle?: boolean;
89
+ /**
90
+ * Override dependency bundling options for declaration file generation.
91
+ */
92
+ dts?: Pick<DepsConfig, "alwaysBundle" | "neverBundle">;
92
93
  }
93
94
  interface ResolvedDepsConfig {
94
95
  neverBundle?: ExternalOption;
95
96
  alwaysBundle?: NoExternalFn;
96
97
  onlyBundle?: Array<string | RegExp> | false;
97
98
  skipNodeModulesBundle: boolean;
99
+ /**
100
+ * Override dependency bundling options for declaration file generation.
101
+ */
102
+ dts: Pick<ResolvedDepsConfig, "alwaysBundle" | "neverBundle">;
98
103
  }
99
104
  declare function DepsPlugin({
100
105
  pkg,
101
106
  deps: {
102
- alwaysBundle,
107
+ alwaysBundle: jsAlwaysBundle,
103
108
  onlyBundle,
104
- skipNodeModulesBundle
109
+ skipNodeModulesBundle,
110
+ dts
105
111
  },
106
112
  logger,
107
113
  nameLabel
@@ -238,7 +244,7 @@ type ChunkAddon = ChunkAddonObject | ChunkAddonFunction | string;
238
244
  //#endregion
239
245
  //#region src/features/pkg/attw.d.ts
240
246
  interface AttwOptions extends CheckPackageOptions {
241
- module?: typeof _$_arethetypeswrong_core0;
247
+ module?: typeof import("@arethetypeswrong/core");
242
248
  /**
243
249
  * Profiles select a set of resolution modes to require/ignore. All are evaluated but failures outside
244
250
  * of those required are ignored.
@@ -465,7 +471,7 @@ interface ExportsOptions {
465
471
  //#endregion
466
472
  //#region src/features/pkg/publint.d.ts
467
473
  interface PublintOptions extends Omit<Options, "pack" | "pkgDir"> {
468
- module?: [typeof _$publint, typeof _$publint_utils0];
474
+ module?: [typeof import("publint"), typeof import("publint/utils")];
469
475
  }
470
476
  //#endregion
471
477
  //#region src/features/plugin.d.ts
@@ -559,6 +565,13 @@ interface DtsOptions extends Options$1 {
559
565
  *
560
566
  * Only applies when building both `esm` and `cjs` formats simultaneously.
561
567
  *
568
+ * @remarks
569
+ * The generated `.d.cts` stub uses a relative path to re-export from the
570
+ * corresponding `.d.mts` file, so both formats must be emitted to the
571
+ * **same** `outDir`. Splitting CJS and ESM outputs into separate
572
+ * format-specific directories (e.g. `dist/cjs` and `dist/esm`) is not
573
+ * supported with this option, because the re-export path would be invalid.
574
+ *
562
575
  * @default false
563
576
  */
564
577
  cjsReexport?: boolean;
@@ -904,6 +917,10 @@ interface UserConfig {
904
917
  */
905
918
  outExtensions?: OutExtensionFactory;
906
919
  /**
920
+ * @deprecated Use {@linkcode outExtensions} instead.
921
+ */
922
+ outExtension?: OutExtensionFactory;
923
+ /**
907
924
  * If enabled, appends hash to chunk filenames.
908
925
  * @default true
909
926
  */
@@ -1086,7 +1103,7 @@ type UserConfigFn = (inlineConfig: InlineConfig, context: {
1086
1103
  rootConfig?: UserConfig;
1087
1104
  }) => Awaitable<Arrayable<UserConfig>>;
1088
1105
  type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>;
1089
- type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "fromVite" | "publicDir" | "bundle" | "injectStyle" | "removeNodeProtocol" | "external" | "noExternal" | "inlineOnly" | "skipNodeModulesBundle" | "logLevel" | "failOnWarn" | "customLogger" | "envFile" | "envPrefix">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "onSuccess" | "outExtensions" | "hooks" | "copy" | "loader" | "name" | "banner" | "footer" | "checks" | "css">, {
1106
+ type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, "workspace" | "fromVite" | "publicDir" | "bundle" | "injectStyle" | "removeNodeProtocol" | "outExtension" | "external" | "noExternal" | "inlineOnly" | "skipNodeModulesBundle" | "logLevel" | "failOnWarn" | "customLogger" | "envFile" | "envPrefix">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "onSuccess" | "outExtensions" | "hooks" | "copy" | "loader" | "name" | "banner" | "footer" | "checks" | "css">, {
1090
1107
  /**
1091
1108
  * Resolved entry map (after glob expansion)
1092
1109
  */
@@ -1,7 +1,7 @@
1
- import { n as fsExists, t as fsCopy } from "./fs-Dd6Htx2P.mjs";
2
- import { i as noop, s as resolveComma, u as toArray } from "./general-D3muxt2f.mjs";
3
- import { o as prettyFormat } from "./logger-uV8l1UFa.mjs";
4
- import { t as formatBytes } from "./format-CajNSstg.mjs";
1
+ import { n as fsExists, t as fsCopy } from "./fs-qxJxxoCE.mjs";
2
+ import { i as noop, s as resolveComma, u as toArray } from "./general-Cp4NiJNK.mjs";
3
+ import { o as prettyFormat } from "./logger-BxuhTmAE.mjs";
4
+ import { t as formatBytes } from "./format-DMceewlS.mjs";
5
5
  import { builtinModules } from "node:module";
6
6
  import { chmod } from "node:fs/promises";
7
7
  import path from "node:path";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tsdown",
3
3
  "type": "module",
4
- "version": "0.22.0",
4
+ "version": "0.22.1",
5
5
  "description": "The Elegant Bundler for Libraries",
6
6
  "author": "Kevin Deng <sxzz@sxzz.moe>",
7
7
  "license": "MIT",
@@ -54,8 +54,8 @@
54
54
  "typescript": "^5.0.0 || ^6.0.0",
55
55
  "unplugin-unused": "^0.5.0",
56
56
  "unrun": "*",
57
- "@tsdown/css": "0.22.0",
58
- "@tsdown/exe": "0.22.0"
57
+ "@tsdown/exe": "0.22.1",
58
+ "@tsdown/css": "0.22.1"
59
59
  },
60
60
  "peerDependenciesMeta": {
61
61
  "@arethetypeswrong/core": {
@@ -87,17 +87,17 @@
87
87
  }
88
88
  },
89
89
  "dependencies": {
90
- "ansis": "^4.2.0",
90
+ "ansis": "^4.3.0",
91
91
  "cac": "^7.0.0",
92
92
  "defu": "^6.1.7",
93
- "empathic": "^2.0.0",
93
+ "empathic": "^2.0.1",
94
94
  "hookable": "^6.1.1",
95
95
  "import-without-cache": "^0.4.0",
96
96
  "obug": "^2.1.1",
97
97
  "picomatch": "^4.0.4",
98
- "rolldown": "^1.0.0",
99
- "rolldown-plugin-dts": "^0.25.0",
100
- "semver": "^7.7.4",
98
+ "rolldown": "^1.0.2",
99
+ "rolldown-plugin-dts": "^0.25.1",
100
+ "semver": "^7.8.0",
101
101
  "tinyexec": "^1.1.2",
102
102
  "tinyglobby": "^0.2.16",
103
103
  "tree-kill": "^1.2.2",
@@ -110,46 +110,47 @@
110
110
  },
111
111
  "devDependencies": {
112
112
  "@arethetypeswrong/core": "^0.18.2",
113
- "@sxzz/eslint-config": "^8.0.0",
113
+ "@sxzz/eslint-config": "^8.1.0",
114
114
  "@sxzz/prettier-config": "^2.3.1",
115
115
  "@sxzz/test-utils": "^0.5.18",
116
- "@types/node": "^25.6.0",
116
+ "@types/node": "^25.9.1",
117
117
  "@types/picomatch": "^4.0.3",
118
118
  "@types/semver": "^7.7.1",
119
- "@typescript/native-preview": "7.0.0-dev.20260507.1",
120
- "@unocss/eslint-plugin": "^66.6.8",
121
- "@vitejs/devtools": "^0.1.19",
122
- "@vitest/coverage-v8": "^4.1.5",
123
- "@vitest/ui": "^4.1.5",
119
+ "@typescript/native-preview": "7.0.0-dev.20260521.1",
120
+ "@unocss/eslint-plugin": "^66.7.0",
121
+ "@vitejs/devtools": "^0.2.0",
122
+ "@vitest/coverage-v8": "^4.1.7",
123
+ "@vitest/ui": "^4.1.7",
124
124
  "@vueuse/core": "^14.3.0",
125
- "baseline-browser-mapping": "^2.10.27",
125
+ "actionspack": "^0.1.5",
126
+ "baseline-browser-mapping": "^2.10.31",
126
127
  "bumpp": "^11.1.0",
127
128
  "dedent": "^1.7.2",
128
- "eslint": "^10.3.0",
129
+ "eslint": "^10.4.0",
129
130
  "is-in-ci": "^2.0.0",
130
131
  "memfs": "^4.57.2",
131
132
  "package-manager-detector": "^1.6.0",
132
133
  "pkg-types": "^2.3.1",
133
- "postcss": "^8.5.14",
134
+ "postcss": "^8.5.15",
134
135
  "postcss-import": "^16.1.1",
135
136
  "prettier": "^3.8.3",
136
- "publint": "^0.3.19",
137
+ "publint": "^0.3.21",
137
138
  "rolldown-plugin-require-cjs": "^0.4.0",
138
139
  "sass": "^1.99.0",
139
- "tsnapi": "^0.3.2",
140
- "tsx": "^4.21.0",
140
+ "tsnapi": "^0.3.3",
141
+ "tsx": "^4.22.3",
141
142
  "typescript": "~6.0.3",
142
- "unocss": "^66.6.8",
143
+ "unocss": "^66.7.0",
143
144
  "unplugin-ast": "^0.17.0",
144
145
  "unplugin-raw": "^0.7.0",
145
146
  "unplugin-unused": "^0.5.7",
146
147
  "unplugin-vue": "^7.2.0",
147
- "unrun": "^0.2.37",
148
- "vite": "^8.0.11",
149
- "vitest": "^4.1.5",
148
+ "unrun": "^0.3.0",
149
+ "vite": "^8.0.14",
150
+ "vitest": "^4.1.7",
150
151
  "vue": "^3.5.34",
151
- "@tsdown/css": "0.22.0",
152
- "@tsdown/exe": "0.22.0"
152
+ "@tsdown/css": "0.22.1",
153
+ "@tsdown/exe": "0.22.1"
153
154
  },
154
155
  "prettier": "@sxzz/prettier-config",
155
156
  "scripts": {
@@ -1,4 +0,0 @@
1
- //#region package.json
2
- var version = "0.22.0";
3
- //#endregion
4
- export { version as t };
File without changes