@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
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
// src/actions/packman/convert.ts
|
|
2
2
|
import {
|
|
3
|
-
existsSync as
|
|
3
|
+
existsSync as existsSync5,
|
|
4
4
|
readdirSync,
|
|
5
|
-
readFileSync as
|
|
5
|
+
readFileSync as readFileSync5,
|
|
6
6
|
statSync
|
|
7
7
|
} from "fs";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import PATH4 from "path";
|
|
9
|
+
import chalk5 from "chalk";
|
|
10
10
|
|
|
11
11
|
// src/actions/packman/convertToPnpm.ts
|
|
12
12
|
import {
|
|
13
|
-
existsSync,
|
|
13
|
+
existsSync as existsSync3,
|
|
14
14
|
mkdirSync,
|
|
15
|
-
readFileSync,
|
|
15
|
+
readFileSync as readFileSync3,
|
|
16
16
|
rmSync,
|
|
17
|
-
writeFileSync
|
|
17
|
+
writeFileSync as writeFileSync3
|
|
18
18
|
} from "fs";
|
|
19
|
-
import
|
|
20
|
-
import
|
|
19
|
+
import PATH2 from "path";
|
|
20
|
+
import chalk3 from "chalk";
|
|
21
21
|
|
|
22
22
|
// src/actions/packman/rewriteScripts.ts
|
|
23
23
|
function rewriteYarnToPnpm(script) {
|
|
@@ -67,6 +67,113 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
67
67
|
return { ...pkg, scripts: rewritten };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
71
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
72
|
+
import chalk from "chalk";
|
|
73
|
+
import { globSync } from "glob";
|
|
74
|
+
var IMPORT_SWAP_MAP = {
|
|
75
|
+
"yarn-to-pnpm": [
|
|
76
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
77
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
78
|
+
],
|
|
79
|
+
"pnpm-to-yarn": [
|
|
80
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
81
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
var SOURCE_GLOBS = [
|
|
85
|
+
"**/*.ts",
|
|
86
|
+
"**/*.tsx",
|
|
87
|
+
"**/*.mts",
|
|
88
|
+
"**/*.cts",
|
|
89
|
+
"**/*.js",
|
|
90
|
+
"**/*.mjs"
|
|
91
|
+
];
|
|
92
|
+
var IGNORE_PATTERNS = [
|
|
93
|
+
"**/node_modules/**",
|
|
94
|
+
"**/dist/**",
|
|
95
|
+
"**/build/**",
|
|
96
|
+
"**/.yarn/**"
|
|
97
|
+
];
|
|
98
|
+
function rewriteSourceImports(cwd, direction) {
|
|
99
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
100
|
+
const files = globSync(SOURCE_GLOBS, {
|
|
101
|
+
cwd,
|
|
102
|
+
absolute: true,
|
|
103
|
+
ignore: IGNORE_PATTERNS
|
|
104
|
+
});
|
|
105
|
+
let count = 0;
|
|
106
|
+
for (const file of files) {
|
|
107
|
+
if (!existsSync(file)) continue;
|
|
108
|
+
const original = readFileSync(file, "utf8");
|
|
109
|
+
let content = original;
|
|
110
|
+
for (const [from, to] of swaps) {
|
|
111
|
+
content = content.replaceAll(from, to);
|
|
112
|
+
}
|
|
113
|
+
if (content !== original) {
|
|
114
|
+
writeFileSync(file, content, "utf8");
|
|
115
|
+
count++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (count > 0) {
|
|
119
|
+
console.log(chalk.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/actions/packman/swapTsScriptsDependency.ts
|
|
124
|
+
import {
|
|
125
|
+
existsSync as existsSync2,
|
|
126
|
+
readFileSync as readFileSync2,
|
|
127
|
+
writeFileSync as writeFileSync2
|
|
128
|
+
} from "fs";
|
|
129
|
+
import PATH from "path";
|
|
130
|
+
import chalk2 from "chalk";
|
|
131
|
+
var SWAP_MAP = {
|
|
132
|
+
"yarn-to-pnpm": [
|
|
133
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
134
|
+
],
|
|
135
|
+
"pnpm-to-yarn": [
|
|
136
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"]
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
function swapInPackageJson(pkgPath, direction) {
|
|
140
|
+
if (!existsSync2(pkgPath)) return false;
|
|
141
|
+
const raw = readFileSync2(pkgPath, "utf8");
|
|
142
|
+
const pkg = JSON.parse(raw);
|
|
143
|
+
let changed = false;
|
|
144
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
145
|
+
const deps = pkg[depField];
|
|
146
|
+
if (!deps) continue;
|
|
147
|
+
for (const [from, to] of SWAP_MAP[direction]) {
|
|
148
|
+
if (deps[from]) {
|
|
149
|
+
deps[to] = deps[from];
|
|
150
|
+
delete deps[from];
|
|
151
|
+
changed = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (changed) {
|
|
156
|
+
writeFileSync2(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
157
|
+
}
|
|
158
|
+
return changed;
|
|
159
|
+
}
|
|
160
|
+
function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
161
|
+
let count = 0;
|
|
162
|
+
if (swapInPackageJson(PATH.join(cwd, "package.json"), direction)) {
|
|
163
|
+
count++;
|
|
164
|
+
}
|
|
165
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
166
|
+
const fullPath = PATH.resolve(cwd, pkgPath, "package.json");
|
|
167
|
+
if (swapInPackageJson(fullPath, direction)) {
|
|
168
|
+
count++;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (count > 0) {
|
|
172
|
+
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
173
|
+
console.log(chalk2.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
70
177
|
// src/actions/packman/convertToPnpm.ts
|
|
71
178
|
var PNPM_VERSION = "10.12.1";
|
|
72
179
|
function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
@@ -74,24 +181,45 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
|
74
181
|
for (const pattern of workspacePatterns) {
|
|
75
182
|
lines.push(` - '${pattern}'`);
|
|
76
183
|
}
|
|
77
|
-
|
|
78
|
-
console.log(
|
|
184
|
+
writeFileSync3(PATH2.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
185
|
+
console.log(chalk3.green(" Created pnpm-workspace.yaml"));
|
|
186
|
+
}
|
|
187
|
+
function readPnpmWorkspacePatterns(cwd) {
|
|
188
|
+
const wsPath = PATH2.join(cwd, "pnpm-workspace.yaml");
|
|
189
|
+
if (!existsSync3(wsPath)) return [];
|
|
190
|
+
const content = readFileSync3(wsPath, "utf8");
|
|
191
|
+
const patterns = [];
|
|
192
|
+
const lines = content.split("\n");
|
|
193
|
+
let inPackages = false;
|
|
194
|
+
for (const line of lines) {
|
|
195
|
+
if (line.trim() === "packages:") {
|
|
196
|
+
inPackages = true;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
200
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
201
|
+
if (pattern) patterns.push(pattern);
|
|
202
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
203
|
+
inPackages = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return patterns;
|
|
79
207
|
}
|
|
80
208
|
function updateRootPackageJson(cwd) {
|
|
81
|
-
const pkgPath =
|
|
82
|
-
const pkg = JSON.parse(
|
|
83
|
-
const workspacePatterns = pkg.workspaces ??
|
|
209
|
+
const pkgPath = PATH2.join(cwd, "package.json");
|
|
210
|
+
const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
|
|
211
|
+
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd);
|
|
84
212
|
delete pkg.workspaces;
|
|
85
213
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
86
214
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
87
|
-
|
|
88
|
-
console.log(
|
|
215
|
+
writeFileSync3(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
216
|
+
console.log(chalk3.green(" Updated root package.json"));
|
|
89
217
|
return workspacePatterns;
|
|
90
218
|
}
|
|
91
219
|
function updateGitignore(cwd) {
|
|
92
|
-
const gitignorePath =
|
|
93
|
-
if (!
|
|
94
|
-
let content =
|
|
220
|
+
const gitignorePath = PATH2.join(cwd, ".gitignore");
|
|
221
|
+
if (!existsSync3(gitignorePath)) return;
|
|
222
|
+
let content = readFileSync3(gitignorePath, "utf8");
|
|
95
223
|
const yarnLines = [
|
|
96
224
|
".pnp.*",
|
|
97
225
|
".pnp",
|
|
@@ -106,63 +234,65 @@ function updateGitignore(cwd) {
|
|
|
106
234
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
107
235
|
}
|
|
108
236
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
109
|
-
|
|
110
|
-
console.log(
|
|
237
|
+
writeFileSync3(gitignorePath, content, "utf8");
|
|
238
|
+
console.log(chalk3.green(" Updated .gitignore"));
|
|
111
239
|
}
|
|
112
240
|
function deleteYarnArtifacts(cwd) {
|
|
113
|
-
const yarnLock =
|
|
114
|
-
const yarnrc =
|
|
115
|
-
const yarnDir =
|
|
116
|
-
if (
|
|
241
|
+
const yarnLock = PATH2.join(cwd, "yarn.lock");
|
|
242
|
+
const yarnrc = PATH2.join(cwd, ".yarnrc.yml");
|
|
243
|
+
const yarnDir = PATH2.join(cwd, ".yarn");
|
|
244
|
+
if (existsSync3(yarnLock)) {
|
|
117
245
|
rmSync(yarnLock);
|
|
118
|
-
console.log(
|
|
246
|
+
console.log(chalk3.gray(" Deleted yarn.lock"));
|
|
119
247
|
}
|
|
120
|
-
if (
|
|
248
|
+
if (existsSync3(yarnrc)) {
|
|
121
249
|
rmSync(yarnrc);
|
|
122
|
-
console.log(
|
|
250
|
+
console.log(chalk3.gray(" Deleted .yarnrc.yml"));
|
|
123
251
|
}
|
|
124
|
-
if (
|
|
252
|
+
if (existsSync3(yarnDir)) {
|
|
125
253
|
rmSync(yarnDir, { force: true, recursive: true });
|
|
126
|
-
console.log(
|
|
254
|
+
console.log(chalk3.gray(" Deleted .yarn/"));
|
|
127
255
|
}
|
|
128
256
|
}
|
|
129
257
|
function createNpmrc(cwd) {
|
|
130
|
-
const npmrcPath =
|
|
131
|
-
if (
|
|
132
|
-
mkdirSync(
|
|
133
|
-
|
|
134
|
-
console.log(
|
|
258
|
+
const npmrcPath = PATH2.join(cwd, ".npmrc");
|
|
259
|
+
if (existsSync3(npmrcPath)) return;
|
|
260
|
+
mkdirSync(PATH2.dirname(npmrcPath), { recursive: true });
|
|
261
|
+
writeFileSync3(npmrcPath, "", "utf8");
|
|
262
|
+
console.log(chalk3.green(" Created .npmrc"));
|
|
135
263
|
}
|
|
136
264
|
function convertToPnpm(cwd, workspacePackageJsonPaths) {
|
|
137
|
-
console.log(
|
|
265
|
+
console.log(chalk3.blue("\nConverting to pnpm...\n"));
|
|
138
266
|
const workspacePatterns = updateRootPackageJson(cwd);
|
|
139
267
|
createPnpmWorkspaceYaml(cwd, workspacePatterns);
|
|
140
268
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
141
|
-
const fullPath =
|
|
142
|
-
if (!
|
|
143
|
-
const pkg = JSON.parse(
|
|
269
|
+
const fullPath = PATH2.resolve(cwd, pkgPath, "package.json");
|
|
270
|
+
if (!existsSync3(fullPath)) continue;
|
|
271
|
+
const pkg = JSON.parse(readFileSync3(fullPath, "utf8"));
|
|
144
272
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
145
273
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
146
|
-
|
|
274
|
+
writeFileSync3(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
147
275
|
}
|
|
148
276
|
}
|
|
149
|
-
console.log(
|
|
277
|
+
console.log(chalk3.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
150
278
|
updateGitignore(cwd);
|
|
151
279
|
createNpmrc(cwd);
|
|
280
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
281
|
+
rewriteSourceImports(cwd, "yarn-to-pnpm");
|
|
152
282
|
deleteYarnArtifacts(cwd);
|
|
153
|
-
console.log(
|
|
283
|
+
console.log(chalk3.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
|
|
154
284
|
return 0;
|
|
155
285
|
}
|
|
156
286
|
|
|
157
287
|
// src/actions/packman/convertToYarn.ts
|
|
158
288
|
import {
|
|
159
|
-
existsSync as
|
|
160
|
-
readFileSync as
|
|
289
|
+
existsSync as existsSync4,
|
|
290
|
+
readFileSync as readFileSync4,
|
|
161
291
|
rmSync as rmSync2,
|
|
162
|
-
writeFileSync as
|
|
292
|
+
writeFileSync as writeFileSync4
|
|
163
293
|
} from "fs";
|
|
164
|
-
import
|
|
165
|
-
import
|
|
294
|
+
import PATH3 from "path";
|
|
295
|
+
import chalk4 from "chalk";
|
|
166
296
|
var YARN_VERSION = "4.13.0";
|
|
167
297
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
168
298
|
|
|
@@ -183,10 +313,10 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
183
313
|
!.yarn/sdks
|
|
184
314
|
!.yarn/versions
|
|
185
315
|
`;
|
|
186
|
-
function
|
|
187
|
-
const wsPath =
|
|
188
|
-
if (!
|
|
189
|
-
const content =
|
|
316
|
+
function readPnpmWorkspacePatterns2(cwd) {
|
|
317
|
+
const wsPath = PATH3.join(cwd, "pnpm-workspace.yaml");
|
|
318
|
+
if (!existsSync4(wsPath)) return [];
|
|
319
|
+
const content = readFileSync4(wsPath, "utf8");
|
|
190
320
|
const patterns = [];
|
|
191
321
|
const lines = content.split("\n");
|
|
192
322
|
let inPackages = false;
|
|
@@ -205,91 +335,104 @@ function readPnpmWorkspacePatterns(cwd) {
|
|
|
205
335
|
return patterns;
|
|
206
336
|
}
|
|
207
337
|
function updateRootPackageJson2(cwd, workspacePatterns) {
|
|
208
|
-
const pkgPath =
|
|
209
|
-
const pkg = JSON.parse(
|
|
338
|
+
const pkgPath = PATH3.join(cwd, "package.json");
|
|
339
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
210
340
|
pkg.workspaces = workspacePatterns;
|
|
211
341
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
212
342
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
213
|
-
|
|
214
|
-
console.log(
|
|
343
|
+
writeFileSync4(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
344
|
+
console.log(chalk4.green(" Updated root package.json"));
|
|
215
345
|
}
|
|
216
346
|
function updateGitignore2(cwd) {
|
|
217
|
-
const gitignorePath =
|
|
218
|
-
let content =
|
|
347
|
+
const gitignorePath = PATH3.join(cwd, ".gitignore");
|
|
348
|
+
let content = existsSync4(gitignorePath) ? readFileSync4(gitignorePath, "utf8") : "";
|
|
219
349
|
if (!content.includes(".yarn/*")) {
|
|
220
350
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
221
351
|
}
|
|
222
|
-
|
|
223
|
-
console.log(
|
|
352
|
+
writeFileSync4(gitignorePath, content, "utf8");
|
|
353
|
+
console.log(chalk4.green(" Updated .gitignore"));
|
|
224
354
|
}
|
|
225
355
|
function deletePnpmArtifacts(cwd) {
|
|
226
|
-
const lockfile =
|
|
227
|
-
const workspaceYaml =
|
|
228
|
-
const npmrc =
|
|
229
|
-
if (
|
|
356
|
+
const lockfile = PATH3.join(cwd, "pnpm-lock.yaml");
|
|
357
|
+
const workspaceYaml = PATH3.join(cwd, "pnpm-workspace.yaml");
|
|
358
|
+
const npmrc = PATH3.join(cwd, ".npmrc");
|
|
359
|
+
if (existsSync4(lockfile)) {
|
|
230
360
|
rmSync2(lockfile);
|
|
231
|
-
console.log(
|
|
361
|
+
console.log(chalk4.gray(" Deleted pnpm-lock.yaml"));
|
|
232
362
|
}
|
|
233
|
-
if (
|
|
363
|
+
if (existsSync4(workspaceYaml)) {
|
|
234
364
|
rmSync2(workspaceYaml);
|
|
235
|
-
console.log(
|
|
365
|
+
console.log(chalk4.gray(" Deleted pnpm-workspace.yaml"));
|
|
236
366
|
}
|
|
237
|
-
if (
|
|
238
|
-
const content =
|
|
367
|
+
if (existsSync4(npmrc)) {
|
|
368
|
+
const content = readFileSync4(npmrc, "utf8");
|
|
239
369
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
240
370
|
rmSync2(npmrc);
|
|
241
|
-
console.log(
|
|
371
|
+
console.log(chalk4.gray(" Deleted .npmrc"));
|
|
242
372
|
}
|
|
243
373
|
}
|
|
244
374
|
}
|
|
245
375
|
function createYarnrc(cwd) {
|
|
246
|
-
const yarnrcPath =
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
console.log(
|
|
376
|
+
const yarnrcPath = PATH3.join(cwd, ".yarnrc.yml");
|
|
377
|
+
if (existsSync4(yarnrcPath)) return;
|
|
378
|
+
writeFileSync4(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
379
|
+
console.log(chalk4.green(" Created .yarnrc.yml"));
|
|
380
|
+
}
|
|
381
|
+
function readWorkspacePatternsFromPackageJson(cwd) {
|
|
382
|
+
const pkgPath = PATH3.join(cwd, "package.json");
|
|
383
|
+
if (!existsSync4(pkgPath)) return [];
|
|
384
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf8"));
|
|
385
|
+
return pkg.workspaces ?? [];
|
|
250
386
|
}
|
|
251
387
|
function convertToYarn(cwd, workspacePackageJsonPaths) {
|
|
252
|
-
console.log(
|
|
253
|
-
const workspacePatterns =
|
|
388
|
+
console.log(chalk4.blue("\nConverting to yarn...\n"));
|
|
389
|
+
const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
|
|
254
390
|
if (workspacePatterns.length === 0) {
|
|
255
|
-
|
|
391
|
+
const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
|
|
392
|
+
if (fromPkg.length > 0) {
|
|
393
|
+
workspacePatterns.push(...fromPkg);
|
|
394
|
+
} else {
|
|
395
|
+
console.warn(chalk4.yellow(" No workspace patterns found"));
|
|
396
|
+
}
|
|
256
397
|
}
|
|
257
398
|
updateRootPackageJson2(cwd, workspacePatterns);
|
|
258
399
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
259
|
-
const fullPath =
|
|
260
|
-
if (!
|
|
261
|
-
const pkg = JSON.parse(
|
|
400
|
+
const fullPath = PATH3.resolve(cwd, pkgPath, "package.json");
|
|
401
|
+
if (!existsSync4(fullPath)) continue;
|
|
402
|
+
const pkg = JSON.parse(readFileSync4(fullPath, "utf8"));
|
|
262
403
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
263
404
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
264
|
-
|
|
405
|
+
writeFileSync4(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
265
406
|
}
|
|
266
407
|
}
|
|
267
|
-
console.log(
|
|
408
|
+
console.log(chalk4.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
268
409
|
updateGitignore2(cwd);
|
|
269
410
|
createYarnrc(cwd);
|
|
411
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
412
|
+
rewriteSourceImports(cwd, "pnpm-to-yarn");
|
|
270
413
|
deletePnpmArtifacts(cwd);
|
|
271
|
-
console.log(
|
|
414
|
+
console.log(chalk4.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
|
|
272
415
|
return 0;
|
|
273
416
|
}
|
|
274
417
|
|
|
275
418
|
// src/actions/packman/convert.ts
|
|
276
419
|
function detectCurrentPM(cwd) {
|
|
277
|
-
if (
|
|
420
|
+
if (existsSync5(PATH4.join(cwd, "pnpm-lock.yaml")) || existsSync5(PATH4.join(cwd, "pnpm-workspace.yaml"))) {
|
|
278
421
|
return "pnpm";
|
|
279
422
|
}
|
|
280
|
-
if (
|
|
423
|
+
if (existsSync5(PATH4.join(cwd, "yarn.lock")) || existsSync5(PATH4.join(cwd, ".yarnrc.yml"))) {
|
|
281
424
|
return "yarn";
|
|
282
425
|
}
|
|
283
426
|
return "unknown";
|
|
284
427
|
}
|
|
285
428
|
function findWorkspacePackagePaths(cwd) {
|
|
286
|
-
const pkgPath =
|
|
287
|
-
const pkg = JSON.parse(
|
|
429
|
+
const pkgPath = PATH4.join(cwd, "package.json");
|
|
430
|
+
const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
|
|
288
431
|
let patterns = pkg.workspaces ?? [];
|
|
289
432
|
if (patterns.length === 0) {
|
|
290
|
-
const wsPath =
|
|
291
|
-
if (
|
|
292
|
-
const content =
|
|
433
|
+
const wsPath = PATH4.join(cwd, "pnpm-workspace.yaml");
|
|
434
|
+
if (existsSync5(wsPath)) {
|
|
435
|
+
const content = readFileSync5(wsPath, "utf8");
|
|
293
436
|
const lines = content.split("\n");
|
|
294
437
|
let inPackages = false;
|
|
295
438
|
for (const line of lines) {
|
|
@@ -319,15 +462,15 @@ function resolveWorkspaceGlob(cwd, pattern) {
|
|
|
319
462
|
}
|
|
320
463
|
function walkGlob(basePath, parts, currentPath) {
|
|
321
464
|
if (parts.length === 0) {
|
|
322
|
-
const fullPath =
|
|
323
|
-
if (
|
|
465
|
+
const fullPath = PATH4.join(basePath, currentPath);
|
|
466
|
+
if (existsSync5(PATH4.join(fullPath, "package.json"))) {
|
|
324
467
|
return [currentPath];
|
|
325
468
|
}
|
|
326
469
|
return [];
|
|
327
470
|
}
|
|
328
471
|
const [part, ...rest] = parts;
|
|
329
|
-
const dirPath =
|
|
330
|
-
if (!
|
|
472
|
+
const dirPath = PATH4.join(basePath, currentPath);
|
|
473
|
+
if (!existsSync5(dirPath) || !statSync(dirPath).isDirectory()) {
|
|
331
474
|
return [];
|
|
332
475
|
}
|
|
333
476
|
if (part === "*" || part === "**") {
|
|
@@ -355,26 +498,25 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
355
498
|
function convert({ target, verbose }) {
|
|
356
499
|
const validTargets = ["pnpm", "yarn"];
|
|
357
500
|
if (!validTargets.includes(target)) {
|
|
358
|
-
console.error(
|
|
501
|
+
console.error(chalk5.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
359
502
|
return 1;
|
|
360
503
|
}
|
|
361
504
|
const cwd = process.cwd();
|
|
362
505
|
const currentPM = detectCurrentPM(cwd);
|
|
363
506
|
if (verbose) {
|
|
364
|
-
console.log(
|
|
365
|
-
console.log(
|
|
507
|
+
console.log(chalk5.gray(`Current package manager: ${currentPM}`));
|
|
508
|
+
console.log(chalk5.gray(`Target package manager: ${target}`));
|
|
366
509
|
}
|
|
367
510
|
if (currentPM === target) {
|
|
368
|
-
console.
|
|
369
|
-
return 1;
|
|
511
|
+
console.log(chalk5.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
370
512
|
}
|
|
371
513
|
if (currentPM === "unknown") {
|
|
372
|
-
console.error(
|
|
514
|
+
console.error(chalk5.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
373
515
|
return 1;
|
|
374
516
|
}
|
|
375
517
|
const workspacePaths = findWorkspacePackagePaths(cwd);
|
|
376
518
|
if (verbose) {
|
|
377
|
-
console.log(
|
|
519
|
+
console.log(chalk5.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
378
520
|
}
|
|
379
521
|
if (target === "pnpm") {
|
|
380
522
|
return convertToPnpm(cwd, workspacePaths);
|