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