Skip to content

Commit

Permalink
Add taskUtil as dependency to moduleBundler
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Jul 2, 2024
1 parent 702ea88 commit bb33e24
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 62 deletions.
13 changes: 5 additions & 8 deletions lib/processors/bundlers/moduleBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ const log = getLogger("builder:processors:bundlers:moduleBundler");
* @param {string} [parameters.options.targetUi5CoreVersion] Optional semver compliant sap.ui.core project version, e.g '2.0.0'.
This allows the bundler to make assumptions on available runtime APIs.
Omit if the ultimate UI5 version at runtime is unknown or can't be determined.
* @param {@ui5/project/build/helpers/TaskUtil|object} [parameters.taskUtil] TaskUtil
* @returns {Promise<module:@ui5/builder/processors/bundlers/moduleBundler~ModuleBundlerResult[]>}
* Promise resolving with module bundle resources
*/
/* eslint-enable max-len */
export default function({resources, options: {
export default function({resources, taskUtil, options: {
bundleDefinition, bundleOptions, moduleNameMapping, targetUi5CoreVersion
}}) {
// Apply defaults without modifying the passed object
Expand All @@ -152,12 +153,8 @@ export default function({resources, options: {
ignoreMissingModules: false
}, bundleOptions);

// Take the project from the resources if available.
// It's needed for specVersion check. If unavailable,
// the specVersion would be treated as the most recent one.
const project = resources?.[0]?.getProject();
// Apply defaults without modifying the passed object
bundleDefinition = applyDefaultsToBundleDefinition(bundleDefinition, project?.getSpecVersion());
bundleDefinition = applyDefaultsToBundleDefinition(bundleDefinition, taskUtil);

const pool = new LocatorResourcePool({
ignoreMissingModules: bundleOptions.ignoreMissingModules
Expand Down Expand Up @@ -200,7 +197,7 @@ export default function({resources, options: {
});
}

function applyDefaultsToBundleDefinition(bundleDefinition, specVersion) {
function applyDefaultsToBundleDefinition(bundleDefinition, taskUtil) {
bundleDefinition.sections = bundleDefinition?.sections?.map((section) => {
const defaultValues = {
resolve: false,
Expand All @@ -213,7 +210,7 @@ function applyDefaultsToBundleDefinition(bundleDefinition, specVersion) {
// Since specVersion: 4.0 "require" section starts loading asynchronously.
// If specVersion cannot be determined, the latest spec is taken into account.
// This is a breaking change in specVersion: 4.0
if (section.mode === "require" && (!specVersion || specVersion.gte("4.0"))) {
if (section.mode === "require" && (!taskUtil || taskUtil.getProject().getSpecVersion().gte("4.0"))) {
defaultValues.async = true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/bundlers/generateBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default async function({
if (coreVersion) {
options.targetUi5CoreVersion = coreVersion;
}
return moduleBundler({options, resources}).then((bundles) => {
return moduleBundler({options, resources, taskUtil}).then((bundles) => {
return Promise.all(bundles.map(({bundle, sourceMap} = {}) => {
if (!bundle) {
// Skip empty bundles
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/bundlers/generateComponentPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export default async function({
}
return moduleBundler({
resources,
options
options,
taskUtil
});
}));
})
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
if (coreVersion) {
options.targetUi5CoreVersion = coreVersion;
}
return moduleBundler({options, resources});
return moduleBundler({options, resources, taskUtil});
};

return nonDbgWorkspace.byGlob("/**/*.{js,json,xml,html,properties,library,js.map}").then(async (resources) => {
Expand Down
18 changes: 12 additions & 6 deletions test/lib/tasks/bundlers/generateBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ test.serial("generateBundle: No taskUtil, no bundleOptions", async (t) => {
bundleDefinition,
bundleOptions: undefined
},
resources
resources,
taskUtil: undefined
}]);

t.is(combo.byGlob.callCount, 1,
Expand Down Expand Up @@ -171,7 +172,8 @@ test.serial("generateBundle: No bundleOptions, with taskUtil", async (t) => {
bundleOptions: undefined,
targetUi5CoreVersion: "1.120.0",
},
resources
resources,
taskUtil
}]);

t.is(combo.byGlob.callCount, 0,
Expand Down Expand Up @@ -292,7 +294,8 @@ test.serial("generateBundle: bundleOptions: optimize=false, with taskUtil", asyn
},
targetUi5CoreVersion: "1.120.0",
},
resources
resources,
taskUtil
}]);

t.is(combo.byGlob.callCount, 0,
Expand Down Expand Up @@ -415,7 +418,8 @@ test.serial("generateBundle: bundleOptions: sourceMap=false, with taskUtil", asy
bundleOptions,
targetUi5CoreVersion: "1.120.0"
},
resources
resources,
taskUtil
}]);

t.is(combo.byGlob.callCount, 0,
Expand Down Expand Up @@ -513,7 +517,8 @@ test.serial("generateBundle: Empty bundle (skipIfEmpty=true)", async (t) => {
bundleOptions,
targetUi5CoreVersion: "1.120.0"
},
resources
resources,
taskUtil
}]);

t.is(combo.byGlob.callCount, 0,
Expand Down Expand Up @@ -640,7 +645,8 @@ test.serial("generateBundle: No bundleOptions, with taskUtil, UI5 Version >= 2",
bundleOptions: undefined,
targetUi5CoreVersion: "2.0.0",
},
resources
resources,
taskUtil
}]);

t.is(combo.byGlob.callCount, 0,
Expand Down
24 changes: 16 additions & 8 deletions test/lib/tasks/bundlers/generateComponentPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ test.serial("generateComponentPreload - one namespace", async (t) => {
ignoreMissingModules: true
}
},
resources
resources,
taskUtil: undefined
}]);

t.is(byGlob.callCount, 1,
Expand Down Expand Up @@ -188,7 +189,8 @@ test.serial("generateComponentPreload - one namespace - excludes", async (t) =>
ignoreMissingModules: true
}
},
resources
resources,
taskUtil: undefined
}]);

t.is(byGlob.callCount, 1,
Expand Down Expand Up @@ -293,7 +295,8 @@ test.serial("generateComponentPreload - one namespace - excludes w/o namespace",
ignoreMissingModules: true
}
},
resources
resources,
taskUtil
}]);

t.is(byGlob.callCount, 1,
Expand Down Expand Up @@ -414,7 +417,8 @@ test.serial("generateComponentPreload - multiple namespaces - excludes", async (
ignoreMissingModules: true
}
},
resources
resources,
taskUtil: undefined
}]);
t.deepEqual(moduleBundlerStub.getCall(1).args, [{
options: {
Expand Down Expand Up @@ -455,7 +459,8 @@ test.serial("generateComponentPreload - multiple namespaces - excludes", async (
ignoreMissingModules: true
}
},
resources
resources,
taskUtil: undefined
}]);

t.is(byGlob.callCount, 1,
Expand Down Expand Up @@ -599,7 +604,8 @@ test.serial("generateComponentPreload - nested namespaces - excludes", async (t)
ignoreMissingModules: true
}
},
resources
resources,
taskUtil: undefined
}]);
t.deepEqual(moduleBundlerStub.getCall(1).args, [{
options: {
Expand Down Expand Up @@ -648,7 +654,8 @@ test.serial("generateComponentPreload - nested namespaces - excludes", async (t)
ignoreMissingModules: true
}
},
resources
resources,
taskUtil: undefined
}]);
t.deepEqual(moduleBundlerStub.getCall(2).args, [{
options: {
Expand Down Expand Up @@ -690,7 +697,8 @@ test.serial("generateComponentPreload - nested namespaces - excludes", async (t)
ignoreMissingModules: true
}
},
resources
resources,
taskUtil: undefined
}]);

t.is(log.warn.callCount, 1, "log.warn should be called once");
Expand Down
Loading

0 comments on commit bb33e24

Please sign in to comment.