MCPcopy
hub / github.com/vitejs/vite / stringifyDepsOptimizerMetadata

Function stringifyDepsOptimizerMetadata

packages/vite/src/node/optimizer/index.ts:1067–1110  ·  view source on GitHub ↗

* Stringify metadata for deps cache. Remove processing promises * and individual dep info browserHash. Once the cache is reload * the next time the server start we need to use the global * browserHash to allow long term caching

(
  metadata: DepOptimizationMetadata,
  depsCacheDir: string,
)

Source from the content-addressed store, hash-verified

1065 * browserHash to allow long term caching
1066 */
1067function stringifyDepsOptimizerMetadata(
1068 metadata: DepOptimizationMetadata,
1069 depsCacheDir: string,
1070) {
1071 const { hash, configHash, lockfileHash, browserHash, optimized, chunks } =
1072 metadata
1073 return JSON.stringify(
1074 {
1075 hash,
1076 configHash,
1077 lockfileHash,
1078 browserHash,
1079 optimized: Object.fromEntries(
1080 Object.values(optimized).map(
1081 ({ id, src, file, fileHash, needsInterop, isDynamicEntry }) => [
1082 id,
1083 {
1084 src,
1085 file,
1086 fileHash,
1087 needsInterop,
1088 isDynamicEntry,
1089 },
1090 ],
1091 ),
1092 ),
1093 chunks: Object.fromEntries(
1094 Object.values(chunks).map(({ id, file, isDynamicEntry }) => [
1095 id,
1096 { file, isDynamicEntry },
1097 ]),
1098 ),
1099 },
1100 (key: string, value: string) => {
1101 // Paths can be absolute or relative to the deps cache dir where
1102 // the _metadata.json is located
1103 if (key === 'file' || key === 'src') {
1104 return normalizePath(path.relative(depsCacheDir, value))
1105 }
1106 return value
1107 },
1108 2,
1109 )
1110}
1111
1112export async function extractExportsData(
1113 environment: Environment,

Callers 1

runOptimizeDepsFunction · 0.85

Calls 1

normalizePathFunction · 0.90

Tested by

no test coverage detected