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