* @param {number} startTime * @return {Promise }
(startTime)
| 324 | * @return {Promise<void>} |
| 325 | */ |
| 326 | async function build(startTime) { |
| 327 | if (!esbuildContext) { |
| 328 | esbuildContext = await esbuild.context({ |
| 329 | entryPoints: [entryPoint], |
| 330 | bundle: true, |
| 331 | sourcemap: 'external', |
| 332 | sourcesContent: includeSourcesContent(), |
| 333 | outfile: destFile, |
| 334 | define: experimentDefines, |
| 335 | plugins, |
| 336 | // When using `nomodule-loader` we build as ESM in order to preserve |
| 337 | // import statements. These are transformed in a post-build Babel step. |
| 338 | format: |
| 339 | options.outputFormat === 'nomodule-loader' |
| 340 | ? 'esm' |
| 341 | : options.outputFormat, |
| 342 | banner, |
| 343 | footer, |
| 344 | // For es5 builds, ensure esbuild-injected code is transpiled. |
| 345 | target: argv.esm ? 'es6' : 'es5', |
| 346 | logLevel: 'silent', |
| 347 | external: options.externalDependencies, |
| 348 | mainFields: ['module', 'browser', 'main'], |
| 349 | write: false, |
| 350 | }); |
| 351 | } |
| 352 | |
| 353 | const {outputFiles} = await esbuildContext.rebuild(); |
| 354 | if (outputFiles === undefined) { |
| 355 | throw new Error(`No output files for ${destFilename}`); |
| 356 | } |
| 357 | |
| 358 | const codeFile = outputFiles.find(({path}) => !path.endsWith('.map')); |
| 359 | const mapFile = outputFiles.find(({path}) => path.endsWith('.map')); |
| 360 | |
| 361 | if (!codeFile || !mapFile) { |
| 362 | throw new Error( |
| 363 | `Expected code and map file for ${destFilename}; got ${outputFiles.map( |
| 364 | ({path}) => path |
| 365 | )}` |
| 366 | ); |
| 367 | } |
| 368 | |
| 369 | let {text: code} = codeFile; |
| 370 | const mapChain = [JSON.parse(mapFile.text)]; |
| 371 | |
| 372 | if (options.outputFormat === 'nomodule-loader') { |
| 373 | const result = await babel.transformAsync(code, { |
| 374 | caller: {name: 'nomodule-loader'}, |
| 375 | filename: destFile, |
| 376 | sourceRoot: path.dirname(destFile), |
| 377 | sourceMaps: true, |
| 378 | }); |
| 379 | if (!result?.code) { |
| 380 | throw new Error('failed to babel'); |
| 381 | } |
| 382 | code = result.code; |
| 383 | mapChain.unshift(result.map); |
no test coverage detected