@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/index.js CHANGED
@@ -43931,9 +43931,76 @@ ${registrations}
43931
43931
  if (typeof hostSource === "string")
43932
43932
  return hostSource;
43933
43933
  return fs2.readFile(fileName, "utf-8");
43934
+ }, safeStableStringify = (value2) => {
43935
+ const seen = new WeakSet;
43936
+ return JSON.stringify(value2, (_key, entry) => {
43937
+ if (typeof entry === "function")
43938
+ return `[Function:${entry.name}]`;
43939
+ if (!entry || typeof entry !== "object")
43940
+ return entry;
43941
+ if (seen.has(entry))
43942
+ return "[Circular]";
43943
+ seen.add(entry);
43944
+ if (Array.isArray(entry))
43945
+ return entry;
43946
+ return Object.fromEntries(Object.entries(entry).sort(([left], [right]) => left.localeCompare(right)));
43947
+ });
43948
+ }, collectAngularResourcePaths = (source, fileDir) => {
43949
+ const paths = [];
43950
+ const templateUrlMatch = findUncommentedMatch(source, /templateUrl\s*:\s*['"]([^'"]+)['"]/);
43951
+ if (templateUrlMatch?.[1])
43952
+ paths.push(join15(fileDir, templateUrlMatch[1]));
43953
+ const styleUrlMatch = findUncommentedMatch(source, /styleUrl\s*:\s*['"]([^'"]+)['"]/);
43954
+ if (styleUrlMatch?.[1])
43955
+ paths.push(join15(fileDir, styleUrlMatch[1]));
43956
+ const styleUrlsMatch = findUncommentedMatch(source, /styleUrls\s*:\s*\[([^\]]+)\]/);
43957
+ const urlMatches = styleUrlsMatch?.[1]?.match(/['"]([^'"]+)['"]/g);
43958
+ if (urlMatches) {
43959
+ for (const urlMatch of urlMatches) {
43960
+ paths.push(join15(fileDir, urlMatch.replace(/['"]/g, "")));
43961
+ }
43962
+ }
43963
+ return paths.map((path2) => resolve19(path2));
43964
+ }, readResourceCacheFile = async (cachePath) => {
43965
+ try {
43966
+ const entry = JSON.parse(await fs2.readFile(cachePath, "utf-8"));
43967
+ if (entry.version !== 1 || typeof entry.source !== "string") {
43968
+ return null;
43969
+ }
43970
+ return entry;
43971
+ } catch {
43972
+ return null;
43973
+ }
43974
+ }, writeResourceCacheFile = async (cachePath, source) => {
43975
+ await fs2.mkdir(dirname11(cachePath), { recursive: true });
43976
+ await fs2.writeFile(cachePath, JSON.stringify({
43977
+ source,
43978
+ version: 1
43979
+ }), "utf-8");
43980
+ }, resolveResourceTransformCachePath = async (filePath, source, stylePreprocessors) => {
43981
+ const resourcePaths = collectAngularResourcePaths(source, dirname11(filePath));
43982
+ const resourceContents = await Promise.all(resourcePaths.map(async (resourcePath) => {
43983
+ const content = await fs2.readFile(resourcePath, "utf-8");
43984
+ return `${resourcePath}\x00${content}`;
43985
+ }));
43986
+ const cacheInput = [
43987
+ "v1",
43988
+ filePath,
43989
+ source,
43990
+ ...resourceContents,
43991
+ safeStableStringify(stylePreprocessors ?? null)
43992
+ ].join("\x00");
43993
+ const cacheKey2 = Bun.hash(cacheInput).toString(BASE_36_RADIX);
43994
+ return join15(process.cwd(), ".absolutejs", "cache", "angular-resources", `${cacheKey2}.json`);
43934
43995
  }, precomputeAotResourceTransforms = async (inputPaths, readFile4, stylePreprocessors) => {
43935
43996
  const transformedSources = new Map;
43936
43997
  const visited = new Set;
43998
+ const stats = {
43999
+ cacheHits: 0,
44000
+ cacheMisses: 0,
44001
+ filesVisited: 0,
44002
+ transformedFiles: 0
44003
+ };
43937
44004
  const transformFile = async (filePath) => {
43938
44005
  const resolvedPath = resolve19(filePath);
43939
44006
  if (visited.has(resolvedPath))
@@ -43941,10 +44008,23 @@ ${registrations}
43941
44008
  visited.add(resolvedPath);
43942
44009
  if (!existsSync16(resolvedPath) || resolvedPath.endsWith(".d.ts"))
43943
44010
  return;
44011
+ stats.filesVisited += 1;
43944
44012
  const source = await readFileForAotTransform(resolvedPath, readFile4);
43945
- const transformed = await inlineResources(source, dirname11(resolvedPath), stylePreprocessors);
43946
- if (transformed.source !== source) {
43947
- transformedSources.set(resolvedPath, transformed.source);
44013
+ const cachePath = await resolveResourceTransformCachePath(resolvedPath, source, stylePreprocessors);
44014
+ const cached = await readResourceCacheFile(cachePath);
44015
+ let transformedSource;
44016
+ if (cached) {
44017
+ stats.cacheHits += 1;
44018
+ transformedSource = cached.source;
44019
+ } else {
44020
+ stats.cacheMisses += 1;
44021
+ const transformed = await inlineResources(source, dirname11(resolvedPath), stylePreprocessors);
44022
+ transformedSource = transformed.source;
44023
+ await writeResourceCacheFile(cachePath, transformedSource);
44024
+ }
44025
+ if (transformedSource !== source) {
44026
+ stats.transformedFiles += 1;
44027
+ transformedSources.set(resolvedPath, transformedSource);
43948
44028
  }
43949
44029
  const imports = extractLocalImportSpecifiers(source, resolvedPath);
43950
44030
  await Promise.all(imports.map(async (specifier) => {
@@ -43954,7 +44034,7 @@ ${registrations}
43954
44034
  }));
43955
44035
  };
43956
44036
  await Promise.all(inputPaths.map((inputPath) => transformFile(inputPath)));
43957
- return transformedSources;
44037
+ return { stats, transformedSources };
43958
44038
  }, compileAngularFiles = async (inputPaths, outDir, stylePreprocessors) => {
43959
44039
  const islandMetadataByOutputPath = await traceAngularPhase("aot/island-metadata", () => new Map(inputPaths.map((inputPath) => {
43960
44040
  const outputPath = resolve19(join15(outDir, relative9(process.cwd(), resolve19(inputPath)).replace(/\.[cm]?[tj]sx?$/, ".js")));
@@ -44015,7 +44095,15 @@ ${registrations}
44015
44095
  emitted[relativePath] = text;
44016
44096
  };
44017
44097
  const originalReadFile = host.readFile;
44018
- const aotTransformedSources = await traceAngularPhase("aot/precompute-resources", () => precomputeAotResourceTransforms(inputPaths, originalReadFile?.bind(host), stylePreprocessors), { entries: inputPaths.length });
44098
+ const { stats: aotResourceTransformStats, transformedSources } = await traceAngularPhase("aot/precompute-resources", () => precomputeAotResourceTransforms(inputPaths, originalReadFile?.bind(host), stylePreprocessors), { entries: inputPaths.length });
44099
+ await traceAngularPhase("aot/resource-cache-summary", () => {
44100
+ return;
44101
+ }, {
44102
+ cacheHits: aotResourceTransformStats.cacheHits,
44103
+ cacheMisses: aotResourceTransformStats.cacheMisses,
44104
+ filesVisited: aotResourceTransformStats.filesVisited,
44105
+ transformedFiles: aotResourceTransformStats.transformedFiles
44106
+ });
44019
44107
  host.readFile = (fileName) => {
44020
44108
  const source = originalReadFile ? originalReadFile.call(host, fileName) : undefined;
44021
44109
  if (typeof source !== "string")
@@ -44024,11 +44112,11 @@ ${registrations}
44024
44112
  return source;
44025
44113
  }
44026
44114
  const resolvedPath = resolve19(fileName);
44027
- return aotTransformedSources.get(resolvedPath) ?? source;
44115
+ return transformedSources.get(resolvedPath) ?? source;
44028
44116
  };
44029
44117
  const originalGetSourceFileForCompile = host.getSourceFile;
44030
44118
  host.getSourceFile = (fileName, languageVersion, onError2) => {
44031
- const source = aotTransformedSources.get(resolve19(fileName));
44119
+ const source = transformedSources.get(resolve19(fileName));
44032
44120
  if (source) {
44033
44121
  return ts2.createSourceFile(fileName, source, languageVersion, true);
44034
44122
  }
@@ -58675,5 +58763,5 @@ export {
58675
58763
  ANGULAR_INIT_TIMEOUT_MS
58676
58764
  };
58677
58765
 
58678
- //# debugId=2F07E1892FE8624964756E2164756E21
58766
+ //# debugId=076CED2F51B54E1564756E2164756E21
58679
58767
  //# sourceMappingURL=index.js.map