@local-sandbox/lsb-nodejs 0.1.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 +191 -0
- package/README.md +193 -0
- package/index.d.ts +106 -0
- package/index.js +561 -0
- package/package.json +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2025 SuperHQ AI
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# `@local-sandbox/lsb-nodejs`
|
|
2
|
+
|
|
3
|
+
Native Node.js bindings for [lsb](https://github.com/LocalSandBox/local-sandbox.git), built with
|
|
4
|
+
[`napi-rs`](https://napi.rs/).
|
|
5
|
+
|
|
6
|
+
This package is the canonical JavaScript and TypeScript entrypoint for lsb. It wraps the
|
|
7
|
+
Rust [`lsb-sdk`](../../crates/lsb-sdk) directly and exposes a Node-facing `Sandbox` API.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @local-sandbox/lsb-nodejs
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The published npm package is split into a root package plus a platform package. On supported hosts,
|
|
16
|
+
`npm` resolves and installs either `@local-sandbox/lsb-nodejs-darwin-arm64` or
|
|
17
|
+
`@local-sandbox/lsb-nodejs-darwin-x64` automatically.
|
|
18
|
+
|
|
19
|
+
For local development, use Corepack to run the Yarn version pinned in
|
|
20
|
+
[`package.json`](./package.json):
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
corepack yarn install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
- Node.js 18+
|
|
29
|
+
- macOS 14+ on Apple Silicon or Intel x86_64
|
|
30
|
+
- [lsb CLI](https://github.com/LocalSandBox/local-sandbox.git) installed
|
|
31
|
+
- `Sandbox.start()` expects the lsb runtime data directory to already exist. In the default
|
|
32
|
+
location, `~/.local/share/lsb/Image` must be present before booting a sandbox. This VM image
|
|
33
|
+
is not bundled with `@local-sandbox/lsb-nodejs` and needs to be downloaded manually as part of your
|
|
34
|
+
lsb runtime setup.
|
|
35
|
+
- On macOS, the `node` executable loading this SDK must be code signed with the
|
|
36
|
+
`com.apple.security.virtualization` entitlement. For a project-local workflow, sign a copied
|
|
37
|
+
Node binary with [`../../lsb.entitlements`](../../lsb.entitlements), or use
|
|
38
|
+
[`test:signed-node`](./package.json) as a reference.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Start a sandbox and run commands
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { Sandbox } from '@local-sandbox/lsb-nodejs'
|
|
46
|
+
|
|
47
|
+
const dataDir = `${process.env.HOME}/.local/share/lsb`
|
|
48
|
+
const sandbox = await Sandbox.start({
|
|
49
|
+
dataDir,
|
|
50
|
+
cpus: 2,
|
|
51
|
+
memory: 2048,
|
|
52
|
+
allowNet: true,
|
|
53
|
+
mounts: {
|
|
54
|
+
'./src': '/workspace',
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const result = await sandbox.exec('echo hello from lsb')
|
|
59
|
+
console.log(result.stdout)
|
|
60
|
+
|
|
61
|
+
await sandbox.writeFile('/tmp/demo.txt', 'hello')
|
|
62
|
+
const content = await sandbox.readFile('/tmp/demo.txt')
|
|
63
|
+
console.log(content.toString())
|
|
64
|
+
|
|
65
|
+
await sandbox.stop()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Pass argv directly or run through a shell
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { Sandbox } from '@local-sandbox/lsb-nodejs'
|
|
72
|
+
|
|
73
|
+
const sandbox = await Sandbox.start()
|
|
74
|
+
|
|
75
|
+
const argvResult = await sandbox.exec(['sh', '-lc', 'printf "%s" "$HOME"'])
|
|
76
|
+
console.log(argvResult.stdout)
|
|
77
|
+
|
|
78
|
+
const shellResult = await sandbox.execShell('uname -a')
|
|
79
|
+
console.log(shellResult.stdout)
|
|
80
|
+
|
|
81
|
+
await sandbox.stop()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Inspect the guest filesystem
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { Sandbox } from '@local-sandbox/lsb-nodejs'
|
|
88
|
+
|
|
89
|
+
const sandbox = await Sandbox.start()
|
|
90
|
+
|
|
91
|
+
await sandbox.writeFile('/tmp/demo.txt', 'hello from lsb')
|
|
92
|
+
|
|
93
|
+
const entries = await sandbox.readDir('/tmp')
|
|
94
|
+
const stat = await sandbox.stat('/tmp/demo.txt')
|
|
95
|
+
const exists = await sandbox.exists('/tmp/demo.txt')
|
|
96
|
+
|
|
97
|
+
console.log(entries.map((entry) => `${entry.type}: ${entry.name}`))
|
|
98
|
+
console.log({ size: stat.size, mode: stat.mode, exists })
|
|
99
|
+
|
|
100
|
+
await sandbox.stop()
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Save and resume from a checkpoint
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { Sandbox } from '@local-sandbox/lsb-nodejs'
|
|
107
|
+
|
|
108
|
+
const base = await Sandbox.start()
|
|
109
|
+
await base.exec('mkdir -p /workspace && echo ready > /workspace/state.txt')
|
|
110
|
+
await base.checkpoint('my-env')
|
|
111
|
+
|
|
112
|
+
const resumed = await Sandbox.start({ from: 'my-env' })
|
|
113
|
+
const state = await resumed.readFile('/workspace/state.txt')
|
|
114
|
+
console.log(state.toString())
|
|
115
|
+
|
|
116
|
+
await resumed.stop()
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Configure mounts, ports, secrets, and network policy
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { Sandbox } from '@local-sandbox/lsb-nodejs'
|
|
123
|
+
|
|
124
|
+
const sandbox = await Sandbox.start({
|
|
125
|
+
cpus: 4,
|
|
126
|
+
memory: 4096,
|
|
127
|
+
diskSize: 8192,
|
|
128
|
+
allowNet: true,
|
|
129
|
+
ports: ['8080:80'],
|
|
130
|
+
mounts: { './src': '/workspace' },
|
|
131
|
+
secrets: {
|
|
132
|
+
API_KEY: { value: 'sk-test', hosts: ['api.openai.com'] },
|
|
133
|
+
},
|
|
134
|
+
network: { allow: ['api.openai.com', 'registry.npmjs.org'] },
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
console.log(sandbox.instanceDir)
|
|
138
|
+
|
|
139
|
+
await sandbox.stop()
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Start options
|
|
143
|
+
|
|
144
|
+
| Option | Type | Description |
|
|
145
|
+
|--------|------|-------------|
|
|
146
|
+
| `from` | `string` | Checkpoint name to start from |
|
|
147
|
+
| `cpus` | `number` | Number of vCPUs |
|
|
148
|
+
| `memory` | `number` | Memory in MB |
|
|
149
|
+
| `diskSize` | `number` | Disk size in MB |
|
|
150
|
+
| `dataDir` | `string` | lsb runtime data directory |
|
|
151
|
+
| `allowNet` | `boolean` | Enable network access |
|
|
152
|
+
| `allowedHosts` | `string[]` | Additional allowlisted hosts |
|
|
153
|
+
| `ports` | `string[]` | Port forwards (`"host:guest"`) |
|
|
154
|
+
| `mounts` | `Record<string, string>` | Directory mounts (`{ hostPath: guestPath }`) |
|
|
155
|
+
| `secrets` | `Record<string, SecretConfig>` | Secrets injected via the lsb proxy |
|
|
156
|
+
| `network` | `NetworkConfig` | Network access policy |
|
|
157
|
+
|
|
158
|
+
## Scripts
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
corepack yarn build
|
|
162
|
+
corepack yarn test
|
|
163
|
+
corepack yarn test:signed-node
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`corepack yarn test` always builds the native binding first, then runs AVA against the
|
|
167
|
+
generated root entrypoint. The positive VM smoke test only runs when both of these are true:
|
|
168
|
+
|
|
169
|
+
- lsb runtime assets already exist in `~/.local/share/lsb` or in `LSB_NODEJS_TEST_DATA_DIR`
|
|
170
|
+
(`Image` is expected there and usually needs to be provisioned manually)
|
|
171
|
+
- the current `node` executable has the `com.apple.security.virtualization` entitlement
|
|
172
|
+
|
|
173
|
+
To avoid modifying your global Node installation, use [`test:signed-node`](./package.json),
|
|
174
|
+
which copies the current `node` binary into `.signed-node/node`, signs that local copy with
|
|
175
|
+
[`../../lsb.entitlements`](../../lsb.entitlements), prepends it to `PATH`, and then runs
|
|
176
|
+
the local `napi build --platform` plus `ava` commands through that signed Node:
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
corepack yarn test:signed-node
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
If runtime assets are missing, provision them in the lsb data directory first. The generated build outputs
|
|
183
|
+
(`index.js`, `index.d.ts`, `lsb-nodejs.*.node`) are local artifacts and are ignored by git.
|
|
184
|
+
This explicit smoke-test entrypoint will attempt a real VM boot; if your host still refuses
|
|
185
|
+
virtualization after signing the local Node copy, the command will surface that underlying error.
|
|
186
|
+
|
|
187
|
+
## Platform Notes
|
|
188
|
+
|
|
189
|
+
- Supported targets: macOS on Apple Silicon (`aarch64-apple-darwin`) and Intel (`x86_64-apple-darwin`).
|
|
190
|
+
- Installation is limited to supported macOS architectures. Unsupported platforms should fail during
|
|
191
|
+
`npm install` instead of installing a package that only errors at runtime.
|
|
192
|
+
- The published native binaries live in the platform packages
|
|
193
|
+
`@local-sandbox/lsb-nodejs-darwin-arm64` and `@local-sandbox/lsb-nodejs-darwin-x64`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class Sandbox {
|
|
4
|
+
static start(opts?: StartOptions | undefined | null): Promise<Sandbox>
|
|
5
|
+
exec(command: string | Array<string>, opts?: ExecOptions | undefined | null): Promise<ExecResult>
|
|
6
|
+
execShell(command: string): Promise<ExecResult>
|
|
7
|
+
spawn(command: string | Array<string>, opts?: SpawnOptions | undefined | null): Promise<SpawnedProcess>
|
|
8
|
+
watch(path: string, callback: (arg: FileChangeEvent) => unknown, opts?: WatchOptions | undefined | null): void
|
|
9
|
+
readFile(path: string): Promise<Buffer>
|
|
10
|
+
writeFile(path: string, content: string | Uint8Array): Promise<void>
|
|
11
|
+
mkdir(path: string, opts?: MkdirOptions | undefined | null): Promise<void>
|
|
12
|
+
readDir(path: string): Promise<Array<DirEntry>>
|
|
13
|
+
stat(path: string): Promise<StatResult>
|
|
14
|
+
remove(path: string, opts?: RemoveOptions | undefined | null): Promise<void>
|
|
15
|
+
rename(oldPath: string, newPath: string): Promise<void>
|
|
16
|
+
copy(src: string, dst: string, opts?: CopyOptions | undefined | null): Promise<void>
|
|
17
|
+
chmod(path: string, mode: number): Promise<void>
|
|
18
|
+
exists(path: string): Promise<boolean>
|
|
19
|
+
checkpoint(name: string): Promise<void>
|
|
20
|
+
stop(): Promise<void>
|
|
21
|
+
get instanceDir(): string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare class SpawnedProcess {
|
|
25
|
+
on(event: string, callback: (arg: unknown) => unknown): void
|
|
26
|
+
write(data: string | Uint8Array): void
|
|
27
|
+
kill(): Promise<void>
|
|
28
|
+
get pid(): string
|
|
29
|
+
get exited(): Promise<number>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CopyOptions {
|
|
33
|
+
recursive?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DirEntry {
|
|
37
|
+
name: string
|
|
38
|
+
type: string
|
|
39
|
+
size: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ExecOptions {
|
|
43
|
+
shell?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ExecResult {
|
|
47
|
+
stdout: string
|
|
48
|
+
stderr: string
|
|
49
|
+
exitCode: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface FileChangeEvent {
|
|
53
|
+
path: string
|
|
54
|
+
event: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface MkdirOptions {
|
|
58
|
+
recursive?: boolean
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface NetworkConfig {
|
|
62
|
+
allow?: Array<string>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface RemoveOptions {
|
|
66
|
+
recursive?: boolean
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface SecretConfig {
|
|
70
|
+
value: string
|
|
71
|
+
hosts: Array<string>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SpawnOptions {
|
|
75
|
+
cwd?: string
|
|
76
|
+
env?: Record<string, string>
|
|
77
|
+
shell?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface StartOptions {
|
|
81
|
+
instanceId?: string
|
|
82
|
+
from?: string
|
|
83
|
+
cpus?: number
|
|
84
|
+
memory?: number
|
|
85
|
+
diskSize?: number
|
|
86
|
+
dataDir?: string
|
|
87
|
+
allowNet?: boolean
|
|
88
|
+
allowedHosts?: Array<string>
|
|
89
|
+
ports?: Array<string>
|
|
90
|
+
mounts?: Record<string, string>
|
|
91
|
+
secrets?: Record<string, SecretConfig>
|
|
92
|
+
network?: NetworkConfig
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface StatResult {
|
|
96
|
+
size: number
|
|
97
|
+
mode: number
|
|
98
|
+
mtime: number
|
|
99
|
+
isDir: boolean
|
|
100
|
+
isFile: boolean
|
|
101
|
+
isSymlink: boolean
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface WatchOptions {
|
|
105
|
+
recursive?: boolean
|
|
106
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
require = createRequire(__filename)
|
|
8
|
+
|
|
9
|
+
const { readFileSync } = require('node:fs')
|
|
10
|
+
let nativeBinding = null
|
|
11
|
+
const loadErrors = []
|
|
12
|
+
|
|
13
|
+
const isMusl = () => {
|
|
14
|
+
let musl = false
|
|
15
|
+
if (process.platform === 'linux') {
|
|
16
|
+
musl = isMuslFromFilesystem()
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromReport()
|
|
19
|
+
}
|
|
20
|
+
if (musl === null) {
|
|
21
|
+
musl = isMuslFromChildProcess()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return musl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
28
|
+
|
|
29
|
+
const isMuslFromFilesystem = () => {
|
|
30
|
+
try {
|
|
31
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isMuslFromReport = () => {
|
|
38
|
+
let report = null
|
|
39
|
+
if (typeof process.report?.getReport === 'function') {
|
|
40
|
+
process.report.excludeNetwork = true
|
|
41
|
+
report = process.report.getReport()
|
|
42
|
+
}
|
|
43
|
+
if (!report) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
50
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isMuslFromChildProcess = () => {
|
|
58
|
+
try {
|
|
59
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requireNative() {
|
|
67
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
+
try {
|
|
69
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
loadErrors.push(err)
|
|
72
|
+
}
|
|
73
|
+
} else if (process.platform === 'android') {
|
|
74
|
+
if (process.arch === 'arm64') {
|
|
75
|
+
try {
|
|
76
|
+
return require('./lsb-nodejs.android-arm64.node')
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadErrors.push(e)
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const binding = require('@local-sandbox/lsb-nodejs-android-arm64')
|
|
82
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-android-arm64/package.json').version
|
|
83
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
84
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
85
|
+
}
|
|
86
|
+
return binding
|
|
87
|
+
} catch (e) {
|
|
88
|
+
loadErrors.push(e)
|
|
89
|
+
}
|
|
90
|
+
} else if (process.arch === 'arm') {
|
|
91
|
+
try {
|
|
92
|
+
return require('./lsb-nodejs.android-arm-eabi.node')
|
|
93
|
+
} catch (e) {
|
|
94
|
+
loadErrors.push(e)
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const binding = require('@local-sandbox/lsb-nodejs-android-arm-eabi')
|
|
98
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-android-arm-eabi/package.json').version
|
|
99
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
100
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
101
|
+
}
|
|
102
|
+
return binding
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadErrors.push(e)
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
108
|
+
}
|
|
109
|
+
} else if (process.platform === 'win32') {
|
|
110
|
+
if (process.arch === 'x64') {
|
|
111
|
+
try {
|
|
112
|
+
return require('./lsb-nodejs.win32-x64-msvc.node')
|
|
113
|
+
} catch (e) {
|
|
114
|
+
loadErrors.push(e)
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const binding = require('@local-sandbox/lsb-nodejs-win32-x64-msvc')
|
|
118
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-win32-x64-msvc/package.json').version
|
|
119
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
120
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
121
|
+
}
|
|
122
|
+
return binding
|
|
123
|
+
} catch (e) {
|
|
124
|
+
loadErrors.push(e)
|
|
125
|
+
}
|
|
126
|
+
} else if (process.arch === 'ia32') {
|
|
127
|
+
try {
|
|
128
|
+
return require('./lsb-nodejs.win32-ia32-msvc.node')
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadErrors.push(e)
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const binding = require('@local-sandbox/lsb-nodejs-win32-ia32-msvc')
|
|
134
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-win32-ia32-msvc/package.json').version
|
|
135
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
136
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
137
|
+
}
|
|
138
|
+
return binding
|
|
139
|
+
} catch (e) {
|
|
140
|
+
loadErrors.push(e)
|
|
141
|
+
}
|
|
142
|
+
} else if (process.arch === 'arm64') {
|
|
143
|
+
try {
|
|
144
|
+
return require('./lsb-nodejs.win32-arm64-msvc.node')
|
|
145
|
+
} catch (e) {
|
|
146
|
+
loadErrors.push(e)
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const binding = require('@local-sandbox/lsb-nodejs-win32-arm64-msvc')
|
|
150
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-win32-arm64-msvc/package.json').version
|
|
151
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
152
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
153
|
+
}
|
|
154
|
+
return binding
|
|
155
|
+
} catch (e) {
|
|
156
|
+
loadErrors.push(e)
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
160
|
+
}
|
|
161
|
+
} else if (process.platform === 'darwin') {
|
|
162
|
+
try {
|
|
163
|
+
return require('./lsb-nodejs.darwin-universal.node')
|
|
164
|
+
} catch (e) {
|
|
165
|
+
loadErrors.push(e)
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
const binding = require('@local-sandbox/lsb-nodejs-darwin-universal')
|
|
169
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-darwin-universal/package.json').version
|
|
170
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
171
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
172
|
+
}
|
|
173
|
+
return binding
|
|
174
|
+
} catch (e) {
|
|
175
|
+
loadErrors.push(e)
|
|
176
|
+
}
|
|
177
|
+
if (process.arch === 'x64') {
|
|
178
|
+
try {
|
|
179
|
+
return require('./lsb-nodejs.darwin-x64.node')
|
|
180
|
+
} catch (e) {
|
|
181
|
+
loadErrors.push(e)
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const binding = require('@local-sandbox/lsb-nodejs-darwin-x64')
|
|
185
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-darwin-x64/package.json').version
|
|
186
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
187
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
188
|
+
}
|
|
189
|
+
return binding
|
|
190
|
+
} catch (e) {
|
|
191
|
+
loadErrors.push(e)
|
|
192
|
+
}
|
|
193
|
+
} else if (process.arch === 'arm64') {
|
|
194
|
+
try {
|
|
195
|
+
return require('./lsb-nodejs.darwin-arm64.node')
|
|
196
|
+
} catch (e) {
|
|
197
|
+
loadErrors.push(e)
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const binding = require('@local-sandbox/lsb-nodejs-darwin-arm64')
|
|
201
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-darwin-arm64/package.json').version
|
|
202
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
203
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
204
|
+
}
|
|
205
|
+
return binding
|
|
206
|
+
} catch (e) {
|
|
207
|
+
loadErrors.push(e)
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
211
|
+
}
|
|
212
|
+
} else if (process.platform === 'freebsd') {
|
|
213
|
+
if (process.arch === 'x64') {
|
|
214
|
+
try {
|
|
215
|
+
return require('./lsb-nodejs.freebsd-x64.node')
|
|
216
|
+
} catch (e) {
|
|
217
|
+
loadErrors.push(e)
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const binding = require('@local-sandbox/lsb-nodejs-freebsd-x64')
|
|
221
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-freebsd-x64/package.json').version
|
|
222
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
223
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
224
|
+
}
|
|
225
|
+
return binding
|
|
226
|
+
} catch (e) {
|
|
227
|
+
loadErrors.push(e)
|
|
228
|
+
}
|
|
229
|
+
} else if (process.arch === 'arm64') {
|
|
230
|
+
try {
|
|
231
|
+
return require('./lsb-nodejs.freebsd-arm64.node')
|
|
232
|
+
} catch (e) {
|
|
233
|
+
loadErrors.push(e)
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
const binding = require('@local-sandbox/lsb-nodejs-freebsd-arm64')
|
|
237
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-freebsd-arm64/package.json').version
|
|
238
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
239
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
240
|
+
}
|
|
241
|
+
return binding
|
|
242
|
+
} catch (e) {
|
|
243
|
+
loadErrors.push(e)
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
247
|
+
}
|
|
248
|
+
} else if (process.platform === 'linux') {
|
|
249
|
+
if (process.arch === 'x64') {
|
|
250
|
+
if (isMusl()) {
|
|
251
|
+
try {
|
|
252
|
+
return require('./lsb-nodejs.linux-x64-musl.node')
|
|
253
|
+
} catch (e) {
|
|
254
|
+
loadErrors.push(e)
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-x64-musl')
|
|
258
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-x64-musl/package.json').version
|
|
259
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
260
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
261
|
+
}
|
|
262
|
+
return binding
|
|
263
|
+
} catch (e) {
|
|
264
|
+
loadErrors.push(e)
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
try {
|
|
268
|
+
return require('./lsb-nodejs.linux-x64-gnu.node')
|
|
269
|
+
} catch (e) {
|
|
270
|
+
loadErrors.push(e)
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-x64-gnu')
|
|
274
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-x64-gnu/package.json').version
|
|
275
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
276
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
277
|
+
}
|
|
278
|
+
return binding
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadErrors.push(e)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} else if (process.arch === 'arm64') {
|
|
284
|
+
if (isMusl()) {
|
|
285
|
+
try {
|
|
286
|
+
return require('./lsb-nodejs.linux-arm64-musl.node')
|
|
287
|
+
} catch (e) {
|
|
288
|
+
loadErrors.push(e)
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-arm64-musl')
|
|
292
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-arm64-musl/package.json').version
|
|
293
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
294
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
295
|
+
}
|
|
296
|
+
return binding
|
|
297
|
+
} catch (e) {
|
|
298
|
+
loadErrors.push(e)
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
try {
|
|
302
|
+
return require('./lsb-nodejs.linux-arm64-gnu.node')
|
|
303
|
+
} catch (e) {
|
|
304
|
+
loadErrors.push(e)
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-arm64-gnu')
|
|
308
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-arm64-gnu/package.json').version
|
|
309
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
310
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
311
|
+
}
|
|
312
|
+
return binding
|
|
313
|
+
} catch (e) {
|
|
314
|
+
loadErrors.push(e)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} else if (process.arch === 'arm') {
|
|
318
|
+
if (isMusl()) {
|
|
319
|
+
try {
|
|
320
|
+
return require('./lsb-nodejs.linux-arm-musleabihf.node')
|
|
321
|
+
} catch (e) {
|
|
322
|
+
loadErrors.push(e)
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-arm-musleabihf')
|
|
326
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-arm-musleabihf/package.json').version
|
|
327
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
328
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
329
|
+
}
|
|
330
|
+
return binding
|
|
331
|
+
} catch (e) {
|
|
332
|
+
loadErrors.push(e)
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
try {
|
|
336
|
+
return require('./lsb-nodejs.linux-arm-gnueabihf.node')
|
|
337
|
+
} catch (e) {
|
|
338
|
+
loadErrors.push(e)
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-arm-gnueabihf')
|
|
342
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-arm-gnueabihf/package.json').version
|
|
343
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
344
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
345
|
+
}
|
|
346
|
+
return binding
|
|
347
|
+
} catch (e) {
|
|
348
|
+
loadErrors.push(e)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} else if (process.arch === 'loong64') {
|
|
352
|
+
if (isMusl()) {
|
|
353
|
+
try {
|
|
354
|
+
return require('./lsb-nodejs.linux-loong64-musl.node')
|
|
355
|
+
} catch (e) {
|
|
356
|
+
loadErrors.push(e)
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-loong64-musl')
|
|
360
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-loong64-musl/package.json').version
|
|
361
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
362
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
363
|
+
}
|
|
364
|
+
return binding
|
|
365
|
+
} catch (e) {
|
|
366
|
+
loadErrors.push(e)
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
try {
|
|
370
|
+
return require('./lsb-nodejs.linux-loong64-gnu.node')
|
|
371
|
+
} catch (e) {
|
|
372
|
+
loadErrors.push(e)
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-loong64-gnu')
|
|
376
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-loong64-gnu/package.json').version
|
|
377
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
378
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
379
|
+
}
|
|
380
|
+
return binding
|
|
381
|
+
} catch (e) {
|
|
382
|
+
loadErrors.push(e)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else if (process.arch === 'riscv64') {
|
|
386
|
+
if (isMusl()) {
|
|
387
|
+
try {
|
|
388
|
+
return require('./lsb-nodejs.linux-riscv64-musl.node')
|
|
389
|
+
} catch (e) {
|
|
390
|
+
loadErrors.push(e)
|
|
391
|
+
}
|
|
392
|
+
try {
|
|
393
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-riscv64-musl')
|
|
394
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-riscv64-musl/package.json').version
|
|
395
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
396
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
397
|
+
}
|
|
398
|
+
return binding
|
|
399
|
+
} catch (e) {
|
|
400
|
+
loadErrors.push(e)
|
|
401
|
+
}
|
|
402
|
+
} else {
|
|
403
|
+
try {
|
|
404
|
+
return require('./lsb-nodejs.linux-riscv64-gnu.node')
|
|
405
|
+
} catch (e) {
|
|
406
|
+
loadErrors.push(e)
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-riscv64-gnu')
|
|
410
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-riscv64-gnu/package.json').version
|
|
411
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
412
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
413
|
+
}
|
|
414
|
+
return binding
|
|
415
|
+
} catch (e) {
|
|
416
|
+
loadErrors.push(e)
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
} else if (process.arch === 'ppc64') {
|
|
420
|
+
try {
|
|
421
|
+
return require('./lsb-nodejs.linux-ppc64-gnu.node')
|
|
422
|
+
} catch (e) {
|
|
423
|
+
loadErrors.push(e)
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-ppc64-gnu')
|
|
427
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-ppc64-gnu/package.json').version
|
|
428
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
429
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
430
|
+
}
|
|
431
|
+
return binding
|
|
432
|
+
} catch (e) {
|
|
433
|
+
loadErrors.push(e)
|
|
434
|
+
}
|
|
435
|
+
} else if (process.arch === 's390x') {
|
|
436
|
+
try {
|
|
437
|
+
return require('./lsb-nodejs.linux-s390x-gnu.node')
|
|
438
|
+
} catch (e) {
|
|
439
|
+
loadErrors.push(e)
|
|
440
|
+
}
|
|
441
|
+
try {
|
|
442
|
+
const binding = require('@local-sandbox/lsb-nodejs-linux-s390x-gnu')
|
|
443
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-linux-s390x-gnu/package.json').version
|
|
444
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
445
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
446
|
+
}
|
|
447
|
+
return binding
|
|
448
|
+
} catch (e) {
|
|
449
|
+
loadErrors.push(e)
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
453
|
+
}
|
|
454
|
+
} else if (process.platform === 'openharmony') {
|
|
455
|
+
if (process.arch === 'arm64') {
|
|
456
|
+
try {
|
|
457
|
+
return require('./lsb-nodejs.openharmony-arm64.node')
|
|
458
|
+
} catch (e) {
|
|
459
|
+
loadErrors.push(e)
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
const binding = require('@local-sandbox/lsb-nodejs-openharmony-arm64')
|
|
463
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-openharmony-arm64/package.json').version
|
|
464
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
465
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
466
|
+
}
|
|
467
|
+
return binding
|
|
468
|
+
} catch (e) {
|
|
469
|
+
loadErrors.push(e)
|
|
470
|
+
}
|
|
471
|
+
} else if (process.arch === 'x64') {
|
|
472
|
+
try {
|
|
473
|
+
return require('./lsb-nodejs.openharmony-x64.node')
|
|
474
|
+
} catch (e) {
|
|
475
|
+
loadErrors.push(e)
|
|
476
|
+
}
|
|
477
|
+
try {
|
|
478
|
+
const binding = require('@local-sandbox/lsb-nodejs-openharmony-x64')
|
|
479
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-openharmony-x64/package.json').version
|
|
480
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
481
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
482
|
+
}
|
|
483
|
+
return binding
|
|
484
|
+
} catch (e) {
|
|
485
|
+
loadErrors.push(e)
|
|
486
|
+
}
|
|
487
|
+
} else if (process.arch === 'arm') {
|
|
488
|
+
try {
|
|
489
|
+
return require('./lsb-nodejs.openharmony-arm.node')
|
|
490
|
+
} catch (e) {
|
|
491
|
+
loadErrors.push(e)
|
|
492
|
+
}
|
|
493
|
+
try {
|
|
494
|
+
const binding = require('@local-sandbox/lsb-nodejs-openharmony-arm')
|
|
495
|
+
const bindingPackageVersion = require('@local-sandbox/lsb-nodejs-openharmony-arm/package.json').version
|
|
496
|
+
if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
497
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
498
|
+
}
|
|
499
|
+
return binding
|
|
500
|
+
} catch (e) {
|
|
501
|
+
loadErrors.push(e)
|
|
502
|
+
}
|
|
503
|
+
} else {
|
|
504
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
nativeBinding = requireNative()
|
|
512
|
+
|
|
513
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
514
|
+
let wasiBinding = null
|
|
515
|
+
let wasiBindingError = null
|
|
516
|
+
try {
|
|
517
|
+
wasiBinding = require('./lsb-nodejs.wasi.cjs')
|
|
518
|
+
nativeBinding = wasiBinding
|
|
519
|
+
} catch (err) {
|
|
520
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
521
|
+
wasiBindingError = err
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (!nativeBinding) {
|
|
525
|
+
try {
|
|
526
|
+
wasiBinding = require('@local-sandbox/lsb-nodejs-wasm32-wasi')
|
|
527
|
+
nativeBinding = wasiBinding
|
|
528
|
+
} catch (err) {
|
|
529
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
530
|
+
wasiBindingError.cause = err
|
|
531
|
+
loadErrors.push(err)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
536
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
537
|
+
error.cause = wasiBindingError
|
|
538
|
+
throw error
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (!nativeBinding) {
|
|
543
|
+
if (loadErrors.length > 0) {
|
|
544
|
+
throw new Error(
|
|
545
|
+
`Cannot find native binding. ` +
|
|
546
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
547
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
548
|
+
{
|
|
549
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
550
|
+
cur.cause = err
|
|
551
|
+
return cur
|
|
552
|
+
}),
|
|
553
|
+
},
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
throw new Error(`Failed to load native binding`)
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
module.exports = nativeBinding
|
|
560
|
+
module.exports.Sandbox = nativeBinding.Sandbox
|
|
561
|
+
module.exports.SpawnedProcess = nativeBinding.SpawnedProcess
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@local-sandbox/lsb-nodejs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Native Node.js bindings for lsb microVM sandboxes",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"os": [
|
|
9
|
+
"darwin"
|
|
10
|
+
],
|
|
11
|
+
"cpu": [
|
|
12
|
+
"arm64",
|
|
13
|
+
"x64"
|
|
14
|
+
],
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/LocalSandBox/local-sandbox.git",
|
|
18
|
+
"directory": "bindings/nodejs"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"lsb",
|
|
22
|
+
"napi-rs",
|
|
23
|
+
"node-addon",
|
|
24
|
+
"sandbox",
|
|
25
|
+
"microvm"
|
|
26
|
+
],
|
|
27
|
+
"files": [
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"index.d.ts",
|
|
31
|
+
"index.js"
|
|
32
|
+
],
|
|
33
|
+
"napi": {
|
|
34
|
+
"binaryName": "lsb-nodejs",
|
|
35
|
+
"packageName": "@local-sandbox/lsb-nodejs",
|
|
36
|
+
"targets": [
|
|
37
|
+
"aarch64-apple-darwin",
|
|
38
|
+
"x86_64-apple-darwin"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"registry": "https://registry.npmjs.org/",
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"artifacts": "napi artifacts",
|
|
50
|
+
"build": "napi build --platform --release",
|
|
51
|
+
"build:debug": "napi build --platform",
|
|
52
|
+
"format": "run-p format:prettier format:rs format:toml",
|
|
53
|
+
"format:prettier": "prettier . -w",
|
|
54
|
+
"format:rs": "cargo fmt",
|
|
55
|
+
"format:toml": "taplo format",
|
|
56
|
+
"lint": "oxlint .",
|
|
57
|
+
"prepublishOnly": "napi prepublish -t npm --no-gh-release",
|
|
58
|
+
"test": "napi build --platform && ava",
|
|
59
|
+
"test:signed-node": "./scripts/test-with-signed-node.sh",
|
|
60
|
+
"version": "napi version"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@napi-rs/cli": "^3.2.0",
|
|
64
|
+
"@oxc-node/core": "^0.0.35",
|
|
65
|
+
"@taplo/cli": "^0.7.0",
|
|
66
|
+
"@types/node": "^22.15.30",
|
|
67
|
+
"ava": "^7.0.0",
|
|
68
|
+
"npm-run-all2": "^8.0.4",
|
|
69
|
+
"oxlint": "^1.14.0",
|
|
70
|
+
"prettier": "^3.6.2",
|
|
71
|
+
"typescript": "^5.9.2"
|
|
72
|
+
},
|
|
73
|
+
"ava": {
|
|
74
|
+
"files": [
|
|
75
|
+
"test/**/*.spec.ts"
|
|
76
|
+
],
|
|
77
|
+
"extensions": {
|
|
78
|
+
"ts": "module"
|
|
79
|
+
},
|
|
80
|
+
"timeout": "1m",
|
|
81
|
+
"workerThreads": false,
|
|
82
|
+
"environmentVariables": {
|
|
83
|
+
"OXC_TSCONFIG_PATH": "./test/tsconfig.json"
|
|
84
|
+
},
|
|
85
|
+
"nodeArguments": [
|
|
86
|
+
"--import",
|
|
87
|
+
"@oxc-node/core/register"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"prettier": {
|
|
91
|
+
"printWidth": 100,
|
|
92
|
+
"semi": false,
|
|
93
|
+
"trailingComma": "all",
|
|
94
|
+
"singleQuote": true,
|
|
95
|
+
"arrowParens": "always"
|
|
96
|
+
},
|
|
97
|
+
"packageManager": "yarn@4.12.0",
|
|
98
|
+
"optionalDependencies": {
|
|
99
|
+
"@local-sandbox/lsb-nodejs-darwin-arm64": "0.1.0",
|
|
100
|
+
"@local-sandbox/lsb-nodejs-darwin-x64": "0.1.0"
|
|
101
|
+
}
|
|
102
|
+
}
|