From 13bda1158315e1bc67145766843a6ba235a8db5b Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Tue, 23 Apr 2024 13:01:16 -0700 Subject: [PATCH] [Node.js binding] Fix install script (#20416) ### Description Fix a few bugs of the install script of onnxruntime-node package. This change is integrated from branch `rel-1.17.3` (#20397) --- js/node/script/install.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/js/node/script/install.js b/js/node/script/install.js index 81304b3351..5136fbccbf 100644 --- a/js/node/script/install.js +++ b/js/node/script/install.js @@ -29,6 +29,8 @@ const {Readable} = require('stream'); // --onnxruntime-node-install-cuda=v12 Force install the CUDA EP binaries for CUDA 12. // --onnxruntime-node-install-cuda=skip Skip the installation of the CUDA EP binaries. // +// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL_CUDA" +// // If the flag is not provided, the script will only install the CUDA EP binaries when: // - The platform is Linux/x64. // - The binaries are not already present in the package. @@ -58,7 +60,7 @@ if (NO_INSTALL || !shouldInstall) { const artifactUrl = { 11: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${ ORT_VERSION}.tgz`, - 12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-cuda12-${ + 12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-cuda12-${ ORT_VERSION}.tgz` }[INSTALL_CUDA_FLAG || tryGetCudaVersion()]; console.log(`Downloading "${artifactUrl}"...`); @@ -79,15 +81,19 @@ Use "--onnxruntime-node-install-cuda=skip" to skip the installation. You will st ]); Readable.fromWeb(res.body) - .pipe(tar.t()) - .on('entry', - (entry) => { - const filename = path.basename(entry.path); - if (entry.type === 'File' && FILES.has(filename)) { - console.log(`Extracting "${filename}" to "${BIN_FOLDER}"...`); - entry.pipe(fs.createWriteStream(path.join(BIN_FOLDER, filename))); - } - }) + .pipe(tar.t({ + strict: true, + onentry: (entry) => { + const filename = path.basename(entry.path); + if (entry.type === 'File' && FILES.has(filename)) { + console.log(`Extracting "${filename}" to "${BIN_FOLDER}"...`); + entry.pipe(fs.createWriteStream(path.join(BIN_FOLDER, filename))); + entry.on('finish', () => { + console.log(`Finished extracting "${filename}".`); + }); + } + } + })) .on('error', (err) => { throw new Error(`Failed to extract the binaries: ${err.message}. @@ -105,7 +111,7 @@ function tryGetCudaVersion() { } function parseInstallCudaFlag() { - let flag = process.env.npm_config_onnxruntime_node_install_cuda; + let flag = process.env.ONNXRUNTIME_NODE_INSTALL_CUDA || process.env.npm_config_onnxruntime_node_install_cuda; if (!flag) { for (let i = 0; i < process.argv.length; i++) { if (process.argv[i].startsWith('--onnxruntime-node-install-cuda=')) { @@ -118,6 +124,8 @@ function parseInstallCudaFlag() { } switch (flag) { case 'true': + case '1': + case 'ON': return tryGetCudaVersion(); case 'v11': return 11;