@absolutejs/absolute 0.19.0-beta.762 → 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,9 +3537,24 @@ ${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
- 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);
3557
+ }
3476
3558
  const imports = extractLocalImportSpecifiers(source, resolvedPath);
3477
3559
  await Promise.all(imports.map(async (specifier) => {
3478
3560
  const resolvedImport = resolveLocalTsImport(resolvedPath, specifier);
@@ -3481,7 +3563,7 @@ ${registrations}
3481
3563
  }));
3482
3564
  };
3483
3565
  await Promise.all(inputPaths.map((inputPath) => transformFile(inputPath)));
3484
- return transformedSources;
3566
+ return { stats, transformedSources };
3485
3567
  }, compileAngularFiles = async (inputPaths, outDir, stylePreprocessors) => {
3486
3568
  const islandMetadataByOutputPath = await traceAngularPhase("aot/island-metadata", () => new Map(inputPaths.map((inputPath) => {
3487
3569
  const outputPath = resolve6(join5(outDir, relative3(process.cwd(), resolve6(inputPath)).replace(/\.[cm]?[tj]sx?$/, ".js")));
@@ -3542,7 +3624,15 @@ ${registrations}
3542
3624
  emitted[relativePath] = text;
3543
3625
  };
3544
3626
  const originalReadFile = host.readFile;
3545
- 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
+ });
3546
3636
  host.readFile = (fileName) => {
3547
3637
  const source = originalReadFile ? originalReadFile.call(host, fileName) : undefined;
3548
3638
  if (typeof source !== "string")
@@ -3551,12 +3641,12 @@ ${registrations}
3551
3641
  return source;
3552
3642
  }
3553
3643
  const resolvedPath = resolve6(fileName);
3554
- return aotTransformedSources.get(resolvedPath) ?? source;
3644
+ return transformedSources.get(resolvedPath) ?? source;
3555
3645
  };
3556
3646
  const originalGetSourceFileForCompile = host.getSourceFile;
3557
3647
  host.getSourceFile = (fileName, languageVersion, onError) => {
3558
- const source = host.readFile(fileName);
3559
- if (typeof source === "string") {
3648
+ const source = transformedSources.get(resolve6(fileName));
3649
+ if (source) {
3560
3650
  return ts.createSourceFile(fileName, source, languageVersion, true);
3561
3651
  }
3562
3652
  return originalGetSourceFileForCompile?.call(host, fileName, languageVersion, onError);
@@ -14813,5 +14903,5 @@ export {
14813
14903
  ABSOLUTE_HTTP_TRANSFER_CACHE_SKIP_HEADER
14814
14904
  };
14815
14905
 
14816
- //# debugId=AC0168E0665445E964756E2164756E21
14906
+ //# debugId=05ED230334EA990B64756E2164756E21
14817
14907
  //# sourceMappingURL=index.js.map