tsdown-migrate 0.20.2 → 0.21.0-beta.1

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.mjs CHANGED
@@ -1,62 +1,3 @@
1
- import { n as migratePackageJson, t as migrateTsupConfig } from "./tsup-config-Cc0of_k5.mjs";
2
- import process from "node:process";
3
- import { getCliCommand, parseNi, run } from "@antfu/ni";
4
- import { green, greenBright, underline } from "ansis";
5
- import consola from "consola";
6
- import { glob } from "tinyglobby";
1
+ import { t as migrate } from "./src-CHnjgP-W.mjs";
7
2
 
8
- //#region src/index.ts
9
- async function migrate({ dirs, dryRun }) {
10
- if (dryRun) consola.info("Dry run enabled. No changes were made.");
11
- 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" })) {
12
- consola.warn("Migration cancelled.");
13
- process.exitCode = 1;
14
- return;
15
- }
16
- const baseCwd = process.cwd();
17
- let cwds;
18
- if (dirs?.length) {
19
- cwds = await glob(dirs, {
20
- cwd: baseCwd,
21
- onlyDirectories: true,
22
- absolute: true,
23
- expandDirectories: false
24
- });
25
- if (cwds.length === 0) {
26
- consola.error(`No directories matched: ${dirs.join(", ")}`);
27
- process.exitCode = 1;
28
- return;
29
- }
30
- } else cwds = [baseCwd];
31
- let migratedAny = false;
32
- try {
33
- for (const dir of cwds) {
34
- process.chdir(dir);
35
- const dirLabel = greenBright(dir);
36
- consola.info(`Processing ${dirLabel}`);
37
- let migrated = await migratePackageJson(dryRun);
38
- if (await migrateTsupConfig(dryRun)) migrated = true;
39
- if (!migrated) {
40
- consola.warn(`No migrations to apply in ${dirLabel}.`);
41
- continue;
42
- }
43
- migratedAny = true;
44
- }
45
- } finally {
46
- process.chdir(baseCwd);
47
- }
48
- if (!migratedAny) {
49
- consola.error("No migration performed.");
50
- process.exitCode = 1;
51
- return;
52
- }
53
- consola.info("Migration completed. Installing dependencies...");
54
- if (dryRun) consola.info("[dry-run] would run:", await getCliCommand(parseNi, []));
55
- else {
56
- await run(parseNi, [], { cwd: baseCwd });
57
- consola.success("Dependencies installed.");
58
- }
59
- }
60
-
61
- //#endregion
62
3
  export { migrate };
package/dist/run.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { i as version, r as name } from "./tsup-config-Cc0of_k5.mjs";
3
- import { migrate } from "./index.mjs";
2
+ import { n as name, r as version, t as migrate } from "./src-CHnjgP-W.mjs";
4
3
  import process from "node:process";
5
4
  import consola from "consola";
6
5
  import { cac } from "cac";
@@ -1,5 +1,8 @@
1
- import { dim, green, red } from "ansis";
1
+ import process from "node:process";
2
+ import { getCliCommand, parseNi, run } from "@antfu/ni";
3
+ import { dim, green, greenBright, red, underline } from "ansis";
2
4
  import consola from "consola";
5
+ import { glob } from "tinyglobby";
3
6
  import { existsSync } from "node:fs";
4
7
  import { readFile, unlink, writeFile } from "node:fs/promises";
5
8
  import { createPatch, createTwoFilesPatch } from "diff";
@@ -20,7 +23,7 @@ function detectIndentation(jsonText) {
20
23
  //#endregion
21
24
  //#region package.json
22
25
  var name = "tsdown-migrate";
23
- var version = "0.20.2";
26
+ var version = "0.21.0-beta.1";
24
27
 
25
28
  //#endregion
26
29
  //#region src/utils.ts
@@ -105,6 +108,10 @@ const PROPERTY_RENAMES = {
105
108
  publicDir: "copy",
106
109
  cjsInterop: "cjsDefault"
107
110
  };
111
+ const DEPS_NAMESPACE_RENAMES = {
112
+ external: "neverBundle",
113
+ noExternal: "alwaysBundle"
114
+ };
108
115
  /**
109
116
  * Transform tsup config code to tsdown config code.
110
117
  * This function applies all migration rules and returns the transformed code
@@ -189,6 +196,18 @@ function transformTsupConfig(code, filename) {
189
196
  } }]
190
197
  } });
191
198
  for (const node of removeNodeProtocolPairs) edits.push(node.replace("nodeProtocol: 'strip'"));
199
+ const depsProperties = [];
200
+ for (const [oldName, newName] of Object.entries(DEPS_NAMESPACE_RENAMES)) {
201
+ const pair = findPropertyPair(oldName);
202
+ if (pair) {
203
+ const valueNode = pair.field("value");
204
+ if (valueNode) depsProperties.push({
205
+ name: newName,
206
+ value: valueNode.text()
207
+ });
208
+ edits.push(pair.replace(""));
209
+ }
210
+ }
192
211
  const tsupIdentifiers = root.findAll({ rule: {
193
212
  kind: "identifier",
194
213
  regex: "^tsup$"
@@ -237,6 +256,10 @@ function transformTsupConfig(code, filename) {
237
256
  } });
238
257
  const missingDefaults = [];
239
258
  if (configObjectNode) {
259
+ if (depsProperties.length > 0) {
260
+ const depsEntries = depsProperties.map((p) => `${p.name}: ${p.value}`).join(",\n ");
261
+ missingDefaults.push(`deps: {\n ${depsEntries},\n }`);
262
+ }
240
263
  if (!hasOption("format")) missingDefaults.push("format: 'cjs'");
241
264
  if (!hasOption("clean")) missingDefaults.push("clean: false");
242
265
  if (!hasOption("dts")) missingDefaults.push("dts: false");
@@ -296,4 +319,58 @@ async function migrateTsupConfig(dryRun) {
296
319
  }
297
320
 
298
321
  //#endregion
299
- export { version as i, migratePackageJson as n, name as r, migrateTsupConfig as t };
322
+ //#region src/index.ts
323
+ async function migrate({ dirs, dryRun }) {
324
+ if (dryRun) consola.info("Dry run enabled. No changes were made.");
325
+ 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" })) {
326
+ consola.warn("Migration cancelled.");
327
+ process.exitCode = 1;
328
+ return;
329
+ }
330
+ const baseCwd = process.cwd();
331
+ let cwds;
332
+ if (dirs?.length) {
333
+ cwds = await glob(dirs, {
334
+ cwd: baseCwd,
335
+ onlyDirectories: true,
336
+ absolute: true,
337
+ expandDirectories: false
338
+ });
339
+ if (cwds.length === 0) {
340
+ consola.error(`No directories matched: ${dirs.join(", ")}`);
341
+ process.exitCode = 1;
342
+ return;
343
+ }
344
+ } else cwds = [baseCwd];
345
+ let migratedAny = false;
346
+ try {
347
+ for (const dir of cwds) {
348
+ process.chdir(dir);
349
+ const dirLabel = greenBright(dir);
350
+ consola.info(`Processing ${dirLabel}`);
351
+ let migrated = await migratePackageJson(dryRun);
352
+ if (await migrateTsupConfig(dryRun)) migrated = true;
353
+ if (!migrated) {
354
+ consola.warn(`No migrations to apply in ${dirLabel}.`);
355
+ continue;
356
+ }
357
+ migratedAny = true;
358
+ }
359
+ } finally {
360
+ process.chdir(baseCwd);
361
+ }
362
+ if (!migratedAny) {
363
+ consola.error("No migration performed.");
364
+ process.exitCode = 1;
365
+ return;
366
+ }
367
+ consola.info("Migration completed. Installing dependencies...");
368
+ if (dryRun) consola.info("[dry-run] would run:", await getCliCommand(parseNi, []));
369
+ else {
370
+ await run(parseNi, [], { cwd: baseCwd });
371
+ consola.success("Dependencies installed.");
372
+ }
373
+ }
374
+
375
+ //#endregion
376
+ export { name as n, version as r, migrate as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tsdown-migrate",
3
3
  "type": "module",
4
- "version": "0.20.2",
4
+ "version": "0.21.0-beta.1",
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",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@antfu/ni": "^28.2.0",
46
- "@ast-grep/napi": "^0.40.5",
46
+ "@ast-grep/napi": "^0.41.0",
47
47
  "ansis": "^4.2.0",
48
48
  "cac": "^6.7.14",
49
49
  "consola": "^3.4.2",