Skip to content

Commit 8005f51

Browse files
authored
Merge pull request #332 from AreevAI/dependabot/npm_and_yarn/crates/areev-js/areev-js-npm-0eea5a21c8
deps: bump @napi-rs/cli from 3.9.0 to 3.10.3 in /crates/areev-js in the areev-js-npm group
2 parents 36ecf22 + faaef67 commit 8005f51

3 files changed

Lines changed: 133 additions & 46 deletions

File tree

‎crates/areev-js/index.d.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
/* auto-generated by NAPI-RS */
22
/* eslint-disable */
3+
4+
/**
5+
* Which binding artifact the generated loader actually loaded: `'native'` for
6+
* a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7+
* flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8+
* can point the loader at a WASI artifact this package does not build itself.
9+
*/
10+
export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11+
312
export declare class Areev {
413
constructor(path: string, ns?: string | undefined | null, passphrase?: string | undefined | null, actor?: string | undefined | null, telemetry?: string | undefined | null, principal?: string | undefined | null, indexText?: boolean | undefined | null, anonKey?: string | undefined | null, readOnly?: boolean | undefined | null)
514
/**

‎crates/areev-js/index.js‎

Lines changed: 110 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// prettier-ignore
21
/* eslint-disable */
32
// @ts-nocheck
43
/* auto-generated by NAPI-RS */
54

65
const { readFileSync } = require('fs')
76
let nativeBinding = null
7+
// Which artifact actually loaded. The WASI fallback chain overwrites it with
8+
// the flavor it resolved; the late native retry below leaves it alone because
9+
// it only runs while no WASI candidate has been loaded.
10+
let __napiLoadedBindingTarget = 'native'
811
const loadErrors = []
912

1013
const isMusl = () => {
@@ -63,7 +66,16 @@ const isMuslFromChildProcess = () => {
6366
function requireNative() {
6467
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
6568
try {
66-
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
69+
const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
70+
// The override may be a generated WASI loader, which already reports its
71+
// own flavor. Adopt it: `module.exports` aliases this object, so claiming
72+
// 'native' would both misreport the artifact and overwrite the loader's
73+
// marker through the alias.
74+
__napiLoadedBindingTarget =
75+
overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
76+
? overrideBinding.__napiBindingTarget
77+
: 'native'
78+
return overrideBinding
6779
} catch (err) {
6880
loadErrors.push(err)
6981
}
@@ -107,36 +119,36 @@ function requireNative() {
107119
if (process.arch === 'x64') {
108120
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
109121
try {
110-
return require('./areev.win32-x64-gnu.node')
111-
} catch (e) {
112-
loadErrors.push(e)
113-
}
114-
try {
115-
const binding = require('@areev/areev-win32-x64-gnu')
116-
const bindingPackageVersion = require('@areev/areev-win32-x64-gnu/package.json').version
117-
if (bindingPackageVersion !== '1.9.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118-
throw new Error(`Native binding package version mismatch, expected 1.9.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
122+
return require('./areev.win32-x64-gnu.node')
123+
} catch (e) {
124+
loadErrors.push(e)
125+
}
126+
try {
127+
const binding = require('@areev/areev-win32-x64-gnu')
128+
const bindingPackageVersion = require('@areev/areev-win32-x64-gnu/package.json').version
129+
if (bindingPackageVersion !== '1.9.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
130+
throw new Error(`Native binding package version mismatch, expected 1.9.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
131+
}
132+
return binding
133+
} catch (e) {
134+
loadErrors.push(e)
119135
}
120-
return binding
121-
} catch (e) {
122-
loadErrors.push(e)
123-
}
124136
} else {
125137
try {
126-
return require('./areev.win32-x64-msvc.node')
127-
} catch (e) {
128-
loadErrors.push(e)
129-
}
130-
try {
131-
const binding = require('@areev/areev-win32-x64-msvc')
132-
const bindingPackageVersion = require('@areev/areev-win32-x64-msvc/package.json').version
133-
if (bindingPackageVersion !== '1.9.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134-
throw new Error(`Native binding package version mismatch, expected 1.9.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
138+
return require('./areev.win32-x64-msvc.node')
139+
} catch (e) {
140+
loadErrors.push(e)
141+
}
142+
try {
143+
const binding = require('@areev/areev-win32-x64-msvc')
144+
const bindingPackageVersion = require('@areev/areev-win32-x64-msvc/package.json').version
145+
if (bindingPackageVersion !== '1.9.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
146+
throw new Error(`Native binding package version mismatch, expected 1.9.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
147+
}
148+
return binding
149+
} catch (e) {
150+
loadErrors.push(e)
135151
}
136-
return binding
137-
} catch (e) {
138-
loadErrors.push(e)
139-
}
140152
}
141153
} else if (process.arch === 'ia32') {
142154
try {
@@ -550,7 +562,7 @@ function createLoadErrorChain(errors) {
550562
//
551563
// NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
552564
// WASI loading. It never crosses into another flavor or falls back to native.
553-
const __napiWasiFlavors = ["wasm32-wasi"]
565+
const __napiWasiFlavors = ['wasm32-wasi']
554566
const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
555567
const __napiWasiFlavorRequested =
556568
typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
@@ -619,15 +631,16 @@ if (!nativeBinding || forceWasi) {
619631
}
620632
return null
621633
}
622-
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
634+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
623635
let candidateError = null
624636
let candidateFailed = false
625637
try {
626-
candidateError = __napiWasiResolveCandidate('./areev.wasi.cjs', false, ["./areev.wasm32-wasi.debug.wasm","./areev.wasm32-wasi.wasm"])
638+
candidateError = __napiWasiResolveCandidate('./areev.wasi.cjs', false, ['./areev.wasm32-wasi.debug.wasm', './areev.wasm32-wasi.wasm'])
627639
candidateFailed = candidateError !== null
628640
if (!candidateFailed) {
629641
wasiBinding = require('./areev.wasi.cjs')
630642
nativeBinding = wasiBinding
643+
__napiLoadedBindingTarget = 'wasm32-wasi'
631644
wasiBindingLoaded = true
632645
}
633646
} catch (err) {
@@ -639,7 +652,7 @@ if (!nativeBinding || forceWasi) {
639652
loadErrors.push(candidateError)
640653
}
641654
}
642-
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
655+
if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
643656
let candidateError = null
644657
let candidateFailed = false
645658
try {
@@ -654,6 +667,7 @@ if (!nativeBinding || forceWasi) {
654667
}
655668
wasiBinding = require('@areev/areev-wasm32-wasi')
656669
nativeBinding = wasiBinding
670+
__napiLoadedBindingTarget = 'wasm32-wasi'
657671
wasiBindingLoaded = true
658672
}
659673
} catch (err) {
@@ -699,6 +713,70 @@ if (!nativeBinding) {
699713
throw new Error(`Failed to load native binding`)
700714
}
701715

716+
function __napiStampBindingTarget(exportsObject, target) {
717+
if (
718+
Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')
719+
) {
720+
if (exportsObject.__napiBindingTarget === target) {
721+
// Already ours: the root entry aliases the object it loaded, so a WASI
722+
// fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
723+
// is a generated loader — arrives already stamped with this same value.
724+
return target
725+
}
726+
const error = new Error(
727+
'`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
728+
)
729+
error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT'
730+
throw error
731+
}
732+
if (!Object.isExtensible(exportsObject)) {
733+
// A `#[napi(module_exports)]` hook may seal or freeze this object
734+
// (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
735+
// never a reason to fail an otherwise successful load, so the stamp is
736+
// skipped. What a consumer still sees then follows the entry point: the
737+
// browser and deferred loaders declare `__napiBindingTarget` at module
738+
// level and go on reporting it, while the CommonJS entries hand back this
739+
// very object as `module.exports`, so there the value is absent.
740+
return target
741+
}
742+
try {
743+
// [[Define]], not [[Set]]: an ordinary assignment walks the prototype
744+
// chain, so an inherited accessor could swallow the value or throw and
745+
// fail an otherwise successful load. The descriptor is what a successful
746+
// assignment would have produced.
747+
Object.defineProperty(exportsObject, '__napiBindingTarget', {
748+
configurable: true,
749+
enumerable: true,
750+
value: target,
751+
writable: true,
752+
})
753+
} catch {
754+
// Same rule as the non-extensible skip above: reporting the artifact is
755+
// metadata, never a reason to fail an otherwise successful load. An exotic
756+
// object (a Proxy whose defineProperty trap refuses) is skipped, not
757+
// thrown over.
758+
}
759+
// The CommonJS loaders assign this return value so `cjs-module-lexer` — and
760+
// therefore Node's CJS -> ESM named export detection — can see
761+
// `__napiBindingTarget` statically.
762+
return target
763+
}
764+
// Stamp before the alias, not after. The guard only reads `nativeBinding`
765+
// (`hasOwnProperty` plus a comparison), which is safe against any addon
766+
// accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
767+
// expose a getter reporting this very value and a setter that throws. So the
768+
// assignment lands on the loader's own `module.exports`, still the original
769+
// object here, and the alias below replaces it.
770+
//
771+
// The assignment is what keeps the marker a statically visible CommonJS export:
772+
// `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
773+
// a bare call, and the later `module.exports = nativeBinding` does not undo the
774+
// detection. The assignment itself always succeeds — its target is this
775+
// loader's own, still extensible `module.exports` — and the alias below then
776+
// discards the value it wrote. What a consumer reads is whatever the guard put
777+
// on `nativeBinding`, so on a frozen binding, where the guard skips, the
778+
// linked import resolves to `undefined`.
779+
module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
702780
module.exports = nativeBinding
703781
module.exports.Areev = nativeBinding.Areev
704782
module.exports.dropPostgresSchema = nativeBinding.dropPostgresSchema

‎crates/areev-js/package-lock.json‎

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)