@liferay/amd-loader
Version:
AMD Loader with support for combo URL and conditional loading
2 lines • 24.5 kB
JavaScript
(()=>{"use strict";(()=>{const e="5.4.2";var t=function e(){throw function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),new Error("Don't construct ResolvablePromise objects directly: rely on ResolvablePromise.new() instead")};function n(e){if(e.fulfilled)throw new Error("Promise already fulfilled")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}t.new=function(){var e={},t=new Promise((function(t,n){e._resolve=t,e._reject=n}));return Object.assign(t,e,{fulfilled:!1,rejected:!1,rejection:void 0,resolution:void 0,resolved:!1}),t.resolve=function(e){return function(e,t){n(e),e.fulfilled=!0,e.resolved=!0,e.resolution=t,e._resolve(t)}(t,e)},t.reject=function(e){return function(e,t){n(e),e.fulfilled=!0,e.rejected=!0,e.rejection=t,e._reject(t)}(t,e)},"undefined"!=typeof jest&&t.catch((function(){})),t};var o=function(){function e(n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._name=n,this._dependencies=void 0,this._factory=void 0,this._implementation={},this._useESM=!1,this._map=void 0,this._state={_define:t.new(),_fetch:t.new(),_implement:t.new()}}var n,o,i;return n=e,(o=[{key:"name",get:function(){return this._name},set:function(e){throw new Error("Name of module ".concat(this.name," is read-only"))}},{key:"dependencies",get:function(){return this._dependencies},set:function(e){if(this._dependencies)throw new Error("Dependencies of module ".concat(this.name," already set"));this._dependencies=e}},{key:"factory",get:function(){return this._factory},set:function(e){if(this._factory)throw new Error("Factory of module ".concat(this.name," already set"));this._factory=e}},{key:"implementation",get:function(){return this._implementation},set:function(e){this._implementation=e}},{key:"map",get:function(){return this._map},set:function(e){if(this._map)throw new Error("Local module map of module ".concat(this.name," already set"));this._map=e}},{key:"esModule",get:function(){return this._implementation.__esModule},set:function(e){Object.defineProperty(this._implementation,"__esModule",{configurable:!0,value:e,writable:!0})}},{key:"fetch",get:function(){return this._state._fetch}},{key:"fetched",get:function(){return this.fetch.resolved}},{key:"define",get:function(){return this._state._define}},{key:"defined",get:function(){return this.define.resolved}},{key:"implement",get:function(){return this._state._implement}},{key:"implemented",get:function(){return this.implement.resolved}},{key:"useESM",get:function(){return this._useESM},set:function(e){this._useESM=e}}])&&r(n.prototype,o),i&&r(n,i),e}();function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,o,i=[],a=!0,l=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){l=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(l)throw o}}return i}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return l(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var c=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};u(this,e),this._modules={},this._maps={},this._paths={},this._config={maps:{},paths:{}},this._parse(t,"defaultURLParams",{}),this._parse(t,"explainResolutions",!1),this._parse(t,"showWarnings",!1),this._parse(t,"waitTimeout",7e3),this._parse(t,"basePath","/"),this._parse(t,"resolvePath","/o/js_resolve_modules"),this._parse(t,"combine",!1),this._parse(t,"nonce",""),this._parse(t,"url",""),this._parse(t,"urlMaxLength",2e3),this._parse(t,"logLevel","error"),this._parse(t,"moduleType","module")}var t,n,r;return t=e,(n=[{key:"explainResolutions",get:function(){return this._config.explainResolutions}},{key:"showWarnings",get:function(){return this._config.showWarnings}},{key:"waitTimeout",get:function(){return this._config.waitTimeout}},{key:"basePath",get:function(){return this._config.basePath}},{key:"resolvePath",get:function(){return this._config.resolvePath}},{key:"combine",get:function(){return this._config.combine}},{key:"url",get:function(){return this._config.url}},{key:"urlMaxLength",get:function(){return this._config.urlMaxLength}},{key:"logLevel",get:function(){return this._config.logLevel}},{key:"moduleType",get:function(){return this._config.moduleType}},{key:"defaultURLParams",get:function(){return this._config.defaultURLParams}},{key:"paths",get:function(){return this._paths}},{key:"nonce",get:function(){return this._config.nonce}},{key:"addModule",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this._modules[e])throw new Error("Module is already registered: ".concat(e));var n=new o(e);return Object.entries(t).forEach((function(e){var t=a(e,2),r=t[0],o=t[1];n[r]=o})),this._modules[e]=n,n}},{key:"addMappings",value:function(e){Object.assign(this._maps,e)}},{key:"addPaths",value:function(e){Object.assign(this._paths,e)}},{key:"getModules",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;return void 0===t?Object.values(this._modules):t.map((function(t){return e.getModule(t)}))}},{key:"getModule",value:function(e){var t=this._modules[e];if(!t){var n=this._mapModule(e);t=this._modules[n]}return t}},{key:"getDependency",value:function(e,t){var n=this.getModule(e),r=this._modules[t];if(!r){var o=this._mapModule(t,n.map);r=this._modules[o]}return r}},{key:"updateResolvePath",value:function(e){var t="".concat(window.location.protocol,"//").concat(window.location.host);e.startsWith(t)&&(e=e.substr(t.length)),this._config.resolvePath=e}},{key:"_parse",value:function(e,t,n){this._config[t]=Object.prototype.hasOwnProperty.call(e,t)?e[t]:n}},{key:"_mapModule",value:function(e,t){return t&&(e=this._mapMatches(e,t)),Object.keys(this._maps).length&&(e=this._mapMatches(e,this._maps)),e}},{key:"_mapMatches",value:function(e,t){var n=t[e];return n?"object"===i(n)?n.value:n:((n=this._mapExactMatch(e,t))||(n=this._mapPartialMatch(e,t)),n||(n=this._mapWildcardMatch(e,t)),n||e)}},{key:"_mapExactMatch",value:function(e,t){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var r=t[n];if(r.value&&r.exactMatch&&e===n)return r.value}}},{key:"_mapPartialMatch",value:function(e,t){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var r=t[n];if(!r.exactMatch&&(r.value&&(r=r.value),e===n||0===e.indexOf(n+"/")))return r+e.substring(n.length)}}},{key:"_mapWildcardMatch",value:function(e,t){if("function"==typeof t["*"])return t["*"](e)}}])&&s(t.prototype,n),r&&s(t,r),e}();function f(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function h(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?f(Object(n),!0).forEach((function(t){d(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var m=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._config=t,this._cachedResolutions={}}var t,n,r;return t=e,(n=[{key:"resolve",value:function(e){var t=this;if(void 0===e||!e.length)throw new Error("Argument 'modules' cannot be undefined or empty");var n=this._config;return new Promise((function(r,o){var i=t._cachedResolutions[e];if(i)r(i);else{var a="modules=".concat(encodeURIComponent(e)),l="".concat(n.resolvePath,"?").concat(a),u={redirect:"follow"};l.length>n.urlMaxLength&&(l=n.resolvePath,u=h(h({},u),{},{body:a,method:"POST"})),fetch(l,u).then((function(n){n.redirected?(t._config.updateResolvePath(n.url),t.resolve(e).then(r).catch(o)):n.text().then((function(n){var o=JSON.parse(n);t._cachedResolutions[e]=o,r(o)})).catch(o)})).catch(o)}}))}}])&&p(t.prototype,n),r&&p(t,r),e}();function g(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var v={off:0,error:1,warn:2,info:3,debug:4},y="liferay-amd-loader |",_=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._config=t}var t,n,r;return t=e,(n=[{key:"error",value:function(){var e;if(this._applies("error")){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(e=console).error.apply(e,[y].concat(n))}}},{key:"warn",value:function(){var e;if(this._applies("warn")){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(e=console).warn.apply(e,[y].concat(n))}}},{key:"info",value:function(){var e;if(this._applies("info")){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(e=console).info.apply(e,[y].concat(n))}}},{key:"debug",value:function(){var e;if(this._applies("debug")){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(e=console).debug.apply(e,[y].concat(n))}}},{key:"resolution",value:function(){var e;if(this._config.explainResolutions){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(e=console).log.apply(e,[y].concat(n))}}},{key:"_applies",value:function(e){var t=v[this._config.logLevel];return v[e]<=t}}])&&g(t.prototype,n),r&&g(t,r),e}();function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?w(Object(n),!0).forEach((function(t){k(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function k(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var j=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._config=t}var t,n,r;return t=e,(n=[{key:"build",value:function(e){var t=this._config,n=[],r=e.filter((function(e){return!t.getModule(e).useESM}));n=n.concat(this._build(r));var o=e.filter((function(e){return t.getModule(e).useESM})),i=this._build(o).map((function(e){return b(b({},e),{},{useESM:!0})}));return n=n.concat(i)}},{key:"_build",value:function(e){var t=this,n=this._config,r=[],o=[],i=[],a=n.basePath;return a.length&&"/"!==a.charAt(a.length-1)&&(a+="/"),e.forEach((function(e){var l=n.getModule(e),u=t._getModulePath(l);n.combine?(r.push(u),o.push(l.name)):i.push({modules:[l.name],url:t._getURLWithParams(n.url+a+u)})})),r.length&&(i=i.concat(this._generateBufferURLs(o,r,{basePath:a,url:n.url,urlMaxLength:n.urlMaxLength})),r.length=0),i}},{key:"_generateBufferURLs",value:function(e,t,n){for(var r=n.basePath,o=[],i=n.urlMaxLength,a={modules:[e[0]],url:n.url+r+t[0]},l=1;l<t.length;l++){var u=e[l],s=t[l];a.url.length+r.length+s.length+1<i?(a.modules.push(u),a.url+="&"+r+s):(o.push(a),a={modules:[u],url:n.url+r+s})}return a.url=this._getURLWithParams(a.url),o.push(a),o}},{key:"_getModulePath",value:function(e){var t=this._config.paths,n=e.name;return Object.keys(t).forEach((function(e){n!==e&&0!==n.indexOf(e+"/")||(n=t[e]+n.substring(e.length))})),n.lastIndexOf(".js")!==n.length-3&&(n+=".js"),n}},{key:"_getURLWithParams",value:function(e){var t=this._config.defaultURLParams||{},n=Object.keys(t);if(!n.length)return e;var r=n.map((function(e){return e+"="+t[e]})).join("&");return e+(e.indexOf("?")>-1?"&":"?")+r}}])&&M(t.prototype,n),r&&M(t,r),e}();function O(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var P=function(){function e(t,n,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._document=t,this._config=n,this._log=r,this._urlBuilder=new j(n),this._injectedScripts={}}var t,n,r;return t=e,(n=[{key:"loadModules",value:function(e){var t=this,n=this._urlBuilder;if(!e.length)return Promise.resolve();var r=n.build(e).map((function(e){return t._loadScript(e)}));return Promise.all(r)}},{key:"_loadScript",value:function(e){var t=this,n=this._config,r=n.getModules(e.modules),o=this._injectedScripts[e.url];return o||((o=this._document.createElement("script")).src=e.url,o.async=!1,n.nonce&&o.setAttribute("nonce",n.nonce),e.useESM&&(o.type=n.moduleType),o.onload=o.onreadystatechange=function(){t.readyState&&"complete"!==t.readyState&&"load"!==t.readyState||(o.onload=o.onreadystatechange=null,o.onerror=null,r.forEach((function(e){e.fetch.fulfilled?t._log.warn("Module '".concat(e.name,"' is being fetched from\n"),o.src,"but was already fetched from\n",e.fetch.resolved?e.fetch.resolution.src:e.fetch.rejection.script.src):e.fetch.resolve(o)})))},o.onerror=function(){o.onload=o.onreadystatechange=null,o.onerror=null;var t=Object.assign(new Error("Unable to load script from URL ".concat(e.url)),{modules:e.modules,script:o,url:e.url});r.forEach((function(e){return e.fetch.reject(t)}))},this._injectedScripts[e.url]=o,this._document.head.appendChild(o)),Promise.all(r.map((function(e){return e.fetch})))}}])&&O(t.prototype,n),r&&O(t,r),e}();function E(e){return function(e){if(Array.isArray(e))return S(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return S(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return S(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function L(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function R(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var T=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;L(this,t),this._config=new c(e||window.__CONFIG__),this._log=new _(this._config),this._dependencyResolver=new m(this._config),this._urlBuilder=new j(this._config),this._scriptLoader=new P(n||window.document,this._config,this._log),this._requireCallId=0}var n,r,o;return n=t,(r=[{key:"version",value:function(){return e}},{key:"define",value:function(){for(var e=this._config,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var o=n[0],i=e.getModule(o);if(i&&i.defined)this._log.warn("Module '".concat(o,"' is being redefined. Only the first"),"definition will be used");else{var a=n[1],l=n[2];if(2===n.length&&(l=a,a=["require","exports","module"]),"function"!=typeof l){var u=l;l=function(){return u}}if(!(i=e.getModule(o)))throw new Error("Trying to define a module that was not registered: ".concat(o,"\n")+"This usually means that someone is calling define() for a module that has not been previously required.");if(i.defined)throw new Error("Trying to define a module more than once: ".concat(o,"\n")+"This usually means that someone is calling define() more than once for the same module, which can lead to unexpected results.");this._log.resolution("Defining",i.name),i.factory=l,i.dependencies=a,i.define.resolve(n)}}},{key:"require",value:function(){for(var e,t,n,r,o,i,a=this,l=this._scriptLoader,u=this._config,s=this._requireCallId++,c=arguments.length,f=new Array(c),h=0;h<c;h++)f[h]=arguments[h];if(1===f.length)e=f[0],t=void 0,n=void 0;else if(2===f.length){var d=f[f.length-1];"function"==typeof d?(e=f[0],t=d,n=void 0):null==d?(e=f[0],t=void 0,n=void 0):(e=f,t=void 0,n=void 0)}else{var p=f[f.length-1],m=!1;if("function"!=typeof p&&null!=p||(m=!0),m){var g=f[f.length-2],v=!1;"function"!=typeof g&&null!=g||(v=!0),v?(e=f.slice(0,f.length-2),t=g,n=p):(e=f.slice(0,f.length-1),t=p,n=void 0)}else e=f,t=void 0,n=void 0}if("string"==typeof e)e=[e];else if(1===e.length&&Array.isArray(e[0])){var y;e=(y=[]).concat.apply(y,E(e))}if(void 0===t&&(t=function(){}),void 0===n){var _=new Error("");n=function(t){var n="(n/a)";_.stack&&(n=_.stack.split("\n").map((function(e){return" ".concat(e)})).join("\n"),n="\n".concat(n)),a._log.error("\n","A require() call has failed but no failure handler was","provided.\n","Note that even if the call stack of this error trace","looks like coming from the Liferay AMD Loader, it is not","an error in the Loader what has caused it, but an error","caused by the require() call.\n","The reason why the Loader is in the stack trace is","because it is printing the error so that it doesn't get","lost.\n","However, we recommend providing a failure handler in all","require() calls to be able to recover from errors better","and to avoid the appearance of this message.\n","\n","Some information about the require() call follows:\n"," · Require call id:",s,"\n"," · Required modules:",e,"\n"," · Missing modules:",t.missingModules?t.missingModules:"(n/a)","\n"," · Stack trace of the require() call:","".concat(n),"\n",t)}}t=this._interceptHandler(t,"success",s),n=this._interceptHandler(n,"failure",s);var w=!1;this._dependencyResolver.resolve(e).then((function(t){if(a._log.resolution("Require call",s,"resolved modules",e,"to",t),a._throwOnLegacyProtocolResolutionErrors(t),a._logServerMessages(e,t),t.errors&&t.errors.length>1)throw Object.assign(new Error("The server generated some errors while resolving modules"),{resolutionErrors:t.errors});return u.addMappings(t.configMap),u.addPaths(t.pathMap),r=t.resolvedModules,(o=a._getUnregisteredModuleNames(r)).forEach((function(e){var n={map:t.moduleMap[e]},r=t.moduleFlags?t.moduleFlags[e]:{};(r=r||{}).esModule&&(n.esModule=!0),r.useESM&&(n.useESM=!0),u.addModule(e,n)})),i=a._setRejectTimeout(e,t,(function(){w=!0,n.apply(void 0,arguments)})),a._log.resolution("Fetching",o,"from require call",s),l.loadModules(o)})).then((function(){if(!w)return a._waitForModuleDefinitions(r)})).then((function(){if(!w){clearTimeout(i),a._setModuleImplementations(s,r);var n=a._getModuleImplementations(e);t.apply(void 0,E(n))}})).catch((function(e){w||(i&&clearTimeout(i),n(e))}))}},{key:"_interceptHandler",value:function(e,t,n){var r=this;return function(){r._log.resolution("Invoking",t,"handler for","require call",n);try{e.apply(void 0,arguments)}catch(e){r._log.error("\n","A require() call",t,"handler has thrown an error.\n","Note that even if the call stack of this error trace","looks like coming from the Liferay AMD Loader, it is not","an error in the Loader what has caused it, but an error","in the handler's code.\n","The reason why the Loader is in the stack trace is","because it is printing the error on behalf of the handler","so that it doesn't get lost.\n","However, we recommend wrapping all handler code inside a","try/catch to be able to recover from errors better and to","avoid the appearance of this message.\n","\n",e)}}}},{key:"_getUnregisteredModuleNames",value:function(e){var t=this._config;return e.filter((function(e){return!t.getModule(e)}))}},{key:"_logServerMessages",value:function(e,t){t.errors&&t.errors.length&&this._log.error("Errors returned from server for require(",e,"):",t.errors),t.warnings&&t.warnings.length&&this._log.warn("Warnings returned from server for require(",e,"):",t.warnings)}},{key:"_setRejectTimeout",value:function(e,t,n){var r=this._config;if(0!==r.waitTimeout)return setTimeout((function(){var o=t.resolvedModules.filter((function(e){var t=r.getModule(e);return!t||!t.implemented})),i=Object.assign(new Error("Load timeout for modules: "+e),{missingModules:o,modules:e,resolution:t});n(i)}),r.waitTimeout)}},{key:"_throwOnLegacyProtocolResolutionErrors",value:function(e){var t=e.resolvedModules.filter((function(e){return 0===e.indexOf(":ERROR:")})).map((function(e){return e.substr(7)}));if(t.length)throw Object.assign(new Error("The following problems where detected while resolving modules:\n"+t.map((function(e){return" · ".concat(e)})).join("\n")),{resolutionErrors:t})}},{key:"_waitForModuleDefinitions",value:function(e){var t=this._config;return Promise.all(t.getModules(e).map((function(e){return e.define})))}},{key:"_waitForModuleImplementations",value:function(e){var t=this._config;return Promise.all(t.getModules(e).map((function(e){return e.implement})))}},{key:"_setModuleImplementations",value:function(e,t){var n=this,r=this._config;r.getModules(t).forEach((function(t){if(!t.implemented){if(t.implement.rejected)throw t.implement.rejection;n._log.resolution("Implementing",t.name,"from require call",e);try{var o={get exports(){return t.implementation},set exports(e){t.implementation=e}},i=t.dependencies.map((function(e){if("exports"===e)return o.exports;if("module"===e)return o;if("require"===e)return n._createLocalRequire(t);var i=r.getDependency(t.name,e);if(!i)throw new Error("Unsatisfied dependency: ".concat(e," ")+"found in module ".concat(t.name));if(!i.implementation&&!i.implemented)throw new Error('Module "'+i.name+'" has not been loaded yet for context: '+t.name);return i.implementation})),a=t.factory.apply(t,E(i));void 0!==a&&(t.implementation=a),t.implement.resolve(t.implementation)}catch(e){throw t.implement.fulfilled||t.implement.reject(e),e}}}))}},{key:"_createLocalRequire",value:function(e){var t=this,n=this._config,r=function(r){for(var o=arguments.length,i=new Array(o>1?o-1:0),a=1;a<o;a++)i[a-1]=arguments[a];if(i.length)return t.require.apply(t,[r].concat(i));var l=n.getDependency(e.name,r);if(!l||!("implementation"in l))throw new Error('Module "'+r+'" has not been loaded yet for context: '+e.name);return l.implementation};return r.toUrl=function(e){return t._urlBuilder.build([e])[0].url},r}},{key:"_getModuleImplementations",value:function(e){return this._config.getModules(e).map((function(e){return e.implementation}))}}])&&R(n.prototype,r),o&&R(n,o),t}();T.prototype.define.amd={};var x=window.__CONFIG__||{},A="string"==typeof x.namespace?x.namespace:void 0,q=void 0===x.exposeGlobal||x.exposeGlobal,I=new T(x);if(A){var D=window[A]?window[A]:{};D.Loader=I,window[A]=D}else window.Loader=I;q&&(window.Loader=I,window.require=T.prototype.require.bind(I),window.define=T.prototype.define.bind(I),window.define.amd={})})()})();
//# sourceMappingURL=loader-min.js.map