tsdown 0.17.0-beta.1 → 0.17.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-BrlHanBo.mjs";
1
+ import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-C9klZ7SZ.mjs";
2
2
 
3
3
  //#region src/config.d.ts
4
4
 
package/dist/config.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-BrlHanBo.mjs";
2
- import { t as defineConfig } from "./config-CSoQwDij.mjs";
1
+ import { f as UserConfig, m as UserConfigFn, p as UserConfigExport } from "./index-C9klZ7SZ.mjs";
2
+ import { t as defineConfig } from "./config-LvwttpKK.mjs";
3
3
  export { UserConfig, UserConfigExport, UserConfigFn, defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as TsdownHooks, C as ChunkAddonObject, D as PackageType, E as OutExtensionObject, F as CopyOptions, I as CopyOptionsFn, L as AttwOptions, M as TsdownChunks, N as DebugOptions, O as BuildContext, P as CopyEntry, S as ChunkAddonFunction, T as OutExtensionFactory, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as ResolvedConfig, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as ExportsOptions, k as RolldownContext, l as Sourcemap, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as PublintOptions, t as CIOption, u as TreeshakingOptions, w as OutExtensionContext, x as ChunkAddon, y as Logger } from "./index-BrlHanBo.mjs";
2
- import { t as defineConfig } from "./config-CSoQwDij.mjs";
1
+ import { A as TsdownHooks, C as ChunkAddonObject, D as PackageType, E as OutExtensionObject, F as CopyOptions, I as CopyOptionsFn, L as AttwOptions, M as TsdownChunks, N as DebugOptions, O as BuildContext, P as CopyEntry, S as ChunkAddonFunction, T as OutExtensionFactory, _ as ReportOptions, a as NoExternalFn, b as globalLogger, c as ResolvedConfig, d as UnusedOptions, f as UserConfig, g as Workspace, h as WithEnabled, i as InlineConfig, j as ExportsOptions, k as RolldownContext, l as Sourcemap, m as UserConfigFn, n as DtsOptions, o as NormalizedFormat, p as UserConfigExport, r as Format, s as PublintOptions, t as CIOption, u as TreeshakingOptions, w as OutExtensionContext, x as ChunkAddon, y as Logger } from "./index-C9klZ7SZ.mjs";
2
+ import { t as defineConfig } from "./config-LvwttpKK.mjs";
3
3
 
4
4
  //#region src/index.d.ts
5
5
  interface TsdownBundle extends AsyncDisposable {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as defineConfig } from "./config-DLSWqKoz.mjs";
2
- import { n as buildSingle, r as shimFile, t as build } from "./src-hEE2DSx9.mjs";
3
- import { a as globalLogger } from "./package-r6WmI0kC.mjs";
2
+ import { n as buildSingle, r as shimFile, t as build } from "./src-Cky32-M_.mjs";
3
+ import { a as globalLogger } from "./package-CMsW8X66.mjs";
4
4
 
5
5
  export { build, buildSingle, defineConfig, globalLogger, shimFile };
@@ -150,7 +150,7 @@ function hue2rgb(p, q, t) {
150
150
 
151
151
  //#endregion
152
152
  //#region package.json
153
- var version = "0.17.0-beta.1";
153
+ var version = "0.17.0-beta.2";
154
154
 
155
155
  //#endregion
156
156
  export { globalLogger as a, importWithError as c, pkgExists as d, resolveComma as f, toArray as h, generateColor as i, matchPattern as l, slash as m, LogLevels as n, prettyFormat as o, resolveRegex as p, createLogger as r, prettyName as s, version as t, noop as u };
@@ -1,4 +1,4 @@
1
- import { c as ResolvedConfig, v as ReportPlugin, y as Logger } from "./index-BrlHanBo.mjs";
1
+ import { c as ResolvedConfig, v as ReportPlugin, y as Logger } from "./index-C9klZ7SZ.mjs";
2
2
  import { Plugin } from "rolldown";
3
3
 
4
4
  //#region src/features/external.d.ts
package/dist/plugins.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./config-DLSWqKoz.mjs";
2
- import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, s as ExternalPlugin } from "./src-hEE2DSx9.mjs";
3
- import "./package-r6WmI0kC.mjs";
2
+ import { a as ReportPlugin, i as ShebangPlugin, o as NodeProtocolPlugin, s as ExternalPlugin } from "./src-Cky32-M_.mjs";
3
+ import "./package-CMsW8X66.mjs";
4
4
 
5
5
  export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
package/dist/run.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { a as globalLogger, f as resolveComma, h as toArray, t as version } from "./package-r6WmI0kC.mjs";
2
+ import { a as globalLogger, f as resolveComma, h as toArray, t as version } from "./package-CMsW8X66.mjs";
3
3
  import module from "node:module";
4
4
  import { dim } from "ansis";
5
5
  import { VERSION } from "rolldown";
6
6
  import process from "node:process";
7
7
  import { createDebug, enable, namespaces } from "obug";
8
+ import { x } from "tinyexec";
8
9
  import { cac } from "cac";
9
10
 
10
11
  //#region src/features/debug.ts
@@ -35,9 +36,23 @@ cli.command("[...files]", "Bundle files", {
35
36
  if (input.length > 0) flags.entry = input;
36
37
  await build$1(flags);
37
38
  });
38
- cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
39
- const { migrate } = await import("./migrate-CcVRf9lh.mjs");
40
- await migrate(args);
39
+ cli.command("create", "[deprecated] Create a tsdown project. Use \"npx create-tsdown\" instead.", { allowUnknownOptions: true }).action(async () => {
40
+ globalLogger.warn(`"tsdown create" is deprecated. Please use "npx create-tsdown" instead.`);
41
+ const { exitCode } = await x("npx", [
42
+ "-y",
43
+ "create-tsdown@latest",
44
+ ...process.argv.slice(3)
45
+ ], { nodeOptions: { stdio: "inherit" } });
46
+ process.exitCode = exitCode;
47
+ });
48
+ cli.command("migrate", "[deprecated] Migrate from tsup to tsdown. Use \"npx tsdown-migrate\" instead.", { allowUnknownOptions: true }).action(async () => {
49
+ globalLogger.warn(`"tsdown migrate" is deprecated. Please use "npx tsdown-migrate" instead.`);
50
+ const { exitCode } = await x("npx", [
51
+ "-y",
52
+ "tsdown-migrate@latest",
53
+ ...process.argv.slice(3)
54
+ ], { nodeOptions: { stdio: "inherit" } });
55
+ process.exitCode = exitCode;
41
56
  });
42
57
  async function runCLI() {
43
58
  cli.parse(process.argv, { run: false });
@@ -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 { a as globalLogger, c as importWithError, d as pkgExists, f as resolveComma, h as toArray, i as generateColor, l as matchPattern, m as slash, n as LogLevels, o as prettyFormat, p as resolveRegex, r as createLogger, s as prettyName, t as version, u as noop } from "./package-r6WmI0kC.mjs";
3
+ import { a as globalLogger, c as importWithError, d as pkgExists, f as resolveComma, h as toArray, i as generateColor, l as matchPattern, m as slash, n as LogLevels, o as prettyFormat, p as resolveRegex, r as createLogger, s as prettyName, t as version, u as noop } from "./package-CMsW8X66.mjs";
4
4
  import { builtinModules, isBuiltin } from "node:module";
5
5
  import path, { dirname, join, normalize, sep } from "node:path";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
@@ -274,6 +274,23 @@ async function toObjectEntry(entry, cwd) {
274
274
  }));
275
275
  }
276
276
 
277
+ //#endregion
278
+ //#region src/utils/format.ts
279
+ function formatBytes(bytes) {
280
+ if (bytes === Infinity) return void 0;
281
+ return `${(bytes / 1e3).toFixed(2)} kB`;
282
+ }
283
+ function detectIndentation(jsonText) {
284
+ const lines = jsonText.split(/\r?\n/);
285
+ for (const line of lines) {
286
+ const match = line.match(/^(\s+)\S/);
287
+ if (!match) continue;
288
+ if (match[1].includes(" ")) return " ";
289
+ return match[1].length;
290
+ }
291
+ return 2;
292
+ }
293
+
277
294
  //#endregion
278
295
  //#region src/features/exports.ts
279
296
  async function writeExports(options, chunks) {
@@ -291,20 +308,10 @@ async function writeExports(options, chunks) {
291
308
  updatedPkg.publishConfig.exports = publishExports;
292
309
  }
293
310
  const original = await readFile(pkg.packageJsonPath, "utf8");
294
- let contents = JSON.stringify(updatedPkg, null, detectIndent(original));
311
+ let contents = JSON.stringify(updatedPkg, null, detectIndentation(original));
295
312
  if (original.endsWith("\n")) contents += "\n";
296
313
  if (contents !== original) await writeFile(pkg.packageJsonPath, contents, "utf8");
297
314
  }
298
- function detectIndent(jsonText) {
299
- const lines = jsonText.split(/\r?\n/);
300
- for (const line of lines) {
301
- const match = line.match(/^(\s+)\S/);
302
- if (!match) continue;
303
- if (match[1].includes(" ")) return " ";
304
- return match[1].length;
305
- }
306
- return 2;
307
- }
308
315
  async function generateExports(pkg, outDir, chunks, { devExports, all, customExports }) {
309
316
  const pkgJsonPath = pkg.packageJsonPath;
310
317
  const pkgRoot$1 = path.dirname(pkgJsonPath);
@@ -704,11 +711,7 @@ async function attw(options) {
704
711
  options.logger.warn("attw is enabled but package.json is not found");
705
712
  return;
706
713
  }
707
- let { profile = "strict", level = "warn", ...attwOptions } = options.attw;
708
- if (profile === "esmOnly") {
709
- options.logger.warn("attw option \"esmOnly\" is deprecated, use \"esm-only\" instead");
710
- profile = "esm-only";
711
- }
714
+ const { profile = "strict", level = "warn", ...attwOptions } = options.attw;
712
715
  const t = performance.now();
713
716
  debug$4("Running attw check");
714
717
  const tempDir = await mkdtemp(path.join(tmpdir(), "tsdown-attw-"));
@@ -1066,13 +1069,6 @@ function resolveChunkAddon(chunkAddon, format, dts) {
1066
1069
  };
1067
1070
  }
1068
1071
 
1069
- //#endregion
1070
- //#region src/utils/format.ts
1071
- function formatBytes(bytes) {
1072
- if (bytes === Infinity) return void 0;
1073
- return `${(bytes / 1e3).toFixed(2)} kB`;
1074
- }
1075
-
1076
1072
  //#endregion
1077
1073
  //#region src/features/report.ts
1078
1074
  const debug$1 = createDebug("tsdown:report");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsdown",
3
- "version": "0.17.0-beta.1",
3
+ "version": "0.17.0-beta.2",
4
4
  "description": "The Elegant Bundler for Libraries",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -75,7 +75,6 @@
75
75
  "dependencies": {
76
76
  "ansis": "^4.2.0",
77
77
  "cac": "^6.7.14",
78
- "diff": "^8.0.2",
79
78
  "empathic": "^2.0.0",
80
79
  "hookable": "^5.5.3",
81
80
  "obug": "^2.1.1",
@@ -97,6 +96,7 @@
97
96
  "@types/semver": "^7.7.1",
98
97
  "@unocss/eslint-plugin": "^66.5.9",
99
98
  "@vitejs/devtools": "^0.0.0-alpha.18",
99
+ "@vitest/coverage-v8": "4.0.14",
100
100
  "@vueuse/core": "^14.1.0",
101
101
  "bumpp": "^10.3.2",
102
102
  "eslint": "^9.39.1",
@@ -1,118 +0,0 @@
1
- import { a as globalLogger, t as version } from "./package-r6WmI0kC.mjs";
2
- import { bold, green, underline } from "ansis";
3
- import { readFile, unlink, writeFile } from "node:fs/promises";
4
- import process from "node:process";
5
- import { existsSync } from "node:fs";
6
- import { createInterface } from "node:readline/promises";
7
-
8
- //#region src/migrate.ts
9
- async function migrate({ cwd, dryRun }) {
10
- if (dryRun) globalLogger.info("Dry run enabled. No changes were made.");
11
- else {
12
- const rl = createInterface({
13
- input: process.stdin,
14
- output: process.stdout
15
- });
16
- 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.`);
17
- const input = await rl.question(bold`Continue? (Y/n) `);
18
- rl.close();
19
- if (!(input.toLowerCase() === "y" || input === "")) {
20
- globalLogger.error("Migration cancelled.");
21
- process.exitCode = 1;
22
- return;
23
- }
24
- }
25
- if (cwd) process.chdir(cwd);
26
- let migrated = await migratePackageJson(dryRun);
27
- if (await migrateTsupConfig(dryRun)) migrated = true;
28
- if (migrated) globalLogger.success("Migration completed. Remember to run install command with your package manager.");
29
- else {
30
- globalLogger.error("No migration performed.");
31
- process.exitCode = 1;
32
- }
33
- }
34
- const DEP_FIELDS = {
35
- dependencies: `^${version}`,
36
- devDependencies: `^${version}`,
37
- peerDependencies: "*"
38
- };
39
- async function migratePackageJson(dryRun) {
40
- if (!existsSync("package.json")) {
41
- globalLogger.error("No package.json found");
42
- return false;
43
- }
44
- const pkgRaw = await readFile("package.json", "utf8");
45
- let pkg = JSON.parse(pkgRaw);
46
- let found = false;
47
- for (const [field, semver] of Object.entries(DEP_FIELDS)) if (pkg[field]?.tsup) {
48
- globalLogger.info(`Migrating \`${field}\` to tsdown.`);
49
- found = true;
50
- pkg[field] = renameKey(pkg[field], "tsup", "tsdown", semver);
51
- }
52
- if (pkg.scripts) {
53
- for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
54
- globalLogger.info(`Migrating \`${key}\` script to tsdown`);
55
- found = true;
56
- pkg.scripts[key] = pkg.scripts[key].replaceAll(/tsup(?:-node)?/g, "tsdown");
57
- }
58
- }
59
- if (pkg.tsup) {
60
- globalLogger.info("Migrating `tsup` field in package.json to `tsdown`.");
61
- found = true;
62
- pkg = renameKey(pkg, "tsup", "tsdown");
63
- }
64
- if (!found) {
65
- globalLogger.warn("No tsup-related fields found in package.json");
66
- return false;
67
- }
68
- const pkgStr = `${JSON.stringify(pkg, null, pkgRaw.includes(" ") ? " " : 2)}\n`;
69
- if (dryRun) {
70
- const { createPatch } = await import("diff");
71
- globalLogger.info("[dry-run] package.json:");
72
- console.info(createPatch("package.json", pkgRaw, pkgStr));
73
- } else {
74
- await writeFile("package.json", pkgStr);
75
- globalLogger.success("Migrated `package.json`");
76
- }
77
- return true;
78
- }
79
- const TSUP_FILES = [
80
- "tsup.config.ts",
81
- "tsup.config.cts",
82
- "tsup.config.mts",
83
- "tsup.config.js",
84
- "tsup.config.cjs",
85
- "tsup.config.mjs",
86
- "tsup.config.json"
87
- ];
88
- async function migrateTsupConfig(dryRun) {
89
- let found = false;
90
- for (const file of TSUP_FILES) {
91
- if (!existsSync(file)) continue;
92
- globalLogger.info(`Found \`${file}\``);
93
- found = true;
94
- const tsupConfigRaw = await readFile(file, "utf8");
95
- const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replaceAll(/\bTSUP\b/g, "TSDOWN");
96
- const renamed = file.replaceAll("tsup", "tsdown");
97
- if (dryRun) {
98
- const { createTwoFilesPatch } = await import("diff");
99
- globalLogger.info(`[dry-run] ${file} -> ${renamed}:`);
100
- console.info(createTwoFilesPatch(file, renamed, tsupConfigRaw, tsupConfig));
101
- } else {
102
- await writeFile(renamed, tsupConfig, "utf8");
103
- await unlink(file);
104
- globalLogger.success(`Migrated \`${file}\` to \`${renamed}\``);
105
- }
106
- }
107
- if (!found) globalLogger.warn("No tsup config found");
108
- return found;
109
- }
110
- function renameKey(obj, oldKey, newKey, newValue) {
111
- const newObj = {};
112
- for (const key of Object.keys(obj)) if (key === oldKey) newObj[newKey] = newValue || obj[oldKey];
113
- else newObj[key] = obj[key];
114
- return newObj;
115
- }
116
-
117
- //#endregion
118
- export { migrate };