@xylabs/ts-scripts-common 7.5.0 → 7.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.mjs +197 -110
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/packman/convert.mjs +187 -100
- package/dist/actions/packman/convert.mjs.map +1 -1
- package/dist/actions/packman/convertToPnpm.mjs +114 -38
- package/dist/actions/packman/convertToPnpm.mjs.map +1 -1
- package/dist/actions/packman/convertToYarn.mjs +104 -38
- package/dist/actions/packman/convertToYarn.mjs.map +1 -1
- package/dist/actions/packman/index.mjs +187 -100
- package/dist/actions/packman/index.mjs.map +1 -1
- package/dist/actions/packman/swapTsScriptsDependency.mjs +57 -0
- package/dist/actions/packman/swapTsScriptsDependency.mjs.map +1 -0
- package/dist/bin/xy.mjs +214 -127
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.mjs +216 -129
- package/dist/index.mjs.map +1 -1
- package/dist/xy/common/index.mjs +187 -100
- package/dist/xy/common/index.mjs.map +1 -1
- package/dist/xy/common/packmanCommand.mjs +187 -100
- package/dist/xy/common/packmanCommand.mjs.map +1 -1
- package/dist/xy/index.mjs +214 -127
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +214 -127
- package/dist/xy/xy.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/actions/packman/swapTsScriptsDependency.ts
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
writeFileSync
|
|
6
|
+
} from "fs";
|
|
7
|
+
import PATH from "path";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
var SWAP_MAP = {
|
|
10
|
+
"yarn-to-pnpm": [
|
|
11
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
12
|
+
],
|
|
13
|
+
"pnpm-to-yarn": [
|
|
14
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"]
|
|
15
|
+
]
|
|
16
|
+
};
|
|
17
|
+
function swapInPackageJson(pkgPath, direction) {
|
|
18
|
+
if (!existsSync(pkgPath)) return false;
|
|
19
|
+
const raw = readFileSync(pkgPath, "utf8");
|
|
20
|
+
const pkg = JSON.parse(raw);
|
|
21
|
+
let changed = false;
|
|
22
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
23
|
+
const deps = pkg[depField];
|
|
24
|
+
if (!deps) continue;
|
|
25
|
+
for (const [from, to] of SWAP_MAP[direction]) {
|
|
26
|
+
if (deps[from]) {
|
|
27
|
+
deps[to] = deps[from];
|
|
28
|
+
delete deps[from];
|
|
29
|
+
changed = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (changed) {
|
|
34
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
35
|
+
}
|
|
36
|
+
return changed;
|
|
37
|
+
}
|
|
38
|
+
function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
39
|
+
let count = 0;
|
|
40
|
+
if (swapInPackageJson(PATH.join(cwd, "package.json"), direction)) {
|
|
41
|
+
count++;
|
|
42
|
+
}
|
|
43
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
44
|
+
const fullPath = PATH.resolve(cwd, pkgPath, "package.json");
|
|
45
|
+
if (swapInPackageJson(fullPath, direction)) {
|
|
46
|
+
count++;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (count > 0) {
|
|
50
|
+
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
51
|
+
console.log(chalk.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
swapTsScriptsDependency
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=swapTsScriptsDependency.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/packman/swapTsScriptsDependency.ts"],"sourcesContent":["import {\n existsSync, readFileSync, writeFileSync,\n} from 'node:fs'\nimport PATH from 'node:path'\n\nimport chalk from 'chalk'\n\ntype Direction = 'pnpm-to-yarn' | 'yarn-to-pnpm'\n\nconst SWAP_MAP: Record<Direction, [from: string, to: string][]> = {\n 'yarn-to-pnpm': [\n ['@xylabs/ts-scripts-yarn3', '@xylabs/ts-scripts-pnpm'],\n ],\n 'pnpm-to-yarn': [\n ['@xylabs/ts-scripts-pnpm', '@xylabs/ts-scripts-yarn3'],\n ],\n}\n\nfunction swapInPackageJson(pkgPath: string, direction: Direction): boolean {\n if (!existsSync(pkgPath)) return false\n\n const raw = readFileSync(pkgPath, 'utf8')\n const pkg = JSON.parse(raw)\n let changed = false\n\n for (const depField of ['dependencies', 'devDependencies']) {\n const deps = pkg[depField] as Record<string, string> | undefined\n if (!deps) continue\n\n for (const [from, to] of SWAP_MAP[direction]) {\n if (deps[from]) {\n deps[to] = deps[from]\n delete deps[from]\n changed = true\n }\n }\n }\n\n if (changed) {\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\\n', 'utf8')\n }\n return changed\n}\n\nexport function swapTsScriptsDependency(cwd: string, workspacePackageJsonPaths: string[], direction: Direction): void {\n let count = 0\n\n // Swap in root package.json\n if (swapInPackageJson(PATH.join(cwd, 'package.json'), direction)) {\n count++\n }\n\n // Swap in workspace package.json files\n for (const pkgPath of workspacePackageJsonPaths) {\n const fullPath = PATH.resolve(cwd, pkgPath, 'package.json')\n if (swapInPackageJson(fullPath, direction)) {\n count++\n }\n }\n\n if (count > 0) {\n const target = direction === 'yarn-to-pnpm' ? '@xylabs/ts-scripts-pnpm' : '@xylabs/ts-scripts-yarn3'\n console.log(chalk.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`))\n }\n}\n"],"mappings":";AAAA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