@xylabs/ts-scripts-common 7.5.1 → 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 +270 -110
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/packman/convert.mjs +242 -100
- package/dist/actions/packman/convert.mjs.map +1 -1
- package/dist/actions/packman/convertToPnpm.mjs +168 -38
- package/dist/actions/packman/convertToPnpm.mjs.map +1 -1
- package/dist/actions/packman/convertToYarn.mjs +158 -38
- package/dist/actions/packman/convertToYarn.mjs.map +1 -1
- package/dist/actions/packman/index.mjs +242 -100
- 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/actions/packman/swapTsScriptsDependency.mjs +57 -0
- package/dist/actions/packman/swapTsScriptsDependency.mjs.map +1 -0
- package/dist/bin/xy.mjs +287 -127
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +289 -129
- package/dist/index.mjs.map +1 -1
- package/dist/xy/common/index.mjs +242 -100
- package/dist/xy/common/index.mjs.map +1 -1
- package/dist/xy/common/packmanCommand.mjs +242 -100
- package/dist/xy/common/packmanCommand.mjs.map +1 -1
- package/dist/xy/index.mjs +287 -127
- 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 +287 -127
- 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
|
-
import
|
|
2594
|
-
import
|
|
2611
|
+
import PATH15 from "path";
|
|
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
|
-
import
|
|
2605
|
-
import
|
|
2622
|
+
import PATH13 from "path";
|
|
2623
|
+
import chalk33 from "chalk";
|
|
2606
2624
|
|
|
2607
2625
|
// src/actions/packman/rewriteScripts.ts
|
|
2608
2626
|
function rewriteYarnToPnpm(script) {
|
|
@@ -2652,6 +2670,113 @@ 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
|
+
|
|
2726
|
+
// src/actions/packman/swapTsScriptsDependency.ts
|
|
2727
|
+
import {
|
|
2728
|
+
existsSync as existsSync11,
|
|
2729
|
+
readFileSync as readFileSync12,
|
|
2730
|
+
writeFileSync as writeFileSync9
|
|
2731
|
+
} from "fs";
|
|
2732
|
+
import PATH12 from "path";
|
|
2733
|
+
import chalk32 from "chalk";
|
|
2734
|
+
var SWAP_MAP = {
|
|
2735
|
+
"yarn-to-pnpm": [
|
|
2736
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
2737
|
+
],
|
|
2738
|
+
"pnpm-to-yarn": [
|
|
2739
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"]
|
|
2740
|
+
]
|
|
2741
|
+
};
|
|
2742
|
+
function swapInPackageJson(pkgPath, direction) {
|
|
2743
|
+
if (!existsSync11(pkgPath)) return false;
|
|
2744
|
+
const raw = readFileSync12(pkgPath, "utf8");
|
|
2745
|
+
const pkg = JSON.parse(raw);
|
|
2746
|
+
let changed = false;
|
|
2747
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
2748
|
+
const deps = pkg[depField];
|
|
2749
|
+
if (!deps) continue;
|
|
2750
|
+
for (const [from, to] of SWAP_MAP[direction]) {
|
|
2751
|
+
if (deps[from]) {
|
|
2752
|
+
deps[to] = deps[from];
|
|
2753
|
+
delete deps[from];
|
|
2754
|
+
changed = true;
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
if (changed) {
|
|
2759
|
+
writeFileSync9(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
2760
|
+
}
|
|
2761
|
+
return changed;
|
|
2762
|
+
}
|
|
2763
|
+
function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
2764
|
+
let count = 0;
|
|
2765
|
+
if (swapInPackageJson(PATH12.join(cwd, "package.json"), direction)) {
|
|
2766
|
+
count++;
|
|
2767
|
+
}
|
|
2768
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2769
|
+
const fullPath = PATH12.resolve(cwd, pkgPath, "package.json");
|
|
2770
|
+
if (swapInPackageJson(fullPath, direction)) {
|
|
2771
|
+
count++;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
if (count > 0) {
|
|
2775
|
+
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
2776
|
+
console.log(chalk32.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2655
2780
|
// src/actions/packman/convertToPnpm.ts
|
|
2656
2781
|
var PNPM_VERSION = "10.12.1";
|
|
2657
2782
|
function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
@@ -2659,24 +2784,45 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
|
2659
2784
|
for (const pattern of workspacePatterns) {
|
|
2660
2785
|
lines.push(` - '${pattern}'`);
|
|
2661
2786
|
}
|
|
2662
|
-
|
|
2663
|
-
console.log(
|
|
2787
|
+
writeFileSync10(PATH13.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
2788
|
+
console.log(chalk33.green(" Created pnpm-workspace.yaml"));
|
|
2789
|
+
}
|
|
2790
|
+
function readPnpmWorkspacePatterns(cwd) {
|
|
2791
|
+
const wsPath = PATH13.join(cwd, "pnpm-workspace.yaml");
|
|
2792
|
+
if (!existsSync12(wsPath)) return [];
|
|
2793
|
+
const content = readFileSync13(wsPath, "utf8");
|
|
2794
|
+
const patterns = [];
|
|
2795
|
+
const lines = content.split("\n");
|
|
2796
|
+
let inPackages = false;
|
|
2797
|
+
for (const line of lines) {
|
|
2798
|
+
if (line.trim() === "packages:") {
|
|
2799
|
+
inPackages = true;
|
|
2800
|
+
continue;
|
|
2801
|
+
}
|
|
2802
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
2803
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
2804
|
+
if (pattern) patterns.push(pattern);
|
|
2805
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
2806
|
+
inPackages = false;
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
return patterns;
|
|
2664
2810
|
}
|
|
2665
2811
|
function updateRootPackageJson(cwd) {
|
|
2666
|
-
const pkgPath =
|
|
2667
|
-
const pkg = JSON.parse(
|
|
2668
|
-
const workspacePatterns = pkg.workspaces ??
|
|
2812
|
+
const pkgPath = PATH13.join(cwd, "package.json");
|
|
2813
|
+
const pkg = JSON.parse(readFileSync13(pkgPath, "utf8"));
|
|
2814
|
+
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd);
|
|
2669
2815
|
delete pkg.workspaces;
|
|
2670
2816
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
2671
2817
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
2672
|
-
|
|
2673
|
-
console.log(
|
|
2818
|
+
writeFileSync10(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2819
|
+
console.log(chalk33.green(" Updated root package.json"));
|
|
2674
2820
|
return workspacePatterns;
|
|
2675
2821
|
}
|
|
2676
2822
|
function updateGitignore(cwd) {
|
|
2677
|
-
const gitignorePath =
|
|
2678
|
-
if (!
|
|
2679
|
-
let content =
|
|
2823
|
+
const gitignorePath = PATH13.join(cwd, ".gitignore");
|
|
2824
|
+
if (!existsSync12(gitignorePath)) return;
|
|
2825
|
+
let content = readFileSync13(gitignorePath, "utf8");
|
|
2680
2826
|
const yarnLines = [
|
|
2681
2827
|
".pnp.*",
|
|
2682
2828
|
".pnp",
|
|
@@ -2691,63 +2837,65 @@ function updateGitignore(cwd) {
|
|
|
2691
2837
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
2692
2838
|
}
|
|
2693
2839
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
2694
|
-
|
|
2695
|
-
console.log(
|
|
2840
|
+
writeFileSync10(gitignorePath, content, "utf8");
|
|
2841
|
+
console.log(chalk33.green(" Updated .gitignore"));
|
|
2696
2842
|
}
|
|
2697
2843
|
function deleteYarnArtifacts(cwd) {
|
|
2698
|
-
const yarnLock =
|
|
2699
|
-
const yarnrc =
|
|
2700
|
-
const yarnDir =
|
|
2701
|
-
if (
|
|
2844
|
+
const yarnLock = PATH13.join(cwd, "yarn.lock");
|
|
2845
|
+
const yarnrc = PATH13.join(cwd, ".yarnrc.yml");
|
|
2846
|
+
const yarnDir = PATH13.join(cwd, ".yarn");
|
|
2847
|
+
if (existsSync12(yarnLock)) {
|
|
2702
2848
|
rmSync3(yarnLock);
|
|
2703
|
-
console.log(
|
|
2849
|
+
console.log(chalk33.gray(" Deleted yarn.lock"));
|
|
2704
2850
|
}
|
|
2705
|
-
if (
|
|
2851
|
+
if (existsSync12(yarnrc)) {
|
|
2706
2852
|
rmSync3(yarnrc);
|
|
2707
|
-
console.log(
|
|
2853
|
+
console.log(chalk33.gray(" Deleted .yarnrc.yml"));
|
|
2708
2854
|
}
|
|
2709
|
-
if (
|
|
2855
|
+
if (existsSync12(yarnDir)) {
|
|
2710
2856
|
rmSync3(yarnDir, { force: true, recursive: true });
|
|
2711
|
-
console.log(
|
|
2857
|
+
console.log(chalk33.gray(" Deleted .yarn/"));
|
|
2712
2858
|
}
|
|
2713
2859
|
}
|
|
2714
2860
|
function createNpmrc(cwd) {
|
|
2715
|
-
const npmrcPath =
|
|
2716
|
-
if (
|
|
2717
|
-
mkdirSync5(
|
|
2718
|
-
|
|
2719
|
-
console.log(
|
|
2861
|
+
const npmrcPath = PATH13.join(cwd, ".npmrc");
|
|
2862
|
+
if (existsSync12(npmrcPath)) return;
|
|
2863
|
+
mkdirSync5(PATH13.dirname(npmrcPath), { recursive: true });
|
|
2864
|
+
writeFileSync10(npmrcPath, "", "utf8");
|
|
2865
|
+
console.log(chalk33.green(" Created .npmrc"));
|
|
2720
2866
|
}
|
|
2721
2867
|
function convertToPnpm(cwd, workspacePackageJsonPaths) {
|
|
2722
|
-
console.log(
|
|
2868
|
+
console.log(chalk33.blue("\nConverting to pnpm...\n"));
|
|
2723
2869
|
const workspacePatterns = updateRootPackageJson(cwd);
|
|
2724
2870
|
createPnpmWorkspaceYaml(cwd, workspacePatterns);
|
|
2725
2871
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2726
|
-
const fullPath =
|
|
2727
|
-
if (!
|
|
2728
|
-
const pkg = JSON.parse(
|
|
2872
|
+
const fullPath = PATH13.resolve(cwd, pkgPath, "package.json");
|
|
2873
|
+
if (!existsSync12(fullPath)) continue;
|
|
2874
|
+
const pkg = JSON.parse(readFileSync13(fullPath, "utf8"));
|
|
2729
2875
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
2730
2876
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
2731
|
-
|
|
2877
|
+
writeFileSync10(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2732
2878
|
}
|
|
2733
2879
|
}
|
|
2734
|
-
console.log(
|
|
2880
|
+
console.log(chalk33.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
2735
2881
|
updateGitignore(cwd);
|
|
2736
2882
|
createNpmrc(cwd);
|
|
2883
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
2884
|
+
rewriteSourceImports(cwd, "yarn-to-pnpm");
|
|
2737
2885
|
deleteYarnArtifacts(cwd);
|
|
2738
|
-
console.log(
|
|
2886
|
+
console.log(chalk33.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
2739
2887
|
return 0;
|
|
2740
2888
|
}
|
|
2741
2889
|
|
|
2742
2890
|
// src/actions/packman/convertToYarn.ts
|
|
2743
2891
|
import {
|
|
2744
|
-
existsSync as
|
|
2745
|
-
readFileSync as
|
|
2892
|
+
existsSync as existsSync13,
|
|
2893
|
+
readFileSync as readFileSync14,
|
|
2746
2894
|
rmSync as rmSync4,
|
|
2747
|
-
writeFileSync as
|
|
2895
|
+
writeFileSync as writeFileSync11
|
|
2748
2896
|
} from "fs";
|
|
2749
|
-
import
|
|
2750
|
-
import
|
|
2897
|
+
import PATH14 from "path";
|
|
2898
|
+
import chalk34 from "chalk";
|
|
2751
2899
|
var YARN_VERSION = "4.13.0";
|
|
2752
2900
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
2753
2901
|
|
|
@@ -2768,10 +2916,10 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
2768
2916
|
!.yarn/sdks
|
|
2769
2917
|
!.yarn/versions
|
|
2770
2918
|
`;
|
|
2771
|
-
function
|
|
2772
|
-
const wsPath =
|
|
2773
|
-
if (!
|
|
2774
|
-
const content =
|
|
2919
|
+
function readPnpmWorkspacePatterns2(cwd) {
|
|
2920
|
+
const wsPath = PATH14.join(cwd, "pnpm-workspace.yaml");
|
|
2921
|
+
if (!existsSync13(wsPath)) return [];
|
|
2922
|
+
const content = readFileSync14(wsPath, "utf8");
|
|
2775
2923
|
const patterns = [];
|
|
2776
2924
|
const lines = content.split("\n");
|
|
2777
2925
|
let inPackages = false;
|
|
@@ -2790,91 +2938,104 @@ function readPnpmWorkspacePatterns(cwd) {
|
|
|
2790
2938
|
return patterns;
|
|
2791
2939
|
}
|
|
2792
2940
|
function updateRootPackageJson2(cwd, workspacePatterns) {
|
|
2793
|
-
const pkgPath =
|
|
2794
|
-
const pkg = JSON.parse(
|
|
2941
|
+
const pkgPath = PATH14.join(cwd, "package.json");
|
|
2942
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
2795
2943
|
pkg.workspaces = workspacePatterns;
|
|
2796
2944
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
2797
2945
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
2798
|
-
|
|
2799
|
-
console.log(
|
|
2946
|
+
writeFileSync11(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2947
|
+
console.log(chalk34.green(" Updated root package.json"));
|
|
2800
2948
|
}
|
|
2801
2949
|
function updateGitignore2(cwd) {
|
|
2802
|
-
const gitignorePath =
|
|
2803
|
-
let content =
|
|
2950
|
+
const gitignorePath = PATH14.join(cwd, ".gitignore");
|
|
2951
|
+
let content = existsSync13(gitignorePath) ? readFileSync14(gitignorePath, "utf8") : "";
|
|
2804
2952
|
if (!content.includes(".yarn/*")) {
|
|
2805
2953
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
2806
2954
|
}
|
|
2807
|
-
|
|
2808
|
-
console.log(
|
|
2955
|
+
writeFileSync11(gitignorePath, content, "utf8");
|
|
2956
|
+
console.log(chalk34.green(" Updated .gitignore"));
|
|
2809
2957
|
}
|
|
2810
2958
|
function deletePnpmArtifacts(cwd) {
|
|
2811
|
-
const lockfile =
|
|
2812
|
-
const workspaceYaml =
|
|
2813
|
-
const npmrc =
|
|
2814
|
-
if (
|
|
2959
|
+
const lockfile = PATH14.join(cwd, "pnpm-lock.yaml");
|
|
2960
|
+
const workspaceYaml = PATH14.join(cwd, "pnpm-workspace.yaml");
|
|
2961
|
+
const npmrc = PATH14.join(cwd, ".npmrc");
|
|
2962
|
+
if (existsSync13(lockfile)) {
|
|
2815
2963
|
rmSync4(lockfile);
|
|
2816
|
-
console.log(
|
|
2964
|
+
console.log(chalk34.gray(" Deleted pnpm-lock.yaml"));
|
|
2817
2965
|
}
|
|
2818
|
-
if (
|
|
2966
|
+
if (existsSync13(workspaceYaml)) {
|
|
2819
2967
|
rmSync4(workspaceYaml);
|
|
2820
|
-
console.log(
|
|
2968
|
+
console.log(chalk34.gray(" Deleted pnpm-workspace.yaml"));
|
|
2821
2969
|
}
|
|
2822
|
-
if (
|
|
2823
|
-
const content =
|
|
2970
|
+
if (existsSync13(npmrc)) {
|
|
2971
|
+
const content = readFileSync14(npmrc, "utf8");
|
|
2824
2972
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
2825
2973
|
rmSync4(npmrc);
|
|
2826
|
-
console.log(
|
|
2974
|
+
console.log(chalk34.gray(" Deleted .npmrc"));
|
|
2827
2975
|
}
|
|
2828
2976
|
}
|
|
2829
2977
|
}
|
|
2830
2978
|
function createYarnrc(cwd) {
|
|
2831
|
-
const yarnrcPath =
|
|
2832
|
-
if (
|
|
2833
|
-
|
|
2834
|
-
console.log(
|
|
2979
|
+
const yarnrcPath = PATH14.join(cwd, ".yarnrc.yml");
|
|
2980
|
+
if (existsSync13(yarnrcPath)) return;
|
|
2981
|
+
writeFileSync11(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
2982
|
+
console.log(chalk34.green(" Created .yarnrc.yml"));
|
|
2983
|
+
}
|
|
2984
|
+
function readWorkspacePatternsFromPackageJson(cwd) {
|
|
2985
|
+
const pkgPath = PATH14.join(cwd, "package.json");
|
|
2986
|
+
if (!existsSync13(pkgPath)) return [];
|
|
2987
|
+
const pkg = JSON.parse(readFileSync14(pkgPath, "utf8"));
|
|
2988
|
+
return pkg.workspaces ?? [];
|
|
2835
2989
|
}
|
|
2836
2990
|
function convertToYarn(cwd, workspacePackageJsonPaths) {
|
|
2837
|
-
console.log(
|
|
2838
|
-
const workspacePatterns =
|
|
2991
|
+
console.log(chalk34.blue("\nConverting to yarn...\n"));
|
|
2992
|
+
const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
|
|
2839
2993
|
if (workspacePatterns.length === 0) {
|
|
2840
|
-
|
|
2994
|
+
const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
|
|
2995
|
+
if (fromPkg.length > 0) {
|
|
2996
|
+
workspacePatterns.push(...fromPkg);
|
|
2997
|
+
} else {
|
|
2998
|
+
console.warn(chalk34.yellow(" No workspace patterns found"));
|
|
2999
|
+
}
|
|
2841
3000
|
}
|
|
2842
3001
|
updateRootPackageJson2(cwd, workspacePatterns);
|
|
2843
3002
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
2844
|
-
const fullPath =
|
|
2845
|
-
if (!
|
|
2846
|
-
const pkg = JSON.parse(
|
|
3003
|
+
const fullPath = PATH14.resolve(cwd, pkgPath, "package.json");
|
|
3004
|
+
if (!existsSync13(fullPath)) continue;
|
|
3005
|
+
const pkg = JSON.parse(readFileSync14(fullPath, "utf8"));
|
|
2847
3006
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
2848
3007
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
2849
|
-
|
|
3008
|
+
writeFileSync11(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
2850
3009
|
}
|
|
2851
3010
|
}
|
|
2852
|
-
console.log(
|
|
3011
|
+
console.log(chalk34.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
2853
3012
|
updateGitignore2(cwd);
|
|
2854
3013
|
createYarnrc(cwd);
|
|
3014
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
3015
|
+
rewriteSourceImports(cwd, "pnpm-to-yarn");
|
|
2855
3016
|
deletePnpmArtifacts(cwd);
|
|
2856
|
-
console.log(
|
|
3017
|
+
console.log(chalk34.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
2857
3018
|
return 0;
|
|
2858
3019
|
}
|
|
2859
3020
|
|
|
2860
3021
|
// src/actions/packman/convert.ts
|
|
2861
3022
|
function detectCurrentPM(cwd) {
|
|
2862
|
-
if (
|
|
3023
|
+
if (existsSync14(PATH15.join(cwd, "pnpm-lock.yaml")) || existsSync14(PATH15.join(cwd, "pnpm-workspace.yaml"))) {
|
|
2863
3024
|
return "pnpm";
|
|
2864
3025
|
}
|
|
2865
|
-
if (
|
|
3026
|
+
if (existsSync14(PATH15.join(cwd, "yarn.lock")) || existsSync14(PATH15.join(cwd, ".yarnrc.yml"))) {
|
|
2866
3027
|
return "yarn";
|
|
2867
3028
|
}
|
|
2868
3029
|
return "unknown";
|
|
2869
3030
|
}
|
|
2870
3031
|
function findWorkspacePackagePaths(cwd) {
|
|
2871
|
-
const pkgPath =
|
|
2872
|
-
const pkg = JSON.parse(
|
|
3032
|
+
const pkgPath = PATH15.join(cwd, "package.json");
|
|
3033
|
+
const pkg = JSON.parse(readFileSync15(pkgPath, "utf8"));
|
|
2873
3034
|
let patterns = pkg.workspaces ?? [];
|
|
2874
3035
|
if (patterns.length === 0) {
|
|
2875
|
-
const wsPath =
|
|
2876
|
-
if (
|
|
2877
|
-
const content =
|
|
3036
|
+
const wsPath = PATH15.join(cwd, "pnpm-workspace.yaml");
|
|
3037
|
+
if (existsSync14(wsPath)) {
|
|
3038
|
+
const content = readFileSync15(wsPath, "utf8");
|
|
2878
3039
|
const lines = content.split("\n");
|
|
2879
3040
|
let inPackages = false;
|
|
2880
3041
|
for (const line of lines) {
|
|
@@ -2904,15 +3065,15 @@ function resolveWorkspaceGlob(cwd, pattern) {
|
|
|
2904
3065
|
}
|
|
2905
3066
|
function walkGlob(basePath, parts, currentPath) {
|
|
2906
3067
|
if (parts.length === 0) {
|
|
2907
|
-
const fullPath =
|
|
2908
|
-
if (
|
|
3068
|
+
const fullPath = PATH15.join(basePath, currentPath);
|
|
3069
|
+
if (existsSync14(PATH15.join(fullPath, "package.json"))) {
|
|
2909
3070
|
return [currentPath];
|
|
2910
3071
|
}
|
|
2911
3072
|
return [];
|
|
2912
3073
|
}
|
|
2913
3074
|
const [part, ...rest] = parts;
|
|
2914
|
-
const dirPath =
|
|
2915
|
-
if (!
|
|
3075
|
+
const dirPath = PATH15.join(basePath, currentPath);
|
|
3076
|
+
if (!existsSync14(dirPath) || !statSync3(dirPath).isDirectory()) {
|
|
2916
3077
|
return [];
|
|
2917
3078
|
}
|
|
2918
3079
|
if (part === "*" || part === "**") {
|
|
@@ -2940,26 +3101,25 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
2940
3101
|
function convert({ target, verbose }) {
|
|
2941
3102
|
const validTargets = ["pnpm", "yarn"];
|
|
2942
3103
|
if (!validTargets.includes(target)) {
|
|
2943
|
-
console.error(
|
|
3104
|
+
console.error(chalk35.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
2944
3105
|
return 1;
|
|
2945
3106
|
}
|
|
2946
3107
|
const cwd = process.cwd();
|
|
2947
3108
|
const currentPM = detectCurrentPM(cwd);
|
|
2948
3109
|
if (verbose) {
|
|
2949
|
-
console.log(
|
|
2950
|
-
console.log(
|
|
3110
|
+
console.log(chalk35.gray(`Current package manager: ${currentPM}`));
|
|
3111
|
+
console.log(chalk35.gray(`Target package manager: ${target}`));
|
|
2951
3112
|
}
|
|
2952
3113
|
if (currentPM === target) {
|
|
2953
|
-
console.
|
|
2954
|
-
return 1;
|
|
3114
|
+
console.log(chalk35.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
2955
3115
|
}
|
|
2956
3116
|
if (currentPM === "unknown") {
|
|
2957
|
-
console.error(
|
|
3117
|
+
console.error(chalk35.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
2958
3118
|
return 1;
|
|
2959
3119
|
}
|
|
2960
3120
|
const workspacePaths = findWorkspacePackagePaths(cwd);
|
|
2961
3121
|
if (verbose) {
|
|
2962
|
-
console.log(
|
|
3122
|
+
console.log(chalk35.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
2963
3123
|
}
|
|
2964
3124
|
if (target === "pnpm") {
|
|
2965
3125
|
return convertToPnpm(cwd, workspacePaths);
|
|
@@ -3017,7 +3177,7 @@ var rebuild = ({ target }) => {
|
|
|
3017
3177
|
};
|
|
3018
3178
|
|
|
3019
3179
|
// src/actions/recompile.ts
|
|
3020
|
-
import
|
|
3180
|
+
import chalk36 from "chalk";
|
|
3021
3181
|
var recompile = async ({
|
|
3022
3182
|
verbose,
|
|
3023
3183
|
target,
|
|
@@ -3052,7 +3212,7 @@ var recompileAll = async ({
|
|
|
3052
3212
|
const start = Date.now();
|
|
3053
3213
|
const targetOptions = target ? ["-t", target] : [];
|
|
3054
3214
|
if (jobs) {
|
|
3055
|
-
console.log(
|
|
3215
|
+
console.log(chalk36.blue(`Jobs set to [${jobs}]`));
|
|
3056
3216
|
}
|
|
3057
3217
|
const foreachOptions = {
|
|
3058
3218
|
incremental,
|
|
@@ -3065,25 +3225,25 @@ var recompileAll = async ({
|
|
|
3065
3225
|
pm.foreachWorkspace("package-compile", targetOptions, foreachOptions)
|
|
3066
3226
|
]);
|
|
3067
3227
|
console.log(
|
|
3068
|
-
`${
|
|
3228
|
+
`${chalk36.gray("Recompiled in")} [${chalk36.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk36.gray("seconds")}`
|
|
3069
3229
|
);
|
|
3070
3230
|
return result;
|
|
3071
3231
|
};
|
|
3072
3232
|
|
|
3073
3233
|
// src/actions/relint.ts
|
|
3074
|
-
import
|
|
3234
|
+
import chalk37 from "chalk";
|
|
3075
3235
|
var relintPackage = ({
|
|
3076
3236
|
pkg,
|
|
3077
3237
|
fix: fix2,
|
|
3078
3238
|
verbose
|
|
3079
3239
|
}) => {
|
|
3080
|
-
console.log(
|
|
3240
|
+
console.log(chalk37.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
3081
3241
|
const start = Date.now();
|
|
3082
3242
|
const pm = getPackageManager();
|
|
3083
3243
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
3084
3244
|
pm.runInWorkspace(pkg, fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint")
|
|
3085
3245
|
]);
|
|
3086
|
-
console.log(
|
|
3246
|
+
console.log(chalk37.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk37.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk37.gray("seconds")}`));
|
|
3087
3247
|
return result;
|
|
3088
3248
|
};
|
|
3089
3249
|
var relint = ({
|
|
@@ -3103,13 +3263,13 @@ var relint = ({
|
|
|
3103
3263
|
});
|
|
3104
3264
|
};
|
|
3105
3265
|
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
3106
|
-
console.log(
|
|
3266
|
+
console.log(chalk37.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
3107
3267
|
const start = Date.now();
|
|
3108
3268
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
3109
3269
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
3110
3270
|
["eslint", fixOptions]
|
|
3111
3271
|
]);
|
|
3112
|
-
console.log(
|
|
3272
|
+
console.log(chalk37.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk37.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk37.gray("seconds")}`));
|
|
3113
3273
|
return result;
|
|
3114
3274
|
};
|
|
3115
3275
|
|
|
@@ -3553,7 +3713,7 @@ var xyCommonCommands = (args) => {
|
|
|
3553
3713
|
};
|
|
3554
3714
|
|
|
3555
3715
|
// src/xy/lint/cycleCommand.ts
|
|
3556
|
-
import
|
|
3716
|
+
import chalk38 from "chalk";
|
|
3557
3717
|
var cycleCommand = {
|
|
3558
3718
|
command: "cycle [package]",
|
|
3559
3719
|
describe: "Cycle - Check for dependency cycles",
|
|
@@ -3564,12 +3724,12 @@ var cycleCommand = {
|
|
|
3564
3724
|
const start = Date.now();
|
|
3565
3725
|
if (argv.verbose) console.log("Cycle");
|
|
3566
3726
|
process.exitCode = await cycle({ pkg: argv.package });
|
|
3567
|
-
console.log(
|
|
3727
|
+
console.log(chalk38.blue(`Finished in ${Date.now() - start}ms`));
|
|
3568
3728
|
}
|
|
3569
3729
|
};
|
|
3570
3730
|
|
|
3571
3731
|
// src/xy/lint/deplintCommand.ts
|
|
3572
|
-
import
|
|
3732
|
+
import chalk39 from "chalk";
|
|
3573
3733
|
var deplintCommand = {
|
|
3574
3734
|
command: "deplint [package]",
|
|
3575
3735
|
describe: "Deplint - Run Deplint",
|
|
@@ -3607,12 +3767,12 @@ var deplintCommand = {
|
|
|
3607
3767
|
peerDeps: !!argv.peerDeps,
|
|
3608
3768
|
verbose: !!argv.verbose
|
|
3609
3769
|
});
|
|
3610
|
-
console.log(
|
|
3770
|
+
console.log(chalk39.blue(`Finished in ${Date.now() - start}ms`));
|
|
3611
3771
|
}
|
|
3612
3772
|
};
|
|
3613
3773
|
|
|
3614
3774
|
// src/xy/lint/fixCommand.ts
|
|
3615
|
-
import
|
|
3775
|
+
import chalk40 from "chalk";
|
|
3616
3776
|
var fixCommand = {
|
|
3617
3777
|
command: "fix [package]",
|
|
3618
3778
|
describe: "Fix - Run Eslint w/fix",
|
|
@@ -3623,12 +3783,12 @@ var fixCommand = {
|
|
|
3623
3783
|
const start = Date.now();
|
|
3624
3784
|
if (argv.verbose) console.log("Fix");
|
|
3625
3785
|
process.exitCode = fix();
|
|
3626
|
-
console.log(
|
|
3786
|
+
console.log(chalk40.blue(`Finished in ${Date.now() - start}ms`));
|
|
3627
3787
|
}
|
|
3628
3788
|
};
|
|
3629
3789
|
|
|
3630
3790
|
// src/xy/lint/knipCommand.ts
|
|
3631
|
-
import
|
|
3791
|
+
import chalk41 from "chalk";
|
|
3632
3792
|
var knipCommand = {
|
|
3633
3793
|
command: "knip",
|
|
3634
3794
|
describe: "Knip - Run Knip",
|
|
@@ -3639,12 +3799,12 @@ var knipCommand = {
|
|
|
3639
3799
|
if (argv.verbose) console.log("Knip");
|
|
3640
3800
|
const start = Date.now();
|
|
3641
3801
|
process.exitCode = knip();
|
|
3642
|
-
console.log(
|
|
3802
|
+
console.log(chalk41.blue(`Knip finished in ${Date.now() - start}ms`));
|
|
3643
3803
|
}
|
|
3644
3804
|
};
|
|
3645
3805
|
|
|
3646
3806
|
// src/xy/lint/lintCommand.ts
|
|
3647
|
-
import
|
|
3807
|
+
import chalk42 from "chalk";
|
|
3648
3808
|
var lintCommand = {
|
|
3649
3809
|
command: "lint [package]",
|
|
3650
3810
|
describe: "Lint - Run Eslint",
|
|
@@ -3673,7 +3833,7 @@ var lintCommand = {
|
|
|
3673
3833
|
cache: argv.cache,
|
|
3674
3834
|
verbose: !!argv.verbose
|
|
3675
3835
|
});
|
|
3676
|
-
console.log(
|
|
3836
|
+
console.log(chalk42.blue(`Finished in ${Date.now() - start}ms`));
|
|
3677
3837
|
}
|
|
3678
3838
|
};
|
|
3679
3839
|
|
|
@@ -3715,7 +3875,7 @@ var packageLintCommand = {
|
|
|
3715
3875
|
};
|
|
3716
3876
|
|
|
3717
3877
|
// src/xy/lint/publintCommand.ts
|
|
3718
|
-
import
|
|
3878
|
+
import chalk43 from "chalk";
|
|
3719
3879
|
var publintCommand = {
|
|
3720
3880
|
command: "publint [package]",
|
|
3721
3881
|
describe: "Publint - Run Publint",
|
|
@@ -3726,12 +3886,12 @@ var publintCommand = {
|
|
|
3726
3886
|
if (argv.verbose) console.log("Publint");
|
|
3727
3887
|
const start = Date.now();
|
|
3728
3888
|
process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
|
|
3729
|
-
console.log(
|
|
3889
|
+
console.log(chalk43.blue(`Finished in ${Date.now() - start}ms`));
|
|
3730
3890
|
}
|
|
3731
3891
|
};
|
|
3732
3892
|
|
|
3733
3893
|
// src/xy/lint/relintCommand.ts
|
|
3734
|
-
import
|
|
3894
|
+
import chalk44 from "chalk";
|
|
3735
3895
|
var relintCommand = {
|
|
3736
3896
|
command: "relint [package]",
|
|
3737
3897
|
describe: "Relint - Clean & Lint",
|
|
@@ -3742,12 +3902,12 @@ var relintCommand = {
|
|
|
3742
3902
|
if (argv.verbose) console.log("Relinting");
|
|
3743
3903
|
const start = Date.now();
|
|
3744
3904
|
process.exitCode = relint();
|
|
3745
|
-
console.log(
|
|
3905
|
+
console.log(chalk44.blue(`Finished in ${Date.now() - start}ms`));
|
|
3746
3906
|
}
|
|
3747
3907
|
};
|
|
3748
3908
|
|
|
3749
3909
|
// src/xy/lint/sonarCommand.ts
|
|
3750
|
-
import
|
|
3910
|
+
import chalk45 from "chalk";
|
|
3751
3911
|
var sonarCommand = {
|
|
3752
3912
|
command: "sonar",
|
|
3753
3913
|
describe: "Sonar - Run Sonar Check",
|
|
@@ -3758,7 +3918,7 @@ var sonarCommand = {
|
|
|
3758
3918
|
const start = Date.now();
|
|
3759
3919
|
if (argv.verbose) console.log("Sonar Check");
|
|
3760
3920
|
process.exitCode = sonar();
|
|
3761
|
-
console.log(
|
|
3921
|
+
console.log(chalk45.blue(`Finished in ${Date.now() - start}ms`));
|
|
3762
3922
|
}
|
|
3763
3923
|
};
|
|
3764
3924
|
|
|
@@ -3768,7 +3928,7 @@ var xyLintCommands = (args) => {
|
|
|
3768
3928
|
};
|
|
3769
3929
|
|
|
3770
3930
|
// src/xy/xy.ts
|
|
3771
|
-
import
|
|
3931
|
+
import chalk46 from "chalk";
|
|
3772
3932
|
|
|
3773
3933
|
// src/xy/xyParseOptions.ts
|
|
3774
3934
|
import yargs from "yargs";
|
|
@@ -3811,8 +3971,8 @@ var xyBase = async (plugins) => {
|
|
|
3811
3971
|
let args = xyBuildCommands(xyCommonCommands(xyLintCommands(options)));
|
|
3812
3972
|
if (plugins) args = plugins(args);
|
|
3813
3973
|
return await args.demandCommand(1).command("*", "", () => {
|
|
3814
|
-
console.error(
|
|
3815
|
-
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"));
|
|
3816
3976
|
}).version().help().argv;
|
|
3817
3977
|
};
|
|
3818
3978
|
|