diff --git a/client/src/loader.js b/client/src/loader.js index 79628d7b63..643dd2ef98 100644 --- a/client/src/loader.js +++ b/client/src/loader.js @@ -76,8 +76,10 @@ this._internalModuleListIsSet = false; this._bundleFileMap = {}; this._bundleMapping = {}; - /** @type Object. */ + /** @type {Object.} */ this._bundleDependenciesMap = {}; + /** @type {Object.} */ + this._bundleIsLoadedMap = {}; this._addLibsConfigCallCount = 0; this._addLibsConfigCallMaxCount = 2; @@ -507,7 +509,7 @@ if (name in this._bundleMapping) { let bundleName = this._bundleMapping[name]; - this._addBundle(bundleName).then(() => { + this._requireBundle(bundleName).then(() => { let classObj = this._getClass(name); if (!classObj) { @@ -606,11 +608,15 @@ * @param {string} name * @return {Promise} */ - _addBundle: function (name) { + _requireBundle: function (name) { + if (this._bundleIsLoadedMap[name]) { + return Promise.resolve(); + } + let dependencies = this._bundleDependenciesMap[name] || []; if (!dependencies.length) { - return this._addBundleInternal(name); + return this._addBundle(name); } return new Promise(resolve => { @@ -618,7 +624,7 @@ Promise.all(list) .then(() => { - return this._addBundleInternal(name); + return this._addBundle(name); }) .then(() => resolve()); }); @@ -629,7 +635,7 @@ * @param {string} name * @return {Promise} */ - _addBundleInternal: function (name) { + _addBundle: function (name) { let src = this._bundleFileMap[name]; if (!src) { @@ -656,7 +662,11 @@ return new Promise(resolve => { document.head.appendChild(scriptEl); - scriptEl.addEventListener('load', () => resolve()); + scriptEl.addEventListener('load', () => { + this._bundleIsLoadedMap[name] = true; + + resolve(); + }); }); }, diff --git a/frontend/bundle-config.json b/frontend/bundle-config.json index c1cb2934da..6cbf11cf04 100644 --- a/frontend/bundle-config.json +++ b/frontend/bundle-config.json @@ -107,7 +107,7 @@ "templatePatterns": [ "client/modules/crm/res/templates/**/*.tpl" ], - "allPatterns": [ + "lookupPatterns": [ "client/modules/crm/src/**/*.js" ] }, @@ -119,8 +119,8 @@ "dependentOn": [ "lib!Summernote" ], - "libs": ["Summernote"], - "allPatterns": [ + "requiredLibs": ["Summernote"], + "lookupPatterns": [ "client/modules/crm/src/**/*.js" ] }, @@ -132,8 +132,8 @@ "lib!Flotr", "lib!espo-funnel-chart" ], - "libs": ["Flotr", "espo-funnel-chart"], - "allPatterns": [ + "requiredLibs": ["Flotr", "espo-funnel-chart"], + "lookupPatterns": [ "client/modules/crm/src/**/*.js" ] }, @@ -144,8 +144,8 @@ "dependentOn": [ "lib!full-calendar" ], - "libs": ["full-calendar"], - "allPatterns": [ + "requiredLibs": ["full-calendar"], + "lookupPatterns": [ "client/modules/crm/src/**/*.js" ] }, @@ -156,8 +156,8 @@ "dependentOn": [ "lib!vis" ], - "libs": ["vis"], - "allPatterns": [ + "requiredLibs": ["vis"], + "lookupPatterns": [ "client/modules/crm/src/**/*.js" ] }, @@ -174,7 +174,7 @@ "modulePaths": { "crm": "client/modules/crm" }, - "allPatterns": [ + "lookupPatterns": [ "client/src/**/*.js" ] } diff --git a/js/bundler-general.js b/js/bundler-general.js index 7460a2a302..124bedff5e 100644 --- a/js/bundler-general.js +++ b/js/bundler-general.js @@ -36,14 +36,14 @@ class BundlerGeneral { * chunks: Object., * modulePaths?: Record., - * allPatterns: string[], + * lookupPatterns: string[], * order: string[], * }} config * @param {{ @@ -97,7 +97,7 @@ class BundlerGeneral { let bundleFile = this.filePattern.replace('{*}', name); - let libs = this.config.chunks[name].libs; + let libs = this.config.chunks[name].requiredLibs; if (libs) { let part = JSON.stringify(libs.map(item => 'lib!' + item)); @@ -150,9 +150,9 @@ class BundlerGeneral { let params = this.config.chunks[name]; let patterns = params.patterns; - let allPatterns = [] - .concat(this.config.allPatterns) - .concat(params.allPatterns || []); + let lookupPatterns = [] + .concat(this.config.lookupPatterns) + .concat(params.lookupPatterns || []); let bundledFiles = []; let bundledTemplateFiles = []; @@ -171,7 +171,7 @@ class BundlerGeneral { let data = bundler.bundle({ files: params.files, patterns: patterns, - allPatterns: allPatterns, + lookupPatterns: lookupPatterns, libs: this.libs, ignoreFiles: ignoreFiles, dependentOn: params.dependentOn, diff --git a/js/bundler.js b/js/bundler.js index a7d588513c..917c8f4370 100644 --- a/js/bundler.js +++ b/js/bundler.js @@ -57,7 +57,7 @@ class Bundler { * @param {{ * files?: string[], * patterns: string[], - * allPatterns?: string[], + * lookupPatterns?: string[], * ignoreFiles?: string[], * dependentOn?: string[], * libs: { @@ -79,7 +79,7 @@ class Bundler { .concat(this.#obtainFiles(params.patterns, params.files)) .filter(file => !params.ignoreFiles.includes(file)); - let allFiles = this.#obtainFiles(params.allPatterns || params.patterns); + let allFiles = this.#obtainFiles(params.lookupPatterns || params.patterns); let ignoreLibs = params.libs .filter(item => item.key && !item.bundle) @@ -229,7 +229,7 @@ class Bundler { let modulePaths = modules.map(name => { if (!moduleFileMap[name]) { - throw Error(`Can't obtain ${name}. Might be missing in allPatterns.`); + throw Error(`Can't obtain ${name}. Might be missing in lookupPatterns.`); } return moduleFileMap[name];