@unownplain/anthelion-komac 0.0.53 → 0.0.55
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/index.js +140 -27
- package/package.json +10 -10
package/index.js
CHANGED
|
@@ -527,47 +527,163 @@ function requireNative() {
|
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
-
|
|
530
|
+
function createLoadErrorChain(errors) {
|
|
531
|
+
return errors.reduce((previous, current) => {
|
|
532
|
+
let message
|
|
533
|
+
try {
|
|
534
|
+
message =
|
|
535
|
+
current && typeof current.message === 'string'
|
|
536
|
+
? current.message
|
|
537
|
+
: String(current)
|
|
538
|
+
} catch {
|
|
539
|
+
message = 'Unknown error'
|
|
540
|
+
}
|
|
541
|
+
const error = new Error(message)
|
|
542
|
+
error.cause = previous
|
|
543
|
+
return error
|
|
544
|
+
}, null)
|
|
545
|
+
}
|
|
531
546
|
|
|
532
547
|
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
533
548
|
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
534
|
-
// 'true' →
|
|
535
|
-
// 'error' →
|
|
549
|
+
// 'true' → prefer WASI, but retain native as a lazy fallback
|
|
550
|
+
// 'error' → require WASI without initializing a native fallback
|
|
536
551
|
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
537
552
|
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
538
553
|
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
554
|
+
//
|
|
555
|
+
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
|
|
556
|
+
// WASI loading. It never crosses into another flavor or falls back to native.
|
|
557
|
+
const __napiWasiFlavors = ["wasm32-wasi"]
|
|
558
|
+
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
|
|
559
|
+
const __napiWasiFlavorRequested =
|
|
560
|
+
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
|
|
561
|
+
if (
|
|
562
|
+
__napiWasiFlavorRequested &&
|
|
563
|
+
__napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
|
|
564
|
+
) {
|
|
565
|
+
throw new Error(
|
|
566
|
+
'Unsupported WASI flavor "' +
|
|
567
|
+
__napiWasiFlavor +
|
|
568
|
+
'". Available flavors: ' +
|
|
569
|
+
__napiWasiFlavors.join(', '),
|
|
570
|
+
)
|
|
571
|
+
}
|
|
572
|
+
const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
539
573
|
const forceWasi =
|
|
540
|
-
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
574
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' ||
|
|
575
|
+
forceWasiError ||
|
|
576
|
+
__napiWasiFlavorRequested
|
|
577
|
+
|
|
578
|
+
if (!forceWasi) {
|
|
579
|
+
nativeBinding = requireNative()
|
|
580
|
+
}
|
|
541
581
|
|
|
542
582
|
if (!nativeBinding || forceWasi) {
|
|
543
583
|
let wasiBinding = null
|
|
544
|
-
let
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
584
|
+
let wasiBindingLoaded = false
|
|
585
|
+
const wasiBindingErrors = []
|
|
586
|
+
const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
|
|
587
|
+
try {
|
|
588
|
+
require.resolve(specifier)
|
|
589
|
+
} catch (resolveError) {
|
|
590
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
591
|
+
throw resolveError
|
|
592
|
+
}
|
|
593
|
+
if (isPackage) {
|
|
594
|
+
try {
|
|
595
|
+
require.resolve(specifier + '/package.json')
|
|
596
|
+
} catch (packageError) {
|
|
597
|
+
if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
|
|
598
|
+
return resolveError
|
|
599
|
+
}
|
|
600
|
+
// An exports restriction proves the package exists even when its
|
|
601
|
+
// package.json is not public. Preserve the root resolution failure.
|
|
602
|
+
throw resolveError
|
|
603
|
+
}
|
|
604
|
+
// The package exists but its main/export target is broken.
|
|
605
|
+
throw resolveError
|
|
606
|
+
}
|
|
607
|
+
return resolveError
|
|
608
|
+
}
|
|
609
|
+
if (localArtifacts) {
|
|
610
|
+
let artifactError = null
|
|
611
|
+
for (let i = 0; i < localArtifacts.length; i++) {
|
|
612
|
+
try {
|
|
613
|
+
require.resolve(localArtifacts[i])
|
|
614
|
+
return null
|
|
615
|
+
} catch (resolveError) {
|
|
616
|
+
if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
|
|
617
|
+
throw resolveError
|
|
618
|
+
}
|
|
619
|
+
artifactError = resolveError
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return artifactError
|
|
551
623
|
}
|
|
624
|
+
return null
|
|
552
625
|
}
|
|
553
|
-
if (!
|
|
626
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
|
|
627
|
+
let candidateError = null
|
|
628
|
+
let candidateFailed = false
|
|
554
629
|
try {
|
|
555
|
-
|
|
556
|
-
|
|
630
|
+
candidateError = __napiWasiResolveCandidate('./anthelion-komac.wasi.cjs', false, ["./anthelion-komac.wasm32-wasi.debug.wasm","./anthelion-komac.wasm32-wasi.wasm"])
|
|
631
|
+
candidateFailed = candidateError !== null
|
|
632
|
+
if (!candidateFailed) {
|
|
633
|
+
wasiBinding = require('./anthelion-komac.wasi.cjs')
|
|
634
|
+
nativeBinding = wasiBinding
|
|
635
|
+
wasiBindingLoaded = true
|
|
636
|
+
}
|
|
557
637
|
} catch (err) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
638
|
+
candidateError = err
|
|
639
|
+
candidateFailed = true
|
|
640
|
+
}
|
|
641
|
+
if (candidateFailed) {
|
|
642
|
+
wasiBindingErrors.push(candidateError)
|
|
643
|
+
loadErrors.push(candidateError)
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
|
|
647
|
+
let candidateError = null
|
|
648
|
+
let candidateFailed = false
|
|
649
|
+
try {
|
|
650
|
+
candidateError = __napiWasiResolveCandidate('@unownplain/anthelion-komac-wasm32-wasi', true, undefined)
|
|
651
|
+
candidateFailed = candidateError !== null
|
|
652
|
+
if (!candidateFailed) {
|
|
653
|
+
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
654
|
+
const bindingPackageVersion = require('@unownplain/anthelion-komac-wasm32-wasi/package.json').version
|
|
655
|
+
if (bindingPackageVersion !== '0.0.0') {
|
|
656
|
+
throw new Error(`WASI binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
657
|
+
}
|
|
563
658
|
}
|
|
564
|
-
|
|
659
|
+
wasiBinding = require('@unownplain/anthelion-komac-wasm32-wasi')
|
|
660
|
+
nativeBinding = wasiBinding
|
|
661
|
+
wasiBindingLoaded = true
|
|
565
662
|
}
|
|
663
|
+
} catch (err) {
|
|
664
|
+
candidateError = err
|
|
665
|
+
candidateFailed = true
|
|
666
|
+
}
|
|
667
|
+
if (candidateFailed) {
|
|
668
|
+
wasiBindingErrors.push(candidateError)
|
|
669
|
+
loadErrors.push(candidateError)
|
|
566
670
|
}
|
|
567
671
|
}
|
|
568
|
-
if (
|
|
569
|
-
|
|
570
|
-
|
|
672
|
+
if (
|
|
673
|
+
!wasiBindingLoaded &&
|
|
674
|
+
forceWasi &&
|
|
675
|
+
!forceWasiError &&
|
|
676
|
+
!__napiWasiFlavorRequested
|
|
677
|
+
) {
|
|
678
|
+
nativeBinding = requireNative()
|
|
679
|
+
}
|
|
680
|
+
if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
|
|
681
|
+
const error = new Error(
|
|
682
|
+
__napiWasiFlavorRequested
|
|
683
|
+
? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
|
|
684
|
+
: 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
|
|
685
|
+
)
|
|
686
|
+
error.cause = createLoadErrorChain(wasiBindingErrors)
|
|
571
687
|
throw error
|
|
572
688
|
}
|
|
573
689
|
}
|
|
@@ -581,10 +697,7 @@ if (!nativeBinding) {
|
|
|
581
697
|
)
|
|
582
698
|
// assign instead of the `new Error(message, { cause })` options form,
|
|
583
699
|
// which Node < 16.9 silently ignores
|
|
584
|
-
error.cause = loadErrors
|
|
585
|
-
cur.cause = err
|
|
586
|
-
return cur
|
|
587
|
-
})
|
|
700
|
+
error.cause = createLoadErrorChain(loadErrors)
|
|
588
701
|
throw error
|
|
589
702
|
}
|
|
590
703
|
throw new Error(`Failed to load native binding`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unownplain/anthelion-komac",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.55",
|
|
4
4
|
"description": "komac JS bindings for Anthelion",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"version": "napi version"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@napi-rs/cli": "3.
|
|
25
|
+
"@napi-rs/cli": "3.8.2"
|
|
26
26
|
},
|
|
27
27
|
"napi": {
|
|
28
28
|
"binaryName": "anthelion-komac",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"node": ">=22.0.0"
|
|
42
42
|
},
|
|
43
43
|
"optionalDependencies": {
|
|
44
|
-
"@unownplain/anthelion-komac-win32-x64-msvc": "0.0.
|
|
45
|
-
"@unownplain/anthelion-komac-darwin-x64": "0.0.
|
|
46
|
-
"@unownplain/anthelion-komac-linux-x64-gnu": "0.0.
|
|
47
|
-
"@unownplain/anthelion-komac-linux-x64-musl": "0.0.
|
|
48
|
-
"@unownplain/anthelion-komac-darwin-arm64": "0.0.
|
|
49
|
-
"@unownplain/anthelion-komac-linux-arm64-gnu": "0.0.
|
|
50
|
-
"@unownplain/anthelion-komac-linux-arm64-musl": "0.0.
|
|
51
|
-
"@unownplain/anthelion-komac-win32-arm64-msvc": "0.0.
|
|
44
|
+
"@unownplain/anthelion-komac-win32-x64-msvc": "0.0.55",
|
|
45
|
+
"@unownplain/anthelion-komac-darwin-x64": "0.0.55",
|
|
46
|
+
"@unownplain/anthelion-komac-linux-x64-gnu": "0.0.55",
|
|
47
|
+
"@unownplain/anthelion-komac-linux-x64-musl": "0.0.55",
|
|
48
|
+
"@unownplain/anthelion-komac-darwin-arm64": "0.0.55",
|
|
49
|
+
"@unownplain/anthelion-komac-linux-arm64-gnu": "0.0.55",
|
|
50
|
+
"@unownplain/anthelion-komac-linux-arm64-musl": "0.0.55",
|
|
51
|
+
"@unownplain/anthelion-komac-win32-arm64-msvc": "0.0.55"
|
|
52
52
|
}
|
|
53
53
|
}
|