@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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// src/actions/packman/convertToPnpm.ts
|
|
2
2
|
import {
|
|
3
|
-
existsSync as
|
|
3
|
+
existsSync as existsSync3,
|
|
4
4
|
mkdirSync,
|
|
5
|
-
readFileSync as
|
|
5
|
+
readFileSync as readFileSync3,
|
|
6
6
|
rmSync,
|
|
7
|
-
writeFileSync as
|
|
7
|
+
writeFileSync as writeFileSync3
|
|
8
8
|
} from "fs";
|
|
9
9
|
import PATH2 from "path";
|
|
10
|
-
import
|
|
10
|
+
import chalk3 from "chalk";
|
|
11
11
|
|
|
12
12
|
// src/actions/packman/rewriteScripts.ts
|
|
13
13
|
function rewriteYarnToPnpm(script) {
|
|
@@ -57,14 +57,67 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
57
57
|
return { ...pkg, scripts: rewritten };
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
61
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
62
|
+
import chalk from "chalk";
|
|
63
|
+
import { globSync } from "glob";
|
|
64
|
+
var IMPORT_SWAP_MAP = {
|
|
65
|
+
"yarn-to-pnpm": [
|
|
66
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
67
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
68
|
+
],
|
|
69
|
+
"pnpm-to-yarn": [
|
|
70
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
71
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
var SOURCE_GLOBS = [
|
|
75
|
+
"**/*.ts",
|
|
76
|
+
"**/*.tsx",
|
|
77
|
+
"**/*.mts",
|
|
78
|
+
"**/*.cts",
|
|
79
|
+
"**/*.js",
|
|
80
|
+
"**/*.mjs"
|
|
81
|
+
];
|
|
82
|
+
var IGNORE_PATTERNS = [
|
|
83
|
+
"**/node_modules/**",
|
|
84
|
+
"**/dist/**",
|
|
85
|
+
"**/build/**",
|
|
86
|
+
"**/.yarn/**"
|
|
87
|
+
];
|
|
88
|
+
function rewriteSourceImports(cwd, direction) {
|
|
89
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
90
|
+
const files = globSync(SOURCE_GLOBS, {
|
|
91
|
+
cwd,
|
|
92
|
+
absolute: true,
|
|
93
|
+
ignore: IGNORE_PATTERNS
|
|
94
|
+
});
|
|
95
|
+
let count = 0;
|
|
96
|
+
for (const file of files) {
|
|
97
|
+
if (!existsSync(file)) continue;
|
|
98
|
+
const original = readFileSync(file, "utf8");
|
|
99
|
+
let content = original;
|
|
100
|
+
for (const [from, to] of swaps) {
|
|
101
|
+
content = content.replaceAll(from, to);
|
|
102
|
+
}
|
|
103
|
+
if (content !== original) {
|
|
104
|
+
writeFileSync(file, content, "utf8");
|
|
105
|
+
count++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (count > 0) {
|
|
109
|
+
console.log(chalk.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
60
113
|
// src/actions/packman/swapTsScriptsDependency.ts
|
|
61
114
|
import {
|
|
62
|
-
existsSync,
|
|
63
|
-
readFileSync,
|
|
64
|
-
writeFileSync
|
|
115
|
+
existsSync as existsSync2,
|
|
116
|
+
readFileSync as readFileSync2,
|
|
117
|
+
writeFileSync as writeFileSync2
|
|
65
118
|
} from "fs";
|
|
66
119
|
import PATH from "path";
|
|
67
|
-
import
|
|
120
|
+
import chalk2 from "chalk";
|
|
68
121
|
var SWAP_MAP = {
|
|
69
122
|
"yarn-to-pnpm": [
|
|
70
123
|
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
@@ -74,8 +127,8 @@ var SWAP_MAP = {
|
|
|
74
127
|
]
|
|
75
128
|
};
|
|
76
129
|
function swapInPackageJson(pkgPath, direction) {
|
|
77
|
-
if (!
|
|
78
|
-
const raw =
|
|
130
|
+
if (!existsSync2(pkgPath)) return false;
|
|
131
|
+
const raw = readFileSync2(pkgPath, "utf8");
|
|
79
132
|
const pkg = JSON.parse(raw);
|
|
80
133
|
let changed = false;
|
|
81
134
|
for (const depField of ["dependencies", "devDependencies"]) {
|
|
@@ -90,7 +143,7 @@ function swapInPackageJson(pkgPath, direction) {
|
|
|
90
143
|
}
|
|
91
144
|
}
|
|
92
145
|
if (changed) {
|
|
93
|
-
|
|
146
|
+
writeFileSync2(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
94
147
|
}
|
|
95
148
|
return changed;
|
|
96
149
|
}
|
|
@@ -107,7 +160,7 @@ function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
|
107
160
|
}
|
|
108
161
|
if (count > 0) {
|
|
109
162
|
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
110
|
-
console.log(
|
|
163
|
+
console.log(chalk2.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
111
164
|
}
|
|
112
165
|
}
|
|
113
166
|
|
|
@@ -118,13 +171,13 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
|
118
171
|
for (const pattern of workspacePatterns) {
|
|
119
172
|
lines.push(` - '${pattern}'`);
|
|
120
173
|
}
|
|
121
|
-
|
|
122
|
-
console.log(
|
|
174
|
+
writeFileSync3(PATH2.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
175
|
+
console.log(chalk3.green(" Created pnpm-workspace.yaml"));
|
|
123
176
|
}
|
|
124
177
|
function readPnpmWorkspacePatterns(cwd) {
|
|
125
178
|
const wsPath = PATH2.join(cwd, "pnpm-workspace.yaml");
|
|
126
|
-
if (!
|
|
127
|
-
const content =
|
|
179
|
+
if (!existsSync3(wsPath)) return [];
|
|
180
|
+
const content = readFileSync3(wsPath, "utf8");
|
|
128
181
|
const patterns = [];
|
|
129
182
|
const lines = content.split("\n");
|
|
130
183
|
let inPackages = false;
|
|
@@ -144,19 +197,19 @@ function readPnpmWorkspacePatterns(cwd) {
|
|
|
144
197
|
}
|
|
145
198
|
function updateRootPackageJson(cwd) {
|
|
146
199
|
const pkgPath = PATH2.join(cwd, "package.json");
|
|
147
|
-
const pkg = JSON.parse(
|
|
200
|
+
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
148
201
|
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd);
|
|
149
202
|
delete pkg.workspaces;
|
|
150
203
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
151
204
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
152
|
-
|
|
153
|
-
console.log(
|
|
205
|
+
writeFileSync3(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
206
|
+
console.log(chalk3.green(" Updated root package.json"));
|
|
154
207
|
return workspacePatterns;
|
|
155
208
|
}
|
|
156
209
|
function updateGitignore(cwd) {
|
|
157
210
|
const gitignorePath = PATH2.join(cwd, ".gitignore");
|
|
158
|
-
if (!
|
|
159
|
-
let content =
|
|
211
|
+
if (!existsSync3(gitignorePath)) return;
|
|
212
|
+
let content = readFileSync3(gitignorePath, "utf8");
|
|
160
213
|
const yarnLines = [
|
|
161
214
|
".pnp.*",
|
|
162
215
|
".pnp",
|
|
@@ -171,52 +224,53 @@ function updateGitignore(cwd) {
|
|
|
171
224
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
172
225
|
}
|
|
173
226
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
174
|
-
|
|
175
|
-
console.log(
|
|
227
|
+
writeFileSync3(gitignorePath, content, "utf8");
|
|
228
|
+
console.log(chalk3.green(" Updated .gitignore"));
|
|
176
229
|
}
|
|
177
230
|
function deleteYarnArtifacts(cwd) {
|
|
178
231
|
const yarnLock = PATH2.join(cwd, "yarn.lock");
|
|
179
232
|
const yarnrc = PATH2.join(cwd, ".yarnrc.yml");
|
|
180
233
|
const yarnDir = PATH2.join(cwd, ".yarn");
|
|
181
|
-
if (
|
|
234
|
+
if (existsSync3(yarnLock)) {
|
|
182
235
|
rmSync(yarnLock);
|
|
183
|
-
console.log(
|
|
236
|
+
console.log(chalk3.gray(" Deleted yarn.lock"));
|
|
184
237
|
}
|
|
185
|
-
if (
|
|
238
|
+
if (existsSync3(yarnrc)) {
|
|
186
239
|
rmSync(yarnrc);
|
|
187
|
-
console.log(
|
|
240
|
+
console.log(chalk3.gray(" Deleted .yarnrc.yml"));
|
|
188
241
|
}
|
|
189
|
-
if (
|
|
242
|
+
if (existsSync3(yarnDir)) {
|
|
190
243
|
rmSync(yarnDir, { force: true, recursive: true });
|
|
191
|
-
console.log(
|
|
244
|
+
console.log(chalk3.gray(" Deleted .yarn/"));
|
|
192
245
|
}
|
|
193
246
|
}
|
|
194
247
|
function createNpmrc(cwd) {
|
|
195
248
|
const npmrcPath = PATH2.join(cwd, ".npmrc");
|
|
196
|
-
if (
|
|
249
|
+
if (existsSync3(npmrcPath)) return;
|
|
197
250
|
mkdirSync(PATH2.dirname(npmrcPath), { recursive: true });
|
|
198
|
-
|
|
199
|
-
console.log(
|
|
251
|
+
writeFileSync3(npmrcPath, "", "utf8");
|
|
252
|
+
console.log(chalk3.green(" Created .npmrc"));
|
|
200
253
|
}
|
|
201
254
|
function convertToPnpm(cwd, workspacePackageJsonPaths) {
|
|
202
|
-
console.log(
|
|
255
|
+
console.log(chalk3.blue("\nConverting to pnpm...\n"));
|
|
203
256
|
const workspacePatterns = updateRootPackageJson(cwd);
|
|
204
257
|
createPnpmWorkspaceYaml(cwd, workspacePatterns);
|
|
205
258
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
206
259
|
const fullPath = PATH2.resolve(cwd, pkgPath, "package.json");
|
|
207
|
-
if (!
|
|
208
|
-
const pkg = JSON.parse(
|
|
260
|
+
if (!existsSync3(fullPath)) continue;
|
|
261
|
+
const pkg = JSON.parse(readFileSync3(fullPath, "utf8"));
|
|
209
262
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
210
263
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
211
|
-
|
|
264
|
+
writeFileSync3(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
212
265
|
}
|
|
213
266
|
}
|
|
214
|
-
console.log(
|
|
267
|
+
console.log(chalk3.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
215
268
|
updateGitignore(cwd);
|
|
216
269
|
createNpmrc(cwd);
|
|
217
270
|
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
271
|
+
rewriteSourceImports(cwd, "yarn-to-pnpm");
|
|
218
272
|
deleteYarnArtifacts(cwd);
|
|
219
|
-
console.log(
|
|
273
|
+
console.log(chalk3.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
220
274
|
return 0;
|
|
221
275
|
}
|
|
222
276
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/packman/convertToPnpm.ts","../../../src/actions/packman/rewriteScripts.ts","../../../src/actions/packman/swapTsScriptsDependency.ts"],"sourcesContent":["import {\n existsSync, mkdirSync, readFileSync, rmSync, writeFileSync,\n} from 'node:fs'\nimport PATH from 'node:path'\n\nimport chalk from 'chalk'\n\nimport { rewriteScriptsInPackageJson } from './rewriteScripts.ts'\nimport { swapTsScriptsDependency } from './swapTsScriptsDependency.ts'\n\nconst PNPM_VERSION = '10.12.1'\n\nfunction createPnpmWorkspaceYaml(cwd: string, workspacePatterns: string[]): void {\n const lines = ['packages:']\n for (const pattern of workspacePatterns) {\n lines.push(` - '${pattern}'`)\n }\n writeFileSync(PATH.join(cwd, 'pnpm-workspace.yaml'), lines.join('\\n') + '\\n', 'utf8')\n console.log(chalk.green(' Created pnpm-workspace.yaml'))\n}\n\nfunction readPnpmWorkspacePatterns(cwd: string): string[] {\n const wsPath = PATH.join(cwd, 'pnpm-workspace.yaml')\n if (!existsSync(wsPath)) return []\n\n const content = readFileSync(wsPath, 'utf8')\n const patterns: string[] = []\n const lines = content.split('\\n')\n let inPackages = false\n for (const line of lines) {\n if (line.trim() === 'packages:') {\n inPackages = true\n continue\n }\n if (inPackages && /^\\s+-\\s+/.test(line)) {\n const pattern = line.replace(/^\\s+-\\s+/, '').replaceAll(/['\"]/g, '').trim()\n if (pattern) patterns.push(pattern)\n } else if (inPackages && !/^\\s/.test(line) && line.trim()) {\n inPackages = false\n }\n }\n return patterns\n}\n\nfunction updateRootPackageJson(cwd: string): string[] {\n const pkgPath = PATH.join(cwd, 'package.json')\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))\n\n // Save workspace patterns before removing — fall back to pnpm-workspace.yaml if already converted\n const workspacePatterns: string[] = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd)\n\n // Remove yarn workspaces field (pnpm uses pnpm-workspace.yaml)\n delete pkg.workspaces\n\n // Update packageManager\n pkg.packageManager = `pnpm@${PNPM_VERSION}`\n\n // Rewrite scripts\n const updated = rewriteScriptsInPackageJson(pkg, 'yarn-to-pnpm')\n\n writeFileSync(pkgPath, JSON.stringify(updated, null, 2) + '\\n', 'utf8')\n console.log(chalk.green(' Updated root package.json'))\n\n return workspacePatterns\n}\n\nfunction updateGitignore(cwd: string): void {\n const gitignorePath = PATH.join(cwd, '.gitignore')\n if (!existsSync(gitignorePath)) return\n\n let content = readFileSync(gitignorePath, 'utf8')\n\n // Remove yarn-specific entries\n const yarnLines = [\n '.pnp.*',\n '.pnp',\n '.yarn/*',\n '!.yarn/patches',\n '!.yarn/plugins',\n '!.yarn/releases',\n '!.yarn/sdks',\n '!.yarn/versions',\n ]\n for (const line of yarnLines) {\n content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll('.', String.raw`\\.`).replaceAll('*', String.raw`\\*`).replaceAll('!', String.raw`\\!`)}\\s*$`, 'gm'), '')\n }\n\n // Clean up multiple blank lines\n content = content.replaceAll(/\\n{3,}/g, '\\n\\n')\n\n writeFileSync(gitignorePath, content, 'utf8')\n console.log(chalk.green(' Updated .gitignore'))\n}\n\nfunction deleteYarnArtifacts(cwd: string): void {\n const yarnLock = PATH.join(cwd, 'yarn.lock')\n const yarnrc = PATH.join(cwd, '.yarnrc.yml')\n const yarnDir = PATH.join(cwd, '.yarn')\n\n if (existsSync(yarnLock)) {\n rmSync(yarnLock)\n console.log(chalk.gray(' Deleted yarn.lock'))\n }\n if (existsSync(yarnrc)) {\n rmSync(yarnrc)\n console.log(chalk.gray(' Deleted .yarnrc.yml'))\n }\n if (existsSync(yarnDir)) {\n rmSync(yarnDir, { force: true, recursive: true })\n console.log(chalk.gray(' Deleted .yarn/'))\n }\n}\n\nfunction createNpmrc(cwd: string): void {\n const npmrcPath = PATH.join(cwd, '.npmrc')\n if (existsSync(npmrcPath)) return\n\n mkdirSync(PATH.dirname(npmrcPath), { recursive: true })\n writeFileSync(npmrcPath, '', 'utf8')\n console.log(chalk.green(' Created .npmrc'))\n}\n\nexport function convertToPnpm(cwd: string, workspacePackageJsonPaths: string[]): number {\n console.log(chalk.blue('\\nConverting to pnpm...\\n'))\n\n // 1. Read workspace patterns and update root package.json\n const workspacePatterns = updateRootPackageJson(cwd)\n\n // 2. Create pnpm-workspace.yaml\n createPnpmWorkspaceYaml(cwd, workspacePatterns)\n\n // 3. Rewrite scripts in workspace package.json files\n for (const pkgPath of workspacePackageJsonPaths) {\n const fullPath = PATH.resolve(cwd, pkgPath, 'package.json')\n if (!existsSync(fullPath)) continue\n const pkg = JSON.parse(readFileSync(fullPath, 'utf8'))\n const updated = rewriteScriptsInPackageJson(pkg, 'yarn-to-pnpm')\n if (JSON.stringify(pkg) !== JSON.stringify(updated)) {\n writeFileSync(fullPath, JSON.stringify(updated, null, 2) + '\\n', 'utf8')\n }\n }\n console.log(chalk.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`))\n\n // 4. Update .gitignore\n updateGitignore(cwd)\n\n // 5. Create .npmrc\n createNpmrc(cwd)\n\n // 6. Swap ts-scripts devDependency (yarn3 → pnpm) in root and workspace packages\n swapTsScriptsDependency(cwd, workspacePackageJsonPaths, 'yarn-to-pnpm')\n\n // 7. Delete yarn artifacts\n deleteYarnArtifacts(cwd)\n\n console.log(chalk.blue('\\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\\n'))\n return 0\n}\n","type Direction = 'pnpm-to-yarn' | 'yarn-to-pnpm'\n\nfunction rewriteYarnToPnpm(script: string): string {\n let result = script\n // yarn workspace @pkg run script → pnpm --filter @pkg run script\n result = result.replaceAll(/\\byarn workspace (\\S+) run /g, 'pnpm --filter $1 run ')\n // yarn workspace @pkg package-X → pnpm --filter @pkg run package-X\n result = result.replaceAll(/\\byarn workspace (\\S+) (package-\\S+)/g, 'pnpm --filter $1 run $2')\n // yarn workspaces foreach [flags] run script → pnpm -r run script\n result = result.replaceAll(/\\byarn workspaces foreach\\s+(?:[^\\s]*\\s+)*run /g, 'pnpm -r run ')\n // yarn workspaces foreach --all version X --deferred → pnpm -r exec npm version X --no-git-tag-version\n result = result.replaceAll(/\\byarn workspaces foreach --all version (\\S+) --deferred/g, 'pnpm -r exec npm version $1 --no-git-tag-version')\n // yarn version apply --all → (remove, handled in bump)\n result = result.replaceAll(/\\byarn version apply --all/g, 'echo \"versions applied\"')\n // yarn xy → pnpm xy\n result = result.replaceAll(/\\byarn xy\\b/g, 'pnpm xy')\n // yarn add/remove/install/dedupe/outdated → pnpm equivalents\n result = result.replaceAll(/\\byarn add\\b/g, 'pnpm add')\n result = result.replaceAll(/\\byarn remove\\b/g, 'pnpm remove')\n result = result.replaceAll(/\\byarn install\\b/g, 'pnpm install')\n result = result.replaceAll(/\\byarn dedupe\\b/g, 'pnpm dedupe')\n result = result.replaceAll(/\\byarn outdated\\b/g, 'pnpm outdated')\n result = result.replaceAll(/\\byarn run\\b/g, 'pnpm run')\n // yarn rimraf → rimraf (no PM prefix)\n result = result.replaceAll(/\\byarn rimraf\\b/g, 'rimraf')\n // yarn npm → npm (direct)\n result = result.replaceAll(/\\byarn npm\\b/g, 'npm')\n // Remaining bare \"yarn\" at word boundary (but not in URLs or package names)\n result = result.replaceAll(/\\byarn\\b(?![@/.])/g, 'pnpm')\n return result\n}\n\nfunction rewritePnpmToYarn(script: string): string {\n let result = script\n // pnpm --filter @pkg run script → yarn workspace @pkg run script\n result = result.replaceAll(/\\bpnpm --filter (\\S+) run /g, 'yarn workspace $1 run ')\n // pnpm -r run script → yarn workspaces foreach -Apt run script\n result = result.replaceAll(/\\bpnpm -r run /g, 'yarn workspaces foreach -Apt run ')\n // pnpm -r exec npm version X → yarn workspaces foreach --all version X --deferred\n result = result.replaceAll(/\\bpnpm -r exec npm version (\\S+) --no-git-tag-version/g, 'yarn workspaces foreach --all version $1 --deferred')\n // pnpm xy → yarn xy\n result = result.replaceAll(/\\bpnpm xy\\b/g, 'yarn xy')\n // pnpm add/remove/install/dedupe/outdated → yarn equivalents\n result = result.replaceAll(/\\bpnpm add\\b/g, 'yarn add')\n result = result.replaceAll(/\\bpnpm remove\\b/g, 'yarn remove')\n result = result.replaceAll(/\\bpnpm install\\b/g, 'yarn install')\n result = result.replaceAll(/\\bpnpm dedupe\\b/g, 'yarn dedupe')\n result = result.replaceAll(/\\bpnpm outdated\\b/g, 'yarn outdated')\n result = result.replaceAll(/\\bpnpm run\\b/g, 'yarn run')\n // Remaining bare \"pnpm\"\n result = result.replaceAll(/\\bpnpm\\b(?![@/.])/g, 'yarn')\n return result\n}\n\nexport function rewriteScript(script: string, direction: Direction): string {\n return direction === 'yarn-to-pnpm'\n ? rewriteYarnToPnpm(script)\n : rewritePnpmToYarn(script)\n}\n\nexport function rewriteScriptsInPackageJson(\n pkg: Record<string, unknown>,\n direction: Direction,\n): Record<string, unknown> {\n const scripts = pkg.scripts as Record<string, string> | undefined\n if (!scripts) return pkg\n\n const rewritten: Record<string, string> = {}\n for (const [name, script] of Object.entries(scripts)) {\n rewritten[name] = rewriteScript(script, direction)\n }\n return { ...pkg, scripts: rewritten }\n}\n","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;AAAA,EACE,cAAAA;AAAA,EAAY;AAAA,EAAW,gBAAAC;AAAA,EAAc;AAAA,EAAQ,iBAAAC;AAAA,OACxC;AACP,OAAOC,WAAU;AAEjB,OAAOC,YAAW;;;ACHlB,SAAS,kBAAkB,QAAwB;AACjD,MAAI,SAAS;AAEb,WAAS,OAAO,WAAW,gCAAgC,uBAAuB;AAElF,WAAS,OAAO,WAAW,yCAAyC,yBAAyB;AAE7F,WAAS,OAAO,WAAW,mDAAmD,cAAc;AAE5F,WAAS,OAAO,WAAW,6DAA6D,kDAAkD;AAE1I,WAAS,OAAO,WAAW,+BAA+B,yBAAyB;AAEnF,WAAS,OAAO,WAAW,gBAAgB,SAAS;AAEpD,WAAS,OAAO,WAAW,iBAAiB,UAAU;AACtD,WAAS,OAAO,WAAW,oBAAoB,aAAa;AAC5D,WAAS,OAAO,WAAW,qBAAqB,cAAc;AAC9D,WAAS,OAAO,WAAW,oBAAoB,aAAa;AAC5D,WAAS,OAAO,WAAW,sBAAsB,eAAe;AAChE,WAAS,OAAO,WAAW,iBAAiB,UAAU;AAEtD,WAAS,OAAO,WAAW,oBAAoB,QAAQ;AAEvD,WAAS,OAAO,WAAW,iBAAiB,KAAK;AAEjD,WAAS,OAAO,WAAW,sBAAsB,MAAM;AACvD,SAAO;AACT;AAEA,SAAS,kBAAkB,QAAwB;AACjD,MAAI,SAAS;AAEb,WAAS,OAAO,WAAW,+BAA+B,wBAAwB;AAElF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W,WAAW,2BAA2B;AAC/C,UAAM,WAAWD,MAAK,QAAQ,KAAK,SAAS,cAAc;AAC1D,QAAI,CAACE,YAAW,QAAQ,EAAG;AAC3B,UAAM,MAAM,KAAK,MAAMC,cAAa,UAAU,MAAM,CAAC;AACrD,UAAM,UAAU,4BAA4B,KAAK,cAAc;AAC/D,QAAI,KAAK,UAAU,GAAG,MAAM,KAAK,UAAU,OAAO,GAAG;AACnD,MAAAJ,eAAc,UAAU,KAAK,UAAU,SAAS,MAAM,CAAC,IAAI,MAAM,MAAM;AAAA,IACzE;AAAA,EACF;AACA,UAAQ,IAAIE,OAAM,MAAM,wBAAwB,0BAA0B,MAAM,uBAAuB,CAAC;AAGxG,kBAAgB,GAAG;AAGnB,cAAY,GAAG;AAGf,0BAAwB,KAAK,2BAA2B,cAAc;AAGtE,sBAAoB,GAAG;AAEvB,UAAQ,IAAIA,OAAM,KAAK,yEAAyE,CAAC;AACjG,SAAO;AACT;","names":["existsSync","readFileSync","writeFileSync","PATH","chalk","writeFileSync","PATH","chalk","existsSync","readFileSync"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/packman/convertToPnpm.ts","../../../src/actions/packman/rewriteScripts.ts","../../../src/actions/packman/rewriteSourceImports.ts","../../../src/actions/packman/swapTsScriptsDependency.ts"],"sourcesContent":["import {\n existsSync, mkdirSync, readFileSync, rmSync, writeFileSync,\n} from 'node:fs'\nimport PATH from 'node:path'\n\nimport chalk from 'chalk'\n\nimport { rewriteScriptsInPackageJson } from './rewriteScripts.ts'\nimport { rewriteSourceImports } from './rewriteSourceImports.ts'\nimport { swapTsScriptsDependency } from './swapTsScriptsDependency.ts'\n\nconst PNPM_VERSION = '10.12.1'\n\nfunction createPnpmWorkspaceYaml(cwd: string, workspacePatterns: string[]): void {\n const lines = ['packages:']\n for (const pattern of workspacePatterns) {\n lines.push(` - '${pattern}'`)\n }\n writeFileSync(PATH.join(cwd, 'pnpm-workspace.yaml'), lines.join('\\n') + '\\n', 'utf8')\n console.log(chalk.green(' Created pnpm-workspace.yaml'))\n}\n\nfunction readPnpmWorkspacePatterns(cwd: string): string[] {\n const wsPath = PATH.join(cwd, 'pnpm-workspace.yaml')\n if (!existsSync(wsPath)) return []\n\n const content = readFileSync(wsPath, 'utf8')\n const patterns: string[] = []\n const lines = content.split('\\n')\n let inPackages = false\n for (const line of lines) {\n if (line.trim() === 'packages:') {\n inPackages = true\n continue\n }\n if (inPackages && /^\\s+-\\s+/.test(line)) {\n const pattern = line.replace(/^\\s+-\\s+/, '').replaceAll(/['\"]/g, '').trim()\n if (pattern) patterns.push(pattern)\n } else if (inPackages && !/^\\s/.test(line) && line.trim()) {\n inPackages = false\n }\n }\n return patterns\n}\n\nfunction updateRootPackageJson(cwd: string): string[] {\n const pkgPath = PATH.join(cwd, 'package.json')\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))\n\n // Save workspace patterns before removing — fall back to pnpm-workspace.yaml if already converted\n const workspacePatterns: string[] = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd)\n\n // Remove yarn workspaces field (pnpm uses pnpm-workspace.yaml)\n delete pkg.workspaces\n\n // Update packageManager\n pkg.packageManager = `pnpm@${PNPM_VERSION}`\n\n // Rewrite scripts\n const updated = rewriteScriptsInPackageJson(pkg, 'yarn-to-pnpm')\n\n writeFileSync(pkgPath, JSON.stringify(updated, null, 2) + '\\n', 'utf8')\n console.log(chalk.green(' Updated root package.json'))\n\n return workspacePatterns\n}\n\nfunction updateGitignore(cwd: string): void {\n const gitignorePath = PATH.join(cwd, '.gitignore')\n if (!existsSync(gitignorePath)) return\n\n let content = readFileSync(gitignorePath, 'utf8')\n\n // Remove yarn-specific entries\n const yarnLines = [\n '.pnp.*',\n '.pnp',\n '.yarn/*',\n '!.yarn/patches',\n '!.yarn/plugins',\n '!.yarn/releases',\n '!.yarn/sdks',\n '!.yarn/versions',\n ]\n for (const line of yarnLines) {\n content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll('.', String.raw`\\.`).replaceAll('*', String.raw`\\*`).replaceAll('!', String.raw`\\!`)}\\s*$`, 'gm'), '')\n }\n\n // Clean up multiple blank lines\n content = content.replaceAll(/\\n{3,}/g, '\\n\\n')\n\n writeFileSync(gitignorePath, content, 'utf8')\n console.log(chalk.green(' Updated .gitignore'))\n}\n\nfunction deleteYarnArtifacts(cwd: string): void {\n const yarnLock = PATH.join(cwd, 'yarn.lock')\n const yarnrc = PATH.join(cwd, '.yarnrc.yml')\n const yarnDir = PATH.join(cwd, '.yarn')\n\n if (existsSync(yarnLock)) {\n rmSync(yarnLock)\n console.log(chalk.gray(' Deleted yarn.lock'))\n }\n if (existsSync(yarnrc)) {\n rmSync(yarnrc)\n console.log(chalk.gray(' Deleted .yarnrc.yml'))\n }\n if (existsSync(yarnDir)) {\n rmSync(yarnDir, { force: true, recursive: true })\n console.log(chalk.gray(' Deleted .yarn/'))\n }\n}\n\nfunction createNpmrc(cwd: string): void {\n const npmrcPath = PATH.join(cwd, '.npmrc')\n if (existsSync(npmrcPath)) return\n\n mkdirSync(PATH.dirname(npmrcPath), { recursive: true })\n writeFileSync(npmrcPath, '', 'utf8')\n console.log(chalk.green(' Created .npmrc'))\n}\n\nexport function convertToPnpm(cwd: string, workspacePackageJsonPaths: string[]): number {\n console.log(chalk.blue('\\nConverting to pnpm...\\n'))\n\n // 1. Read workspace patterns and update root package.json\n const workspacePatterns = updateRootPackageJson(cwd)\n\n // 2. Create pnpm-workspace.yaml\n createPnpmWorkspaceYaml(cwd, workspacePatterns)\n\n // 3. Rewrite scripts in workspace package.json files\n for (const pkgPath of workspacePackageJsonPaths) {\n const fullPath = PATH.resolve(cwd, pkgPath, 'package.json')\n if (!existsSync(fullPath)) continue\n const pkg = JSON.parse(readFileSync(fullPath, 'utf8'))\n const updated = rewriteScriptsInPackageJson(pkg, 'yarn-to-pnpm')\n if (JSON.stringify(pkg) !== JSON.stringify(updated)) {\n writeFileSync(fullPath, JSON.stringify(updated, null, 2) + '\\n', 'utf8')\n }\n }\n console.log(chalk.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`))\n\n // 4. Update .gitignore\n updateGitignore(cwd)\n\n // 5. Create .npmrc\n createNpmrc(cwd)\n\n // 6. Swap ts-scripts devDependency (yarn3 → pnpm) in root and workspace packages\n swapTsScriptsDependency(cwd, workspacePackageJsonPaths, 'yarn-to-pnpm')\n\n // 7. Rewrite ts-scripts imports in source files\n rewriteSourceImports(cwd, 'yarn-to-pnpm')\n\n // 8. Delete yarn artifacts\n deleteYarnArtifacts(cwd)\n\n console.log(chalk.blue('\\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\\n'))\n return 0\n}\n","type Direction = 'pnpm-to-yarn' | 'yarn-to-pnpm'\n\nfunction rewriteYarnToPnpm(script: string): string {\n let result = script\n // yarn workspace @pkg run script → pnpm --filter @pkg run script\n result = result.replaceAll(/\\byarn workspace (\\S+) run /g, 'pnpm --filter $1 run ')\n // yarn workspace @pkg package-X → pnpm --filter @pkg run package-X\n result = result.replaceAll(/\\byarn workspace (\\S+) (package-\\S+)/g, 'pnpm --filter $1 run $2')\n // yarn workspaces foreach [flags] run script → pnpm -r run script\n result = result.replaceAll(/\\byarn workspaces foreach\\s+(?:[^\\s]*\\s+)*run /g, 'pnpm -r run ')\n // yarn workspaces foreach --all version X --deferred → pnpm -r exec npm version X --no-git-tag-version\n result = result.replaceAll(/\\byarn workspaces foreach --all version (\\S+) --deferred/g, 'pnpm -r exec npm version $1 --no-git-tag-version')\n // yarn version apply --all → (remove, handled in bump)\n result = result.replaceAll(/\\byarn version apply --all/g, 'echo \"versions applied\"')\n // yarn xy → pnpm xy\n result = result.replaceAll(/\\byarn xy\\b/g, 'pnpm xy')\n // yarn add/remove/install/dedupe/outdated → pnpm equivalents\n result = result.replaceAll(/\\byarn add\\b/g, 'pnpm add')\n result = result.replaceAll(/\\byarn remove\\b/g, 'pnpm remove')\n result = result.replaceAll(/\\byarn install\\b/g, 'pnpm install')\n result = result.replaceAll(/\\byarn dedupe\\b/g, 'pnpm dedupe')\n result = result.replaceAll(/\\byarn outdated\\b/g, 'pnpm outdated')\n result = result.replaceAll(/\\byarn run\\b/g, 'pnpm run')\n // yarn rimraf → rimraf (no PM prefix)\n result = result.replaceAll(/\\byarn rimraf\\b/g, 'rimraf')\n // yarn npm → npm (direct)\n result = result.replaceAll(/\\byarn npm\\b/g, 'npm')\n // Remaining bare \"yarn\" at word boundary (but not in URLs or package names)\n result = result.replaceAll(/\\byarn\\b(?![@/.])/g, 'pnpm')\n return result\n}\n\nfunction rewritePnpmToYarn(script: string): string {\n let result = script\n // pnpm --filter @pkg run script → yarn workspace @pkg run script\n result = result.replaceAll(/\\bpnpm --filter (\\S+) run /g, 'yarn workspace $1 run ')\n // pnpm -r run script → yarn workspaces foreach -Apt run script\n result = result.replaceAll(/\\bpnpm -r run /g, 'yarn workspaces foreach -Apt run ')\n // pnpm -r exec npm version X → yarn workspaces foreach --all version X --deferred\n result = result.replaceAll(/\\bpnpm -r exec npm version (\\S+) --no-git-tag-version/g, 'yarn workspaces foreach --all version $1 --deferred')\n // pnpm xy → yarn xy\n result = result.replaceAll(/\\bpnpm xy\\b/g, 'yarn xy')\n // pnpm add/remove/install/dedupe/outdated → yarn equivalents\n result = result.replaceAll(/\\bpnpm add\\b/g, 'yarn add')\n result = result.replaceAll(/\\bpnpm remove\\b/g, 'yarn remove')\n result = result.replaceAll(/\\bpnpm install\\b/g, 'yarn install')\n result = result.replaceAll(/\\bpnpm dedupe\\b/g, 'yarn dedupe')\n result = result.replaceAll(/\\bpnpm outdated\\b/g, 'yarn outdated')\n result = result.replaceAll(/\\bpnpm run\\b/g, 'yarn run')\n // Remaining bare \"pnpm\"\n result = result.replaceAll(/\\bpnpm\\b(?![@/.])/g, 'yarn')\n return result\n}\n\nexport function rewriteScript(script: string, direction: Direction): string {\n return direction === 'yarn-to-pnpm'\n ? rewriteYarnToPnpm(script)\n : rewritePnpmToYarn(script)\n}\n\nexport function rewriteScriptsInPackageJson(\n pkg: Record<string, unknown>,\n direction: Direction,\n): Record<string, unknown> {\n const scripts = pkg.scripts as Record<string, string> | undefined\n if (!scripts) return pkg\n\n const rewritten: Record<string, string> = {}\n for (const [name, script] of Object.entries(scripts)) {\n rewritten[name] = rewriteScript(script, direction)\n }\n return { ...pkg, scripts: rewritten }\n}\n","import { existsSync, readFileSync, writeFileSync } from 'node:fs'\nimport PATH from 'node:path'\n\nimport chalk from 'chalk'\nimport { globSync } from 'glob'\n\ntype Direction = 'pnpm-to-yarn' | 'yarn-to-pnpm'\n\nconst IMPORT_SWAP_MAP: Record<Direction, [from: string, to: string][]> = {\n 'yarn-to-pnpm': [\n ['@xylabs/ts-scripts-yarn3', '@xylabs/ts-scripts-pnpm'],\n ['@xylabs/ts-scripts-react-yarn3', '@xylabs/ts-scripts-react-pnpm'],\n ],\n 'pnpm-to-yarn': [\n ['@xylabs/ts-scripts-pnpm', '@xylabs/ts-scripts-yarn3'],\n ['@xylabs/ts-scripts-react-pnpm', '@xylabs/ts-scripts-react-yarn3'],\n ],\n}\n\nconst SOURCE_GLOBS = [\n '**/*.ts',\n '**/*.tsx',\n '**/*.mts',\n '**/*.cts',\n '**/*.js',\n '**/*.mjs',\n]\n\nconst IGNORE_PATTERNS = [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.yarn/**',\n]\n\nexport function rewriteSourceImports(cwd: string, direction: Direction): void {\n const swaps = IMPORT_SWAP_MAP[direction]\n const files = globSync(SOURCE_GLOBS, {\n cwd,\n absolute: true,\n ignore: IGNORE_PATTERNS,\n })\n\n let count = 0\n for (const file of files) {\n if (!existsSync(file)) continue\n const original = readFileSync(file, 'utf8')\n let content = original\n for (const [from, to] of swaps) {\n content = content.replaceAll(from, to)\n }\n if (content !== original) {\n writeFileSync(file, content, 'utf8')\n count++\n }\n }\n\n if (count > 0) {\n console.log(chalk.green(` Rewrote ts-scripts imports in ${count} source file(s)`))\n }\n}\n","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;AAAA,EACE,cAAAA;AAAA,EAAY;AAAA,EAAW,gBAAAC;AAAA,EAAc;AAAA,EAAQ,iBAAAC;AAAA,OACxC;AACP,OAAOC,WAAU;AAEjB,OAAOC,YAAW;;;ACHlB,SAAS,kBAAkB,Q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","readFileSync","writeFileSync","chalk","writeFileSync","PATH","chalk","existsSync","readFileSync"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/actions/packman/convertToYarn.ts
|
|
2
2
|
import {
|
|
3
|
-
existsSync as
|
|
4
|
-
readFileSync as
|
|
3
|
+
existsSync as existsSync3,
|
|
4
|
+
readFileSync as readFileSync3,
|
|
5
5
|
rmSync,
|
|
6
|
-
writeFileSync as
|
|
6
|
+
writeFileSync as writeFileSync3
|
|
7
7
|
} from "fs";
|
|
8
8
|
import PATH2 from "path";
|
|
9
|
-
import
|
|
9
|
+
import chalk3 from "chalk";
|
|
10
10
|
|
|
11
11
|
// src/actions/packman/rewriteScripts.ts
|
|
12
12
|
function rewriteYarnToPnpm(script) {
|
|
@@ -56,14 +56,67 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
56
56
|
return { ...pkg, scripts: rewritten };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
60
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
61
|
+
import chalk from "chalk";
|
|
62
|
+
import { globSync } from "glob";
|
|
63
|
+
var IMPORT_SWAP_MAP = {
|
|
64
|
+
"yarn-to-pnpm": [
|
|
65
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
66
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
67
|
+
],
|
|
68
|
+
"pnpm-to-yarn": [
|
|
69
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
70
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
var SOURCE_GLOBS = [
|
|
74
|
+
"**/*.ts",
|
|
75
|
+
"**/*.tsx",
|
|
76
|
+
"**/*.mts",
|
|
77
|
+
"**/*.cts",
|
|
78
|
+
"**/*.js",
|
|
79
|
+
"**/*.mjs"
|
|
80
|
+
];
|
|
81
|
+
var IGNORE_PATTERNS = [
|
|
82
|
+
"**/node_modules/**",
|
|
83
|
+
"**/dist/**",
|
|
84
|
+
"**/build/**",
|
|
85
|
+
"**/.yarn/**"
|
|
86
|
+
];
|
|
87
|
+
function rewriteSourceImports(cwd, direction) {
|
|
88
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
89
|
+
const files = globSync(SOURCE_GLOBS, {
|
|
90
|
+
cwd,
|
|
91
|
+
absolute: true,
|
|
92
|
+
ignore: IGNORE_PATTERNS
|
|
93
|
+
});
|
|
94
|
+
let count = 0;
|
|
95
|
+
for (const file of files) {
|
|
96
|
+
if (!existsSync(file)) continue;
|
|
97
|
+
const original = readFileSync(file, "utf8");
|
|
98
|
+
let content = original;
|
|
99
|
+
for (const [from, to] of swaps) {
|
|
100
|
+
content = content.replaceAll(from, to);
|
|
101
|
+
}
|
|
102
|
+
if (content !== original) {
|
|
103
|
+
writeFileSync(file, content, "utf8");
|
|
104
|
+
count++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (count > 0) {
|
|
108
|
+
console.log(chalk.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
59
112
|
// src/actions/packman/swapTsScriptsDependency.ts
|
|
60
113
|
import {
|
|
61
|
-
existsSync,
|
|
62
|
-
readFileSync,
|
|
63
|
-
writeFileSync
|
|
114
|
+
existsSync as existsSync2,
|
|
115
|
+
readFileSync as readFileSync2,
|
|
116
|
+
writeFileSync as writeFileSync2
|
|
64
117
|
} from "fs";
|
|
65
118
|
import PATH from "path";
|
|
66
|
-
import
|
|
119
|
+
import chalk2 from "chalk";
|
|
67
120
|
var SWAP_MAP = {
|
|
68
121
|
"yarn-to-pnpm": [
|
|
69
122
|
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
@@ -73,8 +126,8 @@ var SWAP_MAP = {
|
|
|
73
126
|
]
|
|
74
127
|
};
|
|
75
128
|
function swapInPackageJson(pkgPath, direction) {
|
|
76
|
-
if (!
|
|
77
|
-
const raw =
|
|
129
|
+
if (!existsSync2(pkgPath)) return false;
|
|
130
|
+
const raw = readFileSync2(pkgPath, "utf8");
|
|
78
131
|
const pkg = JSON.parse(raw);
|
|
79
132
|
let changed = false;
|
|
80
133
|
for (const depField of ["dependencies", "devDependencies"]) {
|
|
@@ -89,7 +142,7 @@ function swapInPackageJson(pkgPath, direction) {
|
|
|
89
142
|
}
|
|
90
143
|
}
|
|
91
144
|
if (changed) {
|
|
92
|
-
|
|
145
|
+
writeFileSync2(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
93
146
|
}
|
|
94
147
|
return changed;
|
|
95
148
|
}
|
|
@@ -106,7 +159,7 @@ function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
|
106
159
|
}
|
|
107
160
|
if (count > 0) {
|
|
108
161
|
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
109
|
-
console.log(
|
|
162
|
+
console.log(chalk2.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
110
163
|
}
|
|
111
164
|
}
|
|
112
165
|
|
|
@@ -133,8 +186,8 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
133
186
|
`;
|
|
134
187
|
function readPnpmWorkspacePatterns(cwd) {
|
|
135
188
|
const wsPath = PATH2.join(cwd, "pnpm-workspace.yaml");
|
|
136
|
-
if (!
|
|
137
|
-
const content =
|
|
189
|
+
if (!existsSync3(wsPath)) return [];
|
|
190
|
+
const content = readFileSync3(wsPath, "utf8");
|
|
138
191
|
const patterns = [];
|
|
139
192
|
const lines = content.split("\n");
|
|
140
193
|
let inPackages = false;
|
|
@@ -154,81 +207,82 @@ function readPnpmWorkspacePatterns(cwd) {
|
|
|
154
207
|
}
|
|
155
208
|
function updateRootPackageJson(cwd, workspacePatterns) {
|
|
156
209
|
const pkgPath = PATH2.join(cwd, "package.json");
|
|
157
|
-
const pkg = JSON.parse(
|
|
210
|
+
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
158
211
|
pkg.workspaces = workspacePatterns;
|
|
159
212
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
160
213
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
161
|
-
|
|
162
|
-
console.log(
|
|
214
|
+
writeFileSync3(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
215
|
+
console.log(chalk3.green(" Updated root package.json"));
|
|
163
216
|
}
|
|
164
217
|
function updateGitignore(cwd) {
|
|
165
218
|
const gitignorePath = PATH2.join(cwd, ".gitignore");
|
|
166
|
-
let content =
|
|
219
|
+
let content = existsSync3(gitignorePath) ? readFileSync3(gitignorePath, "utf8") : "";
|
|
167
220
|
if (!content.includes(".yarn/*")) {
|
|
168
221
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
169
222
|
}
|
|
170
|
-
|
|
171
|
-
console.log(
|
|
223
|
+
writeFileSync3(gitignorePath, content, "utf8");
|
|
224
|
+
console.log(chalk3.green(" Updated .gitignore"));
|
|
172
225
|
}
|
|
173
226
|
function deletePnpmArtifacts(cwd) {
|
|
174
227
|
const lockfile = PATH2.join(cwd, "pnpm-lock.yaml");
|
|
175
228
|
const workspaceYaml = PATH2.join(cwd, "pnpm-workspace.yaml");
|
|
176
229
|
const npmrc = PATH2.join(cwd, ".npmrc");
|
|
177
|
-
if (
|
|
230
|
+
if (existsSync3(lockfile)) {
|
|
178
231
|
rmSync(lockfile);
|
|
179
|
-
console.log(
|
|
232
|
+
console.log(chalk3.gray(" Deleted pnpm-lock.yaml"));
|
|
180
233
|
}
|
|
181
|
-
if (
|
|
234
|
+
if (existsSync3(workspaceYaml)) {
|
|
182
235
|
rmSync(workspaceYaml);
|
|
183
|
-
console.log(
|
|
236
|
+
console.log(chalk3.gray(" Deleted pnpm-workspace.yaml"));
|
|
184
237
|
}
|
|
185
|
-
if (
|
|
186
|
-
const content =
|
|
238
|
+
if (existsSync3(npmrc)) {
|
|
239
|
+
const content = readFileSync3(npmrc, "utf8");
|
|
187
240
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
188
241
|
rmSync(npmrc);
|
|
189
|
-
console.log(
|
|
242
|
+
console.log(chalk3.gray(" Deleted .npmrc"));
|
|
190
243
|
}
|
|
191
244
|
}
|
|
192
245
|
}
|
|
193
246
|
function createYarnrc(cwd) {
|
|
194
247
|
const yarnrcPath = PATH2.join(cwd, ".yarnrc.yml");
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
console.log(
|
|
248
|
+
if (existsSync3(yarnrcPath)) return;
|
|
249
|
+
writeFileSync3(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
250
|
+
console.log(chalk3.green(" Created .yarnrc.yml"));
|
|
198
251
|
}
|
|
199
252
|
function readWorkspacePatternsFromPackageJson(cwd) {
|
|
200
253
|
const pkgPath = PATH2.join(cwd, "package.json");
|
|
201
|
-
if (!
|
|
202
|
-
const pkg = JSON.parse(
|
|
254
|
+
if (!existsSync3(pkgPath)) return [];
|
|
255
|
+
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
203
256
|
return pkg.workspaces ?? [];
|
|
204
257
|
}
|
|
205
258
|
function convertToYarn(cwd, workspacePackageJsonPaths) {
|
|
206
|
-
console.log(
|
|
259
|
+
console.log(chalk3.blue("\nConverting to yarn...\n"));
|
|
207
260
|
const workspacePatterns = readPnpmWorkspacePatterns(cwd);
|
|
208
261
|
if (workspacePatterns.length === 0) {
|
|
209
262
|
const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
|
|
210
263
|
if (fromPkg.length > 0) {
|
|
211
264
|
workspacePatterns.push(...fromPkg);
|
|
212
265
|
} else {
|
|
213
|
-
console.warn(
|
|
266
|
+
console.warn(chalk3.yellow(" No workspace patterns found"));
|
|
214
267
|
}
|
|
215
268
|
}
|
|
216
269
|
updateRootPackageJson(cwd, workspacePatterns);
|
|
217
270
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
218
271
|
const fullPath = PATH2.resolve(cwd, pkgPath, "package.json");
|
|
219
|
-
if (!
|
|
220
|
-
const pkg = JSON.parse(
|
|
272
|
+
if (!existsSync3(fullPath)) continue;
|
|
273
|
+
const pkg = JSON.parse(readFileSync3(fullPath, "utf8"));
|
|
221
274
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
222
275
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
223
|
-
|
|
276
|
+
writeFileSync3(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
224
277
|
}
|
|
225
278
|
}
|
|
226
|
-
console.log(
|
|
279
|
+
console.log(chalk3.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
227
280
|
updateGitignore(cwd);
|
|
228
281
|
createYarnrc(cwd);
|
|
229
282
|
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
283
|
+
rewriteSourceImports(cwd, "pnpm-to-yarn");
|
|
230
284
|
deletePnpmArtifacts(cwd);
|
|
231
|
-
console.log(
|
|
285
|
+
console.log(chalk3.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
232
286
|
return 0;
|
|
233
287
|
}
|
|
234
288
|
export {
|