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.
diff --git a/emsdk.py b/emsdk.py
index aff9b4c..6676607 100644
--- a/emsdk.py
+++ b/emsdk.py
@@ -1243,10 +1243,16 @@
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"]