@xylabs/toolchain 7.10.0 → 7.10.2

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.
package/dist/bin/xy.mjs CHANGED
@@ -6243,7 +6243,7 @@ function packageLintMonorepo(fix2 = false) {
6243
6243
  fix: () => fixInternalDepVersions(cwd, workspaces),
6244
6244
  label: "Internal deps/devDeps use correct version ranges"
6245
6245
  };
6246
- const checks2 = [
6246
+ const checks = [
6247
6247
  {
6248
6248
  check: () => checkRootPrivate(pkg),
6249
6249
  fix: fixRootPrivate,
@@ -6295,7 +6295,7 @@ function packageLintMonorepo(fix2 = false) {
6295
6295
  label: "Internal peerDeps use semver ranges (not workspace: protocol)"
6296
6296
  }
6297
6297
  ];
6298
- const { errors, fixed } = runChecks(checks2, cwd, pkg, fix2);
6298
+ const { errors, fixed } = runChecks(checks, cwd, pkg, fix2);
6299
6299
  logSummary(errors, fixed);
6300
6300
  if (fix2 && fixed > 0) {
6301
6301
  runInstall();
@@ -6918,6 +6918,41 @@ import {
6918
6918
  } from "fs";
6919
6919
  import PATH25 from "path";
6920
6920
  import chalk53 from "chalk";
6921
+ var DEFAULT_MINIMUM_RELEASE_AGE = 4320;
6922
+ var DEFAULT_RELEASE_AGE_EXCLUDES = ["'@xylabs/*'", "'@xyo-network/*'"];
6923
+ function resolvePackmanConfig(cfg) {
6924
+ return {
6925
+ minimumReleaseAge: cfg?.minimumReleaseAge ?? DEFAULT_MINIMUM_RELEASE_AGE,
6926
+ minimumReleaseAgeExclude: cfg?.minimumReleaseAgeExclude ?? DEFAULT_RELEASE_AGE_EXCLUDES
6927
+ };
6928
+ }
6929
+ function readPnpmWorkspaceYaml(cwd) {
6930
+ const wsPath = PATH25.join(cwd, "pnpm-workspace.yaml");
6931
+ if (!existsSync20(wsPath)) return void 0;
6932
+ return readFileSync27(wsPath, "utf8");
6933
+ }
6934
+ function writePnpmWorkspaceYaml(cwd, content) {
6935
+ writeFileSync16(PATH25.join(cwd, "pnpm-workspace.yaml"), content, "utf8");
6936
+ }
6937
+ function parseYamlListSection(content, sectionName) {
6938
+ const items = [];
6939
+ let inSection = false;
6940
+ for (const line of content.split("\n")) {
6941
+ if (new RegExp(String.raw`^${sectionName}\s*:`).test(line)) {
6942
+ inSection = true;
6943
+ continue;
6944
+ }
6945
+ if (inSection) {
6946
+ const match = /^\s+-\s+(.+)$/.exec(line);
6947
+ if (match) {
6948
+ items.push(match[1].trim());
6949
+ } else if (line.trim() && !/^\s/.test(line)) {
6950
+ break;
6951
+ }
6952
+ }
6953
+ }
6954
+ return items;
6955
+ }
6921
6956
  function checkEnableScripts(cwd, verbose, silent) {
6922
6957
  const yarnrcPath = PATH25.join(cwd, ".yarnrc.yml");
6923
6958
  if (!existsSync20(yarnrcPath)) {
@@ -6925,8 +6960,7 @@ function checkEnableScripts(cwd, verbose, silent) {
6925
6960
  return true;
6926
6961
  }
6927
6962
  const content = readFileSync27(yarnrcPath, "utf8");
6928
- const lines = content.split("\n");
6929
- for (const line of lines) {
6963
+ for (const line of content.split("\n")) {
6930
6964
  const trimmed = line.trim();
6931
6965
  if (/^enableScripts\s*:/.test(trimmed)) {
6932
6966
  const value = trimmed.replace(/^enableScripts\s*:\s*/, "").trim();
@@ -6941,12 +6975,9 @@ function checkEnableScripts(cwd, verbose, silent) {
6941
6975
  if (!silent) console.log(chalk53.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
6942
6976
  return false;
6943
6977
  }
6944
- function fixEnableScripts(cwd, verbose) {
6978
+ function fixEnableScripts(cwd) {
6945
6979
  const yarnrcPath = PATH25.join(cwd, ".yarnrc.yml");
6946
- if (!existsSync20(yarnrcPath)) {
6947
- if (verbose) console.log(chalk53.gray(" No .yarnrc.yml found, skipping enableScripts fix"));
6948
- return true;
6949
- }
6980
+ if (!existsSync20(yarnrcPath)) return true;
6950
6981
  const content = readFileSync27(yarnrcPath, "utf8");
6951
6982
  const lines = content.split("\n");
6952
6983
  let found = false;
@@ -6980,28 +7011,129 @@ function fixEnableScripts(cwd, verbose) {
6980
7011
  console.log(chalk53.green(" Fixed: enableScripts set to false"));
6981
7012
  return true;
6982
7013
  }
6983
- var checks = [
6984
- {
6985
- name: "enableScripts should be false in .yarnrc.yml",
6986
- check: checkEnableScripts,
6987
- fix: fixEnableScripts
7014
+ function checkMinimumReleaseAge(cwd, config2, verbose, silent) {
7015
+ if (detectPackageManager() !== "pnpm") return true;
7016
+ const content = readPnpmWorkspaceYaml(cwd);
7017
+ if (!content) {
7018
+ if (!silent) console.log(chalk53.red(" No pnpm-workspace.yaml found"));
7019
+ return false;
6988
7020
  }
6989
- ];
6990
- function packmanLint({ fix: fix2, verbose } = {}) {
7021
+ const { minimumReleaseAge } = config2;
7022
+ for (const line of content.split("\n")) {
7023
+ const match = /^minimumReleaseAge\s*:\s*(\d+)/.exec(line.trim());
7024
+ if (match) {
7025
+ const value = Number.parseInt(match[1], 10);
7026
+ if (value >= minimumReleaseAge) {
7027
+ if (verbose) console.log(chalk53.green(` minimumReleaseAge is ${value} (>= ${minimumReleaseAge})`));
7028
+ return true;
7029
+ }
7030
+ if (!silent) console.log(chalk53.red(` minimumReleaseAge is ${value} (expected >= ${minimumReleaseAge})`));
7031
+ return false;
7032
+ }
7033
+ }
7034
+ if (!silent) console.log(chalk53.red(` minimumReleaseAge is not set in pnpm-workspace.yaml (expected >= ${minimumReleaseAge})`));
7035
+ return false;
7036
+ }
7037
+ function fixMinimumReleaseAge(cwd, config2) {
7038
+ if (detectPackageManager() !== "pnpm") return true;
7039
+ const content = readPnpmWorkspaceYaml(cwd);
7040
+ if (!content) return false;
7041
+ const { minimumReleaseAge } = config2;
7042
+ const lines = content.split("\n");
7043
+ let found = false;
7044
+ const newLines = lines.map((line) => {
7045
+ if (/^minimumReleaseAge\s*:/.test(line)) {
7046
+ found = true;
7047
+ return `minimumReleaseAge: ${minimumReleaseAge}`;
7048
+ }
7049
+ return line;
7050
+ });
7051
+ if (!found) {
7052
+ const lastLine = newLines.at(-1);
7053
+ if (lastLine === "") {
7054
+ newLines.splice(-1, 0, `minimumReleaseAge: ${minimumReleaseAge}`);
7055
+ } else {
7056
+ newLines.push(`minimumReleaseAge: ${minimumReleaseAge}`);
7057
+ }
7058
+ }
7059
+ writePnpmWorkspaceYaml(cwd, newLines.join("\n"));
7060
+ console.log(chalk53.green(` Fixed: minimumReleaseAge set to ${minimumReleaseAge}`));
7061
+ return true;
7062
+ }
7063
+ function checkMinimumReleaseAgeExclude(cwd, config2, verbose, silent) {
7064
+ if (detectPackageManager() !== "pnpm") return true;
7065
+ const content = readPnpmWorkspaceYaml(cwd);
7066
+ if (!content) {
7067
+ if (!silent) console.log(chalk53.red(" No pnpm-workspace.yaml found"));
7068
+ return false;
7069
+ }
7070
+ const excludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
7071
+ const missing = config2.minimumReleaseAgeExclude.filter((scope) => !excludes.includes(scope));
7072
+ if (missing.length === 0) {
7073
+ if (verbose) console.log(chalk53.green(" minimumReleaseAgeExclude includes all required scopes"));
7074
+ return true;
7075
+ }
7076
+ if (!silent) console.log(chalk53.red(` minimumReleaseAgeExclude is missing: ${missing.join(", ")}`));
7077
+ return false;
7078
+ }
7079
+ function fixMinimumReleaseAgeExclude(cwd, config2) {
7080
+ if (detectPackageManager() !== "pnpm") return true;
7081
+ const content = readPnpmWorkspaceYaml(cwd);
7082
+ if (!content) return false;
7083
+ const existingExcludes = parseYamlListSection(content, "minimumReleaseAgeExclude");
7084
+ const toAdd = config2.minimumReleaseAgeExclude.filter((scope) => !existingExcludes.includes(scope));
7085
+ if (toAdd.length === 0) return true;
7086
+ const lines = content.split("\n");
7087
+ const sectionIndex = lines.findIndex((line) => /^minimumReleaseAgeExclude\s*:/.test(line));
7088
+ if (sectionIndex === -1) {
7089
+ const newSection = ["minimumReleaseAgeExclude:", ...config2.minimumReleaseAgeExclude.map((s) => ` - ${s}`)];
7090
+ const lastLine = lines.at(-1);
7091
+ if (lastLine === "") {
7092
+ lines.splice(-1, 0, ...newSection);
7093
+ } else {
7094
+ lines.push(...newSection);
7095
+ }
7096
+ } else {
7097
+ let insertAt = sectionIndex + 1;
7098
+ while (insertAt < lines.length && /^\s+-/.test(lines[insertAt])) {
7099
+ insertAt++;
7100
+ }
7101
+ for (const scope of toAdd) {
7102
+ lines.splice(insertAt, 0, ` - ${scope}`);
7103
+ insertAt++;
7104
+ }
7105
+ }
7106
+ writePnpmWorkspaceYaml(cwd, lines.join("\n"));
7107
+ console.log(chalk53.green(` Fixed: added ${toAdd.join(", ")} to minimumReleaseAgeExclude`));
7108
+ return true;
7109
+ }
7110
+ async function packmanLint({ fix: fix2, verbose } = {}) {
6991
7111
  const cwd = process.cwd();
7112
+ const rootConfig = await loadConfig();
7113
+ const packmanConfig = resolvePackmanConfig(rootConfig.commands ? rootConfig.commands.packman : void 0);
6992
7114
  let failures = 0;
6993
- for (const check of checks) {
6994
- if (verbose) console.log(chalk53.gray(`Checking: ${check.name}`));
6995
- const passed = check.check(cwd, verbose, fix2);
6996
- if (!passed) {
6997
- if (fix2) {
6998
- const fixed = check.fix(cwd, verbose);
6999
- if (!fixed) {
7000
- failures++;
7001
- }
7002
- } else {
7003
- failures++;
7004
- }
7115
+ const enableScriptsPassed = checkEnableScripts(cwd, verbose, fix2);
7116
+ if (!enableScriptsPassed) {
7117
+ if (fix2) {
7118
+ if (!fixEnableScripts(cwd)) failures++;
7119
+ } else {
7120
+ failures++;
7121
+ }
7122
+ }
7123
+ const agePassed = checkMinimumReleaseAge(cwd, packmanConfig, verbose, fix2);
7124
+ if (!agePassed) {
7125
+ if (fix2) {
7126
+ if (!fixMinimumReleaseAge(cwd, packmanConfig)) failures++;
7127
+ } else {
7128
+ failures++;
7129
+ }
7130
+ }
7131
+ const excludePassed = checkMinimumReleaseAgeExclude(cwd, packmanConfig, verbose, fix2);
7132
+ if (!excludePassed) {
7133
+ if (fix2) {
7134
+ if (!fixMinimumReleaseAgeExclude(cwd, packmanConfig)) failures++;
7135
+ } else {
7136
+ failures++;
7005
7137
  }
7006
7138
  }
7007
7139
  if (failures > 0) {
@@ -7273,14 +7405,14 @@ function lintPackages(cwd) {
7273
7405
  function readmeLint({ config: config2, verbose }) {
7274
7406
  const cwd = INIT_CWD();
7275
7407
  console.log(chalk55.green("Readme Lint"));
7276
- const checks2 = [
7408
+ const checks = [
7277
7409
  lintTemplate(cwd),
7278
7410
  lintLogoConfig(cwd, config2),
7279
7411
  lintPackages(cwd)
7280
7412
  ];
7281
7413
  let errorCount = 0;
7282
7414
  let warningCount = 0;
7283
- for (const { errors, warnings } of checks2) {
7415
+ for (const { errors, warnings } of checks) {
7284
7416
  for (const error of errors) {
7285
7417
  console.log(chalk55.red(` \u2717 ${error}`));
7286
7418
  errorCount++;
@@ -8105,8 +8237,8 @@ var lintCommand = {
8105
8237
  type: "boolean"
8106
8238
  });
8107
8239
  },
8108
- handler: (argv) => {
8109
- process.exitCode = packmanLint({
8240
+ handler: async (argv) => {
8241
+ process.exitCode = await packmanLint({
8110
8242
  fix: !!argv.fix,
8111
8243
  verbose: !!argv.verbose
8112
8244
  });