tsdown 0.13.4 → 0.14.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/dist/cli-BwOoKKTM.mjs +46 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +5 -0
- package/dist/{config-CEEvti7D.d.mts → config-77IY7Jdj.d.mts} +1 -1
- package/dist/config-DsBEbB6I.mjs +7 -0
- package/dist/config.d.mts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/logger-YArsxPto.mjs +144 -0
- package/dist/{migrate-BghKfLMP.mjs → migrate-BCQUL2Gs.mjs} +1 -1
- package/dist/migrate-Cl62m5IG.mjs +126 -0
- package/dist/migrate.d.mts +10 -0
- package/dist/migrate.mjs +126 -0
- package/dist/package-DOiAuQ-5.mjs +5 -0
- package/dist/package-DwljelGW.mjs +5 -0
- package/dist/package-TDRl9aMv.mjs +5 -0
- package/dist/plugins.d.mts +1 -1
- package/dist/plugins.mjs +1 -1
- package/dist/run.mjs +2 -2
- package/dist/src-D_PDH4ZS.mjs +1335 -0
- package/dist/src-lmHdfLhi.mjs +1335 -0
- package/dist/{types-QuuoDTDl.d.mts → types-BMMC0pbr.d.mts} +107 -101
- package/package.json +5 -5
- package/dist/package-C-PL6-Mh.mjs +0 -5
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { version } from "./package-DwljelGW.mjs";
|
|
2
|
+
import { globalLogger, resolveComma, toArray } from "./logger-YArsxPto.mjs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { dim } from "ansis";
|
|
5
|
+
import { cac } from "cac";
|
|
6
|
+
import debug from "debug";
|
|
7
|
+
import { VERSION } from "rolldown";
|
|
8
|
+
|
|
9
|
+
//#region src/cli.ts
|
|
10
|
+
const cli = cac("tsdown");
|
|
11
|
+
cli.help().version(version);
|
|
12
|
+
cli.command("[...files]", "Bundle files", {
|
|
13
|
+
ignoreOptionDefaultValue: true,
|
|
14
|
+
allowUnknownOptions: true
|
|
15
|
+
}).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("-f, --format <format>", "Bundle format: esm, cjs, iife, umd", { default: "esm" }).option("--clean", "Clean output directory, --no-clean to disable").option("--external <module>", "Mark dependencies as external").option("--minify", "Minify output").option("--debug [feat]", "Show debug logs").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("-l, --logLevel <level>", "Set log level: info, warn, error, silent").option("--fail-on-warn", "Fail on warnings", { default: true }).option("-d, --out-dir <dir>", "Output directory", { default: "dist" }).option("--treeshake", "Tree-shake bundle", { default: true }).option("--sourcemap", "Generate source map", { default: false }).option("--shims", "Enable cjs and esm shims ", { default: false }).option("--platform <platform>", "Target platform", { default: "node" }).option("--dts", "Generate dts files").option("--publint", "Enable publint", { default: false }).option("--attw", "Enable Are the types wrong integration", { default: false }).option("--unused", "Enable unused dependencies check", { default: false }).option("-w, --watch [path]", "Watch mode").option("--ignore-watch <path>", "Ignore custom paths in watch mode").option("--from-vite [vitest]", "Reuse config from Vite or Vitest").option("--report", "Size report", { default: true }).option("--env.* <value>", "Define compile-time env variables").option("--on-success <command>", "Command to run on success").option("--copy <dir>", "Copy files to output dir").option("--public-dir <dir>", "Alias for --copy, deprecated").option("--tsconfig <tsconfig>", "Set tsconfig path").option("--unbundle", "Unbundle mode").option("-W, --workspace [dir]", "Enable workspace mode").option("-F, --filter <pattern>", "Filter workspace packages, e.g. /regex/ or substring").option("--exports", "Generate export-related metadata for package.json (experimental)").action(async (input, flags) => {
|
|
16
|
+
globalLogger.level = flags.logLevel || (flags.silent ? "silent" : "info");
|
|
17
|
+
globalLogger.info(`tsdown ${dim`v${version}`} powered by rolldown ${dim`v${VERSION}`}`);
|
|
18
|
+
const { build: build$1 } = await import("./index.mjs");
|
|
19
|
+
if (input.length > 0) flags.entry = input;
|
|
20
|
+
await build$1(flags);
|
|
21
|
+
});
|
|
22
|
+
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
23
|
+
const { migrate } = await import("./migrate.mjs");
|
|
24
|
+
await migrate(args);
|
|
25
|
+
});
|
|
26
|
+
async function runCLI() {
|
|
27
|
+
cli.parse(process.argv, { run: false });
|
|
28
|
+
if (cli.options.debug) {
|
|
29
|
+
let namespace;
|
|
30
|
+
if (cli.options.debug === true) namespace = "tsdown:*";
|
|
31
|
+
else namespace = resolveComma(toArray(cli.options.debug)).map((v) => `tsdown:${v}`).join(",");
|
|
32
|
+
const enabled = debug.disable();
|
|
33
|
+
if (enabled) namespace += `,${enabled}`;
|
|
34
|
+
debug.enable(namespace);
|
|
35
|
+
debug("tsdown:debug")("Debugging enabled", namespace);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
await cli.runMatchedCommand();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
globalLogger.error(error);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { runCLI };
|
package/dist/cli.d.mts
ADDED
package/dist/cli.mjs
ADDED
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { UserConfig, UserConfigFn } from "./types-
|
|
2
|
-
import { defineConfig } from "./config-
|
|
1
|
+
import { UserConfig, UserConfigFn } from "./types-BMMC0pbr.mjs";
|
|
2
|
+
import { defineConfig } from "./config-77IY7Jdj.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-
|
|
2
|
-
import { defineConfig } from "./config-
|
|
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-BMMC0pbr.mjs";
|
|
2
|
+
import { defineConfig } from "./config-77IY7Jdj.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-
|
|
2
|
+
import { build, buildSingle, shimFile } from "./src-D_PDH4ZS.mjs";
|
|
3
3
|
import { globalLogger } from "./logger-CGMSjTLn.mjs";
|
|
4
4
|
|
|
5
5
|
export { build, buildSingle, defineConfig, globalLogger, shimFile };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { bgRed, bgYellow, blue, green, rgb, yellow } from "ansis";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/general.ts
|
|
4
|
+
function toArray(val, defaultValue) {
|
|
5
|
+
if (Array.isArray(val)) return val;
|
|
6
|
+
else if (val == null) {
|
|
7
|
+
if (defaultValue) return [defaultValue];
|
|
8
|
+
return [];
|
|
9
|
+
} else return [val];
|
|
10
|
+
}
|
|
11
|
+
function resolveComma(arr) {
|
|
12
|
+
return arr.flatMap((format$1) => format$1.split(","));
|
|
13
|
+
}
|
|
14
|
+
function resolveRegex(str) {
|
|
15
|
+
if (typeof str === "string" && str.length > 2 && str[0] === "/" && str.at(-1) === "/") return new RegExp(str.slice(1, -1));
|
|
16
|
+
return str;
|
|
17
|
+
}
|
|
18
|
+
function debounce(fn, wait) {
|
|
19
|
+
let timeout;
|
|
20
|
+
return function(...args) {
|
|
21
|
+
if (timeout) clearTimeout(timeout);
|
|
22
|
+
timeout = setTimeout(() => {
|
|
23
|
+
timeout = void 0;
|
|
24
|
+
fn.apply(this, args);
|
|
25
|
+
}, wait);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function slash(string) {
|
|
29
|
+
return string.replaceAll("\\", "/");
|
|
30
|
+
}
|
|
31
|
+
const noop = (v) => v;
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/utils/logger.ts
|
|
35
|
+
const LogLevels = {
|
|
36
|
+
silent: 0,
|
|
37
|
+
error: 1,
|
|
38
|
+
warn: 2,
|
|
39
|
+
info: 3
|
|
40
|
+
};
|
|
41
|
+
function format(msgs) {
|
|
42
|
+
return msgs.filter((arg) => arg !== void 0 && arg !== false).join(" ");
|
|
43
|
+
}
|
|
44
|
+
const warnedMessages = /* @__PURE__ */ new Set();
|
|
45
|
+
function createLogger(level = "info", { customLogger, console = globalThis.console, failOnWarn = false } = {}) {
|
|
46
|
+
if (customLogger) return customLogger;
|
|
47
|
+
function output(type, msg) {
|
|
48
|
+
const thresh = LogLevels[logger.level];
|
|
49
|
+
if (thresh < LogLevels[type]) return;
|
|
50
|
+
const method = type === "info" ? "log" : type;
|
|
51
|
+
console[method](msg);
|
|
52
|
+
}
|
|
53
|
+
const logger = {
|
|
54
|
+
level,
|
|
55
|
+
info(...msgs) {
|
|
56
|
+
output("info", `${blue`ℹ`} ${format(msgs)}`);
|
|
57
|
+
},
|
|
58
|
+
warn(...msgs) {
|
|
59
|
+
const message = format(msgs);
|
|
60
|
+
if (failOnWarn) throw new Error(message);
|
|
61
|
+
warnedMessages.add(message);
|
|
62
|
+
output("warn", `\n${bgYellow` WARN `} ${message}\n`);
|
|
63
|
+
},
|
|
64
|
+
warnOnce(...msgs) {
|
|
65
|
+
const message = format(msgs);
|
|
66
|
+
if (warnedMessages.has(message)) return;
|
|
67
|
+
if (failOnWarn) throw new Error(message);
|
|
68
|
+
warnedMessages.add(message);
|
|
69
|
+
output("warn", `\n${bgYellow` WARN `} ${message}\n`);
|
|
70
|
+
},
|
|
71
|
+
error(...msgs) {
|
|
72
|
+
output("error", `\n${bgRed` ERROR `} ${format(msgs)}\n`);
|
|
73
|
+
},
|
|
74
|
+
success(...msgs) {
|
|
75
|
+
output("info", `${green`✔`} ${format(msgs)}`);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return logger;
|
|
79
|
+
}
|
|
80
|
+
const globalLogger = createLogger();
|
|
81
|
+
function prettyName(name) {
|
|
82
|
+
if (!name) return void 0;
|
|
83
|
+
return generateColor(name)(`[${name}]`);
|
|
84
|
+
}
|
|
85
|
+
function prettyFormat(format$1) {
|
|
86
|
+
const formatColor = format$1 === "es" ? blue : format$1 === "cjs" ? yellow : noop;
|
|
87
|
+
let formatText;
|
|
88
|
+
switch (format$1) {
|
|
89
|
+
case "es":
|
|
90
|
+
formatText = "ESM";
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
formatText = format$1.toUpperCase();
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return formatColor(`[${formatText}]`);
|
|
97
|
+
}
|
|
98
|
+
const colors = /* @__PURE__ */ new Map();
|
|
99
|
+
function generateColor(name = "default") {
|
|
100
|
+
if (colors.has(name)) return colors.get(name);
|
|
101
|
+
let color;
|
|
102
|
+
if (name === "default") color = blue;
|
|
103
|
+
else {
|
|
104
|
+
let hash = 0;
|
|
105
|
+
for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash);
|
|
106
|
+
const hue = hash % 360;
|
|
107
|
+
const saturation = 35;
|
|
108
|
+
const lightness = 55;
|
|
109
|
+
color = rgb(...hslToRgb(hue, saturation, lightness));
|
|
110
|
+
}
|
|
111
|
+
colors.set(name, color);
|
|
112
|
+
return color;
|
|
113
|
+
}
|
|
114
|
+
function hslToRgb(h, s, l) {
|
|
115
|
+
h = h % 360;
|
|
116
|
+
h /= 360;
|
|
117
|
+
s /= 100;
|
|
118
|
+
l /= 100;
|
|
119
|
+
let r, g, b;
|
|
120
|
+
if (s === 0) r = g = b = l;
|
|
121
|
+
else {
|
|
122
|
+
const q = l < .5 ? l * (1 + s) : l + s - l * s;
|
|
123
|
+
const p = 2 * l - q;
|
|
124
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
125
|
+
g = hue2rgb(p, q, h);
|
|
126
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
127
|
+
}
|
|
128
|
+
return [
|
|
129
|
+
Math.max(0, Math.round(r * 255)),
|
|
130
|
+
Math.max(0, Math.round(g * 255)),
|
|
131
|
+
Math.max(0, Math.round(b * 255))
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
function hue2rgb(p, q, t) {
|
|
135
|
+
if (t < 0) t += 1;
|
|
136
|
+
if (t > 1) t -= 1;
|
|
137
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
138
|
+
if (t < 1 / 2) return q;
|
|
139
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
140
|
+
return p;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { LogLevels, createLogger, debounce, generateColor, globalLogger, noop, prettyFormat, prettyName, resolveComma, resolveRegex, slash, toArray };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { globalLogger } from "./logger-CGMSjTLn.mjs";
|
|
2
|
-
import { version } from "./package-
|
|
2
|
+
import { version } from "./package-TDRl9aMv.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,126 @@
|
|
|
1
|
+
import { globalLogger } from "./logger-CGMSjTLn.mjs";
|
|
2
|
+
import { version } from "./package-DOiAuQ-5.mjs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { bold, green, underline } from "ansis";
|
|
5
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { createInterface } from "node:readline/promises";
|
|
8
|
+
|
|
9
|
+
//#region src/migrate.ts
|
|
10
|
+
async function migrate({ cwd, dryRun }) {
|
|
11
|
+
if (dryRun) globalLogger.info("Dry run enabled. No changes were made.");
|
|
12
|
+
else {
|
|
13
|
+
const rl = createInterface({
|
|
14
|
+
input: process.stdin,
|
|
15
|
+
output: process.stdout
|
|
16
|
+
});
|
|
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
|
+
const input = await rl.question(bold`Continue? (Y/n) `);
|
|
19
|
+
rl.close();
|
|
20
|
+
const confirm = input.toLowerCase() === "y" || input === "";
|
|
21
|
+
if (!confirm) {
|
|
22
|
+
globalLogger.error("Migration cancelled.");
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (cwd) process.chdir(cwd);
|
|
28
|
+
let migrated = await migratePackageJson(dryRun);
|
|
29
|
+
if (await migrateTsupConfig(dryRun)) migrated = true;
|
|
30
|
+
if (migrated) globalLogger.success("Migration completed. Remember to run install command with your package manager.");
|
|
31
|
+
else {
|
|
32
|
+
globalLogger.error("No migration performed.");
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function migratePackageJson(dryRun) {
|
|
37
|
+
if (!existsSync("package.json")) {
|
|
38
|
+
globalLogger.error("No package.json found");
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const pkgRaw = await readFile("package.json", "utf-8");
|
|
42
|
+
let pkg = JSON.parse(pkgRaw);
|
|
43
|
+
const semver = `^${version}`;
|
|
44
|
+
let found = false;
|
|
45
|
+
if (pkg.dependencies?.tsup) {
|
|
46
|
+
globalLogger.info("Migrating `dependencies` to tsdown.");
|
|
47
|
+
found = true;
|
|
48
|
+
pkg.dependencies = renameKey(pkg.dependencies, "tsup", "tsdown", semver);
|
|
49
|
+
}
|
|
50
|
+
if (pkg.devDependencies?.tsup) {
|
|
51
|
+
globalLogger.info("Migrating `devDependencies` to tsdown.");
|
|
52
|
+
found = true;
|
|
53
|
+
pkg.devDependencies = renameKey(pkg.devDependencies, "tsup", "tsdown", semver);
|
|
54
|
+
}
|
|
55
|
+
if (pkg.peerDependencies?.tsup) {
|
|
56
|
+
globalLogger.info("Migrating `peerDependencies` to tsdown.");
|
|
57
|
+
found = true;
|
|
58
|
+
pkg.peerDependencies = renameKey(pkg.peerDependencies, "tsup", "tsdown", "*");
|
|
59
|
+
}
|
|
60
|
+
if (pkg.scripts) {
|
|
61
|
+
for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
|
|
62
|
+
globalLogger.info(`Migrating \`${key}\` script to tsdown`);
|
|
63
|
+
found = true;
|
|
64
|
+
pkg.scripts[key] = pkg.scripts[key].replaceAll(/tsup(?:-node)?/g, "tsdown");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (pkg.tsup) {
|
|
68
|
+
globalLogger.info("Migrating `tsup` field in package.json to `tsdown`.");
|
|
69
|
+
found = true;
|
|
70
|
+
pkg = renameKey(pkg, "tsup", "tsdown");
|
|
71
|
+
}
|
|
72
|
+
if (!found) {
|
|
73
|
+
globalLogger.warn("No tsup-related fields found in package.json");
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
77
|
+
if (dryRun) {
|
|
78
|
+
const { createPatch } = await import("diff");
|
|
79
|
+
globalLogger.info("[dry-run] package.json:");
|
|
80
|
+
console.info(createPatch("package.json", pkgRaw, pkgStr));
|
|
81
|
+
} else {
|
|
82
|
+
await writeFile("package.json", pkgStr);
|
|
83
|
+
globalLogger.success("Migrated `package.json`");
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
const TSUP_FILES = [
|
|
88
|
+
"tsup.config.ts",
|
|
89
|
+
"tsup.config.cts",
|
|
90
|
+
"tsup.config.mts",
|
|
91
|
+
"tsup.config.js",
|
|
92
|
+
"tsup.config.cjs",
|
|
93
|
+
"tsup.config.mjs",
|
|
94
|
+
"tsup.config.json"
|
|
95
|
+
];
|
|
96
|
+
async function migrateTsupConfig(dryRun) {
|
|
97
|
+
let found = false;
|
|
98
|
+
for (const file of TSUP_FILES) {
|
|
99
|
+
if (!existsSync(file)) continue;
|
|
100
|
+
globalLogger.info(`Found \`${file}\``);
|
|
101
|
+
found = true;
|
|
102
|
+
const tsupConfigRaw = await readFile(file, "utf-8");
|
|
103
|
+
const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replaceAll(/\bTSUP\b/g, "TSDOWN");
|
|
104
|
+
const renamed = file.replaceAll("tsup", "tsdown");
|
|
105
|
+
if (dryRun) {
|
|
106
|
+
const { createTwoFilesPatch } = await import("diff");
|
|
107
|
+
globalLogger.info(`[dry-run] ${file} -> ${renamed}:`);
|
|
108
|
+
console.info(createTwoFilesPatch(file, renamed, tsupConfigRaw, tsupConfig));
|
|
109
|
+
} else {
|
|
110
|
+
await writeFile(renamed, tsupConfig, "utf8");
|
|
111
|
+
await unlink(file);
|
|
112
|
+
globalLogger.success(`Migrated \`${file}\` to \`${renamed}\``);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!found) globalLogger.warn("No tsup config found");
|
|
116
|
+
return found;
|
|
117
|
+
}
|
|
118
|
+
function renameKey(obj, oldKey, newKey, newValue) {
|
|
119
|
+
const newObj = {};
|
|
120
|
+
for (const key of Object.keys(obj)) if (key === oldKey) newObj[newKey] = newValue || obj[oldKey];
|
|
121
|
+
else newObj[key] = obj[key];
|
|
122
|
+
return newObj;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { migrate };
|
package/dist/migrate.mjs
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { version } from "./package-DwljelGW.mjs";
|
|
2
|
+
import { globalLogger } from "./logger-YArsxPto.mjs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { bold, green, underline } from "ansis";
|
|
5
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { createInterface } from "node:readline/promises";
|
|
8
|
+
|
|
9
|
+
//#region src/migrate.ts
|
|
10
|
+
async function migrate({ cwd, dryRun }) {
|
|
11
|
+
if (dryRun) globalLogger.info("Dry run enabled. No changes were made.");
|
|
12
|
+
else {
|
|
13
|
+
const rl = createInterface({
|
|
14
|
+
input: process.stdin,
|
|
15
|
+
output: process.stdout
|
|
16
|
+
});
|
|
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
|
+
const input = await rl.question(bold`Continue? (Y/n) `);
|
|
19
|
+
rl.close();
|
|
20
|
+
const confirm = input.toLowerCase() === "y" || input === "";
|
|
21
|
+
if (!confirm) {
|
|
22
|
+
globalLogger.error("Migration cancelled.");
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (cwd) process.chdir(cwd);
|
|
28
|
+
let migrated = await migratePackageJson(dryRun);
|
|
29
|
+
if (await migrateTsupConfig(dryRun)) migrated = true;
|
|
30
|
+
if (migrated) globalLogger.success("Migration completed. Remember to run install command with your package manager.");
|
|
31
|
+
else {
|
|
32
|
+
globalLogger.error("No migration performed.");
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function migratePackageJson(dryRun) {
|
|
37
|
+
if (!existsSync("package.json")) {
|
|
38
|
+
globalLogger.error("No package.json found");
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const pkgRaw = await readFile("package.json", "utf-8");
|
|
42
|
+
let pkg = JSON.parse(pkgRaw);
|
|
43
|
+
const semver = `^${version}`;
|
|
44
|
+
let found = false;
|
|
45
|
+
if (pkg.dependencies?.tsup) {
|
|
46
|
+
globalLogger.info("Migrating `dependencies` to tsdown.");
|
|
47
|
+
found = true;
|
|
48
|
+
pkg.dependencies = renameKey(pkg.dependencies, "tsup", "tsdown", semver);
|
|
49
|
+
}
|
|
50
|
+
if (pkg.devDependencies?.tsup) {
|
|
51
|
+
globalLogger.info("Migrating `devDependencies` to tsdown.");
|
|
52
|
+
found = true;
|
|
53
|
+
pkg.devDependencies = renameKey(pkg.devDependencies, "tsup", "tsdown", semver);
|
|
54
|
+
}
|
|
55
|
+
if (pkg.peerDependencies?.tsup) {
|
|
56
|
+
globalLogger.info("Migrating `peerDependencies` to tsdown.");
|
|
57
|
+
found = true;
|
|
58
|
+
pkg.peerDependencies = renameKey(pkg.peerDependencies, "tsup", "tsdown", "*");
|
|
59
|
+
}
|
|
60
|
+
if (pkg.scripts) {
|
|
61
|
+
for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
|
|
62
|
+
globalLogger.info(`Migrating \`${key}\` script to tsdown`);
|
|
63
|
+
found = true;
|
|
64
|
+
pkg.scripts[key] = pkg.scripts[key].replaceAll(/tsup(?:-node)?/g, "tsdown");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (pkg.tsup) {
|
|
68
|
+
globalLogger.info("Migrating `tsup` field in package.json to `tsdown`.");
|
|
69
|
+
found = true;
|
|
70
|
+
pkg = renameKey(pkg, "tsup", "tsdown");
|
|
71
|
+
}
|
|
72
|
+
if (!found) {
|
|
73
|
+
globalLogger.warn("No tsup-related fields found in package.json");
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
77
|
+
if (dryRun) {
|
|
78
|
+
const { createPatch } = await import("diff");
|
|
79
|
+
globalLogger.info("[dry-run] package.json:");
|
|
80
|
+
console.info(createPatch("package.json", pkgRaw, pkgStr));
|
|
81
|
+
} else {
|
|
82
|
+
await writeFile("package.json", pkgStr);
|
|
83
|
+
globalLogger.success("Migrated `package.json`");
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
const TSUP_FILES = [
|
|
88
|
+
"tsup.config.ts",
|
|
89
|
+
"tsup.config.cts",
|
|
90
|
+
"tsup.config.mts",
|
|
91
|
+
"tsup.config.js",
|
|
92
|
+
"tsup.config.cjs",
|
|
93
|
+
"tsup.config.mjs",
|
|
94
|
+
"tsup.config.json"
|
|
95
|
+
];
|
|
96
|
+
async function migrateTsupConfig(dryRun) {
|
|
97
|
+
let found = false;
|
|
98
|
+
for (const file of TSUP_FILES) {
|
|
99
|
+
if (!existsSync(file)) continue;
|
|
100
|
+
globalLogger.info(`Found \`${file}\``);
|
|
101
|
+
found = true;
|
|
102
|
+
const tsupConfigRaw = await readFile(file, "utf-8");
|
|
103
|
+
const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replaceAll(/\bTSUP\b/g, "TSDOWN");
|
|
104
|
+
const renamed = file.replaceAll("tsup", "tsdown");
|
|
105
|
+
if (dryRun) {
|
|
106
|
+
const { createTwoFilesPatch } = await import("diff");
|
|
107
|
+
globalLogger.info(`[dry-run] ${file} -> ${renamed}:`);
|
|
108
|
+
console.info(createTwoFilesPatch(file, renamed, tsupConfigRaw, tsupConfig));
|
|
109
|
+
} else {
|
|
110
|
+
await writeFile(renamed, tsupConfig, "utf8");
|
|
111
|
+
await unlink(file);
|
|
112
|
+
globalLogger.success(`Migrated \`${file}\` to \`${renamed}\``);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!found) globalLogger.warn("No tsup config found");
|
|
116
|
+
return found;
|
|
117
|
+
}
|
|
118
|
+
function renameKey(obj, oldKey, newKey, newValue) {
|
|
119
|
+
const newObj = {};
|
|
120
|
+
for (const key of Object.keys(obj)) if (key === oldKey) newObj[newKey] = newValue || obj[oldKey];
|
|
121
|
+
else newObj[key] = obj[key];
|
|
122
|
+
return newObj;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { migrate };
|
package/dist/plugins.d.mts
CHANGED
package/dist/plugins.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./config-CCGWF4al.mjs";
|
|
2
|
-
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-
|
|
2
|
+
import { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin } from "./src-D_PDH4ZS.mjs";
|
|
3
3
|
import "./logger-CGMSjTLn.mjs";
|
|
4
4
|
|
|
5
5
|
export { ExternalPlugin, NodeProtocolPlugin, ReportPlugin, ShebangPlugin };
|
package/dist/run.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { globalLogger, resolveComma, toArray } from "./logger-CGMSjTLn.mjs";
|
|
3
|
-
import { version } from "./package-
|
|
3
|
+
import { version } from "./package-DOiAuQ-5.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-
|
|
25
|
+
const { migrate } = await import("./migrate-Cl62m5IG.mjs");
|
|
26
26
|
await migrate(args);
|
|
27
27
|
});
|
|
28
28
|
async function runCLI() {
|