From a41142da7aef70bd07bb9eecbd1699cc5c36f5bf Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Thu, 14 Sep 2023 23:12:36 -0700 Subject: [PATCH] fix(vcpkg): Use workaround for MODULE_NOT_FOUND error (#187) * fix(vcpkg): Use workaround for MODULE_NOT_FOUND error * changelog --- CHANGELOG.md | 1 + cmds/core/run.js | 35 ++++++++++++++++++++++++++++++++++- lisp/core/run.el | 5 +++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee7e4f95..dec20cb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * Add option to init from elisp source file (#183) * Print archives progress (#184) * Respect package file path in `autoload` command (44c042445bba0dd071d9112e58549437b7ebd58d) +* fix(vcpkg): Use workaround for `MODULE_NOT_FOUND` error (#187) ## 0.8.x > Released Mar 08, 2023 diff --git a/cmds/core/run.js b/cmds/core/run.js index d9671775..dbf61220 100644 --- a/cmds/core/run.js +++ b/cmds/core/run.js @@ -65,7 +65,8 @@ function startCommand(commands, count) { let command = commands[count]; console.log('[RUN]: ' + command); - let proc = child_process.spawn(command, { stdio: 'inherit', shell: true }); + + let proc = spawn(command, { stdio: 'inherit', shell: true }); proc.on('close', function (code) { if (code == 0) { @@ -75,3 +76,35 @@ function startCommand(commands, count) { process.exit(code); }); } + +/** + * Spawn process to avoid `MODULE_NOT_FOUND` not found error, + * see https://github.com/vercel/pkg/issues/1356. + * + * @param { String } command - Command string. + * @param { JSON } options - Process options. + * @return Process object. + */ +function spawn(command, options) { + if (IS_PKG && command.includes('eask ')) { + let cmds = command.split(' '); + cmds = replaceEaskExec(cmds); + return child_process.spawn(process.execPath, cmds, options); + } + return child_process.spawn(command, options); +} + +/** + * Replace all possible eask/cli executable to snapshot executable. + * @param { Array } cmds - Command array. + * @return Return updated command array. + */ +function replaceEaskExec(cmds) { + if (!IS_PKG) return; + for (let index = 0; index < cmds.length; ++index) { + if (cmds[index] == "eask") { + cmds[index] = process.argv[1]; // XXX: This is `/snapshot/cli/eask` + } + } + return cmds; +} diff --git a/lisp/core/run.el b/lisp/core/run.el index 91888108..cf55cbdf 100644 --- a/lisp/core/run.el +++ b/lisp/core/run.el @@ -38,6 +38,11 @@ (defun eask--export-command (command) "Export COMMAND instruction." (ignore-errors (make-directory eask-homedir t)) ; generate dir `~/.eask/' + ;; XXX: Due to `MODULE_NOT_FOUND` not found error from vcpkg, + ;; see https://github.com/vercel/pkg/issues/1356. + ;; + ;; We must split up all commands! + (setq command (eask-s-replace " && " "\n" command)) (write-region (concat command "\n") nil eask--run-file t)) (defun eask--unmatched-scripts (scripts)