@lwrjs/loader 0.6.0-alpha.10 → 0.6.0-alpha.11

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.
@@ -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.10 */
7
+ /* LWR Legacy Module Loader Shim v0.6.0-alpha.11 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -39,6 +39,7 @@
39
39
  var Phase;
40
40
  (function (Phase) {
41
41
  Phase[Phase["Start"] = 0] = "Start";
42
+ Phase[Phase["End"] = 1] = "End";
42
43
  })(Phase || (Phase = {}));
43
44
  function attachDispatcher(dispatcher) {
44
45
  }
@@ -83,7 +84,7 @@
83
84
  // Parse configuration
84
85
  this.global = global;
85
86
  this.config = global.LWR;
86
- this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_10';
87
+ this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_11';
87
88
  // Set up the temporary LWR.define function and customInit hook
88
89
  const tempDefine = this.tempDefine.bind(this);
89
90
  global.LWR.define = tempDefine;
@@ -183,6 +184,16 @@
183
184
  loader.define(...this.defineCache[specifier]);
184
185
  }
185
186
  });
187
+ // Define a dummy profiler since the "lwr/profiler" module is used in "lwr/init" (which is global to all server modes)
188
+ const profilerExporter = (exports) => {
189
+ Object.assign(exports, {
190
+ logOperationStart: () => {
191
+ /* noop */
192
+ },
193
+ });
194
+ return;
195
+ };
196
+ loader.define('lwr/profiler/v/0_6_0-alpha_11', ['exports'], profilerExporter, {});
186
197
  // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
187
198
  const { disableInitDefer } = this.config;
188
199
  // Load the import mappings and application bootstrap module
@@ -222,14 +233,14 @@
222
233
  // The loader module is ALWAYS required
223
234
  const GLOBAL = globalThis;
224
235
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
225
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_10') < 0) {
226
- GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_10');
236
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_11') < 0) {
237
+ GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_11');
227
238
  }
228
239
  new LoaderShim(GLOBAL);
229
240
 
230
241
  }());
231
242
 
232
- LWR.define('lwr/loaderLegacy/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use strict';
243
+ LWR.define('lwr/loaderLegacy/v/0_6_0-alpha_11', ['exports'], function (exports) { 'use strict';
233
244
 
234
245
  const templateRegex = /\{([0-9]+)\}/g;
235
246
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -969,6 +980,9 @@ LWR.define('lwr/loaderLegacy/v/0_6_0-alpha_10', ['exports'], function (exports)
969
980
  if (moduleExports.__defaultInterop) {
970
981
  Object.defineProperty(moduleRecord.module, '__defaultInterop', { value: true });
971
982
  }
983
+ if (moduleExports.__esModule) {
984
+ Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
985
+ }
972
986
  moduleRecord.evaluated = true;
973
987
  Object.freeze(moduleRecord.module);
974
988
  return moduleRecord.module;
@@ -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.10 */
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_10")<0&&n.LWR.requiredModules.push("lwr/loaderLegacy/v/0_6_0-alpha_10"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderModule="lwr/loaderLegacy/v/0_6_0-alpha_10";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_10",["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.11 */
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.End=1]="End"}(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_11")<0&&n.LWR.requiredModules.push("lwr/loaderLegacy/v/0_6_0-alpha_11"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderModule="lwr/loaderLegacy/v/0_6_0-alpha_11";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])}));e.define("lwr/profiler/v/0_6_0-alpha_11",["exports"],(e=>{Object.assign(e,{logOperationStart:()=>{}})}),{});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_11",["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}),l.__esModule&&Object.defineProperty(e.module,"__esModule",{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.10 */
7
+ /* LWR Legacy Module Loader Shim v0.6.0-alpha.11 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -39,6 +39,7 @@
39
39
  var Phase;
40
40
  (function (Phase) {
41
41
  Phase[Phase["Start"] = 0] = "Start";
42
+ Phase[Phase["End"] = 1] = "End";
42
43
  })(Phase || (Phase = {}));
43
44
  function attachDispatcher(dispatcher) {
44
45
  }
@@ -83,7 +84,7 @@
83
84
  // Parse configuration
84
85
  this.global = global;
85
86
  this.config = global.LWR;
86
- this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_10';
87
+ this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_11';
87
88
  // Set up the temporary LWR.define function and customInit hook
88
89
  const tempDefine = this.tempDefine.bind(this);
89
90
  global.LWR.define = tempDefine;
@@ -183,6 +184,16 @@
183
184
  loader.define(...this.defineCache[specifier]);
184
185
  }
185
186
  });
187
+ // Define a dummy profiler since the "lwr/profiler" module is used in "lwr/init" (which is global to all server modes)
188
+ const profilerExporter = (exports) => {
189
+ Object.assign(exports, {
190
+ logOperationStart: () => {
191
+ /* noop */
192
+ },
193
+ });
194
+ return;
195
+ };
196
+ loader.define('lwr/profiler/v/0_6_0-alpha_11', ['exports'], profilerExporter, {});
186
197
  // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
187
198
  const { disableInitDefer } = this.config;
188
199
  // Load the import mappings and application bootstrap module
@@ -222,8 +233,8 @@
222
233
  // The loader module is ALWAYS required
223
234
  const GLOBAL = globalThis;
224
235
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
225
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_10') < 0) {
226
- GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_10');
236
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_11') < 0) {
237
+ GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_11');
227
238
  }
228
239
  new LoaderShim(GLOBAL);
229
240
 
@@ -4,10 +4,14 @@
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.10 */
7
+ /* LWR Module Loader Shim v0.6.0-alpha.11 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
11
+ // Bootstrap / shim
12
+ const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
13
+ const BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
14
+
11
15
  function createLoader(name, definition, config, externalModules) {
12
16
  if (!definition || typeof definition[2] !== 'function') {
13
17
  throw new Error(`Expected loader with specifier "${name}" to be a module`);
@@ -27,19 +31,17 @@
27
31
  load: loader.load.bind(loader),
28
32
  services: loader.services,
29
33
  });
30
- return;
31
34
  };
32
35
  loader.define(name, ['exports'], exporter);
33
36
  return loader;
34
37
  }
35
38
 
36
39
  const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
37
- const METRIC_END = 'lwr.bootstrap.end';
38
- const METRIC_ERROR = 'lwr.bootstrap.error';
39
40
 
40
41
  var Phase;
41
42
  (function (Phase) {
42
43
  Phase[Phase["Start"] = 0] = "Start";
44
+ Phase[Phase["End"] = 1] = "End";
43
45
  })(Phase || (Phase = {}));
44
46
  // Attach a custom dispatcher
45
47
  let customDispatcher;
@@ -48,7 +50,12 @@
48
50
  }
49
51
  // Check if the Performance API is available
50
52
  // e.g. JSDom (used in Jest) doesn't implement these
51
- const isPerfSupported = typeof globalThis.performance !== 'undefined' && typeof globalThis.performance.mark === 'function';
53
+ const perf = globalThis.performance;
54
+ const isPerfSupported = typeof perf !== 'undefined' &&
55
+ typeof perf.mark === 'function' &&
56
+ typeof perf.clearMarks === 'function' &&
57
+ typeof perf.measure === 'function' &&
58
+ typeof perf.clearMeasures === 'function';
52
59
  // For marking request metrics
53
60
  // Fallback to the Performance API if there is no custom dispatcher
54
61
  function logOperationStart({ id, specifier }) {
@@ -56,12 +63,26 @@
56
63
  customDispatcher({ id, phase: Phase.Start, specifier });
57
64
  }
58
65
  else if (isPerfSupported) {
59
- globalThis.performance.mark(id + (specifier ? `.${specifier}` : ''));
66
+ perf.mark(id + (specifier ? `.${specifier}` : ''));
60
67
  }
61
68
  }
62
- function getProfilerAPI() {
63
- // Create the public Profiler API
64
- return { logOperationStart: logOperationStart.bind(this) };
69
+ // For measuring duration metrics
70
+ // Fallback to the Performance API if there is no custom dispatcher
71
+ /* istanbul ignore next */
72
+ function logOperationEnd({ id, specifier }) {
73
+ if (customDispatcher) {
74
+ customDispatcher({ id, phase: Phase.End, specifier });
75
+ }
76
+ else if (isPerfSupported) {
77
+ const suffix = specifier ? `.${specifier}` : '';
78
+ const markName = id + suffix;
79
+ const measureName = `${id}.duration${suffix}`;
80
+ perf.measure(measureName, markName);
81
+ // Clear the created mark and measure to avoid filling the performance entry buffer
82
+ // Even if they get deleted, existing PerformanceObservers preserve copies of the entries
83
+ perf.clearMarks(markName);
84
+ perf.clearMeasures(measureName);
85
+ }
65
86
  }
66
87
 
67
88
  // Check for errors with autoBoot and customInit
@@ -104,9 +125,7 @@
104
125
  // Parse configuration
105
126
  this.global = global;
106
127
  this.config = global.LWR;
107
- this.loaderModule = 'lwr/loader/v/0_6_0-alpha_10';
108
- // Set up the profiler for instrumentation
109
- this.profiler = getProfilerAPI();
128
+ this.loaderSpecifier = 'lwr/loader/v/0_6_0-alpha_11';
110
129
  // Set up the temporary LWR.define function and customInit hook
111
130
  const tempDefine = this.tempDefine.bind(this);
112
131
  global.LWR.define = tempDefine;
@@ -168,9 +187,16 @@
168
187
  const loaderConfig = {
169
188
  endpoints: this.config.endpoints,
170
189
  baseUrl: this.config.baseUrl,
171
- profiler: this.profiler,
190
+ profiler: { logOperationStart, logOperationEnd },
191
+ // TODO: can be removed following https://github.com/salesforce/lwr/issues/1087
192
+ appMetadata: {
193
+ bootstrapModule: this.config.bootstrapModule,
194
+ rootComponent: this.config.rootComponent,
195
+ rootComponents: this.config.rootComponents,
196
+ },
172
197
  };
173
- const loader = createLoader(this.loaderModule, this.defineCache[this.loaderModule], loaderConfig, this.config.preloadModules);
198
+ const loader = createLoader(this.loaderSpecifier, this.defineCache[this.loaderSpecifier], loaderConfig, this.config.preloadModules);
199
+ this.createProfilerModule(loader);
174
200
  this.mountApp(loader);
175
201
  }
176
202
  catch (e) {
@@ -194,6 +220,14 @@
194
220
  });
195
221
  });
196
222
  }
223
+ // Create a module out of the profiler
224
+ // Note: The profiler is also available as a module through lwc module resolution (see package.json)
225
+ createProfilerModule(loader) {
226
+ const exporter = (exports) => {
227
+ Object.assign(exports, { logOperationStart, logOperationEnd });
228
+ };
229
+ loader.define('lwr/profiler/v/0_6_0-alpha_11', ['exports'], exporter);
230
+ }
197
231
  // Set up the application globals, import map, root custom element...
198
232
  mountApp(loader) {
199
233
  const { bootstrapModule, rootComponent, rootComponents, endpoints, imports, index } = this.config;
@@ -208,7 +242,7 @@
208
242
  });
209
243
  // Redefine all modules in the temporary cache
210
244
  this.orderedDefs.forEach((specifier) => {
211
- if (specifier !== this.loaderModule) {
245
+ if (specifier !== this.loaderSpecifier) {
212
246
  loader.define(...this.defineCache[specifier]);
213
247
  }
214
248
  });
@@ -223,16 +257,13 @@
223
257
  }
224
258
  })
225
259
  .then(() => loader.load(bootstrapModule))
226
- .then(() => {
227
- this.profiler.logOperationStart({ id: METRIC_END });
228
- })
229
260
  .catch((reason) => {
230
261
  this.enterErrorState(new Error(`Application ${rootComponent} could not be loaded: ${reason}`));
231
262
  });
232
263
  }
233
264
  // Trigger bootstrap error state, and call error handler if registered
234
265
  enterErrorState(error) {
235
- this.profiler.logOperationStart({ id: METRIC_ERROR });
266
+ logOperationStart({ id: BOOTSTRAP_ERROR });
236
267
  if (this.errorHandler) {
237
268
  this.errorHandler(error);
238
269
  }
@@ -255,14 +286,14 @@
255
286
  // The loader module is ALWAYS required
256
287
  const GLOBAL = globalThis;
257
288
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
258
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_10') < 0) {
259
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_10');
289
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_11') < 0) {
290
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_11');
260
291
  }
261
292
  new LoaderShim(GLOBAL);
262
293
 
263
294
  }());
264
295
 
265
- LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use strict';
296
+ LWR.define('lwr/loader/v/0_6_0-alpha_11', ['exports'], function (exports) { 'use strict';
266
297
 
267
298
  const templateRegex = /\{([0-9]+)\}/g;
268
299
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -559,12 +590,15 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
559
590
  });
560
591
  }
561
592
 
562
- const MODULE_LOAD_TIMEOUT_TIMER = 300000;
563
- const METRIC_MODULE_DEFINE = 'lwr.loader.module.define';
564
- const METRIC_MODULE_FETCH = 'lwr.loader.module.fetch';
565
- const METRIC_MAPPINGS_FETCH = 'lwr.loader.mappings.fetch';
566
- const METRIC_MODULE_ERROR = 'lwr.loader.module.error';
567
- const METRIC_MAPPINGS_ERROR = 'lwr.loader.mappings.error';
593
+ // Bootstrap / shim
594
+ // Loader: modules
595
+ const LOADER_PREFIX = 'lwr.loader.';
596
+ const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
597
+ const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
598
+ const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
599
+ // Loader: mappings
600
+ const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
601
+ const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
568
602
 
569
603
  /* spec based import map resolver */
570
604
  class ImportMetadataResolver {
@@ -681,7 +715,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
681
715
  if (pending) {
682
716
  return pending;
683
717
  }
684
- this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_FETCH, specifier });
718
+ this.config.profiler.logOperationStart({ id: MAPPINGS_FETCH, specifier });
685
719
  const fetchMappingService = this.hasMappingHooks()
686
720
  ? this.evaluateMappingHooks
687
721
  : this.fetchNewMappings;
@@ -696,6 +730,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
696
730
  if (!uri) {
697
731
  throw new LoaderError(UNRESOLVED, [specifier]);
698
732
  }
733
+ this.config.profiler.logOperationEnd({ id: MAPPINGS_FETCH, specifier });
699
734
  return uri;
700
735
  })
701
736
  .finally(() => {
@@ -740,7 +775,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
740
775
  const uri = resolveUrl(this.buildMappingUrl(specifier), this.getBaseUrl());
741
776
  return globalThis.fetch(uri).then((res) => {
742
777
  if (!res.ok) {
743
- this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_ERROR, specifier });
778
+ this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
744
779
  throw new LoaderError(UNRESOLVED, [specifier]);
745
780
  }
746
781
  return res
@@ -794,6 +829,8 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
794
829
  }
795
830
  }
796
831
 
832
+ const MODULE_LOAD_TIMEOUT_TIMER = 300000;
833
+
797
834
  let lastWindowError;
798
835
  if (hasDocument) {
799
836
  globalThis.addEventListener('error', (evt) => {
@@ -1008,7 +1045,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
1008
1045
  // if module is "external", resolve the external promise to notify any dependees
1009
1046
  mod.external.resolveExternal(moduleDef);
1010
1047
  }
1011
- this.profiler.logOperationStart({ id: METRIC_MODULE_DEFINE, specifier: name });
1048
+ this.profiler.logOperationStart({ id: MODULE_DEFINE, specifier: name });
1012
1049
  this.namedDefineRegistry.set(name, moduleDef);
1013
1050
  this.lastDefine = moduleDef;
1014
1051
  }
@@ -1191,6 +1228,9 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
1191
1228
  if (moduleExports.__defaultInterop) {
1192
1229
  Object.defineProperty(moduleRecord.module, '__defaultInterop', { value: true });
1193
1230
  }
1231
+ if (moduleExports.__esModule) {
1232
+ Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
1233
+ }
1194
1234
  moduleRecord.evaluated = true;
1195
1235
  Object.freeze(moduleRecord.module);
1196
1236
  return moduleRecord.module;
@@ -1239,7 +1279,7 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
1239
1279
  }
1240
1280
  const parentUrl = this.resolver.getBaseUrl(); // only support baseUrl for now
1241
1281
  const specifier = moduleName || originalId;
1242
- this.profiler.logOperationStart({ id: METRIC_MODULE_FETCH, specifier });
1282
+ this.profiler.logOperationStart({ id: MODULE_FETCH, specifier });
1243
1283
  return Promise.resolve()
1244
1284
  .then(async () => {
1245
1285
  const loadHooks = this.loadHook;
@@ -1277,10 +1317,11 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
1277
1317
  if (!moduleDef) {
1278
1318
  throw new LoaderError(FAIL_INSTANTIATE, [resolvedId]);
1279
1319
  }
1320
+ this.profiler.logOperationEnd({ id: MODULE_FETCH, specifier });
1280
1321
  return moduleDef;
1281
1322
  })
1282
1323
  .catch((e) => {
1283
- this.profiler.logOperationStart({ id: METRIC_MODULE_ERROR, specifier });
1324
+ this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
1284
1325
  throw e;
1285
1326
  });
1286
1327
  }
@@ -1364,12 +1405,17 @@ LWR.define('lwr/loader/v/0_6_0-alpha_10', ['exports'], function (exports) { 'use
1364
1405
  logOperationStart: () => {
1365
1406
  /* noop */
1366
1407
  },
1408
+ logOperationEnd: () => {
1409
+ /* noop */
1410
+ },
1367
1411
  };
1368
1412
  }
1369
1413
  this.registry = new ModuleRegistry(Object.freeze({ endpoints: config.endpoints, baseUrl, profiler }));
1414
+ // TODO: https://github.com/salesforce/lwr/issues/1087
1370
1415
  this.services = Object.freeze({
1371
1416
  addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
1372
1417
  handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
1418
+ appMetadata: config.appMetadata,
1373
1419
  });
1374
1420
  }
1375
1421
  /**
@@ -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.10 */
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_10")<0&&l.LWR.requiredModules.push("lwr/loader/v/0_6_0-alpha_10"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderModule="lwr/loader/v/0_6_0-alpha_10",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}))}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((()=>e.load(t))).then((()=>{this.profiler.logOperationStart({id:"lwr.bootstrap.end"})})).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_10",["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_DEFINE="lwr.loader.module.define",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.profiler.logOperationStart({id:METRIC_MODULE_DEFINE,specifier:e}),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})}));
7
+ /* LWR Module Loader Shim v0.6.0-alpha.11 */
8
+ !function(){"use strict";var e;let t;function r(e){t=e}!function(e){e[e.Start=0]="Start",e[e.End=1]="End"}(e||(e={}));const o=globalThis.performance,i=void 0!==o&&"function"==typeof o.mark&&"function"==typeof o.clearMarks&&"function"==typeof o.measure&&"function"==typeof o.clearMeasures;function n({id:r,specifier:n}){t?t({id:r,phase:e.Start,specifier:n}):i&&o.mark(r+(n?`.${n}`:""))}function s({id:r,specifier:n}){if(t)t({id:r,phase:e.End,specifier:n});else if(i){const e=n?`.${n}`:"",t=r+e,i=`${r}.duration${e}`;o.measure(i,t),o.clearMarks(t),o.clearMeasures(i)}}function a(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 l="function"==typeof setTimeout,d="undefined"!=typeof console;const c=globalThis;c.LWR.requiredModules=c.LWR.requiredModules||[],c.LWR.requiredModules.indexOf("lwr/loader/v/0_6_0-alpha_11")<0&&c.LWR.requiredModules.push("lwr/loader/v/0_6_0-alpha_11"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderSpecifier="lwr/loader/v/0_6_0-alpha_11";const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot,l&&(this.watchdogTimerId=this.startWatchdogTimer());try{a(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()&&(l&&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:{logOperationStart:n,logOperationEnd:s},appMetadata:{bootstrapModule:this.config.bootstrapModule,rootComponent:this.config.rootComponent,rootComponents:this.config.rootComponents}},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.loaderSpecifier,this.defineCache[this.loaderSpecifier],e,this.config.preloadModules);this.createProfilerModule(t),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()}))}))}createProfilerModule(e){e.define("lwr/profiler/v/0_6_0-alpha_11",["exports"],(e=>{Object.assign(e,{logOperationStart:n,logOperationEnd:s})}))}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.loaderSpecifier&&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((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))}))}enterErrorState(e){n({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):d&&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)}}(c)}(),LWR.define("lwr/loader/v/0_6_0-alpha_11",["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 LOADER_PREFIX="lwr.loader.",MODULE_DEFINE=`${LOADER_PREFIX}module.define`,MODULE_FETCH=`${LOADER_PREFIX}module.fetch`,MODULE_ERROR=`${LOADER_PREFIX}module.error`,MAPPINGS_FETCH=`${LOADER_PREFIX}mappings.fetch`,MAPPINGS_ERROR=`${LOADER_PREFIX}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: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 this.config.profiler.logOperationEnd({id:MAPPINGS_FETCH,specifier:e}),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: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))}}}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 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.profiler.logOperationStart({id:MODULE_DEFINE,specifier:e}),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}),l.__esModule&&Object.defineProperty(e.module,"__esModule",{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: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 this.profiler.logOperationEnd({id:MODULE_FETCH,specifier:n}),o})).catch((e=>{throw this.profiler.logOperationStart({id: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:()=>{},logOperationEnd:()=>{}}),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),appMetadata:e.appMetadata})}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,10 +4,14 @@
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.10 */
7
+ /* LWR Module Loader Shim v0.6.0-alpha.11 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
11
+ // Bootstrap / shim
12
+ const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
13
+ const BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
14
+
11
15
  function createLoader(name, definition, config, externalModules) {
12
16
  if (!definition || typeof definition[2] !== 'function') {
13
17
  throw new Error(`Expected loader with specifier "${name}" to be a module`);
@@ -27,19 +31,17 @@
27
31
  load: loader.load.bind(loader),
28
32
  services: loader.services,
29
33
  });
30
- return;
31
34
  };
32
35
  loader.define(name, ['exports'], exporter);
33
36
  return loader;
34
37
  }
35
38
 
36
39
  const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
37
- const METRIC_END = 'lwr.bootstrap.end';
38
- const METRIC_ERROR = 'lwr.bootstrap.error';
39
40
 
40
41
  var Phase;
41
42
  (function (Phase) {
42
43
  Phase[Phase["Start"] = 0] = "Start";
44
+ Phase[Phase["End"] = 1] = "End";
43
45
  })(Phase || (Phase = {}));
44
46
  // Attach a custom dispatcher
45
47
  let customDispatcher;
@@ -48,7 +50,12 @@
48
50
  }
49
51
  // Check if the Performance API is available
50
52
  // e.g. JSDom (used in Jest) doesn't implement these
51
- const isPerfSupported = typeof globalThis.performance !== 'undefined' && typeof globalThis.performance.mark === 'function';
53
+ const perf = globalThis.performance;
54
+ const isPerfSupported = typeof perf !== 'undefined' &&
55
+ typeof perf.mark === 'function' &&
56
+ typeof perf.clearMarks === 'function' &&
57
+ typeof perf.measure === 'function' &&
58
+ typeof perf.clearMeasures === 'function';
52
59
  // For marking request metrics
53
60
  // Fallback to the Performance API if there is no custom dispatcher
54
61
  function logOperationStart({ id, specifier }) {
@@ -56,12 +63,26 @@
56
63
  customDispatcher({ id, phase: Phase.Start, specifier });
57
64
  }
58
65
  else if (isPerfSupported) {
59
- globalThis.performance.mark(id + (specifier ? `.${specifier}` : ''));
66
+ perf.mark(id + (specifier ? `.${specifier}` : ''));
60
67
  }
61
68
  }
62
- function getProfilerAPI() {
63
- // Create the public Profiler API
64
- return { logOperationStart: logOperationStart.bind(this) };
69
+ // For measuring duration metrics
70
+ // Fallback to the Performance API if there is no custom dispatcher
71
+ /* istanbul ignore next */
72
+ function logOperationEnd({ id, specifier }) {
73
+ if (customDispatcher) {
74
+ customDispatcher({ id, phase: Phase.End, specifier });
75
+ }
76
+ else if (isPerfSupported) {
77
+ const suffix = specifier ? `.${specifier}` : '';
78
+ const markName = id + suffix;
79
+ const measureName = `${id}.duration${suffix}`;
80
+ perf.measure(measureName, markName);
81
+ // Clear the created mark and measure to avoid filling the performance entry buffer
82
+ // Even if they get deleted, existing PerformanceObservers preserve copies of the entries
83
+ perf.clearMarks(markName);
84
+ perf.clearMeasures(measureName);
85
+ }
65
86
  }
66
87
 
67
88
  // Check for errors with autoBoot and customInit
@@ -104,9 +125,7 @@
104
125
  // Parse configuration
105
126
  this.global = global;
106
127
  this.config = global.LWR;
107
- this.loaderModule = 'lwr/loader/v/0_6_0-alpha_10';
108
- // Set up the profiler for instrumentation
109
- this.profiler = getProfilerAPI();
128
+ this.loaderSpecifier = 'lwr/loader/v/0_6_0-alpha_11';
110
129
  // Set up the temporary LWR.define function and customInit hook
111
130
  const tempDefine = this.tempDefine.bind(this);
112
131
  global.LWR.define = tempDefine;
@@ -168,9 +187,16 @@
168
187
  const loaderConfig = {
169
188
  endpoints: this.config.endpoints,
170
189
  baseUrl: this.config.baseUrl,
171
- profiler: this.profiler,
190
+ profiler: { logOperationStart, logOperationEnd },
191
+ // TODO: can be removed following https://github.com/salesforce/lwr/issues/1087
192
+ appMetadata: {
193
+ bootstrapModule: this.config.bootstrapModule,
194
+ rootComponent: this.config.rootComponent,
195
+ rootComponents: this.config.rootComponents,
196
+ },
172
197
  };
173
- const loader = createLoader(this.loaderModule, this.defineCache[this.loaderModule], loaderConfig, this.config.preloadModules);
198
+ const loader = createLoader(this.loaderSpecifier, this.defineCache[this.loaderSpecifier], loaderConfig, this.config.preloadModules);
199
+ this.createProfilerModule(loader);
174
200
  this.mountApp(loader);
175
201
  }
176
202
  catch (e) {
@@ -194,6 +220,14 @@
194
220
  });
195
221
  });
196
222
  }
223
+ // Create a module out of the profiler
224
+ // Note: The profiler is also available as a module through lwc module resolution (see package.json)
225
+ createProfilerModule(loader) {
226
+ const exporter = (exports) => {
227
+ Object.assign(exports, { logOperationStart, logOperationEnd });
228
+ };
229
+ loader.define('lwr/profiler/v/0_6_0-alpha_11', ['exports'], exporter);
230
+ }
197
231
  // Set up the application globals, import map, root custom element...
198
232
  mountApp(loader) {
199
233
  const { bootstrapModule, rootComponent, rootComponents, endpoints, imports, index } = this.config;
@@ -208,7 +242,7 @@
208
242
  });
209
243
  // Redefine all modules in the temporary cache
210
244
  this.orderedDefs.forEach((specifier) => {
211
- if (specifier !== this.loaderModule) {
245
+ if (specifier !== this.loaderSpecifier) {
212
246
  loader.define(...this.defineCache[specifier]);
213
247
  }
214
248
  });
@@ -223,16 +257,13 @@
223
257
  }
224
258
  })
225
259
  .then(() => loader.load(bootstrapModule))
226
- .then(() => {
227
- this.profiler.logOperationStart({ id: METRIC_END });
228
- })
229
260
  .catch((reason) => {
230
261
  this.enterErrorState(new Error(`Application ${rootComponent} could not be loaded: ${reason}`));
231
262
  });
232
263
  }
233
264
  // Trigger bootstrap error state, and call error handler if registered
234
265
  enterErrorState(error) {
235
- this.profiler.logOperationStart({ id: METRIC_ERROR });
266
+ logOperationStart({ id: BOOTSTRAP_ERROR });
236
267
  if (this.errorHandler) {
237
268
  this.errorHandler(error);
238
269
  }
@@ -255,8 +286,8 @@
255
286
  // The loader module is ALWAYS required
256
287
  const GLOBAL = globalThis;
257
288
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
258
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_10') < 0) {
259
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_10');
289
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_11') < 0) {
290
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_11');
260
291
  }
261
292
  new LoaderShim(GLOBAL);
262
293
 
@@ -0,0 +1,43 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+
8
+ // packages/@lwrjs/loader/src/metrics.ts
9
+ __markAsModule(exports);
10
+ __export(exports, {
11
+ BOOTSTRAP_AVAILABILITY: () => BOOTSTRAP_AVAILABILITY,
12
+ BOOTSTRAP_DURATION: () => BOOTSTRAP_DURATION,
13
+ BOOTSTRAP_END: () => BOOTSTRAP_END,
14
+ BOOTSTRAP_ERROR: () => BOOTSTRAP_ERROR,
15
+ BOOTSTRAP_PREFIX: () => BOOTSTRAP_PREFIX,
16
+ LOADER_PREFIX: () => LOADER_PREFIX,
17
+ MAPPINGS_ERROR: () => MAPPINGS_ERROR,
18
+ MAPPINGS_FETCH: () => MAPPINGS_FETCH,
19
+ MAPPINGS_FETCH_COUNT: () => MAPPINGS_FETCH_COUNT,
20
+ MAPPINGS_FETCH_DURATION: () => MAPPINGS_FETCH_DURATION,
21
+ MODULE_DEFINE: () => MODULE_DEFINE,
22
+ MODULE_DEFINE_COUNT: () => MODULE_DEFINE_COUNT,
23
+ MODULE_ERROR: () => MODULE_ERROR,
24
+ MODULE_FETCH: () => MODULE_FETCH,
25
+ MODULE_FETCH_COUNT: () => MODULE_FETCH_COUNT,
26
+ MODULE_FETCH_DURATION: () => MODULE_FETCH_DURATION
27
+ });
28
+ var BOOTSTRAP_PREFIX = "lwr.bootstrap.";
29
+ var BOOTSTRAP_END = `${BOOTSTRAP_PREFIX}end`;
30
+ var BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
31
+ var BOOTSTRAP_DURATION = `${BOOTSTRAP_PREFIX}duration`;
32
+ var BOOTSTRAP_AVAILABILITY = `${BOOTSTRAP_PREFIX}availability`;
33
+ var LOADER_PREFIX = "lwr.loader.";
34
+ var MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
35
+ var MODULE_DEFINE_COUNT = `${MODULE_DEFINE}.count`;
36
+ var MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
37
+ var MODULE_FETCH_COUNT = `${MODULE_FETCH}.count`;
38
+ var MODULE_FETCH_DURATION = `${MODULE_FETCH}.duration`;
39
+ var MODULE_ERROR = `${LOADER_PREFIX}module.error`;
40
+ var MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
41
+ var MAPPINGS_FETCH_COUNT = `${MAPPINGS_FETCH}.count`;
42
+ var MAPPINGS_FETCH_DURATION = `${MAPPINGS_FETCH}.duration`;
43
+ var MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
@@ -8,16 +8,6 @@ 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_DEFINE: () => METRIC_MODULE_DEFINE,
14
- METRIC_MODULE_ERROR: () => METRIC_MODULE_ERROR,
15
- METRIC_MODULE_FETCH: () => METRIC_MODULE_FETCH,
16
11
  MODULE_LOAD_TIMEOUT_TIMER: () => MODULE_LOAD_TIMEOUT_TIMER
17
12
  });
18
13
  var MODULE_LOAD_TIMEOUT_TIMER = 3e5;
19
- var METRIC_MODULE_DEFINE = "lwr.loader.module.define";
20
- var METRIC_MODULE_FETCH = "lwr.loader.module.fetch";
21
- var METRIC_MAPPINGS_FETCH = "lwr.loader.mappings.fetch";
22
- var METRIC_MODULE_ERROR = "lwr.loader.module.error";
23
- var METRIC_MAPPINGS_ERROR = "lwr.loader.mappings.error";
@@ -28,7 +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
+ var import_metrics = __toModule(require("../../../../metrics"));
32
32
  var ImportMetadataResolver = class {
33
33
  constructor(config, invalidationCallback) {
34
34
  this.importURICache = new Map();
@@ -119,7 +119,7 @@ var ImportMetadataResolver = class {
119
119
  if (pending) {
120
120
  return pending;
121
121
  }
122
- this.config.profiler.logOperationStart({id: import_constants.METRIC_MAPPINGS_FETCH, specifier});
122
+ this.config.profiler.logOperationStart({id: import_metrics.MAPPINGS_FETCH, specifier});
123
123
  const fetchMappingService = this.hasMappingHooks() ? this.evaluateMappingHooks : this.fetchNewMappings;
124
124
  const promise = fetchMappingService.bind(this)(specifier).then((importMetadata) => {
125
125
  if (!importMetadata || !importMetadata.imports) {
@@ -130,6 +130,7 @@ var ImportMetadataResolver = class {
130
130
  if (!uri) {
131
131
  throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
132
132
  }
133
+ this.config.profiler.logOperationEnd({id: import_metrics.MAPPINGS_FETCH, specifier});
133
134
  return uri;
134
135
  }).finally(() => {
135
136
  this.pendingURICache.delete(specifier);
@@ -162,7 +163,7 @@ var ImportMetadataResolver = class {
162
163
  const uri = (0, import_url.resolveUrl)(this.buildMappingUrl(specifier), this.getBaseUrl());
163
164
  return globalThis.fetch(uri).then((res) => {
164
165
  if (!res.ok) {
165
- this.config.profiler.logOperationStart({id: import_constants.METRIC_MAPPINGS_ERROR, specifier});
166
+ this.config.profiler.logOperationStart({id: import_metrics.MAPPINGS_ERROR, specifier});
166
167
  throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
167
168
  }
168
169
  return res.json().then((ret) => {
@@ -33,6 +33,7 @@ var import_scriptLoad = __toModule(require("./scriptLoad"));
33
33
  var import_importMetadataResolver = __toModule(require("./importMetadataResolver"));
34
34
  var import_moduleInvalidation = __toModule(require("../hooks/moduleInvalidation"));
35
35
  var import_resolveAndLoadHook = __toModule(require("../hooks/resolveAndLoadHook"));
36
+ var import_metrics = __toModule(require("../../../../metrics"));
36
37
  var import_constants = __toModule(require("../constants/constants"));
37
38
  var ModuleRegistry = class {
38
39
  constructor(config) {
@@ -144,7 +145,7 @@ var ModuleRegistry = class {
144
145
  if (mod && mod.external) {
145
146
  mod.external.resolveExternal(moduleDef);
146
147
  }
147
- this.profiler.logOperationStart({id: import_constants.METRIC_MODULE_DEFINE, specifier: name});
148
+ this.profiler.logOperationStart({id: import_metrics.MODULE_DEFINE, specifier: name});
148
149
  this.namedDefineRegistry.set(name, moduleDef);
149
150
  this.lastDefine = moduleDef;
150
151
  }
@@ -290,6 +291,9 @@ var ModuleRegistry = class {
290
291
  if (moduleExports.__defaultInterop) {
291
292
  Object.defineProperty(moduleRecord.module, "__defaultInterop", {value: true});
292
293
  }
294
+ if (moduleExports.__esModule) {
295
+ Object.defineProperty(moduleRecord.module, "__esModule", {value: true});
296
+ }
293
297
  moduleRecord.evaluated = true;
294
298
  Object.freeze(moduleRecord.module);
295
299
  return moduleRecord.module;
@@ -325,7 +329,7 @@ var ModuleRegistry = class {
325
329
  }
326
330
  const parentUrl = this.resolver.getBaseUrl();
327
331
  const specifier = moduleName || originalId;
328
- this.profiler.logOperationStart({id: import_constants.METRIC_MODULE_FETCH, specifier});
332
+ this.profiler.logOperationStart({id: import_metrics.MODULE_FETCH, specifier});
329
333
  return Promise.resolve().then(async () => {
330
334
  const loadHooks = this.loadHook;
331
335
  if (loadHooks) {
@@ -354,9 +358,10 @@ var ModuleRegistry = class {
354
358
  if (!moduleDef) {
355
359
  throw new import_messages.LoaderError(import_messages.FAIL_INSTANTIATE, [resolvedId]);
356
360
  }
361
+ this.profiler.logOperationEnd({id: import_metrics.MODULE_FETCH, specifier});
357
362
  return moduleDef;
358
363
  }).catch((e) => {
359
- this.profiler.logOperationStart({id: import_constants.METRIC_MODULE_ERROR, specifier});
364
+ this.profiler.logOperationStart({id: import_metrics.MODULE_ERROR, specifier});
360
365
  throw e;
361
366
  });
362
367
  }
@@ -316,6 +316,9 @@ var ModuleRegistry = class {
316
316
  if (moduleExports.__defaultInterop) {
317
317
  Object.defineProperty(moduleRecord.module, "__defaultInterop", {value: true});
318
318
  }
319
+ if (moduleExports.__esModule) {
320
+ Object.defineProperty(moduleRecord.module, "__esModule", {value: true});
321
+ }
319
322
  moduleRecord.evaluated = true;
320
323
  Object.freeze(moduleRecord.module);
321
324
  return moduleRecord.module;
@@ -0,0 +1,18 @@
1
+ export declare type LWRMetric = 'lwr.bootstrap.end' | 'lwr.bootstrap.error' | 'lwr.loader.module.define' | 'lwr.loader.module.fetch' | 'lwr.loader.mappings.fetch' | 'lwr.loader.module.error' | 'lwr.loader.mappings.error';
2
+ export declare const BOOTSTRAP_PREFIX = "lwr.bootstrap.";
3
+ export declare const BOOTSTRAP_END: LWRMetric;
4
+ export declare const BOOTSTRAP_ERROR: LWRMetric;
5
+ export declare const BOOTSTRAP_DURATION: string;
6
+ export declare const BOOTSTRAP_AVAILABILITY: string;
7
+ export declare const LOADER_PREFIX = "lwr.loader.";
8
+ export declare const MODULE_DEFINE: LWRMetric;
9
+ export declare const MODULE_DEFINE_COUNT: string;
10
+ export declare const MODULE_FETCH: LWRMetric;
11
+ export declare const MODULE_FETCH_COUNT: string;
12
+ export declare const MODULE_FETCH_DURATION: string;
13
+ export declare const MODULE_ERROR: LWRMetric;
14
+ export declare const MAPPINGS_FETCH: LWRMetric;
15
+ export declare const MAPPINGS_FETCH_COUNT: string;
16
+ export declare const MAPPINGS_FETCH_DURATION: string;
17
+ export declare const MAPPINGS_ERROR: LWRMetric;
18
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1,20 @@
1
+ // Bootstrap / shim
2
+ export const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
3
+ export const BOOTSTRAP_END = `${BOOTSTRAP_PREFIX}end`;
4
+ export const BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
5
+ export const BOOTSTRAP_DURATION = `${BOOTSTRAP_PREFIX}duration`;
6
+ export const BOOTSTRAP_AVAILABILITY = `${BOOTSTRAP_PREFIX}availability`;
7
+ // Loader: modules
8
+ export const LOADER_PREFIX = 'lwr.loader.';
9
+ export const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
10
+ export const MODULE_DEFINE_COUNT = `${MODULE_DEFINE}.count`;
11
+ export const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
12
+ export const MODULE_FETCH_COUNT = `${MODULE_FETCH}.count`;
13
+ export const MODULE_FETCH_DURATION = `${MODULE_FETCH}.duration`;
14
+ export const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
15
+ // Loader: mappings
16
+ export const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
17
+ export const MAPPINGS_FETCH_COUNT = `${MAPPINGS_FETCH}.count`;
18
+ export const MAPPINGS_FETCH_DURATION = `${MAPPINGS_FETCH}.duration`;
19
+ export const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
20
+ //# sourceMappingURL=metrics.js.map
@@ -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.10 */
7
+ /* LWR ESM Module Loader v0.6.0-alpha.11 */
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.10 */
7
+ /* LWR Module Loader v0.6.0-alpha.11 */
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,12 +300,15 @@ if (hasDocument) {
300
300
  });
301
301
  }
302
302
 
303
- const MODULE_LOAD_TIMEOUT_TIMER = 300000;
304
- const METRIC_MODULE_DEFINE = 'lwr.loader.module.define';
305
- const METRIC_MODULE_FETCH = 'lwr.loader.module.fetch';
306
- const METRIC_MAPPINGS_FETCH = 'lwr.loader.mappings.fetch';
307
- const METRIC_MODULE_ERROR = 'lwr.loader.module.error';
308
- const METRIC_MAPPINGS_ERROR = 'lwr.loader.mappings.error';
303
+ // Bootstrap / shim
304
+ // Loader: modules
305
+ const LOADER_PREFIX = 'lwr.loader.';
306
+ const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
307
+ const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
308
+ const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
309
+ // Loader: mappings
310
+ const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
311
+ const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
309
312
 
310
313
  /* spec based import map resolver */
311
314
  class ImportMetadataResolver {
@@ -422,7 +425,7 @@ class ImportMetadataResolver {
422
425
  if (pending) {
423
426
  return pending;
424
427
  }
425
- this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_FETCH, specifier });
428
+ this.config.profiler.logOperationStart({ id: MAPPINGS_FETCH, specifier });
426
429
  const fetchMappingService = this.hasMappingHooks()
427
430
  ? this.evaluateMappingHooks
428
431
  : this.fetchNewMappings;
@@ -437,6 +440,7 @@ class ImportMetadataResolver {
437
440
  if (!uri) {
438
441
  throw new LoaderError(UNRESOLVED, [specifier]);
439
442
  }
443
+ this.config.profiler.logOperationEnd({ id: MAPPINGS_FETCH, specifier });
440
444
  return uri;
441
445
  })
442
446
  .finally(() => {
@@ -481,7 +485,7 @@ class ImportMetadataResolver {
481
485
  const uri = resolveUrl(this.buildMappingUrl(specifier), this.getBaseUrl());
482
486
  return globalThis.fetch(uri).then((res) => {
483
487
  if (!res.ok) {
484
- this.config.profiler.logOperationStart({ id: METRIC_MAPPINGS_ERROR, specifier });
488
+ this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
485
489
  throw new LoaderError(UNRESOLVED, [specifier]);
486
490
  }
487
491
  return res
@@ -535,6 +539,8 @@ function evaluateHandleStaleModuleHooks(handleStaleModuleHooks, hookArgs) {
535
539
  }
536
540
  }
537
541
 
542
+ const MODULE_LOAD_TIMEOUT_TIMER = 300000;
543
+
538
544
  let lastWindowError;
539
545
  if (hasDocument) {
540
546
  globalThis.addEventListener('error', (evt) => {
@@ -749,7 +755,7 @@ class ModuleRegistry {
749
755
  // if module is "external", resolve the external promise to notify any dependees
750
756
  mod.external.resolveExternal(moduleDef);
751
757
  }
752
- this.profiler.logOperationStart({ id: METRIC_MODULE_DEFINE, specifier: name });
758
+ this.profiler.logOperationStart({ id: MODULE_DEFINE, specifier: name });
753
759
  this.namedDefineRegistry.set(name, moduleDef);
754
760
  this.lastDefine = moduleDef;
755
761
  }
@@ -932,6 +938,9 @@ class ModuleRegistry {
932
938
  if (moduleExports.__defaultInterop) {
933
939
  Object.defineProperty(moduleRecord.module, '__defaultInterop', { value: true });
934
940
  }
941
+ if (moduleExports.__esModule) {
942
+ Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
943
+ }
935
944
  moduleRecord.evaluated = true;
936
945
  Object.freeze(moduleRecord.module);
937
946
  return moduleRecord.module;
@@ -980,7 +989,7 @@ class ModuleRegistry {
980
989
  }
981
990
  const parentUrl = this.resolver.getBaseUrl(); // only support baseUrl for now
982
991
  const specifier = moduleName || originalId;
983
- this.profiler.logOperationStart({ id: METRIC_MODULE_FETCH, specifier });
992
+ this.profiler.logOperationStart({ id: MODULE_FETCH, specifier });
984
993
  return Promise.resolve()
985
994
  .then(async () => {
986
995
  const loadHooks = this.loadHook;
@@ -1018,10 +1027,11 @@ class ModuleRegistry {
1018
1027
  if (!moduleDef) {
1019
1028
  throw new LoaderError(FAIL_INSTANTIATE, [resolvedId]);
1020
1029
  }
1030
+ this.profiler.logOperationEnd({ id: MODULE_FETCH, specifier });
1021
1031
  return moduleDef;
1022
1032
  })
1023
1033
  .catch((e) => {
1024
- this.profiler.logOperationStart({ id: METRIC_MODULE_ERROR, specifier });
1034
+ this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
1025
1035
  throw e;
1026
1036
  });
1027
1037
  }
@@ -1105,12 +1115,17 @@ class Loader {
1105
1115
  logOperationStart: () => {
1106
1116
  /* noop */
1107
1117
  },
1118
+ logOperationEnd: () => {
1119
+ /* noop */
1120
+ },
1108
1121
  };
1109
1122
  }
1110
1123
  this.registry = new ModuleRegistry(Object.freeze({ endpoints: config.endpoints, baseUrl, profiler }));
1124
+ // TODO: https://github.com/salesforce/lwr/issues/1087
1111
1125
  this.services = Object.freeze({
1112
1126
  addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
1113
1127
  handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
1128
+ appMetadata: config.appMetadata,
1114
1129
  });
1115
1130
  }
1116
1131
  /**
@@ -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.10 */
7
+ /* LWR Legacy Module Loader v0.6.0-alpha.11 */
8
8
  const templateRegex = /\{([0-9]+)\}/g;
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  function templateString(template, args) {
@@ -743,6 +743,9 @@ class ModuleRegistry {
743
743
  if (moduleExports.__defaultInterop) {
744
744
  Object.defineProperty(moduleRecord.module, '__defaultInterop', { value: true });
745
745
  }
746
+ if (moduleExports.__esModule) {
747
+ Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
748
+ }
746
749
  moduleRecord.evaluated = true;
747
750
  Object.freeze(moduleRecord.module);
748
751
  return moduleRecord.module;
@@ -0,0 +1,23 @@
1
+ import { LWRMetric } from '../metrics';
2
+ declare const enum Phase {
3
+ Start = 0,
4
+ End = 1
5
+ }
6
+ interface LWRLogInfo {
7
+ id: LWRMetric;
8
+ specifier?: string;
9
+ }
10
+ interface LWRDispatcherInfo extends LWRLogInfo {
11
+ phase: Phase;
12
+ }
13
+ declare type LogOperation = (info: LWRLogInfo) => void;
14
+ export declare type LogDispatcher = (info: LWRDispatcherInfo) => void;
15
+ export interface ProfilerAPI {
16
+ logOperationStart: LogOperation;
17
+ logOperationEnd: LogOperation;
18
+ }
19
+ export declare function attachDispatcher(dispatcher: LogDispatcher): void;
20
+ export declare function logOperationStart({ id, specifier }: LWRLogInfo): void;
21
+ export declare function logOperationEnd({ id, specifier }: LWRLogInfo): void;
22
+ export {};
23
+ //# sourceMappingURL=profiler.d.ts.map
@@ -0,0 +1,47 @@
1
+ var Phase;
2
+ (function (Phase) {
3
+ Phase[Phase["Start"] = 0] = "Start";
4
+ Phase[Phase["End"] = 1] = "End";
5
+ })(Phase || (Phase = {}));
6
+ // Attach a custom dispatcher
7
+ let customDispatcher;
8
+ export function attachDispatcher(dispatcher) {
9
+ customDispatcher = dispatcher;
10
+ }
11
+ // Check if the Performance API is available
12
+ // e.g. JSDom (used in Jest) doesn't implement these
13
+ const perf = globalThis.performance;
14
+ const isPerfSupported = typeof perf !== 'undefined' &&
15
+ typeof perf.mark === 'function' &&
16
+ typeof perf.clearMarks === 'function' &&
17
+ typeof perf.measure === 'function' &&
18
+ typeof perf.clearMeasures === 'function';
19
+ // For marking request metrics
20
+ // Fallback to the Performance API if there is no custom dispatcher
21
+ export function logOperationStart({ id, specifier }) {
22
+ if (customDispatcher) {
23
+ customDispatcher({ id, phase: Phase.Start, specifier });
24
+ }
25
+ else if (isPerfSupported) {
26
+ perf.mark(id + (specifier ? `.${specifier}` : ''));
27
+ }
28
+ }
29
+ // For measuring duration metrics
30
+ // Fallback to the Performance API if there is no custom dispatcher
31
+ /* istanbul ignore next */
32
+ export function logOperationEnd({ id, specifier }) {
33
+ if (customDispatcher) {
34
+ customDispatcher({ id, phase: Phase.End, specifier });
35
+ }
36
+ else if (isPerfSupported) {
37
+ const suffix = specifier ? `.${specifier}` : '';
38
+ const markName = id + suffix;
39
+ const measureName = `${id}.duration${suffix}`;
40
+ perf.measure(measureName, markName);
41
+ // Clear the created mark and measure to avoid filling the performance entry buffer
42
+ // Even if they get deleted, existing PerformanceObservers preserve copies of the entries
43
+ perf.clearMarks(markName);
44
+ perf.clearMeasures(measureName);
45
+ }
46
+ }
47
+ //# sourceMappingURL=profiler.js.map
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.6.0-alpha.10",
8
+ "version": "0.6.0-alpha.11",
9
9
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
10
10
  "repository": {
11
11
  "type": "git",
@@ -24,6 +24,10 @@
24
24
  "import": "./build/index.js",
25
25
  "require": "./build/cjs/index.cjs"
26
26
  },
27
+ "./metrics": {
28
+ "import": "./build/metrics.js",
29
+ "require": "./build/cjs/metrics.cjs"
30
+ },
27
31
  "./prod-loader-shim": "./build/assets/prod/lwr-loader-shim.js",
28
32
  "./prod-loader-shim-bundle": "./build/assets/prod/lwr-loader-shim.bundle.js",
29
33
  "./prod-loader-shim-bundle-min": "./build/assets/prod/lwr-loader-shim.bundle.min.js",
@@ -54,28 +58,38 @@
54
58
  "build": "tsc -b; yarn build:shim && yarn build:loader && yarn build:shim:bundle && yarn build:shim:bundle:minify"
55
59
  },
56
60
  "devDependencies": {
57
- "@lwrjs/compiler": "0.6.0-alpha.10",
58
- "@lwrjs/diagnostics": "0.6.0-alpha.10",
59
- "@lwrjs/types": "0.6.0-alpha.10",
61
+ "@lwrjs/compiler": "0.6.0-alpha.11",
62
+ "@lwrjs/diagnostics": "0.6.0-alpha.11",
63
+ "@lwrjs/types": "0.6.0-alpha.11",
60
64
  "rollup-plugin-terser": "^7.0.2"
61
65
  },
62
66
  "dependencies": {
63
- "@lwrjs/shared-utils": "0.6.0-alpha.10"
67
+ "@lwrjs/shared-utils": "0.6.0-alpha.11"
64
68
  },
65
69
  "lwc": {
66
70
  "modules": [
67
71
  {
68
72
  "dir": "build/modules"
73
+ },
74
+ {
75
+ "name": "lwr/metrics",
76
+ "path": "build/metrics.js"
77
+ },
78
+ {
79
+ "name": "lwr/profiler",
80
+ "path": "build/shim/profiler.js"
69
81
  }
70
82
  ],
71
83
  "expose": [
72
84
  "lwr/esmLoader",
73
85
  "lwr/loader",
74
- "lwr/loaderLegacy"
86
+ "lwr/loaderLegacy",
87
+ "lwr/metrics",
88
+ "lwr/profiler"
75
89
  ]
76
90
  },
77
91
  "engines": {
78
92
  "node": ">=14.15.4 <17"
79
93
  },
80
- "gitHead": "85914e17d6214748489426252dd8fa41c8938b8f"
94
+ "gitHead": "18ab72188c2d52e32cca47333951a9c76f996039"
81
95
  }