@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/actions/index.mjs
CHANGED
|
@@ -1813,6 +1813,8 @@ function hasImportPlugin({ location, allDependencies }) {
|
|
|
1813
1813
|
return false;
|
|
1814
1814
|
}
|
|
1815
1815
|
var hasVitest = ({ allDependencies }) => allDependencies.includes("vitest");
|
|
1816
|
+
var isYarnRepo = () => detectPackageManager() === "yarn";
|
|
1817
|
+
var isPnpmRepo = () => detectPackageManager() === "pnpm";
|
|
1816
1818
|
var rules = [
|
|
1817
1819
|
{
|
|
1818
1820
|
package: "typescript",
|
|
@@ -1829,6 +1831,22 @@ var rules = [
|
|
|
1829
1831
|
{
|
|
1830
1832
|
package: "@vitest/coverage-v8",
|
|
1831
1833
|
isNeeded: hasVitest
|
|
1834
|
+
},
|
|
1835
|
+
{
|
|
1836
|
+
package: "@xylabs/ts-scripts-yarn3",
|
|
1837
|
+
isNeeded: isYarnRepo
|
|
1838
|
+
},
|
|
1839
|
+
{
|
|
1840
|
+
package: "@xylabs/ts-scripts-react-yarn3",
|
|
1841
|
+
isNeeded: isYarnRepo
|
|
1842
|
+
},
|
|
1843
|
+
{
|
|
1844
|
+
package: "@xylabs/ts-scripts-pnpm",
|
|
1845
|
+
isNeeded: isPnpmRepo
|
|
1846
|
+
},
|
|
1847
|
+
{
|
|
1848
|
+
package: "@xylabs/ts-scripts-react-pnpm",
|
|
1849
|
+
isNeeded: isPnpmRepo
|
|
1832
1850
|
}
|
|
1833
1851
|
];
|
|
1834
1852
|
function getImplicitDevDependencies(context) {
|
|
@@ -3488,24 +3506,24 @@ function packageLintMonorepo(fix2 = false) {
|
|
|
3488
3506
|
|
|
3489
3507
|
// src/actions/packman/convert.ts
|
|
3490
3508
|
import {
|
|
3491
|
-
existsSync as
|
|
3509
|
+
existsSync as existsSync15,
|
|
3492
3510
|
readdirSync as readdirSync7,
|
|
3493
|
-
readFileSync as
|
|
3511
|
+
readFileSync as readFileSync15,
|
|
3494
3512
|
statSync as statSync3
|
|
3495
3513
|
} from "fs";
|
|
3496
|
-
import
|
|
3497
|
-
import
|
|
3514
|
+
import PATH14 from "path";
|
|
3515
|
+
import chalk48 from "chalk";
|
|
3498
3516
|
|
|
3499
3517
|
// src/actions/packman/convertToPnpm.ts
|
|
3500
3518
|
import {
|
|
3501
|
-
existsSync as
|
|
3519
|
+
existsSync as existsSync13,
|
|
3502
3520
|
mkdirSync as mkdirSync5,
|
|
3503
|
-
readFileSync as
|
|
3521
|
+
readFileSync as readFileSync13,
|
|
3504
3522
|
rmSync as rmSync3,
|
|
3505
|
-
writeFileSync as
|
|
3523
|
+
writeFileSync as writeFileSync10
|
|
3506
3524
|
} from "fs";
|
|
3507
|
-
import
|
|
3508
|
-
import
|
|
3525
|
+
import PATH12 from "path";
|
|
3526
|
+
import chalk46 from "chalk";
|
|
3509
3527
|
|
|
3510
3528
|
// src/actions/packman/rewriteScripts.ts
|
|
3511
3529
|
function rewriteYarnToPnpm(script) {
|
|
@@ -3555,6 +3573,113 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
3555
3573
|
return { ...pkg, scripts: rewritten };
|
|
3556
3574
|
}
|
|
3557
3575
|
|
|
3576
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
3577
|
+
import { existsSync as existsSync11, readFileSync as readFileSync11, writeFileSync as writeFileSync8 } from "fs";
|
|
3578
|
+
import chalk44 from "chalk";
|
|
3579
|
+
import { globSync as globSync3 } from "glob";
|
|
3580
|
+
var IMPORT_SWAP_MAP = {
|
|
3581
|
+
"yarn-to-pnpm": [
|
|
3582
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
3583
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
3584
|
+
],
|
|
3585
|
+
"pnpm-to-yarn": [
|
|
3586
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
3587
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
3588
|
+
]
|
|
3589
|
+
};
|
|
3590
|
+
var SOURCE_GLOBS = [
|
|
3591
|
+
"**/*.ts",
|
|
3592
|
+
"**/*.tsx",
|
|
3593
|
+
"**/*.mts",
|
|
3594
|
+
"**/*.cts",
|
|
3595
|
+
"**/*.js",
|
|
3596
|
+
"**/*.mjs"
|
|
3597
|
+
];
|
|
3598
|
+
var IGNORE_PATTERNS = [
|
|
3599
|
+
"**/node_modules/**",
|
|
3600
|
+
"**/dist/**",
|
|
3601
|
+
"**/build/**",
|
|
3602
|
+
"**/.yarn/**"
|
|
3603
|
+
];
|
|
3604
|
+
function rewriteSourceImports(cwd5, direction) {
|
|
3605
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
3606
|
+
const files = globSync3(SOURCE_GLOBS, {
|
|
3607
|
+
cwd: cwd5,
|
|
3608
|
+
absolute: true,
|
|
3609
|
+
ignore: IGNORE_PATTERNS
|
|
3610
|
+
});
|
|
3611
|
+
let count = 0;
|
|
3612
|
+
for (const file of files) {
|
|
3613
|
+
if (!existsSync11(file)) continue;
|
|
3614
|
+
const original = readFileSync11(file, "utf8");
|
|
3615
|
+
let content = original;
|
|
3616
|
+
for (const [from, to] of swaps) {
|
|
3617
|
+
content = content.replaceAll(from, to);
|
|
3618
|
+
}
|
|
3619
|
+
if (content !== original) {
|
|
3620
|
+
writeFileSync8(file, content, "utf8");
|
|
3621
|
+
count++;
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
if (count > 0) {
|
|
3625
|
+
console.log(chalk44.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
// src/actions/packman/swapTsScriptsDependency.ts
|
|
3630
|
+
import {
|
|
3631
|
+
existsSync as existsSync12,
|
|
3632
|
+
readFileSync as readFileSync12,
|
|
3633
|
+
writeFileSync as writeFileSync9
|
|
3634
|
+
} from "fs";
|
|
3635
|
+
import PATH11 from "path";
|
|
3636
|
+
import chalk45 from "chalk";
|
|
3637
|
+
var SWAP_MAP = {
|
|
3638
|
+
"yarn-to-pnpm": [
|
|
3639
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
3640
|
+
],
|
|
3641
|
+
"pnpm-to-yarn": [
|
|
3642
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"]
|
|
3643
|
+
]
|
|
3644
|
+
};
|
|
3645
|
+
function swapInPackageJson(pkgPath, direction) {
|
|
3646
|
+
if (!existsSync12(pkgPath)) return false;
|
|
3647
|
+
const raw = readFileSync12(pkgPath, "utf8");
|
|
3648
|
+
const pkg = JSON.parse(raw);
|
|
3649
|
+
let changed = false;
|
|
3650
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
3651
|
+
const deps = pkg[depField];
|
|
3652
|
+
if (!deps) continue;
|
|
3653
|
+
for (const [from, to] of SWAP_MAP[direction]) {
|
|
3654
|
+
if (deps[from]) {
|
|
3655
|
+
deps[to] = deps[from];
|
|
3656
|
+
delete deps[from];
|
|
3657
|
+
changed = true;
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
}
|
|
3661
|
+
if (changed) {
|
|
3662
|
+
writeFileSync9(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
3663
|
+
}
|
|
3664
|
+
return changed;
|
|
3665
|
+
}
|
|
3666
|
+
function swapTsScriptsDependency(cwd5, workspacePackageJsonPaths, direction) {
|
|
3667
|
+
let count = 0;
|
|
3668
|
+
if (swapInPackageJson(PATH11.join(cwd5, "package.json"), direction)) {
|
|
3669
|
+
count++;
|
|
3670
|
+
}
|
|
3671
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
3672
|
+
const fullPath = PATH11.resolve(cwd5, pkgPath, "package.json");
|
|
3673
|
+
if (swapInPackageJson(fullPath, direction)) {
|
|
3674
|
+
count++;
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
if (count > 0) {
|
|
3678
|
+
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
3679
|
+
console.log(chalk45.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3558
3683
|
// src/actions/packman/convertToPnpm.ts
|
|
3559
3684
|
var PNPM_VERSION = "10.12.1";
|
|
3560
3685
|
function createPnpmWorkspaceYaml(cwd5, workspacePatterns) {
|
|
@@ -3562,24 +3687,45 @@ function createPnpmWorkspaceYaml(cwd5, workspacePatterns) {
|
|
|
3562
3687
|
for (const pattern of workspacePatterns) {
|
|
3563
3688
|
lines.push(` - '${pattern}'`);
|
|
3564
3689
|
}
|
|
3565
|
-
|
|
3566
|
-
console.log(
|
|
3690
|
+
writeFileSync10(PATH12.join(cwd5, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
3691
|
+
console.log(chalk46.green(" Created pnpm-workspace.yaml"));
|
|
3692
|
+
}
|
|
3693
|
+
function readPnpmWorkspacePatterns(cwd5) {
|
|
3694
|
+
const wsPath = PATH12.join(cwd5, "pnpm-workspace.yaml");
|
|
3695
|
+
if (!existsSync13(wsPath)) return [];
|
|
3696
|
+
const content = readFileSync13(wsPath, "utf8");
|
|
3697
|
+
const patterns = [];
|
|
3698
|
+
const lines = content.split("\n");
|
|
3699
|
+
let inPackages = false;
|
|
3700
|
+
for (const line of lines) {
|
|
3701
|
+
if (line.trim() === "packages:") {
|
|
3702
|
+
inPackages = true;
|
|
3703
|
+
continue;
|
|
3704
|
+
}
|
|
3705
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
3706
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
3707
|
+
if (pattern) patterns.push(pattern);
|
|
3708
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
3709
|
+
inPackages = false;
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
return patterns;
|
|
3567
3713
|
}
|
|
3568
3714
|
function updateRootPackageJson(cwd5) {
|
|
3569
|
-
const pkgPath =
|
|
3570
|
-
const pkg = JSON.parse(
|
|
3571
|
-
const workspacePatterns = pkg.workspaces ??
|
|
3715
|
+
const pkgPath = PATH12.join(cwd5, "package.json");
|
|
3716
|
+
const pkg = JSON.parse(readFileSync13(pkgPath, "utf8"));
|
|
3717
|
+
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd5);
|
|
3572
3718
|
delete pkg.workspaces;
|
|
3573
3719
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
3574
3720
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
3575
|
-
|
|
3576
|
-
console.log(
|
|
3721
|
+
writeFileSync10(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3722
|
+
console.log(chalk46.green(" Updated root package.json"));
|
|
3577
3723
|
return workspacePatterns;
|
|
3578
3724
|
}
|
|
3579
3725
|
function updateGitignore(cwd5) {
|
|
3580
|
-
const gitignorePath =
|
|
3581
|
-
if (!
|
|
3582
|
-
let content =
|
|
3726
|
+
const gitignorePath = PATH12.join(cwd5, ".gitignore");
|
|
3727
|
+
if (!existsSync13(gitignorePath)) return;
|
|
3728
|
+
let content = readFileSync13(gitignorePath, "utf8");
|
|
3583
3729
|
const yarnLines = [
|
|
3584
3730
|
".pnp.*",
|
|
3585
3731
|
".pnp",
|
|
@@ -3594,63 +3740,65 @@ function updateGitignore(cwd5) {
|
|
|
3594
3740
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
3595
3741
|
}
|
|
3596
3742
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
3597
|
-
|
|
3598
|
-
console.log(
|
|
3743
|
+
writeFileSync10(gitignorePath, content, "utf8");
|
|
3744
|
+
console.log(chalk46.green(" Updated .gitignore"));
|
|
3599
3745
|
}
|
|
3600
3746
|
function deleteYarnArtifacts(cwd5) {
|
|
3601
|
-
const yarnLock =
|
|
3602
|
-
const yarnrc =
|
|
3603
|
-
const yarnDir =
|
|
3604
|
-
if (
|
|
3747
|
+
const yarnLock = PATH12.join(cwd5, "yarn.lock");
|
|
3748
|
+
const yarnrc = PATH12.join(cwd5, ".yarnrc.yml");
|
|
3749
|
+
const yarnDir = PATH12.join(cwd5, ".yarn");
|
|
3750
|
+
if (existsSync13(yarnLock)) {
|
|
3605
3751
|
rmSync3(yarnLock);
|
|
3606
|
-
console.log(
|
|
3752
|
+
console.log(chalk46.gray(" Deleted yarn.lock"));
|
|
3607
3753
|
}
|
|
3608
|
-
if (
|
|
3754
|
+
if (existsSync13(yarnrc)) {
|
|
3609
3755
|
rmSync3(yarnrc);
|
|
3610
|
-
console.log(
|
|
3756
|
+
console.log(chalk46.gray(" Deleted .yarnrc.yml"));
|
|
3611
3757
|
}
|
|
3612
|
-
if (
|
|
3758
|
+
if (existsSync13(yarnDir)) {
|
|
3613
3759
|
rmSync3(yarnDir, { force: true, recursive: true });
|
|
3614
|
-
console.log(
|
|
3760
|
+
console.log(chalk46.gray(" Deleted .yarn/"));
|
|
3615
3761
|
}
|
|
3616
3762
|
}
|
|
3617
3763
|
function createNpmrc(cwd5) {
|
|
3618
|
-
const npmrcPath =
|
|
3619
|
-
if (
|
|
3620
|
-
mkdirSync5(
|
|
3621
|
-
|
|
3622
|
-
console.log(
|
|
3764
|
+
const npmrcPath = PATH12.join(cwd5, ".npmrc");
|
|
3765
|
+
if (existsSync13(npmrcPath)) return;
|
|
3766
|
+
mkdirSync5(PATH12.dirname(npmrcPath), { recursive: true });
|
|
3767
|
+
writeFileSync10(npmrcPath, "", "utf8");
|
|
3768
|
+
console.log(chalk46.green(" Created .npmrc"));
|
|
3623
3769
|
}
|
|
3624
3770
|
function convertToPnpm(cwd5, workspacePackageJsonPaths) {
|
|
3625
|
-
console.log(
|
|
3771
|
+
console.log(chalk46.blue("\nConverting to pnpm...\n"));
|
|
3626
3772
|
const workspacePatterns = updateRootPackageJson(cwd5);
|
|
3627
3773
|
createPnpmWorkspaceYaml(cwd5, workspacePatterns);
|
|
3628
3774
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
3629
|
-
const fullPath =
|
|
3630
|
-
if (!
|
|
3631
|
-
const pkg = JSON.parse(
|
|
3775
|
+
const fullPath = PATH12.resolve(cwd5, pkgPath, "package.json");
|
|
3776
|
+
if (!existsSync13(fullPath)) continue;
|
|
3777
|
+
const pkg = JSON.parse(readFileSync13(fullPath, "utf8"));
|
|
3632
3778
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
3633
3779
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
3634
|
-
|
|
3780
|
+
writeFileSync10(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3635
3781
|
}
|
|
3636
3782
|
}
|
|
3637
|
-
console.log(
|
|
3783
|
+
console.log(chalk46.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
3638
3784
|
updateGitignore(cwd5);
|
|
3639
3785
|
createNpmrc(cwd5);
|
|
3786
|
+
swapTsScriptsDependency(cwd5, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
3787
|
+
rewriteSourceImports(cwd5, "yarn-to-pnpm");
|
|
3640
3788
|
deleteYarnArtifacts(cwd5);
|
|
3641
|
-
console.log(
|
|
3789
|
+
console.log(chalk46.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
3642
3790
|
return 0;
|
|
3643
3791
|
}
|
|
3644
3792
|
|
|
3645
3793
|
// src/actions/packman/convertToYarn.ts
|
|
3646
3794
|
import {
|
|
3647
|
-
existsSync as
|
|
3648
|
-
readFileSync as
|
|
3795
|
+
existsSync as existsSync14,
|
|
3796
|
+
readFileSync as readFileSync14,
|
|
3649
3797
|
rmSync as rmSync4,
|
|
3650
|
-
writeFileSync as
|
|
3798
|
+
writeFileSync as writeFileSync11
|
|
3651
3799
|
} from "fs";
|
|
3652
|
-
import
|
|
3653
|
-
import
|
|
3800
|
+
import PATH13 from "path";
|
|
3801
|
+
import chalk47 from "chalk";
|
|
3654
3802
|
var YARN_VERSION = "4.13.0";
|
|
3655
3803
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
3656
3804
|
|
|
@@ -3671,10 +3819,10 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
3671
3819
|
!.yarn/sdks
|
|
3672
3820
|
!.yarn/versions
|
|
3673
3821
|
`;
|
|
3674
|
-
function
|
|
3675
|
-
const wsPath =
|
|
3676
|
-
if (!
|
|
3677
|
-
const content =
|
|
3822
|
+
function readPnpmWorkspacePatterns2(cwd5) {
|
|
3823
|
+
const wsPath = PATH13.join(cwd5, "pnpm-workspace.yaml");
|
|
3824
|
+
if (!existsSync14(wsPath)) return [];
|
|
3825
|
+
const content = readFileSync14(wsPath, "utf8");
|
|
3678
3826
|
const patterns = [];
|
|
3679
3827
|
const lines = content.split("\n");
|
|
3680
3828
|
let inPackages = false;
|
|
@@ -3693,91 +3841,104 @@ function readPnpmWorkspacePatterns(cwd5) {
|
|
|
3693
3841
|
return patterns;
|
|
3694
3842
|
}
|
|
3695
3843
|
function updateRootPackageJson2(cwd5, workspacePatterns) {
|
|
3696
|
-
const pkgPath =
|
|
3697
|
-
const pkg = JSON.parse(
|
|
3844
|
+
const pkgPath = PATH13.join(cwd5, "package.json");
|
|
3845
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
3698
3846
|
pkg.workspaces = workspacePatterns;
|
|
3699
3847
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
3700
3848
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
3701
|
-
|
|
3702
|
-
console.log(
|
|
3849
|
+
writeFileSync11(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3850
|
+
console.log(chalk47.green(" Updated root package.json"));
|
|
3703
3851
|
}
|
|
3704
3852
|
function updateGitignore2(cwd5) {
|
|
3705
|
-
const gitignorePath =
|
|
3706
|
-
let content =
|
|
3853
|
+
const gitignorePath = PATH13.join(cwd5, ".gitignore");
|
|
3854
|
+
let content = existsSync14(gitignorePath) ? readFileSync14(gitignorePath, "utf8") : "";
|
|
3707
3855
|
if (!content.includes(".yarn/*")) {
|
|
3708
3856
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
3709
3857
|
}
|
|
3710
|
-
|
|
3711
|
-
console.log(
|
|
3858
|
+
writeFileSync11(gitignorePath, content, "utf8");
|
|
3859
|
+
console.log(chalk47.green(" Updated .gitignore"));
|
|
3712
3860
|
}
|
|
3713
3861
|
function deletePnpmArtifacts(cwd5) {
|
|
3714
|
-
const lockfile =
|
|
3715
|
-
const workspaceYaml =
|
|
3716
|
-
const npmrc =
|
|
3717
|
-
if (
|
|
3862
|
+
const lockfile = PATH13.join(cwd5, "pnpm-lock.yaml");
|
|
3863
|
+
const workspaceYaml = PATH13.join(cwd5, "pnpm-workspace.yaml");
|
|
3864
|
+
const npmrc = PATH13.join(cwd5, ".npmrc");
|
|
3865
|
+
if (existsSync14(lockfile)) {
|
|
3718
3866
|
rmSync4(lockfile);
|
|
3719
|
-
console.log(
|
|
3867
|
+
console.log(chalk47.gray(" Deleted pnpm-lock.yaml"));
|
|
3720
3868
|
}
|
|
3721
|
-
if (
|
|
3869
|
+
if (existsSync14(workspaceYaml)) {
|
|
3722
3870
|
rmSync4(workspaceYaml);
|
|
3723
|
-
console.log(
|
|
3871
|
+
console.log(chalk47.gray(" Deleted pnpm-workspace.yaml"));
|
|
3724
3872
|
}
|
|
3725
|
-
if (
|
|
3726
|
-
const content =
|
|
3873
|
+
if (existsSync14(npmrc)) {
|
|
3874
|
+
const content = readFileSync14(npmrc, "utf8");
|
|
3727
3875
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
3728
3876
|
rmSync4(npmrc);
|
|
3729
|
-
console.log(
|
|
3877
|
+
console.log(chalk47.gray(" Deleted .npmrc"));
|
|
3730
3878
|
}
|
|
3731
3879
|
}
|
|
3732
3880
|
}
|
|
3733
3881
|
function createYarnrc(cwd5) {
|
|
3734
|
-
const yarnrcPath =
|
|
3735
|
-
if (
|
|
3736
|
-
|
|
3737
|
-
console.log(
|
|
3882
|
+
const yarnrcPath = PATH13.join(cwd5, ".yarnrc.yml");
|
|
3883
|
+
if (existsSync14(yarnrcPath)) return;
|
|
3884
|
+
writeFileSync11(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
3885
|
+
console.log(chalk47.green(" Created .yarnrc.yml"));
|
|
3886
|
+
}
|
|
3887
|
+
function readWorkspacePatternsFromPackageJson(cwd5) {
|
|
3888
|
+
const pkgPath = PATH13.join(cwd5, "package.json");
|
|
3889
|
+
if (!existsSync14(pkgPath)) return [];
|
|
3890
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
3891
|
+
return pkg.workspaces ?? [];
|
|
3738
3892
|
}
|
|
3739
3893
|
function convertToYarn(cwd5, workspacePackageJsonPaths) {
|
|
3740
|
-
console.log(
|
|
3741
|
-
const workspacePatterns =
|
|
3894
|
+
console.log(chalk47.blue("\nConverting to yarn...\n"));
|
|
3895
|
+
const workspacePatterns = readPnpmWorkspacePatterns2(cwd5);
|
|
3742
3896
|
if (workspacePatterns.length === 0) {
|
|
3743
|
-
|
|
3897
|
+
const fromPkg = readWorkspacePatternsFromPackageJson(cwd5);
|
|
3898
|
+
if (fromPkg.length > 0) {
|
|
3899
|
+
workspacePatterns.push(...fromPkg);
|
|
3900
|
+
} else {
|
|
3901
|
+
console.warn(chalk47.yellow(" No workspace patterns found"));
|
|
3902
|
+
}
|
|
3744
3903
|
}
|
|
3745
3904
|
updateRootPackageJson2(cwd5, workspacePatterns);
|
|
3746
3905
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
3747
|
-
const fullPath =
|
|
3748
|
-
if (!
|
|
3749
|
-
const pkg = JSON.parse(
|
|
3906
|
+
const fullPath = PATH13.resolve(cwd5, pkgPath, "package.json");
|
|
3907
|
+
if (!existsSync14(fullPath)) continue;
|
|
3908
|
+
const pkg = JSON.parse(readFileSync14(fullPath, "utf8"));
|
|
3750
3909
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
3751
3910
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
3752
|
-
|
|
3911
|
+
writeFileSync11(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3753
3912
|
}
|
|
3754
3913
|
}
|
|
3755
|
-
console.log(
|
|
3914
|
+
console.log(chalk47.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
3756
3915
|
updateGitignore2(cwd5);
|
|
3757
3916
|
createYarnrc(cwd5);
|
|
3917
|
+
swapTsScriptsDependency(cwd5, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
3918
|
+
rewriteSourceImports(cwd5, "pnpm-to-yarn");
|
|
3758
3919
|
deletePnpmArtifacts(cwd5);
|
|
3759
|
-
console.log(
|
|
3920
|
+
console.log(chalk47.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
3760
3921
|
return 0;
|
|
3761
3922
|
}
|
|
3762
3923
|
|
|
3763
3924
|
// src/actions/packman/convert.ts
|
|
3764
3925
|
function detectCurrentPM(cwd5) {
|
|
3765
|
-
if (
|
|
3926
|
+
if (existsSync15(PATH14.join(cwd5, "pnpm-lock.yaml")) || existsSync15(PATH14.join(cwd5, "pnpm-workspace.yaml"))) {
|
|
3766
3927
|
return "pnpm";
|
|
3767
3928
|
}
|
|
3768
|
-
if (
|
|
3929
|
+
if (existsSync15(PATH14.join(cwd5, "yarn.lock")) || existsSync15(PATH14.join(cwd5, ".yarnrc.yml"))) {
|
|
3769
3930
|
return "yarn";
|
|
3770
3931
|
}
|
|
3771
3932
|
return "unknown";
|
|
3772
3933
|
}
|
|
3773
3934
|
function findWorkspacePackagePaths(cwd5) {
|
|
3774
|
-
const pkgPath =
|
|
3775
|
-
const pkg = JSON.parse(
|
|
3935
|
+
const pkgPath = PATH14.join(cwd5, "package.json");
|
|
3936
|
+
const pkg = JSON.parse(readFileSync15(pkgPath, "utf8"));
|
|
3776
3937
|
let patterns = pkg.workspaces ?? [];
|
|
3777
3938
|
if (patterns.length === 0) {
|
|
3778
|
-
const wsPath =
|
|
3779
|
-
if (
|
|
3780
|
-
const content =
|
|
3939
|
+
const wsPath = PATH14.join(cwd5, "pnpm-workspace.yaml");
|
|
3940
|
+
if (existsSync15(wsPath)) {
|
|
3941
|
+
const content = readFileSync15(wsPath, "utf8");
|
|
3781
3942
|
const lines = content.split("\n");
|
|
3782
3943
|
let inPackages = false;
|
|
3783
3944
|
for (const line of lines) {
|
|
@@ -3807,15 +3968,15 @@ function resolveWorkspaceGlob(cwd5, pattern) {
|
|
|
3807
3968
|
}
|
|
3808
3969
|
function walkGlob(basePath, parts, currentPath) {
|
|
3809
3970
|
if (parts.length === 0) {
|
|
3810
|
-
const fullPath =
|
|
3811
|
-
if (
|
|
3971
|
+
const fullPath = PATH14.join(basePath, currentPath);
|
|
3972
|
+
if (existsSync15(PATH14.join(fullPath, "package.json"))) {
|
|
3812
3973
|
return [currentPath];
|
|
3813
3974
|
}
|
|
3814
3975
|
return [];
|
|
3815
3976
|
}
|
|
3816
3977
|
const [part, ...rest] = parts;
|
|
3817
|
-
const dirPath =
|
|
3818
|
-
if (!
|
|
3978
|
+
const dirPath = PATH14.join(basePath, currentPath);
|
|
3979
|
+
if (!existsSync15(dirPath) || !statSync3(dirPath).isDirectory()) {
|
|
3819
3980
|
return [];
|
|
3820
3981
|
}
|
|
3821
3982
|
if (part === "*" || part === "**") {
|
|
@@ -3843,26 +4004,25 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
3843
4004
|
function convert({ target, verbose }) {
|
|
3844
4005
|
const validTargets = ["pnpm", "yarn"];
|
|
3845
4006
|
if (!validTargets.includes(target)) {
|
|
3846
|
-
console.error(
|
|
4007
|
+
console.error(chalk48.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
3847
4008
|
return 1;
|
|
3848
4009
|
}
|
|
3849
4010
|
const cwd5 = process.cwd();
|
|
3850
4011
|
const currentPM = detectCurrentPM(cwd5);
|
|
3851
4012
|
if (verbose) {
|
|
3852
|
-
console.log(
|
|
3853
|
-
console.log(
|
|
4013
|
+
console.log(chalk48.gray(`Current package manager: ${currentPM}`));
|
|
4014
|
+
console.log(chalk48.gray(`Target package manager: ${target}`));
|
|
3854
4015
|
}
|
|
3855
4016
|
if (currentPM === target) {
|
|
3856
|
-
console.
|
|
3857
|
-
return 1;
|
|
4017
|
+
console.log(chalk48.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
3858
4018
|
}
|
|
3859
4019
|
if (currentPM === "unknown") {
|
|
3860
|
-
console.error(
|
|
4020
|
+
console.error(chalk48.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
3861
4021
|
return 1;
|
|
3862
4022
|
}
|
|
3863
4023
|
const workspacePaths = findWorkspacePackagePaths(cwd5);
|
|
3864
4024
|
if (verbose) {
|
|
3865
|
-
console.log(
|
|
4025
|
+
console.log(chalk48.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
3866
4026
|
}
|
|
3867
4027
|
if (target === "pnpm") {
|
|
3868
4028
|
return convertToPnpm(cwd5, workspacePaths);
|
|
@@ -3920,7 +4080,7 @@ var rebuild = ({ target }) => {
|
|
|
3920
4080
|
};
|
|
3921
4081
|
|
|
3922
4082
|
// src/actions/recompile.ts
|
|
3923
|
-
import
|
|
4083
|
+
import chalk49 from "chalk";
|
|
3924
4084
|
var recompile = async ({
|
|
3925
4085
|
verbose,
|
|
3926
4086
|
target,
|
|
@@ -3955,7 +4115,7 @@ var recompileAll = async ({
|
|
|
3955
4115
|
const start = Date.now();
|
|
3956
4116
|
const targetOptions = target ? ["-t", target] : [];
|
|
3957
4117
|
if (jobs) {
|
|
3958
|
-
console.log(
|
|
4118
|
+
console.log(chalk49.blue(`Jobs set to [${jobs}]`));
|
|
3959
4119
|
}
|
|
3960
4120
|
const foreachOptions = {
|
|
3961
4121
|
incremental,
|
|
@@ -3968,25 +4128,25 @@ var recompileAll = async ({
|
|
|
3968
4128
|
pm.foreachWorkspace("package-compile", targetOptions, foreachOptions)
|
|
3969
4129
|
]);
|
|
3970
4130
|
console.log(
|
|
3971
|
-
`${
|
|
4131
|
+
`${chalk49.gray("Recompiled in")} [${chalk49.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk49.gray("seconds")}`
|
|
3972
4132
|
);
|
|
3973
4133
|
return result;
|
|
3974
4134
|
};
|
|
3975
4135
|
|
|
3976
4136
|
// src/actions/relint.ts
|
|
3977
|
-
import
|
|
4137
|
+
import chalk50 from "chalk";
|
|
3978
4138
|
var relintPackage = ({
|
|
3979
4139
|
pkg,
|
|
3980
4140
|
fix: fix2,
|
|
3981
4141
|
verbose
|
|
3982
4142
|
}) => {
|
|
3983
|
-
console.log(
|
|
4143
|
+
console.log(chalk50.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
3984
4144
|
const start = Date.now();
|
|
3985
4145
|
const pm = getPackageManager();
|
|
3986
4146
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
3987
4147
|
pm.runInWorkspace(pkg, fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint")
|
|
3988
4148
|
]);
|
|
3989
|
-
console.log(
|
|
4149
|
+
console.log(chalk50.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk50.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk50.gray("seconds")}`));
|
|
3990
4150
|
return result;
|
|
3991
4151
|
};
|
|
3992
4152
|
var relint = ({
|
|
@@ -4006,13 +4166,13 @@ var relint = ({
|
|
|
4006
4166
|
});
|
|
4007
4167
|
};
|
|
4008
4168
|
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
4009
|
-
console.log(
|
|
4169
|
+
console.log(chalk50.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
4010
4170
|
const start = Date.now();
|
|
4011
4171
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
4012
4172
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
4013
4173
|
["eslint", fixOptions]
|
|
4014
4174
|
]);
|
|
4015
|
-
console.log(
|
|
4175
|
+
console.log(chalk50.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk50.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk50.gray("seconds")}`));
|
|
4016
4176
|
return result;
|
|
4017
4177
|
};
|
|
4018
4178
|
|
|
@@ -4038,10 +4198,10 @@ var sonar = () => {
|
|
|
4038
4198
|
};
|
|
4039
4199
|
|
|
4040
4200
|
// src/actions/statics.ts
|
|
4041
|
-
import
|
|
4201
|
+
import chalk51 from "chalk";
|
|
4042
4202
|
var DefaultDependencies = ["axios", "@xylabs/pixel", "react", "graphql", "react-router", "@mui/material", "@mui/system"];
|
|
4043
4203
|
var statics = () => {
|
|
4044
|
-
console.log(
|
|
4204
|
+
console.log(chalk51.green("Check Required Static Dependencies"));
|
|
4045
4205
|
const statics2 = parsedPackageJSON()?.xy?.deps?.statics;
|
|
4046
4206
|
return detectDuplicateDependencies(statics2, DefaultDependencies);
|
|
4047
4207
|
};
|