@vizejs/native 0.78.0 → 0.81.0

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.
Files changed (3) hide show
  1. package/index.d.ts +638 -5
  2. package/index.js +723 -272
  3. package/package.json +9 -9
package/index.js CHANGED
@@ -1,333 +1,784 @@
1
- /* tslint:disable */
1
+ // prettier-ignore
2
2
  /* eslint-disable */
3
- /* prettier-ignore */
4
-
3
+ // @ts-nocheck
5
4
  /* auto-generated by NAPI-RS */
6
5
 
7
- const { existsSync, readFileSync } = require('fs')
8
- const { join } = require("path");
6
+ const { readFileSync } = require('node:fs')
7
+ let nativeBinding = null;
8
+ const loadErrors = [];
9
+
10
+ const isMusl = () => {
11
+ let musl = false;
12
+ if (process.platform === "linux") {
13
+ musl = isMuslFromFilesystem();
14
+ if (musl === null) {
15
+ musl = isMuslFromReport();
16
+ }
17
+ if (musl === null) {
18
+ musl = isMuslFromChildProcess();
19
+ }
20
+ }
21
+ return musl;
22
+ };
9
23
 
10
- const { platform, arch } = process;
24
+ const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
11
25
 
12
- let nativeBinding = null;
13
- let localFileExisted = false;
14
- let loadError = null;
26
+ const isMuslFromFilesystem = () => {
27
+ try {
28
+ return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
29
+ } catch {
30
+ return null;
31
+ }
32
+ };
15
33
 
16
- function isMusl() {
17
- // For Node 10
18
- if (!process.report || typeof process.report.getReport !== "function") {
19
- try {
20
- const lddPath = require("child_process").execSync("which ldd").toString().trim();
21
- return readFileSync(lddPath, "utf8").includes("musl");
22
- } catch (e) {
34
+ const isMuslFromReport = () => {
35
+ let report = null;
36
+ if (typeof process.report?.getReport === "function") {
37
+ process.report.excludeNetwork = true;
38
+ report = process.report.getReport();
39
+ }
40
+ if (!report) {
41
+ return null;
42
+ }
43
+ if (report.header && report.header.glibcVersionRuntime) {
44
+ return false;
45
+ }
46
+ if (Array.isArray(report.sharedObjects)) {
47
+ if (report.sharedObjects.some(isFileMusl)) {
23
48
  return true;
24
49
  }
25
- } else {
26
- const { glibcVersionRuntime } = process.report.getReport().header;
27
- return !glibcVersionRuntime;
28
50
  }
29
- }
51
+ return false;
52
+ };
30
53
 
31
- switch (platform) {
32
- case "android":
33
- switch (arch) {
34
- case "arm64":
35
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.android-arm64.node"));
54
+ const isMuslFromChildProcess = () => {
55
+ try {
56
+ return require("child_process")
57
+ .execSync("ldd --version", { encoding: "utf8" })
58
+ .includes("musl");
59
+ } catch (e) {
60
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
61
+ return false;
62
+ }
63
+ };
64
+
65
+ function requireNative() {
66
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
67
+ try {
68
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
69
+ } catch (err) {
70
+ loadErrors.push(err);
71
+ }
72
+ } else if (process.platform === "android") {
73
+ if (process.arch === "arm64") {
74
+ try {
75
+ return require("./vize-vitrine.android-arm64.node");
76
+ } catch (e) {
77
+ loadErrors.push(e);
78
+ }
79
+ try {
80
+ const binding = require("@vizejs/native-android-arm64");
81
+ const bindingPackageVersion = require("@vizejs/native-android-arm64/package.json").version;
82
+ if (
83
+ bindingPackageVersion !== "0.78.0" &&
84
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
85
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
86
+ ) {
87
+ throw new Error(
88
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
89
+ );
90
+ }
91
+ return binding;
92
+ } catch (e) {
93
+ loadErrors.push(e);
94
+ }
95
+ } else if (process.arch === "arm") {
96
+ try {
97
+ return require("./vize-vitrine.android-arm-eabi.node");
98
+ } catch (e) {
99
+ loadErrors.push(e);
100
+ }
101
+ try {
102
+ const binding = require("@vizejs/native-android-arm-eabi");
103
+ const bindingPackageVersion =
104
+ require("@vizejs/native-android-arm-eabi/package.json").version;
105
+ if (
106
+ bindingPackageVersion !== "0.78.0" &&
107
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
108
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
109
+ ) {
110
+ throw new Error(
111
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
112
+ );
113
+ }
114
+ return binding;
115
+ } catch (e) {
116
+ loadErrors.push(e);
117
+ }
118
+ } else {
119
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
120
+ }
121
+ } else if (process.platform === "win32") {
122
+ if (process.arch === "x64") {
123
+ if (
124
+ process.config?.variables?.shlib_suffix === "dll.a" ||
125
+ process.config?.variables?.node_target_type === "shared_library"
126
+ ) {
36
127
  try {
37
- if (localFileExisted) {
38
- nativeBinding = require("./vize-vitrine.android-arm64.node");
39
- } else {
40
- nativeBinding = require("@vizejs/native-android-arm64");
128
+ return require("./vize-vitrine.win32-x64-gnu.node");
129
+ } catch (e) {
130
+ loadErrors.push(e);
131
+ }
132
+ try {
133
+ const binding = require("@vizejs/native-win32-x64-gnu");
134
+ const bindingPackageVersion =
135
+ require("@vizejs/native-win32-x64-gnu/package.json").version;
136
+ if (
137
+ bindingPackageVersion !== "0.78.0" &&
138
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
139
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
140
+ ) {
141
+ throw new Error(
142
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
143
+ );
41
144
  }
145
+ return binding;
42
146
  } catch (e) {
43
- loadError = e;
147
+ loadErrors.push(e);
44
148
  }
45
- break;
46
- case "arm":
47
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.android-arm-eabi.node"));
149
+ } else {
48
150
  try {
49
- if (localFileExisted) {
50
- nativeBinding = require("./vize-vitrine.android-arm-eabi.node");
51
- } else {
52
- nativeBinding = require("@vizejs/native-android-arm-eabi");
151
+ return require("./vize-vitrine.win32-x64-msvc.node");
152
+ } catch (e) {
153
+ loadErrors.push(e);
154
+ }
155
+ try {
156
+ const binding = require("@vizejs/native-win32-x64-msvc");
157
+ const bindingPackageVersion =
158
+ require("@vizejs/native-win32-x64-msvc/package.json").version;
159
+ if (
160
+ bindingPackageVersion !== "0.78.0" &&
161
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
162
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
163
+ ) {
164
+ throw new Error(
165
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
166
+ );
53
167
  }
168
+ return binding;
54
169
  } catch (e) {
55
- loadError = e;
170
+ loadErrors.push(e);
171
+ }
172
+ }
173
+ } else if (process.arch === "ia32") {
174
+ try {
175
+ return require("./vize-vitrine.win32-ia32-msvc.node");
176
+ } catch (e) {
177
+ loadErrors.push(e);
178
+ }
179
+ try {
180
+ const binding = require("@vizejs/native-win32-ia32-msvc");
181
+ const bindingPackageVersion =
182
+ require("@vizejs/native-win32-ia32-msvc/package.json").version;
183
+ if (
184
+ bindingPackageVersion !== "0.78.0" &&
185
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
186
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
187
+ ) {
188
+ throw new Error(
189
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
190
+ );
191
+ }
192
+ return binding;
193
+ } catch (e) {
194
+ loadErrors.push(e);
195
+ }
196
+ } else if (process.arch === "arm64") {
197
+ try {
198
+ return require("./vize-vitrine.win32-arm64-msvc.node");
199
+ } catch (e) {
200
+ loadErrors.push(e);
201
+ }
202
+ try {
203
+ const binding = require("@vizejs/native-win32-arm64-msvc");
204
+ const bindingPackageVersion =
205
+ require("@vizejs/native-win32-arm64-msvc/package.json").version;
206
+ if (
207
+ bindingPackageVersion !== "0.78.0" &&
208
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
209
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
210
+ ) {
211
+ throw new Error(
212
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
213
+ );
56
214
  }
57
- break;
58
- default:
59
- throw new Error(`Unsupported architecture on Android ${arch}`);
215
+ return binding;
216
+ } catch (e) {
217
+ loadErrors.push(e);
218
+ }
219
+ } else {
220
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
221
+ }
222
+ } else if (process.platform === "darwin") {
223
+ try {
224
+ return require("./vize-vitrine.darwin-universal.node");
225
+ } catch (e) {
226
+ loadErrors.push(e);
227
+ }
228
+ try {
229
+ const binding = require("@vizejs/native-darwin-universal");
230
+ const bindingPackageVersion = require("@vizejs/native-darwin-universal/package.json").version;
231
+ if (
232
+ bindingPackageVersion !== "0.78.0" &&
233
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
234
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
235
+ ) {
236
+ throw new Error(
237
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
238
+ );
239
+ }
240
+ return binding;
241
+ } catch (e) {
242
+ loadErrors.push(e);
243
+ }
244
+ if (process.arch === "x64") {
245
+ try {
246
+ return require("./vize-vitrine.darwin-x64.node");
247
+ } catch (e) {
248
+ loadErrors.push(e);
249
+ }
250
+ try {
251
+ const binding = require("@vizejs/native-darwin-x64");
252
+ const bindingPackageVersion = require("@vizejs/native-darwin-x64/package.json").version;
253
+ if (
254
+ bindingPackageVersion !== "0.78.0" &&
255
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
256
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
257
+ ) {
258
+ throw new Error(
259
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
260
+ );
261
+ }
262
+ return binding;
263
+ } catch (e) {
264
+ loadErrors.push(e);
265
+ }
266
+ } else if (process.arch === "arm64") {
267
+ try {
268
+ return require("./vize-vitrine.darwin-arm64.node");
269
+ } catch (e) {
270
+ loadErrors.push(e);
271
+ }
272
+ try {
273
+ const binding = require("@vizejs/native-darwin-arm64");
274
+ const bindingPackageVersion = require("@vizejs/native-darwin-arm64/package.json").version;
275
+ if (
276
+ bindingPackageVersion !== "0.78.0" &&
277
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
278
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
279
+ ) {
280
+ throw new Error(
281
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
282
+ );
283
+ }
284
+ return binding;
285
+ } catch (e) {
286
+ loadErrors.push(e);
287
+ }
288
+ } else {
289
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
60
290
  }
61
- break;
62
- case "win32":
63
- switch (arch) {
64
- case "x64":
65
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.win32-x64-msvc.node"));
291
+ } else if (process.platform === "freebsd") {
292
+ if (process.arch === "x64") {
293
+ try {
294
+ return require("./vize-vitrine.freebsd-x64.node");
295
+ } catch (e) {
296
+ loadErrors.push(e);
297
+ }
298
+ try {
299
+ const binding = require("@vizejs/native-freebsd-x64");
300
+ const bindingPackageVersion = require("@vizejs/native-freebsd-x64/package.json").version;
301
+ if (
302
+ bindingPackageVersion !== "0.78.0" &&
303
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
304
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
305
+ ) {
306
+ throw new Error(
307
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
308
+ );
309
+ }
310
+ return binding;
311
+ } catch (e) {
312
+ loadErrors.push(e);
313
+ }
314
+ } else if (process.arch === "arm64") {
315
+ try {
316
+ return require("./vize-vitrine.freebsd-arm64.node");
317
+ } catch (e) {
318
+ loadErrors.push(e);
319
+ }
320
+ try {
321
+ const binding = require("@vizejs/native-freebsd-arm64");
322
+ const bindingPackageVersion = require("@vizejs/native-freebsd-arm64/package.json").version;
323
+ if (
324
+ bindingPackageVersion !== "0.78.0" &&
325
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
326
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
327
+ ) {
328
+ throw new Error(
329
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
330
+ );
331
+ }
332
+ return binding;
333
+ } catch (e) {
334
+ loadErrors.push(e);
335
+ }
336
+ } else {
337
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
338
+ }
339
+ } else if (process.platform === "linux") {
340
+ if (process.arch === "x64") {
341
+ if (isMusl()) {
66
342
  try {
67
- if (localFileExisted) {
68
- nativeBinding = require("./vize-vitrine.win32-x64-msvc.node");
69
- } else {
70
- nativeBinding = require("@vizejs/native-win32-x64-msvc");
71
- }
343
+ return require("./vize-vitrine.linux-x64-musl.node");
72
344
  } catch (e) {
73
- loadError = e;
345
+ loadErrors.push(e);
74
346
  }
75
- break;
76
- case "ia32":
77
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.win32-ia32-msvc.node"));
78
347
  try {
79
- if (localFileExisted) {
80
- nativeBinding = require("./vize-vitrine.win32-ia32-msvc.node");
81
- } else {
82
- nativeBinding = require("@vizejs/native-win32-ia32-msvc");
348
+ const binding = require("@vizejs/native-linux-x64-musl");
349
+ const bindingPackageVersion =
350
+ require("@vizejs/native-linux-x64-musl/package.json").version;
351
+ if (
352
+ bindingPackageVersion !== "0.78.0" &&
353
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
354
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
355
+ ) {
356
+ throw new Error(
357
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
358
+ );
83
359
  }
360
+ return binding;
361
+ } catch (e) {
362
+ loadErrors.push(e);
363
+ }
364
+ } else {
365
+ try {
366
+ return require("./vize-vitrine.linux-x64-gnu.node");
84
367
  } catch (e) {
85
- loadError = e;
368
+ loadErrors.push(e);
86
369
  }
87
- break;
88
- case "arm64":
89
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.win32-arm64-msvc.node"));
90
370
  try {
91
- if (localFileExisted) {
92
- nativeBinding = require("./vize-vitrine.win32-arm64-msvc.node");
93
- } else {
94
- nativeBinding = require("@vizejs/native-win32-arm64-msvc");
371
+ const binding = require("@vizejs/native-linux-x64-gnu");
372
+ const bindingPackageVersion =
373
+ require("@vizejs/native-linux-x64-gnu/package.json").version;
374
+ if (
375
+ bindingPackageVersion !== "0.78.0" &&
376
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
377
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
378
+ ) {
379
+ throw new Error(
380
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
381
+ );
95
382
  }
383
+ return binding;
96
384
  } catch (e) {
97
- loadError = e;
385
+ loadErrors.push(e);
98
386
  }
99
- break;
100
- default:
101
- throw new Error(`Unsupported architecture on Windows: ${arch}`);
102
- }
103
- break;
104
- case "darwin":
105
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.darwin-universal.node"));
106
- try {
107
- if (localFileExisted) {
108
- nativeBinding = require("./vize-vitrine.darwin-universal.node");
109
- } else {
110
- nativeBinding = require("@vizejs/native-darwin-universal");
111
387
  }
112
- break;
113
- } catch {}
114
- switch (arch) {
115
- case "x64":
116
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.darwin-x64.node"));
388
+ } else if (process.arch === "arm64") {
389
+ if (isMusl()) {
117
390
  try {
118
- if (localFileExisted) {
119
- nativeBinding = require("./vize-vitrine.darwin-x64.node");
120
- } else {
121
- nativeBinding = require("@vizejs/native-darwin-x64");
122
- }
391
+ return require("./vize-vitrine.linux-arm64-musl.node");
123
392
  } catch (e) {
124
- loadError = e;
393
+ loadErrors.push(e);
125
394
  }
126
- break;
127
- case "arm64":
128
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.darwin-arm64.node"));
129
395
  try {
130
- if (localFileExisted) {
131
- nativeBinding = require("./vize-vitrine.darwin-arm64.node");
132
- } else {
133
- nativeBinding = require("@vizejs/native-darwin-arm64");
396
+ const binding = require("@vizejs/native-linux-arm64-musl");
397
+ const bindingPackageVersion =
398
+ require("@vizejs/native-linux-arm64-musl/package.json").version;
399
+ if (
400
+ bindingPackageVersion !== "0.78.0" &&
401
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
402
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
403
+ ) {
404
+ throw new Error(
405
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
406
+ );
134
407
  }
408
+ return binding;
135
409
  } catch (e) {
136
- loadError = e;
410
+ loadErrors.push(e);
137
411
  }
138
- break;
139
- default:
140
- throw new Error(`Unsupported architecture on macOS: ${arch}`);
141
- }
142
- break;
143
- case "freebsd":
144
- if (arch !== "x64") {
145
- throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
146
- }
147
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.freebsd-x64.node"));
148
- try {
149
- if (localFileExisted) {
150
- nativeBinding = require("./vize-vitrine.freebsd-x64.node");
151
412
  } else {
152
- nativeBinding = require("@vizejs/native-freebsd-x64");
153
- }
154
- } catch (e) {
155
- loadError = e;
156
- }
157
- break;
158
- case "linux":
159
- switch (arch) {
160
- case "x64":
161
- if (isMusl()) {
162
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-x64-musl.node"));
163
- try {
164
- if (localFileExisted) {
165
- nativeBinding = require("./vize-vitrine.linux-x64-musl.node");
166
- } else {
167
- nativeBinding = require("@vizejs/native-linux-x64-musl");
168
- }
169
- } catch (e) {
170
- loadError = e;
171
- }
172
- } else {
173
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-x64-gnu.node"));
174
- try {
175
- if (localFileExisted) {
176
- nativeBinding = require("./vize-vitrine.linux-x64-gnu.node");
177
- } else {
178
- nativeBinding = require("@vizejs/native-linux-x64-gnu");
179
- }
180
- } catch (e) {
181
- loadError = e;
182
- }
413
+ try {
414
+ return require("./vize-vitrine.linux-arm64-gnu.node");
415
+ } catch (e) {
416
+ loadErrors.push(e);
183
417
  }
184
- break;
185
- case "arm64":
186
- if (isMusl()) {
187
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-arm64-musl.node"));
188
- try {
189
- if (localFileExisted) {
190
- nativeBinding = require("./vize-vitrine.linux-arm64-musl.node");
191
- } else {
192
- nativeBinding = require("@vizejs/native-linux-arm64-musl");
193
- }
194
- } catch (e) {
195
- loadError = e;
418
+ try {
419
+ const binding = require("@vizejs/native-linux-arm64-gnu");
420
+ const bindingPackageVersion =
421
+ require("@vizejs/native-linux-arm64-gnu/package.json").version;
422
+ if (
423
+ bindingPackageVersion !== "0.78.0" &&
424
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
425
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
426
+ ) {
427
+ throw new Error(
428
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
429
+ );
196
430
  }
197
- } else {
198
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-arm64-gnu.node"));
199
- try {
200
- if (localFileExisted) {
201
- nativeBinding = require("./vize-vitrine.linux-arm64-gnu.node");
202
- } else {
203
- nativeBinding = require("@vizejs/native-linux-arm64-gnu");
204
- }
205
- } catch (e) {
206
- loadError = e;
431
+ return binding;
432
+ } catch (e) {
433
+ loadErrors.push(e);
434
+ }
435
+ }
436
+ } else if (process.arch === "arm") {
437
+ if (isMusl()) {
438
+ try {
439
+ return require("./vize-vitrine.linux-arm-musleabihf.node");
440
+ } catch (e) {
441
+ loadErrors.push(e);
442
+ }
443
+ try {
444
+ const binding = require("@vizejs/native-linux-arm-musleabihf");
445
+ const bindingPackageVersion =
446
+ require("@vizejs/native-linux-arm-musleabihf/package.json").version;
447
+ if (
448
+ bindingPackageVersion !== "0.78.0" &&
449
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
450
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
451
+ ) {
452
+ throw new Error(
453
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
454
+ );
207
455
  }
456
+ return binding;
457
+ } catch (e) {
458
+ loadErrors.push(e);
459
+ }
460
+ } else {
461
+ try {
462
+ return require("./vize-vitrine.linux-arm-gnueabihf.node");
463
+ } catch (e) {
464
+ loadErrors.push(e);
208
465
  }
209
- break;
210
- case "arm":
211
- if (isMusl()) {
212
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-arm-musleabihf.node"));
213
- try {
214
- if (localFileExisted) {
215
- nativeBinding = require("./vize-vitrine.linux-arm-musleabihf.node");
216
- } else {
217
- nativeBinding = require("@vizejs/native-linux-arm-musleabihf");
218
- }
219
- } catch (e) {
220
- loadError = e;
466
+ try {
467
+ const binding = require("@vizejs/native-linux-arm-gnueabihf");
468
+ const bindingPackageVersion =
469
+ require("@vizejs/native-linux-arm-gnueabihf/package.json").version;
470
+ if (
471
+ bindingPackageVersion !== "0.78.0" &&
472
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
473
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
474
+ ) {
475
+ throw new Error(
476
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
477
+ );
221
478
  }
222
- } else {
223
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-arm-gnueabihf.node"));
224
- try {
225
- if (localFileExisted) {
226
- nativeBinding = require("./vize-vitrine.linux-arm-gnueabihf.node");
227
- } else {
228
- nativeBinding = require("@vizejs/native-linux-arm-gnueabihf");
229
- }
230
- } catch (e) {
231
- loadError = e;
479
+ return binding;
480
+ } catch (e) {
481
+ loadErrors.push(e);
482
+ }
483
+ }
484
+ } else if (process.arch === "loong64") {
485
+ if (isMusl()) {
486
+ try {
487
+ return require("./vize-vitrine.linux-loong64-musl.node");
488
+ } catch (e) {
489
+ loadErrors.push(e);
490
+ }
491
+ try {
492
+ const binding = require("@vizejs/native-linux-loong64-musl");
493
+ const bindingPackageVersion =
494
+ require("@vizejs/native-linux-loong64-musl/package.json").version;
495
+ if (
496
+ bindingPackageVersion !== "0.78.0" &&
497
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
498
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
499
+ ) {
500
+ throw new Error(
501
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
502
+ );
232
503
  }
504
+ return binding;
505
+ } catch (e) {
506
+ loadErrors.push(e);
233
507
  }
234
- break;
235
- case "riscv64":
236
- if (isMusl()) {
237
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-riscv64-musl.node"));
238
- try {
239
- if (localFileExisted) {
240
- nativeBinding = require("./vize-vitrine.linux-riscv64-musl.node");
241
- } else {
242
- nativeBinding = require("@vizejs/native-linux-riscv64-musl");
243
- }
244
- } catch (e) {
245
- loadError = e;
508
+ } else {
509
+ try {
510
+ return require("./vize-vitrine.linux-loong64-gnu.node");
511
+ } catch (e) {
512
+ loadErrors.push(e);
513
+ }
514
+ try {
515
+ const binding = require("@vizejs/native-linux-loong64-gnu");
516
+ const bindingPackageVersion =
517
+ require("@vizejs/native-linux-loong64-gnu/package.json").version;
518
+ if (
519
+ bindingPackageVersion !== "0.78.0" &&
520
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
521
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
522
+ ) {
523
+ throw new Error(
524
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
525
+ );
246
526
  }
247
- } else {
248
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-riscv64-gnu.node"));
249
- try {
250
- if (localFileExisted) {
251
- nativeBinding = require("./vize-vitrine.linux-riscv64-gnu.node");
252
- } else {
253
- nativeBinding = require("@vizejs/native-linux-riscv64-gnu");
254
- }
255
- } catch (e) {
256
- loadError = e;
527
+ return binding;
528
+ } catch (e) {
529
+ loadErrors.push(e);
530
+ }
531
+ }
532
+ } else if (process.arch === "riscv64") {
533
+ if (isMusl()) {
534
+ try {
535
+ return require("./vize-vitrine.linux-riscv64-musl.node");
536
+ } catch (e) {
537
+ loadErrors.push(e);
538
+ }
539
+ try {
540
+ const binding = require("@vizejs/native-linux-riscv64-musl");
541
+ const bindingPackageVersion =
542
+ require("@vizejs/native-linux-riscv64-musl/package.json").version;
543
+ if (
544
+ bindingPackageVersion !== "0.78.0" &&
545
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
546
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
547
+ ) {
548
+ throw new Error(
549
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
550
+ );
257
551
  }
552
+ return binding;
553
+ } catch (e) {
554
+ loadErrors.push(e);
555
+ }
556
+ } else {
557
+ try {
558
+ return require("./vize-vitrine.linux-riscv64-gnu.node");
559
+ } catch (e) {
560
+ loadErrors.push(e);
258
561
  }
259
- break;
260
- case "s390x":
261
- localFileExisted = existsSync(join(__dirname, "vize-vitrine.linux-s390x-gnu.node"));
262
562
  try {
263
- if (localFileExisted) {
264
- nativeBinding = require("./vize-vitrine.linux-s390x-gnu.node");
265
- } else {
266
- nativeBinding = require("@vizejs/native-linux-s390x-gnu");
563
+ const binding = require("@vizejs/native-linux-riscv64-gnu");
564
+ const bindingPackageVersion =
565
+ require("@vizejs/native-linux-riscv64-gnu/package.json").version;
566
+ if (
567
+ bindingPackageVersion !== "0.78.0" &&
568
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
569
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
570
+ ) {
571
+ throw new Error(
572
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
573
+ );
267
574
  }
575
+ return binding;
268
576
  } catch (e) {
269
- loadError = e;
577
+ loadErrors.push(e);
578
+ }
579
+ }
580
+ } else if (process.arch === "ppc64") {
581
+ try {
582
+ return require("./vize-vitrine.linux-ppc64-gnu.node");
583
+ } catch (e) {
584
+ loadErrors.push(e);
585
+ }
586
+ try {
587
+ const binding = require("@vizejs/native-linux-ppc64-gnu");
588
+ const bindingPackageVersion =
589
+ require("@vizejs/native-linux-ppc64-gnu/package.json").version;
590
+ if (
591
+ bindingPackageVersion !== "0.78.0" &&
592
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
593
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
594
+ ) {
595
+ throw new Error(
596
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
597
+ );
598
+ }
599
+ return binding;
600
+ } catch (e) {
601
+ loadErrors.push(e);
602
+ }
603
+ } else if (process.arch === "s390x") {
604
+ try {
605
+ return require("./vize-vitrine.linux-s390x-gnu.node");
606
+ } catch (e) {
607
+ loadErrors.push(e);
608
+ }
609
+ try {
610
+ const binding = require("@vizejs/native-linux-s390x-gnu");
611
+ const bindingPackageVersion =
612
+ require("@vizejs/native-linux-s390x-gnu/package.json").version;
613
+ if (
614
+ bindingPackageVersion !== "0.78.0" &&
615
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
616
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
617
+ ) {
618
+ throw new Error(
619
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
620
+ );
621
+ }
622
+ return binding;
623
+ } catch (e) {
624
+ loadErrors.push(e);
625
+ }
626
+ } else {
627
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
628
+ }
629
+ } else if (process.platform === "openharmony") {
630
+ if (process.arch === "arm64") {
631
+ try {
632
+ return require("./vize-vitrine.openharmony-arm64.node");
633
+ } catch (e) {
634
+ loadErrors.push(e);
635
+ }
636
+ try {
637
+ const binding = require("@vizejs/native-openharmony-arm64");
638
+ const bindingPackageVersion =
639
+ require("@vizejs/native-openharmony-arm64/package.json").version;
640
+ if (
641
+ bindingPackageVersion !== "0.78.0" &&
642
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
643
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
644
+ ) {
645
+ throw new Error(
646
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
647
+ );
648
+ }
649
+ return binding;
650
+ } catch (e) {
651
+ loadErrors.push(e);
652
+ }
653
+ } else if (process.arch === "x64") {
654
+ try {
655
+ return require("./vize-vitrine.openharmony-x64.node");
656
+ } catch (e) {
657
+ loadErrors.push(e);
658
+ }
659
+ try {
660
+ const binding = require("@vizejs/native-openharmony-x64");
661
+ const bindingPackageVersion =
662
+ require("@vizejs/native-openharmony-x64/package.json").version;
663
+ if (
664
+ bindingPackageVersion !== "0.78.0" &&
665
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
666
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
667
+ ) {
668
+ throw new Error(
669
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
670
+ );
270
671
  }
271
- break;
272
- default:
273
- throw new Error(`Unsupported architecture on Linux: ${arch}`);
672
+ return binding;
673
+ } catch (e) {
674
+ loadErrors.push(e);
675
+ }
676
+ } else if (process.arch === "arm") {
677
+ try {
678
+ return require("./vize-vitrine.openharmony-arm.node");
679
+ } catch (e) {
680
+ loadErrors.push(e);
681
+ }
682
+ try {
683
+ const binding = require("@vizejs/native-openharmony-arm");
684
+ const bindingPackageVersion =
685
+ require("@vizejs/native-openharmony-arm/package.json").version;
686
+ if (
687
+ bindingPackageVersion !== "0.78.0" &&
688
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
689
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0"
690
+ ) {
691
+ throw new Error(
692
+ `Native binding package version mismatch, expected 0.78.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
693
+ );
694
+ }
695
+ return binding;
696
+ } catch (e) {
697
+ loadErrors.push(e);
698
+ }
699
+ } else {
700
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`));
274
701
  }
275
- break;
276
- default:
277
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
702
+ } else {
703
+ loadErrors.push(
704
+ new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`),
705
+ );
706
+ }
707
+ }
708
+
709
+ nativeBinding = requireNative();
710
+
711
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
712
+ let wasiBinding = null;
713
+ let wasiBindingError = null;
714
+ try {
715
+ wasiBinding = require("./vize-vitrine.wasi.cjs");
716
+ nativeBinding = wasiBinding;
717
+ } catch (err) {
718
+ if (process.env.NAPI_RS_FORCE_WASI) {
719
+ wasiBindingError = err;
720
+ }
721
+ }
722
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
723
+ try {
724
+ wasiBinding = require("@vizejs/native-wasm32-wasi");
725
+ nativeBinding = wasiBinding;
726
+ } catch (err) {
727
+ if (process.env.NAPI_RS_FORCE_WASI) {
728
+ if (!wasiBindingError) {
729
+ wasiBindingError = err;
730
+ } else {
731
+ wasiBindingError.cause = err;
732
+ }
733
+ loadErrors.push(err);
734
+ }
735
+ }
736
+ }
737
+ if (process.env.NAPI_RS_FORCE_WASI === "error" && !wasiBinding) {
738
+ const error = new Error("WASI binding not found and NAPI_RS_FORCE_WASI is set to error");
739
+ error.cause = wasiBindingError;
740
+ throw error;
741
+ }
278
742
  }
279
743
 
280
744
  if (!nativeBinding) {
281
- if (loadError) {
282
- throw loadError;
745
+ if (loadErrors.length > 0) {
746
+ throw new Error(
747
+ `Cannot find native binding. ` +
748
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
749
+ "Please try `npm i` again after removing both package-lock.json and node_modules directory.",
750
+ {
751
+ cause: loadErrors.reduce((err, cur) => {
752
+ cur.cause = err;
753
+ return cur;
754
+ }),
755
+ },
756
+ );
283
757
  }
284
758
  throw new Error(`Failed to load native binding`);
285
759
  }
286
760
 
287
- const {
288
- typeCheck,
289
- getTypeCheckCapabilities,
290
- typeCheckBatch,
291
- generateDeclaration,
292
- compile,
293
- compileVapor,
294
- parseTemplate,
295
- parseSfc,
296
- compileSfc,
297
- compileSfcBatch,
298
- compileSfcBatchWithResults,
299
- compileCss,
300
- parseArt,
301
- artToCsf,
302
- generateArtDoc,
303
- generateArtCatalog,
304
- generateArtDocsBatch,
305
- generateArtPalette,
306
- formatSfc,
307
- lint,
308
- lintPatinaSfc,
309
- getPatinaRules,
310
- } = nativeBinding;
311
-
312
- module.exports.typeCheck = typeCheck;
313
- module.exports.getTypeCheckCapabilities = getTypeCheckCapabilities;
314
- module.exports.typeCheckBatch = typeCheckBatch;
315
- module.exports.generateDeclaration = generateDeclaration;
316
- module.exports.compile = compile;
317
- module.exports.compileVapor = compileVapor;
318
- module.exports.parseTemplate = parseTemplate;
319
- module.exports.parseSfc = parseSfc;
320
- module.exports.compileSfc = compileSfc;
321
- module.exports.compileSfcBatch = compileSfcBatch;
322
- module.exports.compileSfcBatchWithResults = compileSfcBatchWithResults;
323
- module.exports.compileCss = compileCss;
324
- module.exports.parseArt = parseArt;
325
- module.exports.artToCsf = artToCsf;
326
- module.exports.generateArtDoc = generateArtDoc;
327
- module.exports.generateArtCatalog = generateArtCatalog;
328
- module.exports.generateArtDocsBatch = generateArtDocsBatch;
329
- module.exports.generateArtPalette = generateArtPalette;
330
- module.exports.formatSfc = formatSfc;
331
- module.exports.lint = lint;
332
- module.exports.lintPatinaSfc = lintPatinaSfc;
333
- module.exports.getPatinaRules = getPatinaRules;
761
+ module.exports = nativeBinding;
762
+ module.exports.artToCsf = nativeBinding.artToCsf;
763
+ module.exports.compile = nativeBinding.compile;
764
+ module.exports.compileCss = nativeBinding.compileCss;
765
+ module.exports.compileSfc = nativeBinding.compileSfc;
766
+ module.exports.compileSfcBatch = nativeBinding.compileSfcBatch;
767
+ module.exports.compileSfcBatchWithResults = nativeBinding.compileSfcBatchWithResults;
768
+ module.exports.compileVapor = nativeBinding.compileVapor;
769
+ module.exports.formatSfc = nativeBinding.formatSfc;
770
+ module.exports.generateArtCatalog = nativeBinding.generateArtCatalog;
771
+ module.exports.generateArtDoc = nativeBinding.generateArtDoc;
772
+ module.exports.generateArtDocsBatch = nativeBinding.generateArtDocsBatch;
773
+ module.exports.generateArtPalette = nativeBinding.generateArtPalette;
774
+ module.exports.generateDeclaration = nativeBinding.generateDeclaration;
775
+ module.exports.generateVariants = nativeBinding.generateVariants;
776
+ module.exports.getPatinaRules = nativeBinding.getPatinaRules;
777
+ module.exports.getTypeCheckCapabilities = nativeBinding.getTypeCheckCapabilities;
778
+ module.exports.lint = nativeBinding.lint;
779
+ module.exports.lintPatinaSfc = nativeBinding.lintPatinaSfc;
780
+ module.exports.parseArt = nativeBinding.parseArt;
781
+ module.exports.parseSfc = nativeBinding.parseSfc;
782
+ module.exports.parseTemplate = nativeBinding.parseTemplate;
783
+ module.exports.typeCheck = nativeBinding.typeCheck;
784
+ module.exports.typeCheckBatch = nativeBinding.typeCheckBatch;