coderaft 0.0.42 → 0.0.44

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/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 = "1bd91db31c40505f";
7
+ const codeArchiveHash = "d612b55678d45406";
8
8
 
9
9
  const archivePath = fileURLToPath(new URL("./code.tar.zst", import.meta.url));
10
10
 
package/code.tar.zst CHANGED
Binary file
@@ -5,7 +5,9 @@ import { createReadStream, readFileSync, readdirSync, unlinkSync } from "node:fs
5
5
  import { randomBytes, randomUUID } from "node:crypto";
6
6
  import { createServer } from "node:http";
7
7
  import { extname, join, normalize, sep } from "node:path";
8
- import { stat } from "node:fs/promises";
8
+ import { readFile, stat } from "node:fs/promises";
9
+ import { promisify } from "node:util";
10
+ import { brotliCompress, constants, gzip } from "node:zlib";
9
11
  import { loadCode } from "#code";
10
12
  const STATIC_MIME = {
11
13
  ".js": "text/javascript",
@@ -23,10 +25,28 @@ const STATIC_MIME = {
23
25
  ".wasm": "application/wasm",
24
26
  ".woff": "font/woff",
25
27
  ".woff2": "font/woff2",
28
+ ".ttf": "font/ttf",
26
29
  ".map": "application/json",
27
30
  ".txt": "text/plain"
28
31
  };
29
- async function serveStatic(res, root, relPath) {
32
+ const COMPRESSIBLE_EXT = /* @__PURE__ */ new Set([
33
+ ".js",
34
+ ".mjs",
35
+ ".css",
36
+ ".html",
37
+ ".json",
38
+ ".svg",
39
+ ".map",
40
+ ".txt",
41
+ ".wasm",
42
+ ".ttf",
43
+ ".ico"
44
+ ]);
45
+ const MIN_COMPRESS_SIZE = 1024;
46
+ const brotliAsync = promisify(brotliCompress);
47
+ const gzipAsync = promisify(gzip);
48
+ const compressedCache = /* @__PURE__ */ new Map();
49
+ async function serveStatic(req, res, root, relPath) {
30
50
  const abs = normalize(join(root, decodeURIComponent(relPath)));
31
51
  if (abs !== root && !abs.startsWith(root + sep)) {
32
52
  res.writeHead(400).end("Bad request.");
@@ -35,19 +55,61 @@ async function serveStatic(res, root, relPath) {
35
55
  try {
36
56
  const st = await stat(abs);
37
57
  if (!st.isFile()) return false;
58
+ const ext = extname(abs).toLowerCase();
38
59
  const headers = {
39
- "Content-Type": STATIC_MIME[extname(abs).toLowerCase()] ?? "application/octet-stream",
40
- "Content-Length": st.size,
60
+ "Content-Type": STATIC_MIME[ext] ?? "application/octet-stream",
41
61
  "Cache-Control": "public, max-age=31536000, immutable"
42
62
  };
43
63
  if (abs.endsWith("/serviceWorker.js")) headers["Service-Worker-Allowed"] = "/";
64
+ const compressible = COMPRESSIBLE_EXT.has(ext) && st.size >= MIN_COMPRESS_SIZE;
65
+ if (compressible) headers["Vary"] = "Accept-Encoding";
66
+ const encoding = compressible ? negotiateEncoding(req.headers["accept-encoding"]) : void 0;
67
+ if (encoding) {
68
+ const key = `${encoding}:${abs}:${st.mtimeMs}:${st.size}`;
69
+ let body = compressedCache.get(key);
70
+ if (!body) {
71
+ body = compressFile(abs, encoding);
72
+ compressedCache.set(key, body);
73
+ body.catch(() => compressedCache.delete(key));
74
+ }
75
+ const buf = await body;
76
+ headers["Content-Encoding"] = encoding;
77
+ headers["Content-Length"] = buf.length;
78
+ res.writeHead(200, headers);
79
+ res.end(req.method === "HEAD" ? void 0 : buf);
80
+ return true;
81
+ }
82
+ headers["Content-Length"] = st.size;
44
83
  res.writeHead(200, headers);
45
- createReadStream(abs).pipe(res);
84
+ if (req.method === "HEAD") res.end();
85
+ else createReadStream(abs).pipe(res);
46
86
  return true;
47
87
  } catch {
48
88
  return false;
49
89
  }
50
90
  }
91
+ async function compressFile(abs, encoding) {
92
+ const raw = await readFile(abs);
93
+ if (encoding === "br") return brotliAsync(raw, { params: {
94
+ [constants.BROTLI_PARAM_QUALITY]: 5,
95
+ [constants.BROTLI_PARAM_SIZE_HINT]: raw.length
96
+ } });
97
+ return gzipAsync(raw, { level: 6 });
98
+ }
99
+ function negotiateEncoding(acceptEncoding) {
100
+ const value = Array.isArray(acceptEncoding) ? acceptEncoding.join(",") : acceptEncoding;
101
+ if (!value) return void 0;
102
+ const accepted = /* @__PURE__ */ new Set();
103
+ for (const part of value.split(",")) {
104
+ const [name, ...params] = part.trim().toLowerCase().split(";");
105
+ if (!name) continue;
106
+ const q = params.map((p) => p.trim()).find((p) => p.startsWith("q="));
107
+ if (q && Number(q.slice(2)) === 0) continue;
108
+ accepted.add(name);
109
+ }
110
+ if (accepted.has("br")) return "br";
111
+ if (accepted.has("gzip")) return "gzip";
112
+ }
51
113
  var server_exports = /* @__PURE__ */ __exportAll({
52
114
  createCodeServer: () => createCodeServer,
53
115
  startCodeServer: () => startCodeServer
@@ -107,6 +169,7 @@ async function createCodeServer(opts = {}) {
107
169
  _product.nameLong = "coderaft";
108
170
  _product.applicationName = "coderaft";
109
171
  }
172
+ const staticPrefix = `/${_product?.quality ?? "oss"}-${_product?.commit ?? "dev"}/static/`;
110
173
  const vscodeServer = await (await mod.loadCodeWithNls()).createServer(null, {
111
174
  "default-folder": defaultFolder,
112
175
  "extensions-dir": extensionsDir,
@@ -177,7 +240,13 @@ async function createCodeServer(opts = {}) {
177
240
  return;
178
241
  }
179
242
  if (url.startsWith("/_static/")) {
180
- serveStatic(res, join(modulesDir, "code-server"), url.slice(9)).then((served) => {
243
+ serveStatic(req, res, join(modulesDir, "code-server"), url.slice(9)).then((served) => {
244
+ if (!served) vscodeServer.handleRequest(req, res);
245
+ });
246
+ return;
247
+ }
248
+ if ((method === "GET" || method === "HEAD") && url.startsWith(staticPrefix)) {
249
+ serveStatic(req, res, vsRootPath, url.slice(staticPrefix.length)).then((served) => {
181
250
  if (!served) vscodeServer.handleRequest(req, res);
182
251
  });
183
252
  return;
@@ -192,6 +261,7 @@ async function createCodeServer(opts = {}) {
192
261
  });
193
262
  return;
194
263
  }
264
+ if (baseURL) req.originalUrl = strippedUrl;
195
265
  vscodeServer.handleRequest(req, res);
196
266
  },
197
267
  handleUpgrade(req, socket, _head) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coderaft",
3
- "version": "0.0.42",
3
+ "version": "0.0.44",
4
4
  "repository": "pithings/coderaft",
5
5
  "bin": {
6
6
  "coderaft": "./dist/cli.mjs"
@@ -31,12 +31,13 @@
31
31
  "build": "obuild"
32
32
  },
33
33
  "devDependencies": {
34
- "code-server": "https://github.com/coder/code-server/releases/download/v4.133.0/package.tar.gz",
34
+ "code-server": "https://github.com/coder/code-server/releases/download/v4.140.0/package.tar.gz",
35
+ "@devcontainers/cli": "0.88.0",
35
36
  "@github/copilot": "workspace:*",
36
37
  "@github/copilot-sdk": "workspace:*",
37
38
  "@microsoft/1ds-core-js": "workspace:*",
38
39
  "@microsoft/1ds-post-js": "workspace:*",
39
- "@microsoft/mxc-sdk": "0.6.1",
40
+ "@microsoft/mxc-sdk": "0.8.0",
40
41
  "@parcel/watcher": "workspace:*",
41
42
  "@vscode/copilot-api": "^0.5.2",
42
43
  "@vscode/deviceid": "workspace:*",
@@ -53,16 +54,16 @@
53
54
  "@vscode/vscode-languagedetection": "1.0.23",
54
55
  "@vscode/windows-process-tree": "workspace:*",
55
56
  "@vscode/windows-registry": "workspace:*",
56
- "@xterm/addon-clipboard": "^0.3.0-beta.292",
57
- "@xterm/addon-image": "^0.10.0-beta.292",
58
- "@xterm/addon-ligatures": "^0.11.0-beta.292",
59
- "@xterm/addon-progress": "^0.3.0-beta.292",
60
- "@xterm/addon-search": "^0.17.0-beta.292",
61
- "@xterm/addon-serialize": "^0.15.0-beta.292",
62
- "@xterm/addon-unicode11": "^0.10.0-beta.292",
63
- "@xterm/addon-webgl": "^0.20.0-beta.291",
64
- "@xterm/headless": "^6.1.0-beta.292",
65
- "@xterm/xterm": "^6.1.0-beta.292",
57
+ "@xterm/addon-clipboard": "^0.3.0-beta.303",
58
+ "@xterm/addon-image": "^0.10.0-beta.301",
59
+ "@xterm/addon-ligatures": "^0.11.0-beta.301",
60
+ "@xterm/addon-progress": "^0.3.0-beta.301",
61
+ "@xterm/addon-search": "^0.17.0-beta.301",
62
+ "@xterm/addon-serialize": "^0.15.0-beta.301",
63
+ "@xterm/addon-unicode11": "^0.10.0-beta.301",
64
+ "@xterm/addon-webgl": "^0.20.0-beta.300",
65
+ "@xterm/headless": "^6.1.0-beta.303",
66
+ "@xterm/xterm": "^6.1.0-beta.304",
66
67
  "cookie": "^0.7.0",
67
68
  "detect-libc": "^2.1.2",
68
69
  "http-proxy-agent": "^7.0.0",
@@ -76,7 +77,7 @@
76
77
  "node-pty": "workspace:*",
77
78
  "ssh2": "workspace:*",
78
79
  "tar": "^7.5.20",
79
- "tas-client": "0.3.1",
80
+ "tas-client": "0.4.6",
80
81
  "typescript": "^6.0.3",
81
82
  "vscode-oniguruma": "1.7.0",
82
83
  "vscode-regexpp": "^3.1.0",