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