@absolutejs/absolute 0.19.0-beta.702 → 0.19.0-beta.704

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
@@ -629,7 +629,7 @@ __export(exports_prerender, {
629
629
  });
630
630
  import { mkdirSync as mkdirSync3, readFileSync as readFileSync6 } from "fs";
631
631
  import { join as join5 } from "path";
632
- var MAX_STARTUP_ATTEMPTS = 50, STARTUP_POLL_INTERVAL_MS = 100, PRERENDER_BYPASS_HEADER = "X-Absolute-Prerender-Bypass", routeToFilename = (route) => route === "/" ? "index.html" : `${route.slice(1).replace(/\//g, "-")}.html`, writeTimestamp = async (htmlPath) => {
632
+ var SERVER_OUTPUT_LIMIT = 4000, STARTUP_POLL_INTERVAL_MS = 100, DEFAULT_STARTUP_TIMEOUT_MS = 30000, PRERENDER_BYPASS_HEADER = "X-Absolute-Prerender-Bypass", routeToFilename = (route) => route === "/" ? "index.html" : `${route.slice(1).replace(/\//g, "-")}.html`, writeTimestamp = async (htmlPath) => {
633
633
  const metaPath = htmlPath.replace(/\.html$/, ".meta");
634
634
  await Bun.write(metaPath, String(Date.now()));
635
635
  }, readTimestamp = (htmlPath) => {
@@ -727,25 +727,66 @@ var MAX_STARTUP_ATTEMPTS = 50, STARTUP_POLL_INTERVAL_MS = 100, PRERENDER_BYPASS_
727
727
  await prerenderRoute(baseUrl, route, prerenderDir, result, log);
728
728
  }
729
729
  return result;
730
+ }, getStartupTimeoutMs = () => {
731
+ const rawTimeout = Bun.env.ABSOLUTE_PRERENDER_STARTUP_TIMEOUT_MS;
732
+ const parsedTimeout = rawTimeout ? Number(rawTimeout) : NaN;
733
+ return Number.isFinite(parsedTimeout) && parsedTimeout > 0 ? parsedTimeout : DEFAULT_STARTUP_TIMEOUT_MS;
730
734
  }, waitForServerReady = async (port) => {
731
- for (let attempt = 0;attempt < MAX_STARTUP_ATTEMPTS; attempt++) {
735
+ const deadline = performance.now() + getStartupTimeoutMs();
736
+ while (performance.now() < deadline) {
732
737
  const res = await fetch(`http://localhost:${port}/`).catch(() => null);
733
- if (res?.ok)
738
+ if (res) {
739
+ await res.body?.cancel().catch(() => {
740
+ return;
741
+ });
734
742
  return true;
743
+ }
735
744
  await Bun.sleep(STARTUP_POLL_INTERVAL_MS);
736
745
  }
737
746
  return false;
747
+ }, captureStreamOutput = (stream, output) => {
748
+ if (!stream)
749
+ return;
750
+ const reader = stream.getReader();
751
+ const decoder = new TextDecoder;
752
+ const read = () => {
753
+ reader.read().then(({ done, value }) => {
754
+ if (done)
755
+ return;
756
+ output.push(decoder.decode(value, { stream: true }));
757
+ read();
758
+ }).catch(() => {});
759
+ };
760
+ read();
761
+ }, formatServerOutput = (output) => {
762
+ const text = output.join("").trim();
763
+ if (!text)
764
+ return "";
765
+ return text.length > SERVER_OUTPUT_LIMIT ? text.slice(-SERVER_OUTPUT_LIMIT) : text;
766
+ }, createServerStartupError = (output) => {
767
+ const serverOutput = formatServerOutput(output);
768
+ const message = serverOutput ? `Server failed to start for pre-rendering.
769
+
770
+ Server output:
771
+ ${serverOutput}` : "Server failed to start for pre-rendering";
772
+ return new Error(message);
738
773
  }, prerenderWithServer = async (serverBundlePath, port, outDir, staticConfig, env2, log) => {
774
+ const serverOutput = [];
739
775
  const serverProcess = Bun.spawn(["bun", "run", serverBundlePath], {
740
776
  cwd: process.cwd(),
741
777
  env: { ...process.env, ...env2, PORT: String(port) },
742
778
  stderr: "pipe",
743
779
  stdout: "pipe"
744
780
  });
781
+ captureStreamOutput(serverProcess.stdout, serverOutput);
782
+ captureStreamOutput(serverProcess.stderr, serverOutput);
745
783
  const ready = await waitForServerReady(port);
746
784
  if (!ready) {
747
785
  serverProcess.kill();
748
- throw new Error("Server failed to start for pre-rendering");
786
+ await serverProcess.exited.catch(() => {
787
+ return;
788
+ });
789
+ throw createServerStartupError(serverOutput);
749
790
  }
750
791
  const result = await prerender(port, outDir, staticConfig, log);
751
792
  serverProcess.kill();
@@ -762,7 +803,12 @@ __export(exports_compile, {
762
803
  var {env: env3 } = globalThis.Bun;
763
804
  import { existsSync as existsSync9, readdirSync as readdirSync2, readFileSync as readFileSync9, unlinkSync as unlinkSync2 } from "fs";
764
805
  import { basename as basename2, join as join6, relative, resolve as resolve7 } from "path";
765
- var cliTag3 = (color, message) => `\x1B[2m${formatTimestamp()}\x1B[0m ${color}[cli]\x1B[0m ${color}${message}\x1B[0m`, collectFiles2 = (dir) => {
806
+ var cliTag3 = (color, message) => `\x1B[2m${formatTimestamp()}\x1B[0m ${color}[cli]\x1B[0m ${color}${message}\x1B[0m`, compileBanner = (version2) => {
807
+ const resolvedVersion = version2 || "unknown";
808
+ console.log("");
809
+ console.log(` \x1B[36m\x1B[1mABSOLUTEJS\x1B[0m \x1B[2mv${resolvedVersion}\x1B[0m \x1B[2mcompile\x1B[0m`);
810
+ console.log("");
811
+ }, collectFiles2 = (dir) => {
766
812
  const result = [];
767
813
  let pending = readdirSync2(dir, { withFileTypes: true });
768
814
  while (pending.length > 0) {
@@ -951,6 +997,7 @@ console.log(\`
951
997
  resolve7(import.meta.dir, "..", "..", "..", "package.json"),
952
998
  resolve7(import.meta.dir, "..", "..", "package.json")
953
999
  ]);
1000
+ compileBanner(absoluteVersion);
954
1001
  const totalStart = performance.now();
955
1002
  const buildStart = performance.now();
956
1003
  process.stdout.write(cliTag3("\x1B[36m", "Building assets"));
package/dist/index.js CHANGED
@@ -2372,6 +2372,22 @@ var frameworks, isRecord4 = (value) => typeof value === "object" && value !== nu
2372
2372
  source
2373
2373
  });
2374
2374
  }
2375
+ }, isIslandRegistryHelperImport = (source) => source === "@absolutejs/absolute/islands" || source.endsWith("/islands") || source.endsWith("/core/islands"), collectRegistryHelperImports = (importClause, source, registryFactoryNames, registryNamespaceNames) => {
2376
+ if (!isIslandRegistryHelperImport(source))
2377
+ return;
2378
+ const bindings = importClause.namedBindings;
2379
+ if (!bindings)
2380
+ return;
2381
+ if (ts.isNamespaceImport(bindings)) {
2382
+ registryNamespaceNames.add(bindings.name.text);
2383
+ return;
2384
+ }
2385
+ for (const element of bindings.elements) {
2386
+ const importedName = element.propertyName?.text ?? element.name.text;
2387
+ if (importedName === "defineIslandRegistry") {
2388
+ registryFactoryNames.add(element.name.text);
2389
+ }
2390
+ }
2375
2391
  }, createRegistryEntryValue = (reference) => ({
2376
2392
  component: reference.source,
2377
2393
  export: reference.export,
@@ -2421,11 +2437,16 @@ var frameworks, isRecord4 = (value) => typeof value === "object" && value !== nu
2421
2437
  continue;
2422
2438
  addRegistryEntries(property.initializer, framework, imports, definitions, registry);
2423
2439
  }
2424
- }, walkRegistryNode = (node, imports, definitions, registry) => {
2425
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "defineIslandRegistry") {
2440
+ }, walkRegistryNode = (node, imports, registryFactoryNames, registryNamespaceNames, definitions, registry) => {
2441
+ if (ts.isCallExpression(node) && isDefineIslandRegistryCall(node.expression, registryFactoryNames, registryNamespaceNames)) {
2426
2442
  processDefineIslandRegistry(node, imports, definitions, registry);
2427
2443
  }
2428
- ts.forEachChild(node, (child) => walkRegistryNode(child, imports, definitions, registry));
2444
+ ts.forEachChild(node, (child) => walkRegistryNode(child, imports, registryFactoryNames, registryNamespaceNames, definitions, registry));
2445
+ }, isDefineIslandRegistryCall = (expression, registryFactoryNames, registryNamespaceNames) => {
2446
+ if (ts.isIdentifier(expression)) {
2447
+ return registryFactoryNames.has(expression.text);
2448
+ }
2449
+ return ts.isPropertyAccessExpression(expression) && expression.name.text === "defineIslandRegistry" && ts.isIdentifier(expression.expression) && registryNamespaceNames.has(expression.expression.text);
2429
2450
  }, hasIslandRegistryNamedExport = (sourceFile) => {
2430
2451
  for (const statement of sourceFile.statements) {
2431
2452
  if (ts.isVariableStatement(statement) && statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) && statement.declarationList.declarations.some((declaration) => ts.isIdentifier(declaration.name) && declaration.name.text === "islandRegistry")) {
@@ -2440,7 +2461,7 @@ var frameworks, isRecord4 = (value) => typeof value === "object" && value !== nu
2440
2461
  }
2441
2462
  }
2442
2463
  return false;
2443
- }, collectImportDeclarations = (sourceFile, registryPath, imports) => {
2464
+ }, collectImportDeclarations = (sourceFile, registryPath, imports, registryFactoryNames, registryNamespaceNames) => {
2444
2465
  for (const statement of sourceFile.statements) {
2445
2466
  if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
2446
2467
  continue;
@@ -2450,14 +2471,17 @@ var frameworks, isRecord4 = (value) => typeof value === "object" && value !== nu
2450
2471
  const source = resolveIslandSourcePath(registryPath, statement.moduleSpecifier.text);
2451
2472
  collectDefaultImport(imports, importClause, source);
2452
2473
  collectNamedImports(imports, importClause, source);
2474
+ collectRegistryHelperImports(importClause, statement.moduleSpecifier.text, registryFactoryNames, registryNamespaceNames);
2453
2475
  }
2454
2476
  }, parseIslandRegistryBuildInfo = (registrySource, registryPath) => {
2455
2477
  const sourceFile = ts.createSourceFile(registryPath, registrySource, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
2456
2478
  const imports = new Map;
2479
+ const registryFactoryNames = new Set(["defineIslandRegistry"]);
2480
+ const registryNamespaceNames = new Set;
2457
2481
  const definitions = [];
2458
2482
  const registry = {};
2459
- collectImportDeclarations(sourceFile, registryPath, imports);
2460
- walkRegistryNode(sourceFile, imports, definitions, registry);
2483
+ collectImportDeclarations(sourceFile, registryPath, imports, registryFactoryNames, registryNamespaceNames);
2484
+ walkRegistryNode(sourceFile, imports, registryFactoryNames, registryNamespaceNames, definitions, registry);
2461
2485
  return {
2462
2486
  definitions,
2463
2487
  hasNamedExport: hasIslandRegistryNamedExport(sourceFile),
@@ -50066,7 +50090,7 @@ __export(exports_prerender, {
50066
50090
  });
50067
50091
  import { mkdirSync as mkdirSync13, readFileSync as readFileSync16 } from "fs";
50068
50092
  import { join as join24 } from "path";
50069
- var MAX_STARTUP_ATTEMPTS = 50, STARTUP_POLL_INTERVAL_MS = 100, PRERENDER_BYPASS_HEADER = "X-Absolute-Prerender-Bypass", routeToFilename = (route) => route === "/" ? "index.html" : `${route.slice(1).replace(/\//g, "-")}.html`, writeTimestamp = async (htmlPath) => {
50093
+ var SERVER_OUTPUT_LIMIT = 4000, STARTUP_POLL_INTERVAL_MS = 100, DEFAULT_STARTUP_TIMEOUT_MS = 30000, PRERENDER_BYPASS_HEADER = "X-Absolute-Prerender-Bypass", routeToFilename = (route) => route === "/" ? "index.html" : `${route.slice(1).replace(/\//g, "-")}.html`, writeTimestamp = async (htmlPath) => {
50070
50094
  const metaPath = htmlPath.replace(/\.html$/, ".meta");
50071
50095
  await Bun.write(metaPath, String(Date.now()));
50072
50096
  }, readTimestamp = (htmlPath) => {
@@ -50164,25 +50188,66 @@ var MAX_STARTUP_ATTEMPTS = 50, STARTUP_POLL_INTERVAL_MS = 100, PRERENDER_BYPASS_
50164
50188
  await prerenderRoute(baseUrl, route, prerenderDir, result, log2);
50165
50189
  }
50166
50190
  return result;
50191
+ }, getStartupTimeoutMs = () => {
50192
+ const rawTimeout = Bun.env.ABSOLUTE_PRERENDER_STARTUP_TIMEOUT_MS;
50193
+ const parsedTimeout = rawTimeout ? Number(rawTimeout) : NaN;
50194
+ return Number.isFinite(parsedTimeout) && parsedTimeout > 0 ? parsedTimeout : DEFAULT_STARTUP_TIMEOUT_MS;
50167
50195
  }, waitForServerReady = async (port) => {
50168
- for (let attempt = 0;attempt < MAX_STARTUP_ATTEMPTS; attempt++) {
50196
+ const deadline = performance.now() + getStartupTimeoutMs();
50197
+ while (performance.now() < deadline) {
50169
50198
  const res = await fetch(`http://localhost:${port}/`).catch(() => null);
50170
- if (res?.ok)
50199
+ if (res) {
50200
+ await res.body?.cancel().catch(() => {
50201
+ return;
50202
+ });
50171
50203
  return true;
50204
+ }
50172
50205
  await Bun.sleep(STARTUP_POLL_INTERVAL_MS);
50173
50206
  }
50174
50207
  return false;
50208
+ }, captureStreamOutput = (stream, output) => {
50209
+ if (!stream)
50210
+ return;
50211
+ const reader = stream.getReader();
50212
+ const decoder2 = new TextDecoder;
50213
+ const read = () => {
50214
+ reader.read().then(({ done, value: value2 }) => {
50215
+ if (done)
50216
+ return;
50217
+ output.push(decoder2.decode(value2, { stream: true }));
50218
+ read();
50219
+ }).catch(() => {});
50220
+ };
50221
+ read();
50222
+ }, formatServerOutput = (output) => {
50223
+ const text = output.join("").trim();
50224
+ if (!text)
50225
+ return "";
50226
+ return text.length > SERVER_OUTPUT_LIMIT ? text.slice(-SERVER_OUTPUT_LIMIT) : text;
50227
+ }, createServerStartupError = (output) => {
50228
+ const serverOutput = formatServerOutput(output);
50229
+ const message = serverOutput ? `Server failed to start for pre-rendering.
50230
+
50231
+ Server output:
50232
+ ${serverOutput}` : "Server failed to start for pre-rendering";
50233
+ return new Error(message);
50175
50234
  }, prerenderWithServer = async (serverBundlePath, port, outDir, staticConfig, env4, log2) => {
50235
+ const serverOutput = [];
50176
50236
  const serverProcess = Bun.spawn(["bun", "run", serverBundlePath], {
50177
50237
  cwd: process.cwd(),
50178
50238
  env: { ...process.env, ...env4, PORT: String(port) },
50179
50239
  stderr: "pipe",
50180
50240
  stdout: "pipe"
50181
50241
  });
50242
+ captureStreamOutput(serverProcess.stdout, serverOutput);
50243
+ captureStreamOutput(serverProcess.stderr, serverOutput);
50182
50244
  const ready = await waitForServerReady(port);
50183
50245
  if (!ready) {
50184
50246
  serverProcess.kill();
50185
- throw new Error("Server failed to start for pre-rendering");
50247
+ await serverProcess.exited.catch(() => {
50248
+ return;
50249
+ });
50250
+ throw createServerStartupError(serverOutput);
50186
50251
  }
50187
50252
  const result = await prerender(port, outDir, staticConfig, log2);
50188
50253
  serverProcess.kill();
@@ -57868,5 +57933,5 @@ export {
57868
57933
  ANGULAR_INIT_TIMEOUT_MS
57869
57934
  };
57870
57935
 
57871
- //# debugId=B174A989DC85D95764756E2164756E21
57936
+ //# debugId=86E5E86ED2B2842E64756E2164756E21
57872
57937
  //# sourceMappingURL=index.js.map