@absolutejs/absolute 0.19.0-beta.777 → 0.19.0-beta.778

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
@@ -893,6 +893,7 @@ import {
893
893
  readdirSync as readdirSync2,
894
894
  readFileSync as readFileSync9,
895
895
  rmSync as rmSync2,
896
+ statSync,
896
897
  unlinkSync as unlinkSync2,
897
898
  writeFileSync as writeFileSync3
898
899
  } from "fs";
@@ -1024,6 +1025,16 @@ var cliTag4 = (color, message) => `\x1B[2m${formatTimestamp()}\x1B[0m ${color}[c
1024
1025
  for (const specifier of roots) {
1025
1026
  copyPackageToBuild(specifier, outdir, seen);
1026
1027
  }
1028
+ }, copyFrameworkRuntimePackages = (buildConfig, outdir) => {
1029
+ const seen = new Set;
1030
+ if (buildConfig.svelteDirectory) {
1031
+ copyPackageToBuild("svelte", outdir, seen);
1032
+ }
1033
+ if (buildConfig.vueDirectory) {
1034
+ copyPackageToBuild("vue", outdir, seen);
1035
+ copyPackageToBuild("@vue/server-renderer", outdir, seen);
1036
+ }
1037
+ copyAngularRuntimePackages(buildConfig, outdir);
1027
1038
  }, collectRuntimePackageSpecifiers = (distDir) => {
1028
1039
  const nodeModulesDir = join6(distDir, "node_modules");
1029
1040
  if (!existsSync9(nodeModulesDir))
@@ -1046,9 +1057,21 @@ var cliTag4 = (color, message) => `\x1B[2m${formatTimestamp()}\x1B[0m ${color}[c
1046
1057
  specifiers.push(entry.name);
1047
1058
  }
1048
1059
  return specifiers.sort((a, b) => b.length - a.length);
1049
- }, escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), ensureRelativeModuleSpecifier = (fromFile, toFile) => {
1060
+ }, ensureRelativeModuleSpecifier = (fromFile, toFile) => {
1050
1061
  const rel = relative(dirname2(fromFile), toFile).replace(/\\/g, "/");
1051
1062
  return rel.startsWith(".") ? rel : `./${rel}`;
1063
+ }, pickExportEntry = (value) => {
1064
+ if (typeof value === "string")
1065
+ return value;
1066
+ if (!value || typeof value !== "object")
1067
+ return;
1068
+ const record = value;
1069
+ for (const key of ["bun", "node", "import", "module", "default"]) {
1070
+ const entry = pickExportEntry(record[key]);
1071
+ if (entry)
1072
+ return entry;
1073
+ }
1074
+ return;
1052
1075
  }, resolvePackageEntryFile = (distDir, packageSpecifiers, specifier) => {
1053
1076
  const packageSpecifier = packageSpecifiers.find((root) => specifier === root || specifier.startsWith(`${root}/`));
1054
1077
  if (!packageSpecifier)
@@ -1063,26 +1086,78 @@ var cliTag4 = (color, message) => `\x1B[2m${formatTimestamp()}\x1B[0m ${color}[c
1063
1086
  const pkg = JSON.parse(readFileSync9(packageJsonPath, "utf-8"));
1064
1087
  const exportKey = resolvedPackageDir === subPackageDir ? "." : subpath ? `.${subpath}` : ".";
1065
1088
  const rootExport = pkg.exports?.[exportKey];
1066
- const entry = (typeof rootExport === "string" ? rootExport : rootExport?.default) ?? (resolvedPackageDir === subPackageDir || !subpath ? pkg.module ?? pkg.main ?? "index.js" : `.${subpath}`);
1089
+ const entry = pickExportEntry(rootExport) ?? (resolvedPackageDir === subPackageDir || !subpath ? pkg.module ?? pkg.main ?? "index.js" : `.${subpath}`);
1067
1090
  return join6(resolvedPackageDir, entry);
1068
- }, rewriteRuntimeModuleSpecifiers = (distDir) => {
1091
+ }, RUNTIME_JS_EXTENSIONS, MODULE_SPECIFIER_RE, isRuntimeJsFile = (filePath) => RUNTIME_JS_EXTENSIONS.some((extension) => filePath.endsWith(extension)), isNodeModulesPath = (filePath) => filePath.split(/[\\/]/).includes("node_modules"), isFile = (filePath) => {
1092
+ try {
1093
+ return statSync(filePath).isFile();
1094
+ } catch {
1095
+ return false;
1096
+ }
1097
+ }, resolveRuntimeJsFile = (candidate) => {
1098
+ if (!candidate)
1099
+ return null;
1100
+ const candidates = [
1101
+ candidate,
1102
+ ...RUNTIME_JS_EXTENSIONS.map((extension) => `${candidate}${extension}`),
1103
+ ...RUNTIME_JS_EXTENSIONS.map((extension) => join6(candidate, `index${extension}`))
1104
+ ];
1105
+ return candidates.find((filePath) => isRuntimeJsFile(filePath) && isFile(filePath)) ?? null;
1106
+ }, findContainingRuntimePackageDir = (filePath) => {
1107
+ let dir = dirname2(filePath);
1108
+ while (dir !== dirname2(dir)) {
1109
+ if (isNodeModulesPath(dir) && existsSync9(join6(dir, "package.json"))) {
1110
+ return dir;
1111
+ }
1112
+ dir = dirname2(dir);
1113
+ }
1114
+ return null;
1115
+ }, resolvePackageImportEntryFile = (fromFile, specifier) => {
1116
+ if (!specifier.startsWith("#"))
1117
+ return null;
1118
+ const packageDir = findContainingRuntimePackageDir(fromFile);
1119
+ if (!packageDir)
1120
+ return null;
1121
+ const pkg = tryReadNodePackageJson(packageDir);
1122
+ const entry = pickExportEntry(pkg?.imports?.[specifier]);
1123
+ if (!entry)
1124
+ return null;
1125
+ return join6(packageDir, entry);
1126
+ }, collectRuntimeRewriteRoots = (distDir) => collectFiles2(distDir).filter((filePath) => isRuntimeJsFile(filePath) && !isNodeModulesPath(filePath)), rewriteRuntimeModuleSpecifiers = (distDir) => {
1069
1127
  const packageSpecifiers = collectRuntimePackageSpecifiers(distDir);
1070
1128
  if (packageSpecifiers.length === 0)
1071
1129
  return;
1072
- for (const filePath of collectFiles2(distDir)) {
1073
- if (!/\.(cjs|js|mjs)$/.test(filePath))
1130
+ const pending = collectRuntimeRewriteRoots(distDir);
1131
+ const seen = new Set;
1132
+ const enqueue = (filePath) => {
1133
+ if (!filePath || seen.has(filePath) || !isRuntimeJsFile(filePath))
1134
+ return;
1135
+ if (!isFile(filePath))
1136
+ return;
1137
+ pending.push(filePath);
1138
+ };
1139
+ for (let index = 0;index < pending.length; index += 1) {
1140
+ const filePath = pending[index];
1141
+ if (!filePath || seen.has(filePath))
1074
1142
  continue;
1143
+ seen.add(filePath);
1075
1144
  const source = readFileSync9(filePath, "utf-8");
1076
- let rewritten = source;
1077
- for (const specifier of packageSpecifiers) {
1078
- const pattern = new RegExp(`(from\\s*|import\\s*|import\\(\\s*|require\\(\\s*)(["'])(${escapeRegExp(specifier)}(?:/[^"']+)?)\\2`, "g");
1079
- rewritten = rewritten.replace(pattern, (match, prefix, quote, fullSpecifier) => {
1080
- const target = resolvePackageEntryFile(distDir, packageSpecifiers, fullSpecifier);
1081
- if (!target)
1082
- return match;
1083
- return `${prefix}${quote}${ensureRelativeModuleSpecifier(filePath, target)}${quote}`;
1084
- });
1085
- }
1145
+ const rewritten = source.replace(MODULE_SPECIFIER_RE, (match, prefix, quote, specifier) => {
1146
+ if (typeof specifier === "string" && specifier.startsWith(".")) {
1147
+ enqueue(resolveRuntimeJsFile(resolve8(dirname2(filePath), specifier)));
1148
+ return match;
1149
+ }
1150
+ const packageImportTarget = resolveRuntimeJsFile(resolvePackageImportEntryFile(filePath, specifier) ?? "");
1151
+ if (packageImportTarget) {
1152
+ enqueue(packageImportTarget);
1153
+ return `${prefix}${quote}${ensureRelativeModuleSpecifier(filePath, packageImportTarget)}${quote}`;
1154
+ }
1155
+ const target = resolveRuntimeJsFile(resolvePackageEntryFile(distDir, packageSpecifiers, specifier) ?? "");
1156
+ if (!target)
1157
+ return match;
1158
+ enqueue(target);
1159
+ return `${prefix}${quote}${ensureRelativeModuleSpecifier(filePath, target)}${quote}`;
1160
+ });
1086
1161
  if (rewritten !== source) {
1087
1162
  writeFileSync3(filePath, rewritten);
1088
1163
  }
@@ -1525,7 +1600,7 @@ console.log(\`
1525
1600
  });
1526
1601
  const prerenderMap = prerenderResult.routes;
1527
1602
  console.log(` \x1B[2m(${prerenderMap.size} pages, ${getDurationString(performance.now() - prerenderStart)})\x1B[0m`);
1528
- copyAngularRuntimePackages(buildConfig, resolvedOutdir);
1603
+ copyFrameworkRuntimePackages(buildConfig, resolvedOutdir);
1529
1604
  rewriteRuntimeModuleSpecifiers(resolvedOutdir);
1530
1605
  const compileStart = performance.now();
1531
1606
  process.stdout.write(cliTag4("\x1B[36m", "Compiling standalone executable"));
@@ -1575,6 +1650,8 @@ var init_compile = __esm(() => {
1575
1650
  init_telemetryEvent();
1576
1651
  init_utils();
1577
1652
  jsxDevRuntimeCompatPath2 = resolveJsxDevRuntimeCompatPath2();
1653
+ RUNTIME_JS_EXTENSIONS = [".js", ".mjs", ".cjs"];
1654
+ MODULE_SPECIFIER_RE = /(from\s*|import\s*|import\(\s*|require\(\s*)(["'])([^"']+)\2/g;
1578
1655
  FRAMEWORK_EXTERNALS = [
1579
1656
  "react",
1580
1657
  "react/jsx-runtime",
@@ -3508,6 +3508,26 @@ var buildDirtyResponse = (indexPath, props) => {
3508
3508
  headers: { "Content-Type": "text/html" }
3509
3509
  });
3510
3510
  };
3511
+ var primeSvelteStream = async (stream) => {
3512
+ const reader = stream.getReader();
3513
+ const firstChunk = await reader.read();
3514
+ return { firstChunk, reader };
3515
+ };
3516
+ var restorePrimedStream = (firstChunk, reader) => new ReadableStream({
3517
+ start(controller) {
3518
+ if (!firstChunk.done) {
3519
+ controller.enqueue(firstChunk.value);
3520
+ }
3521
+ if (firstChunk.done) {
3522
+ controller.close();
3523
+ return;
3524
+ }
3525
+ const pumpLoop = () => {
3526
+ reader.read().then(({ done, value }) => done ? controller.close() : (controller.enqueue(value), pumpLoop())).catch((err) => controller.error(err));
3527
+ };
3528
+ pumpLoop();
3529
+ }
3530
+ });
3511
3531
  var handleSveltePageRequest = async (input) => {
3512
3532
  const resolvedIndexPath = input.indexPath;
3513
3533
  const resolvedOptions = input;
@@ -3555,11 +3575,12 @@ var handleSveltePageRequest = async (input) => {
3555
3575
  const htmlStream = injectIslandPageContextStream(stream, {
3556
3576
  hasIslands: resolvedPage.hasIslands ? true : undefined
3557
3577
  });
3558
- return new Response(htmlStream, {
3578
+ const { firstChunk, reader } = await primeSvelteStream(htmlStream);
3579
+ return new Response(restorePrimedStream(firstChunk, reader), {
3559
3580
  headers: { "Content-Type": "text/html" }
3560
3581
  });
3561
3582
  };
3562
- return runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, {
3583
+ return await runWithStreamingSlotWarningScope(() => resolvedOptions?.collectStreamingSlots === true ? withRegisteredStreamingSlots(renderPageResponse, {
3563
3584
  ...resolvedOptions,
3564
3585
  runtimePlacement: resolvedOptions.runtimePlacement ?? "body"
3565
3586
  }) : renderPageResponse(), { handlerCallsite });
@@ -3716,5 +3737,5 @@ export {
3716
3737
  createTypedIsland
3717
3738
  };
3718
3739
 
3719
- //# debugId=D9B36B76CF286A5164756E2164756E21
3740
+ //# debugId=19C304DDFA29CDCA64756E2164756E21
3720
3741
  //# sourceMappingURL=index.js.map