tsdown-migrate 0.19.0-beta.2 → 0.19.0-beta.4
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.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/run.mjs +5 -2
- package/dist/{src-Duj7Xgmb.mjs → src-DP-GF725.mjs} +38 -8
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
package/dist/run.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as name, r as version, t as migrate } from "./src-
|
|
2
|
+
import { n as name, r as version, t as migrate } from "./src-DP-GF725.mjs";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import consola from "consola";
|
|
5
5
|
import { cac } from "cac";
|
|
6
6
|
|
|
7
7
|
//#region src/cli.ts
|
|
8
8
|
const cli = cac(name).version(version).help();
|
|
9
|
-
cli.command("", "Migrate a project to tsdown").option("-
|
|
9
|
+
cli.command("[...dirs]", "Migrate a project to tsdown").option("-d, --dry-run", "Perform a dry run without making changes").action((dirs, options) => migrate({
|
|
10
|
+
...options,
|
|
11
|
+
dirs
|
|
12
|
+
}));
|
|
10
13
|
async function runCLI() {
|
|
11
14
|
cli.parse(process.argv, { run: false });
|
|
12
15
|
try {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import { getCliCommand, parseNi, run } from "@antfu/ni";
|
|
3
|
-
import { dim, green, red, underline } from "ansis";
|
|
3
|
+
import { dim, green, greenBright, red, underline } from "ansis";
|
|
4
4
|
import consola from "consola";
|
|
5
|
+
import { glob } from "tinyglobby";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
7
8
|
import { createPatch, createTwoFilesPatch } from "diff";
|
|
@@ -22,7 +23,7 @@ function detectIndentation(jsonText) {
|
|
|
22
23
|
//#endregion
|
|
23
24
|
//#region package.json
|
|
24
25
|
var name = "tsdown-migrate";
|
|
25
|
-
var version = "0.19.0-beta.
|
|
26
|
+
var version = "0.19.0-beta.4";
|
|
26
27
|
|
|
27
28
|
//#endregion
|
|
28
29
|
//#region src/utils.ts
|
|
@@ -299,17 +300,46 @@ async function migrateTsupConfig(dryRun) {
|
|
|
299
300
|
|
|
300
301
|
//#endregion
|
|
301
302
|
//#region src/index.ts
|
|
302
|
-
async function migrate({
|
|
303
|
+
async function migrate({ dirs, dryRun }) {
|
|
303
304
|
if (dryRun) consola.info("Dry run enabled. No changes were made.");
|
|
304
305
|
else if (!await consola.prompt(`Before 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.\n\nContinue?`, { type: "confirm" })) {
|
|
305
306
|
consola.warn("Migration cancelled.");
|
|
306
307
|
process.exitCode = 1;
|
|
307
308
|
return;
|
|
308
309
|
}
|
|
309
|
-
|
|
310
|
-
let
|
|
311
|
-
if (
|
|
312
|
-
|
|
310
|
+
const baseCwd = process.cwd();
|
|
311
|
+
let cwds;
|
|
312
|
+
if (dirs?.length) {
|
|
313
|
+
cwds = await glob(dirs, {
|
|
314
|
+
cwd: baseCwd,
|
|
315
|
+
onlyDirectories: true,
|
|
316
|
+
absolute: true,
|
|
317
|
+
expandDirectories: false
|
|
318
|
+
});
|
|
319
|
+
if (cwds.length === 0) {
|
|
320
|
+
consola.error(`No directories matched: ${dirs.join(", ")}`);
|
|
321
|
+
process.exitCode = 1;
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
} else cwds = [baseCwd];
|
|
325
|
+
let migratedAny = false;
|
|
326
|
+
try {
|
|
327
|
+
for (const dir of cwds) {
|
|
328
|
+
process.chdir(dir);
|
|
329
|
+
const dirLabel = greenBright(dir);
|
|
330
|
+
consola.info(`Processing ${dirLabel}`);
|
|
331
|
+
let migrated = await migratePackageJson(dryRun);
|
|
332
|
+
if (await migrateTsupConfig(dryRun)) migrated = true;
|
|
333
|
+
if (!migrated) {
|
|
334
|
+
consola.warn(`No migrations to apply in ${dirLabel}.`);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
migratedAny = true;
|
|
338
|
+
}
|
|
339
|
+
} finally {
|
|
340
|
+
process.chdir(baseCwd);
|
|
341
|
+
}
|
|
342
|
+
if (!migratedAny) {
|
|
313
343
|
consola.error("No migration performed.");
|
|
314
344
|
process.exitCode = 1;
|
|
315
345
|
return;
|
|
@@ -317,7 +347,7 @@ async function migrate({ cwd, dryRun }) {
|
|
|
317
347
|
consola.info("Migration completed. Installing dependencies...");
|
|
318
348
|
if (dryRun) consola.info("[dry-run] would run:", await getCliCommand(parseNi, []));
|
|
319
349
|
else {
|
|
320
|
-
await run(parseNi, [], { cwd });
|
|
350
|
+
await run(parseNi, [], { cwd: baseCwd });
|
|
321
351
|
consola.success("Dependencies installed.");
|
|
322
352
|
}
|
|
323
353
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown-migrate",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.19.0-beta.
|
|
4
|
+
"version": "0.19.0-beta.4",
|
|
5
5
|
"description": "A CLI tool to help migrate your project to tsdown.",
|
|
6
6
|
"author": "Kevin Deng <sxzz@sxzz.moe>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,12 +42,13 @@
|
|
|
42
42
|
"node": ">=20.19.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@antfu/ni": "^28.
|
|
46
|
-
"@ast-grep/napi": "^0.40.
|
|
45
|
+
"@antfu/ni": "^28.1.0",
|
|
46
|
+
"@ast-grep/napi": "^0.40.4",
|
|
47
47
|
"ansis": "^4.2.0",
|
|
48
48
|
"cac": "^6.7.14",
|
|
49
49
|
"consola": "^3.4.2",
|
|
50
|
-
"diff": "^8.0.2"
|
|
50
|
+
"diff": "^8.0.2",
|
|
51
|
+
"tinyglobby": "^0.2.15"
|
|
51
52
|
},
|
|
52
53
|
"scripts": {
|
|
53
54
|
"dev": "node ./src/run.ts",
|