From 68100d6c3a136ef53bf9f4d80c1f0d30b6caf0c5 Mon Sep 17 00:00:00 2001 From: Kiwi Date: Tue, 19 May 2026 02:15:26 -0400 Subject: [PATCH 1/2] feat(cli): accept WIREIT_WATCH as an escape hatch for --watch detection (#1346) --- src/cli-options.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cli-options.ts b/src/cli-options.ts index b12645f4b..97d8fb46f 100644 --- a/src/cli-options.ts +++ b/src/cli-options.ts @@ -276,9 +276,15 @@ function getArgvOptions( // // npm 8.11.0 // - Like npm 6, except there is no "npm_config_argv" environment variable. + // + // npm 12 (https://github.com/npm/cli/pull/8071) + // - "npm run build --watch" is rejected as an unrecognized npm argument + // instead of being silently turned into "npm_config_watch", so we also + // accept WIREIT_WATCH=1 as an escape hatch (see #1346). 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), @@ -446,6 +452,11 @@ function parseRemainingArgs( `e.g. "npm run build -- --extra".`, ); } + // 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, From a0ada1b5300bd17f04de32252d437e4351aa418c Mon Sep 17 00:00:00 2001 From: Kiwi Date: Tue, 19 May 2026 02:15:52 -0400 Subject: [PATCH 2/2] test(cli): cover WIREIT_WATCH escape hatch across all agents --- src/test/cli-options.test.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/cli-options.test.ts b/src/test/cli-options.test.ts index 48520ad4e..60278d96a 100644 --- a/src/test/cli-options.test.ts +++ b/src/test/cli-options.test.ts @@ -247,6 +247,30 @@ for (const {agent, runCmd, testCmd, startCmd, needsExtraDashes} of commands) { }), ); + // https://github.com/google/wireit/issues/1346 + // npm 12 no longer forwards `--watch` as `npm_config_watch`, so we accept + // WIREIT_WATCH=1 as an alternative trigger. Should work on every agent. + void test( + `${agent} WIREIT_WATCH=1 run`, + rigTest(async ({rig}) => { + await assertOptions( + rig, + `${runCmd} main`, + { + agent, + script: { + packageDir: rig.temp, + name: 'main', + }, + watch: {strategy: 'event'}, + }, + { + WIREIT_WATCH: '1', + }, + ); + }), + ); + // Doesn't work with yarn 1.x due to // https://github.com/yarnpkg/yarn/issues/8905. Anything before a "--" is not // included on argv, and the npm_config_argv variable does not let us