@apollion-dsi/scripts 0.9.0 → 0.9.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.
@@ -1,30 +1,26 @@
1
1
  import spawn from 'cross-spawn';
2
2
 
3
+ import { buildWrapperArgs } from '../utils/buildWrapperArgs';
3
4
  import { resolveBin } from '../utils/resolveBin';
4
5
 
5
6
  /**
6
- * `scripts lint` — ESLint over `src` with `--quiet`. ESLint 9 flat
7
- * config uses `eslint.config.js#files` for filtering (no `--ext`).
7
+ * `scripts lint` — ESLint over `src`. ESLint 9 flat config uses
8
+ * `eslint.config.js#files` for filtering (no `--ext`).
8
9
  *
9
- * If the consumer passes any path-like arg, they own the invocation
10
- * entirely. Flag-only invocations (e.g. `scripts lint --fix`) keep the
11
- * default `src` target so the common case Just Works.
10
+ * Flag args pass through; the default `src` target is always appended
11
+ * so the common case (`scripts lint --fix`, `scripts lint
12
+ * --max-warnings 0`, `scripts lint -- --fix`) Just Works. Consumers
13
+ * that need a different target should call `eslint` directly from
14
+ * `node_modules/.bin`.
12
15
  */
13
16
  const eslintBin = resolveBin('eslint');
14
17
 
15
18
  const userArgs = process.argv.slice(2);
16
19
 
17
- const userProvidedPath = userArgs.some((a) => !a.startsWith('-'));
18
-
19
- let args: string[];
20
-
21
- if (userArgs.length === 0) {
22
- args = ['src', '--quiet'];
23
- } else if (userProvidedPath) {
24
- args = userArgs;
25
- } else {
26
- args = [...userArgs, 'src'];
27
- }
20
+ const args = buildWrapperArgs(userArgs, {
21
+ defaults: ['src', '--quiet'],
22
+ target: 'src',
23
+ });
28
24
 
29
25
  const result = spawn.sync(process.execPath, [eslintBin, ...args], { stdio: 'inherit' });
30
26
 
@@ -1,13 +1,15 @@
1
1
  import spawn from 'cross-spawn';
2
2
 
3
+ import { buildWrapperArgs } from '../utils/buildWrapperArgs';
3
4
  import { resolveBin } from '../utils/resolveBin';
4
5
 
5
6
  /**
6
7
  * `scripts prettier` — `--check` over `src/**\/*.{ts,tsx,json,css,md}`.
7
8
  *
8
- * Flag-only user args (e.g. `scripts prettier --write`) keep the default
9
- * glob so `--write` is enough. A path-like arg switches to fully
10
- * user-controlled invocation.
9
+ * Flag args pass through; the default glob is always appended so
10
+ * `scripts prettier --write` Just Works. Consumers that need a
11
+ * different target should call `prettier` directly from
12
+ * `node_modules/.bin`.
11
13
  */
12
14
  const prettierBin = resolveBin('prettier');
13
15
 
@@ -15,17 +17,10 @@ const DEFAULT_GLOB = 'src/**/*.{ts,tsx,json,css,md}';
15
17
 
16
18
  const userArgs = process.argv.slice(2);
17
19
 
18
- const userProvidedPath = userArgs.some((a) => !a.startsWith('-'));
19
-
20
- let args: string[];
21
-
22
- if (userArgs.length === 0) {
23
- args = ['--check', DEFAULT_GLOB];
24
- } else if (userProvidedPath) {
25
- args = userArgs;
26
- } else {
27
- args = [...userArgs, DEFAULT_GLOB];
28
- }
20
+ const args = buildWrapperArgs(userArgs, {
21
+ defaults: ['--check', DEFAULT_GLOB],
22
+ target: DEFAULT_GLOB,
23
+ });
29
24
 
30
25
  const result = spawn.sync(process.execPath, [prettierBin, ...args], { stdio: 'inherit' });
31
26
 
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Build the argv passed to an underlying CLI (eslint, prettier) for a
3
+ * `scripts <cmd>` wrapper, from the user-provided argv.
4
+ *
5
+ * - Empty input → `defaults` verbatim (the canonical no-args
6
+ * invocation, e.g. `['src', '--quiet']` for lint).
7
+ * - Non-empty input → user args (with the POSIX `--` end-of-options
8
+ * marker removed) followed by `target`.
9
+ *
10
+ * The previous heuristic tried to detect "user-provided path" by
11
+ * scanning for any argv entry not starting with `-`, then handed full
12
+ * control to the user. That broke two real consumer invocations:
13
+ *
14
+ * 1. `scripts lint --max-warnings 0` — the `0` value of the flag was
15
+ * misread as a path, so `src` was dropped and ESLint ran with no
16
+ * files.
17
+ * 2. `scripts lint -- --fix` — every arg started with `-`, so `src`
18
+ * was appended, but the surviving `--` separator forced ESLint to
19
+ * treat `--fix` and `src` as positional files.
20
+ *
21
+ * The wrapper is intentionally narrow: pass flags, get the default
22
+ * target. Consumers that need a non-default target should invoke the
23
+ * underlying CLI directly (`node_modules/.bin/eslint <path>`).
24
+ *
25
+ * @param userArgs - argv after `scripts <cmd>` (i.e. `process.argv.slice(2)`).
26
+ * @param options.defaults - argv to use when `userArgs` is empty.
27
+ * @param options.target - path/glob appended after user flags otherwise.
28
+ */
29
+ export function buildWrapperArgs(userArgs: string[], options: { defaults: string[]; target: string }): string[] {
30
+ if (userArgs.length === 0) {
31
+ return [...options.defaults];
32
+ }
33
+
34
+ const passthrough = userArgs.filter((a) => a !== '--');
35
+
36
+ return [...passthrough, options.target];
37
+ }
File without changes