onnxruntime-node 1.21.0 → 1.22.0-dev.20250418-c19a49615b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -14
- package/__commit.txt +1 -0
- package/bin/{napi-v3/darwin/arm64/libonnxruntime.1.21.0.dylib → napi-v6/darwin/arm64/libonnxruntime.1.22.0.dylib} +0 -0
- package/bin/napi-v6/darwin/arm64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3/darwin/x64/libonnxruntime.1.21.0.dylib → napi-v6/darwin/x64/libonnxruntime.1.22.0.dylib} +0 -0
- package/bin/napi-v6/darwin/x64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/linux/arm64/libonnxruntime.so.1 +0 -0
- package/bin/napi-v6/linux/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v6/linux/x64/libonnxruntime.so.1 +0 -0
- package/bin/napi-v6/linux/x64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/arm64/DirectML.dll +0 -0
- package/bin/{napi-v3/linux/x64/libonnxruntime.so.1 → napi-v6/win32/arm64/dxcompiler.dll} +0 -0
- package/bin/napi-v6/win32/arm64/dxil.dll +0 -0
- package/bin/{napi-v3/linux/x64/libonnxruntime.so.1.21.0 → napi-v6/win32/arm64/onnxruntime.dll} +0 -0
- package/bin/napi-v6/win32/arm64/onnxruntime_binding.node +0 -0
- package/bin/{napi-v3 → napi-v6}/win32/x64/DirectML.dll +0 -0
- package/bin/{napi-v3/linux/arm64/libonnxruntime.so.1.21.0 → napi-v6/win32/x64/dxcompiler.dll} +0 -0
- package/bin/napi-v6/win32/x64/dxil.dll +0 -0
- package/bin/{napi-v3/win32/arm64 → napi-v6/win32/x64}/onnxruntime.dll +0 -0
- package/bin/napi-v6/win32/x64/onnxruntime_binding.node +0 -0
- package/dist/backend.js +71 -2
- package/dist/backend.js.map +1 -1
- package/dist/binding.d.ts +9 -2
- package/dist/binding.js +1 -1
- package/dist/binding.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/lib/backend.ts +79 -2
- package/lib/binding.ts +10 -3
- package/lib/version.ts +1 -1
- package/package.json +4 -6
- package/script/build.js +92 -69
- package/script/install-metadata-versions.js +12 -0
- package/script/install-metadata.js +58 -0
- package/script/install-utils.js +306 -0
- package/script/install.js +94 -159
- package/script/prepack.js +49 -32
- package/bin/napi-v3/darwin/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/darwin/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/linux/x64/libonnxruntime_providers_shared.so +0 -0
- package/bin/napi-v3/linux/x64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/arm64/onnxruntime_binding.node +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime.dll +0 -0
- package/bin/napi-v3/win32/x64/onnxruntime_binding.node +0 -0
package/script/install.js
CHANGED
|
@@ -8,22 +8,20 @@
|
|
|
8
8
|
// not always available.
|
|
9
9
|
|
|
10
10
|
// The purpose of this script is to download the required binaries for the platform and architecture.
|
|
11
|
-
// Currently, most of the binaries are already bundled in the package, except for the
|
|
12
|
-
// -
|
|
13
|
-
// - Linux/x64/CUDA 12
|
|
11
|
+
// Currently, most of the binaries are already bundled in the package, except for the files that described in the file
|
|
12
|
+
// install-metadata.js.
|
|
14
13
|
//
|
|
15
|
-
//
|
|
16
|
-
// downloaded from the
|
|
17
|
-
//
|
|
14
|
+
// Some files (eg. the CUDA EP binaries) are not bundled because they are too large to be allowed in the npm registry.
|
|
15
|
+
// Instead, they are downloaded from the Nuget feed. The script will download the binaries if they are not already
|
|
16
|
+
// present in the NPM package.
|
|
18
17
|
|
|
19
18
|
// Step.1: Check if we should exit early
|
|
20
19
|
const os = require('os');
|
|
21
|
-
const fs = require('fs');
|
|
22
|
-
const https = require('https');
|
|
23
20
|
const path = require('path');
|
|
24
|
-
const tar = require('tar');
|
|
25
|
-
const { execFileSync } = require('child_process');
|
|
26
21
|
const { bootstrap: globalAgentBootstrap } = require('global-agent');
|
|
22
|
+
const { installPackages, parseInstallFlag } = require('./install-utils.js');
|
|
23
|
+
|
|
24
|
+
const INSTALL_METADATA = require('./install-metadata.js');
|
|
27
25
|
|
|
28
26
|
// Bootstrap global-agent to honor the proxy settings in
|
|
29
27
|
// environment variables, e.g. GLOBAL_AGENT_HTTPS_PROXY.
|
|
@@ -31,169 +29,106 @@ const { bootstrap: globalAgentBootstrap } = require('global-agent');
|
|
|
31
29
|
globalAgentBootstrap();
|
|
32
30
|
|
|
33
31
|
// commandline flag:
|
|
34
|
-
//
|
|
35
|
-
// --onnxruntime-node-install
|
|
36
|
-
//
|
|
32
|
+
//
|
|
33
|
+
// --onnxruntime-node-install Force install the files that are not bundled in the package.
|
|
34
|
+
//
|
|
35
|
+
// --onnxruntime-node-install=skip Skip the installation of the files that are not bundled in the package.
|
|
36
|
+
//
|
|
37
|
+
// --onnxruntime-node-install=cuda12 Force install the CUDA EP binaries for CUDA 12.
|
|
38
|
+
//
|
|
39
|
+
// --onnxruntime-node-install-cuda Force install the CUDA EP binaries.
|
|
40
|
+
// (deprecated, use --onnxruntime-node-install=cuda12)
|
|
41
|
+
//
|
|
37
42
|
// --onnxruntime-node-install-cuda=skip Skip the installation of the CUDA EP binaries.
|
|
43
|
+
// (deprecated, use --onnxruntime-node-install=skip)
|
|
38
44
|
//
|
|
39
|
-
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL_CUDA"
|
|
40
45
|
//
|
|
41
|
-
//
|
|
42
|
-
// - The platform is Linux/x64.
|
|
43
|
-
// - The binaries are not already present in the package.
|
|
44
|
-
// - The installation is not a local install (when used inside ONNX Runtime repo).
|
|
46
|
+
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL" or "ONNXRUNTIME_NODE_INSTALL_CUDA" (deprecated).
|
|
45
47
|
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
// If the flag is not provided, the script will look up the metadata file to determine the manifest.
|
|
49
|
+
//
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Possible values:
|
|
53
|
+
* - undefined: the default behavior. This is the value when no installation flag is specified.
|
|
54
|
+
*
|
|
55
|
+
* - false: skip installation. This is the value when the installation flag is set to "skip":
|
|
56
|
+
* --onnxruntime-node-install=skip
|
|
57
|
+
*
|
|
58
|
+
* - true: force installation. This is the value when the installation flag is set with no value:
|
|
59
|
+
* --onnxruntime-node-install
|
|
60
|
+
*
|
|
61
|
+
* - string: the installation flag is set to a specific value:
|
|
62
|
+
* --onnxruntime-node-install=cuda12
|
|
63
|
+
*/
|
|
64
|
+
const INSTALL_FLAG = parseInstallFlag();
|
|
65
|
+
|
|
66
|
+
// if installation is skipped, exit early
|
|
67
|
+
if (INSTALL_FLAG === false) {
|
|
63
68
|
process.exit(0);
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
1. Use "--onnxruntime-node-install-cuda=skip" to skip the auto installation.
|
|
75
|
-
2. Navigate to https://aiinfra.visualstudio.com/PublicPackages/_artifacts/feed/onnxruntime-cuda-11
|
|
76
|
-
3. Download the binaries for your platform and architecture
|
|
77
|
-
4. Extract the following binaries to "node_modules/onnxruntime-node/bin/napi-v3/linux/x64:
|
|
78
|
-
- libonnxruntime_providers_tensorrt.so
|
|
79
|
-
- libonnxruntime_providers_shared.so
|
|
80
|
-
- libonnxruntime.so.${ORT_VERSION}
|
|
81
|
-
- libonnxruntime_providers_cuda.so
|
|
82
|
-
`);
|
|
83
|
-
},
|
|
84
|
-
12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${
|
|
85
|
-
ORT_VERSION
|
|
86
|
-
}.tgz`,
|
|
87
|
-
}[INSTALL_CUDA_FLAG || tryGetCudaVersion()];
|
|
88
|
-
console.log(`Downloading "${artifactUrl}"...`);
|
|
89
|
-
|
|
90
|
-
const FILES = new Set([
|
|
91
|
-
'libonnxruntime_providers_tensorrt.so',
|
|
92
|
-
'libonnxruntime_providers_shared.so',
|
|
93
|
-
`libonnxruntime.so.${ORT_VERSION}`,
|
|
94
|
-
'libonnxruntime_providers_cuda.so',
|
|
95
|
-
]);
|
|
96
|
-
|
|
97
|
-
downloadAndExtract(artifactUrl, BIN_FOLDER, FILES);
|
|
98
|
-
|
|
99
|
-
async function downloadAndExtract(url, dest, files) {
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
https.get(url, (res) => {
|
|
102
|
-
const { statusCode } = res;
|
|
103
|
-
const contentType = res.headers['content-type'];
|
|
104
|
-
|
|
105
|
-
if (statusCode === 301 || statusCode === 302) {
|
|
106
|
-
downloadAndExtract(res.headers.location, dest, files).then(
|
|
107
|
-
(value) => resolve(value),
|
|
108
|
-
(reason) => reject(reason),
|
|
109
|
-
);
|
|
110
|
-
return;
|
|
111
|
-
} else if (statusCode !== 200) {
|
|
112
|
-
throw new Error(`Failed to download the binaries: ${res.statusCode} ${res.statusMessage}.
|
|
113
|
-
|
|
114
|
-
Use "--onnxruntime-node-install-cuda=skip" to skip the installation. You will still be able to use ONNX Runtime, but the CUDA EP will not be available.`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!contentType || !/^application\/octet-stream/.test(contentType)) {
|
|
118
|
-
throw new Error(`unexpected content type: ${contentType}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
res
|
|
122
|
-
.pipe(
|
|
123
|
-
tar.t({
|
|
124
|
-
strict: true,
|
|
125
|
-
onentry: (entry) => {
|
|
126
|
-
const filename = path.basename(entry.path);
|
|
127
|
-
if (entry.type === 'File' && files.has(filename)) {
|
|
128
|
-
console.log(`Extracting "${filename}" to "${dest}"...`);
|
|
129
|
-
entry.pipe(fs.createWriteStream(path.join(dest, filename)));
|
|
130
|
-
entry.on('finish', () => {
|
|
131
|
-
console.log(`Finished extracting "${filename}".`);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
}),
|
|
136
|
-
)
|
|
137
|
-
.on('error', (err) => {
|
|
138
|
-
throw new Error(`Failed to extract the binaries: ${err.message}.
|
|
139
|
-
|
|
140
|
-
Use "--onnxruntime-node-install-cuda=skip" to skip the installation. You will still be able to use ONNX Runtime, but the CUDA EP will not be available.`);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
70
|
+
// if installation is not specified, exit early when the installation is local (e.g. `npm ci` in <ORT_ROOT>/js/node/)
|
|
71
|
+
if (INSTALL_FLAG === undefined) {
|
|
72
|
+
const npm_config_local_prefix = process.env.npm_config_local_prefix;
|
|
73
|
+
const npm_package_json = process.env.npm_package_json;
|
|
74
|
+
const IS_LOCAL_INSTALL =
|
|
75
|
+
npm_config_local_prefix && npm_package_json && path.dirname(npm_package_json) === npm_config_local_prefix;
|
|
76
|
+
if (IS_LOCAL_INSTALL) {
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
144
79
|
}
|
|
145
80
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
ver = parseInt(match[1]);
|
|
156
|
-
if (ver !== 11 && ver !== 12) {
|
|
157
|
-
throw new Error(`Unsupported CUDA version: ${ver}`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
} catch (e) {
|
|
161
|
-
if (e?.code === 'ENOENT') {
|
|
162
|
-
console.warn('`nvcc` not found. Assuming CUDA 12.');
|
|
163
|
-
} else {
|
|
164
|
-
console.warn('Failed to detect CUDA version from `nvcc --version`:', e.message);
|
|
81
|
+
const PLATFORM = `${os.platform()}/${os.arch()}`;
|
|
82
|
+
let INSTALL_MANIFEST_NAMES = INSTALL_METADATA.requirements[PLATFORM] ?? [];
|
|
83
|
+
|
|
84
|
+
// if installation is specified explicitly, validate the manifest
|
|
85
|
+
if (typeof INSTALL_FLAG === 'string') {
|
|
86
|
+
const installations = INSTALL_FLAG.split(',').map((x) => x.trim());
|
|
87
|
+
for (const installation of installations) {
|
|
88
|
+
if (INSTALL_MANIFEST_NAMES.indexOf(installation) === -1) {
|
|
89
|
+
throw new Error(`Invalid installation: ${installation} for platform: ${PLATFORM}`);
|
|
165
90
|
}
|
|
166
91
|
}
|
|
92
|
+
INSTALL_MANIFEST_NAMES = installations;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const BIN_FOLDER = path.join(__dirname, '..', 'bin/napi-v6', PLATFORM);
|
|
96
|
+
const INSTALL_MANIFESTS = [];
|
|
97
|
+
|
|
98
|
+
const PACKAGES = new Set();
|
|
99
|
+
for (const name of INSTALL_MANIFEST_NAMES) {
|
|
100
|
+
const manifest = INSTALL_METADATA.manifests[`${PLATFORM}:${name}`];
|
|
101
|
+
if (!manifest) {
|
|
102
|
+
throw new Error(`Manifest not found: ${name} for platform: ${PLATFORM}`);
|
|
103
|
+
}
|
|
167
104
|
|
|
168
|
-
|
|
169
|
-
|
|
105
|
+
for (const [filename, { package: pkg, path: pathInPackage }] of Object.entries(manifest)) {
|
|
106
|
+
const packageCandidates = INSTALL_METADATA.packages[pkg];
|
|
107
|
+
if (!packageCandidates) {
|
|
108
|
+
throw new Error(`Package information not found: ${pkg}`);
|
|
109
|
+
}
|
|
110
|
+
PACKAGES.add(packageCandidates);
|
|
111
|
+
|
|
112
|
+
INSTALL_MANIFESTS.push({
|
|
113
|
+
filepath: path.normalize(path.join(BIN_FOLDER, filename)),
|
|
114
|
+
packagesInfo: packageCandidates,
|
|
115
|
+
pathInPackage,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
170
118
|
}
|
|
171
119
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
} else if (process.argv[i] === '--onnxruntime-node-install-cuda') {
|
|
180
|
-
flag = 'true';
|
|
181
|
-
}
|
|
120
|
+
// If the installation flag is not specified, we do a check to see if the files are already installed.
|
|
121
|
+
if (INSTALL_FLAG === undefined) {
|
|
122
|
+
let hasMissingFiles = false;
|
|
123
|
+
for (const { filepath } of INSTALL_MANIFESTS) {
|
|
124
|
+
if (!require('fs').existsSync(filepath)) {
|
|
125
|
+
hasMissingFiles = true;
|
|
126
|
+
break;
|
|
182
127
|
}
|
|
183
128
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
case '1':
|
|
187
|
-
case 'ON':
|
|
188
|
-
return tryGetCudaVersion();
|
|
189
|
-
case 'v11':
|
|
190
|
-
return 11;
|
|
191
|
-
case 'v12':
|
|
192
|
-
return 12;
|
|
193
|
-
case 'skip':
|
|
194
|
-
case undefined:
|
|
195
|
-
return flag;
|
|
196
|
-
default:
|
|
197
|
-
throw new Error(`Invalid value for --onnxruntime-node-install-cuda: ${flag}`);
|
|
129
|
+
if (!hasMissingFiles) {
|
|
130
|
+
process.exit(0);
|
|
198
131
|
}
|
|
199
132
|
}
|
|
133
|
+
|
|
134
|
+
void installPackages(PACKAGES, INSTALL_MANIFESTS, INSTALL_METADATA.feeds);
|
package/script/prepack.js
CHANGED
|
@@ -1,42 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
|
-
var __createBinding =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
4
|
+
var __createBinding =
|
|
5
|
+
(this && this.__createBinding) ||
|
|
6
|
+
(Object.create
|
|
7
|
+
? function (o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return m[k];
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}
|
|
20
|
+
: function (o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
});
|
|
24
|
+
var __setModuleDefault =
|
|
25
|
+
(this && this.__setModuleDefault) ||
|
|
26
|
+
(Object.create
|
|
27
|
+
? function (o, v) {
|
|
28
|
+
Object.defineProperty(o, 'default', { enumerable: true, value: v });
|
|
29
|
+
}
|
|
30
|
+
: function (o, v) {
|
|
31
|
+
o['default'] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar =
|
|
34
|
+
(this && this.__importStar) ||
|
|
35
|
+
function (mod) {
|
|
21
36
|
if (mod && mod.__esModule) return mod;
|
|
22
37
|
var result = {};
|
|
23
|
-
if (mod != null)
|
|
38
|
+
if (mod != null)
|
|
39
|
+
for (var k in mod)
|
|
40
|
+
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
41
|
__setModuleDefault(result, mod);
|
|
25
42
|
return result;
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports,
|
|
28
|
-
const fs = __importStar(require(
|
|
29
|
-
const path = __importStar(require(
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
45
|
+
const fs = __importStar(require('fs-extra'));
|
|
46
|
+
const path = __importStar(require('path'));
|
|
30
47
|
function updatePackageJson() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
|
|
49
|
+
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
50
|
+
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
|
|
51
|
+
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
|
|
52
|
+
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
|
|
53
|
+
const version = packageCommon.version;
|
|
54
|
+
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
|
|
55
|
+
fs.writeJSONSync(selfPackageJsonPath, packageSelf, { spaces: 2 });
|
|
56
|
+
console.log('=== finished updating package.json.');
|
|
40
57
|
}
|
|
41
58
|
// update version of dependency "onnxruntime-common" before packing
|
|
42
59
|
updatePackageJson();
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|