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