MCPcopy Index your code
hub / github.com/rollup/rollup / transformChunksAndGenerateContentHashes

Function transformChunksAndGenerateContentHashes

src/utils/renderChunks.ts:202–291  ·  view source on GitHub ↗
(
	renderedChunks: ChunkRenderResult[],
	chunkGraph: Record<string, RenderedChunk>,
	outputOptions: NormalizedOutputOptions,
	pluginDriver: PluginDriver,
	getHash: GetHash,
	log: LogHandler
)

Source from the content-addressed store, hash-verified

200}
201
202async function transformChunksAndGenerateContentHashes(
203 renderedChunks: ChunkRenderResult[],
204 chunkGraph: Record<string, RenderedChunk>,
205 outputOptions: NormalizedOutputOptions,
206 pluginDriver: PluginDriver,
207 getHash: GetHash,
208 log: LogHandler
209) {
210 const nonHashedChunksWithPlaceholders: RenderedChunkWithPlaceholders[] = [];
211 const renderedChunksByPlaceholder = new Map<string, RenderedChunkWithPlaceholders>();
212 const hashDependenciesByPlaceholder = new Map<string, HashResult>();
213 const initialHashesByPlaceholder = new Map<string, string>();
214 const placeholders = new Set<string>();
215 for (const {
216 preliminaryFileName: { hashPlaceholder }
217 } of renderedChunks) {
218 if (hashPlaceholder) placeholders.add(hashPlaceholder);
219 }
220 await Promise.all(
221 renderedChunks.map(
222 async ({
223 chunk,
224 preliminaryFileName: { fileName, hashPlaceholder },
225 preliminarySourcemapFileName,
226 magicString,
227 usedModules
228 }) => {
229 const transformedChunk: RenderedChunkWithPlaceholders = {
230 chunk,
231 fileName,
232 sourcemapFileName: preliminarySourcemapFileName?.fileName ?? null,
233 ...(await transformChunk(
234 magicString,
235 fileName,
236 usedModules,
237 chunkGraph,
238 outputOptions,
239 pluginDriver,
240 log
241 ))
242 };
243 const { code, map } = transformedChunk;
244
245 if (hashPlaceholder) {
246 // To create a reproducible content-only hash, all placeholders are
247 // replaced with the same value before hashing
248 const { containedPlaceholders, transformedCode } =
249 replacePlaceholdersWithDefaultAndGetContainedPlaceholders(code, placeholders);
250 let contentToHash = transformedCode;
251 const hashAugmentation = pluginDriver.hookReduceValueSync(
252 'augmentChunkHash',
253 '',
254 [chunk.getRenderedChunkInfo()],
255 (augmentation, pluginHash) => {
256 if (pluginHash) {
257 augmentation += pluginHash;
258 }
259 return augmentation;

Callers 1

renderChunksFunction · 0.85

Calls 8

transformChunkFunction · 0.85
addMethod · 0.80
hookReduceValueSyncMethod · 0.80
getRenderedChunkInfoMethod · 0.80
pushMethod · 0.80
toStringMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…