@reliverse/dler 1.7.152 → 1.7.153

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 (33) hide show
  1. package/bin/impl/auth/impl/init.d.ts +2 -2
  2. package/bin/impl/build/impl.d.ts +7 -1
  3. package/bin/impl/build/impl.js +161 -1
  4. package/bin/impl/config/constants.d.ts +1 -1
  5. package/bin/impl/config/constants.js +1 -1
  6. package/bin/impl/providers/better-t-stack/types.d.ts +7 -7
  7. package/bin/impl/pub/impl.d.ts +6 -1
  8. package/bin/impl/pub/impl.js +176 -2
  9. package/bin/impl/schema/mod.d.ts +140 -0
  10. package/bin/impl/schema/mod.js +22 -0
  11. package/bin/impl/utils/workspace-prompt.d.ts +9 -0
  12. package/bin/impl/utils/workspace-prompt.js +46 -0
  13. package/bin/impl/utils/workspace-utils.d.ts +28 -0
  14. package/bin/impl/utils/workspace-utils.js +127 -0
  15. package/bin/mod.d.ts +2 -9
  16. package/bin/mod.js +9 -23
  17. package/package.json +2 -1
  18. package/bin/impl/migrate/codemods/anything-bun.d.ts +0 -5
  19. package/bin/impl/migrate/codemods/anything-bun.js +0 -577
  20. package/bin/impl/migrate/codemods/commander-rempts.d.ts +0 -4
  21. package/bin/impl/migrate/codemods/commander-rempts.js +0 -250
  22. package/bin/impl/migrate/codemods/console-relinka.d.ts +0 -3
  23. package/bin/impl/migrate/codemods/console-relinka.js +0 -142
  24. package/bin/impl/migrate/codemods/fs-relifso.d.ts +0 -8
  25. package/bin/impl/migrate/codemods/fs-relifso.js +0 -156
  26. package/bin/impl/migrate/codemods/monorepo-catalog.d.ts +0 -96
  27. package/bin/impl/migrate/codemods/monorepo-catalog.js +0 -517
  28. package/bin/impl/migrate/codemods/nodenext-bundler.d.ts +0 -10
  29. package/bin/impl/migrate/codemods/nodenext-bundler.js +0 -222
  30. package/bin/impl/migrate/codemods/path-pathkit.d.ts +0 -8
  31. package/bin/impl/migrate/codemods/path-pathkit.js +0 -143
  32. package/bin/impl/migrate/codemods/readdir-glob.d.ts +0 -8
  33. package/bin/impl/migrate/codemods/readdir-glob.js +0 -133
@@ -1,517 +0,0 @@
1
- import path from "@reliverse/pathkit";
2
- import fs from "@reliverse/relifso";
3
- import { relinka } from "@reliverse/relinka";
4
- import { multiselectPrompt } from "@reliverse/rempts";
5
- import { readPackageJSON } from "pkg-types";
6
- import semver from "semver";
7
- import { glob } from "tinyglobby";
8
- export function isCatalogReference(versionSpec) {
9
- return versionSpec.startsWith("catalog:");
10
- }
11
- export function isWorkspaceDependency(versionSpec) {
12
- return versionSpec.startsWith("workspace:");
13
- }
14
- export function isNpmAlias(versionSpec) {
15
- return versionSpec.startsWith("npm:");
16
- }
17
- export function shouldSkipDependency(versionSpec) {
18
- return isNpmAlias(versionSpec) || isWorkspaceDependency(versionSpec) || isCatalogReference(versionSpec) || versionSpec.startsWith("git+") || versionSpec.startsWith("file:") || versionSpec.startsWith("link:") || versionSpec.startsWith("http:") || versionSpec.startsWith("https:");
19
- }
20
- export async function findWorkspacePackageJsons(cwd) {
21
- const root = await readPackageJSON(cwd);
22
- const ws = root.workspaces;
23
- let patterns = [];
24
- if (Array.isArray(ws)) {
25
- patterns = ws;
26
- } else if (ws && Array.isArray(ws.packages)) {
27
- patterns = ws.packages;
28
- }
29
- if (!patterns.length) return [];
30
- const dirs = await glob(patterns, {
31
- cwd,
32
- onlyDirectories: true,
33
- absolute: true,
34
- ignore: ["**/node_modules/**", "**/dist/**", "**/.git/**"]
35
- });
36
- const pkgJsonPaths = [];
37
- for (const dir of dirs) {
38
- const pj = path.join(dir, "package.json");
39
- if (await fs.pathExists(pj)) pkgJsonPaths.push(pj);
40
- }
41
- return pkgJsonPaths;
42
- }
43
- export async function isMonorepo(cwd) {
44
- try {
45
- const root = await readPackageJSON(cwd);
46
- const ws = root.workspaces;
47
- if (Array.isArray(ws) && ws.length > 0) {
48
- return true;
49
- }
50
- if (ws && Array.isArray(ws.packages) && ws.packages.length > 0) {
51
- return true;
52
- }
53
- return false;
54
- } catch {
55
- return false;
56
- }
57
- }
58
- export function extractDependencies(packageJson, packageJsonPath) {
59
- const dependencies = [];
60
- const deps = packageJson.dependencies || {};
61
- for (const [name, version] of Object.entries(deps)) {
62
- if (typeof version === "string" && !shouldSkipDependency(version)) {
63
- dependencies.push({
64
- name,
65
- version,
66
- locations: /* @__PURE__ */ new Set(["dependencies"]),
67
- packageJsonPath
68
- });
69
- }
70
- }
71
- const devDeps = packageJson.devDependencies || {};
72
- for (const [name, version] of Object.entries(devDeps)) {
73
- if (typeof version === "string" && !shouldSkipDependency(version)) {
74
- const existing = dependencies.find((d) => d.name === name);
75
- if (existing) {
76
- existing.locations.add("devDependencies");
77
- if (existing.locations.has("dependencies")) {
78
- existing.version = deps[name] || existing.version;
79
- }
80
- } else {
81
- dependencies.push({
82
- name,
83
- version,
84
- locations: /* @__PURE__ */ new Set(["devDependencies"]),
85
- packageJsonPath
86
- });
87
- }
88
- }
89
- }
90
- return dependencies;
91
- }
92
- export function mergeToCatalog(existingCatalog, newDependencies) {
93
- const result = {
94
- added: [],
95
- bumped: [],
96
- skipped: []
97
- };
98
- for (const dep of newDependencies) {
99
- const existingVersion = existingCatalog[dep.name];
100
- if (!existingVersion) {
101
- existingCatalog[dep.name] = dep.version;
102
- result.added.push(dep);
103
- } else {
104
- try {
105
- const cleanExisting = existingVersion.replace(/^[\^~]/, "");
106
- const cleanNew = dep.version.replace(/^[\^~]/, "");
107
- if (semver.valid(cleanExisting) && semver.valid(cleanNew)) {
108
- if (semver.gt(cleanNew, cleanExisting)) {
109
- existingCatalog[dep.name] = dep.version;
110
- result.bumped.push({ ...dep, oldVersion: existingVersion });
111
- } else {
112
- result.skipped.push(dep);
113
- }
114
- } else {
115
- result.skipped.push(dep);
116
- }
117
- } catch {
118
- result.skipped.push(dep);
119
- }
120
- }
121
- }
122
- return result;
123
- }
124
- export async function replaceDependenciesWithCatalogRefs(packageJsonPath, dependenciesToReplace) {
125
- try {
126
- const packageJsonContent = await fs.readFile(packageJsonPath, "utf8");
127
- const packageJson = JSON.parse(packageJsonContent);
128
- let replacedCount = 0;
129
- for (const dep of dependenciesToReplace) {
130
- for (const location of dep.locations) {
131
- if (location === "dependencies" && packageJson.dependencies?.[dep.name]) {
132
- packageJson.dependencies[dep.name] = "catalog:";
133
- replacedCount++;
134
- } else if (location === "devDependencies" && packageJson.devDependencies?.[dep.name]) {
135
- packageJson.devDependencies[dep.name] = "catalog:";
136
- replacedCount++;
137
- }
138
- }
139
- }
140
- if (replacedCount > 0) {
141
- await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf8");
142
- }
143
- return replacedCount;
144
- } catch (error) {
145
- relinka(
146
- "warn",
147
- `Failed to update ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`
148
- );
149
- return 0;
150
- }
151
- }
152
- export async function restoreCatalogReferences(packageJsonPath, catalog) {
153
- try {
154
- const packageJsonContent = await fs.readFile(packageJsonPath, "utf8");
155
- const packageJson = JSON.parse(packageJsonContent);
156
- let restoredCount = 0;
157
- const deps = packageJson.dependencies || {};
158
- for (const [name, version] of Object.entries(deps)) {
159
- if (typeof version === "string" && isCatalogReference(version)) {
160
- const catalogVersion = catalog[name];
161
- if (catalogVersion && packageJson.dependencies) {
162
- packageJson.dependencies[name] = catalogVersion;
163
- restoredCount++;
164
- } else {
165
- relinka("warn", `No catalog entry found for dependency: ${name} in ${packageJsonPath}`);
166
- }
167
- }
168
- }
169
- const devDeps = packageJson.devDependencies || {};
170
- for (const [name, version] of Object.entries(devDeps)) {
171
- if (typeof version === "string" && isCatalogReference(version)) {
172
- const catalogVersion = catalog[name];
173
- if (catalogVersion && packageJson.devDependencies) {
174
- packageJson.devDependencies[name] = catalogVersion;
175
- restoredCount++;
176
- } else {
177
- relinka(
178
- "warn",
179
- `No catalog entry found for devDependency: ${name} in ${packageJsonPath}`
180
- );
181
- }
182
- }
183
- }
184
- if (restoredCount > 0) {
185
- await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf8");
186
- }
187
- return restoredCount;
188
- } catch (error) {
189
- relinka(
190
- "warn",
191
- `Failed to restore ${packageJsonPath}: ${error instanceof Error ? error.message : String(error)}`
192
- );
193
- return 0;
194
- }
195
- }
196
- export async function updateRootWithCatalog(rootPackageJsonPath, catalog) {
197
- try {
198
- const packageJsonContent = await fs.readFile(rootPackageJsonPath, "utf8");
199
- const packageJson = JSON.parse(packageJsonContent);
200
- if (!packageJson.workspaces) {
201
- packageJson.workspaces = {};
202
- }
203
- if (Array.isArray(packageJson.workspaces)) {
204
- packageJson.workspaces = { packages: packageJson.workspaces };
205
- }
206
- packageJson.workspaces.catalog = catalog;
207
- await fs.writeFile(rootPackageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf8");
208
- } catch (error) {
209
- throw new Error(
210
- `Failed to update root package.json: ${error instanceof Error ? error.message : String(error)}`
211
- );
212
- }
213
- }
214
- export async function removeCatalogFromRoot(rootPackageJsonPath) {
215
- try {
216
- const packageJsonContent = await fs.readFile(rootPackageJsonPath, "utf8");
217
- const packageJson = JSON.parse(packageJsonContent);
218
- if (packageJson.workspaces && !Array.isArray(packageJson.workspaces) && packageJson.workspaces.catalog) {
219
- packageJson.workspaces.catalog = void 0;
220
- if (Object.keys(packageJson.workspaces).length === 0 || Object.keys(packageJson.workspaces).length === 1 && packageJson.workspaces.packages) {
221
- if (!packageJson.workspaces.packages) {
222
- packageJson.workspaces = void 0;
223
- }
224
- }
225
- }
226
- if (packageJson.catalog) {
227
- packageJson.catalog = void 0;
228
- }
229
- await fs.writeFile(rootPackageJsonPath, JSON.stringify(packageJson, null, 2) + "\n", "utf8");
230
- } catch (error) {
231
- throw new Error(
232
- `Failed to remove catalog from root package.json: ${error instanceof Error ? error.message : String(error)}`
233
- );
234
- }
235
- }
236
- export async function migrateToCatalog(rootPath, dryRun = false, interactive = false) {
237
- const results = [];
238
- const workspacePaths = await findWorkspacePackageJsons(rootPath);
239
- if (workspacePaths.length === 0) {
240
- throw new Error("No workspace packages found. This command requires a monorepo setup.");
241
- }
242
- relinka("log", `Found ${workspacePaths.length} workspace packages`);
243
- const allDependencies = [];
244
- for (const workspacePath of workspacePaths) {
245
- try {
246
- const packageJsonContent = await fs.readFile(workspacePath, "utf8");
247
- const packageJson = JSON.parse(packageJsonContent);
248
- const deps = extractDependencies(packageJson, workspacePath);
249
- allDependencies.push(...deps);
250
- } catch (error) {
251
- relinka(
252
- "warn",
253
- `Failed to read ${workspacePath}: ${error instanceof Error ? error.message : String(error)}`
254
- );
255
- }
256
- }
257
- if (allDependencies.length === 0) {
258
- relinka("log", "No dependencies found to migrate to catalog");
259
- return results;
260
- }
261
- relinka("log", `Found ${allDependencies.length} total dependency entries across workspaces`);
262
- const rootPackageJsonPath = path.resolve(rootPath, "package.json");
263
- let existingCatalog = {};
264
- try {
265
- const rootPackageJson = await readPackageJSON(rootPath);
266
- existingCatalog = rootPackageJson.workspaces?.catalog || {};
267
- } catch (error) {
268
- relinka(
269
- "warn",
270
- `Failed to read root package.json: ${error instanceof Error ? error.message : String(error)}`
271
- );
272
- }
273
- const mergeResult = mergeToCatalog(existingCatalog, allDependencies);
274
- relinka("log", `Catalog merge summary:`);
275
- relinka("log", ` - ${mergeResult.added.length} new dependencies added`);
276
- relinka("log", ` - ${mergeResult.bumped.length} dependencies bumped to newer versions`);
277
- relinka(
278
- "log",
279
- ` - ${mergeResult.skipped.length} dependencies skipped (already up-to-date or incompatible)`
280
- );
281
- let dependenciesToMigrate = allDependencies;
282
- if (interactive && allDependencies.length > 0) {
283
- const selectedPackages = await multiselectPrompt({
284
- title: "Select dependencies to migrate to catalog",
285
- options: [
286
- { label: "Migrate all dependencies", value: "all" },
287
- { label: "Cancel migration", value: "cancel" },
288
- ...Array.from(new Set(allDependencies.map((d) => d.name))).map((name) => ({
289
- label: name,
290
- value: name
291
- }))
292
- ]
293
- });
294
- if (selectedPackages.includes("cancel")) {
295
- relinka("log", "Migration cancelled");
296
- return results;
297
- }
298
- if (!selectedPackages.includes("all")) {
299
- dependenciesToMigrate = allDependencies.filter((dep) => selectedPackages.includes(dep.name));
300
- }
301
- }
302
- if (dryRun) {
303
- relinka("log", "Dry run mode - no changes were made");
304
- relinka("log", "Would migrate the following dependencies to catalog:");
305
- const uniqueDeps = Array.from(new Set(dependenciesToMigrate.map((d) => d.name)));
306
- for (const depName of uniqueDeps) {
307
- const catalogVersion = existingCatalog[depName];
308
- relinka("log", ` ${depName}: ${catalogVersion || "new entry"}`);
309
- }
310
- return results;
311
- }
312
- await updateRootWithCatalog(rootPackageJsonPath, existingCatalog);
313
- const workspaceResults = /* @__PURE__ */ new Map();
314
- for (const dep of dependenciesToMigrate) {
315
- if (!workspaceResults.has(dep.packageJsonPath)) {
316
- workspaceResults.set(dep.packageJsonPath, []);
317
- }
318
- workspaceResults.get(dep.packageJsonPath).push(dep);
319
- }
320
- for (const [packagePath, deps] of workspaceResults.entries()) {
321
- const replacedCount = await replaceDependenciesWithCatalogRefs(packagePath, deps);
322
- if (replacedCount > 0) {
323
- relinka("log", `Updated ${replacedCount} dependencies in ${packagePath}`);
324
- for (const dep of deps) {
325
- results.push({
326
- package: dep.name,
327
- action: "replaced-with-catalog",
328
- oldVersion: dep.version,
329
- newVersion: "catalog:",
330
- location: Array.from(dep.locations).join(", "),
331
- packageJsonPath: packagePath
332
- });
333
- }
334
- }
335
- }
336
- for (const dep of mergeResult.added) {
337
- results.push({
338
- package: dep.name,
339
- action: "added-to-catalog",
340
- newVersion: dep.version,
341
- location: "catalog"
342
- });
343
- }
344
- for (const dep of mergeResult.bumped) {
345
- results.push({
346
- package: dep.name,
347
- action: "version-bumped",
348
- oldVersion: dep.oldVersion,
349
- newVersion: dep.version,
350
- location: "catalog"
351
- });
352
- }
353
- return results;
354
- }
355
- export async function migrateFromCatalog(rootPath, removeCatalog = false, dryRun = false, interactive = false) {
356
- const results = [];
357
- const rootPackageJson = await readPackageJSON(rootPath);
358
- const catalog = rootPackageJson.workspaces?.catalog || {};
359
- if (Object.keys(catalog).length === 0) {
360
- relinka("warn", "No workspaces.catalog found in root package.json");
361
- return results;
362
- }
363
- relinka("log", `Found catalog with ${Object.keys(catalog).length} entries`);
364
- const workspacePaths = await findWorkspacePackageJsons(rootPath);
365
- if (workspacePaths.length === 0) {
366
- relinka("warn", "No workspace packages found");
367
- return results;
368
- }
369
- const packagesWithCatalogRefs = [];
370
- for (const workspacePath of workspacePaths) {
371
- try {
372
- const packageJsonContent = await fs.readFile(workspacePath, "utf8");
373
- const packageJson = JSON.parse(packageJsonContent);
374
- const catalogRefs = [];
375
- const deps = packageJson.dependencies || {};
376
- for (const [name, version] of Object.entries(deps)) {
377
- if (typeof version === "string" && isCatalogReference(version)) {
378
- catalogRefs.push(name);
379
- }
380
- }
381
- const devDeps = packageJson.devDependencies || {};
382
- for (const [name, version] of Object.entries(devDeps)) {
383
- if (typeof version === "string" && isCatalogReference(version)) {
384
- catalogRefs.push(name);
385
- }
386
- }
387
- if (catalogRefs.length > 0) {
388
- packagesWithCatalogRefs.push({
389
- path: workspacePath,
390
- catalogRefs: [...new Set(catalogRefs)]
391
- // Remove duplicates
392
- });
393
- }
394
- } catch (error) {
395
- relinka(
396
- "warn",
397
- `Failed to read ${workspacePath}: ${error instanceof Error ? error.message : String(error)}`
398
- );
399
- }
400
- }
401
- if (packagesWithCatalogRefs.length === 0) {
402
- relinka("log", "No catalog references found in workspace packages");
403
- if (removeCatalog && !dryRun) {
404
- const rootPackageJsonPath = path.resolve(rootPath, "package.json");
405
- await removeCatalogFromRoot(rootPackageJsonPath);
406
- relinka("log", "Removed catalog from root package.json");
407
- }
408
- return results;
409
- }
410
- const totalCatalogRefs = packagesWithCatalogRefs.reduce(
411
- (sum, pkg) => sum + pkg.catalogRefs.length,
412
- 0
413
- );
414
- relinka(
415
- "log",
416
- `Found ${totalCatalogRefs} catalog references across ${packagesWithCatalogRefs.length} packages`
417
- );
418
- let packagesToProcess = packagesWithCatalogRefs;
419
- if (interactive && packagesWithCatalogRefs.length > 0) {
420
- const allCatalogRefs = Array.from(
421
- new Set(packagesWithCatalogRefs.flatMap((p) => p.catalogRefs))
422
- );
423
- const selectedPackages = await multiselectPrompt({
424
- title: "Select dependencies to restore from catalog",
425
- options: [
426
- { label: "Restore all catalog references", value: "all" },
427
- { label: "Cancel restoration", value: "cancel" },
428
- ...allCatalogRefs.map((name) => ({
429
- label: `${name} (${catalog[name] || "missing in catalog"})`,
430
- value: name,
431
- disabled: !catalog[name]
432
- }))
433
- ]
434
- });
435
- if (selectedPackages.includes("cancel")) {
436
- relinka("log", "Restoration cancelled");
437
- return results;
438
- }
439
- if (!selectedPackages.includes("all")) {
440
- packagesToProcess = packagesWithCatalogRefs.map((pkg) => ({
441
- ...pkg,
442
- catalogRefs: pkg.catalogRefs.filter((ref) => selectedPackages.includes(ref))
443
- })).filter((pkg) => pkg.catalogRefs.length > 0);
444
- }
445
- }
446
- if (dryRun) {
447
- relinka("log", "Dry run mode - no changes were made");
448
- relinka("log", "Would restore the following catalog references:");
449
- for (const pkg of packagesToProcess) {
450
- relinka("log", ` ${pkg.path}:`);
451
- for (const ref of pkg.catalogRefs) {
452
- const catalogVersion = catalog[ref];
453
- relinka("log", ` ${ref}: catalog: \u2192 ${catalogVersion || "MISSING"}`);
454
- }
455
- }
456
- if (removeCatalog) {
457
- relinka("log", "Would also remove workspaces.catalog from root package.json");
458
- }
459
- return results;
460
- }
461
- for (const pkg of packagesToProcess) {
462
- const restoredCount = await restoreCatalogReferences(pkg.path, catalog);
463
- if (restoredCount > 0) {
464
- relinka("log", `Restored ${restoredCount} catalog references in ${pkg.path}`);
465
- for (const ref of pkg.catalogRefs) {
466
- if (catalog[ref]) {
467
- results.push({
468
- package: ref,
469
- action: "restored-from-catalog",
470
- oldVersion: "catalog:",
471
- newVersion: catalog[ref],
472
- location: "dependencies/devDependencies",
473
- packageJsonPath: pkg.path
474
- });
475
- }
476
- }
477
- }
478
- }
479
- if (removeCatalog) {
480
- const rootPackageJsonPath = path.resolve(rootPath, "package.json");
481
- await removeCatalogFromRoot(rootPackageJsonPath);
482
- relinka("log", "Removed workspaces.catalog from root package.json");
483
- }
484
- return results;
485
- }
486
- export function displayMigrationResults(results) {
487
- if (results.length === 0) {
488
- relinka("log", "No changes were made");
489
- return;
490
- }
491
- const byAction = results.reduce(
492
- (acc, result) => {
493
- if (!acc[result.action]) acc[result.action] = [];
494
- acc[result.action].push(result);
495
- return acc;
496
- },
497
- {}
498
- );
499
- for (const [action, actionResults] of Object.entries(byAction)) {
500
- relinka("log", `
501
- ${action.replace(/-/g, " ")} (${actionResults.length}):`);
502
- for (const result of actionResults) {
503
- let message = ` ${result.package}`;
504
- if (result.oldVersion && result.newVersion) {
505
- message += `: ${result.oldVersion} \u2192 ${result.newVersion}`;
506
- } else if (result.newVersion) {
507
- message += `: ${result.newVersion}`;
508
- }
509
- if (result.packageJsonPath) {
510
- message += ` (${result.packageJsonPath})`;
511
- }
512
- relinka("log", message);
513
- }
514
- }
515
- relinka("success", `Migration completed: ${results.length} changes made`);
516
- relinka("log", "Run your package manager install command to apply the changes");
517
- }
@@ -1,10 +0,0 @@
1
- interface MigrationResult {
2
- file: string;
3
- success: boolean;
4
- message: string;
5
- changes?: string[];
6
- }
7
- export declare function migrateToNodeNext(dryRun?: boolean): Promise<MigrationResult[]>;
8
- export declare function migrateToBundler(dryRun?: boolean): Promise<MigrationResult[]>;
9
- export declare function migrateModuleResolution(target: "nodenext" | "bundler", dryRun?: boolean): Promise<MigrationResult[]>;
10
- export {};