@absolutejs/absolute 0.19.0-beta.123 → 0.19.0-beta.125

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/index.js CHANGED
@@ -171299,6 +171299,28 @@ var isDev, extractBuildError = (logs, pass, label, frameworkNames, isIncremental
171299
171299
  globalThis.__absoluteVersion = pkg.version;
171300
171300
  return;
171301
171301
  }
171302
+ }, scanWorkerReferences = async (dirs) => {
171303
+ const urlPattern = /new\s+URL\(\s*["'](\.\.?\/[^"']+)["']\s*,\s*import\.meta\.url\s*\)/g;
171304
+ const resolvePattern = /import\.meta\.resolve\(\s*["'](\.\.?\/[^"']+)["']\s*\)/g;
171305
+ const workerPaths = new Set;
171306
+ for (const dir of dirs) {
171307
+ const glob = new Glob5("**/*.{ts,tsx,js,jsx}");
171308
+ for await (const file4 of glob.scan({ absolute: true, cwd: dir })) {
171309
+ const content = readFileSync5(file4, "utf-8");
171310
+ for (const pattern of [urlPattern, resolvePattern]) {
171311
+ pattern.lastIndex = 0;
171312
+ let match;
171313
+ while ((match = pattern.exec(content)) !== null) {
171314
+ const relPath = match[1];
171315
+ if (!relPath)
171316
+ continue;
171317
+ const absPath = resolve11(file4, "..", relPath);
171318
+ workerPaths.add(absPath);
171319
+ }
171320
+ }
171321
+ }
171322
+ }
171323
+ return [...workerPaths];
171302
171324
  }, vueFeatureFlags, build2 = async ({
171303
171325
  buildDirectory = "build",
171304
171326
  assetsDirectory,
@@ -171711,6 +171733,68 @@ var isDev, extractBuildError = (logs, pass, label, frameworkNames, isIncremental
171711
171733
  if (vueCssResult && !vueCssResult.success && vueCssResult.logs.length > 0) {
171712
171734
  extractBuildError(vueCssResult.logs, "vue-css", "Vue CSS", frameworkNames, isIncremental, throwOnError);
171713
171735
  }
171736
+ const frameworkDirs = [
171737
+ reactDir,
171738
+ svelteDir,
171739
+ vueDir,
171740
+ angularDir,
171741
+ htmlDir,
171742
+ htmxDir
171743
+ ].filter((d) => Boolean(d));
171744
+ const workerEntryPoints = await scanWorkerReferences(frameworkDirs);
171745
+ let workerOutputs = [];
171746
+ if (workerEntryPoints.length > 0) {
171747
+ const workerResult = await bunBuild6({
171748
+ entrypoints: workerEntryPoints,
171749
+ format: "esm",
171750
+ minify: !isDev,
171751
+ naming: "[dir]/[name].[hash].[ext]",
171752
+ outdir: buildPath,
171753
+ root: commonAncestor(workerEntryPoints),
171754
+ target: "browser",
171755
+ throw: false
171756
+ });
171757
+ if (workerResult.success) {
171758
+ workerOutputs = workerResult.outputs;
171759
+ const workerUrlMap = new Map;
171760
+ for (const artifact of workerOutputs) {
171761
+ for (const ep of workerEntryPoints) {
171762
+ const epBase = basename5(ep).replace(/\.[^.]+$/, "");
171763
+ if (basename5(artifact.path).startsWith(epBase)) {
171764
+ workerUrlMap.set(ep, "/" + relative7(buildPath, artifact.path));
171765
+ }
171766
+ }
171767
+ }
171768
+ const allClientOutputPaths = [
171769
+ ...reactClientOutputPaths,
171770
+ ...nonReactClientOutputs.map((a) => a.path)
171771
+ ];
171772
+ for (const outputPath of allClientOutputPaths) {
171773
+ let content = readFileSync5(outputPath, "utf-8");
171774
+ let changed = false;
171775
+ for (const [srcPath, hashedPath] of workerUrlMap) {
171776
+ const srcRelPatterns = [
171777
+ "./" + relative7(buildPath, srcPath),
171778
+ "../" + relative7(buildPath, srcPath),
171779
+ relative7(buildPath, srcPath)
171780
+ ];
171781
+ for (const pattern of srcRelPatterns) {
171782
+ if (content.includes(pattern)) {
171783
+ content = content.replaceAll(pattern, hashedPath);
171784
+ changed = true;
171785
+ }
171786
+ }
171787
+ }
171788
+ if (changed)
171789
+ writeFileSync3(outputPath, content);
171790
+ }
171791
+ } else {
171792
+ const workerLogs = workerResult.logs;
171793
+ if (workerLogs.length > 0) {
171794
+ extractBuildError(workerLogs, "worker", "Worker", frameworkNames, isIncremental, throwOnError);
171795
+ }
171796
+ }
171797
+ }
171714
171798
  const allLogs = [
171715
171799
  ...serverLogs,
171716
171800
  ...reactClientLogs,
@@ -171724,7 +171808,8 @@ var isDev, extractBuildError = (logs, pass, label, frameworkNames, isIncremental
171724
171808
  ...serverOutputs,
171725
171809
  ...reactClientOutputs,
171726
171810
  ...nonReactClientOutputs,
171727
- ...cssOutputs
171811
+ ...cssOutputs,
171812
+ ...workerOutputs
171728
171813
  ], buildPath)
171729
171814
  };
171730
171815
  for (const artifact of serverOutputs) {
@@ -202553,6 +202638,16 @@ ${stubs}
202553
202638
  }
202554
202639
  return _match;
202555
202640
  });
202641
+ result = result.replace(/new\s+URL\(\s*["'](\.\.?\/[^"']+)["']\s*,\s*import\.meta\.url\s*\)/g, (_match, relPath) => {
202642
+ const absPath = resolve18(fileDir, relPath);
202643
+ const rel = relative8(projectRoot, absPath);
202644
+ return `new URL('/${srcUrl(rel, projectRoot)}', import.meta.url)`;
202645
+ });
202646
+ result = result.replace(/import\.meta\.resolve\(\s*["'](\.\.?\/[^"']+)["']\s*\)/g, (_match, relPath) => {
202647
+ const absPath = resolve18(fileDir, relPath);
202648
+ const rel = relative8(projectRoot, absPath);
202649
+ return `'${srcUrl(rel, projectRoot)}'`;
202650
+ });
202556
202651
  return result;
202557
202652
  }, HOOK_NAMES, REFRESH_PREAMBLE, JSX_AUTO_RE, JSXS_AUTO_RE, JSX_PROD_RE, FRAGMENT_RE, addJsxImport = (code) => {
202558
202653
  const imports = [];
@@ -205047,188 +205142,6 @@ var init_hmr = __esm(() => {
205047
205142
  init_webSocket();
205048
205143
  });
205049
205144
 
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
-
205232
205145
  // src/dev/devCert.ts
205233
205146
  var exports_devCert = {};
205234
205147
  __export(exports_devCert, {
@@ -205612,8 +205525,6 @@ var pageRouterPlugin = () => {
205612
205525
  };
205613
205526
  // src/plugins/networking.ts
205614
205527
  init_constants();
205615
- import { readFileSync as readFileSync12 } from "fs";
205616
- import { join as join18 } from "path";
205617
205528
  import { argv } from "process";
205618
205529
  var {env: env3 } = globalThis.Bun;
205619
205530
 
@@ -205646,65 +205557,45 @@ if (hostFlag) {
205646
205557
  localIP = getLocalIPAddress();
205647
205558
  host = "0.0.0.0";
205648
205559
  }
205649
- var isHttpsDev = env3.NODE_ENV === "development" && env3.ABSOLUTE_HTTPS === "true";
205650
- var protocol = isHttpsDev ? "https" : "http";
205651
- var showBanner = () => {
205560
+ var tls = (() => {
205561
+ if (env3.NODE_ENV !== "development")
205562
+ return;
205563
+ if (env3.ABSOLUTE_HTTPS !== "true")
205564
+ return;
205565
+ try {
205566
+ const { loadDevCert: loadDevCert2 } = (init_devCert(), __toCommonJS(exports_devCert));
205567
+ return loadDevCert2();
205568
+ } catch {
205569
+ return;
205570
+ }
205571
+ })();
205572
+ var protocol = tls ? "https" : "http";
205573
+ var networking = (app) => app.listen({
205574
+ hostname: host,
205575
+ port,
205576
+ ...tls ? {
205577
+ tls: {
205578
+ cert: tls.cert,
205579
+ key: tls.key
205580
+ }
205581
+ } : {}
205582
+ }, () => {
205652
205583
  const isHotReload = Boolean(globalThis.__hmrServerStartup);
205653
205584
  globalThis.__hmrServerStartup = true;
205654
- if (isHotReload)
205585
+ if (isHotReload) {
205655
205586
  return;
205587
+ }
205588
+ const buildDuration = globalThis.__hmrBuildDuration ?? Number(env3.ABSOLUTE_BUILD_DURATION || 0);
205589
+ const version = globalThis.__absoluteVersion || env3.ABSOLUTE_VERSION || "";
205656
205590
  startupBanner({
205657
- duration: globalThis.__hmrBuildDuration ?? Number(env3.ABSOLUTE_BUILD_DURATION || 0),
205591
+ duration: buildDuration,
205658
205592
  host,
205659
205593
  networkUrl: hostFlag ? `${protocol}://${localIP}:${port}/` : undefined,
205660
205594
  port,
205661
205595
  protocol,
205662
- version: globalThis.__absoluteVersion || env3.ABSOLUTE_VERSION || ""
205663
- });
205664
- };
205665
- var networking = (app) => {
205666
- if (isHttpsDev) {
205667
- const certDir = join18(process.cwd(), ".absolutejs");
205668
- const cert = readFileSync12(join18(certDir, "cert.pem"), "utf-8");
205669
- const key = readFileSync12(join18(certDir, "key.pem"), "utf-8");
205670
- app.compile();
205671
- const http2 = __require("http2");
205672
- const server2 = http2.createSecureServer({
205673
- cert,
205674
- key,
205675
- settings: { enableConnectProtocol: true }
205676
- });
205677
- server2.on("session", (session) => {
205678
- session.settings({ enableConnectProtocol: true });
205679
- });
205680
- const { bridgeHttp2Stream: bridgeHttp2Stream2 } = (init_http2Bridge(), __toCommonJS(exports_http2Bridge));
205681
- const http2Config = globalThis.__http2Config;
205682
- server2.on("stream", (stream, headers) => {
205683
- bridgeHttp2Stream2(stream, headers, app.fetch.bind(app), http2Config?.hmrState, http2Config?.manifest);
205684
- });
205685
- server2.listen(Number(port), () => {
205686
- showBanner();
205687
- });
205688
- return app;
205689
- }
205690
- const tls = (() => {
205691
- if (!isHttpsDev)
205692
- return;
205693
- try {
205694
- const { loadDevCert: loadDevCert2 } = (init_devCert(), __toCommonJS(exports_devCert));
205695
- return loadDevCert2();
205696
- } catch {
205697
- return;
205698
- }
205699
- })();
205700
- return app.listen({
205701
- hostname: host,
205702
- port,
205703
- ...tls ? { tls: { cert: tls.cert, key: tls.key } } : {}
205704
- }, () => {
205705
- showBanner();
205596
+ version
205706
205597
  });
205707
- };
205598
+ });
205708
205599
  // src/utils/defineConfig.ts
205709
205600
  var defineConfig = (config) => config;
205710
205601
  // src/utils/generateHeadElement.ts
@@ -205804,5 +205695,5 @@ export {
205804
205695
  ANGULAR_INIT_TIMEOUT_MS
205805
205696
  };
205806
205697
 
205807
- //# debugId=2C01AC5C57FE055564756E2164756E21
205698
+ //# debugId=FAEDECCCFD8E76FD64756E2164756E21
205808
205699
  //# sourceMappingURL=index.js.map