* @param {string} mode * @param {string} html * @param {string} hostName * @param {boolean} useMaxNames * @return {string}
(mode, html, hostName, useMaxNames)
| 101 | * @return {string} |
| 102 | */ |
| 103 | function replaceCdnJsUrls(mode, html, hostName, useMaxNames) { |
| 104 | const {CDNURLToRTVURL, replaceCDNURLPath} = |
| 105 | /** @type {import('./new-server/transforms/utilities/cdn')} */ ( |
| 106 | requireNewServerModule('utilities/cdn') |
| 107 | ); |
| 108 | |
| 109 | const pathnames = undefined; // we don't override the mapping, optional arg |
| 110 | const isRtv = isRtvMode(mode); |
| 111 | |
| 112 | // TODO(alanorozco): Match --esm in output extension and/or allow |
| 113 | // `.mjs` to be lazily built regardless of --esm |
| 114 | return html.replace(getCdnUrlRegExp(), (urlString, _cdnPrefix, extension) => { |
| 115 | const url = new URL(urlString); |
| 116 | if (isRtv) { |
| 117 | return CDNURLToRTVURL(url, mode, pathnames, extension).href; |
| 118 | } |
| 119 | // Only JS files have "max" files. Even mjs files don't have an equivalent |
| 120 | // max file during "amp build". |
| 121 | const useMaxNamesForFile = useMaxNames && extension === '.js'; |
| 122 | const href = getHrefWithoutHost( |
| 123 | replaceCDNURLPath(url, pathnames, extension, useMaxNamesForFile) |
| 124 | ); |
| 125 | return hostName + href; |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @param {string} mode |
no test coverage detected