coderaft 0.0.12 → 0.0.14
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 +14 -10
- package/code.mjs +1 -1
- package/code.tar.zst +0 -0
- package/dist/_chunks/server.mjs +14 -7
- package/dist/cli.mjs +19 -2
- package/dist/index.d.mts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ const instance = await startCodeServer({
|
|
|
57
57
|
port: 6063,
|
|
58
58
|
host: "127.0.0.1",
|
|
59
59
|
defaultFolder: "/path/to/workspace",
|
|
60
|
-
// connectionToken: "my-secret", // auto-generated
|
|
60
|
+
// connectionToken: "my-secret", // disabled for localhost, auto-generated otherwise
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
console.log(`Ready at ${instance.url}`);
|
|
@@ -93,11 +93,12 @@ server.listen(3000);
|
|
|
93
93
|
|
|
94
94
|
Creates a code-server handler without binding to a port.
|
|
95
95
|
|
|
96
|
-
| Option | Type | Description
|
|
97
|
-
| ----------------- | --------------------- |
|
|
98
|
-
| `defaultFolder` | `string` | Workspace folder opened when no input is given in the URL.
|
|
99
|
-
| `connectionToken` | `string` | Shared auth secret.
|
|
100
|
-
| `
|
|
96
|
+
| Option | Type | Description |
|
|
97
|
+
| ----------------- | --------------------- | ---------------------------------------------------------------------------- |
|
|
98
|
+
| `defaultFolder` | `string` | Workspace folder opened when no input is given in the URL. |
|
|
99
|
+
| `connectionToken` | `string` | Shared auth secret. Disabled for localhost, auto-generated for remote hosts. |
|
|
100
|
+
| `host` | `string` | Host/interface to bind. Used to infer whether to require a token. |
|
|
101
|
+
| `vscode` | `VSCodeServerOptions` | Extra options forwarded to VS Code's internal `createServer()`. |
|
|
101
102
|
|
|
102
103
|
Returns a `CodeServerHandler`:
|
|
103
104
|
|
|
@@ -116,10 +117,9 @@ Convenience wrapper around `createCodeServer` that creates an HTTP server and st
|
|
|
116
117
|
|
|
117
118
|
Accepts all `createCodeServer` options plus:
|
|
118
119
|
|
|
119
|
-
| Option | Type | Description
|
|
120
|
-
| ------ | -------- |
|
|
121
|
-
| `port` | `number` | TCP port to listen on. Defaults to `$PORT` or `6063`.
|
|
122
|
-
| `host` | `string` | Host/interface to bind. Defaults to Node's default (all interfaces). |
|
|
120
|
+
| Option | Type | Description |
|
|
121
|
+
| ------ | -------- | ----------------------------------------------------- |
|
|
122
|
+
| `port` | `number` | TCP port to listen on. Defaults to `$PORT` or `6063`. |
|
|
123
123
|
|
|
124
124
|
Returns a `CodeServerHandle`:
|
|
125
125
|
|
|
@@ -147,8 +147,12 @@ interface CodeServerHandle {
|
|
|
147
147
|
|
|
148
148
|
### Auth
|
|
149
149
|
|
|
150
|
+
> [!NOTE]
|
|
151
|
+
> When binding to `localhost` / `127.0.0.1` (or no `--host`), the connection token is **disabled by default** for convenience. When binding to any other host, a token is auto-generated unless `--without-connection-token` is explicitly passed. You can always override by providing `--token` or `--connection-token`.
|
|
152
|
+
|
|
150
153
|
| Option | Description |
|
|
151
154
|
| -------------------------------- | ----------------------------------------------------- |
|
|
155
|
+
| `-t, --token <token>` | Connection token for auth (shorthand) |
|
|
152
156
|
| `--connection-token <token>` | Connection token for auth (auto-generated if omitted) |
|
|
153
157
|
| `--connection-token-file <path>` | Path to file containing the connection token |
|
|
154
158
|
| `--without-connection-token` | Disable connection token auth |
|
package/code.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
// Auto-updated by scripts/pack.ts
|
|
7
|
-
const codeArchiveHash = "
|
|
7
|
+
const codeArchiveHash = "d28f51becc566aa4";
|
|
8
8
|
|
|
9
9
|
const archivePath = fileURLToPath(new URL("./code.tar.zst", import.meta.url));
|
|
10
10
|
|
package/code.tar.zst
CHANGED
|
Binary file
|
package/dist/_chunks/server.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
3
3
|
import { createReadStream, readFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
|
-
import os, { homedir } from "node:os";
|
|
6
5
|
import { extname, join, normalize, sep } from "node:path";
|
|
7
6
|
import { stat } from "node:fs/promises";
|
|
8
7
|
import { loadCode } from "#code";
|
|
@@ -48,6 +47,12 @@ async function serveStatic(res, root, relPath) {
|
|
|
48
47
|
return false;
|
|
49
48
|
}
|
|
50
49
|
}
|
|
50
|
+
if (process.platform === "android") {
|
|
51
|
+
Object.defineProperty(process, "platform", { value: "linux" });
|
|
52
|
+
const preload = `--import "data:text/javascript,Object.defineProperty(process,'platform',{value:'linux'})"`;
|
|
53
|
+
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} ${preload}` : preload;
|
|
54
|
+
}
|
|
55
|
+
const _os = __require("node:os");
|
|
51
56
|
const MANIFEST_BODY = JSON.stringify({
|
|
52
57
|
name: "coderaft",
|
|
53
58
|
short_name: "coderaft",
|
|
@@ -69,12 +74,14 @@ const MANIFEST_BODY = JSON.stringify({
|
|
|
69
74
|
});
|
|
70
75
|
const ROBOTS_TXT = "User-agent: *\nDisallow: /\n";
|
|
71
76
|
async function createCodeServer(opts = {}) {
|
|
72
|
-
const
|
|
77
|
+
const explicitToken = opts.connectionToken || opts.vscode?.["connection-token"];
|
|
78
|
+
const isLocal = !opts.host || /^(localhost|127\.0\.0\.1)$/.test(opts.host);
|
|
79
|
+
const withoutToken = opts.vscode?.["without-connection-token"] === true || !explicitToken && isLocal;
|
|
73
80
|
const connectionToken = withoutToken ? "" : opts.connectionToken ?? randomUUID();
|
|
74
81
|
const defaultFolder = opts.defaultFolder ?? process.cwd();
|
|
75
82
|
const mintKey = randomBytes(32);
|
|
76
83
|
process.env.CODE_SERVER_PARENT_PID ??= String(process.pid);
|
|
77
|
-
cleanupStaleLocks(opts.vscode?.["user-data-dir"] ?? join(homedir(), ".vscode-server-oss", "data"));
|
|
84
|
+
cleanupStaleLocks(opts.vscode?.["user-data-dir"] ?? join(_os.homedir(), ".vscode-server-oss", "data"));
|
|
78
85
|
const { modulesDir } = await loadCode();
|
|
79
86
|
const vsRootPath = join(modulesDir, "code-server", "lib", "vscode");
|
|
80
87
|
ensureNetworkInterface();
|
|
@@ -207,17 +214,17 @@ async function startCodeServer(opts = {}) {
|
|
|
207
214
|
};
|
|
208
215
|
}
|
|
209
216
|
function ensureNetworkInterface() {
|
|
210
|
-
const original =
|
|
217
|
+
const original = _os.networkInterfaces;
|
|
211
218
|
const BLACKLISTED = new Set([
|
|
212
219
|
"00:00:00:00:00:00",
|
|
213
220
|
"ff:ff:ff:ff:ff:ff",
|
|
214
221
|
"ac:de:48:00:11:22"
|
|
215
222
|
]);
|
|
216
|
-
|
|
217
|
-
const ifaces = original.call(
|
|
223
|
+
_os.networkInterfaces = function networkInterfaces() {
|
|
224
|
+
const ifaces = original.call(_os);
|
|
218
225
|
for (const name in ifaces) for (const info of ifaces[name]) if (info.mac && !BLACKLISTED.has(info.mac)) return ifaces;
|
|
219
226
|
const { createHash } = __require("node:crypto");
|
|
220
|
-
const hash = createHash("md5").update(
|
|
227
|
+
const hash = createHash("md5").update(_os.hostname()).digest();
|
|
221
228
|
hash[0] = (hash[0] | 2) & 254;
|
|
222
229
|
ifaces._coderaft = [{
|
|
223
230
|
address: "10.0.0.1",
|
package/dist/cli.mjs
CHANGED
|
@@ -15,6 +15,10 @@ const { values, positionals } = parseArgs({
|
|
|
15
15
|
"server-base-path": { type: "string" },
|
|
16
16
|
"socket-path": { type: "string" },
|
|
17
17
|
"print-startup-performance": { type: "boolean" },
|
|
18
|
+
token: {
|
|
19
|
+
type: "string",
|
|
20
|
+
short: "t"
|
|
21
|
+
},
|
|
18
22
|
"connection-token": { type: "string" },
|
|
19
23
|
"connection-token-file": { type: "string" },
|
|
20
24
|
"without-connection-token": { type: "boolean" },
|
|
@@ -29,7 +33,10 @@ const { values, positionals } = parseArgs({
|
|
|
29
33
|
"extensions-download-dir": { type: "string" },
|
|
30
34
|
"builtin-extensions-dir": { type: "string" },
|
|
31
35
|
"agent-plugins-dir": { type: "string" },
|
|
32
|
-
log: {
|
|
36
|
+
log: {
|
|
37
|
+
type: "string",
|
|
38
|
+
multiple: true
|
|
39
|
+
},
|
|
33
40
|
"logs-path": { type: "string" },
|
|
34
41
|
"disable-websocket-compression": { type: "boolean" },
|
|
35
42
|
"use-host-proxy": { type: "boolean" },
|
|
@@ -41,6 +48,11 @@ const { values, positionals } = parseArgs({
|
|
|
41
48
|
"disable-update-check": { type: "boolean" },
|
|
42
49
|
"disable-experiments": { type: "boolean" },
|
|
43
50
|
"enable-sync": { type: "boolean" },
|
|
51
|
+
"disable-extensions": { type: "boolean" },
|
|
52
|
+
"disable-extension": {
|
|
53
|
+
type: "string",
|
|
54
|
+
multiple: true
|
|
55
|
+
},
|
|
44
56
|
"enable-proposed-api": {
|
|
45
57
|
type: "string",
|
|
46
58
|
multiple: true
|
|
@@ -85,6 +97,7 @@ if (values.help) {
|
|
|
85
97
|
--print-startup-performance Print startup timing to stdout
|
|
86
98
|
|
|
87
99
|
Auth:
|
|
100
|
+
-t, --token <token> Connection token for auth (shorthand)
|
|
88
101
|
--connection-token <token> Connection token for auth (auto-generated)
|
|
89
102
|
--connection-token-file <path> Path to file containing connection token
|
|
90
103
|
--without-connection-token Disable connection token auth
|
|
@@ -125,6 +138,8 @@ if (values.help) {
|
|
|
125
138
|
|
|
126
139
|
Features:
|
|
127
140
|
--enable-sync Enable settings sync
|
|
141
|
+
--disable-extensions Disable all installed extensions
|
|
142
|
+
--disable-extension <ext-id> Disable specific extension (repeatable)
|
|
128
143
|
--enable-proposed-api <ext-id> Enable proposed API for extension (repeatable)
|
|
129
144
|
--disable-workspace-trust Disable workspace trust
|
|
130
145
|
--disable-getting-started-override Disable getting started override
|
|
@@ -185,6 +200,8 @@ for (const key of [
|
|
|
185
200
|
"disable-update-check",
|
|
186
201
|
"disable-experiments",
|
|
187
202
|
"enable-sync",
|
|
203
|
+
"disable-extensions",
|
|
204
|
+
"disable-extension",
|
|
188
205
|
"enable-proposed-api",
|
|
189
206
|
"disable-workspace-trust",
|
|
190
207
|
"disable-getting-started-override",
|
|
@@ -211,7 +228,7 @@ const handle = await startCodeServer({
|
|
|
211
228
|
port: values.port ? Number(values.port) : void 0,
|
|
212
229
|
host: values.host,
|
|
213
230
|
defaultFolder: dir || values["default-folder"],
|
|
214
|
-
connectionToken: values["connection-token"],
|
|
231
|
+
connectionToken: values["connection-token"] ?? values.token,
|
|
215
232
|
vscode
|
|
216
233
|
});
|
|
217
234
|
const c = {
|
package/dist/index.d.mts
CHANGED
|
@@ -42,7 +42,7 @@ interface VSCodeServerOptions {
|
|
|
42
42
|
/** The workspace to open when no input is specified in the browser URL. A relative or absolute path resolved against the current working directory. */
|
|
43
43
|
"default-workspace"?: string;
|
|
44
44
|
locale?: string;
|
|
45
|
-
log?: string;
|
|
45
|
+
log?: string[];
|
|
46
46
|
logsPath?: string;
|
|
47
47
|
"disable-websocket-compression"?: boolean;
|
|
48
48
|
"use-host-proxy"?: boolean;
|
|
@@ -83,14 +83,14 @@ interface CreateCodeServerOptions {
|
|
|
83
83
|
defaultFolder?: string;
|
|
84
84
|
/** Connection token (shared auth secret). Auto-generated if omitted. */
|
|
85
85
|
connectionToken?: string;
|
|
86
|
+
/** Host/interface to bind (used to infer local-only access for token default). */
|
|
87
|
+
host?: string;
|
|
86
88
|
/** Extra options forwarded to VS Code's `createServer()`. */
|
|
87
89
|
vscode?: VSCodeServerOptions;
|
|
88
90
|
}
|
|
89
91
|
interface StartCodeServerOptions extends CreateCodeServerOptions {
|
|
90
92
|
/** TCP port to listen on. Defaults to `$PORT` or `6063`. */
|
|
91
93
|
port?: number;
|
|
92
|
-
/** Host/interface to bind. Defaults to Node's default (all interfaces). */
|
|
93
|
-
host?: string;
|
|
94
94
|
}
|
|
95
95
|
interface CodeServerHandler {
|
|
96
96
|
/** Node-style HTTP request handler (middleware). */
|