@xylabs/ts-scripts-common 7.5.1 → 7.5.2
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/index.mjs +197 -110
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/packman/convert.mjs +187 -100
- package/dist/actions/packman/convert.mjs.map +1 -1
- package/dist/actions/packman/convertToPnpm.mjs +114 -38
- package/dist/actions/packman/convertToPnpm.mjs.map +1 -1
- package/dist/actions/packman/convertToYarn.mjs +104 -38
- package/dist/actions/packman/convertToYarn.mjs.map +1 -1
- package/dist/actions/packman/index.mjs +187 -100
- package/dist/actions/packman/index.mjs.map +1 -1
- package/dist/actions/packman/swapTsScriptsDependency.mjs +57 -0
- package/dist/actions/packman/swapTsScriptsDependency.mjs.map +1 -0
- package/dist/bin/xy.mjs +214 -127
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +216 -129
- package/dist/index.mjs.map +1 -1
- package/dist/xy/common/index.mjs +187 -100
- package/dist/xy/common/index.mjs.map +1 -1
- package/dist/xy/common/packmanCommand.mjs +187 -100
- package/dist/xy/common/packmanCommand.mjs.map +1 -1
- package/dist/xy/index.mjs +214 -127
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +214 -127
- package/dist/xy/xy.mjs.map +1 -1
- package/package.json +2 -2
package/dist/xy/xy.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/xy/xy.ts
|
|
2
|
-
import
|
|
2
|
+
import chalk45 from "chalk";
|
|
3
3
|
|
|
4
4
|
// src/actions/build.ts
|
|
5
5
|
import chalk9 from "chalk";
|
|
@@ -2586,24 +2586,24 @@ function packageLintMonorepo(fix2 = false) {
|
|
|
2586
2586
|
|
|
2587
2587
|
// src/actions/packman/convert.ts
|
|
2588
2588
|
import {
|
|
2589
|
-
existsSync as
|
|
2589
|
+
existsSync as existsSync13,
|
|
2590
2590
|
readdirSync as readdirSync6,
|
|
2591
|
-
readFileSync as
|
|
2591
|
+
readFileSync as readFileSync14,
|
|
2592
2592
|
statSync as statSync3
|
|
2593
2593
|
} from "fs";
|
|
2594
|
-
import
|
|
2595
|
-
import
|
|
2594
|
+
import PATH15 from "path";
|
|
2595
|
+
import chalk34 from "chalk";
|
|
2596
2596
|
|
|
2597
2597
|
// src/actions/packman/convertToPnpm.ts
|
|
2598
2598
|
import {
|
|
2599
|
-
existsSync as
|
|
2599
|
+
existsSync as existsSync11,
|
|
2600
2600
|
mkdirSync as mkdirSync5,
|
|
2601
|
-
readFileSync as
|
|
2601
|
+
readFileSync as readFileSync12,
|
|
2602
2602
|
rmSync as rmSync3,
|
|
2603
|
-
writeFileSync as
|
|
2603
|
+
writeFileSync as writeFileSync9
|
|
2604
2604
|
} from "fs";
|
|
2605
|
-
import
|
|
2606
|
-
import
|
|
2605
|
+
import PATH13 from "path";
|
|
2606
|
+
import chalk32 from "chalk";
|
|
2607
2607
|
|
|
2608
2608
|
// src/actions/packman/rewriteScripts.ts
|
|
2609
2609
|
function rewriteYarnToPnpm(script) {
|
|
@@ -2653,6 +2653,60 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
2653
2653
|
return { ...pkg, scripts: rewritten };
|
|
2654
2654
|
}
|
|
2655
2655
|
|
|
2656
|
+
// src/actions/packman/swapTsScriptsDependency.ts
|
|
2657
|
+
import {
|
|
2658
|
+
existsSync as existsSync10,
|
|
2659
|
+
readFileSync as readFileSync11,
|
|
2660
|
+
writeFileSync as writeFileSync8
|
|
2661
|
+
} from "fs";
|
|
2662
|
+
import PATH12 from "path";
|
|
2663
|
+
import chalk31 from "chalk";
|
|
2664
|
+
var SWAP_MAP = {
|
|
2665
|
+
"yarn-to-pnpm": [
|
|
2666
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
2667
|
+
],
|
|
2668
|
+
"pnpm-to-yarn": [
|
|
2669
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"]
|
|
2670
|
+
]
|
|
2671
|
+
};
|
|
2672
|
+
function swapInPackageJson(pkgPath, direction) {
|
|
2673
|
+
if (!existsSync10(pkgPath)) return false;
|
|
2674
|
+
const raw = readFileSync11(pkgPath, "utf8");
|
|
2675
|
+
const pkg = JSON.parse(raw);
|
|
2676
|
+
let changed = false;
|
|
2677
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
2678
|
+
const deps = pkg[depField];
|
|
2679
|
+
if (!deps) continue;
|
|
2680
|
+
for (const [from, to] of SWAP_MAP[direction]) {
|
|
2681
|
+
if (deps[from]) {
|
|
2682
|
+
deps[to] = deps[from];
|
|
2683
|
+
delete deps[from];
|
|
2684
|
+
changed = true;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
if (changed) {
|
|
2689
|
+
writeFileSync8(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
2690
|
+
}
|
|
2691
|
+
return changed;
|
|
2692
|
+
}
|
|
2693
|
+
function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
2694
|
+
let count = 0;
|
|
2695
|
+
if (swapInPackageJson(PATH12.join(cwd, "package.json"), direction)) {
|
|
2696
|
+
count++;
|
|
2697
|
+
}
|
|
2698
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2699
|
+
const fullPath = PATH12.resolve(cwd, pkgPath, "package.json");
|
|
2700
|
+
if (swapInPackageJson(fullPath, direction)) {
|
|
2701
|
+
count++;
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
if (count > 0) {
|
|
2705
|
+
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
2706
|
+
console.log(chalk31.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2656
2710
|
// src/actions/packman/convertToPnpm.ts
|
|
2657
2711
|
var PNPM_VERSION = "10.12.1";
|
|
2658
2712
|
function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
@@ -2660,24 +2714,45 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
|
2660
2714
|
for (const pattern of workspacePatterns) {
|
|
2661
2715
|
lines.push(` - '${pattern}'`);
|
|
2662
2716
|
}
|
|
2663
|
-
|
|
2664
|
-
console.log(
|
|
2717
|
+
writeFileSync9(PATH13.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
2718
|
+
console.log(chalk32.green(" Created pnpm-workspace.yaml"));
|
|
2719
|
+
}
|
|
2720
|
+
function readPnpmWorkspacePatterns(cwd) {
|
|
2721
|
+
const wsPath = PATH13.join(cwd, "pnpm-workspace.yaml");
|
|
2722
|
+
if (!existsSync11(wsPath)) return [];
|
|
2723
|
+
const content = readFileSync12(wsPath, "utf8");
|
|
2724
|
+
const patterns = [];
|
|
2725
|
+
const lines = content.split("\n");
|
|
2726
|
+
let inPackages = false;
|
|
2727
|
+
for (const line of lines) {
|
|
2728
|
+
if (line.trim() === "packages:") {
|
|
2729
|
+
inPackages = true;
|
|
2730
|
+
continue;
|
|
2731
|
+
}
|
|
2732
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
2733
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
2734
|
+
if (pattern) patterns.push(pattern);
|
|
2735
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
2736
|
+
inPackages = false;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
return patterns;
|
|
2665
2740
|
}
|
|
2666
2741
|
function updateRootPackageJson(cwd) {
|
|
2667
|
-
const pkgPath =
|
|
2668
|
-
const pkg = JSON.parse(
|
|
2669
|
-
const workspacePatterns = pkg.workspaces ??
|
|
2742
|
+
const pkgPath = PATH13.join(cwd, "package.json");
|
|
2743
|
+
const pkg = JSON.parse(readFileSync12(pkgPath, "utf8"));
|
|
2744
|
+
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd);
|
|
2670
2745
|
delete pkg.workspaces;
|
|
2671
2746
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
2672
2747
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
2673
|
-
|
|
2674
|
-
console.log(
|
|
2748
|
+
writeFileSync9(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2749
|
+
console.log(chalk32.green(" Updated root package.json"));
|
|
2675
2750
|
return workspacePatterns;
|
|
2676
2751
|
}
|
|
2677
2752
|
function updateGitignore(cwd) {
|
|
2678
|
-
const gitignorePath =
|
|
2679
|
-
if (!
|
|
2680
|
-
let content =
|
|
2753
|
+
const gitignorePath = PATH13.join(cwd, ".gitignore");
|
|
2754
|
+
if (!existsSync11(gitignorePath)) return;
|
|
2755
|
+
let content = readFileSync12(gitignorePath, "utf8");
|
|
2681
2756
|
const yarnLines = [
|
|
2682
2757
|
".pnp.*",
|
|
2683
2758
|
".pnp",
|
|
@@ -2692,63 +2767,64 @@ function updateGitignore(cwd) {
|
|
|
2692
2767
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
2693
2768
|
}
|
|
2694
2769
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
2695
|
-
|
|
2696
|
-
console.log(
|
|
2770
|
+
writeFileSync9(gitignorePath, content, "utf8");
|
|
2771
|
+
console.log(chalk32.green(" Updated .gitignore"));
|
|
2697
2772
|
}
|
|
2698
2773
|
function deleteYarnArtifacts(cwd) {
|
|
2699
|
-
const yarnLock =
|
|
2700
|
-
const yarnrc =
|
|
2701
|
-
const yarnDir =
|
|
2702
|
-
if (
|
|
2774
|
+
const yarnLock = PATH13.join(cwd, "yarn.lock");
|
|
2775
|
+
const yarnrc = PATH13.join(cwd, ".yarnrc.yml");
|
|
2776
|
+
const yarnDir = PATH13.join(cwd, ".yarn");
|
|
2777
|
+
if (existsSync11(yarnLock)) {
|
|
2703
2778
|
rmSync3(yarnLock);
|
|
2704
|
-
console.log(
|
|
2779
|
+
console.log(chalk32.gray(" Deleted yarn.lock"));
|
|
2705
2780
|
}
|
|
2706
|
-
if (
|
|
2781
|
+
if (existsSync11(yarnrc)) {
|
|
2707
2782
|
rmSync3(yarnrc);
|
|
2708
|
-
console.log(
|
|
2783
|
+
console.log(chalk32.gray(" Deleted .yarnrc.yml"));
|
|
2709
2784
|
}
|
|
2710
|
-
if (
|
|
2785
|
+
if (existsSync11(yarnDir)) {
|
|
2711
2786
|
rmSync3(yarnDir, { force: true, recursive: true });
|
|
2712
|
-
console.log(
|
|
2787
|
+
console.log(chalk32.gray(" Deleted .yarn/"));
|
|
2713
2788
|
}
|
|
2714
2789
|
}
|
|
2715
2790
|
function createNpmrc(cwd) {
|
|
2716
|
-
const npmrcPath =
|
|
2717
|
-
if (
|
|
2718
|
-
mkdirSync5(
|
|
2719
|
-
|
|
2720
|
-
console.log(
|
|
2791
|
+
const npmrcPath = PATH13.join(cwd, ".npmrc");
|
|
2792
|
+
if (existsSync11(npmrcPath)) return;
|
|
2793
|
+
mkdirSync5(PATH13.dirname(npmrcPath), { recursive: true });
|
|
2794
|
+
writeFileSync9(npmrcPath, "", "utf8");
|
|
2795
|
+
console.log(chalk32.green(" Created .npmrc"));
|
|
2721
2796
|
}
|
|
2722
2797
|
function convertToPnpm(cwd, workspacePackageJsonPaths) {
|
|
2723
|
-
console.log(
|
|
2798
|
+
console.log(chalk32.blue("\nConverting to pnpm...\n"));
|
|
2724
2799
|
const workspacePatterns = updateRootPackageJson(cwd);
|
|
2725
2800
|
createPnpmWorkspaceYaml(cwd, workspacePatterns);
|
|
2726
2801
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2727
|
-
const fullPath =
|
|
2728
|
-
if (!
|
|
2729
|
-
const pkg = JSON.parse(
|
|
2802
|
+
const fullPath = PATH13.resolve(cwd, pkgPath, "package.json");
|
|
2803
|
+
if (!existsSync11(fullPath)) continue;
|
|
2804
|
+
const pkg = JSON.parse(readFileSync12(fullPath, "utf8"));
|
|
2730
2805
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
2731
2806
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
2732
|
-
|
|
2807
|
+
writeFileSync9(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2733
2808
|
}
|
|
2734
2809
|
}
|
|
2735
|
-
console.log(
|
|
2810
|
+
console.log(chalk32.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
2736
2811
|
updateGitignore(cwd);
|
|
2737
2812
|
createNpmrc(cwd);
|
|
2813
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
2738
2814
|
deleteYarnArtifacts(cwd);
|
|
2739
|
-
console.log(
|
|
2815
|
+
console.log(chalk32.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
2740
2816
|
return 0;
|
|
2741
2817
|
}
|
|
2742
2818
|
|
|
2743
2819
|
// src/actions/packman/convertToYarn.ts
|
|
2744
2820
|
import {
|
|
2745
|
-
existsSync as
|
|
2746
|
-
readFileSync as
|
|
2821
|
+
existsSync as existsSync12,
|
|
2822
|
+
readFileSync as readFileSync13,
|
|
2747
2823
|
rmSync as rmSync4,
|
|
2748
|
-
writeFileSync as
|
|
2824
|
+
writeFileSync as writeFileSync10
|
|
2749
2825
|
} from "fs";
|
|
2750
|
-
import
|
|
2751
|
-
import
|
|
2826
|
+
import PATH14 from "path";
|
|
2827
|
+
import chalk33 from "chalk";
|
|
2752
2828
|
var YARN_VERSION = "4.13.0";
|
|
2753
2829
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
2754
2830
|
|
|
@@ -2769,10 +2845,10 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
2769
2845
|
!.yarn/sdks
|
|
2770
2846
|
!.yarn/versions
|
|
2771
2847
|
`;
|
|
2772
|
-
function
|
|
2773
|
-
const wsPath =
|
|
2774
|
-
if (!
|
|
2775
|
-
const content =
|
|
2848
|
+
function readPnpmWorkspacePatterns2(cwd) {
|
|
2849
|
+
const wsPath = PATH14.join(cwd, "pnpm-workspace.yaml");
|
|
2850
|
+
if (!existsSync12(wsPath)) return [];
|
|
2851
|
+
const content = readFileSync13(wsPath, "utf8");
|
|
2776
2852
|
const patterns = [];
|
|
2777
2853
|
const lines = content.split("\n");
|
|
2778
2854
|
let inPackages = false;
|
|
@@ -2791,91 +2867,103 @@ function readPnpmWorkspacePatterns(cwd) {
|
|
|
2791
2867
|
return patterns;
|
|
2792
2868
|
}
|
|
2793
2869
|
function updateRootPackageJson2(cwd, workspacePatterns) {
|
|
2794
|
-
const pkgPath =
|
|
2795
|
-
const pkg = JSON.parse(
|
|
2870
|
+
const pkgPath = PATH14.join(cwd, "package.json");
|
|
2871
|
+
const pkg = JSON.parse(readFileSync13(pkgPath, "utf8"));
|
|
2796
2872
|
pkg.workspaces = workspacePatterns;
|
|
2797
2873
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
2798
2874
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
2799
|
-
|
|
2800
|
-
console.log(
|
|
2875
|
+
writeFileSync10(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2876
|
+
console.log(chalk33.green(" Updated root package.json"));
|
|
2801
2877
|
}
|
|
2802
2878
|
function updateGitignore2(cwd) {
|
|
2803
|
-
const gitignorePath =
|
|
2804
|
-
let content =
|
|
2879
|
+
const gitignorePath = PATH14.join(cwd, ".gitignore");
|
|
2880
|
+
let content = existsSync12(gitignorePath) ? readFileSync13(gitignorePath, "utf8") : "";
|
|
2805
2881
|
if (!content.includes(".yarn/*")) {
|
|
2806
2882
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
2807
2883
|
}
|
|
2808
|
-
|
|
2809
|
-
console.log(
|
|
2884
|
+
writeFileSync10(gitignorePath, content, "utf8");
|
|
2885
|
+
console.log(chalk33.green(" Updated .gitignore"));
|
|
2810
2886
|
}
|
|
2811
2887
|
function deletePnpmArtifacts(cwd) {
|
|
2812
|
-
const lockfile =
|
|
2813
|
-
const workspaceYaml =
|
|
2814
|
-
const npmrc =
|
|
2815
|
-
if (
|
|
2888
|
+
const lockfile = PATH14.join(cwd, "pnpm-lock.yaml");
|
|
2889
|
+
const workspaceYaml = PATH14.join(cwd, "pnpm-workspace.yaml");
|
|
2890
|
+
const npmrc = PATH14.join(cwd, ".npmrc");
|
|
2891
|
+
if (existsSync12(lockfile)) {
|
|
2816
2892
|
rmSync4(lockfile);
|
|
2817
|
-
console.log(
|
|
2893
|
+
console.log(chalk33.gray(" Deleted pnpm-lock.yaml"));
|
|
2818
2894
|
}
|
|
2819
|
-
if (
|
|
2895
|
+
if (existsSync12(workspaceYaml)) {
|
|
2820
2896
|
rmSync4(workspaceYaml);
|
|
2821
|
-
console.log(
|
|
2897
|
+
console.log(chalk33.gray(" Deleted pnpm-workspace.yaml"));
|
|
2822
2898
|
}
|
|
2823
|
-
if (
|
|
2824
|
-
const content =
|
|
2899
|
+
if (existsSync12(npmrc)) {
|
|
2900
|
+
const content = readFileSync13(npmrc, "utf8");
|
|
2825
2901
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
2826
2902
|
rmSync4(npmrc);
|
|
2827
|
-
console.log(
|
|
2903
|
+
console.log(chalk33.gray(" Deleted .npmrc"));
|
|
2828
2904
|
}
|
|
2829
2905
|
}
|
|
2830
2906
|
}
|
|
2831
2907
|
function createYarnrc(cwd) {
|
|
2832
|
-
const yarnrcPath =
|
|
2833
|
-
if (
|
|
2834
|
-
|
|
2835
|
-
console.log(
|
|
2908
|
+
const yarnrcPath = PATH14.join(cwd, ".yarnrc.yml");
|
|
2909
|
+
if (existsSync12(yarnrcPath)) return;
|
|
2910
|
+
writeFileSync10(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
2911
|
+
console.log(chalk33.green(" Created .yarnrc.yml"));
|
|
2912
|
+
}
|
|
2913
|
+
function readWorkspacePatternsFromPackageJson(cwd) {
|
|
2914
|
+
const pkgPath = PATH14.join(cwd, "package.json");
|
|
2915
|
+
if (!existsSync12(pkgPath)) return [];
|
|
2916
|
+
const pkg = JSON.parse(readFileSync13(pkgPath, "utf8"));
|
|
2917
|
+
return pkg.workspaces ?? [];
|
|
2836
2918
|
}
|
|
2837
2919
|
function convertToYarn(cwd, workspacePackageJsonPaths) {
|
|
2838
|
-
console.log(
|
|
2839
|
-
const workspacePatterns =
|
|
2920
|
+
console.log(chalk33.blue("\nConverting to yarn...\n"));
|
|
2921
|
+
const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
|
|
2840
2922
|
if (workspacePatterns.length === 0) {
|
|
2841
|
-
|
|
2923
|
+
const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
|
|
2924
|
+
if (fromPkg.length > 0) {
|
|
2925
|
+
workspacePatterns.push(...fromPkg);
|
|
2926
|
+
} else {
|
|
2927
|
+
console.warn(chalk33.yellow(" No workspace patterns found"));
|
|
2928
|
+
}
|
|
2842
2929
|
}
|
|
2843
2930
|
updateRootPackageJson2(cwd, workspacePatterns);
|
|
2844
2931
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2845
|
-
const fullPath =
|
|
2846
|
-
if (!
|
|
2847
|
-
const pkg = JSON.parse(
|
|
2932
|
+
const fullPath = PATH14.resolve(cwd, pkgPath, "package.json");
|
|
2933
|
+
if (!existsSync12(fullPath)) continue;
|
|
2934
|
+
const pkg = JSON.parse(readFileSync13(fullPath, "utf8"));
|
|
2848
2935
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
2849
2936
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
2850
|
-
|
|
2937
|
+
writeFileSync10(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2851
2938
|
}
|
|
2852
2939
|
}
|
|
2853
|
-
console.log(
|
|
2940
|
+
console.log(chalk33.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
2854
2941
|
updateGitignore2(cwd);
|
|
2855
2942
|
createYarnrc(cwd);
|
|
2943
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
2856
2944
|
deletePnpmArtifacts(cwd);
|
|
2857
|
-
console.log(
|
|
2945
|
+
console.log(chalk33.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
2858
2946
|
return 0;
|
|
2859
2947
|
}
|
|
2860
2948
|
|
|
2861
2949
|
// src/actions/packman/convert.ts
|
|
2862
2950
|
function detectCurrentPM(cwd) {
|
|
2863
|
-
if (
|
|
2951
|
+
if (existsSync13(PATH15.join(cwd, "pnpm-lock.yaml")) || existsSync13(PATH15.join(cwd, "pnpm-workspace.yaml"))) {
|
|
2864
2952
|
return "pnpm";
|
|
2865
2953
|
}
|
|
2866
|
-
if (
|
|
2954
|
+
if (existsSync13(PATH15.join(cwd, "yarn.lock")) || existsSync13(PATH15.join(cwd, ".yarnrc.yml"))) {
|
|
2867
2955
|
return "yarn";
|
|
2868
2956
|
}
|
|
2869
2957
|
return "unknown";
|
|
2870
2958
|
}
|
|
2871
2959
|
function findWorkspacePackagePaths(cwd) {
|
|
2872
|
-
const pkgPath =
|
|
2873
|
-
const pkg = JSON.parse(
|
|
2960
|
+
const pkgPath = PATH15.join(cwd, "package.json");
|
|
2961
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
2874
2962
|
let patterns = pkg.workspaces ?? [];
|
|
2875
2963
|
if (patterns.length === 0) {
|
|
2876
|
-
const wsPath =
|
|
2877
|
-
if (
|
|
2878
|
-
const content =
|
|
2964
|
+
const wsPath = PATH15.join(cwd, "pnpm-workspace.yaml");
|
|
2965
|
+
if (existsSync13(wsPath)) {
|
|
2966
|
+
const content = readFileSync14(wsPath, "utf8");
|
|
2879
2967
|
const lines = content.split("\n");
|
|
2880
2968
|
let inPackages = false;
|
|
2881
2969
|
for (const line of lines) {
|
|
@@ -2905,15 +2993,15 @@ function resolveWorkspaceGlob(cwd, pattern) {
|
|
|
2905
2993
|
}
|
|
2906
2994
|
function walkGlob(basePath, parts, currentPath) {
|
|
2907
2995
|
if (parts.length === 0) {
|
|
2908
|
-
const fullPath =
|
|
2909
|
-
if (
|
|
2996
|
+
const fullPath = PATH15.join(basePath, currentPath);
|
|
2997
|
+
if (existsSync13(PATH15.join(fullPath, "package.json"))) {
|
|
2910
2998
|
return [currentPath];
|
|
2911
2999
|
}
|
|
2912
3000
|
return [];
|
|
2913
3001
|
}
|
|
2914
3002
|
const [part, ...rest] = parts;
|
|
2915
|
-
const dirPath =
|
|
2916
|
-
if (!
|
|
3003
|
+
const dirPath = PATH15.join(basePath, currentPath);
|
|
3004
|
+
if (!existsSync13(dirPath) || !statSync3(dirPath).isDirectory()) {
|
|
2917
3005
|
return [];
|
|
2918
3006
|
}
|
|
2919
3007
|
if (part === "*" || part === "**") {
|
|
@@ -2941,26 +3029,25 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
2941
3029
|
function convert({ target, verbose }) {
|
|
2942
3030
|
const validTargets = ["pnpm", "yarn"];
|
|
2943
3031
|
if (!validTargets.includes(target)) {
|
|
2944
|
-
console.error(
|
|
3032
|
+
console.error(chalk34.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
2945
3033
|
return 1;
|
|
2946
3034
|
}
|
|
2947
3035
|
const cwd = process.cwd();
|
|
2948
3036
|
const currentPM = detectCurrentPM(cwd);
|
|
2949
3037
|
if (verbose) {
|
|
2950
|
-
console.log(
|
|
2951
|
-
console.log(
|
|
3038
|
+
console.log(chalk34.gray(`Current package manager: ${currentPM}`));
|
|
3039
|
+
console.log(chalk34.gray(`Target package manager: ${target}`));
|
|
2952
3040
|
}
|
|
2953
3041
|
if (currentPM === target) {
|
|
2954
|
-
console.
|
|
2955
|
-
return 1;
|
|
3042
|
+
console.log(chalk34.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
2956
3043
|
}
|
|
2957
3044
|
if (currentPM === "unknown") {
|
|
2958
|
-
console.error(
|
|
3045
|
+
console.error(chalk34.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
2959
3046
|
return 1;
|
|
2960
3047
|
}
|
|
2961
3048
|
const workspacePaths = findWorkspacePackagePaths(cwd);
|
|
2962
3049
|
if (verbose) {
|
|
2963
|
-
console.log(
|
|
3050
|
+
console.log(chalk34.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
2964
3051
|
}
|
|
2965
3052
|
if (target === "pnpm") {
|
|
2966
3053
|
return convertToPnpm(cwd, workspacePaths);
|
|
@@ -3018,7 +3105,7 @@ var rebuild = ({ target }) => {
|
|
|
3018
3105
|
};
|
|
3019
3106
|
|
|
3020
3107
|
// src/actions/recompile.ts
|
|
3021
|
-
import
|
|
3108
|
+
import chalk35 from "chalk";
|
|
3022
3109
|
var recompile = async ({
|
|
3023
3110
|
verbose,
|
|
3024
3111
|
target,
|
|
@@ -3053,7 +3140,7 @@ var recompileAll = async ({
|
|
|
3053
3140
|
const start = Date.now();
|
|
3054
3141
|
const targetOptions = target ? ["-t", target] : [];
|
|
3055
3142
|
if (jobs) {
|
|
3056
|
-
console.log(
|
|
3143
|
+
console.log(chalk35.blue(`Jobs set to [${jobs}]`));
|
|
3057
3144
|
}
|
|
3058
3145
|
const foreachOptions = {
|
|
3059
3146
|
incremental,
|
|
@@ -3066,25 +3153,25 @@ var recompileAll = async ({
|
|
|
3066
3153
|
pm.foreachWorkspace("package-compile", targetOptions, foreachOptions)
|
|
3067
3154
|
]);
|
|
3068
3155
|
console.log(
|
|
3069
|
-
`${
|
|
3156
|
+
`${chalk35.gray("Recompiled in")} [${chalk35.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk35.gray("seconds")}`
|
|
3070
3157
|
);
|
|
3071
3158
|
return result;
|
|
3072
3159
|
};
|
|
3073
3160
|
|
|
3074
3161
|
// src/actions/relint.ts
|
|
3075
|
-
import
|
|
3162
|
+
import chalk36 from "chalk";
|
|
3076
3163
|
var relintPackage = ({
|
|
3077
3164
|
pkg,
|
|
3078
3165
|
fix: fix2,
|
|
3079
3166
|
verbose
|
|
3080
3167
|
}) => {
|
|
3081
|
-
console.log(
|
|
3168
|
+
console.log(chalk36.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
3082
3169
|
const start = Date.now();
|
|
3083
3170
|
const pm = getPackageManager();
|
|
3084
3171
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
3085
3172
|
pm.runInWorkspace(pkg, fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint")
|
|
3086
3173
|
]);
|
|
3087
|
-
console.log(
|
|
3174
|
+
console.log(chalk36.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk36.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk36.gray("seconds")}`));
|
|
3088
3175
|
return result;
|
|
3089
3176
|
};
|
|
3090
3177
|
var relint = ({
|
|
@@ -3104,13 +3191,13 @@ var relint = ({
|
|
|
3104
3191
|
});
|
|
3105
3192
|
};
|
|
3106
3193
|
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
3107
|
-
console.log(
|
|
3194
|
+
console.log(chalk36.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
3108
3195
|
const start = Date.now();
|
|
3109
3196
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
3110
3197
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
3111
3198
|
["eslint", fixOptions]
|
|
3112
3199
|
]);
|
|
3113
|
-
console.log(
|
|
3200
|
+
console.log(chalk36.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk36.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk36.gray("seconds")}`));
|
|
3114
3201
|
return result;
|
|
3115
3202
|
};
|
|
3116
3203
|
|
|
@@ -3554,7 +3641,7 @@ var xyCommonCommands = (args) => {
|
|
|
3554
3641
|
};
|
|
3555
3642
|
|
|
3556
3643
|
// src/xy/lint/cycleCommand.ts
|
|
3557
|
-
import
|
|
3644
|
+
import chalk37 from "chalk";
|
|
3558
3645
|
var cycleCommand = {
|
|
3559
3646
|
command: "cycle [package]",
|
|
3560
3647
|
describe: "Cycle - Check for dependency cycles",
|
|
@@ -3565,12 +3652,12 @@ var cycleCommand = {
|
|
|
3565
3652
|
const start = Date.now();
|
|
3566
3653
|
if (argv.verbose) console.log("Cycle");
|
|
3567
3654
|
process.exitCode = await cycle({ pkg: argv.package });
|
|
3568
|
-
console.log(
|
|
3655
|
+
console.log(chalk37.blue(`Finished in ${Date.now() - start}ms`));
|
|
3569
3656
|
}
|
|
3570
3657
|
};
|
|
3571
3658
|
|
|
3572
3659
|
// src/xy/lint/deplintCommand.ts
|
|
3573
|
-
import
|
|
3660
|
+
import chalk38 from "chalk";
|
|
3574
3661
|
var deplintCommand = {
|
|
3575
3662
|
command: "deplint [package]",
|
|
3576
3663
|
describe: "Deplint - Run Deplint",
|
|
@@ -3608,12 +3695,12 @@ var deplintCommand = {
|
|
|
3608
3695
|
peerDeps: !!argv.peerDeps,
|
|
3609
3696
|
verbose: !!argv.verbose
|
|
3610
3697
|
});
|
|
3611
|
-
console.log(
|
|
3698
|
+
console.log(chalk38.blue(`Finished in ${Date.now() - start}ms`));
|
|
3612
3699
|
}
|
|
3613
3700
|
};
|
|
3614
3701
|
|
|
3615
3702
|
// src/xy/lint/fixCommand.ts
|
|
3616
|
-
import
|
|
3703
|
+
import chalk39 from "chalk";
|
|
3617
3704
|
var fixCommand = {
|
|
3618
3705
|
command: "fix [package]",
|
|
3619
3706
|
describe: "Fix - Run Eslint w/fix",
|
|
@@ -3624,12 +3711,12 @@ var fixCommand = {
|
|
|
3624
3711
|
const start = Date.now();
|
|
3625
3712
|
if (argv.verbose) console.log("Fix");
|
|
3626
3713
|
process.exitCode = fix();
|
|
3627
|
-
console.log(
|
|
3714
|
+
console.log(chalk39.blue(`Finished in ${Date.now() - start}ms`));
|
|
3628
3715
|
}
|
|
3629
3716
|
};
|
|
3630
3717
|
|
|
3631
3718
|
// src/xy/lint/knipCommand.ts
|
|
3632
|
-
import
|
|
3719
|
+
import chalk40 from "chalk";
|
|
3633
3720
|
var knipCommand = {
|
|
3634
3721
|
command: "knip",
|
|
3635
3722
|
describe: "Knip - Run Knip",
|
|
@@ -3640,12 +3727,12 @@ var knipCommand = {
|
|
|
3640
3727
|
if (argv.verbose) console.log("Knip");
|
|
3641
3728
|
const start = Date.now();
|
|
3642
3729
|
process.exitCode = knip();
|
|
3643
|
-
console.log(
|
|
3730
|
+
console.log(chalk40.blue(`Knip finished in ${Date.now() - start}ms`));
|
|
3644
3731
|
}
|
|
3645
3732
|
};
|
|
3646
3733
|
|
|
3647
3734
|
// src/xy/lint/lintCommand.ts
|
|
3648
|
-
import
|
|
3735
|
+
import chalk41 from "chalk";
|
|
3649
3736
|
var lintCommand = {
|
|
3650
3737
|
command: "lint [package]",
|
|
3651
3738
|
describe: "Lint - Run Eslint",
|
|
@@ -3674,7 +3761,7 @@ var lintCommand = {
|
|
|
3674
3761
|
cache: argv.cache,
|
|
3675
3762
|
verbose: !!argv.verbose
|
|
3676
3763
|
});
|
|
3677
|
-
console.log(
|
|
3764
|
+
console.log(chalk41.blue(`Finished in ${Date.now() - start}ms`));
|
|
3678
3765
|
}
|
|
3679
3766
|
};
|
|
3680
3767
|
|
|
@@ -3716,7 +3803,7 @@ var packageLintCommand = {
|
|
|
3716
3803
|
};
|
|
3717
3804
|
|
|
3718
3805
|
// src/xy/lint/publintCommand.ts
|
|
3719
|
-
import
|
|
3806
|
+
import chalk42 from "chalk";
|
|
3720
3807
|
var publintCommand = {
|
|
3721
3808
|
command: "publint [package]",
|
|
3722
3809
|
describe: "Publint - Run Publint",
|
|
@@ -3727,12 +3814,12 @@ var publintCommand = {
|
|
|
3727
3814
|
if (argv.verbose) console.log("Publint");
|
|
3728
3815
|
const start = Date.now();
|
|
3729
3816
|
process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
|
|
3730
|
-
console.log(
|
|
3817
|
+
console.log(chalk42.blue(`Finished in ${Date.now() - start}ms`));
|
|
3731
3818
|
}
|
|
3732
3819
|
};
|
|
3733
3820
|
|
|
3734
3821
|
// src/xy/lint/relintCommand.ts
|
|
3735
|
-
import
|
|
3822
|
+
import chalk43 from "chalk";
|
|
3736
3823
|
var relintCommand = {
|
|
3737
3824
|
command: "relint [package]",
|
|
3738
3825
|
describe: "Relint - Clean & Lint",
|
|
@@ -3743,12 +3830,12 @@ var relintCommand = {
|
|
|
3743
3830
|
if (argv.verbose) console.log("Relinting");
|
|
3744
3831
|
const start = Date.now();
|
|
3745
3832
|
process.exitCode = relint();
|
|
3746
|
-
console.log(
|
|
3833
|
+
console.log(chalk43.blue(`Finished in ${Date.now() - start}ms`));
|
|
3747
3834
|
}
|
|
3748
3835
|
};
|
|
3749
3836
|
|
|
3750
3837
|
// src/xy/lint/sonarCommand.ts
|
|
3751
|
-
import
|
|
3838
|
+
import chalk44 from "chalk";
|
|
3752
3839
|
var sonarCommand = {
|
|
3753
3840
|
command: "sonar",
|
|
3754
3841
|
describe: "Sonar - Run Sonar Check",
|
|
@@ -3759,7 +3846,7 @@ var sonarCommand = {
|
|
|
3759
3846
|
const start = Date.now();
|
|
3760
3847
|
if (argv.verbose) console.log("Sonar Check");
|
|
3761
3848
|
process.exitCode = sonar();
|
|
3762
|
-
console.log(
|
|
3849
|
+
console.log(chalk44.blue(`Finished in ${Date.now() - start}ms`));
|
|
3763
3850
|
}
|
|
3764
3851
|
};
|
|
3765
3852
|
|
|
@@ -3809,8 +3896,8 @@ var xyBase = async (plugins) => {
|
|
|
3809
3896
|
let args = xyBuildCommands(xyCommonCommands(xyLintCommands(options)));
|
|
3810
3897
|
if (plugins) args = plugins(args);
|
|
3811
3898
|
return await args.demandCommand(1).command("*", "", () => {
|
|
3812
|
-
console.error(
|
|
3813
|
-
console.log(
|
|
3899
|
+
console.error(chalk45.yellow(`Command not found [${chalk45.magenta(process.argv[2])}]`));
|
|
3900
|
+
console.log(chalk45.gray("Try 'xy --help' for list of commands"));
|
|
3814
3901
|
}).version().help().argv;
|
|
3815
3902
|
};
|
|
3816
3903
|
export {
|