From 93165cb947ee0ad895e24d15c0ce5410afde3668 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 20 Jun 2022 13:46:14 +0530 Subject: [PATCH] runtime theme chunks should also be stored in map There will be more than one runtime theme file when multiple theme collections exist. --- .../build-plugins/rollup-plugin-build-themes.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/build-plugins/rollup-plugin-build-themes.js b/scripts/build-plugins/rollup-plugin-build-themes.js index e74d3b85..41e78044 100644 --- a/scripts/build-plugins/rollup-plugin-build-themes.js +++ b/scripts/build-plugins/rollup-plugin-build-themes.js @@ -46,7 +46,7 @@ function addThemesToConfig(bundle, manifestLocations, defaultThemes) { function parseBundle(bundle) { const chunkMap = new Map(); const assetMap = new Map(); - let runtimeThemeChunk; + let runtimeThemeChunkMap = new Map(); for (const [fileName, info] of Object.entries(bundle)) { if (!fileName.endsWith(".css")) { continue; @@ -60,18 +60,18 @@ function parseBundle(bundle) { assetMap.set(info.name, info); continue; } + const location = info.facadeModuleId?.match(/(.+)\/.+\.css/)?.[1]; + if (!location) { + throw new Error("Cannot find location of css chunk!"); + } if (info.facadeModuleId?.includes("type=runtime")) { /** * We have a separate field in manifest.source just for the runtime theme, * so store this separately. */ - runtimeThemeChunk = info; + runtimeThemeChunkMap.set(location, info); continue; } - const location = info.facadeModuleId?.match(/(.+)\/.+\.css/)?.[1]; - if (!location) { - throw new Error("Cannot find location of css chunk!"); - } const array = chunkMap.get(location); if (!array) { chunkMap.set(location, [info]); @@ -80,7 +80,7 @@ function parseBundle(bundle) { array.push(info); } } - return { chunkMap, assetMap, runtimeThemeChunk }; + return { chunkMap, assetMap, runtimeThemeChunkMap }; } module.exports = function buildThemes(options) { @@ -249,7 +249,7 @@ module.exports = function buildThemes(options) { // assetMap: Mapping from asset-name (eg: element-dark.css) to AssetInfo // chunkMap: Mapping from theme-location (eg: hydrogen-web/src/.../css/themes/element) to a list of ChunkInfo // types of AssetInfo and ChunkInfo can be found at https://rollupjs.org/guide/en/#generatebundle - const { assetMap, chunkMap, runtimeThemeChunk } = parseBundle(bundle); + const { assetMap, chunkMap, runtimeThemeChunkMap } = parseBundle(bundle); const manifestLocations = []; for (const [location, chunkArray] of chunkMap) { const manifest = require(`${location}/manifest.json`); @@ -263,6 +263,7 @@ module.exports = function buildThemes(options) { themeKey = name; builtAssets[`${name}-${variant}`] = assetMap.get(chunk.fileName).fileName; } + const runtimeThemeChunk = runtimeThemeChunkMap.get(location); manifest.source = { "built-assets": builtAssets, "runtime-asset": assetMap.get(runtimeThemeChunk.fileName).fileName,