tsdown 0.12.7 → 0.12.8

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.
@@ -13,6 +13,40 @@ type Awaitable<T> = T | Promise<T>;
13
13
  type MarkPartial<T, K extends keyof T> = Omit<Required<T>, K> & Partial<Pick<T, K>>;
14
14
  type Arrayable<T> = T | T[];
15
15
  //#endregion
16
+ //#region src/features/attw.d.ts
17
+ interface AttwOptions extends CheckPackageOptions {
18
+ /**
19
+ * Profiles select a set of resolution modes to require/ignore. All are evaluated but failures outside
20
+ * of those required are ignored.
21
+ *
22
+ * The available profiles are:
23
+ * - `strict`: requires all resolutions
24
+ * - `node16`: ignores node10 resolution failures
25
+ * - `esmOnly`: ignores CJS resolution failures
26
+ *
27
+ * @default 'strict'
28
+ */
29
+ profile?: "strict" | "node16" | "esmOnly";
30
+ /**
31
+ * The level of the check.
32
+ *
33
+ * The available levels are:
34
+ * - `error`: fails the build
35
+ * - `warn`: warns the build
36
+ *
37
+ * @default 'warn'
38
+ */
39
+ level?: "error" | "warn";
40
+ }
41
+ //#endregion
42
+ //#region src/features/copy.d.ts
43
+ interface CopyEntry {
44
+ from: string;
45
+ to: string;
46
+ }
47
+ type CopyOptions = Arrayable<string | CopyEntry>;
48
+ type CopyOptionsFn = (options: ResolvedOptions) => Awaitable<CopyOptions>;
49
+ //#endregion
16
50
  //#region src/utils/logger.d.ts
17
51
  declare class Logger {
18
52
  silent: boolean;
@@ -72,13 +106,25 @@ type TsdownChunks = Partial<Record<NormalizedFormat, Array<OutputChunk | OutputA
72
106
  */
73
107
  declare function buildSingle(config: ResolvedOptions, clean: () => Promise<void>): Promise<(() => Promise<void>) | undefined>;
74
108
  //#endregion
75
- //#region src/features/copy.d.ts
76
- interface CopyEntry {
77
- from: string;
78
- to: string;
109
+ //#region src/features/exports.d.ts
110
+ interface ExportsOptions {
111
+ /**
112
+ * Generate exports that link to source code during development.
113
+ * - string: add as a custom condition.
114
+ * - true: all conditions point to source files, and add dist exports to `publishConfig`.
115
+ */
116
+ devExports?: boolean | string;
117
+ /**
118
+ * Exports for all files.
119
+ */
120
+ all?: boolean;
121
+ customExports?: (exports: Record<string, any>, context: {
122
+ pkg: PackageJson;
123
+ chunks: TsdownChunks;
124
+ outDir: string;
125
+ isPublish: boolean;
126
+ }) => Awaitable<Record<string, any>>;
79
127
  }
80
- type CopyOptions = Arrayable<string | CopyEntry>;
81
- type CopyOptionsFn = (options: ResolvedOptions) => Awaitable<CopyOptions>;
82
128
  //#endregion
83
129
  //#region src/utils/package.d.ts
84
130
  type PackageType = "module" | "commonjs" | undefined;
@@ -135,24 +181,6 @@ interface Workspace {
135
181
  */
136
182
  config?: boolean | string;
137
183
  }
138
- interface ExportsOptions {
139
- /**
140
- * Generate exports that link to source code during development.
141
- * - string: add as a custom condition.
142
- * - true: all conditions point to source files, and add dist exports to `publishConfig`.
143
- */
144
- devExports?: boolean | string;
145
- /**
146
- * Exports for all files.
147
- */
148
- all?: boolean;
149
- customExports?: (exports: Record<string, any>, context: {
150
- pkg: PackageJson;
151
- chunks: TsdownChunks;
152
- outDir: string;
153
- isPublish: boolean;
154
- }) => Awaitable<Record<string, any>>;
155
- }
156
184
  /**
157
185
  * Options for tsdown.
158
186
  */
@@ -225,6 +253,11 @@ interface Options$3 {
225
253
  * @default false
226
254
  */
227
255
  unbundle?: boolean;
256
+ /**
257
+ * @deprecated Use `unbundle` instead.
258
+ * @default true
259
+ */
260
+ bundle?: boolean;
228
261
  define?: Record<string, string>;
229
262
  /** @default false */
230
263
  shims?: boolean;
@@ -310,7 +343,7 @@ interface Options$3 {
310
343
  * @default false
311
344
  * @see https://github.com/arethetypeswrong/arethetypeswrong.github.io
312
345
  */
313
- attw?: boolean | CheckPackageOptions;
346
+ attw?: boolean | AttwOptions;
314
347
  /**
315
348
  * Enable size reporting after bundling.
316
349
  * @default true
@@ -386,7 +419,7 @@ interface Options$3 {
386
419
  */
387
420
  type UserConfig = Arrayable<Omit<Options$3, "config" | "filter">>;
388
421
  type UserConfigFn = (cliOptions: Options$3) => Awaitable<UserConfig>;
389
- type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" | "workspace" | "filter">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name" | "unbundle">, {
422
+ type ResolvedOptions = Omit<Overwrite<MarkPartial<Omit<Options$3, "publicDir" | "workspace" | "filter">, "globalName" | "inputOptions" | "outputOptions" | "minify" | "define" | "alias" | "external" | "noExternal" | "onSuccess" | "fixedExtension" | "outExtensions" | "hooks" | "removeNodeProtocol" | "copy" | "loader" | "name" | "bundle">, {
390
423
  format: NormalizedFormat[];
391
424
  target?: string[];
392
425
  clean: string[];
package/dist/config.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { UserConfig, UserConfigFn, defineConfig } from "./config-BJDUww56.mjs";
1
+ import { UserConfig, UserConfigFn, defineConfig } from "./config-D_2fTM9-.mjs";
2
2
  export { UserConfig, UserConfigFn, defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { BuildContext, Options, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot } from "./config-BJDUww56.mjs";
2
- export { BuildContext, Options, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot };
1
+ import { BuildContext, Options, ResolvedOptions, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot } from "./config-D_2fTM9-.mjs";
2
+ export { BuildContext, Options, ResolvedOptions, TsdownChunks, TsdownHooks, UserConfig, UserConfigFn, build, buildSingle, defineConfig, logger, pkgRoot };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineConfig } from "./config-CzjtjH-U.mjs";
2
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsExists, fsRemove, fsStat, lowestCommonAncestor } from "./plugins-BmNEEFYs.mjs";
2
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin, fsCopy, fsExists, fsRemove, fsStat, lowestCommonAncestor } from "./plugins-qNZNAFcS.mjs";
3
3
  import { debounce, generateColor, logger, prettyName, resolveComma, resolveRegex, slash, toArray } from "./logger-CdK2zFTY.mjs";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
@@ -24,12 +24,50 @@ import { loadConfig } from "unconfig";
24
24
  //#region src/features/attw.ts
25
25
  const debug$5 = debug("tsdown:attw");
26
26
  const exec$1 = promisify(child_process.exec);
27
+ /**
28
+ * ATTW profiles.
29
+ * Defines the resolution modes to ignore for each profile.
30
+ *
31
+ * @see https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/packages/cli/README.md#profiles
32
+ */
33
+ const profiles = {
34
+ strict: [],
35
+ node16: ["node10"],
36
+ esmOnly: ["node10", "node16-cjs"]
37
+ };
38
+ /**
39
+ * Format an ATTW problem for display
40
+ */
41
+ function formatProblem(problem) {
42
+ const resolutionKind = "resolutionKind" in problem ? ` (${problem.resolutionKind})` : "";
43
+ const entrypoint = "entrypoint" in problem ? ` at ${problem.entrypoint}` : "";
44
+ switch (problem.kind) {
45
+ case "NoResolution": return ` ❌ No resolution${resolutionKind}${entrypoint}`;
46
+ case "UntypedResolution": return ` ⚠️ Untyped resolution${resolutionKind}${entrypoint}`;
47
+ case "FalseESM": return ` 🔄 False ESM: Types indicate ESM (${problem.typesModuleKind}) but implementation is CJS (${problem.implementationModuleKind})\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
48
+ case "FalseCJS": return ` 🔄 False CJS: Types indicate CJS (${problem.typesModuleKind}) but implementation is ESM (${problem.implementationModuleKind})\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
49
+ case "CJSResolvesToESM": return ` ⚡ CJS resolves to ESM${resolutionKind}${entrypoint}`;
50
+ case "NamedExports": {
51
+ const missingExports = problem.missing?.length > 0 ? ` Missing: ${problem.missing.join(", ")}` : "";
52
+ const allMissing = problem.isMissingAllNamed ? " (all named exports missing)" : "";
53
+ return ` 📤 Named exports problem${allMissing}${missingExports}\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
54
+ }
55
+ case "FallbackCondition": return ` 🎯 Fallback condition used${resolutionKind}${entrypoint}`;
56
+ case "FalseExportDefault": return ` 🎭 False export default\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
57
+ case "MissingExportEquals": return ` 📝 Missing export equals\n Types: ${problem.typesFileName} | Implementation: ${problem.implementationFileName}`;
58
+ case "InternalResolutionError": return ` 💥 Internal resolution error in ${problem.fileName} (${problem.resolutionOption})\n Module: ${problem.moduleSpecifier} | Mode: ${problem.resolutionMode}`;
59
+ case "UnexpectedModuleSyntax": return ` 📋 Unexpected module syntax in ${problem.fileName}\n Expected: ${problem.moduleKind} | Found: ${problem.syntax === 99 ? "ESM" : "CJS"}`;
60
+ case "CJSOnlyExportsDefault": return ` 🏷️ CJS only exports default in ${problem.fileName}`;
61
+ default: return ` ❓ Unknown problem: ${JSON.stringify(problem)}`;
62
+ }
63
+ }
27
64
  async function attw(options) {
28
65
  if (!options.attw) return;
29
66
  if (!options.pkg) {
30
67
  logger.warn("attw is enabled but package.json is not found");
31
68
  return;
32
69
  }
70
+ const { profile = "strict", level = "warn",...attwOptions } = options.attw === true ? {} : options.attw;
33
71
  const t = performance.now();
34
72
  debug$5("Running attw check");
35
73
  const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
@@ -41,15 +79,28 @@ async function attw(options) {
41
79
  return;
42
80
  }
43
81
  try {
44
- const { stdout: tarballInfo } = await exec$1(`npm pack --json ----pack-destination ${tempDir}`, { encoding: "utf-8" });
82
+ const { stdout: tarballInfo } = await exec$1(`npm pack --json ----pack-destination ${tempDir}`, {
83
+ encoding: "utf8",
84
+ cwd: options.cwd
85
+ });
45
86
  const parsed = JSON.parse(tarballInfo);
46
87
  if (!Array.isArray(parsed) || !parsed[0]?.filename) throw new Error("Invalid npm pack output format");
47
88
  const tarballPath = path.join(tempDir, parsed[0].filename);
48
89
  const tarball = await readFile(tarballPath);
49
90
  const pkg = attwCore.createPackageFromTarballData(tarball);
50
- const checkResult = await attwCore.checkPackage(pkg, options.attw === true ? {} : options.attw);
51
- if (checkResult.types !== false && checkResult.problems) for (const problem of checkResult.problems) logger.warn("Are the types wrong problem:", problem);
52
- else logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
91
+ const checkResult = await attwCore.checkPackage(pkg, attwOptions);
92
+ if (checkResult.types !== false && checkResult.problems) {
93
+ const problems = checkResult.problems.filter((problem) => {
94
+ if ("resolutionKind" in problem) return !profiles[profile]?.includes(problem.resolutionKind);
95
+ return true;
96
+ });
97
+ if (problems.length) {
98
+ const problemList = problems.map(formatProblem).join("\n");
99
+ const problemMessage = `Are the types wrong problems found:\n${problemList}`;
100
+ if (level === "error") throw new Error(problemMessage);
101
+ logger.warn(problemMessage);
102
+ }
103
+ } else logger.success(`No Are the types wrong problems found`, dim`(${Math.round(performance.now() - t)}ms)`);
53
104
  } catch (error) {
54
105
  logger.error("ATTW check failed:", error);
55
106
  debug$5("Found errors, setting exit code to 1");
@@ -751,7 +802,8 @@ async function resolveWorkspace(config, options) {
751
802
  };
752
803
  }
753
804
  async function resolveConfig(userConfig) {
754
- let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch = [], shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false } = userConfig;
805
+ let { entry, format = ["es"], plugins = [], clean = true, silent = false, treeshake = true, platform = "node", outDir = "dist", sourcemap = false, dts, unused = false, watch = false, ignoreWatch = [], shims = false, skipNodeModulesBundle = false, publint: publint$1 = false, attw: attw$1 = false, fromVite, alias, tsconfig, report = true, target, env = {}, copy: copy$1, publicDir, hash, cwd = process.cwd(), name, workspace, external, noExternal, exports = false, bundle, unbundle = typeof bundle === "boolean" ? !bundle : false } = userConfig;
806
+ if (typeof bundle === "boolean") logger.warn("`bundle` option is deprecated. Use `unbundle` instead.");
755
807
  outDir = path.resolve(cwd, outDir);
756
808
  clean = resolveClean(clean, outDir, cwd);
757
809
  const pkg = await readPackageJson(cwd);
@@ -807,7 +859,8 @@ async function resolveConfig(userConfig) {
807
859
  name,
808
860
  external,
809
861
  noExternal,
810
- exports
862
+ exports,
863
+ unbundle
811
864
  };
812
865
  return config;
813
866
  }
@@ -1,5 +1,5 @@
1
1
  import { logger } from "./logger-CdK2zFTY.mjs";
2
- import { version } from "./package-ZDuXNobF.mjs";
2
+ import { version } from "./package-DRxdhN87.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.12.8";
3
+
4
+ //#endregion
5
+ export { version };
@@ -1,5 +1,5 @@
1
1
  import { logger, noop, prettyFormat, prettyName, toArray } from "./logger-CdK2zFTY.mjs";
2
- import { isBuiltin } from "node:module";
2
+ import { builtinModules } from "node:module";
3
3
  import path, { dirname, normalize, sep } from "node:path";
4
4
  import { bold, dim, green, underline } from "ansis";
5
5
  import { access, chmod, cp, rm, stat } from "node:fs/promises";
@@ -61,7 +61,11 @@ function ExternalPlugin(options) {
61
61
  if (noExternal) {
62
62
  const noExternalPatterns = toArray(noExternal);
63
63
  if (noExternalPatterns.some((pattern) => {
64
- return pattern instanceof RegExp ? pattern.test(id) : id === pattern;
64
+ if (pattern instanceof RegExp) {
65
+ pattern.lastIndex = 0;
66
+ return pattern.test(id);
67
+ }
68
+ return id === pattern;
65
69
  })) return;
66
70
  }
67
71
  let shouldExternal = false;
@@ -76,7 +80,7 @@ function ExternalPlugin(options) {
76
80
  return {
77
81
  id,
78
82
  external: shouldExternal,
79
- moduleSideEffects: id.startsWith("node:") || isBuiltin(id) ? false : void 0
83
+ moduleSideEffects: id.startsWith("node:") || builtinModules.includes(id) ? false : void 0
80
84
  };
81
85
  }
82
86
  }
@@ -1,4 +1,4 @@
1
- import { ReportPlugin, ResolvedOptions } from "./config-BJDUww56.mjs";
1
+ import { ReportPlugin, ResolvedOptions } from "./config-D_2fTM9-.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
  import { PackageJson } from "pkg-types";
4
4
 
package/dist/plugins.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-BmNEEFYs.mjs";
1
+ import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./plugins-qNZNAFcS.mjs";
2
2
  import "./logger-CdK2zFTY.mjs";
3
3
 
4
4
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
package/dist/run.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { logger, resolveComma, toArray } from "./logger-CdK2zFTY.mjs";
3
- import { version } from "./package-ZDuXNobF.mjs";
3
+ import { version } from "./package-DRxdhN87.mjs";
4
4
  import module from "node:module";
5
5
  import process from "node:process";
6
6
  import { dim } from "ansis";
@@ -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-CMJIC73T.mjs");
25
+ const { migrate } = await import("./migrate-D3HAtePC.mjs");
26
26
  await migrate(args);
27
27
  });
28
28
  async function runCLI() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.12.7",
3
+ "version": "0.12.8",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -74,23 +74,23 @@
74
74
  "diff": "^8.0.2",
75
75
  "empathic": "^1.1.0",
76
76
  "hookable": "^5.5.3",
77
- "rolldown": "1.0.0-beta.11-commit.f051675",
78
- "rolldown-plugin-dts": "^0.13.8",
77
+ "rolldown": "1.0.0-beta.15",
78
+ "rolldown-plugin-dts": "^0.13.11",
79
79
  "semver": "^7.7.2",
80
80
  "tinyexec": "^1.0.1",
81
81
  "tinyglobby": "^0.2.14",
82
82
  "unconfig": "^7.3.2"
83
83
  },
84
84
  "devDependencies": {
85
- "@arethetypeswrong/core": "^0.18.1",
86
- "@oxc-node/core": "^0.0.27",
85
+ "@arethetypeswrong/core": "^0.18.2",
86
+ "@oxc-node/core": "^0.0.28",
87
87
  "@sxzz/eslint-config": "^7.0.2",
88
88
  "@sxzz/prettier-config": "^2.2.1",
89
89
  "@sxzz/test-utils": "^0.5.6",
90
90
  "@types/debug": "^4.1.12",
91
- "@types/node": "^22.15.29",
91
+ "@types/node": "^24.0.1",
92
92
  "@types/semver": "^7.7.0",
93
- "@unocss/eslint-plugin": "^66.1.3",
93
+ "@unocss/eslint-plugin": "^66.2.0",
94
94
  "@vueuse/core": "^13.3.0",
95
95
  "bumpp": "^10.1.1",
96
96
  "eslint": "^9.28.0",
@@ -101,14 +101,14 @@
101
101
  "typedoc": "^0.28.5",
102
102
  "typedoc-plugin-markdown": "^4.6.4",
103
103
  "typescript": "~5.8.3",
104
- "unocss": "^66.1.3",
104
+ "unocss": "^66.2.0",
105
105
  "unplugin-lightningcss": "^0.4.1",
106
- "unplugin-unused": "^0.5.0",
106
+ "unplugin-unused": "^0.5.1",
107
107
  "vite": "npm:rolldown-vite@latest",
108
108
  "vitepress": "^1.6.3",
109
109
  "vitepress-plugin-group-icons": "^1.6.0",
110
- "vitepress-plugin-llms": "^1.3.4",
111
- "vitest": "^3.2.1",
110
+ "vitepress-plugin-llms": "^1.5.0",
111
+ "vitest": "^3.2.3",
112
112
  "vue": "^3.5.16"
113
113
  },
114
114
  "engines": {
@@ -1,5 +0,0 @@
1
- //#region package.json
2
- var version = "0.12.7";
3
-
4
- //#endregion
5
- export { version };