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

Function replaceCdnJsUrls

build-system/server/app-utils.js:103–127  ·  view source on GitHub ↗

* @param {string} mode * @param {string} html * @param {string} hostName * @param {boolean} useMaxNames * @return {string}

(mode, html, hostName, useMaxNames)

Source from the content-addressed store, hash-verified

101 * @return {string}
102 */
103function 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

Callers 1

replaceUrlsFunction · 0.85

Calls 7

requireNewServerModuleFunction · 0.85
isRtvModeFunction · 0.85
getCdnUrlRegExpFunction · 0.85
CDNURLToRTVURLFunction · 0.85
getHrefWithoutHostFunction · 0.85
replaceCDNURLPathFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected