[cli] Fix "now-dev-next" and "now-dev-static-build-routing" unit tests (#7824)

These two tests have been problematic on MacOS for a long time,
but now that we've re-introduced `@vercel/next` into this repo,
they've started to fail on Linux/Windows as well.

So the idea is to use the `devCommand` property so that
`@vercel/next` Builder doesn't get invoked at all.

Since the `devCommand` property was not yet being unit tested,
some logic in `vc build` needed to be adjusted in order to properly
shut down the dev command (via `tree-kill` module) when the
process was being stopped in order to cleanly shut down.
This commit is contained in:
Nathan Rajlich
2022-05-19 09:27:51 -07:00
committed by GitHub
parent 234c4dfa84
commit e3c4435606
7 changed files with 44 additions and 60 deletions

View File

@@ -89,6 +89,7 @@ import {
} from './types';
import { ProjectEnvVariable, ProjectSettings } from '../../types';
import exposeSystemEnvs from './expose-system-envs';
import { treeKill } from '../tree-kill';
const frontendRuntimeSet = new Set(
frameworkList.map(f => f.useRuntime?.use || '@vercel/static-build')
@@ -998,20 +999,7 @@ export default class DevServer {
}
if (devProcess) {
ops.push(
new Promise<void>((resolve, reject) => {
devProcess.once('exit', () => resolve());
try {
process.kill(devProcess.pid);
} catch (err) {
if (err.code === 'ESRCH') {
// Process already exited
return resolve();
}
reject(err);
}
})
);
ops.push(treeKill(devProcess.pid));
}
ops.push(close(this.server));
@@ -1052,12 +1040,7 @@ export default class DevServer {
const { debug } = this.output;
debug(`Killing builder dev server with PID ${pid}`);
this.devServerPids.delete(pid);
try {
process.kill(pid, 'SIGTERM');
debug(`Killed builder dev server with PID ${pid}`);
} catch (err) {
debug(`Failed to kill builder dev server with PID ${pid}: ${err}`);
}
await treeKill(pid);
}
async send404(
@@ -2120,7 +2103,7 @@ export default class DevServer {
.replace(/%PORT%/g, `${port}`);
this.output.debug(
`Starting dev command with parameters : ${JSON.stringify({
`Starting dev command with parameters: ${JSON.stringify({
cwd,
command,
port,
@@ -2152,6 +2135,7 @@ export default class DevServer {
cwd,
env,
});
this.devProcess = p;
if (!p.stdout || !p.stderr) {
throw new Error('Expected child process to have stdout and stderr');
@@ -2164,17 +2148,14 @@ export default class DevServer {
process.stdout.write(data.replace(proxyPort, devPort));
});
p.on('exit', (code: number) => {
if (code > 0) {
process.exit(code);
}
p.on('exit', (code, signal) => {
this.output.debug(`Dev command exited with "${signal || code}"`);
this.devProcessPort = undefined;
});
await checkForPort(port, 1000 * 60 * 5);
this.devProcessPort = port;
this.devProcess = p;
}
}