@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/xy/index.mjs
CHANGED
|
@@ -1696,6 +1696,8 @@ function hasImportPlugin({ location, allDependencies }) {
|
|
|
1696
1696
|
return false;
|
|
1697
1697
|
}
|
|
1698
1698
|
var hasVitest = ({ allDependencies }) => allDependencies.includes("vitest");
|
|
1699
|
+
var isYarnRepo = () => detectPackageManager() === "yarn";
|
|
1700
|
+
var isPnpmRepo = () => detectPackageManager() === "pnpm";
|
|
1699
1701
|
var rules = [
|
|
1700
1702
|
{
|
|
1701
1703
|
package: "typescript",
|
|
@@ -1712,6 +1714,22 @@ var rules = [
|
|
|
1712
1714
|
{
|
|
1713
1715
|
package: "@vitest/coverage-v8",
|
|
1714
1716
|
isNeeded: hasVitest
|
|
1717
|
+
},
|
|
1718
|
+
{
|
|
1719
|
+
package: "@xylabs/ts-scripts-yarn3",
|
|
1720
|
+
isNeeded: isYarnRepo
|
|
1721
|
+
},
|
|
1722
|
+
{
|
|
1723
|
+
package: "@xylabs/ts-scripts-react-yarn3",
|
|
1724
|
+
isNeeded: isYarnRepo
|
|
1725
|
+
},
|
|
1726
|
+
{
|
|
1727
|
+
package: "@xylabs/ts-scripts-pnpm",
|
|
1728
|
+
isNeeded: isPnpmRepo
|
|
1729
|
+
},
|
|
1730
|
+
{
|
|
1731
|
+
package: "@xylabs/ts-scripts-react-pnpm",
|
|
1732
|
+
isNeeded: isPnpmRepo
|
|
1715
1733
|
}
|
|
1716
1734
|
];
|
|
1717
1735
|
function getImplicitDevDependencies(context) {
|
|
@@ -2583,24 +2601,24 @@ function packageLintMonorepo(fix2 = false) {
|
|
|
2583
2601
|
|
|
2584
2602
|
// src/actions/packman/convert.ts
|
|
2585
2603
|
import {
|
|
2586
|
-
existsSync as
|
|
2604
|
+
existsSync as existsSync14,
|
|
2587
2605
|
readdirSync as readdirSync6,
|
|
2588
|
-
readFileSync as
|
|
2606
|
+
readFileSync as readFileSync15,
|
|
2589
2607
|
statSync as statSync3
|
|
2590
2608
|
} from "fs";
|
|
2591
2609
|
import PATH15 from "path";
|
|
2592
|
-
import
|
|
2610
|
+
import chalk35 from "chalk";
|
|
2593
2611
|
|
|
2594
2612
|
// src/actions/packman/convertToPnpm.ts
|
|
2595
2613
|
import {
|
|
2596
|
-
existsSync as
|
|
2614
|
+
existsSync as existsSync12,
|
|
2597
2615
|
mkdirSync as mkdirSync5,
|
|
2598
|
-
readFileSync as
|
|
2616
|
+
readFileSync as readFileSync13,
|
|
2599
2617
|
rmSync as rmSync3,
|
|
2600
|
-
writeFileSync as
|
|
2618
|
+
writeFileSync as writeFileSync10
|
|
2601
2619
|
} from "fs";
|
|
2602
2620
|
import PATH13 from "path";
|
|
2603
|
-
import
|
|
2621
|
+
import chalk33 from "chalk";
|
|
2604
2622
|
|
|
2605
2623
|
// src/actions/packman/rewriteScripts.ts
|
|
2606
2624
|
function rewriteYarnToPnpm(script) {
|
|
@@ -2650,14 +2668,67 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
2650
2668
|
return { ...pkg, scripts: rewritten };
|
|
2651
2669
|
}
|
|
2652
2670
|
|
|
2671
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
2672
|
+
import { existsSync as existsSync10, readFileSync as readFileSync11, writeFileSync as writeFileSync8 } from "fs";
|
|
2673
|
+
import chalk31 from "chalk";
|
|
2674
|
+
import { globSync as globSync3 } from "glob";
|
|
2675
|
+
var IMPORT_SWAP_MAP = {
|
|
2676
|
+
"yarn-to-pnpm": [
|
|
2677
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
2678
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
2679
|
+
],
|
|
2680
|
+
"pnpm-to-yarn": [
|
|
2681
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
2682
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
2683
|
+
]
|
|
2684
|
+
};
|
|
2685
|
+
var SOURCE_GLOBS = [
|
|
2686
|
+
"**/*.ts",
|
|
2687
|
+
"**/*.tsx",
|
|
2688
|
+
"**/*.mts",
|
|
2689
|
+
"**/*.cts",
|
|
2690
|
+
"**/*.js",
|
|
2691
|
+
"**/*.mjs"
|
|
2692
|
+
];
|
|
2693
|
+
var IGNORE_PATTERNS = [
|
|
2694
|
+
"**/node_modules/**",
|
|
2695
|
+
"**/dist/**",
|
|
2696
|
+
"**/build/**",
|
|
2697
|
+
"**/.yarn/**"
|
|
2698
|
+
];
|
|
2699
|
+
function rewriteSourceImports(cwd, direction) {
|
|
2700
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
2701
|
+
const files = globSync3(SOURCE_GLOBS, {
|
|
2702
|
+
cwd,
|
|
2703
|
+
absolute: true,
|
|
2704
|
+
ignore: IGNORE_PATTERNS
|
|
2705
|
+
});
|
|
2706
|
+
let count = 0;
|
|
2707
|
+
for (const file of files) {
|
|
2708
|
+
if (!existsSync10(file)) continue;
|
|
2709
|
+
const original = readFileSync11(file, "utf8");
|
|
2710
|
+
let content = original;
|
|
2711
|
+
for (const [from, to] of swaps) {
|
|
2712
|
+
content = content.replaceAll(from, to);
|
|
2713
|
+
}
|
|
2714
|
+
if (content !== original) {
|
|
2715
|
+
writeFileSync8(file, content, "utf8");
|
|
2716
|
+
count++;
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
if (count > 0) {
|
|
2720
|
+
console.log(chalk31.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2653
2724
|
// src/actions/packman/swapTsScriptsDependency.ts
|
|
2654
2725
|
import {
|
|
2655
|
-
existsSync as
|
|
2656
|
-
readFileSync as
|
|
2657
|
-
writeFileSync as
|
|
2726
|
+
existsSync as existsSync11,
|
|
2727
|
+
readFileSync as readFileSync12,
|
|
2728
|
+
writeFileSync as writeFileSync9
|
|
2658
2729
|
} from "fs";
|
|
2659
2730
|
import PATH12 from "path";
|
|
2660
|
-
import
|
|
2731
|
+
import chalk32 from "chalk";
|
|
2661
2732
|
var SWAP_MAP = {
|
|
2662
2733
|
"yarn-to-pnpm": [
|
|
2663
2734
|
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
@@ -2667,8 +2738,8 @@ var SWAP_MAP = {
|
|
|
2667
2738
|
]
|
|
2668
2739
|
};
|
|
2669
2740
|
function swapInPackageJson(pkgPath, direction) {
|
|
2670
|
-
if (!
|
|
2671
|
-
const raw =
|
|
2741
|
+
if (!existsSync11(pkgPath)) return false;
|
|
2742
|
+
const raw = readFileSync12(pkgPath, "utf8");
|
|
2672
2743
|
const pkg = JSON.parse(raw);
|
|
2673
2744
|
let changed = false;
|
|
2674
2745
|
for (const depField of ["dependencies", "devDependencies"]) {
|
|
@@ -2683,7 +2754,7 @@ function swapInPackageJson(pkgPath, direction) {
|
|
|
2683
2754
|
}
|
|
2684
2755
|
}
|
|
2685
2756
|
if (changed) {
|
|
2686
|
-
|
|
2757
|
+
writeFileSync9(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
2687
2758
|
}
|
|
2688
2759
|
return changed;
|
|
2689
2760
|
}
|
|
@@ -2700,7 +2771,7 @@ function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
|
2700
2771
|
}
|
|
2701
2772
|
if (count > 0) {
|
|
2702
2773
|
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
2703
|
-
console.log(
|
|
2774
|
+
console.log(chalk32.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
2704
2775
|
}
|
|
2705
2776
|
}
|
|
2706
2777
|
|
|
@@ -2711,13 +2782,13 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
|
2711
2782
|
for (const pattern of workspacePatterns) {
|
|
2712
2783
|
lines.push(` - '${pattern}'`);
|
|
2713
2784
|
}
|
|
2714
|
-
|
|
2715
|
-
console.log(
|
|
2785
|
+
writeFileSync10(PATH13.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
2786
|
+
console.log(chalk33.green(" Created pnpm-workspace.yaml"));
|
|
2716
2787
|
}
|
|
2717
2788
|
function readPnpmWorkspacePatterns(cwd) {
|
|
2718
2789
|
const wsPath = PATH13.join(cwd, "pnpm-workspace.yaml");
|
|
2719
|
-
if (!
|
|
2720
|
-
const content =
|
|
2790
|
+
if (!existsSync12(wsPath)) return [];
|
|
2791
|
+
const content = readFileSync13(wsPath, "utf8");
|
|
2721
2792
|
const patterns = [];
|
|
2722
2793
|
const lines = content.split("\n");
|
|
2723
2794
|
let inPackages = false;
|
|
@@ -2737,19 +2808,19 @@ function readPnpmWorkspacePatterns(cwd) {
|
|
|
2737
2808
|
}
|
|
2738
2809
|
function updateRootPackageJson(cwd) {
|
|
2739
2810
|
const pkgPath = PATH13.join(cwd, "package.json");
|
|
2740
|
-
const pkg = JSON.parse(
|
|
2811
|
+
const pkg = JSON.parse(readFileSync13(pkgPath, "utf8"));
|
|
2741
2812
|
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd);
|
|
2742
2813
|
delete pkg.workspaces;
|
|
2743
2814
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
2744
2815
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
2745
|
-
|
|
2746
|
-
console.log(
|
|
2816
|
+
writeFileSync10(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2817
|
+
console.log(chalk33.green(" Updated root package.json"));
|
|
2747
2818
|
return workspacePatterns;
|
|
2748
2819
|
}
|
|
2749
2820
|
function updateGitignore(cwd) {
|
|
2750
2821
|
const gitignorePath = PATH13.join(cwd, ".gitignore");
|
|
2751
|
-
if (!
|
|
2752
|
-
let content =
|
|
2822
|
+
if (!existsSync12(gitignorePath)) return;
|
|
2823
|
+
let content = readFileSync13(gitignorePath, "utf8");
|
|
2753
2824
|
const yarnLines = [
|
|
2754
2825
|
".pnp.*",
|
|
2755
2826
|
".pnp",
|
|
@@ -2764,64 +2835,65 @@ function updateGitignore(cwd) {
|
|
|
2764
2835
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
2765
2836
|
}
|
|
2766
2837
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
2767
|
-
|
|
2768
|
-
console.log(
|
|
2838
|
+
writeFileSync10(gitignorePath, content, "utf8");
|
|
2839
|
+
console.log(chalk33.green(" Updated .gitignore"));
|
|
2769
2840
|
}
|
|
2770
2841
|
function deleteYarnArtifacts(cwd) {
|
|
2771
2842
|
const yarnLock = PATH13.join(cwd, "yarn.lock");
|
|
2772
2843
|
const yarnrc = PATH13.join(cwd, ".yarnrc.yml");
|
|
2773
2844
|
const yarnDir = PATH13.join(cwd, ".yarn");
|
|
2774
|
-
if (
|
|
2845
|
+
if (existsSync12(yarnLock)) {
|
|
2775
2846
|
rmSync3(yarnLock);
|
|
2776
|
-
console.log(
|
|
2847
|
+
console.log(chalk33.gray(" Deleted yarn.lock"));
|
|
2777
2848
|
}
|
|
2778
|
-
if (
|
|
2849
|
+
if (existsSync12(yarnrc)) {
|
|
2779
2850
|
rmSync3(yarnrc);
|
|
2780
|
-
console.log(
|
|
2851
|
+
console.log(chalk33.gray(" Deleted .yarnrc.yml"));
|
|
2781
2852
|
}
|
|
2782
|
-
if (
|
|
2853
|
+
if (existsSync12(yarnDir)) {
|
|
2783
2854
|
rmSync3(yarnDir, { force: true, recursive: true });
|
|
2784
|
-
console.log(
|
|
2855
|
+
console.log(chalk33.gray(" Deleted .yarn/"));
|
|
2785
2856
|
}
|
|
2786
2857
|
}
|
|
2787
2858
|
function createNpmrc(cwd) {
|
|
2788
2859
|
const npmrcPath = PATH13.join(cwd, ".npmrc");
|
|
2789
|
-
if (
|
|
2860
|
+
if (existsSync12(npmrcPath)) return;
|
|
2790
2861
|
mkdirSync5(PATH13.dirname(npmrcPath), { recursive: true });
|
|
2791
|
-
|
|
2792
|
-
console.log(
|
|
2862
|
+
writeFileSync10(npmrcPath, "", "utf8");
|
|
2863
|
+
console.log(chalk33.green(" Created .npmrc"));
|
|
2793
2864
|
}
|
|
2794
2865
|
function convertToPnpm(cwd, workspacePackageJsonPaths) {
|
|
2795
|
-
console.log(
|
|
2866
|
+
console.log(chalk33.blue("\nConverting to pnpm...\n"));
|
|
2796
2867
|
const workspacePatterns = updateRootPackageJson(cwd);
|
|
2797
2868
|
createPnpmWorkspaceYaml(cwd, workspacePatterns);
|
|
2798
2869
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2799
2870
|
const fullPath = PATH13.resolve(cwd, pkgPath, "package.json");
|
|
2800
|
-
if (!
|
|
2801
|
-
const pkg = JSON.parse(
|
|
2871
|
+
if (!existsSync12(fullPath)) continue;
|
|
2872
|
+
const pkg = JSON.parse(readFileSync13(fullPath, "utf8"));
|
|
2802
2873
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
2803
2874
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
2804
|
-
|
|
2875
|
+
writeFileSync10(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2805
2876
|
}
|
|
2806
2877
|
}
|
|
2807
|
-
console.log(
|
|
2878
|
+
console.log(chalk33.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
2808
2879
|
updateGitignore(cwd);
|
|
2809
2880
|
createNpmrc(cwd);
|
|
2810
2881
|
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
2882
|
+
rewriteSourceImports(cwd, "yarn-to-pnpm");
|
|
2811
2883
|
deleteYarnArtifacts(cwd);
|
|
2812
|
-
console.log(
|
|
2884
|
+
console.log(chalk33.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
2813
2885
|
return 0;
|
|
2814
2886
|
}
|
|
2815
2887
|
|
|
2816
2888
|
// src/actions/packman/convertToYarn.ts
|
|
2817
2889
|
import {
|
|
2818
|
-
existsSync as
|
|
2819
|
-
readFileSync as
|
|
2890
|
+
existsSync as existsSync13,
|
|
2891
|
+
readFileSync as readFileSync14,
|
|
2820
2892
|
rmSync as rmSync4,
|
|
2821
|
-
writeFileSync as
|
|
2893
|
+
writeFileSync as writeFileSync11
|
|
2822
2894
|
} from "fs";
|
|
2823
2895
|
import PATH14 from "path";
|
|
2824
|
-
import
|
|
2896
|
+
import chalk34 from "chalk";
|
|
2825
2897
|
var YARN_VERSION = "4.13.0";
|
|
2826
2898
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
2827
2899
|
|
|
@@ -2844,8 +2916,8 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
2844
2916
|
`;
|
|
2845
2917
|
function readPnpmWorkspacePatterns2(cwd) {
|
|
2846
2918
|
const wsPath = PATH14.join(cwd, "pnpm-workspace.yaml");
|
|
2847
|
-
if (!
|
|
2848
|
-
const content =
|
|
2919
|
+
if (!existsSync13(wsPath)) return [];
|
|
2920
|
+
const content = readFileSync14(wsPath, "utf8");
|
|
2849
2921
|
const patterns = [];
|
|
2850
2922
|
const lines = content.split("\n");
|
|
2851
2923
|
let inPackages = false;
|
|
@@ -2865,102 +2937,103 @@ function readPnpmWorkspacePatterns2(cwd) {
|
|
|
2865
2937
|
}
|
|
2866
2938
|
function updateRootPackageJson2(cwd, workspacePatterns) {
|
|
2867
2939
|
const pkgPath = PATH14.join(cwd, "package.json");
|
|
2868
|
-
const pkg = JSON.parse(
|
|
2940
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
2869
2941
|
pkg.workspaces = workspacePatterns;
|
|
2870
2942
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
2871
2943
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
2872
|
-
|
|
2873
|
-
console.log(
|
|
2944
|
+
writeFileSync11(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2945
|
+
console.log(chalk34.green(" Updated root package.json"));
|
|
2874
2946
|
}
|
|
2875
2947
|
function updateGitignore2(cwd) {
|
|
2876
2948
|
const gitignorePath = PATH14.join(cwd, ".gitignore");
|
|
2877
|
-
let content =
|
|
2949
|
+
let content = existsSync13(gitignorePath) ? readFileSync14(gitignorePath, "utf8") : "";
|
|
2878
2950
|
if (!content.includes(".yarn/*")) {
|
|
2879
2951
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
2880
2952
|
}
|
|
2881
|
-
|
|
2882
|
-
console.log(
|
|
2953
|
+
writeFileSync11(gitignorePath, content, "utf8");
|
|
2954
|
+
console.log(chalk34.green(" Updated .gitignore"));
|
|
2883
2955
|
}
|
|
2884
2956
|
function deletePnpmArtifacts(cwd) {
|
|
2885
2957
|
const lockfile = PATH14.join(cwd, "pnpm-lock.yaml");
|
|
2886
2958
|
const workspaceYaml = PATH14.join(cwd, "pnpm-workspace.yaml");
|
|
2887
2959
|
const npmrc = PATH14.join(cwd, ".npmrc");
|
|
2888
|
-
if (
|
|
2960
|
+
if (existsSync13(lockfile)) {
|
|
2889
2961
|
rmSync4(lockfile);
|
|
2890
|
-
console.log(
|
|
2962
|
+
console.log(chalk34.gray(" Deleted pnpm-lock.yaml"));
|
|
2891
2963
|
}
|
|
2892
|
-
if (
|
|
2964
|
+
if (existsSync13(workspaceYaml)) {
|
|
2893
2965
|
rmSync4(workspaceYaml);
|
|
2894
|
-
console.log(
|
|
2966
|
+
console.log(chalk34.gray(" Deleted pnpm-workspace.yaml"));
|
|
2895
2967
|
}
|
|
2896
|
-
if (
|
|
2897
|
-
const content =
|
|
2968
|
+
if (existsSync13(npmrc)) {
|
|
2969
|
+
const content = readFileSync14(npmrc, "utf8");
|
|
2898
2970
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
2899
2971
|
rmSync4(npmrc);
|
|
2900
|
-
console.log(
|
|
2972
|
+
console.log(chalk34.gray(" Deleted .npmrc"));
|
|
2901
2973
|
}
|
|
2902
2974
|
}
|
|
2903
2975
|
}
|
|
2904
2976
|
function createYarnrc(cwd) {
|
|
2905
2977
|
const yarnrcPath = PATH14.join(cwd, ".yarnrc.yml");
|
|
2906
|
-
if (
|
|
2907
|
-
|
|
2908
|
-
console.log(
|
|
2978
|
+
if (existsSync13(yarnrcPath)) return;
|
|
2979
|
+
writeFileSync11(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
2980
|
+
console.log(chalk34.green(" Created .yarnrc.yml"));
|
|
2909
2981
|
}
|
|
2910
2982
|
function readWorkspacePatternsFromPackageJson(cwd) {
|
|
2911
2983
|
const pkgPath = PATH14.join(cwd, "package.json");
|
|
2912
|
-
if (!
|
|
2913
|
-
const pkg = JSON.parse(
|
|
2984
|
+
if (!existsSync13(pkgPath)) return [];
|
|
2985
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
2914
2986
|
return pkg.workspaces ?? [];
|
|
2915
2987
|
}
|
|
2916
2988
|
function convertToYarn(cwd, workspacePackageJsonPaths) {
|
|
2917
|
-
console.log(
|
|
2989
|
+
console.log(chalk34.blue("\nConverting to yarn...\n"));
|
|
2918
2990
|
const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
|
|
2919
2991
|
if (workspacePatterns.length === 0) {
|
|
2920
2992
|
const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
|
|
2921
2993
|
if (fromPkg.length > 0) {
|
|
2922
2994
|
workspacePatterns.push(...fromPkg);
|
|
2923
2995
|
} else {
|
|
2924
|
-
console.warn(
|
|
2996
|
+
console.warn(chalk34.yellow(" No workspace patterns found"));
|
|
2925
2997
|
}
|
|
2926
2998
|
}
|
|
2927
2999
|
updateRootPackageJson2(cwd, workspacePatterns);
|
|
2928
3000
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2929
3001
|
const fullPath = PATH14.resolve(cwd, pkgPath, "package.json");
|
|
2930
|
-
if (!
|
|
2931
|
-
const pkg = JSON.parse(
|
|
3002
|
+
if (!existsSync13(fullPath)) continue;
|
|
3003
|
+
const pkg = JSON.parse(readFileSync14(fullPath, "utf8"));
|
|
2932
3004
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
2933
3005
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
2934
|
-
|
|
3006
|
+
writeFileSync11(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2935
3007
|
}
|
|
2936
3008
|
}
|
|
2937
|
-
console.log(
|
|
3009
|
+
console.log(chalk34.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
2938
3010
|
updateGitignore2(cwd);
|
|
2939
3011
|
createYarnrc(cwd);
|
|
2940
3012
|
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
3013
|
+
rewriteSourceImports(cwd, "pnpm-to-yarn");
|
|
2941
3014
|
deletePnpmArtifacts(cwd);
|
|
2942
|
-
console.log(
|
|
3015
|
+
console.log(chalk34.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
2943
3016
|
return 0;
|
|
2944
3017
|
}
|
|
2945
3018
|
|
|
2946
3019
|
// src/actions/packman/convert.ts
|
|
2947
3020
|
function detectCurrentPM(cwd) {
|
|
2948
|
-
if (
|
|
3021
|
+
if (existsSync14(PATH15.join(cwd, "pnpm-lock.yaml")) || existsSync14(PATH15.join(cwd, "pnpm-workspace.yaml"))) {
|
|
2949
3022
|
return "pnpm";
|
|
2950
3023
|
}
|
|
2951
|
-
if (
|
|
3024
|
+
if (existsSync14(PATH15.join(cwd, "yarn.lock")) || existsSync14(PATH15.join(cwd, ".yarnrc.yml"))) {
|
|
2952
3025
|
return "yarn";
|
|
2953
3026
|
}
|
|
2954
3027
|
return "unknown";
|
|
2955
3028
|
}
|
|
2956
3029
|
function findWorkspacePackagePaths(cwd) {
|
|
2957
3030
|
const pkgPath = PATH15.join(cwd, "package.json");
|
|
2958
|
-
const pkg = JSON.parse(
|
|
3031
|
+
const pkg = JSON.parse(readFileSync15(pkgPath, "utf8"));
|
|
2959
3032
|
let patterns = pkg.workspaces ?? [];
|
|
2960
3033
|
if (patterns.length === 0) {
|
|
2961
3034
|
const wsPath = PATH15.join(cwd, "pnpm-workspace.yaml");
|
|
2962
|
-
if (
|
|
2963
|
-
const content =
|
|
3035
|
+
if (existsSync14(wsPath)) {
|
|
3036
|
+
const content = readFileSync15(wsPath, "utf8");
|
|
2964
3037
|
const lines = content.split("\n");
|
|
2965
3038
|
let inPackages = false;
|
|
2966
3039
|
for (const line of lines) {
|
|
@@ -2991,14 +3064,14 @@ function resolveWorkspaceGlob(cwd, pattern) {
|
|
|
2991
3064
|
function walkGlob(basePath, parts, currentPath) {
|
|
2992
3065
|
if (parts.length === 0) {
|
|
2993
3066
|
const fullPath = PATH15.join(basePath, currentPath);
|
|
2994
|
-
if (
|
|
3067
|
+
if (existsSync14(PATH15.join(fullPath, "package.json"))) {
|
|
2995
3068
|
return [currentPath];
|
|
2996
3069
|
}
|
|
2997
3070
|
return [];
|
|
2998
3071
|
}
|
|
2999
3072
|
const [part, ...rest] = parts;
|
|
3000
3073
|
const dirPath = PATH15.join(basePath, currentPath);
|
|
3001
|
-
if (!
|
|
3074
|
+
if (!existsSync14(dirPath) || !statSync3(dirPath).isDirectory()) {
|
|
3002
3075
|
return [];
|
|
3003
3076
|
}
|
|
3004
3077
|
if (part === "*" || part === "**") {
|
|
@@ -3026,25 +3099,25 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
3026
3099
|
function convert({ target, verbose }) {
|
|
3027
3100
|
const validTargets = ["pnpm", "yarn"];
|
|
3028
3101
|
if (!validTargets.includes(target)) {
|
|
3029
|
-
console.error(
|
|
3102
|
+
console.error(chalk35.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
3030
3103
|
return 1;
|
|
3031
3104
|
}
|
|
3032
3105
|
const cwd = process.cwd();
|
|
3033
3106
|
const currentPM = detectCurrentPM(cwd);
|
|
3034
3107
|
if (verbose) {
|
|
3035
|
-
console.log(
|
|
3036
|
-
console.log(
|
|
3108
|
+
console.log(chalk35.gray(`Current package manager: ${currentPM}`));
|
|
3109
|
+
console.log(chalk35.gray(`Target package manager: ${target}`));
|
|
3037
3110
|
}
|
|
3038
3111
|
if (currentPM === target) {
|
|
3039
|
-
console.log(
|
|
3112
|
+
console.log(chalk35.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
3040
3113
|
}
|
|
3041
3114
|
if (currentPM === "unknown") {
|
|
3042
|
-
console.error(
|
|
3115
|
+
console.error(chalk35.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
3043
3116
|
return 1;
|
|
3044
3117
|
}
|
|
3045
3118
|
const workspacePaths = findWorkspacePackagePaths(cwd);
|
|
3046
3119
|
if (verbose) {
|
|
3047
|
-
console.log(
|
|
3120
|
+
console.log(chalk35.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
3048
3121
|
}
|
|
3049
3122
|
if (target === "pnpm") {
|
|
3050
3123
|
return convertToPnpm(cwd, workspacePaths);
|
|
@@ -3102,7 +3175,7 @@ var rebuild = ({ target }) => {
|
|
|
3102
3175
|
};
|
|
3103
3176
|
|
|
3104
3177
|
// src/actions/recompile.ts
|
|
3105
|
-
import
|
|
3178
|
+
import chalk36 from "chalk";
|
|
3106
3179
|
var recompile = async ({
|
|
3107
3180
|
verbose,
|
|
3108
3181
|
target,
|
|
@@ -3137,7 +3210,7 @@ var recompileAll = async ({
|
|
|
3137
3210
|
const start = Date.now();
|
|
3138
3211
|
const targetOptions = target ? ["-t", target] : [];
|
|
3139
3212
|
if (jobs) {
|
|
3140
|
-
console.log(
|
|
3213
|
+
console.log(chalk36.blue(`Jobs set to [${jobs}]`));
|
|
3141
3214
|
}
|
|
3142
3215
|
const foreachOptions = {
|
|
3143
3216
|
incremental,
|
|
@@ -3150,25 +3223,25 @@ var recompileAll = async ({
|
|
|
3150
3223
|
pm.foreachWorkspace("package-compile", targetOptions, foreachOptions)
|
|
3151
3224
|
]);
|
|
3152
3225
|
console.log(
|
|
3153
|
-
`${
|
|
3226
|
+
`${chalk36.gray("Recompiled in")} [${chalk36.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk36.gray("seconds")}`
|
|
3154
3227
|
);
|
|
3155
3228
|
return result;
|
|
3156
3229
|
};
|
|
3157
3230
|
|
|
3158
3231
|
// src/actions/relint.ts
|
|
3159
|
-
import
|
|
3232
|
+
import chalk37 from "chalk";
|
|
3160
3233
|
var relintPackage = ({
|
|
3161
3234
|
pkg,
|
|
3162
3235
|
fix: fix2,
|
|
3163
3236
|
verbose
|
|
3164
3237
|
}) => {
|
|
3165
|
-
console.log(
|
|
3238
|
+
console.log(chalk37.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
3166
3239
|
const start = Date.now();
|
|
3167
3240
|
const pm = getPackageManager();
|
|
3168
3241
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
3169
3242
|
pm.runInWorkspace(pkg, fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint")
|
|
3170
3243
|
]);
|
|
3171
|
-
console.log(
|
|
3244
|
+
console.log(chalk37.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk37.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk37.gray("seconds")}`));
|
|
3172
3245
|
return result;
|
|
3173
3246
|
};
|
|
3174
3247
|
var relint = ({
|
|
@@ -3188,13 +3261,13 @@ var relint = ({
|
|
|
3188
3261
|
});
|
|
3189
3262
|
};
|
|
3190
3263
|
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
3191
|
-
console.log(
|
|
3264
|
+
console.log(chalk37.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
3192
3265
|
const start = Date.now();
|
|
3193
3266
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
3194
3267
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
3195
3268
|
["eslint", fixOptions]
|
|
3196
3269
|
]);
|
|
3197
|
-
console.log(
|
|
3270
|
+
console.log(chalk37.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk37.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk37.gray("seconds")}`));
|
|
3198
3271
|
return result;
|
|
3199
3272
|
};
|
|
3200
3273
|
|
|
@@ -3638,7 +3711,7 @@ var xyCommonCommands = (args) => {
|
|
|
3638
3711
|
};
|
|
3639
3712
|
|
|
3640
3713
|
// src/xy/lint/cycleCommand.ts
|
|
3641
|
-
import
|
|
3714
|
+
import chalk38 from "chalk";
|
|
3642
3715
|
var cycleCommand = {
|
|
3643
3716
|
command: "cycle [package]",
|
|
3644
3717
|
describe: "Cycle - Check for dependency cycles",
|
|
@@ -3649,12 +3722,12 @@ var cycleCommand = {
|
|
|
3649
3722
|
const start = Date.now();
|
|
3650
3723
|
if (argv.verbose) console.log("Cycle");
|
|
3651
3724
|
process.exitCode = await cycle({ pkg: argv.package });
|
|
3652
|
-
console.log(
|
|
3725
|
+
console.log(chalk38.blue(`Finished in ${Date.now() - start}ms`));
|
|
3653
3726
|
}
|
|
3654
3727
|
};
|
|
3655
3728
|
|
|
3656
3729
|
// src/xy/lint/deplintCommand.ts
|
|
3657
|
-
import
|
|
3730
|
+
import chalk39 from "chalk";
|
|
3658
3731
|
var deplintCommand = {
|
|
3659
3732
|
command: "deplint [package]",
|
|
3660
3733
|
describe: "Deplint - Run Deplint",
|
|
@@ -3692,12 +3765,12 @@ var deplintCommand = {
|
|
|
3692
3765
|
peerDeps: !!argv.peerDeps,
|
|
3693
3766
|
verbose: !!argv.verbose
|
|
3694
3767
|
});
|
|
3695
|
-
console.log(
|
|
3768
|
+
console.log(chalk39.blue(`Finished in ${Date.now() - start}ms`));
|
|
3696
3769
|
}
|
|
3697
3770
|
};
|
|
3698
3771
|
|
|
3699
3772
|
// src/xy/lint/fixCommand.ts
|
|
3700
|
-
import
|
|
3773
|
+
import chalk40 from "chalk";
|
|
3701
3774
|
var fixCommand = {
|
|
3702
3775
|
command: "fix [package]",
|
|
3703
3776
|
describe: "Fix - Run Eslint w/fix",
|
|
@@ -3708,12 +3781,12 @@ var fixCommand = {
|
|
|
3708
3781
|
const start = Date.now();
|
|
3709
3782
|
if (argv.verbose) console.log("Fix");
|
|
3710
3783
|
process.exitCode = fix();
|
|
3711
|
-
console.log(
|
|
3784
|
+
console.log(chalk40.blue(`Finished in ${Date.now() - start}ms`));
|
|
3712
3785
|
}
|
|
3713
3786
|
};
|
|
3714
3787
|
|
|
3715
3788
|
// src/xy/lint/knipCommand.ts
|
|
3716
|
-
import
|
|
3789
|
+
import chalk41 from "chalk";
|
|
3717
3790
|
var knipCommand = {
|
|
3718
3791
|
command: "knip",
|
|
3719
3792
|
describe: "Knip - Run Knip",
|
|
@@ -3724,12 +3797,12 @@ var knipCommand = {
|
|
|
3724
3797
|
if (argv.verbose) console.log("Knip");
|
|
3725
3798
|
const start = Date.now();
|
|
3726
3799
|
process.exitCode = knip();
|
|
3727
|
-
console.log(
|
|
3800
|
+
console.log(chalk41.blue(`Knip finished in ${Date.now() - start}ms`));
|
|
3728
3801
|
}
|
|
3729
3802
|
};
|
|
3730
3803
|
|
|
3731
3804
|
// src/xy/lint/lintCommand.ts
|
|
3732
|
-
import
|
|
3805
|
+
import chalk42 from "chalk";
|
|
3733
3806
|
var lintCommand = {
|
|
3734
3807
|
command: "lint [package]",
|
|
3735
3808
|
describe: "Lint - Run Eslint",
|
|
@@ -3758,7 +3831,7 @@ var lintCommand = {
|
|
|
3758
3831
|
cache: argv.cache,
|
|
3759
3832
|
verbose: !!argv.verbose
|
|
3760
3833
|
});
|
|
3761
|
-
console.log(
|
|
3834
|
+
console.log(chalk42.blue(`Finished in ${Date.now() - start}ms`));
|
|
3762
3835
|
}
|
|
3763
3836
|
};
|
|
3764
3837
|
|
|
@@ -3800,7 +3873,7 @@ var packageLintCommand = {
|
|
|
3800
3873
|
};
|
|
3801
3874
|
|
|
3802
3875
|
// src/xy/lint/publintCommand.ts
|
|
3803
|
-
import
|
|
3876
|
+
import chalk43 from "chalk";
|
|
3804
3877
|
var publintCommand = {
|
|
3805
3878
|
command: "publint [package]",
|
|
3806
3879
|
describe: "Publint - Run Publint",
|
|
@@ -3811,12 +3884,12 @@ var publintCommand = {
|
|
|
3811
3884
|
if (argv.verbose) console.log("Publint");
|
|
3812
3885
|
const start = Date.now();
|
|
3813
3886
|
process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
|
|
3814
|
-
console.log(
|
|
3887
|
+
console.log(chalk43.blue(`Finished in ${Date.now() - start}ms`));
|
|
3815
3888
|
}
|
|
3816
3889
|
};
|
|
3817
3890
|
|
|
3818
3891
|
// src/xy/lint/relintCommand.ts
|
|
3819
|
-
import
|
|
3892
|
+
import chalk44 from "chalk";
|
|
3820
3893
|
var relintCommand = {
|
|
3821
3894
|
command: "relint [package]",
|
|
3822
3895
|
describe: "Relint - Clean & Lint",
|
|
@@ -3827,12 +3900,12 @@ var relintCommand = {
|
|
|
3827
3900
|
if (argv.verbose) console.log("Relinting");
|
|
3828
3901
|
const start = Date.now();
|
|
3829
3902
|
process.exitCode = relint();
|
|
3830
|
-
console.log(
|
|
3903
|
+
console.log(chalk44.blue(`Finished in ${Date.now() - start}ms`));
|
|
3831
3904
|
}
|
|
3832
3905
|
};
|
|
3833
3906
|
|
|
3834
3907
|
// src/xy/lint/sonarCommand.ts
|
|
3835
|
-
import
|
|
3908
|
+
import chalk45 from "chalk";
|
|
3836
3909
|
var sonarCommand = {
|
|
3837
3910
|
command: "sonar",
|
|
3838
3911
|
describe: "Sonar - Run Sonar Check",
|
|
@@ -3843,7 +3916,7 @@ var sonarCommand = {
|
|
|
3843
3916
|
const start = Date.now();
|
|
3844
3917
|
if (argv.verbose) console.log("Sonar Check");
|
|
3845
3918
|
process.exitCode = sonar();
|
|
3846
|
-
console.log(
|
|
3919
|
+
console.log(chalk45.blue(`Finished in ${Date.now() - start}ms`));
|
|
3847
3920
|
}
|
|
3848
3921
|
};
|
|
3849
3922
|
|
|
@@ -3853,7 +3926,7 @@ var xyLintCommands = (args) => {
|
|
|
3853
3926
|
};
|
|
3854
3927
|
|
|
3855
3928
|
// src/xy/xy.ts
|
|
3856
|
-
import
|
|
3929
|
+
import chalk46 from "chalk";
|
|
3857
3930
|
|
|
3858
3931
|
// src/xy/xyParseOptions.ts
|
|
3859
3932
|
import yargs from "yargs";
|
|
@@ -3896,8 +3969,8 @@ var xyBase = async (plugins) => {
|
|
|
3896
3969
|
let args = xyBuildCommands(xyCommonCommands(xyLintCommands(options)));
|
|
3897
3970
|
if (plugins) args = plugins(args);
|
|
3898
3971
|
return await args.demandCommand(1).command("*", "", () => {
|
|
3899
|
-
console.error(
|
|
3900
|
-
console.log(
|
|
3972
|
+
console.error(chalk46.yellow(`Command not found [${chalk46.magenta(process.argv[2])}]`));
|
|
3973
|
+
console.log(chalk46.gray("Try 'xy --help' for list of commands"));
|
|
3901
3974
|
}).version().help().argv;
|
|
3902
3975
|
};
|
|
3903
3976
|
export {
|