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