build-system/tasks/extension-helpers.js
/**
 * Build the JavaScript for the extension specified
 *
 * @param {string} dir Path to the extension's directory
 * @param {string} name Name of the extension. Must be the sub directory in
 *     the extensions directory and the name of the JS and optional CSS file.
 * @param {!Object} options
 * @return {!Promise}
 */
Build the JavaScript for the extension specified
@param {string} dir Path to the extension's directory
@param {string} name Name of the extension. Must be the sub directory in
the extensions directory and the name of the JS and optional CSS file.
@param {!Object} options
@return {!Promise}
Build the JavaScript for the extension specified @param { string } dir Path to the extension ' s directory @param { string } name Name of the extension . Must be the sub directory in the extensions directory and the name of the JS and optional CSS file . @param { !Object } options @return { !Promise }
async function buildExtensionJs(dir, name, options) {
  const isLatest = legacyLatestVersions[options.name] === options.version;
  const {version, filename = `${name}.js`, wrapper = 'extension'} = options;
  const wrapperOrFn = wrappers[wrapper];
  if (!wrapperOrFn) {
    throw new Error(
      `Unknown options.wrapper "${wrapper}" (${name}:${version})\n` +
        `Expected one of: ${Object.keys(wrappers).join(', ')}`
    );
  }
  const resolvedWrapper =
    typeof wrapperOrFn === 'function'
      ? wrapperOrFn(name, version, argv.esm, options.loadPriority)
      : wrapperOrFn;
  await compileJs(`${dir}/`, filename, './dist/v0', {
    ...options,
    toName: `${name}-${version}.max.js`,
    minifiedName: `${name}-${version}.js`,
    aliasName: isLatest ? `${name}-latest.js` : '',
    wrapper: resolvedWrapper,
  });
  if (options.errored) {
    return;
  }
  const aliasBundle = extensionAliasBundles[name];
  const isAliased = aliasBundle && aliasBundle.version == version;
  if (isAliased) {
    const {aliasedVersion} = aliasBundle;
    const src = maybeToEsmName(
      `${name}-${version}${options.minify ? '' : '.max'}.js`
    );
    const dest = maybeToEsmName(
      `${name}-${aliasedVersion}${options.minify ? '' : '.max'}.js`
    );
    fs.copySync(`dist/v0/${src}`, `dist/v0/${dest}`);
    fs.copySync(`dist/v0/${src}.map`, `dist/v0/${dest}.map`);
  }
  if (name === 'amp-script') {
    await copyWorkerDomResources(version);
    await buildSandboxedProxyIframe(options.minify);
  }
}
async function buildExtensionJs ( dir , name , options ) { const isLatest = legacyLatestVersions [ options . name ] === options . version ; const { version , filename = ` ${ name } ` , wrapper = 'extension' } = options ; const wrapperOrFn = wrappers [ wrapper ] ; if ( ! wrapperOrFn ) { throw new Error ( ` ${ wrapper } ${ name } ${ version } \n ` + ` ${ Object . keys ( wrappers ) . join ( ', ' ) } ` ) ; } const resolvedWrapper = typeof wrapperOrFn === 'function' ? wrapperOrFn ( name , version , argv . esm , options . loadPriority ) : wrapperOrFn ; await compileJs ( ` ${ dir } ` , filename , './dist/v0' , { ... options , toName : ` ${ name } ${ version } ` , minifiedName : ` ${ name } ${ version } ` , aliasName : isLatest ? ` ${ name } ` : '' , wrapper : resolvedWrapper , } ) ; if ( options . errored ) { return ; } const aliasBundle = extensionAliasBundles [ name ] ; const isAliased = aliasBundle && aliasBundle . version == version ; if ( isAliased ) { const { aliasedVersion } = aliasBundle ; const src = maybeToEsmName ( ` ${ name } ${ version } ${ options . minify ? '' : '.max' } ` ) ; const dest = maybeToEsmName ( ` ${ name } ${ aliasedVersion } ${ options . minify ? '' : '.max' } ` ) ; fs . copySync ( ` ${ src } ` , ` ${ dest } ` ) ; fs . copySync ( ` ${ src } ` , ` ${ dest } ` ) ; } if ( name === 'amp-script' ) { await copyWorkerDomResources ( version ) ; await buildSandboxedProxyIframe ( options . minify ) ; } }
Build the JavaScript for the extension specified
 @param {string} dir Path to the extension's directory
 @param {string} name Name of the extension.
Build the JavaScript for the extension specified @param { string } dir Path to the extension ' s directory @param { string } name Name of the extension .
// If an incremental watch build fails, simply return.