Skip to content
Open
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: 12 additions & 1 deletion src/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/test/cli-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down