Skip to content

Commit 095d91e

Browse files
committed
fix(shortcuts): keep the terminal's keys away from the Vite dev server
The HMR dev server (vite serve) inherited the CLI's stdin, so it read the same TTY as the raw-mode shortcut handler: each keypress went to whichever process read first, and Vite printed its own "press h + enter" hint. Give it no stdin; its output stays inherited.
1 parent 8a55b3e commit 095d91e

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎lib/services/bundler/bundler-compiler-service.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,12 @@ export class BundlerCompilerService
736736

737737
const options: { [key: string]: any } = {
738738
cwd: projectData.projectDir,
739-
// Inherit so the dev server's URLs/logs stream to the user as
740-
// before. No IPC needed here — the build watcher provides the
739+
// Output is inherited so the dev server's URLs/logs stream to the
740+
// user. No IPC needed here — the build watcher provides the
741741
// bundle-complete IPC; the dev server is fetched over HTTP/ws.
742-
stdio: "inherit",
742+
// stdin must not be the terminal: Vite reads it for shortcuts of
743+
// its own and would take the keys meant for the CLI's.
744+
stdio: ["ignore", "inherit", "inherit"],
743745
env: {
744746
...process.env,
745747
NATIVESCRIPT_BUNDLER_ENV: JSON.stringify(envData),

‎test/services/bundler/bundler-compiler-service.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,40 @@ describe("BundlerCompilerService", () => {
373373
});
374374
});
375375

376+
describe("startViteDevServer", () => {
377+
it("does not hand the dev server the terminal's stdin", async () => {
378+
const spawned: { [key: string]: any }[] = [];
379+
testInjector.resolve("childProcess").spawn = (
380+
_command: string,
381+
_args: string[],
382+
options: { [key: string]: any },
383+
) => {
384+
spawned.push(options);
385+
return fakeChildProcess(321);
386+
};
387+
const service = <any>bundlerCompilerService;
388+
service.getBundler = () => "vite";
389+
service.buildEnvData = () => ({});
390+
service.buildEnvCommandLineParams = async (): Promise<string[]> => [];
391+
service.getBundlerExecutablePath = () => "/project/vite.js";
392+
service.waitForPort = async () => true;
393+
394+
await service.startViteDevServer(
395+
{ platformNameLowerCase: "ios" },
396+
{
397+
projectDir: "/project",
398+
bundlerConfigPath: "/project/vite.config.ts",
399+
},
400+
{ watch: true, hmr: true },
401+
);
402+
403+
assert.lengthOf(spawned, 1);
404+
const { stdio } = spawned[0];
405+
assert.isArray(stdio);
406+
assert.equal(stdio[0], "ignore");
407+
});
408+
});
409+
376410
describe("compileWithWatch", () => {
377411
it("fails when the value set for bundlerConfigPath is not existant file", async () => {
378412
const bundlerConfigPath = "some path.js";

0 commit comments

Comments
 (0)