|
1 |
| -/* tslint:disable */ |
2 |
| -/* eslint-disable */ |
3 |
| -/* prettier-ignore */ |
| 1 | +const { existsSync, readFileSync } = require('fs'); |
| 2 | +const { join } = require('path'); |
4 | 3 |
|
5 |
| -/* auto-generated by NAPI-RS */ |
| 4 | +const { platform, arch } = process; |
6 | 5 |
|
7 |
| -const { existsSync, readFileSync } = require('fs') |
8 |
| -const { join } = require('path') |
9 |
| - |
10 |
| -const { platform, arch } = process |
11 |
| - |
12 |
| -let nativeBinding = null |
13 |
| -let localFileExisted = false |
14 |
| -let loadError = null |
| 6 | +let nativeBinding = null; |
| 7 | +let localFileExisted = false; |
| 8 | +let loadError = null; |
15 | 9 |
|
16 | 10 | function isMusl() {
|
17 | 11 | // For Node 10
|
18 | 12 | if (!process.report || typeof process.report.getReport !== 'function') {
|
19 | 13 | try {
|
20 |
| - const lddPath = require('child_process').execSync('which ldd').toString().trim() |
21 |
| - return readFileSync(lddPath, 'utf8').includes('musl') |
| 14 | + return readFileSync('/usr/bin/ldd', 'utf8').includes('musl'); |
22 | 15 | } catch (e) {
|
23 |
| - return true |
| 16 | + return true; |
24 | 17 | }
|
25 | 18 | } else {
|
26 |
| - const { glibcVersionRuntime } = process.report.getReport().header |
27 |
| - return !glibcVersionRuntime |
| 19 | + const { glibcVersionRuntime } = process.report.getReport().header; |
| 20 | + return !glibcVersionRuntime; |
28 | 21 | }
|
29 | 22 | }
|
30 | 23 |
|
31 | 24 | switch (platform) {
|
32 |
| - case 'android': |
33 |
| - switch (arch) { |
34 |
| - case 'arm64': |
35 |
| - localFileExisted = existsSync(join(__dirname, 'zstd.android-arm64.node')) |
36 |
| - try { |
37 |
| - if (localFileExisted) { |
38 |
| - nativeBinding = require('./zstd.android-arm64.node') |
39 |
| - } else { |
40 |
| - nativeBinding = require('@mongodb-js/zstd-android-arm64') |
41 |
| - } |
42 |
| - } catch (e) { |
43 |
| - loadError = e |
44 |
| - } |
45 |
| - break |
46 |
| - case 'arm': |
47 |
| - localFileExisted = existsSync(join(__dirname, 'zstd.android-arm-eabi.node')) |
48 |
| - try { |
49 |
| - if (localFileExisted) { |
50 |
| - nativeBinding = require('./zstd.android-arm-eabi.node') |
51 |
| - } else { |
52 |
| - nativeBinding = require('@mongodb-js/zstd-android-arm-eabi') |
53 |
| - } |
54 |
| - } catch (e) { |
55 |
| - loadError = e |
56 |
| - } |
57 |
| - break |
58 |
| - default: |
59 |
| - throw new Error(`Unsupported architecture on Android ${arch}`) |
60 |
| - } |
61 |
| - break |
62 | 25 | case 'win32':
|
63 | 26 | switch (arch) {
|
64 | 27 | case 'x64':
|
65 |
| - localFileExisted = existsSync( |
66 |
| - join(__dirname, 'zstd.win32-x64-msvc.node') |
67 |
| - ) |
| 28 | + localFileExisted = existsSync(join(__dirname, 'zstd.win32-x64-msvc.node')); |
68 | 29 | try {
|
69 | 30 | if (localFileExisted) {
|
70 |
| - nativeBinding = require('./zstd.win32-x64-msvc.node') |
| 31 | + nativeBinding = require('./zstd.win32-x64-msvc.node'); |
71 | 32 | } else {
|
72 |
| - nativeBinding = require('@mongodb-js/zstd-win32-x64-msvc') |
| 33 | + nativeBinding = require('@mongodb-js/zstd-win32-x64-msvc'); |
73 | 34 | }
|
74 | 35 | } catch (e) {
|
75 |
| - loadError = e |
| 36 | + loadError = e; |
76 | 37 | }
|
77 |
| - break |
78 |
| - case 'ia32': |
79 |
| - localFileExisted = existsSync( |
80 |
| - join(__dirname, 'zstd.win32-ia32-msvc.node') |
81 |
| - ) |
82 |
| - try { |
83 |
| - if (localFileExisted) { |
84 |
| - nativeBinding = require('./zstd.win32-ia32-msvc.node') |
85 |
| - } else { |
86 |
| - nativeBinding = require('@mongodb-js/zstd-win32-ia32-msvc') |
87 |
| - } |
88 |
| - } catch (e) { |
89 |
| - loadError = e |
90 |
| - } |
91 |
| - break |
92 |
| - case 'arm64': |
93 |
| - localFileExisted = existsSync( |
94 |
| - join(__dirname, 'zstd.win32-arm64-msvc.node') |
95 |
| - ) |
96 |
| - try { |
97 |
| - if (localFileExisted) { |
98 |
| - nativeBinding = require('./zstd.win32-arm64-msvc.node') |
99 |
| - } else { |
100 |
| - nativeBinding = require('@mongodb-js/zstd-win32-arm64-msvc') |
101 |
| - } |
102 |
| - } catch (e) { |
103 |
| - loadError = e |
104 |
| - } |
105 |
| - break |
| 38 | + break; |
106 | 39 | default:
|
107 |
| - throw new Error(`Unsupported architecture on Windows: ${arch}`) |
| 40 | + throw new Error(`Unsupported architecture on Windows: ${arch}`); |
108 | 41 | }
|
109 |
| - break |
| 42 | + break; |
110 | 43 | case 'darwin':
|
111 |
| - localFileExisted = existsSync(join(__dirname, 'zstd.darwin-universal.node')) |
112 |
| - try { |
113 |
| - if (localFileExisted) { |
114 |
| - nativeBinding = require('./zstd.darwin-universal.node') |
115 |
| - } else { |
116 |
| - nativeBinding = require('@mongodb-js/zstd-darwin-universal') |
117 |
| - } |
118 |
| - break |
119 |
| - } catch {} |
120 | 44 | switch (arch) {
|
121 | 45 | case 'x64':
|
122 |
| - localFileExisted = existsSync(join(__dirname, 'zstd.darwin-x64.node')) |
| 46 | + localFileExisted = existsSync(join(__dirname, 'zstd.darwin-x64.node')); |
123 | 47 | try {
|
124 | 48 | if (localFileExisted) {
|
125 |
| - nativeBinding = require('./zstd.darwin-x64.node') |
| 49 | + nativeBinding = require('./zstd.darwin-x64.node'); |
126 | 50 | } else {
|
127 |
| - nativeBinding = require('@mongodb-js/zstd-darwin-x64') |
| 51 | + nativeBinding = require('@mongodb-js/zstd-darwin-x64'); |
128 | 52 | }
|
129 | 53 | } catch (e) {
|
130 |
| - loadError = e |
| 54 | + loadError = e; |
131 | 55 | }
|
132 |
| - break |
| 56 | + break; |
133 | 57 | case 'arm64':
|
134 |
| - localFileExisted = existsSync( |
135 |
| - join(__dirname, 'zstd.darwin-arm64.node') |
136 |
| - ) |
| 58 | + localFileExisted = existsSync(join(__dirname, 'zstd.darwin-arm64.node')); |
137 | 59 | try {
|
138 | 60 | if (localFileExisted) {
|
139 |
| - nativeBinding = require('./zstd.darwin-arm64.node') |
| 61 | + nativeBinding = require('./zstd.darwin-arm64.node'); |
140 | 62 | } else {
|
141 |
| - nativeBinding = require('@mongodb-js/zstd-darwin-arm64') |
| 63 | + nativeBinding = require('@mongodb-js/zstd-darwin-arm64'); |
142 | 64 | }
|
143 | 65 | } catch (e) {
|
144 |
| - loadError = e |
| 66 | + loadError = e; |
145 | 67 | }
|
146 |
| - break |
| 68 | + break; |
147 | 69 | default:
|
148 |
| - throw new Error(`Unsupported architecture on macOS: ${arch}`) |
149 |
| - } |
150 |
| - break |
151 |
| - case 'freebsd': |
152 |
| - if (arch !== 'x64') { |
153 |
| - throw new Error(`Unsupported architecture on FreeBSD: ${arch}`) |
| 70 | + throw new Error(`Unsupported architecture on macOS: ${arch}`); |
154 | 71 | }
|
155 |
| - localFileExisted = existsSync(join(__dirname, 'zstd.freebsd-x64.node')) |
156 |
| - try { |
157 |
| - if (localFileExisted) { |
158 |
| - nativeBinding = require('./zstd.freebsd-x64.node') |
159 |
| - } else { |
160 |
| - nativeBinding = require('@mongodb-js/zstd-freebsd-x64') |
161 |
| - } |
162 |
| - } catch (e) { |
163 |
| - loadError = e |
164 |
| - } |
165 |
| - break |
| 72 | + break; |
166 | 73 | case 'linux':
|
167 | 74 | switch (arch) {
|
168 | 75 | case 'x64':
|
169 | 76 | if (isMusl()) {
|
170 |
| - localFileExisted = existsSync( |
171 |
| - join(__dirname, 'zstd.linux-x64-musl.node') |
172 |
| - ) |
| 77 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-x64-musl.node')); |
173 | 78 | try {
|
174 | 79 | if (localFileExisted) {
|
175 |
| - nativeBinding = require('./zstd.linux-x64-musl.node') |
| 80 | + nativeBinding = require('./zstd.linux-x64-musl.node'); |
176 | 81 | } else {
|
177 |
| - nativeBinding = require('@mongodb-js/zstd-linux-x64-musl') |
| 82 | + nativeBinding = require('@mongodb-js/zstd-linux-x64-musl'); |
178 | 83 | }
|
179 | 84 | } catch (e) {
|
180 |
| - loadError = e |
| 85 | + loadError = e; |
181 | 86 | }
|
182 | 87 | } else {
|
183 |
| - localFileExisted = existsSync( |
184 |
| - join(__dirname, 'zstd.linux-x64-gnu.node') |
185 |
| - ) |
| 88 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-x64-gnu.node')); |
186 | 89 | try {
|
187 | 90 | if (localFileExisted) {
|
188 |
| - nativeBinding = require('./zstd.linux-x64-gnu.node') |
| 91 | + nativeBinding = require('./zstd.linux-x64-gnu.node'); |
189 | 92 | } else {
|
190 |
| - nativeBinding = require('@mongodb-js/zstd-linux-x64-gnu') |
| 93 | + nativeBinding = require('@mongodb-js/zstd-linux-x64-gnu'); |
191 | 94 | }
|
192 | 95 | } catch (e) {
|
193 |
| - loadError = e |
| 96 | + loadError = e; |
194 | 97 | }
|
195 | 98 | }
|
196 |
| - break |
| 99 | + break; |
197 | 100 | case 'arm64':
|
198 | 101 | if (isMusl()) {
|
199 |
| - localFileExisted = existsSync( |
200 |
| - join(__dirname, 'zstd.linux-arm64-musl.node') |
201 |
| - ) |
| 102 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-arm64-musl.node')); |
202 | 103 | try {
|
203 | 104 | if (localFileExisted) {
|
204 |
| - nativeBinding = require('./zstd.linux-arm64-musl.node') |
| 105 | + nativeBinding = require('./zstd.linux-arm64-musl.node'); |
205 | 106 | } else {
|
206 |
| - nativeBinding = require('@mongodb-js/zstd-linux-arm64-musl') |
| 107 | + nativeBinding = require('@mongodb-js/zstd-linux-arm64-musl'); |
207 | 108 | }
|
208 | 109 | } catch (e) {
|
209 |
| - loadError = e |
| 110 | + loadError = e; |
210 | 111 | }
|
211 | 112 | } else {
|
212 |
| - localFileExisted = existsSync( |
213 |
| - join(__dirname, 'zstd.linux-arm64-gnu.node') |
214 |
| - ) |
| 113 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-arm64-gnu.node')); |
215 | 114 | try {
|
216 | 115 | if (localFileExisted) {
|
217 |
| - nativeBinding = require('./zstd.linux-arm64-gnu.node') |
| 116 | + nativeBinding = require('./zstd.linux-arm64-gnu.node'); |
218 | 117 | } else {
|
219 |
| - nativeBinding = require('@mongodb-js/zstd-linux-arm64-gnu') |
| 118 | + nativeBinding = require('@mongodb-js/zstd-linux-arm64-gnu'); |
220 | 119 | }
|
221 | 120 | } catch (e) {
|
222 |
| - loadError = e |
| 121 | + loadError = e; |
223 | 122 | }
|
224 | 123 | }
|
225 |
| - break |
| 124 | + break; |
226 | 125 | case 'arm':
|
227 |
| - if (isMusl()) { |
228 |
| - localFileExisted = existsSync( |
229 |
| - join(__dirname, 'zstd.linux-arm-musleabihf.node') |
230 |
| - ) |
231 |
| - try { |
232 |
| - if (localFileExisted) { |
233 |
| - nativeBinding = require('./zstd.linux-arm-musleabihf.node') |
234 |
| - } else { |
235 |
| - nativeBinding = require('@mongodb-js/zstd-linux-arm-musleabihf') |
236 |
| - } |
237 |
| - } catch (e) { |
238 |
| - loadError = e |
239 |
| - } |
240 |
| - } else { |
241 |
| - localFileExisted = existsSync( |
242 |
| - join(__dirname, 'zstd.linux-arm-gnueabihf.node') |
243 |
| - ) |
244 |
| - try { |
245 |
| - if (localFileExisted) { |
246 |
| - nativeBinding = require('./zstd.linux-arm-gnueabihf.node') |
247 |
| - } else { |
248 |
| - nativeBinding = require('@mongodb-js/zstd-linux-arm-gnueabihf') |
249 |
| - } |
250 |
| - } catch (e) { |
251 |
| - loadError = e |
252 |
| - } |
253 |
| - } |
254 |
| - break |
255 |
| - case 'riscv64': |
256 |
| - if (isMusl()) { |
257 |
| - localFileExisted = existsSync( |
258 |
| - join(__dirname, 'zstd.linux-riscv64-musl.node') |
259 |
| - ) |
260 |
| - try { |
261 |
| - if (localFileExisted) { |
262 |
| - nativeBinding = require('./zstd.linux-riscv64-musl.node') |
263 |
| - } else { |
264 |
| - nativeBinding = require('@mongodb-js/zstd-linux-riscv64-musl') |
265 |
| - } |
266 |
| - } catch (e) { |
267 |
| - loadError = e |
268 |
| - } |
269 |
| - } else { |
270 |
| - localFileExisted = existsSync( |
271 |
| - join(__dirname, 'zstd.linux-riscv64-gnu.node') |
272 |
| - ) |
273 |
| - try { |
274 |
| - if (localFileExisted) { |
275 |
| - nativeBinding = require('./zstd.linux-riscv64-gnu.node') |
276 |
| - } else { |
277 |
| - nativeBinding = require('@mongodb-js/zstd-linux-riscv64-gnu') |
278 |
| - } |
279 |
| - } catch (e) { |
280 |
| - loadError = e |
281 |
| - } |
282 |
| - } |
283 |
| - break |
284 |
| - case 's390x': |
285 |
| - localFileExisted = existsSync( |
286 |
| - join(__dirname, 'zstd.linux-s390x-gnu.node') |
287 |
| - ) |
| 126 | + localFileExisted = existsSync(join(__dirname, 'zstd.linux-arm-gnueabihf.node')); |
288 | 127 | try {
|
289 | 128 | if (localFileExisted) {
|
290 |
| - nativeBinding = require('./zstd.linux-s390x-gnu.node') |
| 129 | + nativeBinding = require('./zstd.linux-arm-gnueabihf.node'); |
291 | 130 | } else {
|
292 |
| - nativeBinding = require('@mongodb-js/zstd-linux-s390x-gnu') |
| 131 | + nativeBinding = require('@mongodb-js/zstd-linux-arm-gnueabihf'); |
293 | 132 | }
|
294 | 133 | } catch (e) {
|
295 |
| - loadError = e |
| 134 | + loadError = e; |
296 | 135 | }
|
297 |
| - break |
| 136 | + break; |
298 | 137 | default:
|
299 |
| - throw new Error(`Unsupported architecture on Linux: ${arch}`) |
| 138 | + throw new Error(`Unsupported architecture on Linux: ${arch}`); |
300 | 139 | }
|
301 |
| - break |
| 140 | + break; |
302 | 141 | default:
|
303 |
| - throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) |
| 142 | + throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`); |
304 | 143 | }
|
305 | 144 |
|
306 | 145 | if (!nativeBinding) {
|
307 | 146 | if (loadError) {
|
308 |
| - throw loadError |
| 147 | + throw loadError; |
309 | 148 | }
|
310 |
| - throw new Error(`Failed to load native binding`) |
| 149 | + throw new Error(`Failed to load native binding`); |
311 | 150 | }
|
312 | 151 |
|
313 |
| -const { compress, decompress } = nativeBinding |
| 152 | +const { compress, decompress } = nativeBinding; |
314 | 153 |
|
315 |
| -module.exports.compress = compress |
316 |
| -module.exports.decompress = decompress |
| 154 | +module.exports.compress = compress; |
| 155 | +module.exports.decompress = decompress; |
0 commit comments