microsandbox 0.1.0 → 0.3.6
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/README.md +368 -14
- package/index.cjs +609 -0
- package/index.d.cts +751 -0
- package/index.mjs +21 -0
- package/package.json +31 -30
- package/postinstall.js +144 -0
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -19
package/index.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Auto-generated ESM wrapper for NAPI-RS CJS module.
|
|
2
|
+
import binding from "./index.cjs";
|
|
3
|
+
|
|
4
|
+
export const {
|
|
5
|
+
ExecHandle,
|
|
6
|
+
ExecOutput,
|
|
7
|
+
ExecSink,
|
|
8
|
+
Mount,
|
|
9
|
+
NetworkPolicy,
|
|
10
|
+
Sandbox,
|
|
11
|
+
SandboxFs,
|
|
12
|
+
SandboxHandle,
|
|
13
|
+
Secret,
|
|
14
|
+
Volume,
|
|
15
|
+
VolumeHandle,
|
|
16
|
+
allSandboxMetrics,
|
|
17
|
+
install,
|
|
18
|
+
isInstalled,
|
|
19
|
+
} = binding;
|
|
20
|
+
|
|
21
|
+
export default binding;
|
package/package.json
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "microsandbox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"types": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"main": "index.cjs",
|
|
5
|
+
"module": "index.mjs",
|
|
6
|
+
"types": "index.d.cts",
|
|
7
|
+
"napi": {
|
|
8
|
+
"binaryName": "microsandbox",
|
|
9
|
+
"packageName": "@superradcompany/microsandbox",
|
|
10
|
+
"targets": [
|
|
11
|
+
"aarch64-apple-darwin",
|
|
12
|
+
"x86_64-unknown-linux-gnu",
|
|
13
|
+
"aarch64-unknown-linux-gnu"
|
|
14
|
+
]
|
|
15
15
|
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"microsandbox",
|
|
18
|
-
"sdk"
|
|
19
|
-
],
|
|
20
|
-
"author": "Microsandbox Team <team@microsandbox.dev>",
|
|
21
16
|
"license": "Apache-2.0",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"url": "git+https://github.com/microsandbox/microsandbox.git"
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">= 18"
|
|
25
19
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "napi build --release --platform --js index.cjs --dts index.d.cts",
|
|
22
|
+
"build:debug": "napi build --platform --js index.cjs --dts index.d.cts",
|
|
23
|
+
"postinstall": "node postinstall.js"
|
|
28
24
|
},
|
|
29
|
-
"homepage": "https://github.com/microsandbox/microsandbox",
|
|
30
25
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
}
|
|
26
|
+
"@napi-rs/cli": "^3"
|
|
27
|
+
},
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"@superradcompany/microsandbox-darwin-arm64": "0.3.6",
|
|
30
|
+
"@superradcompany/microsandbox-linux-x64-gnu": "0.3.6",
|
|
31
|
+
"@superradcompany/microsandbox-linux-arm64-gnu": "0.3.6"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"index.cjs",
|
|
35
|
+
"index.mjs",
|
|
36
|
+
"index.d.cts",
|
|
37
|
+
"postinstall.js"
|
|
38
|
+
]
|
|
38
39
|
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Downloads msb + libkrunfw binaries to ~/.microsandbox/{bin,lib}/ during npm install.
|
|
4
|
+
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const https = require("https");
|
|
10
|
+
const http = require("http");
|
|
11
|
+
|
|
12
|
+
const PREBUILT_VERSION = "0.3.5";
|
|
13
|
+
const LIBKRUNFW_ABI = "5";
|
|
14
|
+
const LIBKRUNFW_VERSION = "5.2.1";
|
|
15
|
+
const GITHUB_ORG = "superradcompany";
|
|
16
|
+
const REPO = "microsandbox";
|
|
17
|
+
const BASE_DIR = path.join(os.homedir(), ".microsandbox");
|
|
18
|
+
const BIN_DIR = path.join(BASE_DIR, "bin");
|
|
19
|
+
const LIB_DIR = path.join(BASE_DIR, "lib");
|
|
20
|
+
|
|
21
|
+
function getArch() {
|
|
22
|
+
const arch = process.arch;
|
|
23
|
+
if (arch === "arm64" || arch === "aarch64") return "aarch64";
|
|
24
|
+
if (arch === "x64" || arch === "x86_64") return "x86_64";
|
|
25
|
+
throw new Error(`Unsupported architecture: ${arch}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getOS() {
|
|
29
|
+
const platform = process.platform;
|
|
30
|
+
if (platform === "darwin") return "darwin";
|
|
31
|
+
if (platform === "linux") return "linux";
|
|
32
|
+
throw new Error(`Unsupported platform: ${platform}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function libkrunfwFilename(targetOS) {
|
|
36
|
+
if (targetOS === "darwin") return `libkrunfw.${LIBKRUNFW_ABI}.dylib`;
|
|
37
|
+
return `libkrunfw.so.${LIBKRUNFW_VERSION}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function libkrunfwSymlinks(filename, targetOS) {
|
|
41
|
+
if (targetOS === "darwin") {
|
|
42
|
+
return [["libkrunfw.dylib", filename]];
|
|
43
|
+
}
|
|
44
|
+
const soname = `libkrunfw.so.${LIBKRUNFW_ABI}`;
|
|
45
|
+
return [
|
|
46
|
+
[soname, filename],
|
|
47
|
+
["libkrunfw.so", soname],
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function bundleUrl(version, arch, targetOS) {
|
|
52
|
+
return `https://github.com/${GITHUB_ORG}/${REPO}/releases/download/v${version}/${REPO}-${targetOS}-${arch}.tar.gz`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Follow redirects and return the response body as a Buffer. */
|
|
56
|
+
function download(url) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const get = url.startsWith("https:") ? https.get : http.get;
|
|
59
|
+
get(url, (res) => {
|
|
60
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
61
|
+
return download(res.headers.location).then(resolve, reject);
|
|
62
|
+
}
|
|
63
|
+
if (res.statusCode !== 200) {
|
|
64
|
+
return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
65
|
+
}
|
|
66
|
+
const chunks = [];
|
|
67
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
68
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
69
|
+
res.on("error", reject);
|
|
70
|
+
}).on("error", reject);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Extract a .tar.gz buffer, routing files to bin/ or lib/. */
|
|
75
|
+
function extractBundle(data) {
|
|
76
|
+
// Use tar CLI since Node doesn't have built-in tar support without dependencies.
|
|
77
|
+
const tmpFile = path.join(os.tmpdir(), `microsandbox-bundle-${Date.now()}.tar.gz`);
|
|
78
|
+
const tmpExtract = path.join(os.tmpdir(), `microsandbox-extract-${Date.now()}`);
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
fs.writeFileSync(tmpFile, data);
|
|
82
|
+
fs.mkdirSync(tmpExtract, { recursive: true });
|
|
83
|
+
execSync(`tar xzf "${tmpFile}" -C "${tmpExtract}"`, { stdio: "pipe" });
|
|
84
|
+
|
|
85
|
+
for (const name of fs.readdirSync(tmpExtract)) {
|
|
86
|
+
const src = path.join(tmpExtract, name);
|
|
87
|
+
const dest = name.startsWith("libkrunfw")
|
|
88
|
+
? path.join(LIB_DIR, name)
|
|
89
|
+
: path.join(BIN_DIR, name);
|
|
90
|
+
fs.copyFileSync(src, dest);
|
|
91
|
+
fs.chmodSync(dest, 0o755);
|
|
92
|
+
}
|
|
93
|
+
} finally {
|
|
94
|
+
try { fs.unlinkSync(tmpFile); } catch {}
|
|
95
|
+
try { fs.rmSync(tmpExtract, { recursive: true }); } catch {}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function main() {
|
|
100
|
+
const targetOS = getOS();
|
|
101
|
+
const arch = getArch();
|
|
102
|
+
const libkrunfw = libkrunfwFilename(targetOS);
|
|
103
|
+
|
|
104
|
+
// Skip if already installed.
|
|
105
|
+
if (
|
|
106
|
+
fs.existsSync(path.join(BIN_DIR, "msb")) &&
|
|
107
|
+
fs.existsSync(path.join(LIB_DIR, libkrunfw))
|
|
108
|
+
) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
113
|
+
fs.mkdirSync(LIB_DIR, { recursive: true });
|
|
114
|
+
|
|
115
|
+
const url = bundleUrl(PREBUILT_VERSION, arch, targetOS);
|
|
116
|
+
console.log(`microsandbox: downloading runtime dependencies (v${PREBUILT_VERSION})...`);
|
|
117
|
+
const data = await download(url);
|
|
118
|
+
|
|
119
|
+
extractBundle(data);
|
|
120
|
+
|
|
121
|
+
// Create libkrunfw symlinks.
|
|
122
|
+
for (const [linkName, target] of libkrunfwSymlinks(libkrunfw, targetOS)) {
|
|
123
|
+
const linkPath = path.join(LIB_DIR, linkName);
|
|
124
|
+
try { fs.unlinkSync(linkPath); } catch {}
|
|
125
|
+
fs.symlinkSync(target, linkPath);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Verify.
|
|
129
|
+
if (!fs.existsSync(path.join(BIN_DIR, "msb"))) {
|
|
130
|
+
throw new Error("msb binary not found after extraction");
|
|
131
|
+
}
|
|
132
|
+
if (!fs.existsSync(path.join(LIB_DIR, libkrunfw))) {
|
|
133
|
+
throw new Error(`${libkrunfw} not found after extraction`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
console.log("microsandbox: runtime dependencies installed.");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
main().catch((err) => {
|
|
140
|
+
console.error(`microsandbox: failed to install runtime dependencies: ${err.message}`);
|
|
141
|
+
console.error("You can install them manually: curl -fsSL https://get.microsandbox.dev | sh");
|
|
142
|
+
// Don't fail the npm install — the user can install manually.
|
|
143
|
+
process.exit(0);
|
|
144
|
+
});
|
package/dist/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Microsandbox JavaScript SDK
|
|
3
|
-
*
|
|
4
|
-
* A minimal SDK for the Microsandbox project.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Returns a greeting message for the given name.
|
|
8
|
-
*
|
|
9
|
-
* @param name - The name to greet
|
|
10
|
-
* @returns A greeting message
|
|
11
|
-
*/
|
|
12
|
-
export declare function greet(name: string): string;
|
package/dist/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Microsandbox JavaScript SDK
|
|
4
|
-
*
|
|
5
|
-
* A minimal SDK for the Microsandbox project.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.greet = greet;
|
|
9
|
-
/**
|
|
10
|
-
* Returns a greeting message for the given name.
|
|
11
|
-
*
|
|
12
|
-
* @param name - The name to greet
|
|
13
|
-
* @returns A greeting message
|
|
14
|
-
*/
|
|
15
|
-
function greet(name) {
|
|
16
|
-
const message = `Hello, ${name}! Welcome to Microsandbox!`;
|
|
17
|
-
console.log(message);
|
|
18
|
-
return message;
|
|
19
|
-
}
|