MCPcopy Create free account
hub / github.com/ampproject/amphtml / replaceOutputFile

Function replaceOutputFile

build-system/common/esbuild-babel.js:192–218  ·  view source on GitHub ↗

* @param {Array } outputFiles * @param {import('esbuild').OutputFile} original * @param {string} text

(outputFiles, original, text)

Source from the content-addressed store, hash-verified

190 * @param {string} text
191 */
192function replaceOutputFile(outputFiles, original, text) {
193 const index = outputFiles.indexOf(original);
194 if (index === -1) {
195 throw new Error(`couldn't find outputFile ${original.path}`);
196 }
197
198 let contents;
199 const generateContents = () =>
200 // eslint-disable-next-line local/no-forbidden-terms
201 (contents ||= new TextEncoder().encode(text));
202
203 let hash;
204 const generateHash = () =>
205 (hash ||= createHash('sha1').update(text).digest('hex'));
206
207 const file = {
208 path: original.path,
209 text,
210 get contents() {
211 return generateContents();
212 },
213 get hash() {
214 return generateHash();
215 },
216 };
217 outputFiles[index] = file;
218}
219
220const CJS_TRANSFORMS = new Set([
221 'transform-modules-commonjs',

Callers 1

setupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected