sandbox 2.0.0-alpha5 → 2.0.1
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 +18 -12
- package/README.md +18 -93
- package/bin/sandbox.mjs +3 -0
- package/dist/ansi-styles-B57ln_zO.mjs +168 -0
- package/dist/ansi-styles-B57ln_zO.mjs.map +1 -0
- package/dist/app-rsOUZPpL.mjs +14168 -0
- package/dist/app-rsOUZPpL.mjs.map +1 -0
- package/dist/chunk-btbCw1m3.mjs +52 -0
- package/dist/cli-cursor-Dab4mDU2.mjs +348 -0
- package/dist/cli-cursor-Dab4mDU2.mjs.map +1 -0
- package/dist/cli-truncate-DMIDACmY.mjs +124 -0
- package/dist/cli-truncate-DMIDACmY.mjs.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +17 -0
- package/dist/index.mjs.map +1 -0
- package/dist/log-update-txb7Or7B.mjs +223 -0
- package/dist/log-update-txb7Or7B.mjs.map +1 -0
- package/dist/pty-server-linux-x86_64 +0 -0
- package/dist/sandbox.d.mts +1 -0
- package/dist/sandbox.mjs +647 -0
- package/dist/sandbox.mjs.map +1 -0
- package/dist/string-width-D78SVDLD.mjs +85 -0
- package/dist/string-width-D78SVDLD.mjs.map +1 -0
- package/dist/token-Bwtve9Y6.mjs +51 -0
- package/dist/token-Bwtve9Y6.mjs.map +1 -0
- package/dist/token-error-C0CafU2G.mjs +43 -0
- package/dist/token-error-C0CafU2G.mjs.map +1 -0
- package/dist/token-util-BpWskZEO.mjs +357 -0
- package/dist/token-util-BpWskZEO.mjs.map +1 -0
- package/dist/token-util-CRAtcwBI.mjs +6 -0
- package/dist/wrap-ansi-CEi7ZT5i.mjs +5 -0
- package/dist/wrap-ansi-DoQ74EEn.mjs +130 -0
- package/dist/wrap-ansi-DoQ74EEn.mjs.map +1 -0
- package/package.json +52 -31
- package/index.js +0 -29
- package/install.js +0 -5
- package/platform-target.js +0 -217
package/package.json
CHANGED
|
@@ -1,38 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sandbox",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Command line interface for Vercel Sandbox",
|
|
4
|
+
"version": "2.0.1",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vercel",
|
|
7
|
+
"sandbox",
|
|
8
|
+
"cli"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/index.mjs",
|
|
11
|
+
"bin": {
|
|
12
|
+
"sandbox": "./bin/sandbox.mjs",
|
|
13
|
+
"sbx": "./bin/sandbox.mjs"
|
|
14
|
+
},
|
|
6
15
|
"files": [
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"platform-target.js"
|
|
16
|
+
"bin",
|
|
17
|
+
"README.md",
|
|
18
|
+
"dist"
|
|
11
19
|
],
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"test": "mocha"
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"debug": "^4.4.1",
|
|
23
|
+
"zod": "^4.1.1",
|
|
24
|
+
"@vercel/sandbox": "1.3.1"
|
|
18
25
|
},
|
|
19
|
-
"author": "Gianni Chiappetta <gianni@runlevel6.org>",
|
|
20
|
-
"license": "ISC",
|
|
21
26
|
"devDependencies": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
27
|
+
"@types/debug": "^4.1.12",
|
|
28
|
+
"@types/ms": "^2.1.0",
|
|
29
|
+
"@types/node": "^22.15.12",
|
|
30
|
+
"@vercel/oidc": "^3.1.0",
|
|
31
|
+
"chalk": "^5.6.0",
|
|
32
|
+
"cmd-ts": "0.14.3",
|
|
33
|
+
"date-fns": "^4.1.0",
|
|
34
|
+
"dotenv-flow": "^4.1.0",
|
|
35
|
+
"listr2": "^9.0.2",
|
|
36
|
+
"ms": "^2.1.3",
|
|
37
|
+
"open": "^10.2.0",
|
|
38
|
+
"ora": "^8.2.0",
|
|
39
|
+
"tsdown": "0.16.6",
|
|
40
|
+
"vitest": "3.2.1",
|
|
41
|
+
"xdg-app-paths": "5.1.0",
|
|
42
|
+
"@vercel/pty-tunnel": "2.0.3",
|
|
43
|
+
"@vercel/pty-tunnel-server": "0.0.2",
|
|
44
|
+
"@vercel/sandbox": "1.3.1"
|
|
28
45
|
},
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"sandbox",
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
"scripts": {
|
|
47
|
+
"clean": "rm -rf node_modules dist",
|
|
48
|
+
"sandbox": "ts-node ./src/sandbox.ts",
|
|
49
|
+
"build": "tsdown",
|
|
50
|
+
"vercel-build": "ts-node ./scripts/create-preview-deployment-tgz.ts",
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"example-whoami": "ts-node ./src/example-whoami.ts",
|
|
53
|
+
"example-next": "ts-node ./src/example-next.ts",
|
|
54
|
+
"example-flask": "ts-node ./src/example-flask.ts",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"generate-docs": "ts-node ./scripts/print-usage.ts > docs/index.md",
|
|
57
|
+
"version:bump": "pnpm generate-docs"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { shovelNew, shovelEval } = require("./index.node");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Sandbox for running JavaScript.
|
|
7
|
-
*/
|
|
8
|
-
class Sandbox {
|
|
9
|
-
constructor() {
|
|
10
|
-
// Wrapper for boxed `Shovel`
|
|
11
|
-
this._shovel = shovelNew();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Evaluate arbitrary source code.
|
|
16
|
-
*/
|
|
17
|
-
eval(source, callback) {
|
|
18
|
-
return shovelEval.call(this._shovel, source, function (err, res) {
|
|
19
|
-
try {
|
|
20
|
-
callback.call(undefined, err, res);
|
|
21
|
-
} catch (e) {
|
|
22
|
-
console.error("Uncaught %O", e);
|
|
23
|
-
throw e;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = Sandbox;
|
package/install.js
DELETED
package/platform-target.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
const http = require("https");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const os = require("os");
|
|
4
|
-
const { gunzip } = require("zlib");
|
|
5
|
-
const { bugs, version, name, repository } = require("./package.json");
|
|
6
|
-
const { debuglog, promisify } = require("util");
|
|
7
|
-
|
|
8
|
-
const PLATFORMS = [
|
|
9
|
-
{
|
|
10
|
-
TYPE: "Windows_NT",
|
|
11
|
-
ARCHITECTURE: "x64",
|
|
12
|
-
RUST_TARGET: "x86_64-pc-windows-msvc",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
TYPE: "Linux",
|
|
16
|
-
ARCHITECTURE: "x64",
|
|
17
|
-
RUST_TARGET: "x86_64-unknown-linux-gnu",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
TYPE: "Darwin",
|
|
21
|
-
ARCHITECTURE: "x64",
|
|
22
|
-
RUST_TARGET: "x86_64-apple-darwin",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
TYPE: "Darwin",
|
|
26
|
-
ARCHITECTURE: "arm64",
|
|
27
|
-
RUST_TARGET: "aarch64-apple-darwin",
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
const BINARY_NAME = "index.node";
|
|
31
|
-
|
|
32
|
-
const log = debuglog("sandbox");
|
|
33
|
-
|
|
34
|
-
function error(message) {
|
|
35
|
-
console.error(`💥 ${message}`);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getPlatform() {
|
|
40
|
-
const type = os.type();
|
|
41
|
-
const arch = os.arch();
|
|
42
|
-
|
|
43
|
-
for (let platform of PLATFORMS) {
|
|
44
|
-
if (type === platform.TYPE && arch === platform.ARCHITECTURE) {
|
|
45
|
-
return platform;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
error(
|
|
50
|
-
`Platform "${type}" and architecture "${arch}" are not supported by ${name}. Please file an issue: ${bugs.url}`,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @callback BufferCallback
|
|
56
|
-
* @param {any} err - Error, if `undefined` the operation was successful.
|
|
57
|
-
* @param {Buffer} buffer - Result of operation.
|
|
58
|
-
* @returns {void}
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Download a given URL to a Buffer.
|
|
63
|
-
*
|
|
64
|
-
* @param {string} url - URL to download.
|
|
65
|
-
* @param {BufferCallback} callback - Buffer containing downloaded file.
|
|
66
|
-
* @returns {void}
|
|
67
|
-
*/
|
|
68
|
-
function download(url, callback) {
|
|
69
|
-
log("download: %s", url);
|
|
70
|
-
|
|
71
|
-
const chunks = [];
|
|
72
|
-
|
|
73
|
-
http
|
|
74
|
-
.get(url, function (response) {
|
|
75
|
-
log("download.response: %d", response.statusCode);
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
response.statusCode >= 300 &&
|
|
79
|
-
response.statusCode < 400 &&
|
|
80
|
-
response.headers &&
|
|
81
|
-
response.headers.location
|
|
82
|
-
) {
|
|
83
|
-
download(response.headers.location, callback);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (response.statusCode !== 200) {
|
|
88
|
-
process.nextTick(callback, `Status ${response.statusCode} for ${url}`);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
response.on("data", function (chunk) {
|
|
93
|
-
chunks.push(chunk);
|
|
94
|
-
});
|
|
95
|
-
response.on("end", function () {
|
|
96
|
-
process.nextTick(callback, undefined, Buffer.concat(chunks));
|
|
97
|
-
});
|
|
98
|
-
response.on("error", callback);
|
|
99
|
-
})
|
|
100
|
-
.on("error", function (err) {
|
|
101
|
-
log("download.error: %O", err);
|
|
102
|
-
process.nextTick(callback, err);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Decompress a given Buffer.
|
|
108
|
-
*
|
|
109
|
-
* @param {Buffer} buffer - Compressed data.
|
|
110
|
-
* @param {BufferCallback} callback - Buffer containing decompressed data.
|
|
111
|
-
* @returns {void}
|
|
112
|
-
*/
|
|
113
|
-
function decompress(buffer, callback) {
|
|
114
|
-
log("decompress");
|
|
115
|
-
|
|
116
|
-
gunzip(buffer, function (err, decompressedBuffer) {
|
|
117
|
-
if (err) {
|
|
118
|
-
log("decompress.error: %O", err);
|
|
119
|
-
process.nextTick(callback, err);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
process.nextTick(callback, undefined, decompressedBuffer);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Save a buffer to the filesystem.
|
|
128
|
-
*
|
|
129
|
-
* @param {Buffer} buffer - File contents.
|
|
130
|
-
* @param {string} filename - File path and name.
|
|
131
|
-
* @param {Function} callback - Called with the saved filename if sucessful.
|
|
132
|
-
* @returns {void}
|
|
133
|
-
*/
|
|
134
|
-
function save(buffer, filename, callback) {
|
|
135
|
-
log("save: %s", filename);
|
|
136
|
-
|
|
137
|
-
const stream = fs.createWriteStream(filename);
|
|
138
|
-
const done = function () {
|
|
139
|
-
stream.end();
|
|
140
|
-
process.nextTick(callback, undefined, filename);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
if (stream.write(buffer)) {
|
|
144
|
-
done();
|
|
145
|
-
return;
|
|
146
|
-
} else {
|
|
147
|
-
stream.once("drain", done);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Verify installation.
|
|
153
|
-
*
|
|
154
|
-
* @param {string} filename - File to verify.
|
|
155
|
-
* @param {Function} callback - Called with `true` to indicate the installation
|
|
156
|
-
* has been verified.
|
|
157
|
-
* @returns {void}
|
|
158
|
-
*/
|
|
159
|
-
function verify(filename, callback) {
|
|
160
|
-
log("verify: %s", filename);
|
|
161
|
-
|
|
162
|
-
fs.existsSync(filename)
|
|
163
|
-
? process.nextTick(callback, undefined, true)
|
|
164
|
-
: process.nextTick(callback, true);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Determine the current platform and attempt to download and install a
|
|
169
|
-
* pre-built binary.
|
|
170
|
-
*
|
|
171
|
-
* NOTE: The download will be skipped if an environment variable
|
|
172
|
-
* `SANDBOX_SKIP_DOWNLOAD` exists.
|
|
173
|
-
*
|
|
174
|
-
* @returns {void}
|
|
175
|
-
*/
|
|
176
|
-
async function install() {
|
|
177
|
-
if (process.env.SANDBOX_SKIP_DOWNLOAD) {
|
|
178
|
-
log("skipping install");
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const platform = getPlatform();
|
|
183
|
-
|
|
184
|
-
log("install: %O", platform);
|
|
185
|
-
|
|
186
|
-
if (fs.existsSync(BINARY_NAME)) {
|
|
187
|
-
log("install.exists: %s", BINARY_NAME);
|
|
188
|
-
console.log(`🎊 ${name} already downloaded!`);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const repositoryUrl = repository.url
|
|
193
|
-
.replace("git+https", "https")
|
|
194
|
-
.replace(`${name}.git`, name);
|
|
195
|
-
const url = `${repositoryUrl}/releases/download/v${version}/${name}-v${version}-${platform.RUST_TARGET}.gz`;
|
|
196
|
-
|
|
197
|
-
log("install.url: %s", url);
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
const buffer = await promisify(download)(url);
|
|
201
|
-
const binary = await promisify(decompress)(buffer);
|
|
202
|
-
const filename = await promisify(save)(binary, BINARY_NAME);
|
|
203
|
-
const verified = await promisify(verify)(filename);
|
|
204
|
-
|
|
205
|
-
if (!verified) {
|
|
206
|
-
throw new Error(`Unable to verify ${filename}`);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
console.log(`🥂 Successfully downloaded ${name} ${version}`);
|
|
210
|
-
} catch (err) {
|
|
211
|
-
error(err);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
module.exports = {
|
|
216
|
-
install,
|
|
217
|
-
};
|