@zgeoff/chex 0.8.12 → 0.8.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/chex",
3
- "version": "0.8.12",
3
+ "version": "0.8.13",
4
4
  "description": "Run each shared docs and repo check as one subcommand, with the lefthook pre-push baseline that calls them",
5
5
  "keywords": [
6
6
  "checks",
@@ -17,6 +17,10 @@ export interface CIOnlyVerdictInput {
17
17
  // True when the caller's arguments name files or folders inside the script's folder for lint,
18
18
  // or workspace packages for typecheck.
19
19
  readonly isScoped: boolean;
20
+
21
+ // True when the caller's arguments reach chex, so a scope the caller types can be seen. False for
22
+ // a chained script, where bun appends them to a later command.
23
+ readonly canSeeArgs: boolean;
20
24
  }
21
25
 
22
26
  export type CIOnlyVerdict =
@@ -30,16 +34,23 @@ export function pickCIOnlyVerdict(input: Readonly<CIOnlyVerdictInput>): CIOnlyVe
30
34
  return { kind: 'allow' };
31
35
  }
32
36
 
33
- return { kind: 'refuse', message: buildRefusal(input.check) };
37
+ return { kind: 'refuse', message: buildRefusal(input) };
34
38
  }
35
39
 
36
- function buildRefusal(check: CIOnlyCheck): string {
37
- const checked = check === 'lint' ? 'the files you changed' : 'the packages you changed';
40
+ function buildRefusal(input: Readonly<CIOnlyVerdictInput>): string {
41
+ const checked = input.check === 'lint' ? 'the files you changed' : 'the packages you changed';
42
+
43
+ return `${input.check} runs on the whole repo only in CI and the push hook, which checks ${checked}. Push, or ${pickInstead(input)}. To run it here anyway, set ${overrideVariable}=1.`;
44
+ }
38
45
 
39
- const instead =
40
- check === 'lint'
46
+ function pickInstead(input: Readonly<CIOnlyVerdictInput>): string {
47
+ if (input.check === 'lint') {
48
+ return input.canSeeArgs
41
49
  ? 'lint named files with `bun run lint <file>...`'
42
- : 'check one package with `bun run typecheck --filter <package>`';
50
+ : 'lint named files with `bun x oxlint <file>...`';
51
+ }
43
52
 
44
- return `${check} runs on the whole repo only in CI and the push hook, which checks ${checked}. Push, or ${instead}. To run it here anyway, set ${overrideVariable}=1.`;
53
+ return input.canSeeArgs
54
+ ? 'check one package with `bun run typecheck --filter <package>`'
55
+ : "check one package by running `bun run typecheck` in that package's folder";
45
56
  }
@@ -11,8 +11,26 @@ export function pickExtraArgs(
11
11
  return command.slice(1);
12
12
  }
13
13
 
14
- const baseText = /^[\s\S]*\bci-only \S+ -- (?<base>[\s\S]*)$/u.exec(scriptText)?.groups?.['base'];
15
- const baseWords = baseText === undefined ? null : parseShellWords(baseText);
14
+ const baseWords = splitBaseWords(scriptText);
16
15
 
17
16
  return baseWords === null ? [] : command.slice(baseWords.length);
18
17
  }
18
+
19
+ // True when chex can tell the caller's arguments from the script's own: no script text to read, or a
20
+ // command after `--` that is plain words. A chained or expanded command hides them, and so does a
21
+ // later guard for another check, which is the one that gets bun's appended arguments.
22
+ export function canSeeCallerArgs(check: string, scriptText: string | undefined): boolean {
23
+ if (scriptText === undefined) {
24
+ return true;
25
+ }
26
+
27
+ const lastCheck = /^[\s\S]*\bci-only (?<check>\S+) -- /u.exec(scriptText)?.groups?.['check'];
28
+
29
+ return lastCheck === check && splitBaseWords(scriptText) !== null;
30
+ }
31
+
32
+ function splitBaseWords(scriptText: string): string[] | null {
33
+ const baseText = /^[\s\S]*\bci-only \S+ -- (?<base>[\s\S]*)$/u.exec(scriptText)?.groups?.['base'];
34
+
35
+ return baseText === undefined ? null : parseShellWords(baseText);
36
+ }
@@ -1,7 +1,7 @@
1
1
  import { isCIOnlyAllowed } from './is-ci-only-allowed.ts';
2
2
  import type { CIOnlyCheck } from './pick-ci-only-verdict.ts';
3
3
  import { pickCIOnlyVerdict } from './pick-ci-only-verdict.ts';
4
- import { pickExtraArgs } from './pick-extra-args.ts';
4
+ import { canSeeCallerArgs, pickExtraArgs } from './pick-extra-args.ts';
5
5
  import { pickScriptRuns } from './pick-script-runs.ts';
6
6
  import { readScope } from './read-scope.ts';
7
7
 
@@ -35,6 +35,7 @@ export async function runCIOnlyCheck(options: Readonly<CIOnlyCheckOptions>): Pro
35
35
  const verdict = isCIOnlyAllowed(options.env)
36
36
  ? { kind: 'allow' as const }
37
37
  : pickCIOnlyVerdict({
38
+ canSeeArgs: canSeeCallerArgs(options.check, options.env['npm_lifecycle_script']),
38
39
  check: options.check,
39
40
  isInPackage: scope.isInPackage,
40
41
  isScoped: scope.isScoped,