@absolutejs/absolute 0.19.0-beta.763 → 0.19.0-beta.764

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.
@@ -3460,9 +3460,76 @@ ${registrations}
3460
3460
  if (typeof hostSource === "string")
3461
3461
  return hostSource;
3462
3462
  return fs.readFile(fileName, "utf-8");
3463
+ }, safeStableStringify = (value) => {
3464
+ const seen = new WeakSet;
3465
+ return JSON.stringify(value, (_key, entry) => {
3466
+ if (typeof entry === "function")
3467
+ return `[Function:${entry.name}]`;
3468
+ if (!entry || typeof entry !== "object")
3469
+ return entry;
3470
+ if (seen.has(entry))
3471
+ return "[Circular]";
3472
+ seen.add(entry);
3473
+ if (Array.isArray(entry))
3474
+ return entry;
3475
+ return Object.fromEntries(Object.entries(entry).sort(([left], [right]) => left.localeCompare(right)));
3476
+ });
3477
+ }, collectAngularResourcePaths = (source, fileDir) => {
3478
+ const paths = [];
3479
+ const templateUrlMatch = findUncommentedMatch(source, /templateUrl\s*:\s*['"]([^'"]+)['"]/);
3480
+ if (templateUrlMatch?.[1])
3481
+ paths.push(join5(fileDir, templateUrlMatch[1]));
3482
+ const styleUrlMatch = findUncommentedMatch(source, /styleUrl\s*:\s*['"]([^'"]+)['"]/);
3483
+ if (styleUrlMatch?.[1])
3484
+ paths.push(join5(fileDir, styleUrlMatch[1]));
3485
+ const styleUrlsMatch = findUncommentedMatch(source, /styleUrls\s*:\s*\[([^\]]+)\]/);
3486
+ const urlMatches = styleUrlsMatch?.[1]?.match(/['"]([^'"]+)['"]/g);
3487
+ if (urlMatches) {
3488
+ for (const urlMatch of urlMatches) {
3489
+ paths.push(join5(fileDir, urlMatch.replace(/['"]/g, "")));
3490
+ }
3491
+ }
3492
+ return paths.map((path) => resolve6(path));
3493
+ }, readResourceCacheFile = async (cachePath) => {
3494
+ try {
3495
+ const entry = JSON.parse(await fs.readFile(cachePath, "utf-8"));
3496
+ if (entry.version !== 1 || typeof entry.source !== "string") {
3497
+ return null;
3498
+ }
3499
+ return entry;
3500
+ } catch {
3501
+ return null;
3502
+ }
3503
+ }, writeResourceCacheFile = async (cachePath, source) => {
3504
+ await fs.mkdir(dirname4(cachePath), { recursive: true });
3505
+ await fs.writeFile(cachePath, JSON.stringify({
3506
+ source,
3507
+ version: 1
3508
+ }), "utf-8");
3509
+ }, resolveResourceTransformCachePath = async (filePath, source, stylePreprocessors) => {
3510
+ const resourcePaths = collectAngularResourcePaths(source, dirname4(filePath));
3511
+ const resourceContents = await Promise.all(resourcePaths.map(async (resourcePath) => {
3512
+ const content = await fs.readFile(resourcePath, "utf-8");
3513
+ return `${resourcePath}\x00${content}`;
3514
+ }));
3515
+ const cacheInput = [
3516
+ "v1",
3517
+ filePath,
3518
+ source,
3519
+ ...resourceContents,
3520
+ safeStableStringify(stylePreprocessors ?? null)
3521
+ ].join("\x00");
3522
+ const cacheKey = Bun.hash(cacheInput).toString(BASE_36_RADIX);
3523
+ return join5(process.cwd(), ".absolutejs", "cache", "angular-resources", `${cacheKey}.json`);
3463
3524
  }, precomputeAotResourceTransforms = async (inputPaths, readFile2, stylePreprocessors) => {
3464
3525
  const transformedSources = new Map;
3465
3526
  const visited = new Set;
3527
+ const stats = {
3528
+ cacheHits: 0,
3529
+ cacheMisses: 0,
3530
+ filesVisited: 0,
3531
+ transformedFiles: 0
3532
+ };
3466
3533
  const transformFile = async (filePath) => {
3467
3534
  const resolvedPath = resolve6(filePath);
3468
3535
  if (visited.has(resolvedPath))
@@ -3470,10 +3537,23 @@ ${registrations}
3470
3537
  visited.add(resolvedPath);
3471
3538
  if (!existsSync5(resolvedPath) || resolvedPath.endsWith(".d.ts"))
3472
3539
  return;
3540
+ stats.filesVisited += 1;
3473
3541
  const source = await readFileForAotTransform(resolvedPath, readFile2);
3474
- const transformed = await inlineResources(source, dirname4(resolvedPath), stylePreprocessors);
3475
- if (transformed.source !== source) {
3476
- transformedSources.set(resolvedPath, transformed.source);
3542
+ const cachePath = await resolveResourceTransformCachePath(resolvedPath, source, stylePreprocessors);
3543
+ const cached = await readResourceCacheFile(cachePath);
3544
+ let transformedSource;
3545
+ if (cached) {
3546
+ stats.cacheHits += 1;
3547
+ transformedSource = cached.source;
3548
+ } else {
3549
+ stats.cacheMisses += 1;
3550
+ const transformed = await inlineResources(source, dirname4(resolvedPath), stylePreprocessors);
3551
+ transformedSource = transformed.source;
3552
+ await writeResourceCacheFile(cachePath, transformedSource);
3553
+ }
3554
+ if (transformedSource !== source) {
3555
+ stats.transformedFiles += 1;
3556
+ transformedSources.set(resolvedPath, transformedSource);
3477
3557
  }
3478
3558
  const imports = extractLocalImportSpecifiers(source, resolvedPath);
3479
3559
  await Promise.all(imports.map(async (specifier) => {
@@ -3483,7 +3563,7 @@ ${registrations}
3483
3563
  }));
3484
3564
  };
3485
3565
  await Promise.all(inputPaths.map((inputPath) => transformFile(inputPath)));
3486
- return transformedSources;
3566
+ return { stats, transformedSources };
3487
3567
  }, compileAngularFiles = async (inputPaths, outDir, stylePreprocessors) => {
3488
3568
  const islandMetadataByOutputPath = await traceAngularPhase("aot/island-metadata", () => new Map(inputPaths.map((inputPath) => {
3489
3569
  const outputPath = resolve6(join5(outDir, relative3(process.cwd(), resolve6(inputPath)).replace(/\.[cm]?[tj]sx?$/, ".js")));
@@ -3544,7 +3624,15 @@ ${registrations}
3544
3624
  emitted[relativePath] = text;
3545
3625
  };
3546
3626
  const originalReadFile = host.readFile;
3547
- const aotTransformedSources = await traceAngularPhase("aot/precompute-resources", () => precomputeAotResourceTransforms(inputPaths, originalReadFile?.bind(host), stylePreprocessors), { entries: inputPaths.length });
3627
+ const { stats: aotResourceTransformStats, transformedSources } = await traceAngularPhase("aot/precompute-resources", () => precomputeAotResourceTransforms(inputPaths, originalReadFile?.bind(host), stylePreprocessors), { entries: inputPaths.length });
3628
+ await traceAngularPhase("aot/resource-cache-summary", () => {
3629
+ return;
3630
+ }, {
3631
+ cacheHits: aotResourceTransformStats.cacheHits,
3632
+ cacheMisses: aotResourceTransformStats.cacheMisses,
3633
+ filesVisited: aotResourceTransformStats.filesVisited,
3634
+ transformedFiles: aotResourceTransformStats.transformedFiles
3635
+ });
3548
3636
  host.readFile = (fileName) => {
3549
3637
  const source = originalReadFile ? originalReadFile.call(host, fileName) : undefined;
3550
3638
  if (typeof source !== "string")
@@ -3553,11 +3641,11 @@ ${registrations}
3553
3641
  return source;
3554
3642
  }
3555
3643
  const resolvedPath = resolve6(fileName);
3556
- return aotTransformedSources.get(resolvedPath) ?? source;
3644
+ return transformedSources.get(resolvedPath) ?? source;
3557
3645
  };
3558
3646
  const originalGetSourceFileForCompile = host.getSourceFile;
3559
3647
  host.getSourceFile = (fileName, languageVersion, onError) => {
3560
- const source = aotTransformedSources.get(resolve6(fileName));
3648
+ const source = transformedSources.get(resolve6(fileName));
3561
3649
  if (source) {
3562
3650
  return ts.createSourceFile(fileName, source, languageVersion, true);
3563
3651
  }
@@ -5491,5 +5579,5 @@ export {
5491
5579
  ABSOLUTE_HTTP_TRANSFER_CACHE_SKIP_HEADER
5492
5580
  };
5493
5581
 
5494
- //# debugId=F5CA23B4C3E68C1364756E2164756E21
5582
+ //# debugId=5503040E3F1992BE64756E2164756E21
5495
5583
  //# sourceMappingURL=server.js.map