Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] moduleBundler: Apply defaultFileTypes #580

Merged
merged 3 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 16 additions & 3 deletions lib/tasks/bundlers/generateComponentPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ module.exports = function({
const bundleDefinitions = allNamespaces.map((namespace) => {
const filters = [
`${namespace}/`,
`!${namespace}/test/`,
`!${namespace}/*.html`
`${namespace}/**/manifest.json`,
`!${namespace}/test/`
];

// Add configured excludes for namespace
Expand All @@ -85,12 +85,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`);
Copy link
Member

@RandomByte RandomByte Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether this is our intention. But I guess it's a good solution for the time being.

The exclude-regex generated by ResourceFilterList always applies the default file types and therefore won't exclude manifest.json:

// !library/h/components/subcomponent3/ --> exclude: 
/^library\/h\/components\/subcomponent3\/(?:[^/]+\/)*[^/]*(?:\.js|\.control\.xml|\.fragment\.html|\.fragment\.json|\.fragment\.xml|\.view\.html|\.view\.json|\.view\.xml|\.properties)$/

}
});

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
16 changes: 13 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,9 @@ function getBundleDefinition(config) {
bundleDefinition.sections.push({
mode: "preload",
filters: [
`${config.namespace|| ""}/`,
`${config.namespace || ""}/`,
`${config.namespace || ""}/**/manifest.json`,
`!${config.namespace || ""}/test/`,
`!${config.namespace || ""}/*.html`,
"sap/ui/core/Core.js"
],
resolve: true,
Expand Down
Loading