Skip to content

feat(cli): accept WIREIT_WATCH env var as a --watch escape hatch (#1346)#1418

Open
kiwigitops wants to merge 2 commits into
google:mainfrom
kiwigitops:feat/wireit-watch-env-var
Open

feat(cli): accept WIREIT_WATCH env var as a --watch escape hatch (#1346)#1418
kiwigitops wants to merge 2 commits into
google:mainfrom
kiwigitops:feat/wireit-watch-env-var

Conversation

@kiwigitops
Copy link
Copy Markdown

Resolves the short-term proposal in #1346.

Problem

npm/cli#8071 lands a warning today and will turn into a hard error in npm 12: npm run build --watch is rejected because --watch is not a recognized npm argument. Until now, wireit relied on npm's old behaviour of silently turning npm run build --watch into npm_config_watch= in the script's environment. After npm 12 there is no way to enable wireit watch mode from npm run — neither --watch (rejected) nor -- --watch (forwarded to the underlying script, not wireit).

@aomarks proposed in #1346:

  1. Add a WIREIT_WATCH=1 environment variable.
    [...]
    I'm leaning towards doing 1 in the short term, because we already handle all other runtime wireit settings with WIREIT_ environment variables and it's very easy [...]

This PR implements proposal 1.

Change

Two getArgvOptions call sites now recognize WIREIT_WATCH (any non-undefined value) as an additional trigger for watch mode, OR'd with the existing detection:

   case 'npm': {
     return {
       watch:
-        process.env['npm_config_watch'] !== undefined
+        process.env['npm_config_watch'] !== undefined ||
+        process.env['WIREIT_WATCH'] !== undefined
           ? readWatchConfigFromEnv()
           : false,
       extraArgs: process.argv.slice(2),
     };
   }

And the parseRemainingArgs helper (used for yarn / yarnBerry / pnpm / nodeRun) gets a matching post-loop check so the escape hatch works on every agent, not just npm:

+  // Also accept WIREIT_WATCH as an escape hatch (matches the npm branch behaviour,
+  // useful for yarn/pnpm/node --run wrappers that scrub --watch from argv).
+  if (!watch && process.env['WIREIT_WATCH'] !== undefined) {
+    watch = readWatchConfigFromEnv();
+  }
   return {
     watch,
     extraArgs,
   };

The existing WIREIT_WATCH_STRATEGY / WIREIT_WATCH_POLL_MS env vars still control the watch strategy via the unchanged readWatchConfigFromEnv().

Test plan

  • Added an ${agent} WIREIT_WATCH=1 run test case alongside the existing WIREIT_LOGGER env-var tests. Runs in the per-agent loop, so it covers npm, yarnClassic, yarnBerry, pnpm, and node --run in one go.
  • All existing tests that exercise --watch and WIREIT_WATCH_STRATEGY are untouched and should continue to pass — the change is purely additive (an extra OR'd condition).

Notes for reviewers

  • I deliberately scoped this to proposal 1 only. Proposals 2 (--wireit-watch arg) and 3 (declarative {"watch": true}) are bigger surface-area changes and can land on their own.
  • WIREIT_WATCH= (empty string) also triggers watch mode, because the existing detection uses !== undefined rather than a truthy check — kept consistent so behaviour is predictable; matches how WIREIT_DEBUG_LOGGER is detected in logger.ts (via Boolean(...)) is intentionally NOT used here so an empty WIREIT_WATCH= set in CI's env still triggers, mirroring npm_config_watch=.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant