@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.
@@ -6701,7 +6701,7 @@ function packageLintMonorepo(fix2 = false) {
6701
6701
  fix: () => fixInternalDepVersions(cwd6, workspaces),
6702
6702
  label: "Internal deps/devDeps use correct version ranges"
6703
6703
  };
6704
- const checks2 = [
6704
+ const checks = [
6705
6705
  {
6706
6706
  check: () => checkRootPrivate(pkg),
6707
6707
  fix: fixRootPrivate,
@@ -6753,7 +6753,7 @@ function packageLintMonorepo(fix2 = false) {
6753
6753
  label: "Internal peerDeps use semver ranges (not workspace: protocol)"
6754
6754
  }
6755
6755
  ];
6756
- const { errors, fixed } = runChecks(checks2, cwd6, pkg, fix2);
6756
+ const { errors, fixed } = runChecks(checks, cwd6, pkg, fix2);
6757
6757
  logSummary(errors, fixed);
6758
6758
  if (fix2 && fixed > 0) {
6759
6759
  runInstall();
@@ -7376,6 +7376,41 @@ import {
7376
7376
  } from "fs";
7377
7377
  import PATH23 from "path";
7378
7378
  import chalk63 from "chalk";
7379
+ var DEFAULT_MINIMUM_RELEASE_AGE = 4320;
7380
+ var DEFAULT_RELEASE_AGE_EXCLUDES = ["'@xylabs/*'", "'@xyo-network/*'"];
7381
+ function resolvePackmanConfig(cfg) {
7382
+ return {
7383
+ minimumReleaseAge: cfg?.minimumReleaseAge ?? DEFAULT_MINIMUM_RELEASE_AGE,
7384
+ minimumReleaseAgeExclude: cfg?.minimumReleaseAgeExclude ?? DEFAULT_RELEASE_AGE_EXCLUDES
7385
+ };
7386
+ }
7387
+ function readPnpmWorkspaceYaml(cwd6) {
7388
+ const wsPath = PATH23.join(cwd6, "pnpm-workspace.yaml");
7389
+ if (!existsSync21(wsPath)) return void 0;
7390
+ return readFileSync25(wsPath, "utf8");
7391
+ }
7392
+ function writePnpmWorkspaceYaml(cwd6, content) {
7393
+ writeFileSync16(PATH23.join(cwd6, "pnpm-workspace.yaml"), content, "utf8");
7394
+ }
7395
+ function parseYamlListSection(content, sectionName) {
7396
+ const items = [];
7397
+ let inSection = false;
7398
+ for (const line of content.split("\n")) {
7399
+ if (new RegExp(String.raw`^${sectionName}\s*:`).test(line)) {
7400
+ inSection = true;
7401
+ continue;
7402
+ }
7403
+ if (inSection) {
7404
+ const match = /^\s+-\s+(.+)$/.exec(line);
7405
+ if (match) {
7406
+ items.push(match[1].trim());
7407
+ } else if (line.trim() && !/^\s/.test(line)) {
7408
+ break;
7409
+ }
7410
+ }
7411
+ }
7412
+ return items;
7413
+ }
7379
7414
  function checkEnableScripts(cwd6, verbose, silent) {
7380
7415
  const yarnrcPath = PATH23.join(cwd6, ".yarnrc.yml");
7381
7416
  if (!existsSync21(yarnrcPath)) {
@@ -7383,8 +7418,7 @@ function checkEnableScripts(cwd6, verbose, silent) {
7383
7418
  return true;
7384
7419
  }
7385
7420
  const content = readFileSync25(yarnrcPath, "utf8");
7386
- const lines = content.split("\n");
7387
- for (const line of lines) {
7421
+ for (const line of content.split("\n")) {
7388
7422
  const trimmed = line.trim();
7389
7423
  if (/^enableScripts\s*:/.test(trimmed)) {
7390
7424
  const value = trimmed.replace(/^enableScripts\s*:\s*/, "").trim();
@@ -7399,12 +7433,9 @@ function checkEnableScripts(cwd6, verbose, silent) {
7399
7433
  if (!silent) console.log(chalk63.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
7400
7434
  return false;
7401
7435
  }
7402
- function fixEnableScripts(cwd6, verbose) {
7436
+ function fixEnableScripts(cwd6) {
7403
7437
  const yarnrcPath = PATH23.join(cwd6, ".yarnrc.yml");
7404
- if (!existsSync21(yarnrcPath)) {
7405
- if (verbose) console.log(chalk63.gray(" No .yarnrc.yml found, skipping enableScripts fix"));
7406
- return true;
7407
- }
7438
+ if (!existsSync21(yarnrcPath)) return true;
7408
7439
  const content = readFileSync25(yarnrcPath, "utf8");
7409
7440
  const lines = content.split("\n");
7410
7441
  let found = false;
@@ -7438,28 +7469,129 @@ function fixEnableScripts(cwd6, verbose) {
7438
7469
  console.log(chalk63.green(" Fixed: enableScripts set to false"));
7439
7470
  return true;
7440
7471
  }
7441
- var checks = [
7442
- {
7443
- name: "enableScripts should be false in .yarnrc.yml",
7444
- check: checkEnableScripts,
7445
- fix: fixEnableScripts
7472
+ function checkMinimumReleaseAge(cwd6, config2, verbose, silent) {
7473
+ if (detectPackageManager() !== "pnpm") return true;
7474
+ const content = readPnpmWorkspaceYaml(cwd6);
7475
+ if (!content) {
7476
+ if (!silent) console.log(chalk63.red(" No pnpm-workspace.yaml found"));
7477
+ return false;
7446
7478
  }
7447
- ];
7448
- function packmanLint({ fix: fix2, verbose } = {}) {
7479
+ const { minimumReleaseAge } = config2;
7480
+ for (const line of content.split("\n")) {
7481
+ const match = /^minimumReleaseAge\s*:\s*(\d+)/.exec(line.trim());
7482
+ if (match) {
7483
+ const value = Number.parseInt(match[1], 10);
7484
+ if (value >= minimumReleaseAge) {
7485
+ if (verbose) console.log(chalk63.green(` minimumReleaseAge is ${value} (>= ${minimumReleaseAge})`));
7486
+ return true;
7487
+ }
7488
+ if (!silent) console.log(chalk63.red(` minimumReleaseAge is ${value} (expected >= ${minimumReleaseAge})`));
7489
+ return false;
7490
+ }
7491
+ }
7492
+ if (!silent) console.log(chalk63.red(` minimumReleaseAge is not set in pnpm-workspace.yaml (expected >= ${minimumReleaseAge})`));
7493
+ return false;
7494
+ }
7495
+ function fixMinimumReleaseAge(cwd6, config2) {
7496
+ if (detectPackageManager() !== "pnpm") return true;
7497
+ const content = readPnpmWorkspaceYaml(cwd6);
7498
+ if (!content) return false;
7499
+ const { minimumReleaseAge } = config2;
7500
+ const lines = content.split("\n");
7501
+ let found = false;
7502
+ const newLines = lines.map((line) => {
7503
+ if (/^minimumReleaseAge\s*:/.test(line)) {
7504
+ found = true;
7505
+ return `minimumReleaseAge: ${minimumReleaseAge}`;
7506
+ }
7507
+ return line;
7508
+ });
7509
+ if (!found) {
7510
+ const lastLine = newLines.at(-1);
7511
+ if (lastLine === "") {
7512
+ newLines.splice(-1, 0, `minimumReleaseAge: ${minimumReleaseAge}`);
7513
+ } else {
7514
+ newLines.push(`minimumReleaseAge: ${minimumReleaseAge}`);
7515
+ }
7516
+ }
7517
+ writePnpmWorkspaceYaml(cwd6, newLines.join("\n"));
7518
+ console.log(chalk63.green(` Fixed: minimumReleaseAge set to ${minimumReleaseAge}`));
7519
+ return true;
7520
+ }
7521
+ function checkMinimumReleaseAgeExclude(cwd6, config2, verbose, silent) {
7522
+ if (detectPackageManager() !== "pnpm") return true;
7523
+ const content = readPnpmWorkspaceYaml(cwd6);
7524
+ if (!content) {
7525
+ if (!silent) console.log(chalk63.red(" No pnpm-workspace.yaml found"));
7526
+ return false;
7527
+ }
7528
+ const excludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
7529
+ const missing = config2.minimumReleaseAgeExclude.filter((scope) => !excludes.includes(scope));
7530
+ if (missing.length === 0) {
7531
+ if (verbose) console.log(chalk63.green(" minimumReleaseAgeExclude includes all required scopes"));
7532
+ return true;
7533
+ }
7534
+ if (!silent) console.log(chalk63.red(` minimumReleaseAgeExclude is missing: ${missing.join(", ")}`));
7535
+ return false;
7536
+ }
7537
+ function fixMinimumReleaseAgeExclude(cwd6, config2) {
7538
+ if (detectPackageManager() !== "pnpm") return true;
7539
+ const content = readPnpmWorkspaceYaml(cwd6);
7540
+ if (!content) return false;
7541
+ const existingExcludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
7542
+ const toAdd = config2.minimumReleaseAgeExclude.filter((scope) => !existingExcludes.includes(scope));
7543
+ if (toAdd.length === 0) return true;
7544
+ const lines = content.split("\n");
7545
+ const sectionIndex = lines.findIndex((line) => /^minimumReleaseAgeExclude\s*:/.test(line));
7546
+ if (sectionIndex === -1) {
7547
+ const newSection = ["minimumReleaseAgeExclude:", ...config2.minimumReleaseAgeExclude.map((s) => ` - ${s}`)];
7548
+ const lastLine = lines.at(-1);
7549
+ if (lastLine === "") {
7550
+ lines.splice(-1, 0, ...newSection);
7551
+ } else {
7552
+ lines.push(...newSection);
7553
+ }
7554
+ } else {
7555
+ let insertAt = sectionIndex + 1;
7556
+ while (insertAt < lines.length && /^\s+-/.test(lines[insertAt])) {
7557
+ insertAt++;
7558
+ }
7559
+ for (const scope of toAdd) {
7560
+ lines.splice(insertAt, 0, ` - ${scope}`);
7561
+ insertAt++;
7562
+ }
7563
+ }
7564
+ writePnpmWorkspaceYaml(cwd6, lines.join("\n"));
7565
+ console.log(chalk63.green(` Fixed: added ${toAdd.join(", ")} to minimumReleaseAgeExclude`));
7566
+ return true;
7567
+ }
7568
+ async function packmanLint({ fix: fix2, verbose } = {}) {
7449
7569
  const cwd6 = process.cwd();
7570
+ const rootConfig = await loadConfig();
7571
+ const packmanConfig = resolvePackmanConfig(rootConfig.commands ? rootConfig.commands.packman : void 0);
7450
7572
  let failures = 0;
7451
- for (const check of checks) {
7452
- if (verbose) console.log(chalk63.gray(`Checking: ${check.name}`));
7453
- const passed = check.check(cwd6, verbose, fix2);
7454
- if (!passed) {
7455
- if (fix2) {
7456
- const fixed = check.fix(cwd6, verbose);
7457
- if (!fixed) {
7458
- failures++;
7459
- }
7460
- } else {
7461
- failures++;
7462
- }
7573
+ const enableScriptsPassed = checkEnableScripts(cwd6, verbose, fix2);
7574
+ if (!enableScriptsPassed) {
7575
+ if (fix2) {
7576
+ if (!fixEnableScripts(cwd6)) failures++;
7577
+ } else {
7578
+ failures++;
7579
+ }
7580
+ }
7581
+ const agePassed = checkMinimumReleaseAge(cwd6, packmanConfig, verbose, fix2);
7582
+ if (!agePassed) {
7583
+ if (fix2) {
7584
+ if (!fixMinimumReleaseAge(cwd6, packmanConfig)) failures++;
7585
+ } else {
7586
+ failures++;
7587
+ }
7588
+ }
7589
+ const excludePassed = checkMinimumReleaseAgeExclude(cwd6, packmanConfig, verbose, fix2);
7590
+ if (!excludePassed) {
7591
+ if (fix2) {
7592
+ if (!fixMinimumReleaseAgeExclude(cwd6, packmanConfig)) failures++;
7593
+ } else {
7594
+ failures++;
7463
7595
  }
7464
7596
  }
7465
7597
  if (failures > 0) {
@@ -7743,14 +7875,14 @@ function lintPackages(cwd6) {
7743
7875
  function readmeLint({ config: config2, verbose }) {
7744
7876
  const cwd6 = INIT_CWD();
7745
7877
  console.log(chalk65.green("Readme Lint"));
7746
- const checks2 = [
7878
+ const checks = [
7747
7879
  lintTemplate(cwd6),
7748
7880
  lintLogoConfig(cwd6, config2),
7749
7881
  lintPackages(cwd6)
7750
7882
  ];
7751
7883
  let errorCount = 0;
7752
7884
  let warningCount = 0;
7753
- for (const { errors, warnings } of checks2) {
7885
+ for (const { errors, warnings } of checks) {
7754
7886
  for (const error of errors) {
7755
7887
  console.log(chalk65.red(` \u2717 ${error}`));
7756
7888
  errorCount++;