Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// return cached index.html if it did not change
const cache = cachedHTMLs.get(ctx.url);
if (cache && cache.lastModified === lastModified) {
ctx.body = cache.body;
return;
}
// for performance we didn't drain the index.html stream for the app index above. if we end up here
// we do need the whole body content now
if (!indexHTMLString) {
indexHTMLString = await getBodyAsString(ctx.body);
}
// extract input files from index.html
const resources = extractResources(indexHTMLString);
if (resources.inlineModules.length > 0) {
throw new Error(
`Compatibility cannot handle "inline" modules (modules without a src attribute). Place your js code in a separate file.`,
);
}
if (!resources.jsModules || resources.jsModules.length === 0) {
throw new Error(
`Compatibility mode requires at least one
export function getTransformedIndexHTML(cfg) {
const polyfillModules =
([compatibilityModes.AUTO, compatibilityModes.ALWAYS].includes(cfg.compatibilityMode) &&
!cfg.uaCompat.supportsEsm) ||
cfg.compatibilityMode === compatibilityModes.MAX;
// extract input files from index.html
const resources = extractResources(cfg.indexHTMLString, { removeImportMaps: false });
/** @type {Map} */
const inlineModules = new Map();
resources.inlineModules.forEach((content, i) => {
inlineModules.set(`inline-module-${i}.js`, content);
});
const files = [
...resources.jsModules,
...[...inlineModules.keys()].map(e => `${e}?source=${encodeURIComponent(cfg.indexUrl)}`),
];
if (files.length === 0) {
return {
indexHTML: cfg.indexHTMLString,
inlineModules: new Map(),