Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions devcheck.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/DevCheck.test.vitest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value>` (space form) but rejects `-C=<value>`, 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.
Expand Down
Loading