@lwrjs/loader 0.6.0-alpha.3 → 0.6.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +13 -5
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +2 -2
- package/build/assets/prod/lwr-loader-shim-legacy.js +12 -4
- package/build/assets/prod/lwr-loader-shim.bundle.js +69 -8
- package/build/assets/prod/lwr-loader-shim.bundle.min.js +2 -2
- package/build/assets/prod/lwr-loader-shim.js +46 -4
- package/build/cjs/modules/lwr/loader/constants/constants.cjs +8 -0
- package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +3 -0
- package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +4 -0
- package/build/modules/lwr/esmLoader/esmLoader.js +1 -1
- package/build/modules/lwr/loader/loader.js +23 -4
- package/build/modules/lwr/loaderLegacy/loaderLegacy.js +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -353,6 +353,8 @@ type CustomInitAPI = {
|
|
|
353
353
|
initializeApp: InitializeApp;
|
|
354
354
|
// register bootstrap error state callback
|
|
355
355
|
onBootstrapError: RegisterBootstrapErrorHandler;
|
|
356
|
+
// Register a dispatcher for the metrics profiler
|
|
357
|
+
attachDispatcher: (dispatcher: LogDispatcher) => void;
|
|
356
358
|
// A convenience pointer to the globally available LWR.define
|
|
357
359
|
define: Function;
|
|
358
360
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Legacy Module Loader Shim v0.6.0-alpha.
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.6.0-alpha.7 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -36,6 +36,13 @@
|
|
|
36
36
|
|
|
37
37
|
const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
|
|
38
38
|
|
|
39
|
+
var Phase;
|
|
40
|
+
(function (Phase) {
|
|
41
|
+
Phase[Phase["Start"] = 0] = "Start";
|
|
42
|
+
})(Phase || (Phase = {}));
|
|
43
|
+
function attachDispatcher(dispatcher) {
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
// Check for errors with autoBoot and customInit
|
|
40
47
|
function validatePreInit(autoBoot, customInit) {
|
|
41
48
|
// If autoBoot === false, there must be a customInit hook
|
|
@@ -58,6 +65,7 @@
|
|
|
58
65
|
initializeApp,
|
|
59
66
|
define,
|
|
60
67
|
onBootstrapError,
|
|
68
|
+
attachDispatcher,
|
|
61
69
|
};
|
|
62
70
|
customInit(lwr, config);
|
|
63
71
|
}
|
|
@@ -75,7 +83,7 @@
|
|
|
75
83
|
// Parse configuration
|
|
76
84
|
this.global = global;
|
|
77
85
|
this.config = global.LWR;
|
|
78
|
-
this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-
|
|
86
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_7';
|
|
79
87
|
// Set up the temporary LWR.define function and customInit hook
|
|
80
88
|
const tempDefine = this.tempDefine.bind(this);
|
|
81
89
|
global.LWR.define = tempDefine;
|
|
@@ -214,14 +222,14 @@
|
|
|
214
222
|
// The loader module is ALWAYS required
|
|
215
223
|
const GLOBAL = globalThis;
|
|
216
224
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
217
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-
|
|
218
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-
|
|
225
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_7') < 0) {
|
|
226
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_7');
|
|
219
227
|
}
|
|
220
228
|
new LoaderShim(GLOBAL);
|
|
221
229
|
|
|
222
230
|
}());
|
|
223
231
|
|
|
224
|
-
LWR.define('lwr/loaderLegacy/v/0_6_0-
|
|
232
|
+
LWR.define('lwr/loaderLegacy/v/0_6_0-alpha_7', ['exports'], function (exports) { 'use strict';
|
|
225
233
|
|
|
226
234
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
227
235
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Legacy Module Loader Shim v0.6.0-alpha.
|
|
8
|
-
!function(){"use strict";function e(e,t,r,o){const{autoBoot:s,customInit:n}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(s,n),n){n({initializeApp:t,define:r,onBootstrapError:o},e)}}const t="function"==typeof setTimeout,r="undefined"!=typeof console;const o=globalThis;o.LWR.requiredModules=o.LWR.requiredModules||[],o.LWR.requiredModules.indexOf("lwr/loaderLegacy/v/0_6_0-alpha_3")<0&&o.LWR.requiredModules.push("lwr/loaderLegacy/v/0_6_0-alpha_3"),new class{constructor(r){this.defineCache={},this.orderedDefs=[],this.global=r,this.config=r.LWR,this.loaderModule="lwr/loaderLegacy/v/0_6_0-alpha_3";const o=this.tempDefine.bind(this);r.LWR.define=o,this.bootReady=this.config.autoBoot,t&&(this.watchdogTimerId=this.startWatchdogTimer());try{e(Object.freeze(this.config),this.postCustomInit.bind(this),o,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every((e=>this.orderedDefs.includes(e)));return this.bootReady&&e}tempDefine(...e){const r=e[0];this.defineCache[r]=e,this.orderedDefs.push(r),this.canInit()&&(t&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const s={};t[2].call(null,s);const{Loader:n}=s,i=new n(r);return o&&o.length&&i.registerExternalModules(o),i.define(e,["exports"],(e=>{Object.assign(e,{define:i.define.bind(i),load:i.load.bind(i),services:i.services})}),t[3]),i}(this.loaderModule,this.defineCache[this.loaderModule],this.config.baseUrl,this.config.preloadModules);this.mountApp(e)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,importMappings:o,rootComponents:s,endpoints:n}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:s,importMappings:o,endpoints:n}),this.orderedDefs.forEach((t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])}));const{disableInitDefer:i}=this.config;e.registerImportMappings(o).then((()=>{if(!i)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))}))}enterErrorState(e){this.errorHandler?this.errorHandler(e):r&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))}),3e5)}}(o)}(),LWR.define("lwr/loaderLegacy/v/0_6_0-alpha_3",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),BAD_IMPORT_MAP=Object.freeze({code:3011,level:0,message:"import map is not valid"}),hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const s=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let i=-1;for(let e=0;e<s.length;e++)-1!==i?"/"===s[e]&&(n.push(s.slice(i,e+1)),i=-1):"."===s[e]?"."!==s[e+1]||"/"!==s[e+2]&&e+2!==s.length?"/"===s[e+1]||e+1===s.length?e+=1:i=e:(n.pop(),e+=2):i=e;return-1!==i&&n.push(s.slice(i)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0})).finally((()=>{}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const s=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(s)}))})):t}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldHash:o,newHash:s}=t;for(let t=0;t<e.length;t++){const n=e[t];try{if(null!==n({name:r,oldHash:o,newHash:s}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.baseUrl=e}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.baseUrl;let o,s=e;const n=this.resolveHook;if(n){for(let e=0;e<n.length;e++){const t=(0,n[e])(s,{parentUrl:r});let i;if((t||null===t)&&(i=isResponseAPromise(t)?await t:t),null!==i){if("string"==typeof i){if(resolveIfNotPlainOrUrl(i,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);s=i;continue}if(o=i&&i.url&&(resolveIfNotPlainOrUrl(i.url,r)||i.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(s!==e){if(!o&&this.namedDefineRegistry.has(s))return s;e=s}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;if(this.resolver){if(o=this.resolver.resolve(t,r),this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){const e=this.moduleRegistry.get(o);if(!e||!e.aliases.has(t))return t}}else o=t}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r,o){const s=this.namedDefineRegistry.get(e);if(s&&s.defined)return void(this.lastDefine=s);const n={name:e,dependencies:t,exporter:r,signatures:o,defined:!0};s&&s.external&&s.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n,o.hashes&&Object.entries(o.hashes).forEach((([e,t])=>{this.checkModuleSignature(e,t)}))}registerExternalModules(e){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise(((o,s)=>{t=o,r=setTimeout((()=>{s(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),s={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,s)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}checkModuleSignature(e,t){const r=this.namedDefineRegistry.get(e);if(!r){const r={name:e,signatures:{ownHash:t},defined:!1};return void this.namedDefineRegistry.set(e,r)}const o=r.signatures?r.signatures.ownHash:void 0;if(o&&t!==o){const r=this.handleStaleModuleHook;r?evaluateHandleStaleModuleHooks(r,{name:e,oldHash:o,newHash:t}):hasConsole&&console.warn(`stale module detected ${e}, current sig:${o}, new sig:${t}`)}}setImportResolver(e){this.resolver=e}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r.aliases.has(t)||r.aliases.add(t),r;const o=this.getModuleDef(e,t),s=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)}));return r={id:e,aliases:new Set([t]),module:Object.create(null),dependencyRecords:s,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:s}=await e.instantiation,n={},i=await Promise.all(s.map((async e=>{if("exports"===e)return n;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...i);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(n)&&Object.defineProperty(n,"__useDefault",{value:!0});const l=a||n;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const s=this.baseUrl;return Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,s),n=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===n)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(n&&null!==n)return evaluateLoadHookResponse(n,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o})).catch((e=>{throw e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t])}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}function getMatch(e,t){if(t[e])return e;let r=e.length;do{const o=e.slice(0,r+1);if(o in t)return o}while(-1!==(r=e.lastIndexOf("/",r-1)))}function targetWarning(e,t,r){hasConsole&&console.warn("Package target "+r+", resolving target '"+t+"' for "+e)}function applyPackages(e,t,r){const o=getMatch(e,t);if(o){const r=t[o];if(null===r)return;if(!(e.length>o.length&&"/"!==r[r.length-1])){return e.length>o.length&&"/"===r[r.length-1]&&r.lastIndexOf(o)===r.length-o.length?r.substring(0,r.lastIndexOf(o))+encodeURIComponent(e):r+e.slice(o.length)}targetWarning(o,r,"should have a trailing '/'")}else if(r&&!isUrl(e))return r+encodeURIComponent(e)}function resolveImportMapEntry(e,t,r){e.scopes||(e.scopes={}),e.imports||(e.imports={});const o=e.scopes;let s=r&&getMatch(r,o);for(;s;){const e=applyPackages(t,o[s]);if(e)return e;s=getMatch(s.slice(0,s.lastIndexOf("/")),o)}return applyPackages(t,e.imports,e.default)||isUrl(t)&&t||void 0}function resolveAndComposePackages(e,t,r,o,s){for(const n in e){const i=resolveIfNotPlainOrUrl(n,r)||n,a=e[n];if("string"!=typeof a)continue;const l=resolveImportMapEntry(o,resolveIfNotPlainOrUrl(a,r)||a,s);l?t[i]=l:targetWarning(n,a,"bare specifier did not resolve")}}function resolveAndComposeImportMap(e,t,r={imports:{},scopes:{}}){const o={imports:Object.assign({},r.imports),scopes:Object.assign({},r.scopes),default:e.default};if(e.imports&&resolveAndComposePackages(e.imports,o.imports,t,r),e.scopes)for(const s in e.scopes){const n=resolveUrl(s,t);resolveAndComposePackages(e.scopes[s],o.scopes[n]||(o.scopes[n]={}),t,r,n)}return e.default&&(o.default=resolveIfNotPlainOrUrl(e.default,t)),o}class ImportMapResolver{constructor(e){this.importMap=e}resolve(e,t){return resolveImportMapEntry(this.importMap,e,t)}}const IMPORTMAP_SCRIPT_TYPE="lwr-importmap";function iterateDocumentImportMaps(e,t){const r=document.querySelectorAll(`script[type="${IMPORTMAP_SCRIPT_TYPE}"]`+t),o=Array.from(r).filter((e=>!e.src||(hasConsole&&console.warn("LWR does not support import maps from script src"),!1)));Array.prototype.forEach.call(o,e)}async function getImportMapFromScript(e){return Promise.resolve(e.innerHTML)}async function evaluateImportMaps(e){let t={imports:{},scopes:{}},r=Promise.resolve(t);if(hasDocument){if(e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);iterateDocumentImportMaps((o=>{r=r.then((()=>getImportMapFromScript(o))).then((e=>{try{return JSON.parse(e)}catch(e){throw new LoaderError(BAD_IMPORT_MAP)}})).then((r=>(t=resolveAndComposeImportMap(r,o.src||e,t),t)))}),"")}return r}class Loader{constructor(e){if(e&&(e=e.replace(/\/?$/,"/")),e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);this.baseUrl=e,this.registry=new ModuleRegistry(e),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r,o){invariant("string"==typeof e,MISSING_NAME);let s=r,n=t,i=o;"function"==typeof n&&(s=t,n=[],i=r),i=i||{},invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,s,i)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e){let t;if(t=e?resolveAndComposeImportMap(e,this.baseUrl,this.parentImportMap):await evaluateImportMaps(this.baseUrl),this.parentImportMap=t,this.parentImportMap){const e=new ImportMapResolver(this.parentImportMap);this.registry.setImportResolver(e)}}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.6.0-alpha.7 */
|
|
8
|
+
!function(){"use strict";var e;function t(e){}function r(e,r,o,s){const{autoBoot:n,customInit:i}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(n,i),i){i({initializeApp:r,define:o,onBootstrapError:s,attachDispatcher:t},e)}}!function(e){e[e.Start=0]="Start"}(e||(e={}));const o="function"==typeof setTimeout,s="undefined"!=typeof console;const n=globalThis;n.LWR.requiredModules=n.LWR.requiredModules||[],n.LWR.requiredModules.indexOf("lwr/loaderLegacy/v/0_6_0-alpha_7")<0&&n.LWR.requiredModules.push("lwr/loaderLegacy/v/0_6_0-alpha_7"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderModule="lwr/loaderLegacy/v/0_6_0-alpha_7";const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot,o&&(this.watchdogTimerId=this.startWatchdogTimer());try{r(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every((e=>this.orderedDefs.includes(e)));return this.bootReady&&e}tempDefine(...e){const t=e[0];this.defineCache[t]=e,this.orderedDefs.push(t),this.canInit()&&(o&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const s={};t[2].call(null,s);const{Loader:n}=s,i=new n(r);return o&&o.length&&i.registerExternalModules(o),i.define(e,["exports"],(e=>{Object.assign(e,{define:i.define.bind(i),load:i.load.bind(i),services:i.services})}),t[3]),i}(this.loaderModule,this.defineCache[this.loaderModule],this.config.baseUrl,this.config.preloadModules);this.mountApp(e)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,importMappings:o,rootComponents:s,endpoints:n}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:s,importMappings:o,endpoints:n}),this.orderedDefs.forEach((t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])}));const{disableInitDefer:i}=this.config;e.registerImportMappings(o).then((()=>{if(!i)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))}))}enterErrorState(e){this.errorHandler?this.errorHandler(e):s&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))}),3e5)}}(n)}(),LWR.define("lwr/loaderLegacy/v/0_6_0-alpha_7",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),BAD_IMPORT_MAP=Object.freeze({code:3011,level:0,message:"import map is not valid"}),hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const s=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let i=-1;for(let e=0;e<s.length;e++)-1!==i?"/"===s[e]&&(n.push(s.slice(i,e+1)),i=-1):"."===s[e]?"."!==s[e+1]||"/"!==s[e+2]&&e+2!==s.length?"/"===s[e+1]||e+1===s.length?e+=1:i=e:(n.pop(),e+=2):i=e;return-1!==i&&n.push(s.slice(i)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0})).finally((()=>{}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const s=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(s)}))})):t}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldHash:o,newHash:s}=t;for(let t=0;t<e.length;t++){const n=e[t];try{if(null!==n({name:r,oldHash:o,newHash:s}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.baseUrl=e}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.baseUrl;let o,s=e;const n=this.resolveHook;if(n){for(let e=0;e<n.length;e++){const t=(0,n[e])(s,{parentUrl:r});let i;if((t||null===t)&&(i=isResponseAPromise(t)?await t:t),null!==i){if("string"==typeof i){if(resolveIfNotPlainOrUrl(i,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);s=i;continue}if(o=i&&i.url&&(resolveIfNotPlainOrUrl(i.url,r)||i.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(s!==e){if(!o&&this.namedDefineRegistry.has(s))return s;e=s}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;if(this.resolver){if(o=this.resolver.resolve(t,r),this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){const e=this.moduleRegistry.get(o);if(!e||!e.aliases.has(t))return t}}else o=t}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r,o){const s=this.namedDefineRegistry.get(e);if(s&&s.defined)return void(this.lastDefine=s);const n={name:e,dependencies:t,exporter:r,signatures:o,defined:!0};s&&s.external&&s.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n,o.hashes&&Object.entries(o.hashes).forEach((([e,t])=>{this.checkModuleSignature(e,t)}))}registerExternalModules(e){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise(((o,s)=>{t=o,r=setTimeout((()=>{s(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),s={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,s)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}checkModuleSignature(e,t){const r=this.namedDefineRegistry.get(e);if(!r){const r={name:e,signatures:{ownHash:t},defined:!1};return void this.namedDefineRegistry.set(e,r)}const o=r.signatures?r.signatures.ownHash:void 0;if(o&&t!==o){const r=this.handleStaleModuleHook;r?evaluateHandleStaleModuleHooks(r,{name:e,oldHash:o,newHash:t}):hasConsole&&console.warn(`stale module detected ${e}, current sig:${o}, new sig:${t}`)}}setImportResolver(e){this.resolver=e}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r.aliases.has(t)||r.aliases.add(t),r;const o=this.getModuleDef(e,t),s=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)}));return r={id:e,aliases:new Set([t]),module:Object.create(null),dependencyRecords:s,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:s}=await e.instantiation,n={},i=await Promise.all(s.map((async e=>{if("exports"===e)return n;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...i);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(n)&&Object.defineProperty(n,"__useDefault",{value:!0});const l=a||n;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const s=this.baseUrl;return Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,s),n=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===n)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(n&&null!==n)return evaluateLoadHookResponse(n,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o})).catch((e=>{throw e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t])}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}function getMatch(e,t){if(t[e])return e;let r=e.length;do{const o=e.slice(0,r+1);if(o in t)return o}while(-1!==(r=e.lastIndexOf("/",r-1)))}function targetWarning(e,t,r){hasConsole&&console.warn("Package target "+r+", resolving target '"+t+"' for "+e)}function applyPackages(e,t,r){const o=getMatch(e,t);if(o){const r=t[o];if(null===r)return;if(!(e.length>o.length&&"/"!==r[r.length-1])){return e.length>o.length&&"/"===r[r.length-1]&&r.lastIndexOf(o)===r.length-o.length?r.substring(0,r.lastIndexOf(o))+encodeURIComponent(e):r+e.slice(o.length)}targetWarning(o,r,"should have a trailing '/'")}else if(r&&!isUrl(e))return r+encodeURIComponent(e)}function resolveImportMapEntry(e,t,r){e.scopes||(e.scopes={}),e.imports||(e.imports={});const o=e.scopes;let s=r&&getMatch(r,o);for(;s;){const e=applyPackages(t,o[s]);if(e)return e;s=getMatch(s.slice(0,s.lastIndexOf("/")),o)}return applyPackages(t,e.imports,e.default)||isUrl(t)&&t||void 0}function resolveAndComposePackages(e,t,r,o,s){for(const n in e){const i=resolveIfNotPlainOrUrl(n,r)||n,a=e[n];if("string"!=typeof a)continue;const l=resolveImportMapEntry(o,resolveIfNotPlainOrUrl(a,r)||a,s);l?t[i]=l:targetWarning(n,a,"bare specifier did not resolve")}}function resolveAndComposeImportMap(e,t,r={imports:{},scopes:{}}){const o={imports:Object.assign({},r.imports),scopes:Object.assign({},r.scopes),default:e.default};if(e.imports&&resolveAndComposePackages(e.imports,o.imports,t,r),e.scopes)for(const s in e.scopes){const n=resolveUrl(s,t);resolveAndComposePackages(e.scopes[s],o.scopes[n]||(o.scopes[n]={}),t,r,n)}return e.default&&(o.default=resolveIfNotPlainOrUrl(e.default,t)),o}class ImportMapResolver{constructor(e){this.importMap=e}resolve(e,t){return resolveImportMapEntry(this.importMap,e,t)}}const IMPORTMAP_SCRIPT_TYPE="lwr-importmap";function iterateDocumentImportMaps(e,t){const r=document.querySelectorAll(`script[type="${IMPORTMAP_SCRIPT_TYPE}"]`+t),o=Array.from(r).filter((e=>!e.src||(hasConsole&&console.warn("LWR does not support import maps from script src"),!1)));Array.prototype.forEach.call(o,e)}async function getImportMapFromScript(e){return Promise.resolve(e.innerHTML)}async function evaluateImportMaps(e){let t={imports:{},scopes:{}},r=Promise.resolve(t);if(hasDocument){if(e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);iterateDocumentImportMaps((o=>{r=r.then((()=>getImportMapFromScript(o))).then((e=>{try{return JSON.parse(e)}catch(e){throw new LoaderError(BAD_IMPORT_MAP)}})).then((r=>(t=resolveAndComposeImportMap(r,o.src||e,t),t)))}),"")}return r}class Loader{constructor(e){if(e&&(e=e.replace(/\/?$/,"/")),e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);this.baseUrl=e,this.registry=new ModuleRegistry(e),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r,o){invariant("string"==typeof e,MISSING_NAME);let s=r,n=t,i=o;"function"==typeof n&&(s=t,n=[],i=r),i=i||{},invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,s,i)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e){let t;if(t=e?resolveAndComposeImportMap(e,this.baseUrl,this.parentImportMap):await evaluateImportMaps(this.baseUrl),this.parentImportMap=t,this.parentImportMap){const e=new ImportMapResolver(this.parentImportMap);this.registry.setImportResolver(e)}}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Legacy Module Loader Shim v0.6.0-alpha.
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.6.0-alpha.7 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -36,6 +36,13 @@
|
|
|
36
36
|
|
|
37
37
|
const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
|
|
38
38
|
|
|
39
|
+
var Phase;
|
|
40
|
+
(function (Phase) {
|
|
41
|
+
Phase[Phase["Start"] = 0] = "Start";
|
|
42
|
+
})(Phase || (Phase = {}));
|
|
43
|
+
function attachDispatcher(dispatcher) {
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
// Check for errors with autoBoot and customInit
|
|
40
47
|
function validatePreInit(autoBoot, customInit) {
|
|
41
48
|
// If autoBoot === false, there must be a customInit hook
|
|
@@ -58,6 +65,7 @@
|
|
|
58
65
|
initializeApp,
|
|
59
66
|
define,
|
|
60
67
|
onBootstrapError,
|
|
68
|
+
attachDispatcher,
|
|
61
69
|
};
|
|
62
70
|
customInit(lwr, config);
|
|
63
71
|
}
|
|
@@ -75,7 +83,7 @@
|
|
|
75
83
|
// Parse configuration
|
|
76
84
|
this.global = global;
|
|
77
85
|
this.config = global.LWR;
|
|
78
|
-
this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-
|
|
86
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_7';
|
|
79
87
|
// Set up the temporary LWR.define function and customInit hook
|
|
80
88
|
const tempDefine = this.tempDefine.bind(this);
|
|
81
89
|
global.LWR.define = tempDefine;
|
|
@@ -214,8 +222,8 @@
|
|
|
214
222
|
// The loader module is ALWAYS required
|
|
215
223
|
const GLOBAL = globalThis;
|
|
216
224
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
217
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-
|
|
218
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-
|
|
225
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_7') < 0) {
|
|
226
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_7');
|
|
219
227
|
}
|
|
220
228
|
new LoaderShim(GLOBAL);
|
|
221
229
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Module Loader Shim v0.6.0-alpha.
|
|
7
|
+
/* LWR Module Loader Shim v0.6.0-alpha.7 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -34,6 +34,36 @@
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
|
|
37
|
+
const METRIC_INIT = 'lwr.bootstrap.init';
|
|
38
|
+
const METRIC_APP = 'lwr.bootstrap.application';
|
|
39
|
+
const METRIC_ERROR = 'lwr.bootstrap.error';
|
|
40
|
+
|
|
41
|
+
var Phase;
|
|
42
|
+
(function (Phase) {
|
|
43
|
+
Phase[Phase["Start"] = 0] = "Start";
|
|
44
|
+
})(Phase || (Phase = {}));
|
|
45
|
+
// Attach a custom dispatcher
|
|
46
|
+
let customDispatcher;
|
|
47
|
+
function attachDispatcher(dispatcher) {
|
|
48
|
+
customDispatcher = dispatcher;
|
|
49
|
+
}
|
|
50
|
+
// Check if the Performance API is available
|
|
51
|
+
// e.g. JSDom (used in Jest) doesn't implement these
|
|
52
|
+
const isPerfSupported = typeof globalThis.performance !== 'undefined' && typeof globalThis.performance.mark === 'function';
|
|
53
|
+
// For marking request metrics
|
|
54
|
+
// Fallback to the Performance API if there is no custom dispatcher
|
|
55
|
+
function logOperationStart({ id, specifier }) {
|
|
56
|
+
if (customDispatcher) {
|
|
57
|
+
customDispatcher({ id, phase: Phase.Start, specifier });
|
|
58
|
+
}
|
|
59
|
+
else if (isPerfSupported) {
|
|
60
|
+
globalThis.performance.mark(id + (specifier ? `.${specifier}` : ''));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function getProfilerAPI() {
|
|
64
|
+
// Create the public Profiler API
|
|
65
|
+
return { logOperationStart: logOperationStart.bind(this) };
|
|
66
|
+
}
|
|
37
67
|
|
|
38
68
|
// Check for errors with autoBoot and customInit
|
|
39
69
|
function validatePreInit(autoBoot, customInit) {
|
|
@@ -57,6 +87,7 @@
|
|
|
57
87
|
initializeApp,
|
|
58
88
|
define,
|
|
59
89
|
onBootstrapError,
|
|
90
|
+
attachDispatcher,
|
|
60
91
|
};
|
|
61
92
|
customInit(lwr, config);
|
|
62
93
|
}
|
|
@@ -74,7 +105,9 @@
|
|
|
74
105
|
// Parse configuration
|
|
75
106
|
this.global = global;
|
|
76
107
|
this.config = global.LWR;
|
|
77
|
-
this.loaderModule = 'lwr/loader/v/0_6_0-
|
|
108
|
+
this.loaderModule = 'lwr/loader/v/0_6_0-alpha_7';
|
|
109
|
+
// Set up the profiler for instrumentation
|
|
110
|
+
this.profiler = getProfilerAPI();
|
|
78
111
|
// Set up the temporary LWR.define function and customInit hook
|
|
79
112
|
const tempDefine = this.tempDefine.bind(this);
|
|
80
113
|
global.LWR.define = tempDefine;
|
|
@@ -87,6 +120,10 @@
|
|
|
87
120
|
customInit(Object.freeze(this.config), this.postCustomInit.bind(this), tempDefine, (e) => {
|
|
88
121
|
this.errorHandler = e;
|
|
89
122
|
});
|
|
123
|
+
// Mark "bootstrap init" here so:
|
|
124
|
+
// - a custom dispatcher set in customInit receives the log
|
|
125
|
+
// - the customInit duration is excluded from the "bootstrap init" duration
|
|
126
|
+
this.profiler.logOperationStart({ id: METRIC_INIT });
|
|
90
127
|
}
|
|
91
128
|
catch (e) {
|
|
92
129
|
this.enterErrorState(e);
|
|
@@ -136,6 +173,7 @@
|
|
|
136
173
|
const loaderConfig = {
|
|
137
174
|
endpoints: this.config.endpoints,
|
|
138
175
|
baseUrl: this.config.baseUrl,
|
|
176
|
+
profiler: this.profiler,
|
|
139
177
|
};
|
|
140
178
|
const loader = createLoader(this.loaderModule, this.defineCache[this.loaderModule], loaderConfig, this.config.preloadModules);
|
|
141
179
|
this.mountApp(loader);
|
|
@@ -188,6 +226,9 @@
|
|
|
188
226
|
if (!disableInitDefer) {
|
|
189
227
|
return this.waitForDOMContentLoaded();
|
|
190
228
|
}
|
|
229
|
+
})
|
|
230
|
+
.then(() => {
|
|
231
|
+
this.profiler.logOperationStart({ id: METRIC_APP });
|
|
191
232
|
})
|
|
192
233
|
.then(() => loader.load(bootstrapModule))
|
|
193
234
|
.catch((reason) => {
|
|
@@ -196,6 +237,7 @@
|
|
|
196
237
|
}
|
|
197
238
|
// Trigger bootstrap error state, and call error handler if registered
|
|
198
239
|
enterErrorState(error) {
|
|
240
|
+
this.profiler.logOperationStart({ id: METRIC_ERROR });
|
|
199
241
|
if (this.errorHandler) {
|
|
200
242
|
this.errorHandler(error);
|
|
201
243
|
}
|
|
@@ -218,14 +260,14 @@
|
|
|
218
260
|
// The loader module is ALWAYS required
|
|
219
261
|
const GLOBAL = globalThis;
|
|
220
262
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
221
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-
|
|
222
|
-
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-
|
|
263
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_7') < 0) {
|
|
264
|
+
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_7');
|
|
223
265
|
}
|
|
224
266
|
new LoaderShim(GLOBAL);
|
|
225
267
|
|
|
226
268
|
}());
|
|
227
269
|
|
|
228
|
-
LWR.define('lwr/loader/v/0_6_0-
|
|
270
|
+
LWR.define('lwr/loader/v/0_6_0-alpha_7', ['exports'], function (exports) { 'use strict';
|
|
229
271
|
|
|
230
272
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
231
273
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -522,6 +564,12 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
522
564
|
});
|
|
523
565
|
}
|
|
524
566
|
|
|
567
|
+
const MODULE_LOAD_TIMEOUT_TIMER = 300000;
|
|
568
|
+
const METRIC_MODULE_FETCH = 'lwr.loader.module.fetch';
|
|
569
|
+
const METRIC_MAPPINGS_FETCH = 'lwr.loader.mappings.fetch';
|
|
570
|
+
const METRIC_MODULE_ERROR = 'lwr.loader.module.error';
|
|
571
|
+
const METRIC_MAPPINGS_ERROR = 'lwr.loader.mappings.error';
|
|
572
|
+
|
|
525
573
|
/* spec based import map resolver */
|
|
526
574
|
class ImportMetadataResolver {
|
|
527
575
|
constructor(config, invalidationCallback) {
|
|
@@ -637,6 +685,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
637
685
|
if (pending) {
|
|
638
686
|
return pending;
|
|
639
687
|
}
|
|
688
|
+
this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_FETCH, specifier });
|
|
640
689
|
const fetchMappingService = this.hasMappingHooks()
|
|
641
690
|
? this.evaluateMappingHooks
|
|
642
691
|
: this.fetchNewMappings;
|
|
@@ -695,6 +744,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
695
744
|
const uri = resolveUrl(this.buildMappingUrl(specifier), this.getBaseUrl());
|
|
696
745
|
return globalThis.fetch(uri).then((res) => {
|
|
697
746
|
if (!res.ok) {
|
|
747
|
+
this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_ERROR, specifier });
|
|
698
748
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
699
749
|
}
|
|
700
750
|
return res
|
|
@@ -748,8 +798,6 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
748
798
|
}
|
|
749
799
|
}
|
|
750
800
|
|
|
751
|
-
const MODULE_LOAD_TIMEOUT_TIMER = 300000;
|
|
752
|
-
|
|
753
801
|
let lastWindowError;
|
|
754
802
|
if (hasDocument) {
|
|
755
803
|
globalThis.addEventListener('error', (evt) => {
|
|
@@ -842,6 +890,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
842
890
|
this.namedDefineRegistry = new Map();
|
|
843
891
|
// The evaluted module registry where the module identifier (name or URL?) is the key
|
|
844
892
|
this.moduleRegistry = new Map();
|
|
893
|
+
this.profiler = config.profiler;
|
|
845
894
|
this.resolver = new ImportMetadataResolver(config, this.importMetadataInvalidationCallback.bind(this));
|
|
846
895
|
}
|
|
847
896
|
async load(id, importer) {
|
|
@@ -1192,6 +1241,8 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
1192
1241
|
return moduleDef;
|
|
1193
1242
|
}
|
|
1194
1243
|
const parentUrl = this.resolver.getBaseUrl(); // only support baseUrl for now
|
|
1244
|
+
const specifier = moduleName || originalId;
|
|
1245
|
+
this.profiler.logOperationStart({ id: METRIC_MODULE_FETCH, specifier });
|
|
1195
1246
|
return Promise.resolve()
|
|
1196
1247
|
.then(async () => {
|
|
1197
1248
|
const loadHooks = this.loadHook;
|
|
@@ -1232,6 +1283,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
1232
1283
|
return moduleDef;
|
|
1233
1284
|
})
|
|
1234
1285
|
.catch((e) => {
|
|
1286
|
+
this.profiler.logOperationStart({ id: METRIC_MODULE_ERROR, specifier });
|
|
1235
1287
|
throw e;
|
|
1236
1288
|
});
|
|
1237
1289
|
}
|
|
@@ -1293,6 +1345,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
1293
1345
|
constructor(config) {
|
|
1294
1346
|
let baseUrl = config.baseUrl;
|
|
1295
1347
|
const mappingEndpoint = config.endpoints ? config.endpoints.uris.mapping : undefined;
|
|
1348
|
+
let profiler = config.profiler;
|
|
1296
1349
|
if (!mappingEndpoint) {
|
|
1297
1350
|
throw new LoaderError(NO_MAPPING_URL);
|
|
1298
1351
|
}
|
|
@@ -1308,7 +1361,15 @@ LWR.define('lwr/loader/v/0_6_0-alpha_3', ['exports'], function (exports) { 'use
|
|
|
1308
1361
|
if (!baseUrl) {
|
|
1309
1362
|
throw new LoaderError(NO_BASE_URL);
|
|
1310
1363
|
}
|
|
1311
|
-
|
|
1364
|
+
if (!profiler) {
|
|
1365
|
+
// default noop profiler
|
|
1366
|
+
profiler = {
|
|
1367
|
+
logOperationStart: () => {
|
|
1368
|
+
/* noop */
|
|
1369
|
+
},
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
this.registry = new ModuleRegistry(Object.freeze({ endpoints: config.endpoints, baseUrl, profiler }));
|
|
1312
1373
|
this.services = Object.freeze({
|
|
1313
1374
|
addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
|
|
1314
1375
|
handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Module Loader Shim v0.6.0-alpha.
|
|
8
|
-
!function(){"use strict";function e(e,t,r,o){const{autoBoot:n,customInit:s}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(n,s),s){s({initializeApp:t,define:r,onBootstrapError:o},e)}}const t="function"==typeof setTimeout,r="undefined"!=typeof console;const o=globalThis;o.LWR.requiredModules=o.LWR.requiredModules||[],o.LWR.requiredModules.indexOf("lwr/loader/v/0_6_0-alpha_3")<0&&o.LWR.requiredModules.push("lwr/loader/v/0_6_0-alpha_3"),new class{constructor(r){this.defineCache={},this.orderedDefs=[],this.global=r,this.config=r.LWR,this.loaderModule="lwr/loader/v/0_6_0-alpha_3";const o=this.tempDefine.bind(this);r.LWR.define=o,this.bootReady=this.config.autoBoot,t&&(this.watchdogTimerId=this.startWatchdogTimer());try{e(Object.freeze(this.config),this.postCustomInit.bind(this),o,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every((e=>this.orderedDefs.includes(e)));return this.bootReady&&e}tempDefine(...e){const r=e[0];this.defineCache[r]=e,this.orderedDefs.push(r),this.canInit()&&(t&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e={endpoints:this.config.endpoints,baseUrl:this.config.baseUrl},t=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const n={};t[2].call(null,n);const{Loader:s}=n,i=new s(r);return o&&o.length&&i.registerExternalModules(o),i.define(e,["exports"],(e=>{Object.assign(e,{define:i.define.bind(i),load:i.load.bind(i),services:i.services})})),i}(this.loaderModule,this.defineCache[this.loaderModule],e,this.config.preloadModules);this.mountApp(t)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,endpoints:n,imports:s,index:i}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,endpoints:n,imports:s||{},index:i||{}}),this.orderedDefs.forEach((t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])}));const{disableInitDefer:a}=this.config;e.registerImportMappings({imports:s,index:i},[t,r]).then((()=>{if(!a)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))}))}enterErrorState(e){this.errorHandler?this.errorHandler(e):r&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))}),3e5)}}(o)}(),LWR.define("lwr/loader/v/0_6_0-alpha_3",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const n=o.slice(0,o.lastIndexOf("/")+1)+e,s=[];let i=-1;for(let e=0;e<n.length;e++)-1!==i?"/"===n[e]&&(s.push(n.slice(i,e+1)),i=-1):"."===n[e]?"."!==n[e+1]||"/"!==n[e+2]&&e+2!==n.length?"/"===n[e+1]||e+1===n.length?e+=1:i=e:(s.pop(),e+=2):i=e;return-1!==i&&s.push(n.slice(i)),t.slice(0,t.length-o.length)+s.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));class ImportMetadataResolver{constructor(e,t){this.importURICache=new Map,this.pendingURICache=new Map,this.loadMappingHooks=[],this.config=e,this.invalidationCallback=t}addLoadMappingHook(e){this.loadMappingHooks.push(e)}getMappingEndpoint(){return this.config.endpoints&&this.config.endpoints.uris?this.config.endpoints.uris.mapping:void 0}getModifiersAsUrlParams(){const e=this.config.endpoints?this.config.endpoints.modifiers:void 0;if(e){return`?${Object.keys(e).map((t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}`}return""}buildMappingUrl(e){return`${this.getMappingEndpoint()}${encodeURIComponent(e)}${this.getModifiersAsUrlParams()}`}getBaseUrl(){return this.config.baseUrl}registerImportMappings(e,t){if(!t||0===t.length){const r=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[r,t?"[]":"undefined"])}if(!e)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);if(!e.imports||0===Object.keys(e.imports).length)throw new LoaderError(BAD_IMPORT_METADATA,[JSON.stringify(e),JSON.stringify(t)]);const r=e.index||{};for(const[o,n]of Object.entries(e.imports))n.forEach((e=>{const n=r[e],s=this.importURICache.get(e);if(s){const t=n||o,r=s.identity||s.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,n,t.includes(e))}))}getURI(e){return this.importURICache.has(e)?resolveUrl(this.importURICache.get(e).uri,this.getBaseUrl()):void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then((r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return t})).finally((()=>{this.pendingURICache.delete(e)}));return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const n=t[o],s=await n(e,{knownModules:r});if(s||void 0===s)return s}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then((t=>{if(!t.ok)throw new LoaderError(UNRESOLVED,[e]);return t.json().then((e=>e)).catch((t=>{throw new LoaderError(UNRESOLVED,[e])}))}))}saveImportURIRecord(e,t,r,o){r&&t!==r?this.importURICache.set(e,{uri:t,identity:r,isRoot:o}):this.importURICache.set(e,{uri:t,isRoot:o})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:n}=t;for(let t=0;t<e.length;t++){const s=e[t];try{if(null!==s({name:r,oldUrl:o,newUrl:n}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0})).finally((()=>{}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const n=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(n)}))})):t}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,n=e;const s=this.resolveHook;if(s){for(let e=0;e<s.length;e++){const t=(0,s[e])(n,{parentUrl:r});let i;if((t||null===t)&&(i=isResponseAPromise(t)?await t:t),null!==i){if("string"==typeof i){if(resolveIfNotPlainOrUrl(i,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);n=i;continue}if(o=i&&i.url&&(resolveIfNotPlainOrUrl(i.url,r)||i.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(n!==e){if(!o&&this.namedDefineRegistry.has(n))return n;e=n}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const n=this.resolver.resolveLocal(t);if(n){if(this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){const e=this.moduleRegistry.get(n);if(!e||!e.aliases.has(t))return t}return n}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return void(this.lastDefine=o);const n={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n}registerExternalModules(e){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise(((o,n)=>{t=o,r=setTimeout((()=>{n(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),n={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,n)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}getImportMetadataResolver(){return this.resolver}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r.aliases.has(t)||r.aliases.add(t),r;const o=this.getModuleDef(e,t),n=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)}));return r={id:e,aliases:new Set([t]),module:Object.create(null),dependencyRecords:n,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:n}=await e.instantiation,s={},i=await Promise.all(n.map((async e=>{if("exports"===e)return s;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...i);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(s)&&Object.defineProperty(s,"__useDefault",{value:!0});const l=a||s;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const n=this.resolver.getBaseUrl();return Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,n),s=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===s)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(s&&null!==s)return evaluateLoadHookResponse(s,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o})).catch((e=>{throw e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o?evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r}):hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${r}`)}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t})),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,n=t;"function"==typeof n&&(o=t,n=[]),invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
7
|
+
/* LWR Module Loader Shim v0.6.0-alpha.7 */
|
|
8
|
+
!function(){"use strict";var e;let t;function r(e){t=e}!function(e){e[e.Start=0]="Start"}(e||(e={}));const o=void 0!==globalThis.performance&&"function"==typeof globalThis.performance.mark;function i({id:r,specifier:i}){t?t({id:r,phase:e.Start,specifier:i}):o&&globalThis.performance.mark(r+(i?`.${i}`:""))}function n(e,t,o,i){const{autoBoot:n,customInit:s}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(n,s),s){s({initializeApp:t,define:o,onBootstrapError:i,attachDispatcher:r},e)}}const s="function"==typeof setTimeout,a="undefined"!=typeof console;const l=globalThis;l.LWR.requiredModules=l.LWR.requiredModules||[],l.LWR.requiredModules.indexOf("lwr/loader/v/0_6_0-alpha_7")<0&&l.LWR.requiredModules.push("lwr/loader/v/0_6_0-alpha_7"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderModule="lwr/loader/v/0_6_0-alpha_7",this.profiler=function(){return{logOperationStart:i.bind(this)}}();const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot,s&&(this.watchdogTimerId=this.startWatchdogTimer());try{n(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e})),this.profiler.logOperationStart({id:"lwr.bootstrap.init"})}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every((e=>this.orderedDefs.includes(e)));return this.bootReady&&e}tempDefine(...e){const t=e[0];this.defineCache[t]=e,this.orderedDefs.push(t),this.canInit()&&(s&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e={endpoints:this.config.endpoints,baseUrl:this.config.baseUrl,profiler:this.profiler},t=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const i={};t[2].call(null,i);const{Loader:n}=i,s=new n(r);return o&&o.length&&s.registerExternalModules(o),s.define(e,["exports"],(e=>{Object.assign(e,{define:s.define.bind(s),load:s.load.bind(s),services:s.services})})),s}(this.loaderModule,this.defineCache[this.loaderModule],e,this.config.preloadModules);this.mountApp(t)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,endpoints:i,imports:n,index:s}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,endpoints:i,imports:n||{},index:s||{}}),this.orderedDefs.forEach((t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])}));const{disableInitDefer:a}=this.config;e.registerImportMappings({imports:n,index:s},[t,r]).then((()=>{if(!a)return this.waitForDOMContentLoaded()})).then((()=>{this.profiler.logOperationStart({id:"lwr.bootstrap.application"})})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))}))}enterErrorState(e){this.profiler.logOperationStart({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):a&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))}),3e5)}}(l)}(),LWR.define("lwr/loader/v/0_6_0-alpha_7",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const i=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let s=-1;for(let e=0;e<i.length;e++)-1!==s?"/"===i[e]&&(n.push(i.slice(s,e+1)),s=-1):"."===i[e]?"."!==i[e+1]||"/"!==i[e+2]&&e+2!==i.length?"/"===i[e+1]||e+1===i.length?e+=1:s=e:(n.pop(),e+=2):s=e;return-1!==s&&n.push(i.slice(s)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const MODULE_LOAD_TIMEOUT_TIMER=3e5,METRIC_MODULE_FETCH="lwr.loader.module.fetch",METRIC_MAPPINGS_FETCH="lwr.loader.mappings.fetch",METRIC_MODULE_ERROR="lwr.loader.module.error",METRIC_MAPPINGS_ERROR="lwr.loader.mappings.error";class ImportMetadataResolver{constructor(e,t){this.importURICache=new Map,this.pendingURICache=new Map,this.loadMappingHooks=[],this.config=e,this.invalidationCallback=t}addLoadMappingHook(e){this.loadMappingHooks.push(e)}getMappingEndpoint(){return this.config.endpoints&&this.config.endpoints.uris?this.config.endpoints.uris.mapping:void 0}getModifiersAsUrlParams(){const e=this.config.endpoints?this.config.endpoints.modifiers:void 0;if(e){return`?${Object.keys(e).map((t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}`}return""}buildMappingUrl(e){return`${this.getMappingEndpoint()}${encodeURIComponent(e)}${this.getModifiersAsUrlParams()}`}getBaseUrl(){return this.config.baseUrl}registerImportMappings(e,t){if(!t||0===t.length){const r=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[r,t?"[]":"undefined"])}if(!e)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);if(!e.imports||0===Object.keys(e.imports).length)throw new LoaderError(BAD_IMPORT_METADATA,[JSON.stringify(e),JSON.stringify(t)]);const r=e.index||{};for(const[o,i]of Object.entries(e.imports))i.forEach((e=>{const i=r[e],n=this.importURICache.get(e);if(n){const t=i||o,r=n.identity||n.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,i,t.includes(e))}))}getURI(e){return this.importURICache.has(e)?resolveUrl(this.importURICache.get(e).uri,this.getBaseUrl()):void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;this.config.profiler.logOperationStart({id:METRIC_MAPPINGS_FETCH,specifier:e});const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then((r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return t})).finally((()=>{this.pendingURICache.delete(e)}));return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const i=t[o],n=await i(e,{knownModules:r});if(n||void 0===n)return n}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then((t=>{if(!t.ok)throw this.config.profiler.logOperationStart({id:METRIC_MAPPINGS_ERROR,specifier:e}),new LoaderError(UNRESOLVED,[e]);return t.json().then((e=>e)).catch((t=>{throw new LoaderError(UNRESOLVED,[e])}))}))}saveImportURIRecord(e,t,r,o){r&&t!==r?this.importURICache.set(e,{uri:t,identity:r,isRoot:o}):this.importURICache.set(e,{uri:t,isRoot:o})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:i}=t;for(let t=0;t<e.length;t++){const n=e[t];try{if(null!==n({name:r,oldUrl:o,newUrl:i}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0})).finally((()=>{}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const i=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(i)}))})):t}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.profiler=e.profiler,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,i=e;const n=this.resolveHook;if(n){for(let e=0;e<n.length;e++){const t=(0,n[e])(i,{parentUrl:r});let s;if((t||null===t)&&(s=isResponseAPromise(t)?await t:t),null!==s){if("string"==typeof s){if(resolveIfNotPlainOrUrl(s,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);i=s;continue}if(o=s&&s.url&&(resolveIfNotPlainOrUrl(s.url,r)||s.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(i!==e){if(!o&&this.namedDefineRegistry.has(i))return i;e=i}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const i=this.resolver.resolveLocal(t);if(i){if(this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){const e=this.moduleRegistry.get(i);if(!e||!e.aliases.has(t))return t}return i}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return void(this.lastDefine=o);const i={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(i),this.namedDefineRegistry.set(e,i),this.lastDefine=i}registerExternalModules(e){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise(((o,i)=>{t=o,r=setTimeout((()=>{i(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),i={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,i)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}getImportMetadataResolver(){return this.resolver}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r.aliases.has(t)||r.aliases.add(t),r;const o=this.getModuleDef(e,t),i=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)}));return r={id:e,aliases:new Set([t]),module:Object.create(null),dependencyRecords:i,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:i}=await e.instantiation,n={},s=await Promise.all(i.map((async e=>{if("exports"===e)return n;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...s);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(n)&&Object.defineProperty(n,"__useDefault",{value:!0});const l=a||n;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const i=this.resolver.getBaseUrl(),n=r||t;return this.profiler.logOperationStart({id:METRIC_MODULE_FETCH,specifier:n}),Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,i),n=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===n)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(n&&null!==n)return evaluateLoadHookResponse(n,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o})).catch((e=>{throw this.profiler.logOperationStart({id:METRIC_MODULE_ERROR,specifier:n}),e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o?evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r}):hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${r}`)}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;let o=e.profiler;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);o||(o={logOperationStart:()=>{}}),this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t,profiler:o})),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,i=t;"function"==typeof i&&(o=t,i=[]),invariant(Array.isArray(i),INVALID_DEPS),this.registry.define(e,i,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Module Loader Shim v0.6.0-alpha.
|
|
7
|
+
/* LWR Module Loader Shim v0.6.0-alpha.7 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -34,6 +34,36 @@
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
|
|
37
|
+
const METRIC_INIT = 'lwr.bootstrap.init';
|
|
38
|
+
const METRIC_APP = 'lwr.bootstrap.application';
|
|
39
|
+
const METRIC_ERROR = 'lwr.bootstrap.error';
|
|
40
|
+
|
|
41
|
+
var Phase;
|
|
42
|
+
(function (Phase) {
|
|
43
|
+
Phase[Phase["Start"] = 0] = "Start";
|
|
44
|
+
})(Phase || (Phase = {}));
|
|
45
|
+
// Attach a custom dispatcher
|
|
46
|
+
let customDispatcher;
|
|
47
|
+
function attachDispatcher(dispatcher) {
|
|
48
|
+
customDispatcher = dispatcher;
|
|
49
|
+
}
|
|
50
|
+
// Check if the Performance API is available
|
|
51
|
+
// e.g. JSDom (used in Jest) doesn't implement these
|
|
52
|
+
const isPerfSupported = typeof globalThis.performance !== 'undefined' && typeof globalThis.performance.mark === 'function';
|
|
53
|
+
// For marking request metrics
|
|
54
|
+
// Fallback to the Performance API if there is no custom dispatcher
|
|
55
|
+
function logOperationStart({ id, specifier }) {
|
|
56
|
+
if (customDispatcher) {
|
|
57
|
+
customDispatcher({ id, phase: Phase.Start, specifier });
|
|
58
|
+
}
|
|
59
|
+
else if (isPerfSupported) {
|
|
60
|
+
globalThis.performance.mark(id + (specifier ? `.${specifier}` : ''));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function getProfilerAPI() {
|
|
64
|
+
// Create the public Profiler API
|
|
65
|
+
return { logOperationStart: logOperationStart.bind(this) };
|
|
66
|
+
}
|
|
37
67
|
|
|
38
68
|
// Check for errors with autoBoot and customInit
|
|
39
69
|
function validatePreInit(autoBoot, customInit) {
|
|
@@ -57,6 +87,7 @@
|
|
|
57
87
|
initializeApp,
|
|
58
88
|
define,
|
|
59
89
|
onBootstrapError,
|
|
90
|
+
attachDispatcher,
|
|
60
91
|
};
|
|
61
92
|
customInit(lwr, config);
|
|
62
93
|
}
|
|
@@ -74,7 +105,9 @@
|
|
|
74
105
|
// Parse configuration
|
|
75
106
|
this.global = global;
|
|
76
107
|
this.config = global.LWR;
|
|
77
|
-
this.loaderModule = 'lwr/loader/v/0_6_0-
|
|
108
|
+
this.loaderModule = 'lwr/loader/v/0_6_0-alpha_7';
|
|
109
|
+
// Set up the profiler for instrumentation
|
|
110
|
+
this.profiler = getProfilerAPI();
|
|
78
111
|
// Set up the temporary LWR.define function and customInit hook
|
|
79
112
|
const tempDefine = this.tempDefine.bind(this);
|
|
80
113
|
global.LWR.define = tempDefine;
|
|
@@ -87,6 +120,10 @@
|
|
|
87
120
|
customInit(Object.freeze(this.config), this.postCustomInit.bind(this), tempDefine, (e) => {
|
|
88
121
|
this.errorHandler = e;
|
|
89
122
|
});
|
|
123
|
+
// Mark "bootstrap init" here so:
|
|
124
|
+
// - a custom dispatcher set in customInit receives the log
|
|
125
|
+
// - the customInit duration is excluded from the "bootstrap init" duration
|
|
126
|
+
this.profiler.logOperationStart({ id: METRIC_INIT });
|
|
90
127
|
}
|
|
91
128
|
catch (e) {
|
|
92
129
|
this.enterErrorState(e);
|
|
@@ -136,6 +173,7 @@
|
|
|
136
173
|
const loaderConfig = {
|
|
137
174
|
endpoints: this.config.endpoints,
|
|
138
175
|
baseUrl: this.config.baseUrl,
|
|
176
|
+
profiler: this.profiler,
|
|
139
177
|
};
|
|
140
178
|
const loader = createLoader(this.loaderModule, this.defineCache[this.loaderModule], loaderConfig, this.config.preloadModules);
|
|
141
179
|
this.mountApp(loader);
|
|
@@ -188,6 +226,9 @@
|
|
|
188
226
|
if (!disableInitDefer) {
|
|
189
227
|
return this.waitForDOMContentLoaded();
|
|
190
228
|
}
|
|
229
|
+
})
|
|
230
|
+
.then(() => {
|
|
231
|
+
this.profiler.logOperationStart({ id: METRIC_APP });
|
|
191
232
|
})
|
|
192
233
|
.then(() => loader.load(bootstrapModule))
|
|
193
234
|
.catch((reason) => {
|
|
@@ -196,6 +237,7 @@
|
|
|
196
237
|
}
|
|
197
238
|
// Trigger bootstrap error state, and call error handler if registered
|
|
198
239
|
enterErrorState(error) {
|
|
240
|
+
this.profiler.logOperationStart({ id: METRIC_ERROR });
|
|
199
241
|
if (this.errorHandler) {
|
|
200
242
|
this.errorHandler(error);
|
|
201
243
|
}
|
|
@@ -218,8 +260,8 @@
|
|
|
218
260
|
// The loader module is ALWAYS required
|
|
219
261
|
const GLOBAL = globalThis;
|
|
220
262
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
221
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-
|
|
222
|
-
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-
|
|
263
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_7') < 0) {
|
|
264
|
+
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_7');
|
|
223
265
|
}
|
|
224
266
|
new LoaderShim(GLOBAL);
|
|
225
267
|
|
|
@@ -8,6 +8,14 @@ var __export = (target, all) => {
|
|
|
8
8
|
// packages/@lwrjs/loader/src/modules/lwr/loader/constants/constants.ts
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
|
+
METRIC_MAPPINGS_ERROR: () => METRIC_MAPPINGS_ERROR,
|
|
12
|
+
METRIC_MAPPINGS_FETCH: () => METRIC_MAPPINGS_FETCH,
|
|
13
|
+
METRIC_MODULE_ERROR: () => METRIC_MODULE_ERROR,
|
|
14
|
+
METRIC_MODULE_FETCH: () => METRIC_MODULE_FETCH,
|
|
11
15
|
MODULE_LOAD_TIMEOUT_TIMER: () => MODULE_LOAD_TIMEOUT_TIMER
|
|
12
16
|
});
|
|
13
17
|
var MODULE_LOAD_TIMEOUT_TIMER = 3e5;
|
|
18
|
+
var METRIC_MODULE_FETCH = "lwr.loader.module.fetch";
|
|
19
|
+
var METRIC_MAPPINGS_FETCH = "lwr.loader.mappings.fetch";
|
|
20
|
+
var METRIC_MODULE_ERROR = "lwr.loader.module.error";
|
|
21
|
+
var METRIC_MAPPINGS_ERROR = "lwr.loader.mappings.error";
|
|
@@ -28,6 +28,7 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_messages = __toModule(require("../errors/messages"));
|
|
30
30
|
var import_url = __toModule(require("../utils/url"));
|
|
31
|
+
var import_constants = __toModule(require("../constants/constants"));
|
|
31
32
|
var ImportMetadataResolver = class {
|
|
32
33
|
constructor(config, invalidationCallback) {
|
|
33
34
|
this.importURICache = new Map();
|
|
@@ -118,6 +119,7 @@ var ImportMetadataResolver = class {
|
|
|
118
119
|
if (pending) {
|
|
119
120
|
return pending;
|
|
120
121
|
}
|
|
122
|
+
this.config.profiler.logOperationStart({id: import_constants.METRIC_MAPPINGS_FETCH, specifier});
|
|
121
123
|
const fetchMappingService = this.hasMappingHooks() ? this.evaluateMappingHooks : this.fetchNewMappings;
|
|
122
124
|
const promise = fetchMappingService.bind(this)(specifier).then((importMetadata) => {
|
|
123
125
|
if (!importMetadata || !importMetadata.imports) {
|
|
@@ -160,6 +162,7 @@ var ImportMetadataResolver = class {
|
|
|
160
162
|
const uri = (0, import_url.resolveUrl)(this.buildMappingUrl(specifier), this.getBaseUrl());
|
|
161
163
|
return globalThis.fetch(uri).then((res) => {
|
|
162
164
|
if (!res.ok) {
|
|
165
|
+
this.config.profiler.logOperationStart({id: import_constants.METRIC_MAPPINGS_ERROR, specifier});
|
|
163
166
|
throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
|
|
164
167
|
}
|
|
165
168
|
return res.json().then((ret) => {
|
|
@@ -38,6 +38,7 @@ var ModuleRegistry = class {
|
|
|
38
38
|
constructor(config) {
|
|
39
39
|
this.namedDefineRegistry = new Map();
|
|
40
40
|
this.moduleRegistry = new Map();
|
|
41
|
+
this.profiler = config.profiler;
|
|
41
42
|
this.resolver = new import_importMetadataResolver.ImportMetadataResolver(config, this.importMetadataInvalidationCallback.bind(this));
|
|
42
43
|
}
|
|
43
44
|
async load(id, importer) {
|
|
@@ -322,6 +323,8 @@ var ModuleRegistry = class {
|
|
|
322
323
|
return moduleDef;
|
|
323
324
|
}
|
|
324
325
|
const parentUrl = this.resolver.getBaseUrl();
|
|
326
|
+
const specifier = moduleName || originalId;
|
|
327
|
+
this.profiler.logOperationStart({id: import_constants.METRIC_MODULE_FETCH, specifier});
|
|
325
328
|
return Promise.resolve().then(async () => {
|
|
326
329
|
const loadHooks = this.loadHook;
|
|
327
330
|
if (loadHooks) {
|
|
@@ -352,6 +355,7 @@ var ModuleRegistry = class {
|
|
|
352
355
|
}
|
|
353
356
|
return moduleDef;
|
|
354
357
|
}).catch((e) => {
|
|
358
|
+
this.profiler.logOperationStart({id: import_constants.METRIC_MODULE_ERROR, specifier});
|
|
355
359
|
throw e;
|
|
356
360
|
});
|
|
357
361
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR ESM Module Loader v0.6.0-alpha.
|
|
7
|
+
/* LWR ESM Module Loader v0.6.0-alpha.7 */
|
|
8
8
|
/**
|
|
9
9
|
* Simplified version of the AMD Import Metadata Resolver.
|
|
10
10
|
* Just reads the ImportMetadata at construction time.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Module Loader v0.6.0-alpha.
|
|
7
|
+
/* LWR Module Loader v0.6.0-alpha.7 */
|
|
8
8
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
function templateString(template, args) {
|
|
@@ -300,6 +300,12 @@ if (hasDocument) {
|
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
const MODULE_LOAD_TIMEOUT_TIMER = 300000;
|
|
304
|
+
const METRIC_MODULE_FETCH = 'lwr.loader.module.fetch';
|
|
305
|
+
const METRIC_MAPPINGS_FETCH = 'lwr.loader.mappings.fetch';
|
|
306
|
+
const METRIC_MODULE_ERROR = 'lwr.loader.module.error';
|
|
307
|
+
const METRIC_MAPPINGS_ERROR = 'lwr.loader.mappings.error';
|
|
308
|
+
|
|
303
309
|
/* spec based import map resolver */
|
|
304
310
|
class ImportMetadataResolver {
|
|
305
311
|
constructor(config, invalidationCallback) {
|
|
@@ -415,6 +421,7 @@ class ImportMetadataResolver {
|
|
|
415
421
|
if (pending) {
|
|
416
422
|
return pending;
|
|
417
423
|
}
|
|
424
|
+
this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_FETCH, specifier });
|
|
418
425
|
const fetchMappingService = this.hasMappingHooks()
|
|
419
426
|
? this.evaluateMappingHooks
|
|
420
427
|
: this.fetchNewMappings;
|
|
@@ -473,6 +480,7 @@ class ImportMetadataResolver {
|
|
|
473
480
|
const uri = resolveUrl(this.buildMappingUrl(specifier), this.getBaseUrl());
|
|
474
481
|
return globalThis.fetch(uri).then((res) => {
|
|
475
482
|
if (!res.ok) {
|
|
483
|
+
this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_ERROR, specifier });
|
|
476
484
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
477
485
|
}
|
|
478
486
|
return res
|
|
@@ -526,8 +534,6 @@ function evaluateHandleStaleModuleHooks(handleStaleModuleHooks, hookArgs) {
|
|
|
526
534
|
}
|
|
527
535
|
}
|
|
528
536
|
|
|
529
|
-
const MODULE_LOAD_TIMEOUT_TIMER = 300000;
|
|
530
|
-
|
|
531
537
|
let lastWindowError;
|
|
532
538
|
if (hasDocument) {
|
|
533
539
|
globalThis.addEventListener('error', (evt) => {
|
|
@@ -620,6 +626,7 @@ class ModuleRegistry {
|
|
|
620
626
|
this.namedDefineRegistry = new Map();
|
|
621
627
|
// The evaluted module registry where the module identifier (name or URL?) is the key
|
|
622
628
|
this.moduleRegistry = new Map();
|
|
629
|
+
this.profiler = config.profiler;
|
|
623
630
|
this.resolver = new ImportMetadataResolver(config, this.importMetadataInvalidationCallback.bind(this));
|
|
624
631
|
}
|
|
625
632
|
async load(id, importer) {
|
|
@@ -970,6 +977,8 @@ class ModuleRegistry {
|
|
|
970
977
|
return moduleDef;
|
|
971
978
|
}
|
|
972
979
|
const parentUrl = this.resolver.getBaseUrl(); // only support baseUrl for now
|
|
980
|
+
const specifier = moduleName || originalId;
|
|
981
|
+
this.profiler.logOperationStart({ id: METRIC_MODULE_FETCH, specifier });
|
|
973
982
|
return Promise.resolve()
|
|
974
983
|
.then(async () => {
|
|
975
984
|
const loadHooks = this.loadHook;
|
|
@@ -1010,6 +1019,7 @@ class ModuleRegistry {
|
|
|
1010
1019
|
return moduleDef;
|
|
1011
1020
|
})
|
|
1012
1021
|
.catch((e) => {
|
|
1022
|
+
this.profiler.logOperationStart({ id: METRIC_MODULE_ERROR, specifier });
|
|
1013
1023
|
throw e;
|
|
1014
1024
|
});
|
|
1015
1025
|
}
|
|
@@ -1071,6 +1081,7 @@ class Loader {
|
|
|
1071
1081
|
constructor(config) {
|
|
1072
1082
|
let baseUrl = config.baseUrl;
|
|
1073
1083
|
const mappingEndpoint = config.endpoints ? config.endpoints.uris.mapping : undefined;
|
|
1084
|
+
let profiler = config.profiler;
|
|
1074
1085
|
if (!mappingEndpoint) {
|
|
1075
1086
|
throw new LoaderError(NO_MAPPING_URL);
|
|
1076
1087
|
}
|
|
@@ -1086,7 +1097,15 @@ class Loader {
|
|
|
1086
1097
|
if (!baseUrl) {
|
|
1087
1098
|
throw new LoaderError(NO_BASE_URL);
|
|
1088
1099
|
}
|
|
1089
|
-
|
|
1100
|
+
if (!profiler) {
|
|
1101
|
+
// default noop profiler
|
|
1102
|
+
profiler = {
|
|
1103
|
+
logOperationStart: () => {
|
|
1104
|
+
/* noop */
|
|
1105
|
+
},
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
this.registry = new ModuleRegistry(Object.freeze({ endpoints: config.endpoints, baseUrl, profiler }));
|
|
1090
1109
|
this.services = Object.freeze({
|
|
1091
1110
|
addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
|
|
1092
1111
|
handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Legacy Module Loader v0.6.0-alpha.
|
|
7
|
+
/* LWR Legacy Module Loader v0.6.0-alpha.7 */
|
|
8
8
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
function templateString(template, args) {
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.6.0-alpha.
|
|
9
|
-
"homepage": "https://
|
|
8
|
+
"version": "0.6.0-alpha.7",
|
|
9
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/salesforce/lwr.git",
|
|
@@ -54,13 +54,13 @@
|
|
|
54
54
|
"build": "tsc -b; yarn build:shim && yarn build:loader && yarn build:shim:bundle && yarn build:shim:bundle:minify"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@lwrjs/compiler": "0.6.0-alpha.
|
|
58
|
-
"@lwrjs/diagnostics": "0.6.0-alpha.
|
|
59
|
-
"@lwrjs/types": "0.6.0-alpha.
|
|
57
|
+
"@lwrjs/compiler": "0.6.0-alpha.7",
|
|
58
|
+
"@lwrjs/diagnostics": "0.6.0-alpha.7",
|
|
59
|
+
"@lwrjs/types": "0.6.0-alpha.7",
|
|
60
60
|
"rollup-plugin-terser": "^7.0.2"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@lwrjs/shared-utils": "0.6.0-alpha.
|
|
63
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.7"
|
|
64
64
|
},
|
|
65
65
|
"lwc": {
|
|
66
66
|
"modules": [
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"engines": {
|
|
78
78
|
"node": ">=14.15.4 <17"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "dc066450384dc1e27064b46ddd5f24543758a414"
|
|
81
81
|
}
|