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