MCPcopy
hub / github.com/ampproject/amphtml / compileJs

Function compileJs

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

* Bundles (max) or compiles (min) a given JavaScript file entry point. * * @param {string} srcDir Path to the src directory * @param {string} srcFilename Name of the JS source file * @param {string} destDir Destination folder for output script * @param {?Object} options * @return {!Promise}

(srcDir, srcFilename, destDir, options)

Source from the content-addressed store, hash-verified

530 * @return {!Promise}
531 */
532async function compileJs(srcDir, srcFilename, destDir, options) {
533 options = options || {};
534 const entryPoint = path.join(srcDir, srcFilename);
535 if (watchedEntryPoints.has(entryPoint)) {
536 return;
537 }
538
539 if (options.watch) {
540 watchedEntryPoints.add(entryPoint);
541 const deps = await getDependencies(entryPoint, options);
542 const watchFunc = async () => {
543 await doCompileJs({...options, continueOnError: true});
544 };
545 watch(deps).on('change', debounce(watchFunc, watchDebounceDelay));
546 }
547
548 /**
549 * Actually performs the steps to compile the entry point.
550 * @param {object} options
551 * @return {Promise<void>}
552 */
553 async function doCompileJs(options) {
554 const buildResult = esbuildCompile(srcDir, srcFilename, destDir, options);
555 if (options.onWatchBuild) {
556 options.onWatchBuild(buildResult);
557 }
558 await buildResult;
559 }
560
561 await doCompileJs(options);
562}
563
564/**
565 * Stops the timer for the given build step and prints the execution time.

Callers 5

buildExperimentsFunction · 0.85
buildLoginDoneFunction · 0.85
buildExtensionJsFunction · 0.85
doBuildJsFunction · 0.85

Calls 6

getDependenciesFunction · 0.85
doCompileJsFunction · 0.85
debounceFunction · 0.50
hasMethod · 0.45
addMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected