* @param {Array } outputFiles * @param {import('esbuild').OutputFile} original * @param {string} text
(outputFiles, original, text)
| 190 | * @param {string} text |
| 191 | */ |
| 192 | function 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 | |
| 220 | const CJS_TRANSFORMS = new Set([ |
| 221 | 'transform-modules-commonjs', |