* 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)
| 530 | * @return {!Promise} |
| 531 | */ |
| 532 | async 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. |
no test coverage detected