@mark1russell7/conventions 0.12.0 → 0.12.1

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/build/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as runCli } from "./run-Dgb6gjZJ.js";
2
+ import { c as runCli } from "./run-CKf71WQx.js";
3
3
  // src/cli.ts
4
4
  try {
5
5
  process.exitCode = runCli(process.argv.slice(2), {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/gate-trigger.ts","../src/rules/main-check.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/trust-policy.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;WAEA,iBAAiB;;;;;;UAOX;;WAEN;;WAEA;;WAEA;;;wBAIK,YAAY,cAAc,cAAc;;KAQ5C;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,UAAU;;;UAIJ;;WAEN;;WAEA,aAAa;;WAEb,mBAAmB;;WAEnB,KAAK,SAAS;;WAEd;;EAET;;EAEA,IAAI;;;KAIM,uBAAuB;WAAqB;;;UAGvC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,kBAAkB;;WAElB,SAAS,SAAS,eAAe;EAC1C,MAAM,SAAS,aAAa,SAAS,UAAU;;;qBAIpC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WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;UAoCjC;;WAEN;;WAEA;;WAEA,QAAQ;;;;;;;wBAWH,OAAO,SAAS,eAAe;;wBAyC/B,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBA0BG,OAAO,yBAAyB,IAAI;;;;;;wBC9QpC,aAAa,eAAe;;;;;wBAsD5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/gate-trigger.ts","../src/rules/main-check.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/trust-policy.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;WAEA,iBAAiB;;;;;;UAOX;;WAEN;;WAEA;;WAEA;;;wBAIK,YAAY,cAAc,cAAc;;KAQ5C;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,U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;;wBAmChB,UACd,SAAS,SAAS,0BAClB,cACA,OAAM;qBAuOK,YAAY;qBCpTZ,cAAc;;qBC3Bd;;qBAGA;qBA6DA,aAAa;qBCnEb,mBAAmB;;qBCenB,gBAAgB;;UCXZ;WACN;WACA;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;WAEA;;;UAIM;WACN,gBAAgB;;WAEhB;;;UAIM;;WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;UAoCjC;;WAEN;;WAEA;;WAEA,QAAQ;;;;;;;wBAWH,OAAO,SAAS,eAAe;;wBAyC/B,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBA0BG,OAAO,yBAAyB,IAAI;;;;;;wBC9QpC,aAAa,eAAe;;;;;wBAsD5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
package/build/index.js CHANGED
@@ -1 +1 @@
1
- export { U as ACTIONS_COMMIT, I as DEFAULT_ALLOWED, X as DEPENDENCY_FIELDS, L as HOME_PATTERNS, p as IGNORE_AFTER, B as REAL_COMPARE, d as RULES, J as STRICT_OPTIONS, m as TRAIN_SCOPES, t as USAGE, n as annotations, Z as cleanPath, Q as codePackages, _ as configsOfScript, W as convertGate, r as createContext, Y as cuePreset, pt as defaultOptions, i as formatResult, G as gateTrigger, lt as globFolders, ut as globToRegExp, $ as hasFile, V as hasImportMetaMain, x as hasTests, et as inFolder, N as isGitSpecifier, P as isPinned, C as isSourcePath, tt as keyLine, nt as lineOf, a as listRules, H as mainCheck, rt as matchesAny, z as noBuildOutput, R as noLocalPaths, dt as packageFolders, mt as parseConfig, it as parseJsonc, w as pathsOf, F as pinnedGitDeps, K as prPathFilters, o as readConfig, at as readJsonc, M as releaseFiles, ot as replaceLine, E as repositoryOfRemote, j as requiredScripts, k as roadmapOfLine, A as roadmapParses, s as runChecks, c as runCli, l as runFix, st as runGit, D as runnerBudget, O as scheduleMinute, v as scriptsOf, T as sourceMain, ct as specifiersOf, u as summaryMarkdown, q as summaryName, b as testsRequired, h as trustPolicy, S as tsconfigTest, y as typedFiles, g as typedScripts, ft as workspaceGlobs, f as workspaceProtocol } from "./run-Dgb6gjZJ.js";
1
+ export { U as ACTIONS_COMMIT, I as DEFAULT_ALLOWED, X as DEPENDENCY_FIELDS, L as HOME_PATTERNS, p as IGNORE_AFTER, B as REAL_COMPARE, d as RULES, J as STRICT_OPTIONS, m as TRAIN_SCOPES, t as USAGE, n as annotations, Z as cleanPath, Q as codePackages, _ as configsOfScript, W as convertGate, r as createContext, Y as cuePreset, pt as defaultOptions, i as formatResult, G as gateTrigger, lt as globFolders, ut as globToRegExp, $ as hasFile, V as hasImportMetaMain, x as hasTests, et as inFolder, N as isGitSpecifier, P as isPinned, C as isSourcePath, tt as keyLine, nt as lineOf, a as listRules, H as mainCheck, rt as matchesAny, z as noBuildOutput, R as noLocalPaths, dt as packageFolders, mt as parseConfig, it as parseJsonc, w as pathsOf, F as pinnedGitDeps, K as prPathFilters, o as readConfig, at as readJsonc, M as releaseFiles, ot as replaceLine, E as repositoryOfRemote, j as requiredScripts, k as roadmapOfLine, A as roadmapParses, s as runChecks, c as runCli, l as runFix, st as runGit, D as runnerBudget, O as scheduleMinute, v as scriptsOf, T as sourceMain, ct as specifiersOf, u as summaryMarkdown, q as summaryName, b as testsRequired, h as trustPolicy, S as tsconfigTest, y as typedFiles, g as typedScripts, ft as workspaceGlobs, f as workspaceProtocol } from "./run-CKf71WQx.js";
@@ -3006,10 +3006,40 @@ const ROOT_DIRS = /* @__PURE__ */ new Set([
3006
3006
  "${configDir}/"
3007
3007
  ]);
3008
3008
  /**
3009
+ * This function gives the `rootDir` that a tsconfig gets from the configs it extends, as an absolute path. It gives
3010
+ * `null` when no config of the chain sets it. It gives `undefined` when it cannot read a config of the chain, for example
3011
+ * a package that is not installed.
3012
+ */
3013
+ function inheritedRootDir(tsconfig, leaf = tsconfig, seen = /* @__PURE__ */ new Set()) {
3014
+ const json = readJsonc(tsconfig);
3015
+ if (json === void 0 || seen.has(tsconfig)) return void 0;
3016
+ const specs = Array.isArray(json.extends) ? json.extends : json.extends === void 0 ? [] : [json.extends];
3017
+ let found = null;
3018
+ for (const spec of specs) {
3019
+ if (typeof spec !== "string") return void 0;
3020
+ let file;
3021
+ try {
3022
+ file = spec.startsWith(".") || spec.startsWith("/") ? resolve(dirname(tsconfig), spec) : createRequire(tsconfig).resolve(spec);
3023
+ } catch {
3024
+ return;
3025
+ }
3026
+ if (!existsSync(file) && existsSync(`${file}.json`)) file = `${file}.json`;
3027
+ const parent = readJsonc(file);
3028
+ if (parent === void 0) return void 0;
3029
+ const own = parent.compilerOptions?.rootDir;
3030
+ const rootDir = typeof own === "string" ? own.startsWith("${configDir}") ? resolve(dirname(leaf), `.${own.slice(12)}`) : resolve(dirname(file), own) : inheritedRootDir(file, leaf, /* @__PURE__ */ new Set([...seen, tsconfig]));
3031
+ if (rootDir === void 0) return void 0;
3032
+ if (rootDir !== null) found = rootDir;
3033
+ }
3034
+ return found;
3035
+ }
3036
+ /**
3009
3037
  * This function gives the edit that adds the config files at the root of a package to its `tsconfig.test.json`. It adds
3010
- * the include `*.config.ts`. When the `rootDir` is a subfolder, it sets `rootDir: "."`. The edit changes only these
3011
- * values and keeps the format of the file. It gives no edit for a tsconfig with comments, so that no comment goes. It
3012
- * also gives no edit when the changed text does not parse as the intended config.
3038
+ * the include `*.config.ts`. When the `rootDir` is a subfolder, it sets `rootDir: "."`. It also does this when the file
3039
+ * gets the `rootDir` from a config that it extends, or when it cannot read that config. A `rootDir` of the folder does
3040
+ * no harm to a test config that does not emit. The edit changes only these values and keeps the format of the file. It
3041
+ * gives no edit for a tsconfig with comments, so that no comment goes. It also gives no edit when the changed text does
3042
+ * not parse as the intended config.
3013
3043
  */
3014
3044
  function configEdit(root, tsconfig, extension) {
3015
3045
  const text = readFileSync(tsconfig, "utf8");
@@ -3031,16 +3061,33 @@ function configEdit(root, tsconfig, extension) {
3031
3061
  const indent = kept.includes("\n") ? /\n([ \t]*)[^\n]*$/.exec(kept)?.[1] ?? "" : void 0;
3032
3062
  return `${start}${kept},${indent === void 0 ? " " : `${eol}${indent}`}${JSON.stringify(glob)}${end}]`;
3033
3063
  });
3034
- const rootDir = json.compilerOptions?.["rootDir"];
3064
+ const options = json.compilerOptions;
3065
+ const rootDir = options?.["rootDir"];
3035
3066
  const moveRoot = typeof rootDir === "string" && !ROOT_DIRS.has(rootDir);
3036
3067
  if (moveRoot) after = after.replace(/("rootDir"\s*:\s*)"(?:[^"\\]|\\.)*"/, "$1\".\"");
3037
- const intended = {
3068
+ const inherited = rootDir === void 0 && after !== text ? inheritedRootDir(tsconfig) : null;
3069
+ const addRoot = inherited !== null && (inherited === void 0 || resolve(inherited) !== resolve(dirname(tsconfig)));
3070
+ if (addRoot && options !== void 0) after = Object.keys(options).length === 0 ? after.replace(/("compilerOptions"\s*:\s*\{)\s*\}/, "$1 \"rootDir\": \".\" }") : after.replace(/("compilerOptions"\s*:\s*\{)(\s*)/, (_all, start, space) => `${start}${space}"rootDir": ".",${space}`);
3071
+ else if (addRoot) after = after.replace(/^(\s*\{)(\s*)/, (_all, start, space) => `${start}${space}"compilerOptions": { "rootDir": "." },${space}`);
3072
+ const include = globs.includes(glob) ? globs : [...globs, glob];
3073
+ const intended = addRoot ? options === void 0 ? {
3074
+ compilerOptions: { rootDir: "." },
3075
+ ...json,
3076
+ include
3077
+ } : {
3078
+ ...json,
3079
+ compilerOptions: {
3080
+ rootDir: ".",
3081
+ ...options
3082
+ },
3083
+ include
3084
+ } : {
3038
3085
  ...json,
3039
3086
  ...moveRoot ? { compilerOptions: {
3040
- ...json.compilerOptions,
3087
+ ...options,
3041
3088
  rootDir: "."
3042
3089
  } } : {},
3043
- include: globs.includes(glob) ? globs : [...globs, glob]
3090
+ include
3044
3091
  };
3045
3092
  let parsed;
3046
3093
  try {
@@ -3840,4 +3887,4 @@ function runCli(args, io) {
3840
3887
  }
3841
3888
  export { hasFile as $, roadmapParses as A, REAL_COMPARE as B, isSourcePath as C, runnerBudget as D, repositoryOfRemote as E, pinnedGitDeps as F, gateTrigger as G, mainCheck as H, DEFAULT_ALLOWED as I, STRICT_OPTIONS as J, prPathFilters as K, HOME_PATTERNS as L, releaseFiles as M, isGitSpecifier as N, scheduleMinute as O, isPinned as P, codePackages as Q, noLocalPaths as R, tsconfigTest as S, sourceMain as T, ACTIONS_COMMIT as U, hasImportMetaMain as V, convertGate as W, DEPENDENCY_FIELDS as X, cuePreset as Y, cleanPath as Z, configsOfScript as _, listRules as a, readJsonc as at, testsRequired as b, runCli as c, specifiersOf as ct, RULES as d, packageFolders as dt, inFolder as et, workspaceProtocol as f, workspaceGlobs as ft, typedScripts as g, trustPolicy as h, formatResult as i, parseJsonc as it, requiredScripts as j, roadmapOfLine as k, runFix as l, globFolders as lt, TRAIN_SCOPES as m, parseConfig as mt, annotations as n, lineOf as nt, readConfig as o, replaceLine as ot, IGNORE_AFTER as p, defaultOptions as pt, summaryName as q, createContext as r, matchesAny as rt, runChecks as s, runGit as st, USAGE as t, keyLine as tt, summaryMarkdown as u, globToRegExp as ut, scriptsOf as v, pathsOf as w, hasTests as x, typedFiles as y, noBuildOutput as z };
3842
3889
 
3843
- //# sourceMappingURL=run-Dgb6gjZJ.js.map
3890
+ //# sourceMappingURL=run-CKf71WQx.js.map