@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/index.mjs
CHANGED
|
@@ -1926,6 +1926,8 @@ function hasImportPlugin({ location, allDependencies }) {
|
|
|
1926
1926
|
return false;
|
|
1927
1927
|
}
|
|
1928
1928
|
var hasVitest = ({ allDependencies }) => allDependencies.includes("vitest");
|
|
1929
|
+
var isYarnRepo = () => detectPackageManager() === "yarn";
|
|
1930
|
+
var isPnpmRepo = () => detectPackageManager() === "pnpm";
|
|
1929
1931
|
var rules = [
|
|
1930
1932
|
{
|
|
1931
1933
|
package: "typescript",
|
|
@@ -1942,6 +1944,22 @@ var rules = [
|
|
|
1942
1944
|
{
|
|
1943
1945
|
package: "@vitest/coverage-v8",
|
|
1944
1946
|
isNeeded: hasVitest
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
package: "@xylabs/ts-scripts-yarn3",
|
|
1950
|
+
isNeeded: isYarnRepo
|
|
1951
|
+
},
|
|
1952
|
+
{
|
|
1953
|
+
package: "@xylabs/ts-scripts-react-yarn3",
|
|
1954
|
+
isNeeded: isYarnRepo
|
|
1955
|
+
},
|
|
1956
|
+
{
|
|
1957
|
+
package: "@xylabs/ts-scripts-pnpm",
|
|
1958
|
+
isNeeded: isPnpmRepo
|
|
1959
|
+
},
|
|
1960
|
+
{
|
|
1961
|
+
package: "@xylabs/ts-scripts-react-pnpm",
|
|
1962
|
+
isNeeded: isPnpmRepo
|
|
1945
1963
|
}
|
|
1946
1964
|
];
|
|
1947
1965
|
function getImplicitDevDependencies(context) {
|
|
@@ -3601,24 +3619,24 @@ function packageLintMonorepo(fix2 = false) {
|
|
|
3601
3619
|
|
|
3602
3620
|
// src/actions/packman/convert.ts
|
|
3603
3621
|
import {
|
|
3604
|
-
existsSync as
|
|
3622
|
+
existsSync as existsSync16,
|
|
3605
3623
|
readdirSync as readdirSync7,
|
|
3606
|
-
readFileSync as
|
|
3624
|
+
readFileSync as readFileSync18,
|
|
3607
3625
|
statSync as statSync3
|
|
3608
3626
|
} from "fs";
|
|
3609
3627
|
import PATH15 from "path";
|
|
3610
|
-
import
|
|
3628
|
+
import chalk50 from "chalk";
|
|
3611
3629
|
|
|
3612
3630
|
// src/actions/packman/convertToPnpm.ts
|
|
3613
3631
|
import {
|
|
3614
|
-
existsSync as
|
|
3632
|
+
existsSync as existsSync14,
|
|
3615
3633
|
mkdirSync as mkdirSync5,
|
|
3616
|
-
readFileSync as
|
|
3634
|
+
readFileSync as readFileSync16,
|
|
3617
3635
|
rmSync as rmSync3,
|
|
3618
|
-
writeFileSync as
|
|
3636
|
+
writeFileSync as writeFileSync10
|
|
3619
3637
|
} from "fs";
|
|
3620
3638
|
import PATH13 from "path";
|
|
3621
|
-
import
|
|
3639
|
+
import chalk48 from "chalk";
|
|
3622
3640
|
|
|
3623
3641
|
// src/actions/packman/rewriteScripts.ts
|
|
3624
3642
|
function rewriteYarnToPnpm(script) {
|
|
@@ -3668,14 +3686,67 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
3668
3686
|
return { ...pkg, scripts: rewritten };
|
|
3669
3687
|
}
|
|
3670
3688
|
|
|
3689
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
3690
|
+
import { existsSync as existsSync12, readFileSync as readFileSync14, writeFileSync as writeFileSync8 } from "fs";
|
|
3691
|
+
import chalk46 from "chalk";
|
|
3692
|
+
import { globSync as globSync3 } from "glob";
|
|
3693
|
+
var IMPORT_SWAP_MAP = {
|
|
3694
|
+
"yarn-to-pnpm": [
|
|
3695
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
3696
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
3697
|
+
],
|
|
3698
|
+
"pnpm-to-yarn": [
|
|
3699
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
3700
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
3701
|
+
]
|
|
3702
|
+
};
|
|
3703
|
+
var SOURCE_GLOBS = [
|
|
3704
|
+
"**/*.ts",
|
|
3705
|
+
"**/*.tsx",
|
|
3706
|
+
"**/*.mts",
|
|
3707
|
+
"**/*.cts",
|
|
3708
|
+
"**/*.js",
|
|
3709
|
+
"**/*.mjs"
|
|
3710
|
+
];
|
|
3711
|
+
var IGNORE_PATTERNS = [
|
|
3712
|
+
"**/node_modules/**",
|
|
3713
|
+
"**/dist/**",
|
|
3714
|
+
"**/build/**",
|
|
3715
|
+
"**/.yarn/**"
|
|
3716
|
+
];
|
|
3717
|
+
function rewriteSourceImports(cwd5, direction) {
|
|
3718
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
3719
|
+
const files = globSync3(SOURCE_GLOBS, {
|
|
3720
|
+
cwd: cwd5,
|
|
3721
|
+
absolute: true,
|
|
3722
|
+
ignore: IGNORE_PATTERNS
|
|
3723
|
+
});
|
|
3724
|
+
let count = 0;
|
|
3725
|
+
for (const file of files) {
|
|
3726
|
+
if (!existsSync12(file)) continue;
|
|
3727
|
+
const original = readFileSync14(file, "utf8");
|
|
3728
|
+
let content = original;
|
|
3729
|
+
for (const [from, to] of swaps) {
|
|
3730
|
+
content = content.replaceAll(from, to);
|
|
3731
|
+
}
|
|
3732
|
+
if (content !== original) {
|
|
3733
|
+
writeFileSync8(file, content, "utf8");
|
|
3734
|
+
count++;
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
if (count > 0) {
|
|
3738
|
+
console.log(chalk46.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
|
|
3671
3742
|
// src/actions/packman/swapTsScriptsDependency.ts
|
|
3672
3743
|
import {
|
|
3673
|
-
existsSync as
|
|
3674
|
-
readFileSync as
|
|
3675
|
-
writeFileSync as
|
|
3744
|
+
existsSync as existsSync13,
|
|
3745
|
+
readFileSync as readFileSync15,
|
|
3746
|
+
writeFileSync as writeFileSync9
|
|
3676
3747
|
} from "fs";
|
|
3677
3748
|
import PATH12 from "path";
|
|
3678
|
-
import
|
|
3749
|
+
import chalk47 from "chalk";
|
|
3679
3750
|
var SWAP_MAP = {
|
|
3680
3751
|
"yarn-to-pnpm": [
|
|
3681
3752
|
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
@@ -3685,8 +3756,8 @@ var SWAP_MAP = {
|
|
|
3685
3756
|
]
|
|
3686
3757
|
};
|
|
3687
3758
|
function swapInPackageJson(pkgPath, direction) {
|
|
3688
|
-
if (!
|
|
3689
|
-
const raw =
|
|
3759
|
+
if (!existsSync13(pkgPath)) return false;
|
|
3760
|
+
const raw = readFileSync15(pkgPath, "utf8");
|
|
3690
3761
|
const pkg = JSON.parse(raw);
|
|
3691
3762
|
let changed = false;
|
|
3692
3763
|
for (const depField of ["dependencies", "devDependencies"]) {
|
|
@@ -3701,7 +3772,7 @@ function swapInPackageJson(pkgPath, direction) {
|
|
|
3701
3772
|
}
|
|
3702
3773
|
}
|
|
3703
3774
|
if (changed) {
|
|
3704
|
-
|
|
3775
|
+
writeFileSync9(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
3705
3776
|
}
|
|
3706
3777
|
return changed;
|
|
3707
3778
|
}
|
|
@@ -3718,7 +3789,7 @@ function swapTsScriptsDependency(cwd5, workspacePackageJsonPaths, direction) {
|
|
|
3718
3789
|
}
|
|
3719
3790
|
if (count > 0) {
|
|
3720
3791
|
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
3721
|
-
console.log(
|
|
3792
|
+
console.log(chalk47.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
3722
3793
|
}
|
|
3723
3794
|
}
|
|
3724
3795
|
|
|
@@ -3729,13 +3800,13 @@ function createPnpmWorkspaceYaml(cwd5, workspacePatterns) {
|
|
|
3729
3800
|
for (const pattern of workspacePatterns) {
|
|
3730
3801
|
lines.push(` - '${pattern}'`);
|
|
3731
3802
|
}
|
|
3732
|
-
|
|
3733
|
-
console.log(
|
|
3803
|
+
writeFileSync10(PATH13.join(cwd5, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
3804
|
+
console.log(chalk48.green(" Created pnpm-workspace.yaml"));
|
|
3734
3805
|
}
|
|
3735
3806
|
function readPnpmWorkspacePatterns(cwd5) {
|
|
3736
3807
|
const wsPath = PATH13.join(cwd5, "pnpm-workspace.yaml");
|
|
3737
|
-
if (!
|
|
3738
|
-
const content =
|
|
3808
|
+
if (!existsSync14(wsPath)) return [];
|
|
3809
|
+
const content = readFileSync16(wsPath, "utf8");
|
|
3739
3810
|
const patterns = [];
|
|
3740
3811
|
const lines = content.split("\n");
|
|
3741
3812
|
let inPackages = false;
|
|
@@ -3755,19 +3826,19 @@ function readPnpmWorkspacePatterns(cwd5) {
|
|
|
3755
3826
|
}
|
|
3756
3827
|
function updateRootPackageJson(cwd5) {
|
|
3757
3828
|
const pkgPath = PATH13.join(cwd5, "package.json");
|
|
3758
|
-
const pkg = JSON.parse(
|
|
3829
|
+
const pkg = JSON.parse(readFileSync16(pkgPath, "utf8"));
|
|
3759
3830
|
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd5);
|
|
3760
3831
|
delete pkg.workspaces;
|
|
3761
3832
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
3762
3833
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
3763
|
-
|
|
3764
|
-
console.log(
|
|
3834
|
+
writeFileSync10(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3835
|
+
console.log(chalk48.green(" Updated root package.json"));
|
|
3765
3836
|
return workspacePatterns;
|
|
3766
3837
|
}
|
|
3767
3838
|
function updateGitignore(cwd5) {
|
|
3768
3839
|
const gitignorePath = PATH13.join(cwd5, ".gitignore");
|
|
3769
|
-
if (!
|
|
3770
|
-
let content =
|
|
3840
|
+
if (!existsSync14(gitignorePath)) return;
|
|
3841
|
+
let content = readFileSync16(gitignorePath, "utf8");
|
|
3771
3842
|
const yarnLines = [
|
|
3772
3843
|
".pnp.*",
|
|
3773
3844
|
".pnp",
|
|
@@ -3782,64 +3853,65 @@ function updateGitignore(cwd5) {
|
|
|
3782
3853
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
3783
3854
|
}
|
|
3784
3855
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
3785
|
-
|
|
3786
|
-
console.log(
|
|
3856
|
+
writeFileSync10(gitignorePath, content, "utf8");
|
|
3857
|
+
console.log(chalk48.green(" Updated .gitignore"));
|
|
3787
3858
|
}
|
|
3788
3859
|
function deleteYarnArtifacts(cwd5) {
|
|
3789
3860
|
const yarnLock = PATH13.join(cwd5, "yarn.lock");
|
|
3790
3861
|
const yarnrc = PATH13.join(cwd5, ".yarnrc.yml");
|
|
3791
3862
|
const yarnDir = PATH13.join(cwd5, ".yarn");
|
|
3792
|
-
if (
|
|
3863
|
+
if (existsSync14(yarnLock)) {
|
|
3793
3864
|
rmSync3(yarnLock);
|
|
3794
|
-
console.log(
|
|
3865
|
+
console.log(chalk48.gray(" Deleted yarn.lock"));
|
|
3795
3866
|
}
|
|
3796
|
-
if (
|
|
3867
|
+
if (existsSync14(yarnrc)) {
|
|
3797
3868
|
rmSync3(yarnrc);
|
|
3798
|
-
console.log(
|
|
3869
|
+
console.log(chalk48.gray(" Deleted .yarnrc.yml"));
|
|
3799
3870
|
}
|
|
3800
|
-
if (
|
|
3871
|
+
if (existsSync14(yarnDir)) {
|
|
3801
3872
|
rmSync3(yarnDir, { force: true, recursive: true });
|
|
3802
|
-
console.log(
|
|
3873
|
+
console.log(chalk48.gray(" Deleted .yarn/"));
|
|
3803
3874
|
}
|
|
3804
3875
|
}
|
|
3805
3876
|
function createNpmrc(cwd5) {
|
|
3806
3877
|
const npmrcPath = PATH13.join(cwd5, ".npmrc");
|
|
3807
|
-
if (
|
|
3878
|
+
if (existsSync14(npmrcPath)) return;
|
|
3808
3879
|
mkdirSync5(PATH13.dirname(npmrcPath), { recursive: true });
|
|
3809
|
-
|
|
3810
|
-
console.log(
|
|
3880
|
+
writeFileSync10(npmrcPath, "", "utf8");
|
|
3881
|
+
console.log(chalk48.green(" Created .npmrc"));
|
|
3811
3882
|
}
|
|
3812
3883
|
function convertToPnpm(cwd5, workspacePackageJsonPaths) {
|
|
3813
|
-
console.log(
|
|
3884
|
+
console.log(chalk48.blue("\nConverting to pnpm...\n"));
|
|
3814
3885
|
const workspacePatterns = updateRootPackageJson(cwd5);
|
|
3815
3886
|
createPnpmWorkspaceYaml(cwd5, workspacePatterns);
|
|
3816
3887
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
3817
3888
|
const fullPath = PATH13.resolve(cwd5, pkgPath, "package.json");
|
|
3818
|
-
if (!
|
|
3819
|
-
const pkg = JSON.parse(
|
|
3889
|
+
if (!existsSync14(fullPath)) continue;
|
|
3890
|
+
const pkg = JSON.parse(readFileSync16(fullPath, "utf8"));
|
|
3820
3891
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
3821
3892
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
3822
|
-
|
|
3893
|
+
writeFileSync10(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3823
3894
|
}
|
|
3824
3895
|
}
|
|
3825
|
-
console.log(
|
|
3896
|
+
console.log(chalk48.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
3826
3897
|
updateGitignore(cwd5);
|
|
3827
3898
|
createNpmrc(cwd5);
|
|
3828
3899
|
swapTsScriptsDependency(cwd5, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
3900
|
+
rewriteSourceImports(cwd5, "yarn-to-pnpm");
|
|
3829
3901
|
deleteYarnArtifacts(cwd5);
|
|
3830
|
-
console.log(
|
|
3902
|
+
console.log(chalk48.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
3831
3903
|
return 0;
|
|
3832
3904
|
}
|
|
3833
3905
|
|
|
3834
3906
|
// src/actions/packman/convertToYarn.ts
|
|
3835
3907
|
import {
|
|
3836
|
-
existsSync as
|
|
3837
|
-
readFileSync as
|
|
3908
|
+
existsSync as existsSync15,
|
|
3909
|
+
readFileSync as readFileSync17,
|
|
3838
3910
|
rmSync as rmSync4,
|
|
3839
|
-
writeFileSync as
|
|
3911
|
+
writeFileSync as writeFileSync11
|
|
3840
3912
|
} from "fs";
|
|
3841
3913
|
import PATH14 from "path";
|
|
3842
|
-
import
|
|
3914
|
+
import chalk49 from "chalk";
|
|
3843
3915
|
var YARN_VERSION = "4.13.0";
|
|
3844
3916
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
3845
3917
|
|
|
@@ -3862,8 +3934,8 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
3862
3934
|
`;
|
|
3863
3935
|
function readPnpmWorkspacePatterns2(cwd5) {
|
|
3864
3936
|
const wsPath = PATH14.join(cwd5, "pnpm-workspace.yaml");
|
|
3865
|
-
if (!
|
|
3866
|
-
const content =
|
|
3937
|
+
if (!existsSync15(wsPath)) return [];
|
|
3938
|
+
const content = readFileSync17(wsPath, "utf8");
|
|
3867
3939
|
const patterns = [];
|
|
3868
3940
|
const lines = content.split("\n");
|
|
3869
3941
|
let inPackages = false;
|
|
@@ -3883,102 +3955,103 @@ function readPnpmWorkspacePatterns2(cwd5) {
|
|
|
3883
3955
|
}
|
|
3884
3956
|
function updateRootPackageJson2(cwd5, workspacePatterns) {
|
|
3885
3957
|
const pkgPath = PATH14.join(cwd5, "package.json");
|
|
3886
|
-
const pkg = JSON.parse(
|
|
3958
|
+
const pkg = JSON.parse(readFileSync17(pkgPath, "utf8"));
|
|
3887
3959
|
pkg.workspaces = workspacePatterns;
|
|
3888
3960
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
3889
3961
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
3890
|
-
|
|
3891
|
-
console.log(
|
|
3962
|
+
writeFileSync11(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3963
|
+
console.log(chalk49.green(" Updated root package.json"));
|
|
3892
3964
|
}
|
|
3893
3965
|
function updateGitignore2(cwd5) {
|
|
3894
3966
|
const gitignorePath = PATH14.join(cwd5, ".gitignore");
|
|
3895
|
-
let content =
|
|
3967
|
+
let content = existsSync15(gitignorePath) ? readFileSync17(gitignorePath, "utf8") : "";
|
|
3896
3968
|
if (!content.includes(".yarn/*")) {
|
|
3897
3969
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
3898
3970
|
}
|
|
3899
|
-
|
|
3900
|
-
console.log(
|
|
3971
|
+
writeFileSync11(gitignorePath, content, "utf8");
|
|
3972
|
+
console.log(chalk49.green(" Updated .gitignore"));
|
|
3901
3973
|
}
|
|
3902
3974
|
function deletePnpmArtifacts(cwd5) {
|
|
3903
3975
|
const lockfile = PATH14.join(cwd5, "pnpm-lock.yaml");
|
|
3904
3976
|
const workspaceYaml = PATH14.join(cwd5, "pnpm-workspace.yaml");
|
|
3905
3977
|
const npmrc = PATH14.join(cwd5, ".npmrc");
|
|
3906
|
-
if (
|
|
3978
|
+
if (existsSync15(lockfile)) {
|
|
3907
3979
|
rmSync4(lockfile);
|
|
3908
|
-
console.log(
|
|
3980
|
+
console.log(chalk49.gray(" Deleted pnpm-lock.yaml"));
|
|
3909
3981
|
}
|
|
3910
|
-
if (
|
|
3982
|
+
if (existsSync15(workspaceYaml)) {
|
|
3911
3983
|
rmSync4(workspaceYaml);
|
|
3912
|
-
console.log(
|
|
3984
|
+
console.log(chalk49.gray(" Deleted pnpm-workspace.yaml"));
|
|
3913
3985
|
}
|
|
3914
|
-
if (
|
|
3915
|
-
const content =
|
|
3986
|
+
if (existsSync15(npmrc)) {
|
|
3987
|
+
const content = readFileSync17(npmrc, "utf8");
|
|
3916
3988
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
3917
3989
|
rmSync4(npmrc);
|
|
3918
|
-
console.log(
|
|
3990
|
+
console.log(chalk49.gray(" Deleted .npmrc"));
|
|
3919
3991
|
}
|
|
3920
3992
|
}
|
|
3921
3993
|
}
|
|
3922
3994
|
function createYarnrc(cwd5) {
|
|
3923
3995
|
const yarnrcPath = PATH14.join(cwd5, ".yarnrc.yml");
|
|
3924
|
-
if (
|
|
3925
|
-
|
|
3926
|
-
console.log(
|
|
3996
|
+
if (existsSync15(yarnrcPath)) return;
|
|
3997
|
+
writeFileSync11(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
3998
|
+
console.log(chalk49.green(" Created .yarnrc.yml"));
|
|
3927
3999
|
}
|
|
3928
4000
|
function readWorkspacePatternsFromPackageJson(cwd5) {
|
|
3929
4001
|
const pkgPath = PATH14.join(cwd5, "package.json");
|
|
3930
|
-
if (!
|
|
3931
|
-
const pkg = JSON.parse(
|
|
4002
|
+
if (!existsSync15(pkgPath)) return [];
|
|
4003
|
+
const pkg = JSON.parse(readFileSync17(pkgPath, "utf8"));
|
|
3932
4004
|
return pkg.workspaces ?? [];
|
|
3933
4005
|
}
|
|
3934
4006
|
function convertToYarn(cwd5, workspacePackageJsonPaths) {
|
|
3935
|
-
console.log(
|
|
4007
|
+
console.log(chalk49.blue("\nConverting to yarn...\n"));
|
|
3936
4008
|
const workspacePatterns = readPnpmWorkspacePatterns2(cwd5);
|
|
3937
4009
|
if (workspacePatterns.length === 0) {
|
|
3938
4010
|
const fromPkg = readWorkspacePatternsFromPackageJson(cwd5);
|
|
3939
4011
|
if (fromPkg.length > 0) {
|
|
3940
4012
|
workspacePatterns.push(...fromPkg);
|
|
3941
4013
|
} else {
|
|
3942
|
-
console.warn(
|
|
4014
|
+
console.warn(chalk49.yellow(" No workspace patterns found"));
|
|
3943
4015
|
}
|
|
3944
4016
|
}
|
|
3945
4017
|
updateRootPackageJson2(cwd5, workspacePatterns);
|
|
3946
4018
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
3947
4019
|
const fullPath = PATH14.resolve(cwd5, pkgPath, "package.json");
|
|
3948
|
-
if (!
|
|
3949
|
-
const pkg = JSON.parse(
|
|
4020
|
+
if (!existsSync15(fullPath)) continue;
|
|
4021
|
+
const pkg = JSON.parse(readFileSync17(fullPath, "utf8"));
|
|
3950
4022
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
3951
4023
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
3952
|
-
|
|
4024
|
+
writeFileSync11(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
3953
4025
|
}
|
|
3954
4026
|
}
|
|
3955
|
-
console.log(
|
|
4027
|
+
console.log(chalk49.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
3956
4028
|
updateGitignore2(cwd5);
|
|
3957
4029
|
createYarnrc(cwd5);
|
|
3958
4030
|
swapTsScriptsDependency(cwd5, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
4031
|
+
rewriteSourceImports(cwd5, "pnpm-to-yarn");
|
|
3959
4032
|
deletePnpmArtifacts(cwd5);
|
|
3960
|
-
console.log(
|
|
4033
|
+
console.log(chalk49.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
3961
4034
|
return 0;
|
|
3962
4035
|
}
|
|
3963
4036
|
|
|
3964
4037
|
// src/actions/packman/convert.ts
|
|
3965
4038
|
function detectCurrentPM(cwd5) {
|
|
3966
|
-
if (
|
|
4039
|
+
if (existsSync16(PATH15.join(cwd5, "pnpm-lock.yaml")) || existsSync16(PATH15.join(cwd5, "pnpm-workspace.yaml"))) {
|
|
3967
4040
|
return "pnpm";
|
|
3968
4041
|
}
|
|
3969
|
-
if (
|
|
4042
|
+
if (existsSync16(PATH15.join(cwd5, "yarn.lock")) || existsSync16(PATH15.join(cwd5, ".yarnrc.yml"))) {
|
|
3970
4043
|
return "yarn";
|
|
3971
4044
|
}
|
|
3972
4045
|
return "unknown";
|
|
3973
4046
|
}
|
|
3974
4047
|
function findWorkspacePackagePaths(cwd5) {
|
|
3975
4048
|
const pkgPath = PATH15.join(cwd5, "package.json");
|
|
3976
|
-
const pkg = JSON.parse(
|
|
4049
|
+
const pkg = JSON.parse(readFileSync18(pkgPath, "utf8"));
|
|
3977
4050
|
let patterns = pkg.workspaces ?? [];
|
|
3978
4051
|
if (patterns.length === 0) {
|
|
3979
4052
|
const wsPath = PATH15.join(cwd5, "pnpm-workspace.yaml");
|
|
3980
|
-
if (
|
|
3981
|
-
const content =
|
|
4053
|
+
if (existsSync16(wsPath)) {
|
|
4054
|
+
const content = readFileSync18(wsPath, "utf8");
|
|
3982
4055
|
const lines = content.split("\n");
|
|
3983
4056
|
let inPackages = false;
|
|
3984
4057
|
for (const line of lines) {
|
|
@@ -4009,14 +4082,14 @@ function resolveWorkspaceGlob(cwd5, pattern) {
|
|
|
4009
4082
|
function walkGlob(basePath, parts, currentPath) {
|
|
4010
4083
|
if (parts.length === 0) {
|
|
4011
4084
|
const fullPath = PATH15.join(basePath, currentPath);
|
|
4012
|
-
if (
|
|
4085
|
+
if (existsSync16(PATH15.join(fullPath, "package.json"))) {
|
|
4013
4086
|
return [currentPath];
|
|
4014
4087
|
}
|
|
4015
4088
|
return [];
|
|
4016
4089
|
}
|
|
4017
4090
|
const [part, ...rest] = parts;
|
|
4018
4091
|
const dirPath = PATH15.join(basePath, currentPath);
|
|
4019
|
-
if (!
|
|
4092
|
+
if (!existsSync16(dirPath) || !statSync3(dirPath).isDirectory()) {
|
|
4020
4093
|
return [];
|
|
4021
4094
|
}
|
|
4022
4095
|
if (part === "*" || part === "**") {
|
|
@@ -4044,25 +4117,25 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
4044
4117
|
function convert({ target, verbose }) {
|
|
4045
4118
|
const validTargets = ["pnpm", "yarn"];
|
|
4046
4119
|
if (!validTargets.includes(target)) {
|
|
4047
|
-
console.error(
|
|
4120
|
+
console.error(chalk50.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
4048
4121
|
return 1;
|
|
4049
4122
|
}
|
|
4050
4123
|
const cwd5 = process.cwd();
|
|
4051
4124
|
const currentPM = detectCurrentPM(cwd5);
|
|
4052
4125
|
if (verbose) {
|
|
4053
|
-
console.log(
|
|
4054
|
-
console.log(
|
|
4126
|
+
console.log(chalk50.gray(`Current package manager: ${currentPM}`));
|
|
4127
|
+
console.log(chalk50.gray(`Target package manager: ${target}`));
|
|
4055
4128
|
}
|
|
4056
4129
|
if (currentPM === target) {
|
|
4057
|
-
console.log(
|
|
4130
|
+
console.log(chalk50.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
4058
4131
|
}
|
|
4059
4132
|
if (currentPM === "unknown") {
|
|
4060
|
-
console.error(
|
|
4133
|
+
console.error(chalk50.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
4061
4134
|
return 1;
|
|
4062
4135
|
}
|
|
4063
4136
|
const workspacePaths = findWorkspacePackagePaths(cwd5);
|
|
4064
4137
|
if (verbose) {
|
|
4065
|
-
console.log(
|
|
4138
|
+
console.log(chalk50.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
4066
4139
|
}
|
|
4067
4140
|
if (target === "pnpm") {
|
|
4068
4141
|
return convertToPnpm(cwd5, workspacePaths);
|
|
@@ -4120,7 +4193,7 @@ var rebuild = ({ target }) => {
|
|
|
4120
4193
|
};
|
|
4121
4194
|
|
|
4122
4195
|
// src/actions/recompile.ts
|
|
4123
|
-
import
|
|
4196
|
+
import chalk51 from "chalk";
|
|
4124
4197
|
var recompile = async ({
|
|
4125
4198
|
verbose,
|
|
4126
4199
|
target,
|
|
@@ -4155,7 +4228,7 @@ var recompileAll = async ({
|
|
|
4155
4228
|
const start = Date.now();
|
|
4156
4229
|
const targetOptions = target ? ["-t", target] : [];
|
|
4157
4230
|
if (jobs) {
|
|
4158
|
-
console.log(
|
|
4231
|
+
console.log(chalk51.blue(`Jobs set to [${jobs}]`));
|
|
4159
4232
|
}
|
|
4160
4233
|
const foreachOptions = {
|
|
4161
4234
|
incremental,
|
|
@@ -4168,25 +4241,25 @@ var recompileAll = async ({
|
|
|
4168
4241
|
pm.foreachWorkspace("package-compile", targetOptions, foreachOptions)
|
|
4169
4242
|
]);
|
|
4170
4243
|
console.log(
|
|
4171
|
-
`${
|
|
4244
|
+
`${chalk51.gray("Recompiled in")} [${chalk51.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk51.gray("seconds")}`
|
|
4172
4245
|
);
|
|
4173
4246
|
return result;
|
|
4174
4247
|
};
|
|
4175
4248
|
|
|
4176
4249
|
// src/actions/relint.ts
|
|
4177
|
-
import
|
|
4250
|
+
import chalk52 from "chalk";
|
|
4178
4251
|
var relintPackage = ({
|
|
4179
4252
|
pkg,
|
|
4180
4253
|
fix: fix2,
|
|
4181
4254
|
verbose
|
|
4182
4255
|
}) => {
|
|
4183
|
-
console.log(
|
|
4256
|
+
console.log(chalk52.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
4184
4257
|
const start = Date.now();
|
|
4185
4258
|
const pm = getPackageManager();
|
|
4186
4259
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
4187
4260
|
pm.runInWorkspace(pkg, fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint")
|
|
4188
4261
|
]);
|
|
4189
|
-
console.log(
|
|
4262
|
+
console.log(chalk52.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk52.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk52.gray("seconds")}`));
|
|
4190
4263
|
return result;
|
|
4191
4264
|
};
|
|
4192
4265
|
var relint = ({
|
|
@@ -4206,13 +4279,13 @@ var relint = ({
|
|
|
4206
4279
|
});
|
|
4207
4280
|
};
|
|
4208
4281
|
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
4209
|
-
console.log(
|
|
4282
|
+
console.log(chalk52.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
4210
4283
|
const start = Date.now();
|
|
4211
4284
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
4212
4285
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
4213
4286
|
["eslint", fixOptions]
|
|
4214
4287
|
]);
|
|
4215
|
-
console.log(
|
|
4288
|
+
console.log(chalk52.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk52.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk52.gray("seconds")}`));
|
|
4216
4289
|
return result;
|
|
4217
4290
|
};
|
|
4218
4291
|
|
|
@@ -4238,10 +4311,10 @@ var sonar = () => {
|
|
|
4238
4311
|
};
|
|
4239
4312
|
|
|
4240
4313
|
// src/actions/statics.ts
|
|
4241
|
-
import
|
|
4314
|
+
import chalk53 from "chalk";
|
|
4242
4315
|
var DefaultDependencies = ["axios", "@xylabs/pixel", "react", "graphql", "react-router", "@mui/material", "@mui/system"];
|
|
4243
4316
|
var statics = () => {
|
|
4244
|
-
console.log(
|
|
4317
|
+
console.log(chalk53.green("Check Required Static Dependencies"));
|
|
4245
4318
|
const statics2 = parsedPackageJSON()?.xy?.deps?.statics;
|
|
4246
4319
|
return detectDuplicateDependencies(statics2, DefaultDependencies);
|
|
4247
4320
|
};
|
|
@@ -4673,7 +4746,7 @@ var xyCommonCommands = (args) => {
|
|
|
4673
4746
|
};
|
|
4674
4747
|
|
|
4675
4748
|
// src/xy/lint/cycleCommand.ts
|
|
4676
|
-
import
|
|
4749
|
+
import chalk54 from "chalk";
|
|
4677
4750
|
var cycleCommand = {
|
|
4678
4751
|
command: "cycle [package]",
|
|
4679
4752
|
describe: "Cycle - Check for dependency cycles",
|
|
@@ -4684,12 +4757,12 @@ var cycleCommand = {
|
|
|
4684
4757
|
const start = Date.now();
|
|
4685
4758
|
if (argv.verbose) console.log("Cycle");
|
|
4686
4759
|
process.exitCode = await cycle({ pkg: argv.package });
|
|
4687
|
-
console.log(
|
|
4760
|
+
console.log(chalk54.blue(`Finished in ${Date.now() - start}ms`));
|
|
4688
4761
|
}
|
|
4689
4762
|
};
|
|
4690
4763
|
|
|
4691
4764
|
// src/xy/lint/deplintCommand.ts
|
|
4692
|
-
import
|
|
4765
|
+
import chalk55 from "chalk";
|
|
4693
4766
|
var deplintCommand = {
|
|
4694
4767
|
command: "deplint [package]",
|
|
4695
4768
|
describe: "Deplint - Run Deplint",
|
|
@@ -4727,12 +4800,12 @@ var deplintCommand = {
|
|
|
4727
4800
|
peerDeps: !!argv.peerDeps,
|
|
4728
4801
|
verbose: !!argv.verbose
|
|
4729
4802
|
});
|
|
4730
|
-
console.log(
|
|
4803
|
+
console.log(chalk55.blue(`Finished in ${Date.now() - start}ms`));
|
|
4731
4804
|
}
|
|
4732
4805
|
};
|
|
4733
4806
|
|
|
4734
4807
|
// src/xy/lint/fixCommand.ts
|
|
4735
|
-
import
|
|
4808
|
+
import chalk56 from "chalk";
|
|
4736
4809
|
var fixCommand = {
|
|
4737
4810
|
command: "fix [package]",
|
|
4738
4811
|
describe: "Fix - Run Eslint w/fix",
|
|
@@ -4743,12 +4816,12 @@ var fixCommand = {
|
|
|
4743
4816
|
const start = Date.now();
|
|
4744
4817
|
if (argv.verbose) console.log("Fix");
|
|
4745
4818
|
process.exitCode = fix();
|
|
4746
|
-
console.log(
|
|
4819
|
+
console.log(chalk56.blue(`Finished in ${Date.now() - start}ms`));
|
|
4747
4820
|
}
|
|
4748
4821
|
};
|
|
4749
4822
|
|
|
4750
4823
|
// src/xy/lint/knipCommand.ts
|
|
4751
|
-
import
|
|
4824
|
+
import chalk57 from "chalk";
|
|
4752
4825
|
var knipCommand = {
|
|
4753
4826
|
command: "knip",
|
|
4754
4827
|
describe: "Knip - Run Knip",
|
|
@@ -4759,12 +4832,12 @@ var knipCommand = {
|
|
|
4759
4832
|
if (argv.verbose) console.log("Knip");
|
|
4760
4833
|
const start = Date.now();
|
|
4761
4834
|
process.exitCode = knip();
|
|
4762
|
-
console.log(
|
|
4835
|
+
console.log(chalk57.blue(`Knip finished in ${Date.now() - start}ms`));
|
|
4763
4836
|
}
|
|
4764
4837
|
};
|
|
4765
4838
|
|
|
4766
4839
|
// src/xy/lint/lintCommand.ts
|
|
4767
|
-
import
|
|
4840
|
+
import chalk58 from "chalk";
|
|
4768
4841
|
var lintCommand = {
|
|
4769
4842
|
command: "lint [package]",
|
|
4770
4843
|
describe: "Lint - Run Eslint",
|
|
@@ -4793,7 +4866,7 @@ var lintCommand = {
|
|
|
4793
4866
|
cache: argv.cache,
|
|
4794
4867
|
verbose: !!argv.verbose
|
|
4795
4868
|
});
|
|
4796
|
-
console.log(
|
|
4869
|
+
console.log(chalk58.blue(`Finished in ${Date.now() - start}ms`));
|
|
4797
4870
|
}
|
|
4798
4871
|
};
|
|
4799
4872
|
|
|
@@ -4835,7 +4908,7 @@ var packageLintCommand = {
|
|
|
4835
4908
|
};
|
|
4836
4909
|
|
|
4837
4910
|
// src/xy/lint/publintCommand.ts
|
|
4838
|
-
import
|
|
4911
|
+
import chalk59 from "chalk";
|
|
4839
4912
|
var publintCommand = {
|
|
4840
4913
|
command: "publint [package]",
|
|
4841
4914
|
describe: "Publint - Run Publint",
|
|
@@ -4846,12 +4919,12 @@ var publintCommand = {
|
|
|
4846
4919
|
if (argv.verbose) console.log("Publint");
|
|
4847
4920
|
const start = Date.now();
|
|
4848
4921
|
process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
|
|
4849
|
-
console.log(
|
|
4922
|
+
console.log(chalk59.blue(`Finished in ${Date.now() - start}ms`));
|
|
4850
4923
|
}
|
|
4851
4924
|
};
|
|
4852
4925
|
|
|
4853
4926
|
// src/xy/lint/relintCommand.ts
|
|
4854
|
-
import
|
|
4927
|
+
import chalk60 from "chalk";
|
|
4855
4928
|
var relintCommand = {
|
|
4856
4929
|
command: "relint [package]",
|
|
4857
4930
|
describe: "Relint - Clean & Lint",
|
|
@@ -4862,12 +4935,12 @@ var relintCommand = {
|
|
|
4862
4935
|
if (argv.verbose) console.log("Relinting");
|
|
4863
4936
|
const start = Date.now();
|
|
4864
4937
|
process.exitCode = relint();
|
|
4865
|
-
console.log(
|
|
4938
|
+
console.log(chalk60.blue(`Finished in ${Date.now() - start}ms`));
|
|
4866
4939
|
}
|
|
4867
4940
|
};
|
|
4868
4941
|
|
|
4869
4942
|
// src/xy/lint/sonarCommand.ts
|
|
4870
|
-
import
|
|
4943
|
+
import chalk61 from "chalk";
|
|
4871
4944
|
var sonarCommand = {
|
|
4872
4945
|
command: "sonar",
|
|
4873
4946
|
describe: "Sonar - Run Sonar Check",
|
|
@@ -4878,7 +4951,7 @@ var sonarCommand = {
|
|
|
4878
4951
|
const start = Date.now();
|
|
4879
4952
|
if (argv.verbose) console.log("Sonar Check");
|
|
4880
4953
|
process.exitCode = sonar();
|
|
4881
|
-
console.log(
|
|
4954
|
+
console.log(chalk61.blue(`Finished in ${Date.now() - start}ms`));
|
|
4882
4955
|
}
|
|
4883
4956
|
};
|
|
4884
4957
|
|
|
@@ -4888,7 +4961,7 @@ var xyLintCommands = (args) => {
|
|
|
4888
4961
|
};
|
|
4889
4962
|
|
|
4890
4963
|
// src/xy/xy.ts
|
|
4891
|
-
import
|
|
4964
|
+
import chalk62 from "chalk";
|
|
4892
4965
|
|
|
4893
4966
|
// src/xy/xyParseOptions.ts
|
|
4894
4967
|
import yargs from "yargs";
|
|
@@ -4931,8 +5004,8 @@ var xyBase = async (plugins) => {
|
|
|
4931
5004
|
let args = xyBuildCommands(xyCommonCommands(xyLintCommands(options)));
|
|
4932
5005
|
if (plugins) args = plugins(args);
|
|
4933
5006
|
return await args.demandCommand(1).command("*", "", () => {
|
|
4934
|
-
console.error(
|
|
4935
|
-
console.log(
|
|
5007
|
+
console.error(chalk62.yellow(`Command not found [${chalk62.magenta(process.argv[2])}]`));
|
|
5008
|
+
console.log(chalk62.gray("Try 'xy --help' for list of commands"));
|
|
4936
5009
|
}).version().help().argv;
|
|
4937
5010
|
};
|
|
4938
5011
|
export {
|