@xylabs/ts-scripts-common 7.5.2 → 7.5.3
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/actions/deplint/checkPackage/checkPackage.mjs +27 -0
- package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +27 -0
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/index.mjs +27 -0
- package/dist/actions/deplint/checkPackage/index.mjs.map +1 -1
- package/dist/actions/deplint/deplint.mjs +18 -0
- package/dist/actions/deplint/deplint.mjs.map +1 -1
- package/dist/actions/deplint/implicitDevDependencies.mjs +25 -0
- package/dist/actions/deplint/implicitDevDependencies.mjs.map +1 -1
- package/dist/actions/deplint/index.mjs +18 -0
- package/dist/actions/deplint/index.mjs.map +1 -1
- package/dist/actions/index.mjs +168 -95
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/packman/convert.mjs +140 -85
- package/dist/actions/packman/convert.mjs.map +1 -1
- package/dist/actions/packman/convertToPnpm.mjs +92 -38
- package/dist/actions/packman/convertToPnpm.mjs.map +1 -1
- package/dist/actions/packman/convertToYarn.mjs +93 -39
- package/dist/actions/packman/convertToYarn.mjs.map +1 -1
- package/dist/actions/packman/index.mjs +140 -85
- package/dist/actions/packman/index.mjs.map +1 -1
- package/dist/actions/packman/rewriteSourceImports.mjs +56 -0
- package/dist/actions/packman/rewriteSourceImports.mjs.map +1 -0
- package/dist/bin/xy.mjs +185 -112
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +187 -114
- package/dist/index.mjs.map +1 -1
- package/dist/xy/common/index.mjs +140 -85
- package/dist/xy/common/index.mjs.map +1 -1
- package/dist/xy/common/packmanCommand.mjs +140 -85
- package/dist/xy/common/packmanCommand.mjs.map +1 -1
- package/dist/xy/index.mjs +185 -112
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/lint/deplintCommand.mjs +18 -0
- package/dist/xy/lint/deplintCommand.mjs.map +1 -1
- package/dist/xy/lint/index.mjs +18 -0
- package/dist/xy/lint/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +185 -112
- package/dist/xy/xy.mjs.map +1 -1
- package/package.json +2 -2
package/dist/xy/common/index.mjs
CHANGED
|
@@ -1142,24 +1142,24 @@ var npmignoreGen = (pkg) => generateIgnoreFiles(filename, pkg);
|
|
|
1142
1142
|
|
|
1143
1143
|
// src/actions/packman/convert.ts
|
|
1144
1144
|
import {
|
|
1145
|
-
existsSync as
|
|
1145
|
+
existsSync as existsSync13,
|
|
1146
1146
|
readdirSync as readdirSync6,
|
|
1147
|
-
readFileSync as
|
|
1147
|
+
readFileSync as readFileSync12,
|
|
1148
1148
|
statSync as statSync3
|
|
1149
1149
|
} from "fs";
|
|
1150
1150
|
import PATH12 from "path";
|
|
1151
|
-
import
|
|
1151
|
+
import chalk21 from "chalk";
|
|
1152
1152
|
|
|
1153
1153
|
// src/actions/packman/convertToPnpm.ts
|
|
1154
1154
|
import {
|
|
1155
|
-
existsSync as
|
|
1155
|
+
existsSync as existsSync11,
|
|
1156
1156
|
mkdirSync as mkdirSync5,
|
|
1157
|
-
readFileSync as
|
|
1157
|
+
readFileSync as readFileSync10,
|
|
1158
1158
|
rmSync as rmSync3,
|
|
1159
|
-
writeFileSync as
|
|
1159
|
+
writeFileSync as writeFileSync8
|
|
1160
1160
|
} from "fs";
|
|
1161
1161
|
import PATH10 from "path";
|
|
1162
|
-
import
|
|
1162
|
+
import chalk19 from "chalk";
|
|
1163
1163
|
|
|
1164
1164
|
// src/actions/packman/rewriteScripts.ts
|
|
1165
1165
|
function rewriteYarnToPnpm(script) {
|
|
@@ -1209,14 +1209,67 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
1209
1209
|
return { ...pkg, scripts: rewritten };
|
|
1210
1210
|
}
|
|
1211
1211
|
|
|
1212
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
1213
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync6 } from "fs";
|
|
1214
|
+
import chalk17 from "chalk";
|
|
1215
|
+
import { globSync } from "glob";
|
|
1216
|
+
var IMPORT_SWAP_MAP = {
|
|
1217
|
+
"yarn-to-pnpm": [
|
|
1218
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
1219
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
1220
|
+
],
|
|
1221
|
+
"pnpm-to-yarn": [
|
|
1222
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
1223
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
1224
|
+
]
|
|
1225
|
+
};
|
|
1226
|
+
var SOURCE_GLOBS = [
|
|
1227
|
+
"**/*.ts",
|
|
1228
|
+
"**/*.tsx",
|
|
1229
|
+
"**/*.mts",
|
|
1230
|
+
"**/*.cts",
|
|
1231
|
+
"**/*.js",
|
|
1232
|
+
"**/*.mjs"
|
|
1233
|
+
];
|
|
1234
|
+
var IGNORE_PATTERNS = [
|
|
1235
|
+
"**/node_modules/**",
|
|
1236
|
+
"**/dist/**",
|
|
1237
|
+
"**/build/**",
|
|
1238
|
+
"**/.yarn/**"
|
|
1239
|
+
];
|
|
1240
|
+
function rewriteSourceImports(cwd, direction) {
|
|
1241
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
1242
|
+
const files = globSync(SOURCE_GLOBS, {
|
|
1243
|
+
cwd,
|
|
1244
|
+
absolute: true,
|
|
1245
|
+
ignore: IGNORE_PATTERNS
|
|
1246
|
+
});
|
|
1247
|
+
let count = 0;
|
|
1248
|
+
for (const file of files) {
|
|
1249
|
+
if (!existsSync9(file)) continue;
|
|
1250
|
+
const original = readFileSync8(file, "utf8");
|
|
1251
|
+
let content = original;
|
|
1252
|
+
for (const [from, to] of swaps) {
|
|
1253
|
+
content = content.replaceAll(from, to);
|
|
1254
|
+
}
|
|
1255
|
+
if (content !== original) {
|
|
1256
|
+
writeFileSync6(file, content, "utf8");
|
|
1257
|
+
count++;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
if (count > 0) {
|
|
1261
|
+
console.log(chalk17.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1212
1265
|
// src/actions/packman/swapTsScriptsDependency.ts
|
|
1213
1266
|
import {
|
|
1214
|
-
existsSync as
|
|
1215
|
-
readFileSync as
|
|
1216
|
-
writeFileSync as
|
|
1267
|
+
existsSync as existsSync10,
|
|
1268
|
+
readFileSync as readFileSync9,
|
|
1269
|
+
writeFileSync as writeFileSync7
|
|
1217
1270
|
} from "fs";
|
|
1218
1271
|
import PATH9 from "path";
|
|
1219
|
-
import
|
|
1272
|
+
import chalk18 from "chalk";
|
|
1220
1273
|
var SWAP_MAP = {
|
|
1221
1274
|
"yarn-to-pnpm": [
|
|
1222
1275
|
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
@@ -1226,8 +1279,8 @@ var SWAP_MAP = {
|
|
|
1226
1279
|
]
|
|
1227
1280
|
};
|
|
1228
1281
|
function swapInPackageJson(pkgPath, direction) {
|
|
1229
|
-
if (!
|
|
1230
|
-
const raw =
|
|
1282
|
+
if (!existsSync10(pkgPath)) return false;
|
|
1283
|
+
const raw = readFileSync9(pkgPath, "utf8");
|
|
1231
1284
|
const pkg = JSON.parse(raw);
|
|
1232
1285
|
let changed = false;
|
|
1233
1286
|
for (const depField of ["dependencies", "devDependencies"]) {
|
|
@@ -1242,7 +1295,7 @@ function swapInPackageJson(pkgPath, direction) {
|
|
|
1242
1295
|
}
|
|
1243
1296
|
}
|
|
1244
1297
|
if (changed) {
|
|
1245
|
-
|
|
1298
|
+
writeFileSync7(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
1246
1299
|
}
|
|
1247
1300
|
return changed;
|
|
1248
1301
|
}
|
|
@@ -1259,7 +1312,7 @@ function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
|
1259
1312
|
}
|
|
1260
1313
|
if (count > 0) {
|
|
1261
1314
|
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
1262
|
-
console.log(
|
|
1315
|
+
console.log(chalk18.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
1263
1316
|
}
|
|
1264
1317
|
}
|
|
1265
1318
|
|
|
@@ -1270,13 +1323,13 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
|
1270
1323
|
for (const pattern of workspacePatterns) {
|
|
1271
1324
|
lines.push(` - '${pattern}'`);
|
|
1272
1325
|
}
|
|
1273
|
-
|
|
1274
|
-
console.log(
|
|
1326
|
+
writeFileSync8(PATH10.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
1327
|
+
console.log(chalk19.green(" Created pnpm-workspace.yaml"));
|
|
1275
1328
|
}
|
|
1276
1329
|
function readPnpmWorkspacePatterns(cwd) {
|
|
1277
1330
|
const wsPath = PATH10.join(cwd, "pnpm-workspace.yaml");
|
|
1278
|
-
if (!
|
|
1279
|
-
const content =
|
|
1331
|
+
if (!existsSync11(wsPath)) return [];
|
|
1332
|
+
const content = readFileSync10(wsPath, "utf8");
|
|
1280
1333
|
const patterns = [];
|
|
1281
1334
|
const lines = content.split("\n");
|
|
1282
1335
|
let inPackages = false;
|
|
@@ -1296,19 +1349,19 @@ function readPnpmWorkspacePatterns(cwd) {
|
|
|
1296
1349
|
}
|
|
1297
1350
|
function updateRootPackageJson(cwd) {
|
|
1298
1351
|
const pkgPath = PATH10.join(cwd, "package.json");
|
|
1299
|
-
const pkg = JSON.parse(
|
|
1352
|
+
const pkg = JSON.parse(readFileSync10(pkgPath, "utf8"));
|
|
1300
1353
|
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd);
|
|
1301
1354
|
delete pkg.workspaces;
|
|
1302
1355
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
1303
1356
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
1304
|
-
|
|
1305
|
-
console.log(
|
|
1357
|
+
writeFileSync8(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1358
|
+
console.log(chalk19.green(" Updated root package.json"));
|
|
1306
1359
|
return workspacePatterns;
|
|
1307
1360
|
}
|
|
1308
1361
|
function updateGitignore(cwd) {
|
|
1309
1362
|
const gitignorePath = PATH10.join(cwd, ".gitignore");
|
|
1310
|
-
if (!
|
|
1311
|
-
let content =
|
|
1363
|
+
if (!existsSync11(gitignorePath)) return;
|
|
1364
|
+
let content = readFileSync10(gitignorePath, "utf8");
|
|
1312
1365
|
const yarnLines = [
|
|
1313
1366
|
".pnp.*",
|
|
1314
1367
|
".pnp",
|
|
@@ -1323,64 +1376,65 @@ function updateGitignore(cwd) {
|
|
|
1323
1376
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
1324
1377
|
}
|
|
1325
1378
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
1326
|
-
|
|
1327
|
-
console.log(
|
|
1379
|
+
writeFileSync8(gitignorePath, content, "utf8");
|
|
1380
|
+
console.log(chalk19.green(" Updated .gitignore"));
|
|
1328
1381
|
}
|
|
1329
1382
|
function deleteYarnArtifacts(cwd) {
|
|
1330
1383
|
const yarnLock = PATH10.join(cwd, "yarn.lock");
|
|
1331
1384
|
const yarnrc = PATH10.join(cwd, ".yarnrc.yml");
|
|
1332
1385
|
const yarnDir = PATH10.join(cwd, ".yarn");
|
|
1333
|
-
if (
|
|
1386
|
+
if (existsSync11(yarnLock)) {
|
|
1334
1387
|
rmSync3(yarnLock);
|
|
1335
|
-
console.log(
|
|
1388
|
+
console.log(chalk19.gray(" Deleted yarn.lock"));
|
|
1336
1389
|
}
|
|
1337
|
-
if (
|
|
1390
|
+
if (existsSync11(yarnrc)) {
|
|
1338
1391
|
rmSync3(yarnrc);
|
|
1339
|
-
console.log(
|
|
1392
|
+
console.log(chalk19.gray(" Deleted .yarnrc.yml"));
|
|
1340
1393
|
}
|
|
1341
|
-
if (
|
|
1394
|
+
if (existsSync11(yarnDir)) {
|
|
1342
1395
|
rmSync3(yarnDir, { force: true, recursive: true });
|
|
1343
|
-
console.log(
|
|
1396
|
+
console.log(chalk19.gray(" Deleted .yarn/"));
|
|
1344
1397
|
}
|
|
1345
1398
|
}
|
|
1346
1399
|
function createNpmrc(cwd) {
|
|
1347
1400
|
const npmrcPath = PATH10.join(cwd, ".npmrc");
|
|
1348
|
-
if (
|
|
1401
|
+
if (existsSync11(npmrcPath)) return;
|
|
1349
1402
|
mkdirSync5(PATH10.dirname(npmrcPath), { recursive: true });
|
|
1350
|
-
|
|
1351
|
-
console.log(
|
|
1403
|
+
writeFileSync8(npmrcPath, "", "utf8");
|
|
1404
|
+
console.log(chalk19.green(" Created .npmrc"));
|
|
1352
1405
|
}
|
|
1353
1406
|
function convertToPnpm(cwd, workspacePackageJsonPaths) {
|
|
1354
|
-
console.log(
|
|
1407
|
+
console.log(chalk19.blue("\nConverting to pnpm...\n"));
|
|
1355
1408
|
const workspacePatterns = updateRootPackageJson(cwd);
|
|
1356
1409
|
createPnpmWorkspaceYaml(cwd, workspacePatterns);
|
|
1357
1410
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
1358
1411
|
const fullPath = PATH10.resolve(cwd, pkgPath, "package.json");
|
|
1359
|
-
if (!
|
|
1360
|
-
const pkg = JSON.parse(
|
|
1412
|
+
if (!existsSync11(fullPath)) continue;
|
|
1413
|
+
const pkg = JSON.parse(readFileSync10(fullPath, "utf8"));
|
|
1361
1414
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
1362
1415
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
1363
|
-
|
|
1416
|
+
writeFileSync8(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1364
1417
|
}
|
|
1365
1418
|
}
|
|
1366
|
-
console.log(
|
|
1419
|
+
console.log(chalk19.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
1367
1420
|
updateGitignore(cwd);
|
|
1368
1421
|
createNpmrc(cwd);
|
|
1369
1422
|
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
1423
|
+
rewriteSourceImports(cwd, "yarn-to-pnpm");
|
|
1370
1424
|
deleteYarnArtifacts(cwd);
|
|
1371
|
-
console.log(
|
|
1425
|
+
console.log(chalk19.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
1372
1426
|
return 0;
|
|
1373
1427
|
}
|
|
1374
1428
|
|
|
1375
1429
|
// src/actions/packman/convertToYarn.ts
|
|
1376
1430
|
import {
|
|
1377
|
-
existsSync as
|
|
1378
|
-
readFileSync as
|
|
1431
|
+
existsSync as existsSync12,
|
|
1432
|
+
readFileSync as readFileSync11,
|
|
1379
1433
|
rmSync as rmSync4,
|
|
1380
|
-
writeFileSync as
|
|
1434
|
+
writeFileSync as writeFileSync9
|
|
1381
1435
|
} from "fs";
|
|
1382
1436
|
import PATH11 from "path";
|
|
1383
|
-
import
|
|
1437
|
+
import chalk20 from "chalk";
|
|
1384
1438
|
var YARN_VERSION = "4.13.0";
|
|
1385
1439
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
1386
1440
|
|
|
@@ -1403,8 +1457,8 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
1403
1457
|
`;
|
|
1404
1458
|
function readPnpmWorkspacePatterns2(cwd) {
|
|
1405
1459
|
const wsPath = PATH11.join(cwd, "pnpm-workspace.yaml");
|
|
1406
|
-
if (!
|
|
1407
|
-
const content =
|
|
1460
|
+
if (!existsSync12(wsPath)) return [];
|
|
1461
|
+
const content = readFileSync11(wsPath, "utf8");
|
|
1408
1462
|
const patterns = [];
|
|
1409
1463
|
const lines = content.split("\n");
|
|
1410
1464
|
let inPackages = false;
|
|
@@ -1424,102 +1478,103 @@ function readPnpmWorkspacePatterns2(cwd) {
|
|
|
1424
1478
|
}
|
|
1425
1479
|
function updateRootPackageJson2(cwd, workspacePatterns) {
|
|
1426
1480
|
const pkgPath = PATH11.join(cwd, "package.json");
|
|
1427
|
-
const pkg = JSON.parse(
|
|
1481
|
+
const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
|
|
1428
1482
|
pkg.workspaces = workspacePatterns;
|
|
1429
1483
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
1430
1484
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
1431
|
-
|
|
1432
|
-
console.log(
|
|
1485
|
+
writeFileSync9(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1486
|
+
console.log(chalk20.green(" Updated root package.json"));
|
|
1433
1487
|
}
|
|
1434
1488
|
function updateGitignore2(cwd) {
|
|
1435
1489
|
const gitignorePath = PATH11.join(cwd, ".gitignore");
|
|
1436
|
-
let content =
|
|
1490
|
+
let content = existsSync12(gitignorePath) ? readFileSync11(gitignorePath, "utf8") : "";
|
|
1437
1491
|
if (!content.includes(".yarn/*")) {
|
|
1438
1492
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
1439
1493
|
}
|
|
1440
|
-
|
|
1441
|
-
console.log(
|
|
1494
|
+
writeFileSync9(gitignorePath, content, "utf8");
|
|
1495
|
+
console.log(chalk20.green(" Updated .gitignore"));
|
|
1442
1496
|
}
|
|
1443
1497
|
function deletePnpmArtifacts(cwd) {
|
|
1444
1498
|
const lockfile = PATH11.join(cwd, "pnpm-lock.yaml");
|
|
1445
1499
|
const workspaceYaml = PATH11.join(cwd, "pnpm-workspace.yaml");
|
|
1446
1500
|
const npmrc = PATH11.join(cwd, ".npmrc");
|
|
1447
|
-
if (
|
|
1501
|
+
if (existsSync12(lockfile)) {
|
|
1448
1502
|
rmSync4(lockfile);
|
|
1449
|
-
console.log(
|
|
1503
|
+
console.log(chalk20.gray(" Deleted pnpm-lock.yaml"));
|
|
1450
1504
|
}
|
|
1451
|
-
if (
|
|
1505
|
+
if (existsSync12(workspaceYaml)) {
|
|
1452
1506
|
rmSync4(workspaceYaml);
|
|
1453
|
-
console.log(
|
|
1507
|
+
console.log(chalk20.gray(" Deleted pnpm-workspace.yaml"));
|
|
1454
1508
|
}
|
|
1455
|
-
if (
|
|
1456
|
-
const content =
|
|
1509
|
+
if (existsSync12(npmrc)) {
|
|
1510
|
+
const content = readFileSync11(npmrc, "utf8");
|
|
1457
1511
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
1458
1512
|
rmSync4(npmrc);
|
|
1459
|
-
console.log(
|
|
1513
|
+
console.log(chalk20.gray(" Deleted .npmrc"));
|
|
1460
1514
|
}
|
|
1461
1515
|
}
|
|
1462
1516
|
}
|
|
1463
1517
|
function createYarnrc(cwd) {
|
|
1464
1518
|
const yarnrcPath = PATH11.join(cwd, ".yarnrc.yml");
|
|
1465
|
-
if (
|
|
1466
|
-
|
|
1467
|
-
console.log(
|
|
1519
|
+
if (existsSync12(yarnrcPath)) return;
|
|
1520
|
+
writeFileSync9(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
1521
|
+
console.log(chalk20.green(" Created .yarnrc.yml"));
|
|
1468
1522
|
}
|
|
1469
1523
|
function readWorkspacePatternsFromPackageJson(cwd) {
|
|
1470
1524
|
const pkgPath = PATH11.join(cwd, "package.json");
|
|
1471
|
-
if (!
|
|
1472
|
-
const pkg = JSON.parse(
|
|
1525
|
+
if (!existsSync12(pkgPath)) return [];
|
|
1526
|
+
const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
|
|
1473
1527
|
return pkg.workspaces ?? [];
|
|
1474
1528
|
}
|
|
1475
1529
|
function convertToYarn(cwd, workspacePackageJsonPaths) {
|
|
1476
|
-
console.log(
|
|
1530
|
+
console.log(chalk20.blue("\nConverting to yarn...\n"));
|
|
1477
1531
|
const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
|
|
1478
1532
|
if (workspacePatterns.length === 0) {
|
|
1479
1533
|
const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
|
|
1480
1534
|
if (fromPkg.length > 0) {
|
|
1481
1535
|
workspacePatterns.push(...fromPkg);
|
|
1482
1536
|
} else {
|
|
1483
|
-
console.warn(
|
|
1537
|
+
console.warn(chalk20.yellow(" No workspace patterns found"));
|
|
1484
1538
|
}
|
|
1485
1539
|
}
|
|
1486
1540
|
updateRootPackageJson2(cwd, workspacePatterns);
|
|
1487
1541
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
1488
1542
|
const fullPath = PATH11.resolve(cwd, pkgPath, "package.json");
|
|
1489
|
-
if (!
|
|
1490
|
-
const pkg = JSON.parse(
|
|
1543
|
+
if (!existsSync12(fullPath)) continue;
|
|
1544
|
+
const pkg = JSON.parse(readFileSync11(fullPath, "utf8"));
|
|
1491
1545
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
1492
1546
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
1493
|
-
|
|
1547
|
+
writeFileSync9(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1494
1548
|
}
|
|
1495
1549
|
}
|
|
1496
|
-
console.log(
|
|
1550
|
+
console.log(chalk20.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
1497
1551
|
updateGitignore2(cwd);
|
|
1498
1552
|
createYarnrc(cwd);
|
|
1499
1553
|
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
1554
|
+
rewriteSourceImports(cwd, "pnpm-to-yarn");
|
|
1500
1555
|
deletePnpmArtifacts(cwd);
|
|
1501
|
-
console.log(
|
|
1556
|
+
console.log(chalk20.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
1502
1557
|
return 0;
|
|
1503
1558
|
}
|
|
1504
1559
|
|
|
1505
1560
|
// src/actions/packman/convert.ts
|
|
1506
1561
|
function detectCurrentPM(cwd) {
|
|
1507
|
-
if (
|
|
1562
|
+
if (existsSync13(PATH12.join(cwd, "pnpm-lock.yaml")) || existsSync13(PATH12.join(cwd, "pnpm-workspace.yaml"))) {
|
|
1508
1563
|
return "pnpm";
|
|
1509
1564
|
}
|
|
1510
|
-
if (
|
|
1565
|
+
if (existsSync13(PATH12.join(cwd, "yarn.lock")) || existsSync13(PATH12.join(cwd, ".yarnrc.yml"))) {
|
|
1511
1566
|
return "yarn";
|
|
1512
1567
|
}
|
|
1513
1568
|
return "unknown";
|
|
1514
1569
|
}
|
|
1515
1570
|
function findWorkspacePackagePaths(cwd) {
|
|
1516
1571
|
const pkgPath = PATH12.join(cwd, "package.json");
|
|
1517
|
-
const pkg = JSON.parse(
|
|
1572
|
+
const pkg = JSON.parse(readFileSync12(pkgPath, "utf8"));
|
|
1518
1573
|
let patterns = pkg.workspaces ?? [];
|
|
1519
1574
|
if (patterns.length === 0) {
|
|
1520
1575
|
const wsPath = PATH12.join(cwd, "pnpm-workspace.yaml");
|
|
1521
|
-
if (
|
|
1522
|
-
const content =
|
|
1576
|
+
if (existsSync13(wsPath)) {
|
|
1577
|
+
const content = readFileSync12(wsPath, "utf8");
|
|
1523
1578
|
const lines = content.split("\n");
|
|
1524
1579
|
let inPackages = false;
|
|
1525
1580
|
for (const line of lines) {
|
|
@@ -1550,14 +1605,14 @@ function resolveWorkspaceGlob(cwd, pattern) {
|
|
|
1550
1605
|
function walkGlob(basePath, parts, currentPath) {
|
|
1551
1606
|
if (parts.length === 0) {
|
|
1552
1607
|
const fullPath = PATH12.join(basePath, currentPath);
|
|
1553
|
-
if (
|
|
1608
|
+
if (existsSync13(PATH12.join(fullPath, "package.json"))) {
|
|
1554
1609
|
return [currentPath];
|
|
1555
1610
|
}
|
|
1556
1611
|
return [];
|
|
1557
1612
|
}
|
|
1558
1613
|
const [part, ...rest] = parts;
|
|
1559
1614
|
const dirPath = PATH12.join(basePath, currentPath);
|
|
1560
|
-
if (!
|
|
1615
|
+
if (!existsSync13(dirPath) || !statSync3(dirPath).isDirectory()) {
|
|
1561
1616
|
return [];
|
|
1562
1617
|
}
|
|
1563
1618
|
if (part === "*" || part === "**") {
|
|
@@ -1585,25 +1640,25 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
1585
1640
|
function convert({ target, verbose }) {
|
|
1586
1641
|
const validTargets = ["pnpm", "yarn"];
|
|
1587
1642
|
if (!validTargets.includes(target)) {
|
|
1588
|
-
console.error(
|
|
1643
|
+
console.error(chalk21.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
1589
1644
|
return 1;
|
|
1590
1645
|
}
|
|
1591
1646
|
const cwd = process.cwd();
|
|
1592
1647
|
const currentPM = detectCurrentPM(cwd);
|
|
1593
1648
|
if (verbose) {
|
|
1594
|
-
console.log(
|
|
1595
|
-
console.log(
|
|
1649
|
+
console.log(chalk21.gray(`Current package manager: ${currentPM}`));
|
|
1650
|
+
console.log(chalk21.gray(`Target package manager: ${target}`));
|
|
1596
1651
|
}
|
|
1597
1652
|
if (currentPM === target) {
|
|
1598
|
-
console.log(
|
|
1653
|
+
console.log(chalk21.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
1599
1654
|
}
|
|
1600
1655
|
if (currentPM === "unknown") {
|
|
1601
|
-
console.error(
|
|
1656
|
+
console.error(chalk21.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
1602
1657
|
return 1;
|
|
1603
1658
|
}
|
|
1604
1659
|
const workspacePaths = findWorkspacePackagePaths(cwd);
|
|
1605
1660
|
if (verbose) {
|
|
1606
|
-
console.log(
|
|
1661
|
+
console.log(chalk21.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
1607
1662
|
}
|
|
1608
1663
|
if (target === "pnpm") {
|
|
1609
1664
|
return convertToPnpm(cwd, workspacePaths);
|