Skip to content

Commit 32b34d9

Browse files
Simplified results file generation logic
1 parent d4157ce commit 32b34d9

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

build/gulpfile.esm.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,29 +261,29 @@ export function bundle() {
261261
rawConfig.BundlesVirtualBasePath = "./assets/";
262262

263263
// Bundle results callback
264+
/**
265+
*
266+
* @param {Map<string, any[]} results
267+
*/
264268
function bundleResults(results) {
269+
// Compute possible asset base paths (for matching later)
270+
/** @type {string[]} */
271+
const assetBasePaths = [];
272+
assetBasePaths.push(resolvePath(vendorAssetsDir, "bower_components"));
273+
assetBasePaths.push(resolvePath(vendorAssetsDir, "node_modules"));
274+
for (const sprinkle of sprinkles) {
275+
assetBasePaths.push(resolvePath(sprinklesDir, sprinkle, "assets"));
276+
}
277+
278+
265279
/**
266280
* Resolves absolute path to gulp-uf-bundle-assets v2 style path
267281
* @param {string} path Absolute path to resolve.
268282
*/
269283
function resolveToAssetPath(path) {
270-
// TODO There is a significant amount of duplicated code here. We can do better.
271-
if (path.startsWith(resolvePath(sprinklesDir))) {
272-
// Handle sprinkle path
273-
for (const sprinkle of sprinkles) {
274-
const sprinklePath = resolvePath(sprinklesDir, sprinkle, "assets");
275-
if (path.startsWith(sprinklePath)) {
276-
return path.replace(sprinklePath, "").replace(/\\/g, "/").replace("/", "");
277-
}
278-
}
279-
}
280-
else {
281-
// Handle vendor path
282-
if (path.startsWith(resolvePath(vendorAssetsDir, "bower_components"))) {
283-
return path.replace(resolvePath(vendorAssetsDir, "bower_components"), "").replace(/\\/g, "/").replace("/", "");
284-
}
285-
else if (path.startsWith(resolvePath(vendorAssetsDir, "node_modules"))) {
286-
return path.replace(resolvePath(vendorAssetsDir, "node_modules"), "").replace(/\\/g, "/").replace("/", "");
284+
for (const basePath of assetBasePaths) {
285+
if (path.startsWith(basePath)) {
286+
return path.replace(basePath, "").replace(/\\/g, "/").replace("/", "");
287287
}
288288
}
289289

0 commit comments

Comments
 (0)