@@ -35,7 +35,11 @@ const isMuslFromFilesystem = () => {
35
35
}
36
36
37
37
const isMuslFromReport = ( ) => {
38
- const report = typeof process . report . getReport === 'function' ? process . report . getReport ( ) : null
38
+ let report = null
39
+ if ( typeof process . report ?. getReport === 'function' ) {
40
+ process . report . excludeNetwork = true
41
+ report = process . report . getReport ( )
42
+ }
39
43
if ( ! report ) {
40
44
return null
41
45
}
@@ -64,7 +68,7 @@ function requireNative() {
64
68
try {
65
69
nativeBinding = require ( process . env . NAPI_RS_NATIVE_LIBRARY_PATH ) ;
66
70
} catch ( err ) {
67
- loadErrors . push ( err ) ;
71
+ loadErrors . push ( err )
68
72
}
69
73
} else if ( process . platform === 'android' ) {
70
74
if ( process . arch === 'arm64' ) {
@@ -78,7 +82,6 @@ function requireNative() {
78
82
} catch ( e ) {
79
83
loadErrors . push ( e )
80
84
}
81
-
82
85
} else if ( process . arch === 'arm' ) {
83
86
try {
84
87
return require ( './package-template.android-arm-eabi.node' )
@@ -90,7 +93,6 @@ function requireNative() {
90
93
} catch ( e ) {
91
94
loadErrors . push ( e )
92
95
}
93
-
94
96
} else {
95
97
loadErrors . push ( new Error ( `Unsupported architecture on Android ${ process . arch } ` ) )
96
98
}
@@ -106,7 +108,6 @@ function requireNative() {
106
108
} catch ( e ) {
107
109
loadErrors . push ( e )
108
110
}
109
-
110
111
} else if ( process . arch === 'ia32' ) {
111
112
try {
112
113
return require ( './package-template.win32-ia32-msvc.node' )
@@ -118,7 +119,6 @@ function requireNative() {
118
119
} catch ( e ) {
119
120
loadErrors . push ( e )
120
121
}
121
-
122
122
} else if ( process . arch === 'arm64' ) {
123
123
try {
124
124
return require ( './package-template.win32-arm64-msvc.node' )
@@ -130,22 +130,20 @@ function requireNative() {
130
130
} catch ( e ) {
131
131
loadErrors . push ( e )
132
132
}
133
-
134
133
} else {
135
134
loadErrors . push ( new Error ( `Unsupported architecture on Windows: ${ process . arch } ` ) )
136
135
}
137
136
} else if ( process . platform === 'darwin' ) {
138
137
try {
139
- return require ( './package-template.darwin-universal.node' )
140
- } catch ( e ) {
141
- loadErrors . push ( e )
142
- }
143
- try {
144
- return require ( '@napi-rs/package-template-pnpm-darwin-universal' )
145
- } catch ( e ) {
146
- loadErrors . push ( e )
147
- }
148
-
138
+ return require ( './package-template.darwin-universal.node' )
139
+ } catch ( e ) {
140
+ loadErrors . push ( e )
141
+ }
142
+ try {
143
+ return require ( '@napi-rs/package-template-pnpm-darwin-universal' )
144
+ } catch ( e ) {
145
+ loadErrors . push ( e )
146
+ }
149
147
if ( process . arch === 'x64' ) {
150
148
try {
151
149
return require ( './package-template.darwin-x64.node' )
@@ -157,7 +155,6 @@ function requireNative() {
157
155
} catch ( e ) {
158
156
loadErrors . push ( e )
159
157
}
160
-
161
158
} else if ( process . arch === 'arm64' ) {
162
159
try {
163
160
return require ( './package-template.darwin-arm64.node' )
@@ -169,7 +166,6 @@ function requireNative() {
169
166
} catch ( e ) {
170
167
loadErrors . push ( e )
171
168
}
172
-
173
169
} else {
174
170
loadErrors . push ( new Error ( `Unsupported architecture on macOS: ${ process . arch } ` ) )
175
171
}
@@ -185,7 +181,6 @@ function requireNative() {
185
181
} catch ( e ) {
186
182
loadErrors . push ( e )
187
183
}
188
-
189
184
} else if ( process . arch === 'arm64' ) {
190
185
try {
191
186
return require ( './package-template.freebsd-arm64.node' )
@@ -197,141 +192,167 @@ function requireNative() {
197
192
} catch ( e ) {
198
193
loadErrors . push ( e )
199
194
}
200
-
201
195
} else {
202
196
loadErrors . push ( new Error ( `Unsupported architecture on FreeBSD: ${ process . arch } ` ) )
203
197
}
204
198
} else if ( process . platform === 'linux' ) {
205
199
if ( process . arch === 'x64' ) {
206
200
if ( isMusl ( ) ) {
207
201
try {
208
- return require ( './package-template.linux-x64-musl.node' )
209
- } catch ( e ) {
210
- loadErrors . push ( e )
211
- }
212
- try {
213
- return require ( '@napi-rs/package-template-pnpm-linux-x64-musl' )
214
- } catch ( e ) {
215
- loadErrors . push ( e )
216
- }
217
-
202
+ return require ( './package-template.linux-x64-musl.node' )
203
+ } catch ( e ) {
204
+ loadErrors . push ( e )
205
+ }
206
+ try {
207
+ return require ( '@napi-rs/package-template-pnpm-linux-x64-musl' )
208
+ } catch ( e ) {
209
+ loadErrors . push ( e )
210
+ }
218
211
} else {
219
212
try {
220
- return require ( './package-template.linux-x64-gnu.node' )
221
- } catch ( e ) {
222
- loadErrors . push ( e )
223
- }
224
- try {
225
- return require ( '@napi-rs/package-template-pnpm-linux-x64-gnu' )
226
- } catch ( e ) {
227
- loadErrors . push ( e )
228
- }
229
-
213
+ return require ( './package-template.linux-x64-gnu.node' )
214
+ } catch ( e ) {
215
+ loadErrors . push ( e )
216
+ }
217
+ try {
218
+ return require ( '@napi-rs/package-template-pnpm-linux-x64-gnu' )
219
+ } catch ( e ) {
220
+ loadErrors . push ( e )
221
+ }
230
222
}
231
223
} else if ( process . arch === 'arm64' ) {
232
224
if ( isMusl ( ) ) {
233
225
try {
234
- return require ( './package-template.linux-arm64-musl.node' )
235
- } catch ( e ) {
236
- loadErrors . push ( e )
237
- }
238
- try {
239
- return require ( '@napi-rs/package-template-pnpm-linux-arm64-musl' )
240
- } catch ( e ) {
241
- loadErrors . push ( e )
242
- }
243
-
226
+ return require ( './package-template.linux-arm64-musl.node' )
227
+ } catch ( e ) {
228
+ loadErrors . push ( e )
229
+ }
230
+ try {
231
+ return require ( '@napi-rs/package-template-pnpm-linux-arm64-musl' )
232
+ } catch ( e ) {
233
+ loadErrors . push ( e )
234
+ }
244
235
} else {
245
236
try {
246
- return require ( './package-template.linux-arm64-gnu.node' )
247
- } catch ( e ) {
248
- loadErrors . push ( e )
249
- }
250
- try {
251
- return require ( '@napi-rs/package-template-pnpm-linux-arm64-gnu' )
252
- } catch ( e ) {
253
- loadErrors . push ( e )
254
- }
255
-
237
+ return require ( './package-template.linux-arm64-gnu.node' )
238
+ } catch ( e ) {
239
+ loadErrors . push ( e )
240
+ }
241
+ try {
242
+ return require ( '@napi-rs/package-template-pnpm-linux-arm64-gnu' )
243
+ } catch ( e ) {
244
+ loadErrors . push ( e )
245
+ }
256
246
}
257
247
} else if ( process . arch === 'arm' ) {
258
248
if ( isMusl ( ) ) {
259
249
try {
260
- return require ( './package-template.linux-arm-musleabihf.node' )
261
- } catch ( e ) {
262
- loadErrors . push ( e )
263
- }
264
- try {
265
- return require ( '@napi-rs/package-template-pnpm-linux-arm-musleabihf' )
266
- } catch ( e ) {
267
- loadErrors . push ( e )
250
+ return require ( './package-template.linux-arm-musleabihf.node' )
251
+ } catch ( e ) {
252
+ loadErrors . push ( e )
253
+ }
254
+ try {
255
+ return require ( '@napi-rs/package-template-pnpm-linux-arm-musleabihf' )
256
+ } catch ( e ) {
257
+ loadErrors . push ( e )
258
+ }
259
+ } else {
260
+ try {
261
+ return require ( './package-template.linux-arm-gnueabihf.node' )
262
+ } catch ( e ) {
263
+ loadErrors . push ( e )
264
+ }
265
+ try {
266
+ return require ( '@napi-rs/package-template-pnpm-linux-arm-gnueabihf' )
267
+ } catch ( e ) {
268
+ loadErrors . push ( e )
269
+ }
268
270
}
269
-
271
+ } else if ( process . arch === 'riscv64' ) {
272
+ if ( isMusl ( ) ) {
273
+ try {
274
+ return require ( './package-template.linux-riscv64-musl.node' )
275
+ } catch ( e ) {
276
+ loadErrors . push ( e )
277
+ }
278
+ try {
279
+ return require ( '@napi-rs/package-template-pnpm-linux-riscv64-musl' )
280
+ } catch ( e ) {
281
+ loadErrors . push ( e )
282
+ }
270
283
} else {
271
284
try {
272
- return require ( './package-template.linux-arm-gnueabihf.node' )
285
+ return require ( './package-template.linux-riscv64-gnu.node' )
286
+ } catch ( e ) {
287
+ loadErrors . push ( e )
288
+ }
289
+ try {
290
+ return require ( '@napi-rs/package-template-pnpm-linux-riscv64-gnu' )
291
+ } catch ( e ) {
292
+ loadErrors . push ( e )
293
+ }
294
+ }
295
+ } else if ( process . arch === 'ppc64' ) {
296
+ try {
297
+ return require ( './package-template.linux-ppc64-gnu.node' )
273
298
} catch ( e ) {
274
299
loadErrors . push ( e )
275
300
}
276
301
try {
277
- return require ( '@napi-rs/package-template-pnpm-linux-arm-gnueabihf ' )
302
+ return require ( '@napi-rs/package-template-pnpm-linux-ppc64-gnu ' )
278
303
} catch ( e ) {
279
304
loadErrors . push ( e )
280
305
}
281
-
282
- }
283
- } else if ( process . arch === 'riscv64' ) {
284
- if ( isMusl ( ) ) {
285
- try {
286
- return require ( './package-template.linux-riscv64-musl.node' )
306
+ } else if ( process . arch === 's390x' ) {
307
+ try {
308
+ return require ( './package-template.linux-s390x-gnu.node' )
287
309
} catch ( e ) {
288
310
loadErrors . push ( e )
289
311
}
290
312
try {
291
- return require ( '@napi-rs/package-template-pnpm-linux-riscv64-musl ' )
313
+ return require ( '@napi-rs/package-template-pnpm-linux-s390x-gnu ' )
292
314
} catch ( e ) {
293
315
loadErrors . push ( e )
294
316
}
295
-
296
- } else {
297
- try {
298
- return require ( './package-template.linux-riscv64-gnu.node' )
317
+ } else {
318
+ loadErrors . push ( new Error ( `Unsupported architecture on Linux: ${ process . arch } ` ) )
319
+ }
320
+ } else if ( process . platform === 'openharmony' ) {
321
+ if ( process . arch === 'arm64' ) {
322
+ try {
323
+ return require ( './package-template.linux-arm64-ohos.node' )
299
324
} catch ( e ) {
300
325
loadErrors . push ( e )
301
326
}
302
327
try {
303
- return require ( '@napi-rs/package-template-pnpm-linux-riscv64-gnu ' )
328
+ return require ( '@napi-rs/package-template-pnpm-linux-arm64-ohos ' )
304
329
} catch ( e ) {
305
330
loadErrors . push ( e )
306
331
}
307
-
308
- }
309
- } else if ( process . arch === 'ppc64' ) {
332
+ } else if ( process . arch === 'x64' ) {
310
333
try {
311
- return require ( './package-template.linux-ppc64-gnu .node' )
334
+ return require ( './package-template.linux-x64-ohos .node' )
312
335
} catch ( e ) {
313
336
loadErrors . push ( e )
314
337
}
315
338
try {
316
- return require ( '@napi-rs/package-template-pnpm-linux-ppc64-gnu ' )
339
+ return require ( '@napi-rs/package-template-pnpm-linux-x64-ohos ' )
317
340
} catch ( e ) {
318
341
loadErrors . push ( e )
319
342
}
320
-
321
- } else if ( process . arch === 's390x' ) {
343
+ } else if ( process . arch === 'arm' ) {
322
344
try {
323
- return require ( './package-template.linux-s390x-gnu .node' )
345
+ return require ( './package-template.linux-arm-ohos .node' )
324
346
} catch ( e ) {
325
347
loadErrors . push ( e )
326
348
}
327
349
try {
328
- return require ( '@napi-rs/package-template-pnpm-linux-s390x-gnu ' )
350
+ return require ( '@napi-rs/package-template-pnpm-linux-arm-ohos ' )
329
351
} catch ( e ) {
330
352
loadErrors . push ( e )
331
353
}
332
-
333
354
} else {
334
- loadErrors . push ( new Error ( `Unsupported architecture on Linux : ${ process . arch } ` ) )
355
+ loadErrors . push ( new Error ( `Unsupported architecture on OpenHarmony : ${ process . arch } ` ) )
335
356
}
336
357
} else {
337
358
loadErrors . push ( new Error ( `Unsupported OS: ${ process . platform } , architecture: ${ process . arch } ` ) )
@@ -361,13 +382,15 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
361
382
362
383
if ( ! nativeBinding ) {
363
384
if ( loadErrors . length > 0 ) {
364
- // TODO Link to documentation with potential fixes
365
- // - The package owner could build/publish bindings for this arch
366
- // - The user may need to bundle the correct files
367
- // - The user may need to re-install node_modules to get new packages
368
- throw new Error ( 'Failed to load native binding' , { cause : loadErrors } )
385
+ throw new Error (
386
+ `Cannot find native binding. ` +
387
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
388
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.' ,
389
+ { cause : loadErrors }
390
+ )
369
391
}
370
392
throw new Error ( `Failed to load native binding` )
371
393
}
372
394
395
+ module . exports = nativeBinding
373
396
module . exports . plus100 = nativeBinding . plus100
0 commit comments