@env-lane/native 0.0.0 → 0.5.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bill Toshiaki Stark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
1
  # @env-lane/native
2
2
 
3
- Version 0.0.0 reserves this public package name for env-lane 0.5.0 trusted publishing. It is not a functional release.
3
+ Rust Node-API application binding for `@env-lane/core` and `@env-lane/vault`. The package
4
+ selects an optional platform addon at runtime. Platform packages also contain the standalone
5
+ `env-lane` executable, which the npm CLI installer copies to its bin path.
6
+
7
+ Build locally with `pnpm --filter @env-lane/native build`.
package/bin.cjs ADDED
@@ -0,0 +1,29 @@
1
+ const path = require('node:path')
2
+
3
+ function platformSuffix() {
4
+ const { platform, arch } = process
5
+ if (arch !== 'arm64' && arch !== 'x64') {
6
+ throw new Error(`Unsupported env-lane native architecture: ${arch}`)
7
+ }
8
+ if (platform === 'darwin') return `darwin-${arch === 'arm64' ? 'arm64' : 'x64'}`
9
+ if (platform === 'win32') return `win32-${arch === 'arm64' ? 'arm64' : 'x64'}-msvc`
10
+ if (platform === 'linux') {
11
+ const musl = !process.report?.getReport()?.header?.glibcVersionRuntime
12
+ return `linux-${arch === 'arm64' ? 'arm64' : 'x64'}-${musl ? 'musl' : 'gnu'}`
13
+ }
14
+ throw new Error(`Unsupported env-lane native platform: ${platform}/${arch}`)
15
+ }
16
+
17
+ function resolveBinary() {
18
+ if (process.env.ENV_LANE_NATIVE_BINARY) return path.resolve(process.env.ENV_LANE_NATIVE_BINARY)
19
+ const name = `@env-lane/native-${platformSuffix()}`
20
+ let addon
21
+ try {
22
+ addon = require.resolve(name)
23
+ } catch (error) {
24
+ throw new Error(`Native env-lane package ${name} is not installed`, { cause: error })
25
+ }
26
+ return path.join(path.dirname(addon), process.platform === 'win32' ? 'env-lane.exe' : 'env-lane')
27
+ }
28
+
29
+ module.exports = { platformSuffix, resolveBinary }
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* 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
+
12
+ /**
13
+ * A transport envelope carries stable error codes and data without forcing
14
+ * application objects through duplicate Node-API schemas.
15
+ */
16
+ export declare function invoke(operation: string, request: string): string
package/index.js ADDED
@@ -0,0 +1,782 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ /* auto-generated by NAPI-RS */
4
+
5
+ const { readFileSync } = require('fs')
6
+ const __napiExpectedVersion = require('./package.json').version
7
+ let nativeBinding = null
8
+ // Which artifact actually loaded. The WASI fallback chain overwrites it with
9
+ // the flavor it resolved; the late native retry below leaves it alone because
10
+ // it only runs while no WASI candidate has been loaded.
11
+ let __napiLoadedBindingTarget = 'native'
12
+ const loadErrors = []
13
+
14
+ const isMusl = () => {
15
+ let musl = false
16
+ if (process.platform === 'linux') {
17
+ musl = isMuslFromFilesystem()
18
+ if (musl === null) {
19
+ musl = isMuslFromReport()
20
+ }
21
+ if (musl === null) {
22
+ musl = isMuslFromChildProcess()
23
+ }
24
+ }
25
+ return musl
26
+ }
27
+
28
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
29
+
30
+ const isMuslFromFilesystem = () => {
31
+ try {
32
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
33
+ } catch {
34
+ return null
35
+ }
36
+ }
37
+
38
+ const isMuslFromReport = () => {
39
+ let report = null
40
+ if (process.report && typeof process.report.getReport === 'function') {
41
+ process.report.excludeNetwork = true
42
+ report = process.report.getReport()
43
+ }
44
+ if (!report) {
45
+ return null
46
+ }
47
+ if (report.header && report.header.glibcVersionRuntime) {
48
+ return false
49
+ }
50
+ if (Array.isArray(report.sharedObjects)) {
51
+ if (report.sharedObjects.some(isFileMusl)) {
52
+ return true
53
+ }
54
+ }
55
+ return false
56
+ }
57
+
58
+ const isMuslFromChildProcess = () => {
59
+ try {
60
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
61
+ } catch (e) {
62
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
63
+ return false
64
+ }
65
+ }
66
+
67
+ function requireNative() {
68
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
69
+ try {
70
+ const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
71
+ // The override may be a generated WASI loader, which already reports its
72
+ // own flavor. Adopt it: `module.exports` aliases this object, so claiming
73
+ // 'native' would both misreport the artifact and overwrite the loader's
74
+ // marker through the alias.
75
+ __napiLoadedBindingTarget =
76
+ overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
77
+ ? overrideBinding.__napiBindingTarget
78
+ : 'native'
79
+ return overrideBinding
80
+ } catch (err) {
81
+ loadErrors.push(err)
82
+ }
83
+ } else if (process.platform === 'android') {
84
+ if (process.arch === 'arm64') {
85
+ try {
86
+ return require('./env-lane-native.android-arm64.node')
87
+ } catch (e) {
88
+ loadErrors.push(e)
89
+ }
90
+ try {
91
+ const binding = require('@env-lane/native-android-arm64')
92
+ const bindingPackageVersion = require('@env-lane/native-android-arm64/package.json').version
93
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
94
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
95
+ }
96
+ return binding
97
+ } catch (e) {
98
+ loadErrors.push(e)
99
+ }
100
+ } else if (process.arch === 'arm') {
101
+ try {
102
+ return require('./env-lane-native.android-arm-eabi.node')
103
+ } catch (e) {
104
+ loadErrors.push(e)
105
+ }
106
+ try {
107
+ const binding = require('@env-lane/native-android-arm-eabi')
108
+ const bindingPackageVersion = require('@env-lane/native-android-arm-eabi/package.json').version
109
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
110
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
111
+ }
112
+ return binding
113
+ } catch (e) {
114
+ loadErrors.push(e)
115
+ }
116
+ } else {
117
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
118
+ }
119
+ } else if (process.platform === 'win32') {
120
+ if (process.arch === 'x64') {
121
+ 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')) {
122
+ try {
123
+ return require('./env-lane-native.win32-x64-gnu.node')
124
+ } catch (e) {
125
+ loadErrors.push(e)
126
+ }
127
+ try {
128
+ const binding = require('@env-lane/native-win32-x64-gnu')
129
+ const bindingPackageVersion = require('@env-lane/native-win32-x64-gnu/package.json').version
130
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
131
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
132
+ }
133
+ return binding
134
+ } catch (e) {
135
+ loadErrors.push(e)
136
+ }
137
+ } else {
138
+ try {
139
+ return require('./env-lane-native.win32-x64-msvc.node')
140
+ } catch (e) {
141
+ loadErrors.push(e)
142
+ }
143
+ try {
144
+ const binding = require('@env-lane/native-win32-x64-msvc')
145
+ const bindingPackageVersion = require('@env-lane/native-win32-x64-msvc/package.json').version
146
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
147
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
148
+ }
149
+ return binding
150
+ } catch (e) {
151
+ loadErrors.push(e)
152
+ }
153
+ }
154
+ } else if (process.arch === 'ia32') {
155
+ try {
156
+ return require('./env-lane-native.win32-ia32-msvc.node')
157
+ } catch (e) {
158
+ loadErrors.push(e)
159
+ }
160
+ try {
161
+ const binding = require('@env-lane/native-win32-ia32-msvc')
162
+ const bindingPackageVersion = require('@env-lane/native-win32-ia32-msvc/package.json').version
163
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
164
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
165
+ }
166
+ return binding
167
+ } catch (e) {
168
+ loadErrors.push(e)
169
+ }
170
+ } else if (process.arch === 'arm64') {
171
+ try {
172
+ return require('./env-lane-native.win32-arm64-msvc.node')
173
+ } catch (e) {
174
+ loadErrors.push(e)
175
+ }
176
+ try {
177
+ const binding = require('@env-lane/native-win32-arm64-msvc')
178
+ const bindingPackageVersion = require('@env-lane/native-win32-arm64-msvc/package.json').version
179
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
180
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
181
+ }
182
+ return binding
183
+ } catch (e) {
184
+ loadErrors.push(e)
185
+ }
186
+ } else {
187
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
188
+ }
189
+ } else if (process.platform === 'darwin') {
190
+ try {
191
+ return require('./env-lane-native.darwin-universal.node')
192
+ } catch (e) {
193
+ loadErrors.push(e)
194
+ }
195
+ try {
196
+ const binding = require('@env-lane/native-darwin-universal')
197
+ const bindingPackageVersion = require('@env-lane/native-darwin-universal/package.json').version
198
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
199
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
200
+ }
201
+ return binding
202
+ } catch (e) {
203
+ loadErrors.push(e)
204
+ }
205
+ if (process.arch === 'x64') {
206
+ try {
207
+ return require('./env-lane-native.darwin-x64.node')
208
+ } catch (e) {
209
+ loadErrors.push(e)
210
+ }
211
+ try {
212
+ const binding = require('@env-lane/native-darwin-x64')
213
+ const bindingPackageVersion = require('@env-lane/native-darwin-x64/package.json').version
214
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
215
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
216
+ }
217
+ return binding
218
+ } catch (e) {
219
+ loadErrors.push(e)
220
+ }
221
+ } else if (process.arch === 'arm64') {
222
+ try {
223
+ return require('./env-lane-native.darwin-arm64.node')
224
+ } catch (e) {
225
+ loadErrors.push(e)
226
+ }
227
+ try {
228
+ const binding = require('@env-lane/native-darwin-arm64')
229
+ const bindingPackageVersion = require('@env-lane/native-darwin-arm64/package.json').version
230
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
231
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
232
+ }
233
+ return binding
234
+ } catch (e) {
235
+ loadErrors.push(e)
236
+ }
237
+ } else {
238
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
239
+ }
240
+ } else if (process.platform === 'freebsd') {
241
+ if (process.arch === 'x64') {
242
+ try {
243
+ return require('./env-lane-native.freebsd-x64.node')
244
+ } catch (e) {
245
+ loadErrors.push(e)
246
+ }
247
+ try {
248
+ const binding = require('@env-lane/native-freebsd-x64')
249
+ const bindingPackageVersion = require('@env-lane/native-freebsd-x64/package.json').version
250
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
251
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
252
+ }
253
+ return binding
254
+ } catch (e) {
255
+ loadErrors.push(e)
256
+ }
257
+ } else if (process.arch === 'arm64') {
258
+ try {
259
+ return require('./env-lane-native.freebsd-arm64.node')
260
+ } catch (e) {
261
+ loadErrors.push(e)
262
+ }
263
+ try {
264
+ const binding = require('@env-lane/native-freebsd-arm64')
265
+ const bindingPackageVersion = require('@env-lane/native-freebsd-arm64/package.json').version
266
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
267
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
268
+ }
269
+ return binding
270
+ } catch (e) {
271
+ loadErrors.push(e)
272
+ }
273
+ } else {
274
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
275
+ }
276
+ } else if (process.platform === 'linux') {
277
+ if (process.arch === 'x64') {
278
+ if (isMusl()) {
279
+ try {
280
+ return require('./env-lane-native.linux-x64-musl.node')
281
+ } catch (e) {
282
+ loadErrors.push(e)
283
+ }
284
+ try {
285
+ const binding = require('@env-lane/native-linux-x64-musl')
286
+ const bindingPackageVersion = require('@env-lane/native-linux-x64-musl/package.json').version
287
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
288
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
289
+ }
290
+ return binding
291
+ } catch (e) {
292
+ loadErrors.push(e)
293
+ }
294
+ } else {
295
+ try {
296
+ return require('./env-lane-native.linux-x64-gnu.node')
297
+ } catch (e) {
298
+ loadErrors.push(e)
299
+ }
300
+ try {
301
+ const binding = require('@env-lane/native-linux-x64-gnu')
302
+ const bindingPackageVersion = require('@env-lane/native-linux-x64-gnu/package.json').version
303
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
304
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
305
+ }
306
+ return binding
307
+ } catch (e) {
308
+ loadErrors.push(e)
309
+ }
310
+ }
311
+ } else if (process.arch === 'arm64') {
312
+ if (isMusl()) {
313
+ try {
314
+ return require('./env-lane-native.linux-arm64-musl.node')
315
+ } catch (e) {
316
+ loadErrors.push(e)
317
+ }
318
+ try {
319
+ const binding = require('@env-lane/native-linux-arm64-musl')
320
+ const bindingPackageVersion = require('@env-lane/native-linux-arm64-musl/package.json').version
321
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
322
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
323
+ }
324
+ return binding
325
+ } catch (e) {
326
+ loadErrors.push(e)
327
+ }
328
+ } else {
329
+ try {
330
+ return require('./env-lane-native.linux-arm64-gnu.node')
331
+ } catch (e) {
332
+ loadErrors.push(e)
333
+ }
334
+ try {
335
+ const binding = require('@env-lane/native-linux-arm64-gnu')
336
+ const bindingPackageVersion = require('@env-lane/native-linux-arm64-gnu/package.json').version
337
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
338
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
339
+ }
340
+ return binding
341
+ } catch (e) {
342
+ loadErrors.push(e)
343
+ }
344
+ }
345
+ } else if (process.arch === 'arm') {
346
+ if (isMusl()) {
347
+ try {
348
+ return require('./env-lane-native.linux-arm-musleabihf.node')
349
+ } catch (e) {
350
+ loadErrors.push(e)
351
+ }
352
+ try {
353
+ const binding = require('@env-lane/native-linux-arm-musleabihf')
354
+ const bindingPackageVersion = require('@env-lane/native-linux-arm-musleabihf/package.json').version
355
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
356
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
357
+ }
358
+ return binding
359
+ } catch (e) {
360
+ loadErrors.push(e)
361
+ }
362
+ } else {
363
+ try {
364
+ return require('./env-lane-native.linux-arm-gnueabihf.node')
365
+ } catch (e) {
366
+ loadErrors.push(e)
367
+ }
368
+ try {
369
+ const binding = require('@env-lane/native-linux-arm-gnueabihf')
370
+ const bindingPackageVersion = require('@env-lane/native-linux-arm-gnueabihf/package.json').version
371
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
372
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
373
+ }
374
+ return binding
375
+ } catch (e) {
376
+ loadErrors.push(e)
377
+ }
378
+ }
379
+ } else if (process.arch === 'loong64') {
380
+ if (isMusl()) {
381
+ try {
382
+ return require('./env-lane-native.linux-loong64-musl.node')
383
+ } catch (e) {
384
+ loadErrors.push(e)
385
+ }
386
+ try {
387
+ const binding = require('@env-lane/native-linux-loong64-musl')
388
+ const bindingPackageVersion = require('@env-lane/native-linux-loong64-musl/package.json').version
389
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
390
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
391
+ }
392
+ return binding
393
+ } catch (e) {
394
+ loadErrors.push(e)
395
+ }
396
+ } else {
397
+ try {
398
+ return require('./env-lane-native.linux-loong64-gnu.node')
399
+ } catch (e) {
400
+ loadErrors.push(e)
401
+ }
402
+ try {
403
+ const binding = require('@env-lane/native-linux-loong64-gnu')
404
+ const bindingPackageVersion = require('@env-lane/native-linux-loong64-gnu/package.json').version
405
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
406
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
407
+ }
408
+ return binding
409
+ } catch (e) {
410
+ loadErrors.push(e)
411
+ }
412
+ }
413
+ } else if (process.arch === 'riscv64') {
414
+ if (isMusl()) {
415
+ try {
416
+ return require('./env-lane-native.linux-riscv64-musl.node')
417
+ } catch (e) {
418
+ loadErrors.push(e)
419
+ }
420
+ try {
421
+ const binding = require('@env-lane/native-linux-riscv64-musl')
422
+ const bindingPackageVersion = require('@env-lane/native-linux-riscv64-musl/package.json').version
423
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
424
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
425
+ }
426
+ return binding
427
+ } catch (e) {
428
+ loadErrors.push(e)
429
+ }
430
+ } else {
431
+ try {
432
+ return require('./env-lane-native.linux-riscv64-gnu.node')
433
+ } catch (e) {
434
+ loadErrors.push(e)
435
+ }
436
+ try {
437
+ const binding = require('@env-lane/native-linux-riscv64-gnu')
438
+ const bindingPackageVersion = require('@env-lane/native-linux-riscv64-gnu/package.json').version
439
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
440
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
441
+ }
442
+ return binding
443
+ } catch (e) {
444
+ loadErrors.push(e)
445
+ }
446
+ }
447
+ } else if (process.arch === 'ppc64') {
448
+ try {
449
+ return require('./env-lane-native.linux-ppc64-gnu.node')
450
+ } catch (e) {
451
+ loadErrors.push(e)
452
+ }
453
+ try {
454
+ const binding = require('@env-lane/native-linux-ppc64-gnu')
455
+ const bindingPackageVersion = require('@env-lane/native-linux-ppc64-gnu/package.json').version
456
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
457
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
458
+ }
459
+ return binding
460
+ } catch (e) {
461
+ loadErrors.push(e)
462
+ }
463
+ } else if (process.arch === 's390x') {
464
+ try {
465
+ return require('./env-lane-native.linux-s390x-gnu.node')
466
+ } catch (e) {
467
+ loadErrors.push(e)
468
+ }
469
+ try {
470
+ const binding = require('@env-lane/native-linux-s390x-gnu')
471
+ const bindingPackageVersion = require('@env-lane/native-linux-s390x-gnu/package.json').version
472
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
473
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
474
+ }
475
+ return binding
476
+ } catch (e) {
477
+ loadErrors.push(e)
478
+ }
479
+ } else {
480
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
481
+ }
482
+ } else if (process.platform === 'openharmony') {
483
+ if (process.arch === 'arm64') {
484
+ try {
485
+ return require('./env-lane-native.openharmony-arm64.node')
486
+ } catch (e) {
487
+ loadErrors.push(e)
488
+ }
489
+ try {
490
+ const binding = require('@env-lane/native-openharmony-arm64')
491
+ const bindingPackageVersion = require('@env-lane/native-openharmony-arm64/package.json').version
492
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
493
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
494
+ }
495
+ return binding
496
+ } catch (e) {
497
+ loadErrors.push(e)
498
+ }
499
+ } else if (process.arch === 'x64') {
500
+ try {
501
+ return require('./env-lane-native.openharmony-x64.node')
502
+ } catch (e) {
503
+ loadErrors.push(e)
504
+ }
505
+ try {
506
+ const binding = require('@env-lane/native-openharmony-x64')
507
+ const bindingPackageVersion = require('@env-lane/native-openharmony-x64/package.json').version
508
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
509
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
510
+ }
511
+ return binding
512
+ } catch (e) {
513
+ loadErrors.push(e)
514
+ }
515
+ } else if (process.arch === 'arm') {
516
+ try {
517
+ return require('./env-lane-native.openharmony-arm.node')
518
+ } catch (e) {
519
+ loadErrors.push(e)
520
+ }
521
+ try {
522
+ const binding = require('@env-lane/native-openharmony-arm')
523
+ const bindingPackageVersion = require('@env-lane/native-openharmony-arm/package.json').version
524
+ if (bindingPackageVersion !== __napiExpectedVersion && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
525
+ throw new Error(`Native binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
526
+ }
527
+ return binding
528
+ } catch (e) {
529
+ loadErrors.push(e)
530
+ }
531
+ } else {
532
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
533
+ }
534
+ } else {
535
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
536
+ }
537
+ }
538
+
539
+ function createLoadErrorChain(errors) {
540
+ return errors.reduce((previous, current) => {
541
+ let message
542
+ try {
543
+ message =
544
+ current && typeof current.message === 'string'
545
+ ? current.message
546
+ : String(current)
547
+ } catch {
548
+ message = 'Unknown error'
549
+ }
550
+ const error = new Error(message)
551
+ error.cause = previous
552
+ return error
553
+ }, null)
554
+ }
555
+
556
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
557
+ // unset / any other value → native binding preferred, WASI is only a fallback
558
+ // 'true' → prefer WASI, but retain native as a lazy fallback
559
+ // 'error' → require WASI without initializing a native fallback
560
+ // Treating any non-empty string as truthy (the historical behavior) meant
561
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
562
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
563
+ //
564
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
565
+ // WASI loading. It never crosses into another flavor or falls back to native.
566
+ const __napiWasiFlavors = ['wasm32-wasi']
567
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
568
+ const __napiWasiFlavorRequested =
569
+ typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
570
+ if (
571
+ __napiWasiFlavorRequested &&
572
+ __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
573
+ ) {
574
+ throw new Error(
575
+ 'Unsupported WASI flavor "' +
576
+ __napiWasiFlavor +
577
+ '". Available flavors: ' +
578
+ __napiWasiFlavors.join(', '),
579
+ )
580
+ }
581
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
582
+ const forceWasi =
583
+ process.env.NAPI_RS_FORCE_WASI === 'true' ||
584
+ forceWasiError ||
585
+ __napiWasiFlavorRequested
586
+
587
+ if (!forceWasi) {
588
+ nativeBinding = requireNative()
589
+ }
590
+
591
+ if (!nativeBinding || forceWasi) {
592
+ let wasiBinding = null
593
+ let wasiBindingLoaded = false
594
+ const wasiBindingErrors = []
595
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
596
+ try {
597
+ require.resolve(specifier)
598
+ } catch (resolveError) {
599
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
600
+ throw resolveError
601
+ }
602
+ if (isPackage) {
603
+ try {
604
+ require.resolve(specifier + '/package.json')
605
+ } catch (packageError) {
606
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
607
+ return resolveError
608
+ }
609
+ // An exports restriction proves the package exists even when its
610
+ // package.json is not public. Preserve the root resolution failure.
611
+ throw resolveError
612
+ }
613
+ // The package exists but its main/export target is broken.
614
+ throw resolveError
615
+ }
616
+ return resolveError
617
+ }
618
+ if (localArtifacts) {
619
+ let artifactError = null
620
+ for (let i = 0; i < localArtifacts.length; i++) {
621
+ try {
622
+ require.resolve(localArtifacts[i])
623
+ return null
624
+ } catch (resolveError) {
625
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
626
+ throw resolveError
627
+ }
628
+ artifactError = resolveError
629
+ }
630
+ }
631
+ return artifactError
632
+ }
633
+ return null
634
+ }
635
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
636
+ let candidateError = null
637
+ let candidateFailed = false
638
+ try {
639
+ candidateError = __napiWasiResolveCandidate('./env-lane-native.wasi.cjs', false, ['./env-lane-native.wasm32-wasi.debug.wasm', './env-lane-native.wasm32-wasi.wasm'])
640
+ candidateFailed = candidateError !== null
641
+ if (!candidateFailed) {
642
+ wasiBinding = require('./env-lane-native.wasi.cjs')
643
+ nativeBinding = wasiBinding
644
+ __napiLoadedBindingTarget = 'wasm32-wasi'
645
+ wasiBindingLoaded = true
646
+ }
647
+ } catch (err) {
648
+ candidateError = err
649
+ candidateFailed = true
650
+ }
651
+ if (candidateFailed) {
652
+ wasiBindingErrors.push(candidateError)
653
+ loadErrors.push(candidateError)
654
+ }
655
+ }
656
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
657
+ let candidateError = null
658
+ let candidateFailed = false
659
+ try {
660
+ candidateError = __napiWasiResolveCandidate('@env-lane/native-wasm32-wasi', true, undefined)
661
+ candidateFailed = candidateError !== null
662
+ if (!candidateFailed) {
663
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
664
+ const bindingPackageVersion = require('@env-lane/native-wasm32-wasi/package.json').version
665
+ if (bindingPackageVersion !== __napiExpectedVersion) {
666
+ throw new Error(`WASI binding package version mismatch, expected ${__napiExpectedVersion} but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
667
+ }
668
+ }
669
+ wasiBinding = require('@env-lane/native-wasm32-wasi')
670
+ nativeBinding = wasiBinding
671
+ __napiLoadedBindingTarget = 'wasm32-wasi'
672
+ wasiBindingLoaded = true
673
+ }
674
+ } catch (err) {
675
+ candidateError = err
676
+ candidateFailed = true
677
+ }
678
+ if (candidateFailed) {
679
+ wasiBindingErrors.push(candidateError)
680
+ loadErrors.push(candidateError)
681
+ }
682
+ }
683
+ if (
684
+ !wasiBindingLoaded &&
685
+ forceWasi &&
686
+ !forceWasiError &&
687
+ !__napiWasiFlavorRequested
688
+ ) {
689
+ nativeBinding = requireNative()
690
+ }
691
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
692
+ const error = new Error(
693
+ __napiWasiFlavorRequested
694
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
695
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
696
+ )
697
+ error.cause = createLoadErrorChain(wasiBindingErrors)
698
+ throw error
699
+ }
700
+ }
701
+
702
+ if (!nativeBinding) {
703
+ if (loadErrors.length > 0) {
704
+ const error = new Error(
705
+ `Cannot find native binding. ` +
706
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
707
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
708
+ )
709
+ // assign instead of the `new Error(message, { cause })` options form,
710
+ // which Node < 16.9 silently ignores
711
+ error.cause = createLoadErrorChain(loadErrors)
712
+ throw error
713
+ }
714
+ throw new Error(`Failed to load native binding`)
715
+ }
716
+
717
+ function __napiStampBindingTarget(exportsObject, target) {
718
+ if (
719
+ Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')
720
+ ) {
721
+ if (exportsObject.__napiBindingTarget === target) {
722
+ // Already ours: the root entry aliases the object it loaded, so a WASI
723
+ // fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
724
+ // is a generated loader — arrives already stamped with this same value.
725
+ return target
726
+ }
727
+ const error = new Error(
728
+ '`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
729
+ )
730
+ error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT'
731
+ throw error
732
+ }
733
+ if (!Object.isExtensible(exportsObject)) {
734
+ // A `#[napi(module_exports)]` hook may seal or freeze this object
735
+ // (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
736
+ // never a reason to fail an otherwise successful load, so the stamp is
737
+ // skipped. What a consumer still sees then follows the entry point: the
738
+ // browser and deferred loaders declare `__napiBindingTarget` at module
739
+ // level and go on reporting it, while the CommonJS entries hand back this
740
+ // very object as `module.exports`, so there the value is absent.
741
+ return target
742
+ }
743
+ try {
744
+ // [[Define]], not [[Set]]: an ordinary assignment walks the prototype
745
+ // chain, so an inherited accessor could swallow the value or throw and
746
+ // fail an otherwise successful load. The descriptor is what a successful
747
+ // assignment would have produced.
748
+ Object.defineProperty(exportsObject, '__napiBindingTarget', {
749
+ configurable: true,
750
+ enumerable: true,
751
+ value: target,
752
+ writable: true,
753
+ })
754
+ } catch {
755
+ // Same rule as the non-extensible skip above: reporting the artifact is
756
+ // metadata, never a reason to fail an otherwise successful load. An exotic
757
+ // object (a Proxy whose defineProperty trap refuses) is skipped, not
758
+ // thrown over.
759
+ }
760
+ // The CommonJS loaders assign this return value so `cjs-module-lexer` — and
761
+ // therefore Node's CJS -> ESM named export detection — can see
762
+ // `__napiBindingTarget` statically.
763
+ return target
764
+ }
765
+ // Stamp before the alias, not after. The guard only reads `nativeBinding`
766
+ // (`hasOwnProperty` plus a comparison), which is safe against any addon
767
+ // accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
768
+ // expose a getter reporting this very value and a setter that throws. So the
769
+ // assignment lands on the loader's own `module.exports`, still the original
770
+ // object here, and the alias below replaces it.
771
+ //
772
+ // The assignment is what keeps the marker a statically visible CommonJS export:
773
+ // `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
774
+ // a bare call, and the later `module.exports = nativeBinding` does not undo the
775
+ // detection. The assignment itself always succeeds — its target is this
776
+ // loader's own, still extensible `module.exports` — and the alias below then
777
+ // discards the value it wrote. What a consumer reads is whatever the guard put
778
+ // on `nativeBinding`, so on a frozen binding, where the guard skips, the
779
+ // linked import resolves to `undefined`.
780
+ module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
781
+ module.exports = nativeBinding
782
+ module.exports.invoke = nativeBinding.invoke
package/package.json CHANGED
@@ -1,16 +1,58 @@
1
1
  {
2
2
  "name": "@env-lane/native",
3
- "version": "0.0.0",
4
- "description": "Bootstrap placeholder for the env-lane 0.5.0 trusted release",
3
+ "version": "0.5.0",
4
+ "description": "Native Node-API binding for env-lane",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/billstark001/env-lane.git"
8
+ "url": "git+https://github.com/billstark001/env-lane.git",
9
+ "directory": "packages/native"
10
+ },
11
+ "engines": {
12
+ "node": ">=22"
9
13
  },
10
14
  "publishConfig": {
11
- "access": "public"
15
+ "access": "public",
16
+ "provenance": true
12
17
  },
18
+ "main": "index.js",
19
+ "types": "index.d.ts",
13
20
  "files": [
14
- "README.md"
15
- ]
21
+ "index.js",
22
+ "index.d.ts",
23
+ "bin.cjs",
24
+ "*.node",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "napi": {
29
+ "binaryName": "env-lane-native",
30
+ "targets": [
31
+ "aarch64-apple-darwin",
32
+ "x86_64-apple-darwin",
33
+ "x86_64-unknown-linux-gnu",
34
+ "aarch64-unknown-linux-gnu",
35
+ "x86_64-unknown-linux-musl",
36
+ "aarch64-unknown-linux-musl",
37
+ "x86_64-pc-windows-msvc",
38
+ "aarch64-pc-windows-msvc"
39
+ ]
40
+ },
41
+ "scripts": {
42
+ "build": "napi build --cwd . --manifest-path ../../Cargo.toml --package env-lane-node --platform --output-dir . && node scripts/normalize-loader.mjs",
43
+ "typecheck": "node --check index.js"
44
+ },
45
+ "devDependencies": {
46
+ "@napi-rs/cli": "^3.0.0"
47
+ },
48
+ "optionalDependencies": {
49
+ "@env-lane/native-darwin-arm64": "0.5.0",
50
+ "@env-lane/native-darwin-x64": "0.5.0",
51
+ "@env-lane/native-linux-x64-gnu": "0.5.0",
52
+ "@env-lane/native-linux-arm64-gnu": "0.5.0",
53
+ "@env-lane/native-linux-x64-musl": "0.5.0",
54
+ "@env-lane/native-linux-arm64-musl": "0.5.0",
55
+ "@env-lane/native-win32-x64-msvc": "0.5.0",
56
+ "@env-lane/native-win32-arm64-msvc": "0.5.0"
57
+ }
16
58
  }