@xylabs/toolchain 7.10.1 → 7.10.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.
@@ -32,28 +32,54 @@ var latestVersions = {
32
32
  yarn: "4.13.0"
33
33
  };
34
34
 
35
+ // src/lib/loadConfig.ts
36
+ import chalk from "chalk";
37
+ import { cosmiconfig } from "cosmiconfig";
38
+ import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
39
+ import deepmerge from "deepmerge";
40
+ var config;
41
+ var rootConfigPath;
42
+ function createExplorer() {
43
+ return cosmiconfig("xy", { cache: true, loaders: { ".ts": TypeScriptLoader() } });
44
+ }
45
+ var loadConfig = async (params) => {
46
+ if (config === void 0) {
47
+ const cosmicConfigResult = await createExplorer().search();
48
+ config = cosmicConfigResult?.config ?? {};
49
+ rootConfigPath = cosmicConfigResult?.filepath;
50
+ const configFilePath = cosmicConfigResult?.filepath;
51
+ if (configFilePath !== void 0) {
52
+ console.log(chalk.green(`Loaded config from ${configFilePath}`));
53
+ if (config.verbose) {
54
+ console.log(chalk.gray(`${JSON.stringify(config, null, 2)}`));
55
+ }
56
+ }
57
+ }
58
+ return deepmerge(config, params ?? {});
59
+ };
60
+
35
61
  // src/lib/runInstall.ts
36
62
  import { spawnSync } from "child_process";
37
- import chalk from "chalk";
63
+ import chalk2 from "chalk";
38
64
  function runInstall(cwd) {
39
65
  const pm = detectPackageManager();
40
- console.log(chalk.gray(`Running ${pm} install...`));
66
+ console.log(chalk2.gray(`Running ${pm} install...`));
41
67
  const result = spawnSync(pm, ["install"], {
42
68
  cwd,
43
69
  stdio: "inherit"
44
70
  });
45
71
  if (result.status !== 0) {
46
- console.warn(chalk.yellow(`${pm} install failed`));
72
+ console.warn(chalk2.yellow(`${pm} install failed`));
47
73
  return false;
48
74
  }
49
- console.log(chalk.green("Dependencies installed"));
75
+ console.log(chalk2.green("Dependencies installed"));
50
76
  return true;
51
77
  }
52
78
 
53
79
  // src/actions/package-lint-deps.ts
54
80
  import { readFileSync, writeFileSync } from "fs";
55
81
  import PATH from "path";
56
- import chalk2 from "chalk";
82
+ import chalk3 from "chalk";
57
83
  import semver from "semver";
58
84
  function readWorkspacePackageJson(cwd, location) {
59
85
  const pkgPath = PATH.resolve(cwd, location, "package.json");
@@ -123,7 +149,7 @@ function fixVersionConsistency(cwd, rootPkg, writeRootPackageJson2, workspaces)
123
149
  if (rootPkg.version !== void 0) {
124
150
  delete rootPkg.version;
125
151
  writeRootPackageJson2(cwd, rootPkg);
126
- console.log(chalk2.green(' \u2714 Fixed: removed "version" from root package.json'));
152
+ console.log(chalk3.green(' \u2714 Fixed: removed "version" from root package.json'));
127
153
  }
128
154
  const versions = [];
129
155
  for (const { location } of workspaces) {
@@ -144,7 +170,7 @@ function fixVersionConsistency(cwd, rootPkg, writeRootPackageJson2, workspaces)
144
170
  if (pkg.version !== highest) {
145
171
  pkg.version = highest;
146
172
  writeWorkspacePackageJson(cwd, location, pkg);
147
- console.log(chalk2.green(` \u2714 Fixed: set version to ${highest} in ${name} (${location})`));
173
+ console.log(chalk3.green(` \u2714 Fixed: set version to ${highest} in ${name} (${location})`));
148
174
  }
149
175
  }
150
176
  }
@@ -199,7 +225,7 @@ function fixInternalDepVersions(cwd, workspaces) {
199
225
  const expected = expectedDepVersion(targetVersion);
200
226
  if (version !== expected) {
201
227
  deps[dep] = expected;
202
- console.log(chalk2.green(` \u2714 Fixed: set ${depField}.${dep} to "${expected}" in ${name} (${location})`));
228
+ console.log(chalk3.green(` \u2714 Fixed: set ${depField}.${dep} to "${expected}" in ${name} (${location})`));
203
229
  modified = true;
204
230
  }
205
231
  }
@@ -247,7 +273,7 @@ function fixWorkspaceProtocol(cwd, workspaces) {
247
273
  if (!workspaceNames.has(dep)) continue;
248
274
  if (!version.startsWith("workspace:")) {
249
275
  deps[dep] = "workspace:~";
250
- console.log(chalk2.green(` \u2714 Fixed: set ${depField}.${dep} to "workspace:~" in ${name} (${location})`));
276
+ console.log(chalk3.green(` \u2714 Fixed: set ${depField}.${dep} to "workspace:~" in ${name} (${location})`));
251
277
  modified = true;
252
278
  }
253
279
  }
@@ -305,7 +331,7 @@ function fixInternalPeerVersions(cwd, workspaces) {
305
331
  const expected = expectedPeerRange(devDeps?.[dep], targetVersion);
306
332
  if (version !== expected) {
307
333
  peerDeps[dep] = expected;
308
- console.log(chalk2.green(` \u2714 Fixed: set peerDependencies.${dep} to "${expected}" in ${name} (${location})`));
334
+ console.log(chalk3.green(` \u2714 Fixed: set peerDependencies.${dep} to "${expected}" in ${name} (${location})`));
309
335
  modified = true;
310
336
  }
311
337
  }
@@ -322,7 +348,7 @@ import {
322
348
  writeFileSync as writeFileSync2
323
349
  } from "fs";
324
350
  import PATH2 from "path";
325
- import chalk3 from "chalk";
351
+ import chalk4 from "chalk";
326
352
  import picomatch from "picomatch";
327
353
  import semver2 from "semver";
328
354
  function emptyResult() {
@@ -388,7 +414,7 @@ function checkRootPrivate(pkg) {
388
414
  function fixRootPrivate(cwd, pkg) {
389
415
  pkg.private = true;
390
416
  writeRootPackageJson(cwd, pkg);
391
- console.log(chalk3.green(' \u2714 Fixed: set "private": true in root package.json'));
417
+ console.log(chalk4.green(' \u2714 Fixed: set "private": true in root package.json'));
392
418
  }
393
419
  function checkNoPublishConfigOnPrivate(pkg) {
394
420
  const result = emptyResult();
@@ -400,7 +426,7 @@ function checkNoPublishConfigOnPrivate(pkg) {
400
426
  function fixNoPublishConfigOnPrivate(cwd, pkg) {
401
427
  delete pkg.publishConfig;
402
428
  writeRootPackageJson(cwd, pkg);
403
- console.log(chalk3.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
429
+ console.log(chalk4.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
404
430
  }
405
431
  function checkNoPackageManagerInWorkspaces(cwd, workspaces) {
406
432
  const result = emptyResult();
@@ -429,7 +455,7 @@ function fixNoPackageManagerInWorkspaces(cwd, _pkg, workspaces) {
429
455
  delete pkg.packageManager;
430
456
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
431
457
  `, "utf8");
432
- console.log(chalk3.green(` \u2714 Fixed: removed packageManager from ${location}/package.json`));
458
+ console.log(chalk4.green(` \u2714 Fixed: removed packageManager from ${location}/package.json`));
433
459
  }
434
460
  } catch {
435
461
  }
@@ -464,7 +490,7 @@ function fixWorkspacesFieldPlacement(cwd, pm, workspaces) {
464
490
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
465
491
  `, "utf8");
466
492
  const label = location === "." ? "root" : location;
467
- console.log(chalk3.green(` \u2714 Fixed: removed workspaces from ${label}/package.json`));
493
+ console.log(chalk4.green(` \u2714 Fixed: removed workspaces from ${label}/package.json`));
468
494
  }
469
495
  } catch {
470
496
  }
@@ -494,22 +520,22 @@ function logResults(label, result, fix) {
494
520
  let errors = 0;
495
521
  let fixed = 0;
496
522
  for (const error of result.errors) {
497
- console.log(chalk3.red(` \u2717 ${error}`));
523
+ console.log(chalk4.red(` \u2717 ${error}`));
498
524
  errors++;
499
525
  }
500
526
  for (const fixable of result.fixable) {
501
527
  if (fix) {
502
528
  fixed++;
503
529
  } else {
504
- console.log(chalk3.red(` \u2717 ${fixable} (fixable)`));
530
+ console.log(chalk4.red(` \u2717 ${fixable} (fixable)`));
505
531
  errors++;
506
532
  }
507
533
  }
508
534
  for (const warning of result.warnings) {
509
- console.log(chalk3.yellow(` \u26A0 ${warning}`));
535
+ console.log(chalk4.yellow(` \u26A0 ${warning}`));
510
536
  }
511
537
  if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
512
- console.log(chalk3.green(` \u2713 ${label}`));
538
+ console.log(chalk4.green(` \u2713 ${label}`));
513
539
  }
514
540
  return { errors, fixed };
515
541
  }
@@ -553,7 +579,7 @@ function fixVoltaOnlyInRoot(cwd, _pkg, workspaces) {
553
579
  delete pkg.volta;
554
580
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
555
581
  `, "utf8");
556
- console.log(chalk3.green(` \u2714 Fixed: removed volta from ${location}/package.json`));
582
+ console.log(chalk4.green(` \u2714 Fixed: removed volta from ${location}/package.json`));
557
583
  }
558
584
  } catch {
559
585
  }
@@ -592,7 +618,7 @@ function fixEnginesOnlyInNonTerminal(cwd, _pkg, workspaces) {
592
618
  delete rootPkg.engines;
593
619
  writeFileSync2(rootPath, `${JSON.stringify(rootPkg, null, 2)}
594
620
  `, "utf8");
595
- console.log(chalk3.green(" \u2714 Fixed: removed engines from root package.json"));
621
+ console.log(chalk4.green(" \u2714 Fixed: removed engines from root package.json"));
596
622
  }
597
623
  const enginesTemplate = resolveEnginesTemplate(cwd, workspaces);
598
624
  for (const { location } of workspaces) {
@@ -605,13 +631,13 @@ function fixEnginesOnlyInNonTerminal(cwd, _pkg, workspaces) {
605
631
  delete pkg.engines;
606
632
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
607
633
  `, "utf8");
608
- console.log(chalk3.green(` \u2714 Fixed: removed engines from ${location}/package.json`));
634
+ console.log(chalk4.green(` \u2714 Fixed: removed engines from ${location}/package.json`));
609
635
  }
610
636
  if (!isTerminalPackage(pkg) && !pkg.engines && enginesTemplate) {
611
637
  pkg.engines = enginesTemplate;
612
638
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
613
639
  `, "utf8");
614
- console.log(chalk3.green(` \u2714 Fixed: added engines to ${location}/package.json`));
640
+ console.log(chalk4.green(` \u2714 Fixed: added engines to ${location}/package.json`));
615
641
  }
616
642
  } catch {
617
643
  }
@@ -672,14 +698,14 @@ function checkVersionsIncludeLts(cwd, workspaces) {
672
698
  }
673
699
  function logSummary(errors, fixed) {
674
700
  if (fixed > 0) {
675
- console.log(chalk3.green(`
701
+ console.log(chalk4.green(`
676
702
  Fixed ${fixed} issue(s)`));
677
703
  }
678
704
  if (errors > 0) {
679
- console.log(chalk3.red(`
705
+ console.log(chalk4.red(`
680
706
  ${errors} error(s) found`));
681
707
  } else if (fixed === 0) {
682
- console.log(chalk3.green("\n All checks passed"));
708
+ console.log(chalk4.green("\n All checks passed"));
683
709
  }
684
710
  }
685
711
  function packageLintMonorepo(fix = false) {
@@ -688,14 +714,14 @@ function packageLintMonorepo(fix = false) {
688
714
  try {
689
715
  pkg = readRootPackageJson(cwd);
690
716
  } catch {
691
- console.error(chalk3.red("Could not read package.json"));
717
+ console.error(chalk4.red("Could not read package.json"));
692
718
  return 1;
693
719
  }
694
720
  if (!isMonorepo(pkg, cwd)) {
695
- console.log(chalk3.gray("Not a monorepo \u2014 skipping repo lint checks"));
721
+ console.log(chalk4.gray("Not a monorepo \u2014 skipping repo lint checks"));
696
722
  return 0;
697
723
  }
698
- console.log(chalk3.green("Repo Lint"));
724
+ console.log(chalk4.green("Repo Lint"));
699
725
  const pm = detectPackageManager();
700
726
  const workspaces = getPackageManager().listWorkspaces();
701
727
  const internalDepCheck = pm === "pnpm" ? {
@@ -707,7 +733,7 @@ function packageLintMonorepo(fix = false) {
707
733
  fix: () => fixInternalDepVersions(cwd, workspaces),
708
734
  label: "Internal deps/devDeps use correct version ranges"
709
735
  };
710
- const checks2 = [
736
+ const checks = [
711
737
  {
712
738
  check: () => checkRootPrivate(pkg),
713
739
  fix: fixRootPrivate,
@@ -759,7 +785,7 @@ function packageLintMonorepo(fix = false) {
759
785
  label: "Internal peerDeps use semver ranges (not workspace: protocol)"
760
786
  }
761
787
  ];
762
- const { errors, fixed } = runChecks(checks2, cwd, pkg, fix);
788
+ const { errors, fixed } = runChecks(checks, cwd, pkg, fix);
763
789
  logSummary(errors, fixed);
764
790
  if (fix && fixed > 0) {
765
791
  runInstall();
@@ -774,7 +800,7 @@ import {
774
800
  writeFileSync as writeFileSync7
775
801
  } from "fs";
776
802
  import PATH7 from "path";
777
- import chalk9 from "chalk";
803
+ import chalk10 from "chalk";
778
804
 
779
805
  // src/actions/packman/convert.ts
780
806
  import {
@@ -784,7 +810,7 @@ import {
784
810
  statSync
785
811
  } from "fs";
786
812
  import PATH6 from "path";
787
- import chalk8 from "chalk";
813
+ import chalk9 from "chalk";
788
814
 
789
815
  // src/actions/packman/convertToPnpm.ts
790
816
  import { spawnSync as spawnSync2 } from "child_process";
@@ -796,7 +822,7 @@ import {
796
822
  writeFileSync as writeFileSync5
797
823
  } from "fs";
798
824
  import PATH4 from "path";
799
- import chalk6 from "chalk";
825
+ import chalk7 from "chalk";
800
826
 
801
827
  // src/actions/packman/rewriteScripts.ts
802
828
  function rewriteYarnToPnpm(script) {
@@ -852,7 +878,7 @@ import {
852
878
  readFileSync as readFileSync3,
853
879
  writeFileSync as writeFileSync3
854
880
  } from "fs";
855
- import chalk4 from "chalk";
881
+ import chalk5 from "chalk";
856
882
  import { globSync } from "glob";
857
883
  var IMPORT_SWAP_MAP = {
858
884
  "yarn-to-pnpm": [
@@ -899,7 +925,7 @@ function rewriteSourceImports(cwd, direction) {
899
925
  }
900
926
  }
901
927
  if (count > 0) {
902
- console.log(chalk4.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
928
+ console.log(chalk5.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
903
929
  }
904
930
  }
905
931
 
@@ -910,7 +936,7 @@ import {
910
936
  writeFileSync as writeFileSync4
911
937
  } from "fs";
912
938
  import PATH3 from "path";
913
- import chalk5 from "chalk";
939
+ import chalk6 from "chalk";
914
940
  var SWAP_MAP = {
915
941
  "yarn-to-pnpm": [
916
942
  ["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
@@ -953,7 +979,7 @@ function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
953
979
  }
954
980
  if (count > 0) {
955
981
  const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
956
- console.log(chalk5.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
982
+ console.log(chalk6.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
957
983
  }
958
984
  }
959
985
 
@@ -965,7 +991,7 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
965
991
  lines.push(` - '${pattern}'`);
966
992
  }
967
993
  writeFileSync5(PATH4.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
968
- console.log(chalk6.green(" Created pnpm-workspace.yaml"));
994
+ console.log(chalk7.green(" Created pnpm-workspace.yaml"));
969
995
  }
970
996
  function readPnpmWorkspacePatterns(cwd) {
971
997
  const wsPath = PATH4.join(cwd, "pnpm-workspace.yaml");
@@ -996,7 +1022,7 @@ function updateRootPackageJson(cwd) {
996
1022
  pkg.packageManager = `pnpm@${PNPM_VERSION}`;
997
1023
  const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
998
1024
  writeFileSync5(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
999
- console.log(chalk6.green(" Updated root package.json"));
1025
+ console.log(chalk7.green(" Updated root package.json"));
1000
1026
  return workspacePatterns;
1001
1027
  }
1002
1028
  function updateGitignore(cwd) {
@@ -1018,7 +1044,7 @@ function updateGitignore(cwd) {
1018
1044
  }
1019
1045
  content = content.replaceAll(/\n{3,}/g, "\n\n");
1020
1046
  writeFileSync5(gitignorePath, content, "utf8");
1021
- console.log(chalk6.green(" Updated .gitignore"));
1047
+ console.log(chalk7.green(" Updated .gitignore"));
1022
1048
  }
1023
1049
  function deleteYarnArtifacts(cwd) {
1024
1050
  const yarnLock = PATH4.join(cwd, "yarn.lock");
@@ -1026,15 +1052,15 @@ function deleteYarnArtifacts(cwd) {
1026
1052
  const yarnDir = PATH4.join(cwd, ".yarn");
1027
1053
  if (existsSync5(yarnLock)) {
1028
1054
  rmSync(yarnLock);
1029
- console.log(chalk6.gray(" Deleted yarn.lock"));
1055
+ console.log(chalk7.gray(" Deleted yarn.lock"));
1030
1056
  }
1031
1057
  if (existsSync5(yarnrc)) {
1032
1058
  rmSync(yarnrc);
1033
- console.log(chalk6.gray(" Deleted .yarnrc.yml"));
1059
+ console.log(chalk7.gray(" Deleted .yarnrc.yml"));
1034
1060
  }
1035
1061
  if (existsSync5(yarnDir)) {
1036
1062
  rmSync(yarnDir, { force: true, recursive: true });
1037
- console.log(chalk6.gray(" Deleted .yarn/"));
1063
+ console.log(chalk7.gray(" Deleted .yarn/"));
1038
1064
  }
1039
1065
  }
1040
1066
  function createNpmrc(cwd) {
@@ -1042,10 +1068,10 @@ function createNpmrc(cwd) {
1042
1068
  if (existsSync5(npmrcPath)) return;
1043
1069
  mkdirSync(PATH4.dirname(npmrcPath), { recursive: true });
1044
1070
  writeFileSync5(npmrcPath, "", "utf8");
1045
- console.log(chalk6.green(" Created .npmrc"));
1071
+ console.log(chalk7.green(" Created .npmrc"));
1046
1072
  }
1047
1073
  function convertToPnpm(cwd, workspacePackageJsonPaths) {
1048
- console.log(chalk6.blue("\nConverting to pnpm...\n"));
1074
+ console.log(chalk7.blue("\nConverting to pnpm...\n"));
1049
1075
  const workspacePatterns = updateRootPackageJson(cwd);
1050
1076
  createPnpmWorkspaceYaml(cwd, workspacePatterns);
1051
1077
  for (const pkgPath of workspacePackageJsonPaths) {
@@ -1057,13 +1083,13 @@ function convertToPnpm(cwd, workspacePackageJsonPaths) {
1057
1083
  writeFileSync5(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
1058
1084
  }
1059
1085
  }
1060
- console.log(chalk6.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1086
+ console.log(chalk7.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1061
1087
  updateGitignore(cwd);
1062
1088
  createNpmrc(cwd);
1063
1089
  swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
1064
1090
  rewriteSourceImports(cwd, "yarn-to-pnpm");
1065
1091
  deleteYarnArtifacts(cwd);
1066
- console.log(chalk6.blue("\nRunning pnpm install..."));
1092
+ console.log(chalk7.blue("\nRunning pnpm install..."));
1067
1093
  const install = spawnSync2("pnpm", ["install"], {
1068
1094
  cwd,
1069
1095
  encoding: "utf8",
@@ -1071,10 +1097,10 @@ function convertToPnpm(cwd, workspacePackageJsonPaths) {
1071
1097
  stdio: "inherit"
1072
1098
  });
1073
1099
  if (install.status !== 0) {
1074
- console.error(chalk6.red("pnpm install failed"));
1100
+ console.error(chalk7.red("pnpm install failed"));
1075
1101
  return 1;
1076
1102
  }
1077
- console.log(chalk6.blue("\nConversion complete.\n"));
1103
+ console.log(chalk7.blue("\nConversion complete.\n"));
1078
1104
  return 0;
1079
1105
  }
1080
1106
 
@@ -1087,7 +1113,7 @@ import {
1087
1113
  writeFileSync as writeFileSync6
1088
1114
  } from "fs";
1089
1115
  import PATH5 from "path";
1090
- import chalk7 from "chalk";
1116
+ import chalk8 from "chalk";
1091
1117
  var YARN_VERSION = "4.13.0";
1092
1118
  var YARNRC_TEMPLATE = `compressionLevel: mixed
1093
1119
 
@@ -1136,7 +1162,7 @@ function updateRootPackageJson2(cwd, workspacePatterns) {
1136
1162
  pkg.packageManager = `yarn@${YARN_VERSION}`;
1137
1163
  const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
1138
1164
  writeFileSync6(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
1139
- console.log(chalk7.green(" Updated root package.json"));
1165
+ console.log(chalk8.green(" Updated root package.json"));
1140
1166
  }
1141
1167
  function updateGitignore2(cwd) {
1142
1168
  const gitignorePath = PATH5.join(cwd, ".gitignore");
@@ -1145,7 +1171,7 @@ function updateGitignore2(cwd) {
1145
1171
  content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
1146
1172
  }
1147
1173
  writeFileSync6(gitignorePath, content, "utf8");
1148
- console.log(chalk7.green(" Updated .gitignore"));
1174
+ console.log(chalk8.green(" Updated .gitignore"));
1149
1175
  }
1150
1176
  function deletePnpmArtifacts(cwd) {
1151
1177
  const lockfile = PATH5.join(cwd, "pnpm-lock.yaml");
@@ -1153,17 +1179,17 @@ function deletePnpmArtifacts(cwd) {
1153
1179
  const npmrc = PATH5.join(cwd, ".npmrc");
1154
1180
  if (existsSync6(lockfile)) {
1155
1181
  rmSync2(lockfile);
1156
- console.log(chalk7.gray(" Deleted pnpm-lock.yaml"));
1182
+ console.log(chalk8.gray(" Deleted pnpm-lock.yaml"));
1157
1183
  }
1158
1184
  if (existsSync6(workspaceYaml)) {
1159
1185
  rmSync2(workspaceYaml);
1160
- console.log(chalk7.gray(" Deleted pnpm-workspace.yaml"));
1186
+ console.log(chalk8.gray(" Deleted pnpm-workspace.yaml"));
1161
1187
  }
1162
1188
  if (existsSync6(npmrc)) {
1163
1189
  const content = readFileSync6(npmrc, "utf8");
1164
1190
  if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
1165
1191
  rmSync2(npmrc);
1166
- console.log(chalk7.gray(" Deleted .npmrc"));
1192
+ console.log(chalk8.gray(" Deleted .npmrc"));
1167
1193
  }
1168
1194
  }
1169
1195
  }
@@ -1171,7 +1197,7 @@ function createYarnrc(cwd) {
1171
1197
  const yarnrcPath = PATH5.join(cwd, ".yarnrc.yml");
1172
1198
  if (existsSync6(yarnrcPath)) return;
1173
1199
  writeFileSync6(yarnrcPath, YARNRC_TEMPLATE, "utf8");
1174
- console.log(chalk7.green(" Created .yarnrc.yml"));
1200
+ console.log(chalk8.green(" Created .yarnrc.yml"));
1175
1201
  }
1176
1202
  function readWorkspacePatternsFromPackageJson(cwd) {
1177
1203
  const pkgPath = PATH5.join(cwd, "package.json");
@@ -1180,14 +1206,14 @@ function readWorkspacePatternsFromPackageJson(cwd) {
1180
1206
  return pkg.workspaces ?? [];
1181
1207
  }
1182
1208
  function convertToYarn(cwd, workspacePackageJsonPaths) {
1183
- console.log(chalk7.blue("\nConverting to yarn...\n"));
1209
+ console.log(chalk8.blue("\nConverting to yarn...\n"));
1184
1210
  const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
1185
1211
  if (workspacePatterns.length === 0) {
1186
1212
  const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
1187
1213
  if (fromPkg.length > 0) {
1188
1214
  workspacePatterns.push(...fromPkg);
1189
1215
  } else {
1190
- console.warn(chalk7.yellow(" No workspace patterns found"));
1216
+ console.warn(chalk8.yellow(" No workspace patterns found"));
1191
1217
  }
1192
1218
  }
1193
1219
  updateRootPackageJson2(cwd, workspacePatterns);
@@ -1200,13 +1226,13 @@ function convertToYarn(cwd, workspacePackageJsonPaths) {
1200
1226
  writeFileSync6(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
1201
1227
  }
1202
1228
  }
1203
- console.log(chalk7.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1229
+ console.log(chalk8.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1204
1230
  updateGitignore2(cwd);
1205
1231
  createYarnrc(cwd);
1206
1232
  swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
1207
1233
  rewriteSourceImports(cwd, "pnpm-to-yarn");
1208
1234
  deletePnpmArtifacts(cwd);
1209
- console.log(chalk7.blue("\nRunning yarn install..."));
1235
+ console.log(chalk8.blue("\nRunning yarn install..."));
1210
1236
  const install = spawnSync3("yarn", ["install"], {
1211
1237
  cwd,
1212
1238
  encoding: "utf8",
@@ -1214,10 +1240,10 @@ function convertToYarn(cwd, workspacePackageJsonPaths) {
1214
1240
  stdio: "inherit"
1215
1241
  });
1216
1242
  if (install.status !== 0) {
1217
- console.error(chalk7.red("yarn install failed"));
1243
+ console.error(chalk8.red("yarn install failed"));
1218
1244
  return 1;
1219
1245
  }
1220
- console.log(chalk7.blue("\nConversion complete.\n"));
1246
+ console.log(chalk8.blue("\nConversion complete.\n"));
1221
1247
  return 0;
1222
1248
  }
1223
1249
 
@@ -1304,29 +1330,29 @@ function walkGlob(basePath, parts, currentPath) {
1304
1330
  function convert({ target, verbose }) {
1305
1331
  const validTargets = ["pnpm", "yarn"];
1306
1332
  if (!validTargets.includes(target)) {
1307
- console.error(chalk8.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
1333
+ console.error(chalk9.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
1308
1334
  return 1;
1309
1335
  }
1310
1336
  const cwd = process.cwd();
1311
1337
  const currentPM = detectCurrentPM(cwd);
1312
1338
  if (verbose) {
1313
- console.log(chalk8.gray(`Current package manager: ${currentPM}`));
1314
- console.log(chalk8.gray(`Target package manager: ${target}`));
1339
+ console.log(chalk9.gray(`Current package manager: ${currentPM}`));
1340
+ console.log(chalk9.gray(`Target package manager: ${target}`));
1315
1341
  }
1316
1342
  if (currentPM === target) {
1317
- console.log(chalk8.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
1343
+ console.log(chalk9.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
1318
1344
  }
1319
1345
  if (currentPM === "unknown") {
1320
- console.error(chalk8.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1346
+ console.error(chalk9.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1321
1347
  return 1;
1322
1348
  }
1323
1349
  const workspacePaths = findWorkspacePackagePaths(cwd);
1324
1350
  if (verbose) {
1325
- console.log(chalk8.gray(`Found ${workspacePaths.length} workspace packages`));
1351
+ console.log(chalk9.gray(`Found ${workspacePaths.length} workspace packages`));
1326
1352
  }
1327
1353
  const result = target === "pnpm" ? convertToPnpm(cwd, workspacePaths) : convertToYarn(cwd, workspacePaths);
1328
1354
  if (result !== 0) return result;
1329
- console.log(chalk8.green("\nRunning repo lint --fix..."));
1355
+ console.log(chalk9.green("\nRunning repo lint --fix..."));
1330
1356
  packageLintMonorepo(true);
1331
1357
  return result;
1332
1358
  }
@@ -1335,7 +1361,7 @@ function convert({ target, verbose }) {
1335
1361
  function removeNodeModules(dir, verbose) {
1336
1362
  const nmPath = PATH7.join(dir, "node_modules");
1337
1363
  if (existsSync8(nmPath)) {
1338
- if (verbose) console.log(chalk9.gray(`Removing ${nmPath}`));
1364
+ if (verbose) console.log(chalk10.gray(`Removing ${nmPath}`));
1339
1365
  rmSync3(nmPath, { force: true, recursive: true });
1340
1366
  return true;
1341
1367
  }
@@ -1345,10 +1371,10 @@ function packmanClean({ verbose }) {
1345
1371
  const cwd = process.cwd();
1346
1372
  const pm = detectCurrentPM(cwd);
1347
1373
  if (pm === "unknown") {
1348
- console.error(chalk9.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1374
+ console.error(chalk10.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1349
1375
  return 1;
1350
1376
  }
1351
- console.log(chalk9.blue(`Detected package manager: ${pm}`));
1377
+ console.log(chalk10.blue(`Detected package manager: ${pm}`));
1352
1378
  let removedCount = 0;
1353
1379
  if (removeNodeModules(cwd, verbose)) removedCount++;
1354
1380
  const workspacePaths = findWorkspacePackagePaths(cwd);
@@ -1356,21 +1382,21 @@ function packmanClean({ verbose }) {
1356
1382
  const fullPath = PATH7.join(cwd, wsPath);
1357
1383
  if (removeNodeModules(fullPath, verbose)) removedCount++;
1358
1384
  }
1359
- console.log(chalk9.green(`Removed ${removedCount} node_modules folder${removedCount === 1 ? "" : "s"}`));
1385
+ console.log(chalk10.green(`Removed ${removedCount} node_modules folder${removedCount === 1 ? "" : "s"}`));
1360
1386
  if (pm === "yarn") {
1361
1387
  const lockPath = PATH7.join(cwd, "yarn.lock");
1362
1388
  if (existsSync8(lockPath)) {
1363
1389
  writeFileSync7(lockPath, "");
1364
- console.log(chalk9.green("Truncated yarn.lock"));
1390
+ console.log(chalk10.green("Truncated yarn.lock"));
1365
1391
  }
1366
1392
  } else if (pm === "pnpm") {
1367
1393
  const lockPath = PATH7.join(cwd, "pnpm-lock.yaml");
1368
1394
  if (existsSync8(lockPath)) {
1369
1395
  rmSync3(lockPath);
1370
- console.log(chalk9.green("Deleted pnpm-lock.yaml"));
1396
+ console.log(chalk10.green("Deleted pnpm-lock.yaml"));
1371
1397
  }
1372
1398
  }
1373
- console.log(chalk9.green("Ready for a clean install"));
1399
+ console.log(chalk10.green("Ready for a clean install"));
1374
1400
  return 0;
1375
1401
  }
1376
1402
 
@@ -1381,36 +1407,67 @@ import {
1381
1407
  writeFileSync as writeFileSync8
1382
1408
  } from "fs";
1383
1409
  import PATH8 from "path";
1384
- import chalk10 from "chalk";
1410
+ import chalk11 from "chalk";
1411
+ var DEFAULT_MINIMUM_RELEASE_AGE = 4320;
1412
+ var DEFAULT_RELEASE_AGE_EXCLUDES = ["'@xylabs/*'", "'@xyo-network/*'"];
1413
+ function resolvePackmanConfig(cfg) {
1414
+ return {
1415
+ minimumReleaseAge: cfg?.minimumReleaseAge ?? DEFAULT_MINIMUM_RELEASE_AGE,
1416
+ minimumReleaseAgeExclude: cfg?.minimumReleaseAgeExclude ?? DEFAULT_RELEASE_AGE_EXCLUDES
1417
+ };
1418
+ }
1419
+ function readPnpmWorkspaceYaml(cwd) {
1420
+ const wsPath = PATH8.join(cwd, "pnpm-workspace.yaml");
1421
+ if (!existsSync9(wsPath)) return void 0;
1422
+ return readFileSync8(wsPath, "utf8");
1423
+ }
1424
+ function writePnpmWorkspaceYaml(cwd, content) {
1425
+ writeFileSync8(PATH8.join(cwd, "pnpm-workspace.yaml"), content, "utf8");
1426
+ }
1427
+ function parseYamlListSection(content, sectionName) {
1428
+ const items = [];
1429
+ let inSection = false;
1430
+ for (const line of content.split("\n")) {
1431
+ if (new RegExp(String.raw`^${sectionName}\s*:`).test(line)) {
1432
+ inSection = true;
1433
+ continue;
1434
+ }
1435
+ if (inSection) {
1436
+ const match = /^\s+-\s+(.+)$/.exec(line);
1437
+ if (match) {
1438
+ items.push(match[1].trim());
1439
+ } else if (line.trim() && !/^\s/.test(line)) {
1440
+ break;
1441
+ }
1442
+ }
1443
+ }
1444
+ return items;
1445
+ }
1385
1446
  function checkEnableScripts(cwd, verbose, silent) {
1386
1447
  const yarnrcPath = PATH8.join(cwd, ".yarnrc.yml");
1387
1448
  if (!existsSync9(yarnrcPath)) {
1388
- if (verbose) console.log(chalk10.gray(" No .yarnrc.yml found, skipping enableScripts check"));
1449
+ if (verbose) console.log(chalk11.gray(" No .yarnrc.yml found, skipping enableScripts check"));
1389
1450
  return true;
1390
1451
  }
1391
1452
  const content = readFileSync8(yarnrcPath, "utf8");
1392
- const lines = content.split("\n");
1393
- for (const line of lines) {
1453
+ for (const line of content.split("\n")) {
1394
1454
  const trimmed = line.trim();
1395
1455
  if (/^enableScripts\s*:/.test(trimmed)) {
1396
1456
  const value = trimmed.replace(/^enableScripts\s*:\s*/, "").trim();
1397
1457
  if (value === "false") {
1398
- if (verbose) console.log(chalk10.green(" enableScripts is correctly set to false"));
1458
+ if (verbose) console.log(chalk11.green(" enableScripts is correctly set to false"));
1399
1459
  return true;
1400
1460
  }
1401
- if (!silent) console.log(chalk10.red(" enableScripts is set to", value, "(expected false)"));
1461
+ if (!silent) console.log(chalk11.red(" enableScripts is set to", value, "(expected false)"));
1402
1462
  return false;
1403
1463
  }
1404
1464
  }
1405
- if (!silent) console.log(chalk10.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
1465
+ if (!silent) console.log(chalk11.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
1406
1466
  return false;
1407
1467
  }
1408
- function fixEnableScripts(cwd, verbose) {
1468
+ function fixEnableScripts(cwd) {
1409
1469
  const yarnrcPath = PATH8.join(cwd, ".yarnrc.yml");
1410
- if (!existsSync9(yarnrcPath)) {
1411
- if (verbose) console.log(chalk10.gray(" No .yarnrc.yml found, skipping enableScripts fix"));
1412
- return true;
1413
- }
1470
+ if (!existsSync9(yarnrcPath)) return true;
1414
1471
  const content = readFileSync8(yarnrcPath, "utf8");
1415
1472
  const lines = content.split("\n");
1416
1473
  let found = false;
@@ -1441,41 +1498,142 @@ function fixEnableScripts(cwd, verbose) {
1441
1498
  }
1442
1499
  }
1443
1500
  writeFileSync8(yarnrcPath, newLines.join("\n"), "utf8");
1444
- console.log(chalk10.green(" Fixed: enableScripts set to false"));
1501
+ console.log(chalk11.green(" Fixed: enableScripts set to false"));
1445
1502
  return true;
1446
1503
  }
1447
- var checks = [
1448
- {
1449
- name: "enableScripts should be false in .yarnrc.yml",
1450
- check: checkEnableScripts,
1451
- fix: fixEnableScripts
1504
+ function checkMinimumReleaseAge(cwd, config2, verbose, silent) {
1505
+ if (detectPackageManager() !== "pnpm") return true;
1506
+ const content = readPnpmWorkspaceYaml(cwd);
1507
+ if (!content) {
1508
+ if (!silent) console.log(chalk11.red(" No pnpm-workspace.yaml found"));
1509
+ return false;
1452
1510
  }
1453
- ];
1454
- function packmanLint({ fix, verbose } = {}) {
1511
+ const { minimumReleaseAge } = config2;
1512
+ for (const line of content.split("\n")) {
1513
+ const match = /^minimumReleaseAge\s*:\s*(\d+)/.exec(line.trim());
1514
+ if (match) {
1515
+ const value = Number.parseInt(match[1], 10);
1516
+ if (value >= minimumReleaseAge) {
1517
+ if (verbose) console.log(chalk11.green(` minimumReleaseAge is ${value} (>= ${minimumReleaseAge})`));
1518
+ return true;
1519
+ }
1520
+ if (!silent) console.log(chalk11.red(` minimumReleaseAge is ${value} (expected >= ${minimumReleaseAge})`));
1521
+ return false;
1522
+ }
1523
+ }
1524
+ if (!silent) console.log(chalk11.red(` minimumReleaseAge is not set in pnpm-workspace.yaml (expected >= ${minimumReleaseAge})`));
1525
+ return false;
1526
+ }
1527
+ function fixMinimumReleaseAge(cwd, config2) {
1528
+ if (detectPackageManager() !== "pnpm") return true;
1529
+ const content = readPnpmWorkspaceYaml(cwd);
1530
+ if (!content) return false;
1531
+ const { minimumReleaseAge } = config2;
1532
+ const lines = content.split("\n");
1533
+ let found = false;
1534
+ const newLines = lines.map((line) => {
1535
+ if (/^minimumReleaseAge\s*:/.test(line)) {
1536
+ found = true;
1537
+ return `minimumReleaseAge: ${minimumReleaseAge}`;
1538
+ }
1539
+ return line;
1540
+ });
1541
+ if (!found) {
1542
+ const lastLine = newLines.at(-1);
1543
+ if (lastLine === "") {
1544
+ newLines.splice(-1, 0, `minimumReleaseAge: ${minimumReleaseAge}`);
1545
+ } else {
1546
+ newLines.push(`minimumReleaseAge: ${minimumReleaseAge}`);
1547
+ }
1548
+ }
1549
+ writePnpmWorkspaceYaml(cwd, newLines.join("\n"));
1550
+ console.log(chalk11.green(` Fixed: minimumReleaseAge set to ${minimumReleaseAge}`));
1551
+ return true;
1552
+ }
1553
+ function checkMinimumReleaseAgeExclude(cwd, config2, verbose, silent) {
1554
+ if (detectPackageManager() !== "pnpm") return true;
1555
+ const content = readPnpmWorkspaceYaml(cwd);
1556
+ if (!content) {
1557
+ if (!silent) console.log(chalk11.red(" No pnpm-workspace.yaml found"));
1558
+ return false;
1559
+ }
1560
+ const excludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
1561
+ const missing = config2.minimumReleaseAgeExclude.filter((scope) => !excludes.includes(scope));
1562
+ if (missing.length === 0) {
1563
+ if (verbose) console.log(chalk11.green(" minimumReleaseAgeExclude includes all required scopes"));
1564
+ return true;
1565
+ }
1566
+ if (!silent) console.log(chalk11.red(` minimumReleaseAgeExclude is missing: ${missing.join(", ")}`));
1567
+ return false;
1568
+ }
1569
+ function fixMinimumReleaseAgeExclude(cwd, config2) {
1570
+ if (detectPackageManager() !== "pnpm") return true;
1571
+ const content = readPnpmWorkspaceYaml(cwd);
1572
+ if (!content) return false;
1573
+ const existingExcludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
1574
+ const toAdd = config2.minimumReleaseAgeExclude.filter((scope) => !existingExcludes.includes(scope));
1575
+ if (toAdd.length === 0) return true;
1576
+ const lines = content.split("\n");
1577
+ const sectionIndex = lines.findIndex((line) => /^minimumReleaseAgeExclude\s*:/.test(line));
1578
+ if (sectionIndex === -1) {
1579
+ const newSection = ["minimumReleaseAgeExclude:", ...config2.minimumReleaseAgeExclude.map((s) => ` - ${s}`)];
1580
+ const lastLine = lines.at(-1);
1581
+ if (lastLine === "") {
1582
+ lines.splice(-1, 0, ...newSection);
1583
+ } else {
1584
+ lines.push(...newSection);
1585
+ }
1586
+ } else {
1587
+ let insertAt = sectionIndex + 1;
1588
+ while (insertAt < lines.length && /^\s+-/.test(lines[insertAt])) {
1589
+ insertAt++;
1590
+ }
1591
+ for (const scope of toAdd) {
1592
+ lines.splice(insertAt, 0, ` - ${scope}`);
1593
+ insertAt++;
1594
+ }
1595
+ }
1596
+ writePnpmWorkspaceYaml(cwd, lines.join("\n"));
1597
+ console.log(chalk11.green(` Fixed: added ${toAdd.join(", ")} to minimumReleaseAgeExclude`));
1598
+ return true;
1599
+ }
1600
+ async function packmanLint({ fix, verbose } = {}) {
1455
1601
  const cwd = process.cwd();
1602
+ const rootConfig = await loadConfig();
1603
+ const packmanConfig = resolvePackmanConfig(rootConfig.commands ? rootConfig.commands.packman : void 0);
1456
1604
  let failures = 0;
1457
- for (const check of checks) {
1458
- if (verbose) console.log(chalk10.gray(`Checking: ${check.name}`));
1459
- const passed = check.check(cwd, verbose, fix);
1460
- if (!passed) {
1461
- if (fix) {
1462
- const fixed = check.fix(cwd, verbose);
1463
- if (!fixed) {
1464
- failures++;
1465
- }
1466
- } else {
1467
- failures++;
1468
- }
1605
+ const enableScriptsPassed = checkEnableScripts(cwd, verbose, fix);
1606
+ if (!enableScriptsPassed) {
1607
+ if (fix) {
1608
+ if (!fixEnableScripts(cwd)) failures++;
1609
+ } else {
1610
+ failures++;
1611
+ }
1612
+ }
1613
+ const agePassed = checkMinimumReleaseAge(cwd, packmanConfig, verbose, fix);
1614
+ if (!agePassed) {
1615
+ if (fix) {
1616
+ if (!fixMinimumReleaseAge(cwd, packmanConfig)) failures++;
1617
+ } else {
1618
+ failures++;
1619
+ }
1620
+ }
1621
+ const excludePassed = checkMinimumReleaseAgeExclude(cwd, packmanConfig, verbose, fix);
1622
+ if (!excludePassed) {
1623
+ if (fix) {
1624
+ if (!fixMinimumReleaseAgeExclude(cwd, packmanConfig)) failures++;
1625
+ } else {
1626
+ failures++;
1469
1627
  }
1470
1628
  }
1471
1629
  if (failures > 0) {
1472
- console.log(chalk10.red(`
1630
+ console.log(chalk11.red(`
1473
1631
  packman lint: ${failures} check(s) failed`));
1474
1632
  if (!fix) {
1475
- console.log(chalk10.yellow("Run with --fix to auto-fix issues"));
1633
+ console.log(chalk11.yellow("Run with --fix to auto-fix issues"));
1476
1634
  }
1477
1635
  } else {
1478
- console.log(chalk10.green("\npackman lint: all checks passed"));
1636
+ console.log(chalk11.green("\npackman lint: all checks passed"));
1479
1637
  }
1480
1638
  return failures > 0 ? 1 : 0;
1481
1639
  }
@@ -1516,8 +1674,8 @@ var lintCommand = {
1516
1674
  type: "boolean"
1517
1675
  });
1518
1676
  },
1519
- handler: (argv) => {
1520
- process.exitCode = packmanLint({
1677
+ handler: async (argv) => {
1678
+ process.exitCode = await packmanLint({
1521
1679
  fix: !!argv.fix,
1522
1680
  verbose: !!argv.verbose
1523
1681
  });