@absolutejs/absolute 0.19.0-beta.120 → 0.19.0-beta.122

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/cli/index.js CHANGED
@@ -171,18 +171,14 @@ var CERT_DIR, CERT_PATH, KEY_PATH, CERT_VALIDITY_DAYS = 365, devLog = (msg) => c
171
171
  if (os === "linux") {
172
172
  const sudoOpts = {
173
173
  stdin: "inherit",
174
- stderr: "pipe",
174
+ stderr: "inherit",
175
175
  stdout: "pipe"
176
176
  };
177
177
  if (commandExists("apt-get")) {
178
178
  devLog("Installing mkcert (may prompt for password)...");
179
- const r = Bun.spawnSync(["sudo", "apt-get", "install", "-y", "mkcert"], sudoOpts);
180
- if (r.exitCode === 0) {
181
- if (!commandExists("certutil")) {
182
- Bun.spawnSync(["sudo", "apt-get", "install", "-y", "libnss3-tools"], sudoOpts);
183
- }
179
+ const r = Bun.spawnSync(["sudo", "apt-get", "install", "-y", "mkcert", "libnss3-tools"], sudoOpts);
180
+ if (r.exitCode === 0)
184
181
  return true;
185
- }
186
182
  }
187
183
  if (commandExists("dnf")) {
188
184
  devLog("Installing mkcert (may prompt for password)...");
@@ -28,8 +28,7 @@ if (!window.$RefreshRuntime$) {
28
28
  for (const [type, id] of buffer) {
29
29
  RefreshRuntime.register(type, id);
30
30
  }
31
- (
32
- window as unknown as Record<string, unknown>
33
- ).__REFRESH_BUFFER__ = undefined;
31
+ (window as unknown as Record<string, unknown>).__REFRESH_BUFFER__ =
32
+ undefined;
34
33
  }
35
34
  }
package/dist/index.js CHANGED
@@ -1169,7 +1169,14 @@ var colors, MONTHS, formatTimestamp = () => {
1169
1169
  hours = hours % HOURS_IN_HALF_DAY || HOURS_IN_HALF_DAY;
1170
1170
  return `${month} ${day} ${hours}:${minutes}:${seconds} ${ampm}`;
1171
1171
  }, startupBanner = (options) => {
1172
- const { version, duration, port, host, networkUrl, protocol = "http" } = options;
1172
+ const {
1173
+ version,
1174
+ duration,
1175
+ port,
1176
+ host,
1177
+ networkUrl,
1178
+ protocol = "http"
1179
+ } = options;
1173
1180
  const name = `${colors.cyan}${colors.bold}ABSOLUTEJS${colors.reset}`;
1174
1181
  const ver = `${colors.dim}v${version}${colors.reset}`;
1175
1182
  const time = `${colors.dim}ready in${colors.reset} ${colors.bold}${getDurationString(duration)}${colors.reset}`;
@@ -204980,7 +204987,8 @@ var STORE_KEY = "__elysiaStore", getGlobalValue = (key) => Reflect.get(globalThi
204980
204987
  Reflect.set(globalThis, STORE_KEY, app.store);
204981
204988
  }, hmr = (hmrState2, manifest, moduleServerHandler) => (app) => {
204982
204989
  restoreStore(app);
204983
- return app.onBeforeHandle(async ({ request }) => {
204990
+ const http2Mode = Boolean(globalThis.__http2Config);
204991
+ app.onBeforeHandle(async ({ request }) => {
204984
204992
  if (globalThis.__reactModuleRef) {
204985
204993
  await bridgeReactInternals();
204986
204994
  }
@@ -205015,11 +205023,15 @@ var STORE_KEY = "__elysiaStore", getGlobalValue = (key) => Reflect.get(globalThi
205015
205023
  "Content-Type": getMimeType(pathname)
205016
205024
  }
205017
205025
  });
205018
- }).ws("/hmr", {
205019
- close: (ws) => handleClientDisconnect(hmrState2, ws),
205020
- message: (ws, msg) => handleHMRMessage(hmrState2, ws, msg),
205021
- open: (ws) => handleClientConnect(hmrState2, ws, manifest)
205022
- }).get("/hmr-status", () => ({
205026
+ });
205027
+ if (!http2Mode) {
205028
+ app.ws("/hmr", {
205029
+ close: (ws) => handleClientDisconnect(hmrState2, ws),
205030
+ message: (ws, msg) => handleHMRMessage(hmrState2, ws, msg),
205031
+ open: (ws) => handleClientConnect(hmrState2, ws, manifest)
205032
+ });
205033
+ }
205034
+ return app.get("/hmr-status", () => ({
205023
205035
  connectedClients: hmrState2.connectedClients.size,
205024
205036
  isRebuilding: hmrState2.isRebuilding,
205025
205037
  manifestKeys: Object.keys(manifest),
@@ -205035,6 +205047,188 @@ var init_hmr = __esm(() => {
205035
205047
  init_webSocket();
205036
205048
  });
205037
205049
 
205050
+ // src/dev/http2Bridge.ts
205051
+ var exports_http2Bridge = {};
205052
+ __export(exports_http2Bridge, {
205053
+ bridgeHttp2Stream: () => bridgeHttp2Stream
205054
+ });
205055
+ var WS_OPCODE_TEXT = 1, WS_OPCODE_CLOSE = 8, WS_OPCODE_PING = 9, WS_OPCODE_PONG = 10, parseWsFrame = (buf) => {
205056
+ if (buf.length < 2)
205057
+ return null;
205058
+ const byte0 = buf[0];
205059
+ const byte1 = buf[1];
205060
+ const opcode = byte0 & 15;
205061
+ const masked = (byte1 & 128) !== 0;
205062
+ let payloadLen = byte1 & 127;
205063
+ let offset = 2;
205064
+ if (payloadLen === 126) {
205065
+ if (buf.length < 4)
205066
+ return null;
205067
+ payloadLen = buf.readUInt16BE(2);
205068
+ offset = 4;
205069
+ } else if (payloadLen === 127) {
205070
+ if (buf.length < 10)
205071
+ return null;
205072
+ payloadLen = Number(buf.readBigUInt64BE(2));
205073
+ offset = 10;
205074
+ }
205075
+ if (masked) {
205076
+ if (buf.length < offset + 4 + payloadLen)
205077
+ return null;
205078
+ const maskKey = buf.subarray(offset, offset + 4);
205079
+ offset += 4;
205080
+ const payload = Buffer.allocUnsafe(payloadLen);
205081
+ for (let i = 0;i < payloadLen; i++) {
205082
+ payload[i] = buf[offset + i] ^ maskKey[i & 3];
205083
+ }
205084
+ return { opcode, payload, totalLen: offset + payloadLen };
205085
+ }
205086
+ if (buf.length < offset + payloadLen)
205087
+ return null;
205088
+ return {
205089
+ opcode,
205090
+ payload: buf.subarray(offset, offset + payloadLen),
205091
+ totalLen: offset + payloadLen
205092
+ };
205093
+ }, writeWsFrame = (opcode, payload) => {
205094
+ const len = payload.length;
205095
+ let header;
205096
+ if (len < 126) {
205097
+ header = Buffer.allocUnsafe(2);
205098
+ header[0] = 128 | opcode;
205099
+ header[1] = len;
205100
+ } else if (len < 65536) {
205101
+ header = Buffer.allocUnsafe(4);
205102
+ header[0] = 128 | opcode;
205103
+ header[1] = 126;
205104
+ header.writeUInt16BE(len, 2);
205105
+ } else {
205106
+ header = Buffer.allocUnsafe(10);
205107
+ header[0] = 128 | opcode;
205108
+ header[1] = 127;
205109
+ header.writeBigUInt64BE(BigInt(len), 2);
205110
+ }
205111
+ return Buffer.concat([header, payload]);
205112
+ }, createHttp2WebSocket = (stream) => {
205113
+ let state = WS_READY_STATE_OPEN;
205114
+ let buffer = Buffer.alloc(0);
205115
+ let onMessage = null;
205116
+ let onClose = null;
205117
+ stream.on("data", (chunk) => {
205118
+ buffer = Buffer.concat([buffer, chunk]);
205119
+ while (buffer.length > 0) {
205120
+ const frame = parseWsFrame(buffer);
205121
+ if (!frame)
205122
+ break;
205123
+ buffer = buffer.subarray(frame.totalLen);
205124
+ if (frame.opcode === WS_OPCODE_TEXT && onMessage) {
205125
+ onMessage(frame.payload.toString("utf-8"));
205126
+ } else if (frame.opcode === WS_OPCODE_PING) {
205127
+ if (!stream.destroyed) {
205128
+ stream.write(writeWsFrame(WS_OPCODE_PONG, frame.payload));
205129
+ }
205130
+ } else if (frame.opcode === WS_OPCODE_CLOSE) {
205131
+ if (!stream.destroyed) {
205132
+ stream.write(writeWsFrame(WS_OPCODE_CLOSE, Buffer.alloc(0)));
205133
+ stream.end();
205134
+ }
205135
+ state = 3;
205136
+ if (onClose)
205137
+ onClose();
205138
+ }
205139
+ }
205140
+ });
205141
+ stream.on("close", () => {
205142
+ if (state === WS_READY_STATE_OPEN) {
205143
+ state = 3;
205144
+ if (onClose)
205145
+ onClose();
205146
+ }
205147
+ });
205148
+ stream.on("error", () => {
205149
+ state = 3;
205150
+ });
205151
+ const ws = {
205152
+ get readyState() {
205153
+ return state;
205154
+ },
205155
+ send(data) {
205156
+ if (state !== WS_READY_STATE_OPEN || stream.destroyed)
205157
+ return;
205158
+ stream.write(writeWsFrame(WS_OPCODE_TEXT, Buffer.from(data)));
205159
+ },
205160
+ close() {
205161
+ if (state !== WS_READY_STATE_OPEN || stream.destroyed)
205162
+ return;
205163
+ stream.write(writeWsFrame(WS_OPCODE_CLOSE, Buffer.alloc(0)));
205164
+ stream.end();
205165
+ state = 2;
205166
+ },
205167
+ onMessage: null,
205168
+ onClose: null
205169
+ };
205170
+ onMessage = (data) => ws.onMessage?.(data);
205171
+ onClose = () => ws.onClose?.();
205172
+ return ws;
205173
+ }, bridgeHttp2Stream = async (stream, headers, fetchHandler, hmrState2, manifest) => {
205174
+ const method = headers[":method"] ?? "GET";
205175
+ const path = headers[":path"] ?? "/";
205176
+ if (method === "CONNECT" && headers[":protocol"] === "websocket" && hmrState2 && manifest) {
205177
+ stream.respond({ ":status": 200 });
205178
+ const ws = createHttp2WebSocket(stream);
205179
+ ws.onMessage = (data) => handleHMRMessage(hmrState2, ws, data);
205180
+ ws.onClose = () => handleClientDisconnect(hmrState2, ws);
205181
+ handleClientConnect(hmrState2, ws, manifest);
205182
+ return;
205183
+ }
205184
+ const authority = headers[":authority"] ?? "localhost";
205185
+ const scheme = headers[":scheme"] ?? "https";
205186
+ const url = `${scheme}://${authority}${path}`;
205187
+ const requestHeaders = new Headers;
205188
+ for (const [key, value] of Object.entries(headers)) {
205189
+ if (key.startsWith(":") || value === undefined)
205190
+ continue;
205191
+ const headerValue = Array.isArray(value) ? value.join(", ") : value;
205192
+ requestHeaders.set(key, headerValue);
205193
+ }
205194
+ const hasBody = method !== "GET" && method !== "HEAD";
205195
+ const bodyBlob = hasBody ? await new Promise((resolve24) => {
205196
+ const chunks = [];
205197
+ stream.on("data", (chunk) => chunks.push(chunk));
205198
+ stream.on("end", () => {
205199
+ resolve24(new Blob([Buffer.concat(chunks)]));
205200
+ });
205201
+ }) : null;
205202
+ const request = new Request(url, {
205203
+ body: bodyBlob,
205204
+ headers: requestHeaders,
205205
+ method
205206
+ });
205207
+ try {
205208
+ const response = await fetchHandler(request);
205209
+ const responseHeaders = {
205210
+ ":status": response.status
205211
+ };
205212
+ response.headers.forEach((value, key) => {
205213
+ responseHeaders[key] = value;
205214
+ });
205215
+ if (!response.body) {
205216
+ stream.respond(responseHeaders);
205217
+ stream.end();
205218
+ return;
205219
+ }
205220
+ const arrayBuffer = await response.arrayBuffer();
205221
+ stream.respond(responseHeaders);
205222
+ stream.end(Buffer.from(arrayBuffer));
205223
+ } catch {
205224
+ stream.respond({ ":status": 500, "content-type": "text/plain" });
205225
+ stream.end("Internal Server Error");
205226
+ }
205227
+ };
205228
+ var init_http2Bridge = __esm(() => {
205229
+ init_webSocket();
205230
+ });
205231
+
205038
205232
  // src/dev/devCert.ts
205039
205233
  var exports_devCert = {};
205040
205234
  __export(exports_devCert, {
@@ -205171,18 +205365,14 @@ var CERT_DIR, CERT_PATH, KEY_PATH, CERT_VALIDITY_DAYS = 365, devLog = (msg) => c
205171
205365
  if (os2 === "linux") {
205172
205366
  const sudoOpts = {
205173
205367
  stdin: "inherit",
205174
- stderr: "pipe",
205368
+ stderr: "inherit",
205175
205369
  stdout: "pipe"
205176
205370
  };
205177
205371
  if (commandExists("apt-get")) {
205178
205372
  devLog("Installing mkcert (may prompt for password)...");
205179
- const r = Bun.spawnSync(["sudo", "apt-get", "install", "-y", "mkcert"], sudoOpts);
205180
- if (r.exitCode === 0) {
205181
- if (!commandExists("certutil")) {
205182
- Bun.spawnSync(["sudo", "apt-get", "install", "-y", "libnss3-tools"], sudoOpts);
205183
- }
205373
+ const r = Bun.spawnSync(["sudo", "apt-get", "install", "-y", "mkcert", "libnss3-tools"], sudoOpts);
205374
+ if (r.exitCode === 0)
205184
205375
  return true;
205185
- }
205186
205376
  }
205187
205377
  if (commandExists("dnf")) {
205188
205378
  devLog("Installing mkcert (may prompt for password)...");
@@ -205390,6 +205580,10 @@ var prepare = async (configOrPath) => {
205390
205580
  warmCache2(`${SRC_URL_PREFIX2}${rel}`);
205391
205581
  }
205392
205582
  }
205583
+ globalThis.__http2Config = {
205584
+ hmrState: result.hmrState,
205585
+ manifest: result.manifest
205586
+ };
205393
205587
  const hmrPlugin = hmr2(result.hmrState, result.manifest, moduleHandler);
205394
205588
  const devIndexDir = resolve23(buildDir, "_src_indexes");
205395
205589
  for (const key of Object.keys(result.manifest)) {
@@ -205416,6 +205610,8 @@ var pageRouterPlugin = () => {
205416
205610
  };
205417
205611
  // src/plugins/networking.ts
205418
205612
  init_constants();
205613
+ import { readFileSync as readFileSync12 } from "fs";
205614
+ import { join as join18 } from "path";
205419
205615
  import { argv } from "process";
205420
205616
  var {env: env3 } = globalThis.Bun;
205421
205617
 
@@ -205448,45 +205644,65 @@ if (hostFlag) {
205448
205644
  localIP = getLocalIPAddress();
205449
205645
  host = "0.0.0.0";
205450
205646
  }
205451
- var tls = (() => {
205452
- if (env3.NODE_ENV !== "development")
205453
- return;
205454
- if (env3.ABSOLUTE_HTTPS !== "true")
205455
- return;
205456
- try {
205457
- const { loadDevCert: loadDevCert2 } = (init_devCert(), __toCommonJS(exports_devCert));
205458
- return loadDevCert2();
205459
- } catch {
205460
- return;
205461
- }
205462
- })();
205463
- var protocol = tls ? "https" : "http";
205464
- var networking = (app) => app.listen({
205465
- hostname: host,
205466
- port,
205467
- ...tls ? {
205468
- tls: {
205469
- cert: tls.cert,
205470
- key: tls.key
205471
- }
205472
- } : {}
205473
- }, () => {
205647
+ var isHttpsDev = env3.NODE_ENV === "development" && env3.ABSOLUTE_HTTPS === "true";
205648
+ var protocol = isHttpsDev ? "https" : "http";
205649
+ var showBanner = () => {
205474
205650
  const isHotReload = Boolean(globalThis.__hmrServerStartup);
205475
205651
  globalThis.__hmrServerStartup = true;
205476
- if (isHotReload) {
205652
+ if (isHotReload)
205477
205653
  return;
205478
- }
205479
- const buildDuration = globalThis.__hmrBuildDuration ?? Number(env3.ABSOLUTE_BUILD_DURATION || 0);
205480
- const version = globalThis.__absoluteVersion || env3.ABSOLUTE_VERSION || "";
205481
205654
  startupBanner({
205482
- duration: buildDuration,
205655
+ duration: globalThis.__hmrBuildDuration ?? Number(env3.ABSOLUTE_BUILD_DURATION || 0),
205483
205656
  host,
205484
205657
  networkUrl: hostFlag ? `${protocol}://${localIP}:${port}/` : undefined,
205485
205658
  port,
205486
205659
  protocol,
205487
- version
205660
+ version: globalThis.__absoluteVersion || env3.ABSOLUTE_VERSION || ""
205488
205661
  });
205489
- });
205662
+ };
205663
+ var networking = (app) => {
205664
+ if (isHttpsDev) {
205665
+ const certDir = join18(process.cwd(), ".absolutejs");
205666
+ const cert = readFileSync12(join18(certDir, "cert.pem"), "utf-8");
205667
+ const key = readFileSync12(join18(certDir, "key.pem"), "utf-8");
205668
+ app.compile();
205669
+ const http2 = __require("http2");
205670
+ const server2 = http2.createSecureServer({
205671
+ cert,
205672
+ key,
205673
+ settings: { enableConnectProtocol: true }
205674
+ });
205675
+ server2.on("session", (session) => {
205676
+ session.settings({ enableConnectProtocol: true });
205677
+ });
205678
+ const { bridgeHttp2Stream: bridgeHttp2Stream2 } = (init_http2Bridge(), __toCommonJS(exports_http2Bridge));
205679
+ const http2Config = globalThis.__http2Config;
205680
+ server2.on("stream", (stream, headers) => {
205681
+ bridgeHttp2Stream2(stream, headers, app.fetch.bind(app), http2Config?.hmrState, http2Config?.manifest);
205682
+ });
205683
+ server2.listen(Number(port), () => {
205684
+ showBanner();
205685
+ });
205686
+ return app;
205687
+ }
205688
+ const tls = (() => {
205689
+ if (!isHttpsDev)
205690
+ return;
205691
+ try {
205692
+ const { loadDevCert: loadDevCert2 } = (init_devCert(), __toCommonJS(exports_devCert));
205693
+ return loadDevCert2();
205694
+ } catch {
205695
+ return;
205696
+ }
205697
+ })();
205698
+ return app.listen({
205699
+ hostname: host,
205700
+ port,
205701
+ ...tls ? { tls: { cert: tls.cert, key: tls.key } } : {}
205702
+ }, () => {
205703
+ showBanner();
205704
+ });
205705
+ };
205490
205706
  // src/utils/defineConfig.ts
205491
205707
  var defineConfig = (config) => config;
205492
205708
  // src/utils/generateHeadElement.ts
@@ -205586,5 +205802,5 @@ export {
205586
205802
  ANGULAR_INIT_TIMEOUT_MS
205587
205803
  };
205588
205804
 
205589
- //# debugId=6211C89438595FEE64756E2164756E21
205805
+ //# debugId=781BD03FD0AB276C64756E2164756E21
205590
205806
  //# sourceMappingURL=index.js.map