@@ -449,24 +449,31 @@ int executeNpmCommand(std::vector<std::string> npmArgs, std::string workingDir)
449
449
450
450
std::string executeJs = fmt::format (
451
451
R"(
452
- const engineDir = " {0}";
452
+ const engineDir = require("path").resolve(" {0}") + require("path").sep ;
453
453
const workingDir = "{1}";
454
454
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);
458
456
// Record states and restore at exit
459
457
const oldCwd = process.cwd();
460
458
const oldEnv = Object.entries(process.env).filter(([k]) => k.startsWith("npm_"));
461
459
const oldTitle = process.title;
462
- process.on ("exit", () => {{
460
+ process.once ("exit", () => {{
463
461
Object.keys(process.env)
464
462
.filter((k) => k.startsWith("npm_"))
465
463
.forEach((k) => delete process.env[k]);
466
464
oldEnv.forEach(([k, v]) => (process.env[k] = v));
467
465
process.title = oldTitle;
468
466
process.chdir(oldCwd);
469
467
}});
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));
470
477
471
478
process.chdir(workingDir);
472
479
publicRequire(scriptPath);
0 commit comments