@mark1russell7/conventions 0.12.0 → 0.12.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/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-D6OdZDaQ.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;;;qBAI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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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;;;;wBAmChB,UACd,SAAS,SAAS,0BAClB,cACA,OAAM;qBAkRK,YAAY;qBC/VZ,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-D6OdZDaQ.js";
@@ -3006,10 +3006,55 @@ const ROOT_DIRS = /* @__PURE__ */ new Set([
3006
3006
  "${configDir}/"
3007
3007
  ]);
3008
3008
  /**
3009
+ * This function gives the value of the compiler option `name` that a tsconfig gets from the configs it extends. 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 inheritedOption(tsconfig, name, 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?.[name];
3030
+ const value = own === void 0 ? inheritedOption(file, name, /* @__PURE__ */ new Set([...seen, tsconfig])) : {
3031
+ value: own,
3032
+ file
3033
+ };
3034
+ if (value === void 0) return void 0;
3035
+ if (value !== null) found = value;
3036
+ }
3037
+ return found;
3038
+ }
3039
+ /**
3040
+ * This function tells if a tsconfig gets a `rootDir` other than its folder from a config that it extends. It also says
3041
+ * yes when it cannot read that config. A `${configDir}` is the folder of the tsconfig, the other paths are relative to
3042
+ * the config that sets them.
3043
+ */
3044
+ function inheritsSubfolder(tsconfig) {
3045
+ const inherited = inheritedOption(tsconfig, "rootDir");
3046
+ if (inherited === null) return false;
3047
+ if (inherited === void 0 || typeof inherited.value !== "string") return true;
3048
+ const own = inherited.value;
3049
+ return (own.startsWith("${configDir}") ? resolve(dirname(tsconfig), `.${own.slice(12)}`) : resolve(dirname(inherited.file), own)) !== resolve(dirname(tsconfig));
3050
+ }
3051
+ /**
3009
3052
  * 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.
3053
+ * the include `*.config.ts`. When the `rootDir` is a subfolder, it sets `rootDir: "."`. It also does this when the file
3054
+ * gets the `rootDir` from a config that it extends, or when it cannot read that config. A `rootDir` of the folder does
3055
+ * no harm to a test config that does not emit. The edit changes only these values and keeps the format of the file. It
3056
+ * gives no edit for a tsconfig with comments, so that no comment goes. It also gives no edit when the changed text does
3057
+ * not parse as the intended config.
3013
3058
  */
3014
3059
  function configEdit(root, tsconfig, extension) {
3015
3060
  const text = readFileSync(tsconfig, "utf8");
@@ -3031,16 +3076,41 @@ function configEdit(root, tsconfig, extension) {
3031
3076
  const indent = kept.includes("\n") ? /\n([ \t]*)[^\n]*$/.exec(kept)?.[1] ?? "" : void 0;
3032
3077
  return `${start}${kept},${indent === void 0 ? " " : `${eol}${indent}`}${JSON.stringify(glob)}${end}]`;
3033
3078
  });
3034
- const rootDir = json.compilerOptions?.["rootDir"];
3079
+ const options = json.compilerOptions;
3080
+ const rootDir = options?.["rootDir"];
3035
3081
  const moveRoot = typeof rootDir === "string" && !ROOT_DIRS.has(rootDir);
3036
3082
  if (moveRoot) after = after.replace(/("rootDir"\s*:\s*)"(?:[^"\\]|\\.)*"/, "$1\".\"");
3037
- const intended = {
3083
+ const added = {};
3084
+ if (after !== text) {
3085
+ if (rootDir === void 0 && inheritsSubfolder(tsconfig)) added["rootDir"] = ".";
3086
+ const isolated = options?.["isolatedDeclarations"] === void 0 ? inheritedOption(tsconfig, "isolatedDeclarations") : null;
3087
+ if (isolated === void 0 || isolated !== null && isolated.value !== false) added["isolatedDeclarations"] = false;
3088
+ }
3089
+ const entries = Object.entries(added).map(([key, value]) => `${JSON.stringify(key)}: ${JSON.stringify(value)}`);
3090
+ if (entries.length > 0 && options !== void 0) after = Object.keys(options).length === 0 ? after.replace(/("compilerOptions"\s*:\s*\{)\s*\}/, `$1 ${entries.join(", ")} }`) : after.replace(/("compilerOptions"\s*:\s*\{)(\s*)/, (_all, start, space) => `${start}${space}${entries.join(`,${space}`)},${space}`);
3091
+ else if (entries.length > 0) after = after.replace(/^(\s*\{)(\s*)/, (_all, start, space) => `${start}${space}"compilerOptions": { ${entries.join(", ")} },${space}`);
3092
+ const include = globs.includes(glob) ? globs : [...globs, glob];
3093
+ const intended = entries.length > 0 ? options === void 0 ? {
3094
+ compilerOptions: added,
3095
+ ...json,
3096
+ include
3097
+ } : {
3098
+ ...json,
3099
+ compilerOptions: {
3100
+ ...added,
3101
+ ...moveRoot ? {
3102
+ ...options,
3103
+ rootDir: "."
3104
+ } : options
3105
+ },
3106
+ include
3107
+ } : {
3038
3108
  ...json,
3039
3109
  ...moveRoot ? { compilerOptions: {
3040
- ...json.compilerOptions,
3110
+ ...options,
3041
3111
  rootDir: "."
3042
3112
  } } : {},
3043
- include: globs.includes(glob) ? globs : [...globs, glob]
3113
+ include
3044
3114
  };
3045
3115
  let parsed;
3046
3116
  try {
@@ -3840,4 +3910,4 @@ function runCli(args, io) {
3840
3910
  }
3841
3911
  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
3912
 
3843
- //# sourceMappingURL=run-Dgb6gjZJ.js.map
3913
+ //# sourceMappingURL=run-D6OdZDaQ.js.map