Skip to content

Commit 1fc0773

Browse files
committed
fix: disable input in console npm command
1 parent c60e0be commit 1fc0773

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/legacy/main/NodeJsHelper.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,24 +449,31 @@ int executeNpmCommand(std::vector<std::string> npmArgs, std::string workingDir)
449449

450450
std::string executeJs = fmt::format(
451451
R"(
452-
const engineDir = "{0}";
452+
const engineDir = require("path").resolve("{0}") + require("path").sep;
453453
const workingDir = "{1}";
454454
const scriptPath = "{2}";
455-
const publicRequire = require("module").createRequire(
456-
require("path").resolve(engineDir) + require("path").sep
457-
);
455+
const publicRequire = require("module").createRequire(engineDir);
458456
// Record states and restore at exit
459457
const oldCwd = process.cwd();
460458
const oldEnv = Object.entries(process.env).filter(([k]) => k.startsWith("npm_"));
461459
const oldTitle = process.title;
462-
process.on("exit", () => {{
460+
process.once("exit", () => {{
463461
Object.keys(process.env)
464462
.filter((k) => k.startsWith("npm_"))
465463
.forEach((k) => delete process.env[k]);
466464
oldEnv.forEach(([k, v]) => (process.env[k] = v));
467465
process.title = oldTitle;
468466
process.chdir(oldCwd);
469467
}});
468+
// disable npm input
469+
function inputHandler(type, resolve, reject) {{
470+
if (type === "read") {{
471+
console.error("Input is not allow in server command.");
472+
reject();
473+
}}
474+
}}
475+
process.on("input", inputHandler);
476+
process.once("exit", () => process.off("input", inputHandler));
470477
471478
process.chdir(workingDir);
472479
publicRequire(scriptPath);

0 commit comments

Comments
 (0)