From 42e5a6f8b270dd6ad90774282a47db02a76fe44e Mon Sep 17 00:00:00 2001 From: Shinrai Date: Sat, 8 Aug 2026 20:48:51 -0700 Subject: [PATCH] fix(devcheck): advance scanner past consumed --conditions value; drop invalid -C= form The devcheck scanner (merged via #10) had two nits: the space-form branch (`--conditions x` / `-C x`) consumed tokens[i+1] as the value but did not advance the loop index, so a value that itself looks like a flag could be double-processed; and it handled `-C=value`, which Node rejects outright ("bad option") so it can never appear. Advance i past the consumed value token, drop the dead `-C=` branch (valid forms: `--conditions=x`, `--conditions x`, `-C x`), and add -C short-flag test coverage. Redo of the change that was mistakenly pushed onto the already-merged fix/devcheck-condition-detection branch (which opened a diverged PR #12); this branch is cut fresh from next so the diff is only the scanner delta. --- devcheck.mjs | 13 ++++++++++--- tests/DevCheck.test.vitest.mjs | 8 ++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/devcheck.mjs b/devcheck.mjs index 9dd35cf..7f79d1c 100644 --- a/devcheck.mjs +++ b/devcheck.mjs @@ -61,12 +61,19 @@ if (existsSync(srcPath) && !isCI && !isInstalledPackage) { const scan = (tokens) => { for (let i = 0; i < tokens.length; i++) { if (tokens[i] === "--conditions" || tokens[i] === "-C") { - if (tokens[i + 1] !== undefined) conditions.push(tokens[i + 1]); + // Space form (`--conditions x` / `-C x`): consume the following token as this + // flag's value and SKIP it, so a value that itself looks like a flag (e.g. the + // literal `--conditions=x`) isn't re-interpreted on the next iteration. + if (tokens[i + 1] !== undefined) { + conditions.push(tokens[i + 1]); + i++; + } } else if (tokens[i].startsWith("--conditions=")) { conditions.push(tokens[i].slice("--conditions=".length)); - } else if (tokens[i].startsWith("-C=")) { - conditions.push(tokens[i].slice("-C=".length)); } + // Note: `-C=x` is intentionally not handled - Node rejects it ("bad option"), + // so it can never appear in execArgv/NODE_OPTIONS. Valid forms are + // `--conditions=x`, `--conditions x`, and `-C x`. } }; scan(process.execArgv); diff --git a/tests/DevCheck.test.vitest.mjs b/tests/DevCheck.test.vitest.mjs index de4dfea..0164f31 100644 --- a/tests/DevCheck.test.vitest.mjs +++ b/tests/DevCheck.test.vitest.mjs @@ -92,6 +92,14 @@ describe("devcheck", () => { expect(status).toBe(0); }); + test("stays silent via the -C short flag (Node's alias for --conditions)", () => { + // Node accepts `-C ` (space form) but rejects `-C=`, so only the + // space form is a real input to detect. + const { status, stderr } = runDevcheck({ src: true }, { nodeArgs: ["-C", "uuid-dev"] }); + expect(status).toBe(0); + expect(stderr).toBe(""); + }); + test("NODE_ENV=development alone does NOT silence it (only the condition selects src/)", () => { // Keying off NODE_ENV would be a false negative: dev env set but no condition means // the package is still resolving to dist/, which is exactly what should be flagged.