Commit Graph
3 Commits
Author SHA1 Message Date
Nguyen Thanh Dat e2d742b86d fix(dev-command): the script is the token after run, not any token
Scanning every candidate token fixed the npm-config bypass but blocked valid
commands: `npm run run dev` runs a script called `run` with `dev` as its
argument, and `npm run build dev` passes `dev` to build. Both were refused
outside tmux.

Anchor on the keyword instead. With a `run`, the script is the token right
after it and everything later is that script's argument. Without one
(`pnpm dev`), the first bare token is the script — held rather than returned,
because a `run` further along proves it was an option value, which is what
keeps `npm --userconfig /tmp/npmrc run dev` blocked without needing to know
npm's whole config surface.
2026-08-24 11:53:55 +07:00
Nguyen Thanh Dat e3c1437317 fix(dev-command): an unknown option must not swallow the script name
npm accepts any config key as `--key value`, so listing the value-taking
options can never be complete. `npm --userconfig /tmp/npmrc run dev` read the
script name as `/tmp/npmrc`, and the dev server started outside tmux.

Collect every candidate token after the manager word instead of only the
first, keeping the known value-taking options (so `--workspace dev` still
means a workspace named dev, not the dev script) and the `--` stop. An unknown
option's value now gets scanned too: that costs a false positive only when a
config value is literally `dev`, and a refusal the user sees beats a guard
that silently did nothing.

The auto-tmux tests now gate on tmux availability like their neighbours —
without tmux the hook passes the command through by design — and assert the
hook's exit code before parsing its stdout.
2026-08-24 11:17:21 +07:00
Nguyen Thanh Dat d537723eee refactor(hooks): share one dev-server classifier between the two dev hooks
pre-bash-dev-server-block.js refuses a dev server outside tmux and
auto-tmux-dev.js is what puts it in tmux, so a command one recognises and the
other does not is the worst outcome: refused, and never detached.

Both carried a copy of the same raw-text regex, each with a comment asking the
other to stay byte-identical — which is exactly how the previous commit left
them, since widening the blocker to quoted and option-separated spellings did
not reach the wrapper.

The classification now lives in scripts/lib/dev-command.js and both hooks call
it. pre-bash-dev-server-block.js drops from 304 lines to 34.
2026-08-24 11:08:48 +07:00