From 63b6cd2a4e122f86b4d76d371eed978debf85d0f Mon Sep 17 00:00:00 2001 From: Jia Yuan Lo Date: Wed, 24 Feb 2021 03:18:28 +0800 Subject: [PATCH] Allow system npm in "emsdk install emscripten" (#723) "emsdk install emscripten-master-64bit" is currently dependent on whether emscripten node is installed or not. This change allow using system-provided node / npm command to proceed the installation. Also clarify the error message. --- emsdk.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/emsdk.py b/emsdk.py index aff9b4c..6676607 100644 --- a/emsdk.py +++ b/emsdk.py @@ -1243,10 +1243,16 @@ def find_latest_installed_tool(name): def emscripten_npm_install(tool, directory): node_tool = find_latest_installed_tool('node') if not node_tool: - print('Failed to run "npm ci" in installed Emscripten root directory ' + tool.installation_path() + '! Please install node.js first!') - return False + npm_fallback = which('npm') + if not npm_fallback: + print('Failed to find npm command!') + print('Running "npm ci" in installed Emscripten root directory ' + tool.installation_path() + ' is required!') + print('Please install node.js first!') + return False + node_path = os.path.dirname(npm_fallback) + else: + node_path = os.path.join(node_tool.installation_path(), 'bin') - node_path = os.path.join(node_tool.installation_path(), 'bin') npm = os.path.join(node_path, 'npm' + ('.cmd' if WINDOWS else '')) env = os.environ.copy() env["PATH"] = node_path + os.pathsep + env["PATH"]