@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.
Files changed (43) hide show
  1. package/dist/actions/deplint/checkPackage/checkPackage.mjs +27 -0
  2. package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -1
  3. package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +27 -0
  4. package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +1 -1
  5. package/dist/actions/deplint/checkPackage/index.mjs +27 -0
  6. package/dist/actions/deplint/checkPackage/index.mjs.map +1 -1
  7. package/dist/actions/deplint/deplint.mjs +18 -0
  8. package/dist/actions/deplint/deplint.mjs.map +1 -1
  9. package/dist/actions/deplint/implicitDevDependencies.mjs +25 -0
  10. package/dist/actions/deplint/implicitDevDependencies.mjs.map +1 -1
  11. package/dist/actions/deplint/index.mjs +18 -0
  12. package/dist/actions/deplint/index.mjs.map +1 -1
  13. package/dist/actions/index.mjs +270 -110
  14. package/dist/actions/index.mjs.map +1 -1
  15. package/dist/actions/packman/convert.mjs +242 -100
  16. package/dist/actions/packman/convert.mjs.map +1 -1
  17. package/dist/actions/packman/convertToPnpm.mjs +168 -38
  18. package/dist/actions/packman/convertToPnpm.mjs.map +1 -1
  19. package/dist/actions/packman/convertToYarn.mjs +158 -38
  20. package/dist/actions/packman/convertToYarn.mjs.map +1 -1
  21. package/dist/actions/packman/index.mjs +242 -100
  22. package/dist/actions/packman/index.mjs.map +1 -1
  23. package/dist/actions/packman/rewriteSourceImports.mjs +56 -0
  24. package/dist/actions/packman/rewriteSourceImports.mjs.map +1 -0
  25. package/dist/actions/packman/swapTsScriptsDependency.mjs +57 -0
  26. package/dist/actions/packman/swapTsScriptsDependency.mjs.map +1 -0
  27. package/dist/bin/xy.mjs +287 -127
  28. package/dist/bin/xy.mjs.map +1 -1
  29. package/dist/index.mjs +289 -129
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/xy/common/index.mjs +242 -100
  32. package/dist/xy/common/index.mjs.map +1 -1
  33. package/dist/xy/common/packmanCommand.mjs +242 -100
  34. package/dist/xy/common/packmanCommand.mjs.map +1 -1
  35. package/dist/xy/index.mjs +287 -127
  36. package/dist/xy/index.mjs.map +1 -1
  37. package/dist/xy/lint/deplintCommand.mjs +18 -0
  38. package/dist/xy/lint/deplintCommand.mjs.map +1 -1
  39. package/dist/xy/lint/index.mjs +18 -0
  40. package/dist/xy/lint/index.mjs.map +1 -1
  41. package/dist/xy/xy.mjs +287 -127
  42. package/dist/xy/xy.mjs.map +1 -1
  43. package/package.json +2 -2
@@ -1,23 +1,23 @@
1
1
  // src/actions/packman/convert.ts
2
2
  import {
3
- existsSync as existsSync3,
3
+ existsSync as existsSync5,
4
4
  readdirSync,
5
- readFileSync as readFileSync3,
5
+ readFileSync as readFileSync5,
6
6
  statSync
7
7
  } from "fs";
8
- import PATH3 from "path";
9
- import chalk3 from "chalk";
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 PATH from "path";
20
- import chalk from "chalk";
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
- writeFileSync(PATH.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
78
- console.log(chalk.green(" Created pnpm-workspace.yaml"));
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 = PATH.join(cwd, "package.json");
82
- const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
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
- writeFileSync(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
88
- console.log(chalk.green(" Updated root package.json"));
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 = PATH.join(cwd, ".gitignore");
93
- if (!existsSync(gitignorePath)) return;
94
- let content = readFileSync(gitignorePath, "utf8");
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
- writeFileSync(gitignorePath, content, "utf8");
110
- console.log(chalk.green(" Updated .gitignore"));
237
+ writeFileSync3(gitignorePath, content, "utf8");
238
+ console.log(chalk3.green(" Updated .gitignore"));
111
239
  }
112
240
  function deleteYarnArtifacts(cwd) {
113
- const yarnLock = PATH.join(cwd, "yarn.lock");
114
- const yarnrc = PATH.join(cwd, ".yarnrc.yml");
115
- const yarnDir = PATH.join(cwd, ".yarn");
116
- if (existsSync(yarnLock)) {
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(chalk.gray(" Deleted yarn.lock"));
246
+ console.log(chalk3.gray(" Deleted yarn.lock"));
119
247
  }
120
- if (existsSync(yarnrc)) {
248
+ if (existsSync3(yarnrc)) {
121
249
  rmSync(yarnrc);
122
- console.log(chalk.gray(" Deleted .yarnrc.yml"));
250
+ console.log(chalk3.gray(" Deleted .yarnrc.yml"));
123
251
  }
124
- if (existsSync(yarnDir)) {
252
+ if (existsSync3(yarnDir)) {
125
253
  rmSync(yarnDir, { force: true, recursive: true });
126
- console.log(chalk.gray(" Deleted .yarn/"));
254
+ console.log(chalk3.gray(" Deleted .yarn/"));
127
255
  }
128
256
  }
129
257
  function createNpmrc(cwd) {
130
- const npmrcPath = PATH.join(cwd, ".npmrc");
131
- if (existsSync(npmrcPath)) return;
132
- mkdirSync(PATH.dirname(npmrcPath), { recursive: true });
133
- writeFileSync(npmrcPath, "", "utf8");
134
- console.log(chalk.green(" Created .npmrc"));
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(chalk.blue("\nConverting to pnpm...\n"));
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 = PATH.resolve(cwd, pkgPath, "package.json");
142
- if (!existsSync(fullPath)) continue;
143
- const pkg = JSON.parse(readFileSync(fullPath, "utf8"));
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
- writeFileSync(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
274
+ writeFileSync3(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
147
275
  }
148
276
  }
149
- console.log(chalk.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
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(chalk.blue("\nConversion complete. Run `pnpm install` to generate pnpm-lock.yaml.\n"));
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 existsSync2,
160
- readFileSync as readFileSync2,
289
+ existsSync as existsSync4,
290
+ readFileSync as readFileSync4,
161
291
  rmSync as rmSync2,
162
- writeFileSync as writeFileSync2
292
+ writeFileSync as writeFileSync4
163
293
  } from "fs";
164
- import PATH2 from "path";
165
- import chalk2 from "chalk";
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 readPnpmWorkspacePatterns(cwd) {
187
- const wsPath = PATH2.join(cwd, "pnpm-workspace.yaml");
188
- if (!existsSync2(wsPath)) return [];
189
- const content = readFileSync2(wsPath, "utf8");
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 = PATH2.join(cwd, "package.json");
209
- const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
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
- writeFileSync2(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
214
- console.log(chalk2.green(" Updated root package.json"));
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 = PATH2.join(cwd, ".gitignore");
218
- let content = existsSync2(gitignorePath) ? readFileSync2(gitignorePath, "utf8") : "";
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
- writeFileSync2(gitignorePath, content, "utf8");
223
- console.log(chalk2.green(" Updated .gitignore"));
352
+ writeFileSync4(gitignorePath, content, "utf8");
353
+ console.log(chalk4.green(" Updated .gitignore"));
224
354
  }
225
355
  function deletePnpmArtifacts(cwd) {
226
- const lockfile = PATH2.join(cwd, "pnpm-lock.yaml");
227
- const workspaceYaml = PATH2.join(cwd, "pnpm-workspace.yaml");
228
- const npmrc = PATH2.join(cwd, ".npmrc");
229
- if (existsSync2(lockfile)) {
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(chalk2.gray(" Deleted pnpm-lock.yaml"));
361
+ console.log(chalk4.gray(" Deleted pnpm-lock.yaml"));
232
362
  }
233
- if (existsSync2(workspaceYaml)) {
363
+ if (existsSync4(workspaceYaml)) {
234
364
  rmSync2(workspaceYaml);
235
- console.log(chalk2.gray(" Deleted pnpm-workspace.yaml"));
365
+ console.log(chalk4.gray(" Deleted pnpm-workspace.yaml"));
236
366
  }
237
- if (existsSync2(npmrc)) {
238
- const content = readFileSync2(npmrc, "utf8");
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(chalk2.gray(" Deleted .npmrc"));
371
+ console.log(chalk4.gray(" Deleted .npmrc"));
242
372
  }
243
373
  }
244
374
  }
245
375
  function createYarnrc(cwd) {
246
- const yarnrcPath = PATH2.join(cwd, ".yarnrc.yml");
247
- if (existsSync2(yarnrcPath)) return;
248
- writeFileSync2(yarnrcPath, YARNRC_TEMPLATE, "utf8");
249
- console.log(chalk2.green(" Created .yarnrc.yml"));
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(chalk2.blue("\nConverting to yarn...\n"));
253
- const workspacePatterns = readPnpmWorkspacePatterns(cwd);
388
+ console.log(chalk4.blue("\nConverting to yarn...\n"));
389
+ const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
254
390
  if (workspacePatterns.length === 0) {
255
- console.warn(chalk2.yellow(" No workspace patterns found in pnpm-workspace.yaml"));
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 = PATH2.resolve(cwd, pkgPath, "package.json");
260
- if (!existsSync2(fullPath)) continue;
261
- const pkg = JSON.parse(readFileSync2(fullPath, "utf8"));
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
- writeFileSync2(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
405
+ writeFileSync4(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
265
406
  }
266
407
  }
267
- console.log(chalk2.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
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(chalk2.blue("\nConversion complete. Run `corepack enable yarn && yarn set version stable && yarn install` to finish setup.\n"));
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 (existsSync3(PATH3.join(cwd, "pnpm-lock.yaml")) || existsSync3(PATH3.join(cwd, "pnpm-workspace.yaml"))) {
420
+ if (existsSync5(PATH4.join(cwd, "pnpm-lock.yaml")) || existsSync5(PATH4.join(cwd, "pnpm-workspace.yaml"))) {
278
421
  return "pnpm";
279
422
  }
280
- if (existsSync3(PATH3.join(cwd, "yarn.lock")) || existsSync3(PATH3.join(cwd, ".yarnrc.yml"))) {
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 = PATH3.join(cwd, "package.json");
287
- const pkg = JSON.parse(readFileSync3(pkgPath, "utf8"));
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 = PATH3.join(cwd, "pnpm-workspace.yaml");
291
- if (existsSync3(wsPath)) {
292
- const content = readFileSync3(wsPath, "utf8");
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 = PATH3.join(basePath, currentPath);
323
- if (existsSync3(PATH3.join(fullPath, "package.json"))) {
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 = PATH3.join(basePath, currentPath);
330
- if (!existsSync3(dirPath) || !statSync(dirPath).isDirectory()) {
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(chalk3.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
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(chalk3.gray(`Current package manager: ${currentPM}`));
365
- console.log(chalk3.gray(`Target package manager: ${target}`));
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.error(chalk3.red(`Already using ${target}. No conversion needed.`));
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(chalk3.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
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(chalk3.gray(`Found ${workspacePaths.length} workspace packages`));
519
+ console.log(chalk5.gray(`Found ${workspacePaths.length} workspace packages`));
378
520
  }
379
521
  if (target === "pnpm") {
380
522
  return convertToPnpm(cwd, workspacePaths);