tsdown 0.5.6 → 0.5.7
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/index.js +1 -1
- package/dist/{logger-BV85twVD.js → logger-4bmpqibt.js} +2 -2
- package/dist/migrate-CAxpGo3J.js +132 -0
- package/dist/package-Bvw78lhP.js +6 -0
- package/dist/run.js +15 -15
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "./config-0LDjKwZ7.js";
|
|
2
|
-
import { debug, logger, setSilent } from "./logger-
|
|
2
|
+
import { debug, logger, setSilent } from "./logger-4bmpqibt.js";
|
|
3
3
|
import { ExternalPlugin } from "./external-QIv-o_HK.js";
|
|
4
4
|
import path, { dirname, normalize, sep } from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import Debug from "debug";
|
|
3
|
-
import { consola } from "consola";
|
|
3
|
+
import { consola as consola$1 } from "consola";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/logger.ts
|
|
6
|
-
const logger = consola.withTag("tsdown");
|
|
6
|
+
const logger = consola$1.withTag("tsdown");
|
|
7
7
|
const debug = Debug("tsdown");
|
|
8
8
|
function setSilent(silent) {
|
|
9
9
|
if (!("CONSOLA_LEVEL" in process.env)) logger.level = silent ? 0 : 3;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { version } from "./package-Bvw78lhP.js";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
import pc from "picocolors";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { diffLines } from "diff";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/diff.ts
|
|
10
|
+
function diff(original, updated) {
|
|
11
|
+
let text = "";
|
|
12
|
+
const diff$1 = diffLines(original, updated, {
|
|
13
|
+
ignoreWhitespace: true,
|
|
14
|
+
ignoreNewlineAtEof: true
|
|
15
|
+
});
|
|
16
|
+
for (const line of diff$1) {
|
|
17
|
+
const { value } = line;
|
|
18
|
+
text += line.added ? pc.green(value) : line.removed ? pc.red(value) : pc.gray(line.value);
|
|
19
|
+
}
|
|
20
|
+
return text;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/migrate.ts
|
|
25
|
+
async function migrate({ cwd, dryRun }) {
|
|
26
|
+
if (dryRun) consola.info("Dry run enabled. No changes were made.");
|
|
27
|
+
else {
|
|
28
|
+
const confirm = await consola.prompt("Please make sure to commit your changes before migrating. Continue?", { type: "confirm" });
|
|
29
|
+
if (!confirm) {
|
|
30
|
+
consola.error("Migration cancelled.");
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (cwd) process.chdir(cwd);
|
|
36
|
+
let migrated = await migratePackageJson(dryRun);
|
|
37
|
+
if (await migrateTsupConfig(dryRun)) migrated = true;
|
|
38
|
+
if (migrated) consola.success("Migration completed. Remember to run install command with your package manager.");
|
|
39
|
+
else {
|
|
40
|
+
consola.error("No migration performed.");
|
|
41
|
+
process.exitCode = 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function migratePackageJson(dryRun) {
|
|
45
|
+
if (!existsSync("package.json")) {
|
|
46
|
+
consola.error("No package.json found");
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const pkgRaw = await readFile("package.json", "utf-8");
|
|
50
|
+
let pkg = JSON.parse(pkgRaw);
|
|
51
|
+
const semver = `^${version}`;
|
|
52
|
+
let found = false;
|
|
53
|
+
if (pkg.dependencies?.tsup) {
|
|
54
|
+
consola.info("Migrating `dependencies` to tsdown.");
|
|
55
|
+
found = true;
|
|
56
|
+
pkg.dependencies = renameKey(pkg.dependencies, "tsup", "tsdown", semver);
|
|
57
|
+
}
|
|
58
|
+
if (pkg.devDependencies?.tsup) {
|
|
59
|
+
consola.info("Migrating `devDependencies` to tsdown.");
|
|
60
|
+
found = true;
|
|
61
|
+
pkg.devDependencies = renameKey(pkg.devDependencies, "tsup", "tsdown", semver);
|
|
62
|
+
}
|
|
63
|
+
if (pkg.peerDependencies?.tsup) {
|
|
64
|
+
consola.info("Migrating `peerDependencies` to tsdown.");
|
|
65
|
+
found = true;
|
|
66
|
+
pkg.peerDependencies = renameKey(pkg.peerDependencies, "tsup", "tsdown", "*");
|
|
67
|
+
}
|
|
68
|
+
if (pkg.scripts) {
|
|
69
|
+
for (const key of Object.keys(pkg.scripts)) if (pkg.scripts[key].includes("tsup")) {
|
|
70
|
+
consola.info(`Migrating \`${key}\` script to tsdown`);
|
|
71
|
+
found = true;
|
|
72
|
+
pkg.scripts[key] = pkg.scripts[key].replaceAll("tsup", "tsdown");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (pkg.tsup) {
|
|
76
|
+
consola.info("Migrating `tsup` field in package.json to `tsdown`.");
|
|
77
|
+
found = true;
|
|
78
|
+
pkg = renameKey(pkg, "tsup", "tsdown");
|
|
79
|
+
}
|
|
80
|
+
if (!found) {
|
|
81
|
+
consola.warn("No tsup-related fields found in package.json");
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const pkgStr = `${JSON.stringify(pkg, null, 2)}\n`;
|
|
85
|
+
if (dryRun) {
|
|
86
|
+
consola.info("[dry-run] package.json:");
|
|
87
|
+
console.info(diff(pkgRaw, pkgStr));
|
|
88
|
+
} else {
|
|
89
|
+
await writeFile("package.json", pkgStr);
|
|
90
|
+
consola.success("Migrated `package.json`");
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
const TSUP_FILES = [
|
|
95
|
+
"tsup.config.ts",
|
|
96
|
+
"tsup.config.cts",
|
|
97
|
+
"tsup.config.mts",
|
|
98
|
+
"tsup.config.js",
|
|
99
|
+
"tsup.config.cjs",
|
|
100
|
+
"tsup.config.mjs",
|
|
101
|
+
"tsup.config.json"
|
|
102
|
+
];
|
|
103
|
+
async function migrateTsupConfig(dryRun) {
|
|
104
|
+
let found = false;
|
|
105
|
+
for (const file of TSUP_FILES) {
|
|
106
|
+
if (!existsSync(file)) continue;
|
|
107
|
+
consola.info(`Found \`${file}\``);
|
|
108
|
+
found = true;
|
|
109
|
+
const tsupConfigRaw = await readFile(file, "utf-8");
|
|
110
|
+
const tsupConfig = tsupConfigRaw.replaceAll(/\btsup\b/g, "tsdown").replace(/\bTSUP\b/, "TSDOWN");
|
|
111
|
+
const renamed = file.replaceAll("tsup", "tsdown");
|
|
112
|
+
if (dryRun) {
|
|
113
|
+
consola.info(`[dry-run] ${file} -> ${renamed}:`);
|
|
114
|
+
console.info(diff(tsupConfigRaw, tsupConfig));
|
|
115
|
+
} else {
|
|
116
|
+
await writeFile(renamed, tsupConfig, "utf8");
|
|
117
|
+
await unlink(file);
|
|
118
|
+
consola.success(`Migrated \`${file}\` to \`${renamed}\``);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!found) consola.warn("No tsup config found");
|
|
122
|
+
return found;
|
|
123
|
+
}
|
|
124
|
+
function renameKey(obj, oldKey, newKey, newValue) {
|
|
125
|
+
const newObj = {};
|
|
126
|
+
for (const key of Object.keys(obj)) if (key === oldKey) newObj[newKey] = newValue || obj[oldKey];
|
|
127
|
+
else newObj[key] = obj[key];
|
|
128
|
+
return newObj;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
export { migrate };
|
package/dist/run.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { logger, setSilent } from "./logger-
|
|
1
|
+
import { logger, setSilent } from "./logger-4bmpqibt.js";
|
|
2
|
+
import { version } from "./package-Bvw78lhP.js";
|
|
2
3
|
import process from "node:process";
|
|
3
4
|
import { VERSION } from "rolldown";
|
|
4
5
|
import pc from "picocolors";
|
|
5
6
|
import { cac } from "cac";
|
|
6
7
|
|
|
7
|
-
//#region package.json
|
|
8
|
-
var version = "0.5.6";
|
|
9
|
-
|
|
10
|
-
//#endregion
|
|
11
8
|
//#region src/cli.ts
|
|
9
|
+
const cli = cac("tsdown");
|
|
10
|
+
cli.help().version(version);
|
|
11
|
+
cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--minify", "Minify output").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").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("-w, --watch [path]", "Watch mode").action(async (input, flags) => {
|
|
12
|
+
setSilent(!!flags.silent);
|
|
13
|
+
logger.info(`tsdown ${pc.dim(`v${version}`)} powered by rolldown ${pc.dim(`v${VERSION}`)}`);
|
|
14
|
+
const { build: build$1 } = await import("./index.js");
|
|
15
|
+
if (input.length > 0) flags.entry = input;
|
|
16
|
+
await build$1(flags);
|
|
17
|
+
});
|
|
18
|
+
cli.command("migrate", "Migrate from tsup to tsdown").option("-c, --cwd <dir>", "Working directory").option("-d, --dry-run", "Dry run").action(async (args) => {
|
|
19
|
+
const { migrate } = await import("./migrate-CAxpGo3J.js");
|
|
20
|
+
await migrate(args);
|
|
21
|
+
});
|
|
12
22
|
async function runCLI() {
|
|
13
|
-
const cli = cac("tsdown");
|
|
14
|
-
cli.command("[...files]", "Bundle files", { ignoreOptionDefaultValue: true }).option("-c, --config <filename>", "Use a custom config file").option("--no-config", "Disable config file").option("--format <format>", "Bundle format: esm, cjs, iife", { default: "esm" }).option("--clean", "Clean output directory").option("--minify", "Minify output").option("--target <target>", "Bundle target, e.g \"es2015\", \"esnext\"").option("--silent", "Suppress non-error logs").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("-w, --watch [path]", "Watch mode").action(async (input, flags) => {
|
|
15
|
-
setSilent(!!flags.silent);
|
|
16
|
-
logger.info(`tsdown ${pc.dim(`v${version}`)} powered by rolldown ${pc.dim(`v${VERSION}`)}`);
|
|
17
|
-
const { build: build$1 } = await import("./index.js");
|
|
18
|
-
if (input.length > 0) flags.entry = input;
|
|
19
|
-
await build$1(flags);
|
|
20
|
-
});
|
|
21
|
-
cli.help();
|
|
22
|
-
cli.version(version);
|
|
23
23
|
cli.parse(process.argv, { run: false });
|
|
24
24
|
try {
|
|
25
25
|
await cli.runMatchedCommand();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.7",
|
|
4
4
|
"description": "An even faster bundler powered by Rolldown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"chokidar": "^4.0.3",
|
|
46
46
|
"consola": "^3.4.0",
|
|
47
47
|
"debug": "^4.4.0",
|
|
48
|
+
"diff": "^7.0.0",
|
|
48
49
|
"picocolors": "^1.1.1",
|
|
49
50
|
"pkg-types": "^1.3.1",
|
|
50
51
|
"publint": "^0.3.2",
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"@sxzz/prettier-config": "^2.1.0",
|
|
62
63
|
"@sxzz/test-utils": "^0.4.0",
|
|
63
64
|
"@types/debug": "^4.1.12",
|
|
65
|
+
"@types/diff": "^7.0.1",
|
|
64
66
|
"@types/node": "^22.10.10",
|
|
65
67
|
"bumpp": "^10.0.1",
|
|
66
68
|
"eslint": "^9.19.0",
|