@vesk/vesk-cli 0.1.0 → 0.1.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/dist/sidecar.js CHANGED
@@ -7442,21 +7442,13 @@ var scanApiRoutes;
7442
7442
  var collectMiddlewareChain;
7443
7443
  async function ensureModules() {
7444
7444
  if (compileClient2) return;
7445
- console.log("sidecar: loading client-codegen");
7446
7445
  const clientCodegen = await loadCompilerModule("client-codegen.js");
7447
- console.log("sidecar: loading server-codegen");
7448
7446
  const serverCodegen = await loadCompilerModule("server-codegen.js");
7449
- console.log("sidecar: loading vsk-tsx");
7450
7447
  const vskTsx = await loadCompilerModule("vsk-tsx.js");
7451
- console.log("sidecar: loading typecheck");
7452
7448
  const typecheck = await loadCompilerModule("typecheck.js");
7453
- console.log("sidecar: loading router");
7454
7449
  const router = await loadCompilerModule("router.js");
7455
- console.log("sidecar: loading middleware");
7456
7450
  const middleware = await loadCompilerModule("middleware.js");
7457
- console.log("sidecar: loading api-routes");
7458
7451
  const apiRoutes = await loadCompilerModule("api-routes.js");
7459
- console.log("sidecar: all modules loaded");
7460
7452
  compileClient2 = clientCodegen.compileClient;
7461
7453
  compileServer = serverCodegen.compileServer;
7462
7454
  generateVskDts = vskTsx.generateVskDts;
@@ -7496,6 +7488,10 @@ async function processCssWithPlugins(css, filePath, projectDir) {
7496
7488
  }
7497
7489
  return result;
7498
7490
  }
7491
+ function errorStatusCode(e) {
7492
+ const s = e?.statusCode ?? e?.status;
7493
+ return typeof s === "number" && s >= 100 && s < 600 ? s : 500;
7494
+ }
7499
7495
  function err(id, message) {
7500
7496
  return { jsonrpc: "2.0", id, error: { code: 1, message } };
7501
7497
  }
@@ -8185,7 +8181,8 @@ ${devMods.prettifyHtml(body)}
8185
8181
  } catch (e) {
8186
8182
  const msg = e instanceof Error ? e.message : String(e);
8187
8183
  if (forData) {
8188
- return new Response(JSON.stringify({ error: msg }), { status: 500, headers: { "Content-Type": "application/json", "Cache-Control": "no-store", "Vary": "x-vesk-data" } });
8184
+ const code = errorStatusCode(e);
8185
+ return new Response(JSON.stringify({ error: msg, statusCode: code }), { status: code, headers: { "Content-Type": "application/json", "Cache-Control": "no-store", "Vary": "x-vesk-data" } });
8189
8186
  }
8190
8187
  throw e;
8191
8188
  }
@@ -8268,7 +8265,7 @@ ${devMods.prettifyHtml(body)}
8268
8265
  try {
8269
8266
  const errSrc = readFileSync3(errPath, "utf-8");
8270
8267
  const errCompName = extractCompName(errSrc) || node.error;
8271
- const errProps = { error: err2.message, stack: err2.stack, statusCode: 500, url: url.pathname };
8268
+ const errProps = { error: err2.message, stack: err2.stack, statusCode: errorStatusCode(err2), url: url.pathname };
8272
8269
  const html = await devMods.renderFullPage(errSrc, errCompName, errProps, /* @__PURE__ */ new Map(), {
8273
8270
  hydrate: true,
8274
8271
  cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"],
@@ -8286,10 +8283,11 @@ ${devMods.prettifyHtml(body)}
8286
8283
  }
8287
8284
  const message = err2.message || String(e);
8288
8285
  const stack = err2.stack || "";
8286
+ const errCode = errorStatusCode(err2);
8289
8287
  return {
8290
- status: 500,
8288
+ status: errCode,
8291
8289
  headers: [["Content-Type", "text/html"]],
8292
- bodyB64: Buffer.from(errorHtml || `<!DOCTYPE html><html><body><h1>500</h1><pre>${message}
8290
+ bodyB64: Buffer.from(errorHtml || `<!DOCTYPE html><html><body><h1>${errCode}</h1><pre>${message}
8293
8291
  ${stack}</pre></body></html>`).toString("base64")
8294
8292
  };
8295
8293
  }
@@ -8308,8 +8306,7 @@ async function handleDevRequest(p) {
8308
8306
  const headers = Object.entries({ ...corsAllowed, "Content-Length": "0" });
8309
8307
  return { status: 204, headers, bodyB64: "" };
8310
8308
  }
8311
- const proto = p.headers["x-forwarded-proto"] && state.security?.trustProxy ? p.headers["x-forwarded-proto"] : "http";
8312
- globalThis.__vesk_ssr_base_url = `${proto}://${reqHost}`;
8309
+ globalThis.__vesk_ssr_base_url = `http://127.0.0.1:${p.port || state.port}`;
8313
8310
  const req = {
8314
8311
  method: p.method,
8315
8312
  url: url.pathname + url.search,
@@ -8798,6 +8795,7 @@ async function prodRenderNotFound(urlPath) {
8798
8795
  return await rtMod.renderFullPage(src, compName, { params: {}, url: urlPath }, /* @__PURE__ */ new Map(), {
8799
8796
  hydrate: true,
8800
8797
  cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"],
8798
+ clientScriptUrl: "/_vesk/static/client.js",
8801
8799
  security: state.securityConfig.security || {},
8802
8800
  externalDataScript: prodStoreDataScript,
8803
8801
  sourcePath: nfPath
@@ -8827,6 +8825,7 @@ async function prodRenderError(props) {
8827
8825
  return await rtMod.renderFullPage(src, compName, props, /* @__PURE__ */ new Map(), {
8828
8826
  hydrate: true,
8829
8827
  cssUrls: ["/_vesk/static/_tailwind.css", "/_vesk/static/global.css"],
8828
+ clientScriptUrl: "/_vesk/static/client.js",
8830
8829
  security: state.securityConfig.security || {},
8831
8830
  externalDataScript: prodStoreDataScript,
8832
8831
  sourcePath: errPath
@@ -8887,7 +8886,13 @@ function installSsrFetchHook() {
8887
8886
  clientIp: prodIpStore.getStore()?.clientIp || "127.0.0.1",
8888
8887
  port: state.port
8889
8888
  };
8890
- const resp = await handleProdRequest(devReq);
8889
+ const savedBase = globalThis.__vesk_ssr_base_url;
8890
+ let resp;
8891
+ try {
8892
+ resp = await handleProdRequest(devReq);
8893
+ } finally {
8894
+ globalThis.__vesk_ssr_base_url = savedBase;
8895
+ }
8891
8896
  const bodyBuf = resp.bodyB64 ? Buffer.from(resp.bodyB64, "base64") : Buffer.alloc(0);
8892
8897
  const hdrs = new Headers();
8893
8898
  for (const [k, v] of resp.headers) {
@@ -8906,6 +8911,7 @@ async function handleProdRequest(p) {
8906
8911
  if (!state) {
8907
8912
  return { status: 500, headers: [["Content-Type", "application/json"]], bodyB64: Buffer.from(JSON.stringify({ error: "prod server not initialized" })).toString("base64") };
8908
8913
  }
8914
+ let mwLocals = {};
8909
8915
  const url = new URL(p.url, `http://localhost:${p.port || state.port}`);
8910
8916
  const bodyBuffer = p.bodyB64 ? Buffer.from(p.bodyB64, "base64") : Buffer.alloc(0);
8911
8917
  const req = {
@@ -9006,10 +9012,26 @@ async function handleProdRequest(p) {
9006
9012
  return withSec({ status: mwResult.response.status, headers, bodyB64: Buffer.from(body).toString("base64") });
9007
9013
  }
9008
9014
  if (mwResult.rewriteUrl) url.pathname = mwResult.rewriteUrl;
9015
+ mwLocals = mwCtx.locals || {};
9009
9016
  } catch (e) {
9010
9017
  console.error("prod: middleware error:", e.message);
9011
9018
  }
9012
9019
  }
9020
+ const withVeskRequest = (fn) => {
9021
+ const prev = globalThis.__vesk_request;
9022
+ globalThis.__vesk_request = {
9023
+ request: req,
9024
+ params: {},
9025
+ url,
9026
+ locals: mwLocals,
9027
+ cookies: {}
9028
+ };
9029
+ try {
9030
+ return fn();
9031
+ } finally {
9032
+ globalThis.__vesk_request = prev;
9033
+ }
9034
+ };
9013
9035
  if (url.pathname.startsWith("/_vesk/action/")) {
9014
9036
  const actionId = url.pathname.replace("/_vesk/action/", "");
9015
9037
  const actionEntry = state.buildConfig.actions && state.buildConfig.actions.find((a) => a.id === actionId);
@@ -9022,7 +9044,7 @@ async function handleProdRequest(p) {
9022
9044
  }
9023
9045
  try {
9024
9046
  const webRequest = makeWebRequest(req, url);
9025
- const response = await withProdClientIp(p.clientIp, () => mod.handleAction(webRequest, actionId));
9047
+ const response = await withVeskRequest(() => withProdClientIp(p.clientIp, () => mod.handleAction(webRequest, actionId)));
9026
9048
  const body = await response.text();
9027
9049
  const headers = [];
9028
9050
  for (const [k, v] of response.headers.entries()) headers.push([k, v]);
@@ -9037,17 +9059,14 @@ async function handleProdRequest(p) {
9037
9059
  if (route.type === "api") {
9038
9060
  const params = prodMatchPath(route.path, url.pathname);
9039
9061
  if (params) {
9040
- const t0 = Date.now();
9041
9062
  const mod = await prodLoadFunction(route.function);
9042
- const t1 = Date.now();
9043
9063
  if (mod) {
9044
9064
  try {
9045
9065
  const webRequest = makeWebRequest(req, url);
9046
- const response = await withProdClientIp(p.clientIp, () => mod.handle(webRequest));
9066
+ const response = await withVeskRequest(() => withProdClientIp(p.clientIp, () => mod.handle(webRequest)));
9047
9067
  const body = await response.text();
9048
9068
  const headers = [];
9049
9069
  for (const [k, v] of response.headers.entries()) headers.push([k, v]);
9050
- console.error(`sidecar: prod_api ${url.pathname} load=${t1 - t0}ms handle=${Date.now() - t1}ms`);
9051
9070
  return withSec({ status: response.status, headers, bodyB64: Buffer.from(body).toString("base64") });
9052
9071
  } catch (e) {
9053
9072
  const message = e instanceof Error ? e.message : String(e);
@@ -9069,7 +9088,7 @@ async function handleProdRequest(p) {
9069
9088
  let cachedResult = null;
9070
9089
  if (route.revalidate && route.revalidate > 0) {
9071
9090
  cachedResult = await devMods.runtimeServer.pageIsr(url.pathname, async () => {
9072
- const response2 = await withProdClientIp(p.clientIp, () => mod.handle(webRequest));
9091
+ const response2 = await withVeskRequest(() => withProdClientIp(p.clientIp, () => mod.handle(webRequest)));
9073
9092
  return { html: await response2.text(), headers: Object.fromEntries(response2.headers) };
9074
9093
  }, { revalidate: route.revalidate, tags: route.tags || [] });
9075
9094
  }
@@ -9077,7 +9096,7 @@ async function handleProdRequest(p) {
9077
9096
  const headers2 = Object.entries(cachedResult.headers || { "Content-Type": "text/html" });
9078
9097
  return withSec({ status: 200, headers: headers2, bodyB64: Buffer.from(cachedResult.html).toString("base64") });
9079
9098
  }
9080
- const response = await withProdClientIp(p.clientIp, () => mod.handle(webRequest));
9099
+ const response = await withVeskRequest(() => withProdClientIp(p.clientIp, () => mod.handle(webRequest)));
9081
9100
  const headers = Object.fromEntries(response.headers);
9082
9101
  if (!headers["content-type"] && !headers["Content-Type"]) headers["Content-Type"] = "text/html";
9083
9102
  const body = await response.text();
@@ -9086,15 +9105,15 @@ async function handleProdRequest(p) {
9086
9105
  const err2 = e instanceof Error ? e : new Error(String(e));
9087
9106
  if (err2.name === "NotFoundError") {
9088
9107
  const nfHtml2 = await prodRenderNotFoundCached(url.pathname);
9089
- return withSec({ status: 404, headers: [["Content-Type", "text/html"]], bodyB64: Buffer.from(nfHtml2 || "<!DOCTYPE html><html><body><h1>404</h1><p>Not Found</p></body></html>").toString("base64") });
9108
+ return withSec({ status: 404, headers: [["Content-Type", "text/html"]], bodyB64: Buffer.from(nfHtml2 || '<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="/_vesk/static/_tailwind.css" /><link rel="stylesheet" href="/_vesk/static/global.css" /></head><body><h1>404</h1><p>Not Found</p><script type="module" src="/_vesk/static/client.js"></script></body></html>').toString("base64") });
9090
9109
  }
9091
9110
  console.error("haul ssr error:", err2.message);
9092
9111
  let errorHtml = null;
9093
9112
  try {
9094
- errorHtml = await prodRenderError({ error: err2.message, stack: err2.stack, statusCode: 500, url: url.pathname });
9113
+ errorHtml = await prodRenderError({ error: err2.message, stack: err2.stack, statusCode: errorStatusCode(err2), url: url.pathname });
9095
9114
  } catch {
9096
9115
  }
9097
- return withSec({ status: 500, headers: [["Content-Type", "text/html"]], bodyB64: Buffer.from(errorHtml || "<!DOCTYPE html><html><body><h1>500</h1><pre>Internal Server Error</pre></body></html>").toString("base64") });
9116
+ return withSec({ status: errorStatusCode(err2), headers: [["Content-Type", "text/html"]], bodyB64: Buffer.from(errorHtml || '<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="stylesheet" href="/_vesk/static/_tailwind.css" /><link rel="stylesheet" href="/_vesk/static/global.css" /></head><body><div style="font-family:system-ui;padding:2rem"><h1>' + errorStatusCode(err2) + " \u2014 Internal Server Error</h1><pre>" + String(err2.message).replace(/</g, "&lt;") + '</pre></div><script type="module" src="/_vesk/static/client.js"></script></body></html>').toString("base64") });
9098
9117
  }
9099
9118
  }
9100
9119
  }
@@ -9321,9 +9340,7 @@ ${extracted.body}
9321
9340
  return;
9322
9341
  }
9323
9342
  case "prod_render": {
9324
- const t0 = Date.now();
9325
9343
  const result = await handleProdRequest(rpcReq.params[0] || {});
9326
- console.error(`sidecar: prod_render ${(rpcReq.params[0] || {}).url} ${Date.now() - t0}ms`);
9327
9344
  respond({ jsonrpc: "2.0", id: rpcReq.id, result });
9328
9345
  return;
9329
9346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "description": "Vesk — compiler-first framework for the post-VDOM web. vesk dev, vesk build.",
6
6
  "bin": {
@@ -9,10 +9,10 @@
9
9
  },
10
10
  "main": "./dist/cli.js",
11
11
  "dependencies": {
12
- "@vesk/adapter": "^0.1.0",
13
- "@vesk/compiler": "^0.1.0",
14
- "@vesk/plugin-tailwind": "^0.1.0",
15
- "@vesk/runtime": "^0.1.0",
12
+ "@vesk/adapter": "^0.1.14",
13
+ "@vesk/compiler": "^0.1.14",
14
+ "@vesk/plugin-tailwind": "^0.1.14",
15
+ "@vesk/runtime": "^0.1.14",
16
16
  "esbuild": "^0.25.0",
17
17
  "esrap": "^2.3.0",
18
18
  "sharp": "^0.35.3",
@@ -46,10 +46,10 @@
46
46
  "README.md"
47
47
  ],
48
48
  "optionalDependencies": {
49
- "@vesk/haul-darwin-arm64": "^0.1.0",
50
- "@vesk/haul-darwin-x64": "^0.1.0",
51
- "@vesk/haul-linux-arm64": "^0.1.0",
52
- "@vesk/haul-linux-x64": "^0.1.0",
53
- "@vesk/haul-win32-x64": "^0.1.0"
49
+ "@vesk/haul-darwin-arm64": "^0.1.14",
50
+ "@vesk/haul-darwin-x64": "^0.1.14",
51
+ "@vesk/haul-linux-arm64": "^0.1.14",
52
+ "@vesk/haul-linux-x64": "^0.1.14",
53
+ "@vesk/haul-win32-x64": "^0.1.14"
54
54
  }
55
55
  }