Skip to content

Commit

Permalink
[FIX] moduleBundler: Apply defaultFileTypes (#580)
Browse files Browse the repository at this point in the history
Use default if not provided in bundle definition.

In the past neither a default, nor the bundle definition configuration
was used, since the parameter was mistakenly expected on the bundle
options.

Also align the defaults for library- and component-bundles with Maven.

Co-authored-by: Merlin Beutlberger <[email protected]>
  • Loading branch information
matz3 and RandomByte authored Mar 4, 2021
1 parent fe61d6e commit 42f6474
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 185 deletions.
2 changes: 1 addition & 1 deletion lib/lbt/bundle/AutoSplitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AutoSplitter {
this.optimize = !!options.optimize;

// ---- resolve module definition
const resolvedModule = await this.resolver.resolve(moduleDef, options);
const resolvedModule = await this.resolver.resolve(moduleDef);
// ---- calculate overall size of merged module

if ( moduleDef.configuration ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class BundleBuilder {
}

async _createBundle(module, options) {
const resolvedModule = await this.resolver.resolve(module, options);
const resolvedModule = await this.resolver.resolve(module);
if ( options.skipIfEmpty && isEmptyBundle(resolvedModule) ) {
log.verbose(" skipping empty bundle " + module.name);
return undefined;
Expand Down
17 changes: 13 additions & 4 deletions lib/lbt/bundle/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ const log = require("@ui5/logger").getLogger("lbt:bundle:Resolver");

let dependencyTracker;

const DEFAULT_FILE_TYPES = [
".js",
".control.xml", // XMLComposite
".fragment.html",
".fragment.json",
".fragment.xml",
".view.html",
".view.json",
".view.xml"
];

/**
* Resolve a bundle definition.
*
Expand All @@ -32,13 +43,11 @@ class BundleResolver {

/**
* @param {ModuleDefinition} bundle Bundle definition to resolve
* @param {object} [options] Options
* @param {string[]} [options.defaultFileTypes]
List of default file types to which a prefix pattern shall be expanded.
* @returns {Promise<ResolvedBundleDefinition>}
*/
resolve(bundle, options) {
const fileTypes = (options && options.defaultFileTypes) || undefined;
resolve(bundle) {
const fileTypes = bundle.defaultFileTypes || DEFAULT_FILE_TYPES;
let visitedResources = Object.create(null);
let selectedResources = Object.create(null);
let selectedResourcesSequence = [];
Expand Down
4 changes: 3 additions & 1 deletion lib/processors/bundlers/moduleBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ const log = require("@ui5/logger").getLogger("builder:processors:bundlers:module
* @property {boolean} [sort=true] Whether the modules should be sorted by their dependencies
*/

/* eslint-disable max-len */
/**
* Module bundle definition
*
* @public
* @typedef {object} ModuleBundleDefinition
* @property {string} name The module bundle name
* @property {string[]} [defaultFileTypes=[".js", ".fragment.xml", ".view.xml", ".properties", ".json"]]
* @property {string[]} [defaultFileTypes=[".js", ".control.xml", ".fragment.html", ".fragment.json", ".fragment.xml", ".view.html", ".view.json", ".view.xml"]]
* List of default file types to be included in the bundle
* @property {ModuleBundleDefinitionSection[]} sections List of module bundle definition sections.
*/
/* eslint-enable max-len */

/**
* Module bundle options
Expand Down
21 changes: 18 additions & 3 deletions lib/tasks/bundlers/generateComponentPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ module.exports = function({
const bundleDefinitions = allNamespaces.map((namespace) => {
const filters = [
`${namespace}/`,
`!${namespace}/test/`,
`!${namespace}/*.html`
`${namespace}/**/manifest.json`,
`${namespace}/changes/changes-bundle.json`,
`${namespace}/changes/flexibility-bundle.json`,
`!${namespace}/test/`
];

// Add configured excludes for namespace
Expand All @@ -85,12 +87,25 @@ module.exports = function({
allNamespaces.forEach((ns) => {
if (ns !== namespace && ns.startsWith(`${namespace}/`)) {
filters.push(`!${ns}/`);
// Explicitly exclude manifest.json files of subcomponents since the general exclude above this
// comment only applies to the configured default file types, which do not include ".json"
filters.push(`!${ns}/**/manifest.json`);
}
});

return {
name: `${namespace}/Component-preload.js`,
defaultFileTypes: [".js", ".fragment.xml", ".view.xml", ".properties", ".json"],
defaultFileTypes: [
".js",
".control.xml",
".fragment.html",
".fragment.json",
".fragment.xml",
".view.html",
".view.json",
".view.xml",
".properties"
],
sections: [
{
mode: "preload",
Expand Down
23 changes: 2 additions & 21 deletions lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,14 @@ const moduleBundler = require("../../processors/bundlers/moduleBundler");
const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized;
const {negateFilters} = require("../../lbt/resources/ResourceFilterList");

const DEFAULT_FILE_TYPES = [
".js",
".control.xml", // XMLComposite
".fragment.html",
".fragment.json",
".fragment.xml",
".view.html",
".view.json",
".view.xml",
".properties",
".json"
];

function getDefaultLibraryPreloadFilters(namespace, excludes) {
const filters = [
`${namespace}/`,
`!${namespace}/.library`,
`${namespace}/**/manifest.json`,
`!${namespace}/*-preload.js`, // exclude all bundles
`!${namespace}/designtime/`,
`!${namespace}/**/*.designtime.js`,
`!${namespace}/**/*.support.js`,
`!${namespace}/themes/`,
`!${namespace}/messagebundle*`
`!${namespace}/**/*.support.js`
];

if (Array.isArray(excludes)) {
Expand All @@ -50,7 +35,6 @@ function getBundleDefinition(namespace, excludes) {
if (namespace === "sap/ui/core") {
return {
name: `${namespace}/library-preload.js`,
defaultFileTypes: DEFAULT_FILE_TYPES,
sections: [
{
// exclude the content of sap-ui-core by declaring it as 'provided'
Expand Down Expand Up @@ -106,7 +90,6 @@ function getBundleDefinition(namespace, excludes) {
}
return {
name: `${namespace}/library-preload.js`,
defaultFileTypes: DEFAULT_FILE_TYPES,
sections: [
{
mode: "preload",
Expand All @@ -122,7 +105,6 @@ function getBundleDefinition(namespace, excludes) {
function getDesigntimeBundleDefinition(namespace) {
return {
name: `${namespace}/designtime/library-preload.designtime.js`,
defaultFileTypes: DEFAULT_FILE_TYPES,
sections: [
{
mode: "preload",
Expand All @@ -145,7 +127,6 @@ function getDesigntimeBundleDefinition(namespace) {
function getSupportFilesBundleDefinition(namespace) {
return {
name: `${namespace}/library-preload.support.js`,
defaultFileTypes: DEFAULT_FILE_TYPES,
sections: [
{
mode: "preload",
Expand Down
18 changes: 15 additions & 3 deletions lib/tasks/bundlers/generateStandaloneAppBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ const moduleBundler = require("../../processors/bundlers/moduleBundler");
function getBundleDefinition(config) {
const bundleDefinition = {
name: config.name,
defaultFileTypes: [".js", ".fragment.xml", ".view.xml", ".properties", ".json"],
defaultFileTypes: [
".js",
".control.xml",
".fragment.html",
".fragment.json",
".fragment.xml",
".view.html",
".view.json",
".view.xml",
".properties"
],
sections: []
};

Expand All @@ -23,9 +33,11 @@ function getBundleDefinition(config) {
bundleDefinition.sections.push({
mode: "preload",
filters: [
`${config.namespace|| ""}/`,
`${config.namespace || ""}/`,
`${config.namespace || ""}/**/manifest.json`,
`${config.namespace || ""}/changes/changes-bundle.json`,
`${config.namespace || ""}/changes/flexibility-bundle.json`,
`!${config.namespace || ""}/test/`,
`!${config.namespace || ""}/*.html`,
"sap/ui/core/Core.js"
],
resolve: true,
Expand Down
Loading

0 comments on commit 42f6474

Please sign in to comment.