Skip to content

Commit

Permalink
fix(ui5-tooling-modules): re-enable chunks for middleware (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
petermuessig authored Jul 17, 2023
1 parent c541d7b commit aaea4b0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/ui5-tooling-modules/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const minimatch = require("minimatch");

// local output cache of rollup
const outputCache = {};
const chunkToModulePath = {};

// local cache of negative modules (avoid additional lookups)
const modulesNegativeCache = [];
Expand Down Expand Up @@ -254,7 +255,8 @@ const that = (module.exports = {
let bundling = false;

try {
const modulePath = that.resolveModule(moduleName);
// in case of chunks are requested, we lookup the original module
const modulePath = chunkToModulePath[moduleName] ?? that.resolveModule(moduleName);
if (modulePath) {
if (!existsSync(modulePath)) {
log.error(`Bundle ${moduleName} doesn't exist at the resolved path ${modulePath}!`);
Expand All @@ -263,9 +265,10 @@ const that = (module.exports = {

const lastModified = new Date((await stat(modulePath)).mtime).getTime();
const moduleExt = path.extname(modulePath).toLowerCase();
const isChunk = !!chunkToModulePath[moduleName];

let cachedOutput = outputCache[moduleName];
if (skipCache || !cachedOutput || cachedOutput.lastModified !== lastModified) {
if (!isChunk && (skipCache || !cachedOutput || cachedOutput.lastModified !== lastModified)) {
// is the bundle a UI5 module?
const moduleContent = await readFile(modulePath, { encoding: "utf8" });

Expand Down Expand Up @@ -295,6 +298,12 @@ const that = (module.exports = {
// should be also given by the rollup configuration!
if (output.length > 1) {
debug && log.info(`The bundle for ${moduleName} has ${output.length} chunks!`);
// cleanup the chunkToModulePath mapping for the current module
Object.keys(chunkToModulePath).forEach((fileName) => {
if (chunkToModulePath[fileName] === modulePath) {
delete chunkToModulePath[fileName];
}
});
// store the individual output chunks as well in the cache
cachedOutput.chunks = {};
output.slice(1).forEach((chunk) => {
Expand All @@ -303,6 +312,7 @@ const that = (module.exports = {
code: chunk.code,
lastModified,
};
chunkToModulePath[fileName] = modulePath;
});
}
} else {
Expand Down

0 comments on commit aaea4b0

Please sign in to comment.