@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.
package/dist/build.js CHANGED
@@ -43739,9 +43739,76 @@ ${registrations}
43739
43739
  if (typeof hostSource === "string")
43740
43740
  return hostSource;
43741
43741
  return fs2.readFile(fileName, "utf-8");
43742
+ }, safeStableStringify = (value2) => {
43743
+ const seen = new WeakSet;
43744
+ return JSON.stringify(value2, (_key, entry) => {
43745
+ if (typeof entry === "function")
43746
+ return `[Function:${entry.name}]`;
43747
+ if (!entry || typeof entry !== "object")
43748
+ return entry;
43749
+ if (seen.has(entry))
43750
+ return "[Circular]";
43751
+ seen.add(entry);
43752
+ if (Array.isArray(entry))
43753
+ return entry;
43754
+ return Object.fromEntries(Object.entries(entry).sort(([left], [right]) => left.localeCompare(right)));
43755
+ });
43756
+ }, collectAngularResourcePaths = (source, fileDir) => {
43757
+ const paths = [];
43758
+ const templateUrlMatch = findUncommentedMatch(source, /templateUrl\s*:\s*['"]([^'"]+)['"]/);
43759
+ if (templateUrlMatch?.[1])
43760
+ paths.push(join15(fileDir, templateUrlMatch[1]));
43761
+ const styleUrlMatch = findUncommentedMatch(source, /styleUrl\s*:\s*['"]([^'"]+)['"]/);
43762
+ if (styleUrlMatch?.[1])
43763
+ paths.push(join15(fileDir, styleUrlMatch[1]));
43764
+ const styleUrlsMatch = findUncommentedMatch(source, /styleUrls\s*:\s*\[([^\]]+)\]/);
43765
+ const urlMatches = styleUrlsMatch?.[1]?.match(/['"]([^'"]+)['"]/g);
43766
+ if (urlMatches) {
43767
+ for (const urlMatch of urlMatches) {
43768
+ paths.push(join15(fileDir, urlMatch.replace(/['"]/g, "")));
43769
+ }
43770
+ }
43771
+ return paths.map((path2) => resolve16(path2));
43772
+ }, readResourceCacheFile = async (cachePath) => {
43773
+ try {
43774
+ const entry = JSON.parse(await fs2.readFile(cachePath, "utf-8"));
43775
+ if (entry.version !== 1 || typeof entry.source !== "string") {
43776
+ return null;
43777
+ }
43778
+ return entry;
43779
+ } catch {
43780
+ return null;
43781
+ }
43782
+ }, writeResourceCacheFile = async (cachePath, source) => {
43783
+ await fs2.mkdir(dirname10(cachePath), { recursive: true });
43784
+ await fs2.writeFile(cachePath, JSON.stringify({
43785
+ source,
43786
+ version: 1
43787
+ }), "utf-8");
43788
+ }, resolveResourceTransformCachePath = async (filePath, source, stylePreprocessors) => {
43789
+ const resourcePaths = collectAngularResourcePaths(source, dirname10(filePath));
43790
+ const resourceContents = await Promise.all(resourcePaths.map(async (resourcePath) => {
43791
+ const content = await fs2.readFile(resourcePath, "utf-8");
43792
+ return `${resourcePath}\x00${content}`;
43793
+ }));
43794
+ const cacheInput = [
43795
+ "v1",
43796
+ filePath,
43797
+ source,
43798
+ ...resourceContents,
43799
+ safeStableStringify(stylePreprocessors ?? null)
43800
+ ].join("\x00");
43801
+ const cacheKey2 = Bun.hash(cacheInput).toString(BASE_36_RADIX);
43802
+ return join15(process.cwd(), ".absolutejs", "cache", "angular-resources", `${cacheKey2}.json`);
43742
43803
  }, precomputeAotResourceTransforms = async (inputPaths, readFile4, stylePreprocessors) => {
43743
43804
  const transformedSources = new Map;
43744
43805
  const visited = new Set;
43806
+ const stats = {
43807
+ cacheHits: 0,
43808
+ cacheMisses: 0,
43809
+ filesVisited: 0,
43810
+ transformedFiles: 0
43811
+ };
43745
43812
  const transformFile = async (filePath) => {
43746
43813
  const resolvedPath = resolve16(filePath);
43747
43814
  if (visited.has(resolvedPath))
@@ -43749,10 +43816,23 @@ ${registrations}
43749
43816
  visited.add(resolvedPath);
43750
43817
  if (!existsSync16(resolvedPath) || resolvedPath.endsWith(".d.ts"))
43751
43818
  return;
43819
+ stats.filesVisited += 1;
43752
43820
  const source = await readFileForAotTransform(resolvedPath, readFile4);
43753
- const transformed = await inlineResources(source, dirname10(resolvedPath), stylePreprocessors);
43754
- if (transformed.source !== source) {
43755
- transformedSources.set(resolvedPath, transformed.source);
43821
+ const cachePath = await resolveResourceTransformCachePath(resolvedPath, source, stylePreprocessors);
43822
+ const cached = await readResourceCacheFile(cachePath);
43823
+ let transformedSource;
43824
+ if (cached) {
43825
+ stats.cacheHits += 1;
43826
+ transformedSource = cached.source;
43827
+ } else {
43828
+ stats.cacheMisses += 1;
43829
+ const transformed = await inlineResources(source, dirname10(resolvedPath), stylePreprocessors);
43830
+ transformedSource = transformed.source;
43831
+ await writeResourceCacheFile(cachePath, transformedSource);
43832
+ }
43833
+ if (transformedSource !== source) {
43834
+ stats.transformedFiles += 1;
43835
+ transformedSources.set(resolvedPath, transformedSource);
43756
43836
  }
43757
43837
  const imports = extractLocalImportSpecifiers(source, resolvedPath);
43758
43838
  await Promise.all(imports.map(async (specifier) => {
@@ -43762,7 +43842,7 @@ ${registrations}
43762
43842
  }));
43763
43843
  };
43764
43844
  await Promise.all(inputPaths.map((inputPath) => transformFile(inputPath)));
43765
- return transformedSources;
43845
+ return { stats, transformedSources };
43766
43846
  }, compileAngularFiles = async (inputPaths, outDir, stylePreprocessors) => {
43767
43847
  const islandMetadataByOutputPath = await traceAngularPhase("aot/island-metadata", () => new Map(inputPaths.map((inputPath) => {
43768
43848
  const outputPath = resolve16(join15(outDir, relative9(process.cwd(), resolve16(inputPath)).replace(/\.[cm]?[tj]sx?$/, ".js")));
@@ -43823,7 +43903,15 @@ ${registrations}
43823
43903
  emitted[relativePath] = text;
43824
43904
  };
43825
43905
  const originalReadFile = host.readFile;
43826
- const aotTransformedSources = await traceAngularPhase("aot/precompute-resources", () => precomputeAotResourceTransforms(inputPaths, originalReadFile?.bind(host), stylePreprocessors), { entries: inputPaths.length });
43906
+ const { stats: aotResourceTransformStats, transformedSources } = await traceAngularPhase("aot/precompute-resources", () => precomputeAotResourceTransforms(inputPaths, originalReadFile?.bind(host), stylePreprocessors), { entries: inputPaths.length });
43907
+ await traceAngularPhase("aot/resource-cache-summary", () => {
43908
+ return;
43909
+ }, {
43910
+ cacheHits: aotResourceTransformStats.cacheHits,
43911
+ cacheMisses: aotResourceTransformStats.cacheMisses,
43912
+ filesVisited: aotResourceTransformStats.filesVisited,
43913
+ transformedFiles: aotResourceTransformStats.transformedFiles
43914
+ });
43827
43915
  host.readFile = (fileName) => {
43828
43916
  const source = originalReadFile ? originalReadFile.call(host, fileName) : undefined;
43829
43917
  if (typeof source !== "string")
@@ -43832,11 +43920,11 @@ ${registrations}
43832
43920
  return source;
43833
43921
  }
43834
43922
  const resolvedPath = resolve16(fileName);
43835
- return aotTransformedSources.get(resolvedPath) ?? source;
43923
+ return transformedSources.get(resolvedPath) ?? source;
43836
43924
  };
43837
43925
  const originalGetSourceFileForCompile = host.getSourceFile;
43838
43926
  host.getSourceFile = (fileName, languageVersion, onError2) => {
43839
- const source = aotTransformedSources.get(resolve16(fileName));
43927
+ const source = transformedSources.get(resolve16(fileName));
43840
43928
  if (source) {
43841
43929
  return ts2.createSourceFile(fileName, source, languageVersion, true);
43842
43930
  }
@@ -50215,5 +50303,5 @@ export {
50215
50303
  build
50216
50304
  };
50217
50305
 
50218
- //# debugId=ECE7852F36128E8064756E2164756E21
50306
+ //# debugId=F3728BAC03FD13D664756E2164756E21
50219
50307
  //# sourceMappingURL=build.js.map