MCPcopy Index your code
hub / github.com/ampproject/amphtml / build

Function build

build-system/tasks/helpers.js:326–418  ·  view source on GitHub ↗

* @param {number} startTime * @return {Promise }

(startTime)

Source from the content-addressed store, hash-verified

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);

Callers 1

esbuildCompileFunction · 0.70

Calls 7

includeSourcesContentFunction · 0.85
minifyFunction · 0.85
debugFunction · 0.85
massageSourcemapsFunction · 0.85
finishBundleFunction · 0.85
parseMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected