coderaft 0.0.13 → 0.0.15

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 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 if omitted
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. Auto-generated if omitted. |
100
- | `vscode` | `VSCodeServerOptions` | Extra options forwarded to VS Code's internal `createServer()`. |
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 = "d28f51becc566aa4";
7
+ const codeArchiveHash = "28b47fa16ea99a3f";
8
8
 
9
9
  const archivePath = fileURLToPath(new URL("./code.tar.zst", import.meta.url));
10
10
 
package/code.tar.zst CHANGED
Binary file
@@ -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";
@@ -53,6 +52,7 @@ if (process.platform === "android") {
53
52
  const preload = `--import "data:text/javascript,Object.defineProperty(process,'platform',{value:'linux'})"`;
54
53
  process.env.NODE_OPTIONS = process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} ${preload}` : preload;
55
54
  }
55
+ const _os = __require("node:os");
56
56
  const MANIFEST_BODY = JSON.stringify({
57
57
  name: "coderaft",
58
58
  short_name: "coderaft",
@@ -74,12 +74,14 @@ const MANIFEST_BODY = JSON.stringify({
74
74
  });
75
75
  const ROBOTS_TXT = "User-agent: *\nDisallow: /\n";
76
76
  async function createCodeServer(opts = {}) {
77
- const withoutToken = opts.vscode?.["without-connection-token"] === true;
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;
78
80
  const connectionToken = withoutToken ? "" : opts.connectionToken ?? randomUUID();
79
81
  const defaultFolder = opts.defaultFolder ?? process.cwd();
80
82
  const mintKey = randomBytes(32);
81
83
  process.env.CODE_SERVER_PARENT_PID ??= String(process.pid);
82
- 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"));
83
85
  const { modulesDir } = await loadCode();
84
86
  const vsRootPath = join(modulesDir, "code-server", "lib", "vscode");
85
87
  ensureNetworkInterface();
@@ -98,7 +100,7 @@ async function createCodeServer(opts = {}) {
98
100
  }
99
101
  const vscodeServer = await (await mod.loadCodeWithNls()).createServer(null, {
100
102
  "default-folder": defaultFolder,
101
- ...withoutToken ? {} : { "connection-token": connectionToken },
103
+ ...withoutToken ? { "without-connection-token": true } : { "connection-token": connectionToken },
102
104
  "reconnection-grace-time": "10800",
103
105
  "disable-getting-started-override": true,
104
106
  ...opts.vscode
@@ -212,17 +214,17 @@ async function startCodeServer(opts = {}) {
212
214
  };
213
215
  }
214
216
  function ensureNetworkInterface() {
215
- const original = os.networkInterfaces;
217
+ const original = _os.networkInterfaces;
216
218
  const BLACKLISTED = new Set([
217
219
  "00:00:00:00:00:00",
218
220
  "ff:ff:ff:ff:ff:ff",
219
221
  "ac:de:48:00:11:22"
220
222
  ]);
221
- os.networkInterfaces = function networkInterfaces() {
222
- const ifaces = original.call(os);
223
+ _os.networkInterfaces = function networkInterfaces() {
224
+ const ifaces = original.call(_os);
223
225
  for (const name in ifaces) for (const info of ifaces[name]) if (info.mac && !BLACKLISTED.has(info.mac)) return ifaces;
224
226
  const { createHash } = __require("node:crypto");
225
- const hash = createHash("md5").update(os.hostname()).digest();
227
+ const hash = createHash("md5").update(_os.hostname()).digest();
226
228
  hash[0] = (hash[0] | 2) & 254;
227
229
  ifaces._coderaft = [{
228
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" },
@@ -93,6 +97,7 @@ if (values.help) {
93
97
  --print-startup-performance Print startup timing to stdout
94
98
 
95
99
  Auth:
100
+ -t, --token <token> Connection token for auth (shorthand)
96
101
  --connection-token <token> Connection token for auth (auto-generated)
97
102
  --connection-token-file <path> Path to file containing connection token
98
103
  --without-connection-token Disable connection token auth
@@ -223,7 +228,7 @@ const handle = await startCodeServer({
223
228
  port: values.port ? Number(values.port) : void 0,
224
229
  host: values.host,
225
230
  defaultFolder: dir || values["default-folder"],
226
- connectionToken: values["connection-token"],
231
+ connectionToken: values["connection-token"] ?? values.token,
227
232
  vscode
228
233
  });
229
234
  const c = {
package/dist/index.d.mts CHANGED
@@ -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). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coderaft",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "repository": "pithings/coderaft",
5
5
  "bin": {
6
6
  "coderaft": "./dist/cli.mjs"