@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.
@@ -5,7 +5,7 @@ import {
5
5
  writeFileSync as writeFileSync7
6
6
  } from "fs";
7
7
  import PATH7 from "path";
8
- import chalk9 from "chalk";
8
+ import chalk10 from "chalk";
9
9
 
10
10
  // src/actions/packman/convert.ts
11
11
  import {
@@ -15,7 +15,7 @@ import {
15
15
  statSync
16
16
  } from "fs";
17
17
  import PATH6 from "path";
18
- import chalk8 from "chalk";
18
+ import chalk9 from "chalk";
19
19
 
20
20
  // src/actions/package-lint.ts
21
21
  import {
@@ -24,7 +24,7 @@ import {
24
24
  writeFileSync as writeFileSync2
25
25
  } from "fs";
26
26
  import PATH2 from "path";
27
- import chalk3 from "chalk";
27
+ import chalk4 from "chalk";
28
28
  import picomatch from "picomatch";
29
29
  import semver2 from "semver";
30
30
 
@@ -62,28 +62,54 @@ var latestVersions = {
62
62
  yarn: "4.13.0"
63
63
  };
64
64
 
65
+ // src/lib/loadConfig.ts
66
+ import chalk from "chalk";
67
+ import { cosmiconfig } from "cosmiconfig";
68
+ import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
69
+ import deepmerge from "deepmerge";
70
+ var config;
71
+ var rootConfigPath;
72
+ function createExplorer() {
73
+ return cosmiconfig("xy", { cache: true, loaders: { ".ts": TypeScriptLoader() } });
74
+ }
75
+ var loadConfig = async (params) => {
76
+ if (config === void 0) {
77
+ const cosmicConfigResult = await createExplorer().search();
78
+ config = cosmicConfigResult?.config ?? {};
79
+ rootConfigPath = cosmicConfigResult?.filepath;
80
+ const configFilePath = cosmicConfigResult?.filepath;
81
+ if (configFilePath !== void 0) {
82
+ console.log(chalk.green(`Loaded config from ${configFilePath}`));
83
+ if (config.verbose) {
84
+ console.log(chalk.gray(`${JSON.stringify(config, null, 2)}`));
85
+ }
86
+ }
87
+ }
88
+ return deepmerge(config, params ?? {});
89
+ };
90
+
65
91
  // src/lib/runInstall.ts
66
92
  import { spawnSync } from "child_process";
67
- import chalk from "chalk";
93
+ import chalk2 from "chalk";
68
94
  function runInstall(cwd) {
69
95
  const pm = detectPackageManager();
70
- console.log(chalk.gray(`Running ${pm} install...`));
96
+ console.log(chalk2.gray(`Running ${pm} install...`));
71
97
  const result = spawnSync(pm, ["install"], {
72
98
  cwd,
73
99
  stdio: "inherit"
74
100
  });
75
101
  if (result.status !== 0) {
76
- console.warn(chalk.yellow(`${pm} install failed`));
102
+ console.warn(chalk2.yellow(`${pm} install failed`));
77
103
  return false;
78
104
  }
79
- console.log(chalk.green("Dependencies installed"));
105
+ console.log(chalk2.green("Dependencies installed"));
80
106
  return true;
81
107
  }
82
108
 
83
109
  // src/actions/package-lint-deps.ts
84
110
  import { readFileSync, writeFileSync } from "fs";
85
111
  import PATH from "path";
86
- import chalk2 from "chalk";
112
+ import chalk3 from "chalk";
87
113
  import semver from "semver";
88
114
  function readWorkspacePackageJson(cwd, location) {
89
115
  const pkgPath = PATH.resolve(cwd, location, "package.json");
@@ -153,7 +179,7 @@ function fixVersionConsistency(cwd, rootPkg, writeRootPackageJson2, workspaces)
153
179
  if (rootPkg.version !== void 0) {
154
180
  delete rootPkg.version;
155
181
  writeRootPackageJson2(cwd, rootPkg);
156
- console.log(chalk2.green(' \u2714 Fixed: removed "version" from root package.json'));
182
+ console.log(chalk3.green(' \u2714 Fixed: removed "version" from root package.json'));
157
183
  }
158
184
  const versions = [];
159
185
  for (const { location } of workspaces) {
@@ -174,7 +200,7 @@ function fixVersionConsistency(cwd, rootPkg, writeRootPackageJson2, workspaces)
174
200
  if (pkg.version !== highest) {
175
201
  pkg.version = highest;
176
202
  writeWorkspacePackageJson(cwd, location, pkg);
177
- console.log(chalk2.green(` \u2714 Fixed: set version to ${highest} in ${name} (${location})`));
203
+ console.log(chalk3.green(` \u2714 Fixed: set version to ${highest} in ${name} (${location})`));
178
204
  }
179
205
  }
180
206
  }
@@ -229,7 +255,7 @@ function fixInternalDepVersions(cwd, workspaces) {
229
255
  const expected = expectedDepVersion(targetVersion);
230
256
  if (version !== expected) {
231
257
  deps[dep] = expected;
232
- console.log(chalk2.green(` \u2714 Fixed: set ${depField}.${dep} to "${expected}" in ${name} (${location})`));
258
+ console.log(chalk3.green(` \u2714 Fixed: set ${depField}.${dep} to "${expected}" in ${name} (${location})`));
233
259
  modified = true;
234
260
  }
235
261
  }
@@ -277,7 +303,7 @@ function fixWorkspaceProtocol(cwd, workspaces) {
277
303
  if (!workspaceNames.has(dep)) continue;
278
304
  if (!version.startsWith("workspace:")) {
279
305
  deps[dep] = "workspace:~";
280
- console.log(chalk2.green(` \u2714 Fixed: set ${depField}.${dep} to "workspace:~" in ${name} (${location})`));
306
+ console.log(chalk3.green(` \u2714 Fixed: set ${depField}.${dep} to "workspace:~" in ${name} (${location})`));
281
307
  modified = true;
282
308
  }
283
309
  }
@@ -335,7 +361,7 @@ function fixInternalPeerVersions(cwd, workspaces) {
335
361
  const expected = expectedPeerRange(devDeps?.[dep], targetVersion);
336
362
  if (version !== expected) {
337
363
  peerDeps[dep] = expected;
338
- console.log(chalk2.green(` \u2714 Fixed: set peerDependencies.${dep} to "${expected}" in ${name} (${location})`));
364
+ console.log(chalk3.green(` \u2714 Fixed: set peerDependencies.${dep} to "${expected}" in ${name} (${location})`));
339
365
  modified = true;
340
366
  }
341
367
  }
@@ -409,7 +435,7 @@ function checkRootPrivate(pkg) {
409
435
  function fixRootPrivate(cwd, pkg) {
410
436
  pkg.private = true;
411
437
  writeRootPackageJson(cwd, pkg);
412
- console.log(chalk3.green(' \u2714 Fixed: set "private": true in root package.json'));
438
+ console.log(chalk4.green(' \u2714 Fixed: set "private": true in root package.json'));
413
439
  }
414
440
  function checkNoPublishConfigOnPrivate(pkg) {
415
441
  const result = emptyResult();
@@ -421,7 +447,7 @@ function checkNoPublishConfigOnPrivate(pkg) {
421
447
  function fixNoPublishConfigOnPrivate(cwd, pkg) {
422
448
  delete pkg.publishConfig;
423
449
  writeRootPackageJson(cwd, pkg);
424
- console.log(chalk3.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
450
+ console.log(chalk4.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
425
451
  }
426
452
  function checkNoPackageManagerInWorkspaces(cwd, workspaces) {
427
453
  const result = emptyResult();
@@ -450,7 +476,7 @@ function fixNoPackageManagerInWorkspaces(cwd, _pkg, workspaces) {
450
476
  delete pkg.packageManager;
451
477
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
452
478
  `, "utf8");
453
- console.log(chalk3.green(` \u2714 Fixed: removed packageManager from ${location}/package.json`));
479
+ console.log(chalk4.green(` \u2714 Fixed: removed packageManager from ${location}/package.json`));
454
480
  }
455
481
  } catch {
456
482
  }
@@ -485,7 +511,7 @@ function fixWorkspacesFieldPlacement(cwd, pm, workspaces) {
485
511
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
486
512
  `, "utf8");
487
513
  const label = location === "." ? "root" : location;
488
- console.log(chalk3.green(` \u2714 Fixed: removed workspaces from ${label}/package.json`));
514
+ console.log(chalk4.green(` \u2714 Fixed: removed workspaces from ${label}/package.json`));
489
515
  }
490
516
  } catch {
491
517
  }
@@ -515,22 +541,22 @@ function logResults(label, result, fix) {
515
541
  let errors = 0;
516
542
  let fixed = 0;
517
543
  for (const error of result.errors) {
518
- console.log(chalk3.red(` \u2717 ${error}`));
544
+ console.log(chalk4.red(` \u2717 ${error}`));
519
545
  errors++;
520
546
  }
521
547
  for (const fixable of result.fixable) {
522
548
  if (fix) {
523
549
  fixed++;
524
550
  } else {
525
- console.log(chalk3.red(` \u2717 ${fixable} (fixable)`));
551
+ console.log(chalk4.red(` \u2717 ${fixable} (fixable)`));
526
552
  errors++;
527
553
  }
528
554
  }
529
555
  for (const warning of result.warnings) {
530
- console.log(chalk3.yellow(` \u26A0 ${warning}`));
556
+ console.log(chalk4.yellow(` \u26A0 ${warning}`));
531
557
  }
532
558
  if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
533
- console.log(chalk3.green(` \u2713 ${label}`));
559
+ console.log(chalk4.green(` \u2713 ${label}`));
534
560
  }
535
561
  return { errors, fixed };
536
562
  }
@@ -574,7 +600,7 @@ function fixVoltaOnlyInRoot(cwd, _pkg, workspaces) {
574
600
  delete pkg.volta;
575
601
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
576
602
  `, "utf8");
577
- console.log(chalk3.green(` \u2714 Fixed: removed volta from ${location}/package.json`));
603
+ console.log(chalk4.green(` \u2714 Fixed: removed volta from ${location}/package.json`));
578
604
  }
579
605
  } catch {
580
606
  }
@@ -613,7 +639,7 @@ function fixEnginesOnlyInNonTerminal(cwd, _pkg, workspaces) {
613
639
  delete rootPkg.engines;
614
640
  writeFileSync2(rootPath, `${JSON.stringify(rootPkg, null, 2)}
615
641
  `, "utf8");
616
- console.log(chalk3.green(" \u2714 Fixed: removed engines from root package.json"));
642
+ console.log(chalk4.green(" \u2714 Fixed: removed engines from root package.json"));
617
643
  }
618
644
  const enginesTemplate = resolveEnginesTemplate(cwd, workspaces);
619
645
  for (const { location } of workspaces) {
@@ -626,13 +652,13 @@ function fixEnginesOnlyInNonTerminal(cwd, _pkg, workspaces) {
626
652
  delete pkg.engines;
627
653
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
628
654
  `, "utf8");
629
- console.log(chalk3.green(` \u2714 Fixed: removed engines from ${location}/package.json`));
655
+ console.log(chalk4.green(` \u2714 Fixed: removed engines from ${location}/package.json`));
630
656
  }
631
657
  if (!isTerminalPackage(pkg) && !pkg.engines && enginesTemplate) {
632
658
  pkg.engines = enginesTemplate;
633
659
  writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
634
660
  `, "utf8");
635
- console.log(chalk3.green(` \u2714 Fixed: added engines to ${location}/package.json`));
661
+ console.log(chalk4.green(` \u2714 Fixed: added engines to ${location}/package.json`));
636
662
  }
637
663
  } catch {
638
664
  }
@@ -693,14 +719,14 @@ function checkVersionsIncludeLts(cwd, workspaces) {
693
719
  }
694
720
  function logSummary(errors, fixed) {
695
721
  if (fixed > 0) {
696
- console.log(chalk3.green(`
722
+ console.log(chalk4.green(`
697
723
  Fixed ${fixed} issue(s)`));
698
724
  }
699
725
  if (errors > 0) {
700
- console.log(chalk3.red(`
726
+ console.log(chalk4.red(`
701
727
  ${errors} error(s) found`));
702
728
  } else if (fixed === 0) {
703
- console.log(chalk3.green("\n All checks passed"));
729
+ console.log(chalk4.green("\n All checks passed"));
704
730
  }
705
731
  }
706
732
  function packageLintMonorepo(fix = false) {
@@ -709,14 +735,14 @@ function packageLintMonorepo(fix = false) {
709
735
  try {
710
736
  pkg = readRootPackageJson(cwd);
711
737
  } catch {
712
- console.error(chalk3.red("Could not read package.json"));
738
+ console.error(chalk4.red("Could not read package.json"));
713
739
  return 1;
714
740
  }
715
741
  if (!isMonorepo(pkg, cwd)) {
716
- console.log(chalk3.gray("Not a monorepo \u2014 skipping repo lint checks"));
742
+ console.log(chalk4.gray("Not a monorepo \u2014 skipping repo lint checks"));
717
743
  return 0;
718
744
  }
719
- console.log(chalk3.green("Repo Lint"));
745
+ console.log(chalk4.green("Repo Lint"));
720
746
  const pm = detectPackageManager();
721
747
  const workspaces = getPackageManager().listWorkspaces();
722
748
  const internalDepCheck = pm === "pnpm" ? {
@@ -728,7 +754,7 @@ function packageLintMonorepo(fix = false) {
728
754
  fix: () => fixInternalDepVersions(cwd, workspaces),
729
755
  label: "Internal deps/devDeps use correct version ranges"
730
756
  };
731
- const checks2 = [
757
+ const checks = [
732
758
  {
733
759
  check: () => checkRootPrivate(pkg),
734
760
  fix: fixRootPrivate,
@@ -780,7 +806,7 @@ function packageLintMonorepo(fix = false) {
780
806
  label: "Internal peerDeps use semver ranges (not workspace: protocol)"
781
807
  }
782
808
  ];
783
- const { errors, fixed } = runChecks(checks2, cwd, pkg, fix);
809
+ const { errors, fixed } = runChecks(checks, cwd, pkg, fix);
784
810
  logSummary(errors, fixed);
785
811
  if (fix && fixed > 0) {
786
812
  runInstall();
@@ -798,7 +824,7 @@ import {
798
824
  writeFileSync as writeFileSync5
799
825
  } from "fs";
800
826
  import PATH4 from "path";
801
- import chalk6 from "chalk";
827
+ import chalk7 from "chalk";
802
828
 
803
829
  // src/actions/packman/rewriteScripts.ts
804
830
  function rewriteYarnToPnpm(script) {
@@ -854,7 +880,7 @@ import {
854
880
  readFileSync as readFileSync3,
855
881
  writeFileSync as writeFileSync3
856
882
  } from "fs";
857
- import chalk4 from "chalk";
883
+ import chalk5 from "chalk";
858
884
  import { globSync } from "glob";
859
885
  var IMPORT_SWAP_MAP = {
860
886
  "yarn-to-pnpm": [
@@ -901,7 +927,7 @@ function rewriteSourceImports(cwd, direction) {
901
927
  }
902
928
  }
903
929
  if (count > 0) {
904
- console.log(chalk4.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
930
+ console.log(chalk5.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
905
931
  }
906
932
  }
907
933
 
@@ -912,7 +938,7 @@ import {
912
938
  writeFileSync as writeFileSync4
913
939
  } from "fs";
914
940
  import PATH3 from "path";
915
- import chalk5 from "chalk";
941
+ import chalk6 from "chalk";
916
942
  var SWAP_MAP = {
917
943
  "yarn-to-pnpm": [
918
944
  ["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
@@ -955,7 +981,7 @@ function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
955
981
  }
956
982
  if (count > 0) {
957
983
  const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
958
- console.log(chalk5.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
984
+ console.log(chalk6.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
959
985
  }
960
986
  }
961
987
 
@@ -967,7 +993,7 @@ function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
967
993
  lines.push(` - '${pattern}'`);
968
994
  }
969
995
  writeFileSync5(PATH4.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
970
- console.log(chalk6.green(" Created pnpm-workspace.yaml"));
996
+ console.log(chalk7.green(" Created pnpm-workspace.yaml"));
971
997
  }
972
998
  function readPnpmWorkspacePatterns(cwd) {
973
999
  const wsPath = PATH4.join(cwd, "pnpm-workspace.yaml");
@@ -998,7 +1024,7 @@ function updateRootPackageJson(cwd) {
998
1024
  pkg.packageManager = `pnpm@${PNPM_VERSION}`;
999
1025
  const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
1000
1026
  writeFileSync5(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
1001
- console.log(chalk6.green(" Updated root package.json"));
1027
+ console.log(chalk7.green(" Updated root package.json"));
1002
1028
  return workspacePatterns;
1003
1029
  }
1004
1030
  function updateGitignore(cwd) {
@@ -1020,7 +1046,7 @@ function updateGitignore(cwd) {
1020
1046
  }
1021
1047
  content = content.replaceAll(/\n{3,}/g, "\n\n");
1022
1048
  writeFileSync5(gitignorePath, content, "utf8");
1023
- console.log(chalk6.green(" Updated .gitignore"));
1049
+ console.log(chalk7.green(" Updated .gitignore"));
1024
1050
  }
1025
1051
  function deleteYarnArtifacts(cwd) {
1026
1052
  const yarnLock = PATH4.join(cwd, "yarn.lock");
@@ -1028,15 +1054,15 @@ function deleteYarnArtifacts(cwd) {
1028
1054
  const yarnDir = PATH4.join(cwd, ".yarn");
1029
1055
  if (existsSync5(yarnLock)) {
1030
1056
  rmSync(yarnLock);
1031
- console.log(chalk6.gray(" Deleted yarn.lock"));
1057
+ console.log(chalk7.gray(" Deleted yarn.lock"));
1032
1058
  }
1033
1059
  if (existsSync5(yarnrc)) {
1034
1060
  rmSync(yarnrc);
1035
- console.log(chalk6.gray(" Deleted .yarnrc.yml"));
1061
+ console.log(chalk7.gray(" Deleted .yarnrc.yml"));
1036
1062
  }
1037
1063
  if (existsSync5(yarnDir)) {
1038
1064
  rmSync(yarnDir, { force: true, recursive: true });
1039
- console.log(chalk6.gray(" Deleted .yarn/"));
1065
+ console.log(chalk7.gray(" Deleted .yarn/"));
1040
1066
  }
1041
1067
  }
1042
1068
  function createNpmrc(cwd) {
@@ -1044,10 +1070,10 @@ function createNpmrc(cwd) {
1044
1070
  if (existsSync5(npmrcPath)) return;
1045
1071
  mkdirSync(PATH4.dirname(npmrcPath), { recursive: true });
1046
1072
  writeFileSync5(npmrcPath, "", "utf8");
1047
- console.log(chalk6.green(" Created .npmrc"));
1073
+ console.log(chalk7.green(" Created .npmrc"));
1048
1074
  }
1049
1075
  function convertToPnpm(cwd, workspacePackageJsonPaths) {
1050
- console.log(chalk6.blue("\nConverting to pnpm...\n"));
1076
+ console.log(chalk7.blue("\nConverting to pnpm...\n"));
1051
1077
  const workspacePatterns = updateRootPackageJson(cwd);
1052
1078
  createPnpmWorkspaceYaml(cwd, workspacePatterns);
1053
1079
  for (const pkgPath of workspacePackageJsonPaths) {
@@ -1059,13 +1085,13 @@ function convertToPnpm(cwd, workspacePackageJsonPaths) {
1059
1085
  writeFileSync5(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
1060
1086
  }
1061
1087
  }
1062
- console.log(chalk6.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1088
+ console.log(chalk7.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1063
1089
  updateGitignore(cwd);
1064
1090
  createNpmrc(cwd);
1065
1091
  swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
1066
1092
  rewriteSourceImports(cwd, "yarn-to-pnpm");
1067
1093
  deleteYarnArtifacts(cwd);
1068
- console.log(chalk6.blue("\nRunning pnpm install..."));
1094
+ console.log(chalk7.blue("\nRunning pnpm install..."));
1069
1095
  const install = spawnSync2("pnpm", ["install"], {
1070
1096
  cwd,
1071
1097
  encoding: "utf8",
@@ -1073,10 +1099,10 @@ function convertToPnpm(cwd, workspacePackageJsonPaths) {
1073
1099
  stdio: "inherit"
1074
1100
  });
1075
1101
  if (install.status !== 0) {
1076
- console.error(chalk6.red("pnpm install failed"));
1102
+ console.error(chalk7.red("pnpm install failed"));
1077
1103
  return 1;
1078
1104
  }
1079
- console.log(chalk6.blue("\nConversion complete.\n"));
1105
+ console.log(chalk7.blue("\nConversion complete.\n"));
1080
1106
  return 0;
1081
1107
  }
1082
1108
 
@@ -1089,7 +1115,7 @@ import {
1089
1115
  writeFileSync as writeFileSync6
1090
1116
  } from "fs";
1091
1117
  import PATH5 from "path";
1092
- import chalk7 from "chalk";
1118
+ import chalk8 from "chalk";
1093
1119
  var YARN_VERSION = "4.13.0";
1094
1120
  var YARNRC_TEMPLATE = `compressionLevel: mixed
1095
1121
 
@@ -1138,7 +1164,7 @@ function updateRootPackageJson2(cwd, workspacePatterns) {
1138
1164
  pkg.packageManager = `yarn@${YARN_VERSION}`;
1139
1165
  const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
1140
1166
  writeFileSync6(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
1141
- console.log(chalk7.green(" Updated root package.json"));
1167
+ console.log(chalk8.green(" Updated root package.json"));
1142
1168
  }
1143
1169
  function updateGitignore2(cwd) {
1144
1170
  const gitignorePath = PATH5.join(cwd, ".gitignore");
@@ -1147,7 +1173,7 @@ function updateGitignore2(cwd) {
1147
1173
  content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
1148
1174
  }
1149
1175
  writeFileSync6(gitignorePath, content, "utf8");
1150
- console.log(chalk7.green(" Updated .gitignore"));
1176
+ console.log(chalk8.green(" Updated .gitignore"));
1151
1177
  }
1152
1178
  function deletePnpmArtifacts(cwd) {
1153
1179
  const lockfile = PATH5.join(cwd, "pnpm-lock.yaml");
@@ -1155,17 +1181,17 @@ function deletePnpmArtifacts(cwd) {
1155
1181
  const npmrc = PATH5.join(cwd, ".npmrc");
1156
1182
  if (existsSync6(lockfile)) {
1157
1183
  rmSync2(lockfile);
1158
- console.log(chalk7.gray(" Deleted pnpm-lock.yaml"));
1184
+ console.log(chalk8.gray(" Deleted pnpm-lock.yaml"));
1159
1185
  }
1160
1186
  if (existsSync6(workspaceYaml)) {
1161
1187
  rmSync2(workspaceYaml);
1162
- console.log(chalk7.gray(" Deleted pnpm-workspace.yaml"));
1188
+ console.log(chalk8.gray(" Deleted pnpm-workspace.yaml"));
1163
1189
  }
1164
1190
  if (existsSync6(npmrc)) {
1165
1191
  const content = readFileSync6(npmrc, "utf8");
1166
1192
  if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
1167
1193
  rmSync2(npmrc);
1168
- console.log(chalk7.gray(" Deleted .npmrc"));
1194
+ console.log(chalk8.gray(" Deleted .npmrc"));
1169
1195
  }
1170
1196
  }
1171
1197
  }
@@ -1173,7 +1199,7 @@ function createYarnrc(cwd) {
1173
1199
  const yarnrcPath = PATH5.join(cwd, ".yarnrc.yml");
1174
1200
  if (existsSync6(yarnrcPath)) return;
1175
1201
  writeFileSync6(yarnrcPath, YARNRC_TEMPLATE, "utf8");
1176
- console.log(chalk7.green(" Created .yarnrc.yml"));
1202
+ console.log(chalk8.green(" Created .yarnrc.yml"));
1177
1203
  }
1178
1204
  function readWorkspacePatternsFromPackageJson(cwd) {
1179
1205
  const pkgPath = PATH5.join(cwd, "package.json");
@@ -1182,14 +1208,14 @@ function readWorkspacePatternsFromPackageJson(cwd) {
1182
1208
  return pkg.workspaces ?? [];
1183
1209
  }
1184
1210
  function convertToYarn(cwd, workspacePackageJsonPaths) {
1185
- console.log(chalk7.blue("\nConverting to yarn...\n"));
1211
+ console.log(chalk8.blue("\nConverting to yarn...\n"));
1186
1212
  const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
1187
1213
  if (workspacePatterns.length === 0) {
1188
1214
  const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
1189
1215
  if (fromPkg.length > 0) {
1190
1216
  workspacePatterns.push(...fromPkg);
1191
1217
  } else {
1192
- console.warn(chalk7.yellow(" No workspace patterns found"));
1218
+ console.warn(chalk8.yellow(" No workspace patterns found"));
1193
1219
  }
1194
1220
  }
1195
1221
  updateRootPackageJson2(cwd, workspacePatterns);
@@ -1202,13 +1228,13 @@ function convertToYarn(cwd, workspacePackageJsonPaths) {
1202
1228
  writeFileSync6(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
1203
1229
  }
1204
1230
  }
1205
- console.log(chalk7.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1231
+ console.log(chalk8.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
1206
1232
  updateGitignore2(cwd);
1207
1233
  createYarnrc(cwd);
1208
1234
  swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
1209
1235
  rewriteSourceImports(cwd, "pnpm-to-yarn");
1210
1236
  deletePnpmArtifacts(cwd);
1211
- console.log(chalk7.blue("\nRunning yarn install..."));
1237
+ console.log(chalk8.blue("\nRunning yarn install..."));
1212
1238
  const install = spawnSync3("yarn", ["install"], {
1213
1239
  cwd,
1214
1240
  encoding: "utf8",
@@ -1216,10 +1242,10 @@ function convertToYarn(cwd, workspacePackageJsonPaths) {
1216
1242
  stdio: "inherit"
1217
1243
  });
1218
1244
  if (install.status !== 0) {
1219
- console.error(chalk7.red("yarn install failed"));
1245
+ console.error(chalk8.red("yarn install failed"));
1220
1246
  return 1;
1221
1247
  }
1222
- console.log(chalk7.blue("\nConversion complete.\n"));
1248
+ console.log(chalk8.blue("\nConversion complete.\n"));
1223
1249
  return 0;
1224
1250
  }
1225
1251
 
@@ -1306,29 +1332,29 @@ function walkGlob(basePath, parts, currentPath) {
1306
1332
  function convert({ target, verbose }) {
1307
1333
  const validTargets = ["pnpm", "yarn"];
1308
1334
  if (!validTargets.includes(target)) {
1309
- console.error(chalk8.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
1335
+ console.error(chalk9.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
1310
1336
  return 1;
1311
1337
  }
1312
1338
  const cwd = process.cwd();
1313
1339
  const currentPM = detectCurrentPM(cwd);
1314
1340
  if (verbose) {
1315
- console.log(chalk8.gray(`Current package manager: ${currentPM}`));
1316
- console.log(chalk8.gray(`Target package manager: ${target}`));
1341
+ console.log(chalk9.gray(`Current package manager: ${currentPM}`));
1342
+ console.log(chalk9.gray(`Target package manager: ${target}`));
1317
1343
  }
1318
1344
  if (currentPM === target) {
1319
- console.log(chalk8.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
1345
+ console.log(chalk9.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
1320
1346
  }
1321
1347
  if (currentPM === "unknown") {
1322
- console.error(chalk8.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1348
+ console.error(chalk9.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1323
1349
  return 1;
1324
1350
  }
1325
1351
  const workspacePaths = findWorkspacePackagePaths(cwd);
1326
1352
  if (verbose) {
1327
- console.log(chalk8.gray(`Found ${workspacePaths.length} workspace packages`));
1353
+ console.log(chalk9.gray(`Found ${workspacePaths.length} workspace packages`));
1328
1354
  }
1329
1355
  const result = target === "pnpm" ? convertToPnpm(cwd, workspacePaths) : convertToYarn(cwd, workspacePaths);
1330
1356
  if (result !== 0) return result;
1331
- console.log(chalk8.green("\nRunning repo lint --fix..."));
1357
+ console.log(chalk9.green("\nRunning repo lint --fix..."));
1332
1358
  packageLintMonorepo(true);
1333
1359
  return result;
1334
1360
  }
@@ -1337,7 +1363,7 @@ function convert({ target, verbose }) {
1337
1363
  function removeNodeModules(dir, verbose) {
1338
1364
  const nmPath = PATH7.join(dir, "node_modules");
1339
1365
  if (existsSync8(nmPath)) {
1340
- if (verbose) console.log(chalk9.gray(`Removing ${nmPath}`));
1366
+ if (verbose) console.log(chalk10.gray(`Removing ${nmPath}`));
1341
1367
  rmSync3(nmPath, { force: true, recursive: true });
1342
1368
  return true;
1343
1369
  }
@@ -1347,10 +1373,10 @@ function packmanClean({ verbose }) {
1347
1373
  const cwd = process.cwd();
1348
1374
  const pm = detectCurrentPM(cwd);
1349
1375
  if (pm === "unknown") {
1350
- console.error(chalk9.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1376
+ console.error(chalk10.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
1351
1377
  return 1;
1352
1378
  }
1353
- console.log(chalk9.blue(`Detected package manager: ${pm}`));
1379
+ console.log(chalk10.blue(`Detected package manager: ${pm}`));
1354
1380
  let removedCount = 0;
1355
1381
  if (removeNodeModules(cwd, verbose)) removedCount++;
1356
1382
  const workspacePaths = findWorkspacePackagePaths(cwd);
@@ -1358,21 +1384,21 @@ function packmanClean({ verbose }) {
1358
1384
  const fullPath = PATH7.join(cwd, wsPath);
1359
1385
  if (removeNodeModules(fullPath, verbose)) removedCount++;
1360
1386
  }
1361
- console.log(chalk9.green(`Removed ${removedCount} node_modules folder${removedCount === 1 ? "" : "s"}`));
1387
+ console.log(chalk10.green(`Removed ${removedCount} node_modules folder${removedCount === 1 ? "" : "s"}`));
1362
1388
  if (pm === "yarn") {
1363
1389
  const lockPath = PATH7.join(cwd, "yarn.lock");
1364
1390
  if (existsSync8(lockPath)) {
1365
1391
  writeFileSync7(lockPath, "");
1366
- console.log(chalk9.green("Truncated yarn.lock"));
1392
+ console.log(chalk10.green("Truncated yarn.lock"));
1367
1393
  }
1368
1394
  } else if (pm === "pnpm") {
1369
1395
  const lockPath = PATH7.join(cwd, "pnpm-lock.yaml");
1370
1396
  if (existsSync8(lockPath)) {
1371
1397
  rmSync3(lockPath);
1372
- console.log(chalk9.green("Deleted pnpm-lock.yaml"));
1398
+ console.log(chalk10.green("Deleted pnpm-lock.yaml"));
1373
1399
  }
1374
1400
  }
1375
- console.log(chalk9.green("Ready for a clean install"));
1401
+ console.log(chalk10.green("Ready for a clean install"));
1376
1402
  return 0;
1377
1403
  }
1378
1404
 
@@ -1383,36 +1409,67 @@ import {
1383
1409
  writeFileSync as writeFileSync8
1384
1410
  } from "fs";
1385
1411
  import PATH8 from "path";
1386
- import chalk10 from "chalk";
1412
+ import chalk11 from "chalk";
1413
+ var DEFAULT_MINIMUM_RELEASE_AGE = 4320;
1414
+ var DEFAULT_RELEASE_AGE_EXCLUDES = ["'@xylabs/*'", "'@xyo-network/*'"];
1415
+ function resolvePackmanConfig(cfg) {
1416
+ return {
1417
+ minimumReleaseAge: cfg?.minimumReleaseAge ?? DEFAULT_MINIMUM_RELEASE_AGE,
1418
+ minimumReleaseAgeExclude: cfg?.minimumReleaseAgeExclude ?? DEFAULT_RELEASE_AGE_EXCLUDES
1419
+ };
1420
+ }
1421
+ function readPnpmWorkspaceYaml(cwd) {
1422
+ const wsPath = PATH8.join(cwd, "pnpm-workspace.yaml");
1423
+ if (!existsSync9(wsPath)) return void 0;
1424
+ return readFileSync8(wsPath, "utf8");
1425
+ }
1426
+ function writePnpmWorkspaceYaml(cwd, content) {
1427
+ writeFileSync8(PATH8.join(cwd, "pnpm-workspace.yaml"), content, "utf8");
1428
+ }
1429
+ function parseYamlListSection(content, sectionName) {
1430
+ const items = [];
1431
+ let inSection = false;
1432
+ for (const line of content.split("\n")) {
1433
+ if (new RegExp(String.raw`^${sectionName}\s*:`).test(line)) {
1434
+ inSection = true;
1435
+ continue;
1436
+ }
1437
+ if (inSection) {
1438
+ const match = /^\s+-\s+(.+)$/.exec(line);
1439
+ if (match) {
1440
+ items.push(match[1].trim());
1441
+ } else if (line.trim() && !/^\s/.test(line)) {
1442
+ break;
1443
+ }
1444
+ }
1445
+ }
1446
+ return items;
1447
+ }
1387
1448
  function checkEnableScripts(cwd, verbose, silent) {
1388
1449
  const yarnrcPath = PATH8.join(cwd, ".yarnrc.yml");
1389
1450
  if (!existsSync9(yarnrcPath)) {
1390
- if (verbose) console.log(chalk10.gray(" No .yarnrc.yml found, skipping enableScripts check"));
1451
+ if (verbose) console.log(chalk11.gray(" No .yarnrc.yml found, skipping enableScripts check"));
1391
1452
  return true;
1392
1453
  }
1393
1454
  const content = readFileSync8(yarnrcPath, "utf8");
1394
- const lines = content.split("\n");
1395
- for (const line of lines) {
1455
+ for (const line of content.split("\n")) {
1396
1456
  const trimmed = line.trim();
1397
1457
  if (/^enableScripts\s*:/.test(trimmed)) {
1398
1458
  const value = trimmed.replace(/^enableScripts\s*:\s*/, "").trim();
1399
1459
  if (value === "false") {
1400
- if (verbose) console.log(chalk10.green(" enableScripts is correctly set to false"));
1460
+ if (verbose) console.log(chalk11.green(" enableScripts is correctly set to false"));
1401
1461
  return true;
1402
1462
  }
1403
- if (!silent) console.log(chalk10.red(" enableScripts is set to", value, "(expected false)"));
1463
+ if (!silent) console.log(chalk11.red(" enableScripts is set to", value, "(expected false)"));
1404
1464
  return false;
1405
1465
  }
1406
1466
  }
1407
- if (!silent) console.log(chalk10.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
1467
+ if (!silent) console.log(chalk11.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
1408
1468
  return false;
1409
1469
  }
1410
- function fixEnableScripts(cwd, verbose) {
1470
+ function fixEnableScripts(cwd) {
1411
1471
  const yarnrcPath = PATH8.join(cwd, ".yarnrc.yml");
1412
- if (!existsSync9(yarnrcPath)) {
1413
- if (verbose) console.log(chalk10.gray(" No .yarnrc.yml found, skipping enableScripts fix"));
1414
- return true;
1415
- }
1472
+ if (!existsSync9(yarnrcPath)) return true;
1416
1473
  const content = readFileSync8(yarnrcPath, "utf8");
1417
1474
  const lines = content.split("\n");
1418
1475
  let found = false;
@@ -1443,41 +1500,142 @@ function fixEnableScripts(cwd, verbose) {
1443
1500
  }
1444
1501
  }
1445
1502
  writeFileSync8(yarnrcPath, newLines.join("\n"), "utf8");
1446
- console.log(chalk10.green(" Fixed: enableScripts set to false"));
1503
+ console.log(chalk11.green(" Fixed: enableScripts set to false"));
1447
1504
  return true;
1448
1505
  }
1449
- var checks = [
1450
- {
1451
- name: "enableScripts should be false in .yarnrc.yml",
1452
- check: checkEnableScripts,
1453
- fix: fixEnableScripts
1506
+ function checkMinimumReleaseAge(cwd, config2, verbose, silent) {
1507
+ if (detectPackageManager() !== "pnpm") return true;
1508
+ const content = readPnpmWorkspaceYaml(cwd);
1509
+ if (!content) {
1510
+ if (!silent) console.log(chalk11.red(" No pnpm-workspace.yaml found"));
1511
+ return false;
1454
1512
  }
1455
- ];
1456
- function packmanLint({ fix, verbose } = {}) {
1513
+ const { minimumReleaseAge } = config2;
1514
+ for (const line of content.split("\n")) {
1515
+ const match = /^minimumReleaseAge\s*:\s*(\d+)/.exec(line.trim());
1516
+ if (match) {
1517
+ const value = Number.parseInt(match[1], 10);
1518
+ if (value >= minimumReleaseAge) {
1519
+ if (verbose) console.log(chalk11.green(` minimumReleaseAge is ${value} (>= ${minimumReleaseAge})`));
1520
+ return true;
1521
+ }
1522
+ if (!silent) console.log(chalk11.red(` minimumReleaseAge is ${value} (expected >= ${minimumReleaseAge})`));
1523
+ return false;
1524
+ }
1525
+ }
1526
+ if (!silent) console.log(chalk11.red(` minimumReleaseAge is not set in pnpm-workspace.yaml (expected >= ${minimumReleaseAge})`));
1527
+ return false;
1528
+ }
1529
+ function fixMinimumReleaseAge(cwd, config2) {
1530
+ if (detectPackageManager() !== "pnpm") return true;
1531
+ const content = readPnpmWorkspaceYaml(cwd);
1532
+ if (!content) return false;
1533
+ const { minimumReleaseAge } = config2;
1534
+ const lines = content.split("\n");
1535
+ let found = false;
1536
+ const newLines = lines.map((line) => {
1537
+ if (/^minimumReleaseAge\s*:/.test(line)) {
1538
+ found = true;
1539
+ return `minimumReleaseAge: ${minimumReleaseAge}`;
1540
+ }
1541
+ return line;
1542
+ });
1543
+ if (!found) {
1544
+ const lastLine = newLines.at(-1);
1545
+ if (lastLine === "") {
1546
+ newLines.splice(-1, 0, `minimumReleaseAge: ${minimumReleaseAge}`);
1547
+ } else {
1548
+ newLines.push(`minimumReleaseAge: ${minimumReleaseAge}`);
1549
+ }
1550
+ }
1551
+ writePnpmWorkspaceYaml(cwd, newLines.join("\n"));
1552
+ console.log(chalk11.green(` Fixed: minimumReleaseAge set to ${minimumReleaseAge}`));
1553
+ return true;
1554
+ }
1555
+ function checkMinimumReleaseAgeExclude(cwd, config2, verbose, silent) {
1556
+ if (detectPackageManager() !== "pnpm") return true;
1557
+ const content = readPnpmWorkspaceYaml(cwd);
1558
+ if (!content) {
1559
+ if (!silent) console.log(chalk11.red(" No pnpm-workspace.yaml found"));
1560
+ return false;
1561
+ }
1562
+ const excludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
1563
+ const missing = config2.minimumReleaseAgeExclude.filter((scope) => !excludes.includes(scope));
1564
+ if (missing.length === 0) {
1565
+ if (verbose) console.log(chalk11.green(" minimumReleaseAgeExclude includes all required scopes"));
1566
+ return true;
1567
+ }
1568
+ if (!silent) console.log(chalk11.red(` minimumReleaseAgeExclude is missing: ${missing.join(", ")}`));
1569
+ return false;
1570
+ }
1571
+ function fixMinimumReleaseAgeExclude(cwd, config2) {
1572
+ if (detectPackageManager() !== "pnpm") return true;
1573
+ const content = readPnpmWorkspaceYaml(cwd);
1574
+ if (!content) return false;
1575
+ const existingExcludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
1576
+ const toAdd = config2.minimumReleaseAgeExclude.filter((scope) => !existingExcludes.includes(scope));
1577
+ if (toAdd.length === 0) return true;
1578
+ const lines = content.split("\n");
1579
+ const sectionIndex = lines.findIndex((line) => /^minimumReleaseAgeExclude\s*:/.test(line));
1580
+ if (sectionIndex === -1) {
1581
+ const newSection = ["minimumReleaseAgeExclude:", ...config2.minimumReleaseAgeExclude.map((s) => ` - ${s}`)];
1582
+ const lastLine = lines.at(-1);
1583
+ if (lastLine === "") {
1584
+ lines.splice(-1, 0, ...newSection);
1585
+ } else {
1586
+ lines.push(...newSection);
1587
+ }
1588
+ } else {
1589
+ let insertAt = sectionIndex + 1;
1590
+ while (insertAt < lines.length && /^\s+-/.test(lines[insertAt])) {
1591
+ insertAt++;
1592
+ }
1593
+ for (const scope of toAdd) {
1594
+ lines.splice(insertAt, 0, ` - ${scope}`);
1595
+ insertAt++;
1596
+ }
1597
+ }
1598
+ writePnpmWorkspaceYaml(cwd, lines.join("\n"));
1599
+ console.log(chalk11.green(` Fixed: added ${toAdd.join(", ")} to minimumReleaseAgeExclude`));
1600
+ return true;
1601
+ }
1602
+ async function packmanLint({ fix, verbose } = {}) {
1457
1603
  const cwd = process.cwd();
1604
+ const rootConfig = await loadConfig();
1605
+ const packmanConfig = resolvePackmanConfig(rootConfig.commands ? rootConfig.commands.packman : void 0);
1458
1606
  let failures = 0;
1459
- for (const check of checks) {
1460
- if (verbose) console.log(chalk10.gray(`Checking: ${check.name}`));
1461
- const passed = check.check(cwd, verbose, fix);
1462
- if (!passed) {
1463
- if (fix) {
1464
- const fixed = check.fix(cwd, verbose);
1465
- if (!fixed) {
1466
- failures++;
1467
- }
1468
- } else {
1469
- failures++;
1470
- }
1607
+ const enableScriptsPassed = checkEnableScripts(cwd, verbose, fix);
1608
+ if (!enableScriptsPassed) {
1609
+ if (fix) {
1610
+ if (!fixEnableScripts(cwd)) failures++;
1611
+ } else {
1612
+ failures++;
1613
+ }
1614
+ }
1615
+ const agePassed = checkMinimumReleaseAge(cwd, packmanConfig, verbose, fix);
1616
+ if (!agePassed) {
1617
+ if (fix) {
1618
+ if (!fixMinimumReleaseAge(cwd, packmanConfig)) failures++;
1619
+ } else {
1620
+ failures++;
1621
+ }
1622
+ }
1623
+ const excludePassed = checkMinimumReleaseAgeExclude(cwd, packmanConfig, verbose, fix);
1624
+ if (!excludePassed) {
1625
+ if (fix) {
1626
+ if (!fixMinimumReleaseAgeExclude(cwd, packmanConfig)) failures++;
1627
+ } else {
1628
+ failures++;
1471
1629
  }
1472
1630
  }
1473
1631
  if (failures > 0) {
1474
- console.log(chalk10.red(`
1632
+ console.log(chalk11.red(`
1475
1633
  packman lint: ${failures} check(s) failed`));
1476
1634
  if (!fix) {
1477
- console.log(chalk10.yellow("Run with --fix to auto-fix issues"));
1635
+ console.log(chalk11.yellow("Run with --fix to auto-fix issues"));
1478
1636
  }
1479
1637
  } else {
1480
- console.log(chalk10.green("\npackman lint: all checks passed"));
1638
+ console.log(chalk11.green("\npackman lint: all checks passed"));
1481
1639
  }
1482
1640
  return failures > 0 ? 1 : 0;
1483
1641
  }