@lwrjs/loader 0.22.12 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/assets/prod/lwr-error-shim.js +1 -1
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +6 -6
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +2 -2
- package/build/assets/prod/lwr-loader-shim-legacy.js +5 -5
- package/build/assets/prod/lwr-loader-shim.bundle.js +191 -19
- package/build/assets/prod/lwr-loader-shim.bundle.min.js +3 -3
- package/build/assets/prod/lwr-loader-shim.js +13 -11
- package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +4 -5
- package/build/cjs/modules/lwr/loader/utils/validation.cjs +61 -0
- package/build/modules/lwr/esmLoader/esmLoader.js +1 -1
- package/build/modules/lwr/loader/loader.d.ts +31 -1
- package/build/modules/lwr/loader/loader.js +178 -8
- package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.d.ts +8 -1
- package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.js +12 -5
- package/build/modules/lwr/loader/utils/validation.d.ts +17 -0
- package/build/modules/lwr/loader/utils/validation.js +68 -0
- package/build/modules/lwr/loaderLegacy/loaderLegacy.js +1 -1
- package/build/shim/shim.js +6 -6
- package/build/types.d.ts +4 -3
- package/package.json +6 -6
|
@@ -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 Error Shim v0.
|
|
7
|
+
/* LWR Error Shim v0.23.0 */
|
|
8
8
|
!function(){"use strict";const o=globalThis;if(!(o.LWR&&o.LWR.define)){const r=new Error("The LWR application failed to bootstrap");if(!o.LWR||!o.LWR.onError)throw r;o.LWR.onError(r)}}();
|
|
@@ -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.
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.23.0 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -461,7 +461,7 @@
|
|
|
461
461
|
// Parse configuration
|
|
462
462
|
this.global = global;
|
|
463
463
|
this.config = global.LWR ;
|
|
464
|
-
this.loaderModule = 'lwr/loaderLegacy/v/
|
|
464
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_23_0';
|
|
465
465
|
|
|
466
466
|
// Set up error handler
|
|
467
467
|
this.errorHandler = this.config.onError ;
|
|
@@ -661,7 +661,7 @@
|
|
|
661
661
|
const exporter = (exports) => {
|
|
662
662
|
Object.assign(exports, { logOperationStart, logOperationEnd });
|
|
663
663
|
};
|
|
664
|
-
define('lwr/profiler/v/
|
|
664
|
+
define('lwr/profiler/v/0_23_0', ['exports'], exporter, {});
|
|
665
665
|
}
|
|
666
666
|
|
|
667
667
|
// Set up the application globals, import map, root custom element...
|
|
@@ -758,14 +758,14 @@
|
|
|
758
758
|
// The loader module is ALWAYS required
|
|
759
759
|
const GLOBAL = globalThis ;
|
|
760
760
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
761
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/
|
|
762
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/
|
|
761
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_23_0') < 0) {
|
|
762
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_23_0');
|
|
763
763
|
}
|
|
764
764
|
new LoaderShim(GLOBAL);
|
|
765
765
|
|
|
766
766
|
})();
|
|
767
767
|
|
|
768
|
-
LWR.define('lwr/loaderLegacy/v/
|
|
768
|
+
LWR.define('lwr/loaderLegacy/v/0_23_0', ['exports'], (function (exports) { 'use strict';
|
|
769
769
|
|
|
770
770
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
771
771
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -4,8 +4,8 @@
|
|
|
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.
|
|
8
|
-
!function(){"use strict";var e=function(e){return e[e.Start=0]="Start",e[e.End=1]="End",e}(e||{});let t;function r(e){t=e}const o=globalThis.performance,n=void 0!==o&&"function"==typeof o.mark&&"function"==typeof o.clearMarks&&"function"==typeof o.measure&&"function"==typeof o.clearMeasures;function i(e,t){return t?`${e}-${t}`:e}function s(e,t,r){const o=i(e,t);return t&&r?`${o}_${r}`:o}function a(e,t){const r=e||t?{...t}:null;return r&&e&&(r.specifier=e),r}function l({id:r,specifier:i,specifierIndex:l,metadata:c}){if(t)t({id:r,phase:e.Start,specifier:i,metadata:c,specifierIndex:l});else if(n){const e=s(r,i,l),t=a(i,c);o.mark(e,{detail:t})}}function c({id:r,specifier:l,specifierIndex:c,metadata:d}){if(t)t({id:r,phase:e.End,specifier:l,metadata:d,specifierIndex:c});else if(n){const e=s(r,l,c),t=i(r,l),n=a(l,d);o.measure(t,{start:e,detail:n}),o.clearMarks(e),o.clearMeasures(t)}}function d(e){const[,t,r]=e;if(Array.isArray(t)&&"function"==typeof r)return{deps:t,factory:r};if("function"==typeof t)return{deps:[],factory:t};throw new Error("Invalid module definition")}function p(e,t,r){if("exports"===e)return t;const o=r[e];if(!o)throw new Error(`Dependency "${e}" not found in defineCache for loader`);try{return function(e){const{deps:t,factory:r}=d(e);if(t.length>1||1===t.length&&"exports"!==t[0])throw new Error(`Loader dependencies must have no deps or only ['exports']; got [${t.join(", ")}]`);const o={},n=r(o);return void 0!==n?n:o}(o)}catch(t){const r=t instanceof Error?t.message:String(t);throw new Error(`Loader dependency "${e}" has invalid definition: ${r}`)}}function u(e,t,r){try{const{deps:e,factory:o}=function(e){const{deps:t,factory:r}=d(e);if(t.includes("exports"))return{deps:t,factory:r};const o=0===t.length;return{deps:["exports",...t],factory:(e,...t)=>{const n=o?r(e):r(...t);void 0!==n&&"object"==typeof n&&Object.assign(e,n)}}}(t),n={};return{factory:o,args:e.map((e=>p(e,n,r))),exportsObj:n}}catch(t){const r=t instanceof Error?t.message:String(t);throw new Error(`Expected loader with specifier "${e}" to be a module. ${r}`)}}function f(e,t,o,n){const{autoBoot:i,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")}(i,s),s){s({initializeApp:t,define:o,onBootstrapError:n,attachDispatcher:r},e)}}const h="undefined"!=typeof console;"undefined"!=typeof process&&process.env;const m=[/^lwc$/i,/^lwc\/v\//i,/^@lwc\//i,/^lightningmobileruntime\//i];function g(e,t){const r=e.toLowerCase();if(r.startsWith("blob:"))throw new Error(`Cannot map ${t} to blob: URL`);if(r.startsWith("data:"))throw new Error(`Cannot map ${t} to data: URL`)}function E(e){if("string"!=typeof e||0===e.length)throw new Error("Specifier must be a non-empty string");if(function(e){return m.some((t=>t.test(e)))}(e))throw new Error(`Cannot remap protected module: ${e}`)}function y(e,t,r){const o=r[e];void 0!==o?o!==t&&function(e,t,r){h&&console.warn("Package target "+r+", resolving target '"+t+"' for "+e)}(e,t,`already mapped to "${o}", ignoring conflicting mapping`):r[e]=t}function O(e){let t,r=e[0],o=1;for(;o<e.length;){const n=e[o],i=e[o+1];if(o+=2,("optionalAccess"===n||"optionalCall"===n)&&null==r)return;"access"===n||"optionalAccess"===n?(t=r,r=i(r)):"call"!==n&&"optionalCall"!==n||(r=i(((...e)=>r.call(t,...e))),t=void 0)}return r}const R="function"==typeof setTimeout,M="undefined"!=typeof console;class _{__init(){this.defineCache={}}__init2(){this.orderedDefs=[]}__init3(){this.importMapUpdatesCache={}}constructor(e){_.prototype.__init.call(this),_.prototype.__init2.call(this),_.prototype.__init3.call(this),R&&(this.watchdogTimerId=this.startWatchdogTimer()),this.global=e,this.config=e.LWR,this.loaderModule="lwr/loaderLegacy/v/0_22_12",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t;const r=this.tempImportMap.bind(this);e.LWR.importMap=r,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(e.LWR.define),f(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){if(!this.config.requiredModules)throw new Error("Unexpected missing requiredModules");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()&&(R&&clearTimeout(this.watchdogTimerId),this.initApp())}tempImportMap(e){try{const t=function(e){if(!e||"object"!=typeof e)throw new Error("LWR.importMap() requires an object argument");const t=Object.entries(e);if(0===t.length)return h&&console.warn("LWR.importMap() called with empty update object"),null;const r={};for(const[e,o]of t){if(!Array.isArray(o))throw new Error("moduleNames must be an array");if(!e||"string"!=typeof e)throw new Error("moduleScriptURL must be a string");g(e,e);for(const t of o)E(t),t in r?h&&console.warn(`LWR.importMap(): duplicate module "${t}" — already mapped to "${r[t]}", ignoring mapping to "${e}"`):r[t]=e}return{imports:r}}(e);if(!t)return;for(const[e,r]of Object.entries(t.imports))y(e,r,this.importMapUpdatesCache)}catch(e){this.enterErrorState(e)}}getImportMappingsWithUpdates(){const e=this.config.importMappings,t={...O([e,"optionalAccess",e=>e.imports])||{}};for(const[e,r]of Object.entries(this.importMapUpdatesCache))y(e,r,t);return{...e||{},imports:t}}postCustomInit(){this.bootReady=!0,this.canInit()&&(R&&clearTimeout(this.watchdogTimerId),this.initApp())}initApp(){try{const e={baseUrl:this.config.baseUrl,profiler:{logOperationStart:l,logOperationEnd:c},appMetadata:{appId:this.config.appId,bootstrapModule:this.config.bootstrapModule,rootComponent:this.config.rootComponent,rootComponents:this.config.rootComponents}},t=function(e,t,r,o,n){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const i={};if(n){const{factory:r,args:o,exportsObj:s}=u(e,t,n);r(...o),Object.assign(i,s)}else t[2].call(null,i);const{Loader:s}=i;if(!s)throw new Error("Expected Loader class to be defined");const a=new s(r);return o&&o.length&&a.registerExternalModules(o),a.define(e,["exports"],(e=>{Object.assign(e,{define:a.define.bind(a),load:a.load.bind(a),services:a.services,clearRegistry:a.clearRegistry.bind(a)})}),t[3]),a}(this.loaderModule,this.defineCache[this.loaderModule],e,this.config.preloadModules,this.defineCache);this.mountApp(t),t&&t.getModuleWarnings}catch(e){this.enterErrorState(e)}}waitForBody(){return new Promise((e=>{if(document.body)e();else{const t=new MutationObserver((()=>{document.body&&(t.disconnect(),e())}));t.observe(document.documentElement,{childList:!0})}}))}waitForDOMContentLoaded(){return"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}createProfilerModule(e){e("lwr/profiler/v/0_22_12",["exports"],(e=>{Object.assign(e,{logOperationStart:l,logOperationEnd:c})}),{})}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,serverData:n,endpoints:i}=this.config,s=this.getImportMappingsWithUpdates();this.global.LWR=Object.freeze({define:e.define.bind(e),importMap:e.importMap.bind(e),rootComponent:r,rootComponents:o,serverData:n||{},importMappings:s,endpoints:i,env:this.global.LWR.env}),this.orderedDefs.forEach((t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])}));const{initDeferDOM:a}=this.config;e.registerImportMappings(s).then((()=>"undefined"==typeof window||"undefined"==typeof document?Promise.resolve():a?this.waitForDOMContentLoaded():this.waitForBody())).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){l({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):M&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{const e=this.config.requiredModules&&this.config.requiredModules.filter((e=>!this.orderedDefs.includes(e)))||[];this.enterErrorState(new Error(`Failed to load required modules - timed out: ${e.join(", ")}`))}),6e4)}logWarnings(e){for(const t in e)e[t].length&&console.warn(t,e[t])}}const w=globalThis;w.LWR.requiredModules=w.LWR.requiredModules||[],w.LWR.requiredModules.indexOf("lwr/loaderLegacy/v/0_22_12")<0&&w.LWR.requiredModules.push("lwr/loaderLegacy/v/0_22_12"),new _(w)}(),LWR.define("lwr/loaderLegacy/v/0_22_12",["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}"});Object.freeze({code:3008,level:0,message:"Error loading empty code for {0}"});const 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"});Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"});const FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),EXPORTER_ERROR=Object.freeze({code:3021,level:0,message:'Error evaluating module "{0}", error was {1}'}),NO_IMPORT_LWC=Object.freeze({code:3022,level:0,message:'Cannot dynamically import "lwc" with importer "{0}"'}),NO_BLOB_IMPORT=Object.freeze({code:3023,level:0,message:"Cannot import a blob URL"}),NO_IMPORT_LOADER=Object.freeze({code:3024,level:0,message:'Cannot dynamically import the LWR loader with importer "{0}"'}),NO_IMPORT_TRANSPORT=Object.freeze({code:3025,level:0,message:'Cannot dynamically import "transport" with importer "{0}"'}),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,hasProcess="undefined"!=typeof process;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const n=o.slice(0,o.lastIndexOf("/")+1)+e,i=[];let s=-1;for(let e=0;e<n.length;e++)-1!==s?"/"===n[e]&&(i.push(n.slice(s,e+1)),s=-1):"."===n[e]?"."!==n[e+1]||"/"!==n[e+2]&&e+2!==n.length?"/"===n[e+1]||e+1===n.length?e+=1:s=e:(i.pop(),e+=2):s=e;return-1!==s&&i.push(n.slice(s)),t.slice(0,t.length-o.length)+i.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.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)}}))}hasProcess&&process.env,hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const MODULE_LOAD_TIMEOUT_TIMER=6e4;var MODULE_WARNING;!function(e){e.MODULE_REDEFINE="Module redefine attempted";e.MODULE_ALREADY_LOADED="Marking module(s) as externally loaded, but they are already loaded";e.ALIAS_UPDATE="Alias update attempt"}(MODULE_WARNING||(MODULE_WARNING={}));
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.23.0 */
|
|
8
|
+
!function(){"use strict";var e=function(e){return e[e.Start=0]="Start",e[e.End=1]="End",e}(e||{});let t;function r(e){t=e}const o=globalThis.performance,n=void 0!==o&&"function"==typeof o.mark&&"function"==typeof o.clearMarks&&"function"==typeof o.measure&&"function"==typeof o.clearMeasures;function i(e,t){return t?`${e}-${t}`:e}function s(e,t,r){const o=i(e,t);return t&&r?`${o}_${r}`:o}function a(e,t){const r=e||t?{...t}:null;return r&&e&&(r.specifier=e),r}function l({id:r,specifier:i,specifierIndex:l,metadata:c}){if(t)t({id:r,phase:e.Start,specifier:i,metadata:c,specifierIndex:l});else if(n){const e=s(r,i,l),t=a(i,c);o.mark(e,{detail:t})}}function c({id:r,specifier:l,specifierIndex:c,metadata:d}){if(t)t({id:r,phase:e.End,specifier:l,metadata:d,specifierIndex:c});else if(n){const e=s(r,l,c),t=i(r,l),n=a(l,d);o.measure(t,{start:e,detail:n}),o.clearMarks(e),o.clearMeasures(t)}}function d(e){const[,t,r]=e;if(Array.isArray(t)&&"function"==typeof r)return{deps:t,factory:r};if("function"==typeof t)return{deps:[],factory:t};throw new Error("Invalid module definition")}function p(e,t,r){if("exports"===e)return t;const o=r[e];if(!o)throw new Error(`Dependency "${e}" not found in defineCache for loader`);try{return function(e){const{deps:t,factory:r}=d(e);if(t.length>1||1===t.length&&"exports"!==t[0])throw new Error(`Loader dependencies must have no deps or only ['exports']; got [${t.join(", ")}]`);const o={},n=r(o);return void 0!==n?n:o}(o)}catch(t){const r=t instanceof Error?t.message:String(t);throw new Error(`Loader dependency "${e}" has invalid definition: ${r}`)}}function u(e,t,r){try{const{deps:e,factory:o}=function(e){const{deps:t,factory:r}=d(e);if(t.includes("exports"))return{deps:t,factory:r};const o=0===t.length;return{deps:["exports",...t],factory:(e,...t)=>{const n=o?r(e):r(...t);void 0!==n&&"object"==typeof n&&Object.assign(e,n)}}}(t),n={};return{factory:o,args:e.map((e=>p(e,n,r))),exportsObj:n}}catch(t){const r=t instanceof Error?t.message:String(t);throw new Error(`Expected loader with specifier "${e}" to be a module. ${r}`)}}function f(e,t,o,n){const{autoBoot:i,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")}(i,s),s){s({initializeApp:t,define:o,onBootstrapError:n,attachDispatcher:r},e)}}const h="undefined"!=typeof console;"undefined"!=typeof process&&process.env;const m=[/^lwc$/i,/^lwc\/v\//i,/^@lwc\//i,/^lightningmobileruntime\//i];function g(e,t){const r=e.toLowerCase();if(r.startsWith("blob:"))throw new Error(`Cannot map ${t} to blob: URL`);if(r.startsWith("data:"))throw new Error(`Cannot map ${t} to data: URL`)}function E(e){if("string"!=typeof e||0===e.length)throw new Error("Specifier must be a non-empty string");if(function(e){return m.some((t=>t.test(e)))}(e))throw new Error(`Cannot remap protected module: ${e}`)}function y(e,t,r){const o=r[e];void 0!==o?o!==t&&function(e,t,r){h&&console.warn("Package target "+r+", resolving target '"+t+"' for "+e)}(e,t,`already mapped to "${o}", ignoring conflicting mapping`):r[e]=t}function O(e){let t,r=e[0],o=1;for(;o<e.length;){const n=e[o],i=e[o+1];if(o+=2,("optionalAccess"===n||"optionalCall"===n)&&null==r)return;"access"===n||"optionalAccess"===n?(t=r,r=i(r)):"call"!==n&&"optionalCall"!==n||(r=i(((...e)=>r.call(t,...e))),t=void 0)}return r}const R="function"==typeof setTimeout,M="undefined"!=typeof console;class _{__init(){this.defineCache={}}__init2(){this.orderedDefs=[]}__init3(){this.importMapUpdatesCache={}}constructor(e){_.prototype.__init.call(this),_.prototype.__init2.call(this),_.prototype.__init3.call(this),R&&(this.watchdogTimerId=this.startWatchdogTimer()),this.global=e,this.config=e.LWR,this.loaderModule="lwr/loaderLegacy/v/0_23_0",this.errorHandler=this.config.onError;const t=this.tempDefine.bind(this);e.LWR.define=t;const r=this.tempImportMap.bind(this);e.LWR.importMap=r,this.bootReady=this.config.autoBoot;try{this.createProfilerModule(e.LWR.define),f(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){if(!this.config.requiredModules)throw new Error("Unexpected missing requiredModules");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()&&(R&&clearTimeout(this.watchdogTimerId),this.initApp())}tempImportMap(e){try{const t=function(e){if(!e||"object"!=typeof e)throw new Error("LWR.importMap() requires an object argument");const t=Object.entries(e);if(0===t.length)return h&&console.warn("LWR.importMap() called with empty update object"),null;const r={};for(const[e,o]of t){if(!Array.isArray(o))throw new Error("moduleNames must be an array");if(!e||"string"!=typeof e)throw new Error("moduleScriptURL must be a string");g(e,e);for(const t of o)E(t),t in r?h&&console.warn(`LWR.importMap(): duplicate module "${t}" — already mapped to "${r[t]}", ignoring mapping to "${e}"`):r[t]=e}return{imports:r}}(e);if(!t)return;for(const[e,r]of Object.entries(t.imports))y(e,r,this.importMapUpdatesCache)}catch(e){this.enterErrorState(e)}}getImportMappingsWithUpdates(){const e=this.config.importMappings,t={...O([e,"optionalAccess",e=>e.imports])||{}};for(const[e,r]of Object.entries(this.importMapUpdatesCache))y(e,r,t);return{...e||{},imports:t}}postCustomInit(){this.bootReady=!0,this.canInit()&&(R&&clearTimeout(this.watchdogTimerId),this.initApp())}initApp(){try{const e={baseUrl:this.config.baseUrl,profiler:{logOperationStart:l,logOperationEnd:c},appMetadata:{appId:this.config.appId,bootstrapModule:this.config.bootstrapModule,rootComponent:this.config.rootComponent,rootComponents:this.config.rootComponents}},t=function(e,t,r,o,n){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const i={};if(n){const{factory:r,args:o,exportsObj:s}=u(e,t,n);r(...o),Object.assign(i,s)}else t[2].call(null,i);const{Loader:s}=i;if(!s)throw new Error("Expected Loader class to be defined");const a=new s(r);return o&&o.length&&a.registerExternalModules(o),a.define(e,["exports"],(e=>{Object.assign(e,{define:a.define.bind(a),load:a.load.bind(a),services:a.services,clearRegistry:a.clearRegistry.bind(a)})}),t[3]),a}(this.loaderModule,this.defineCache[this.loaderModule],e,this.config.preloadModules,this.defineCache);this.mountApp(t),t&&t.getModuleWarnings}catch(e){this.enterErrorState(e)}}waitForBody(){return new Promise((e=>{if(document.body)e();else{const t=new MutationObserver((()=>{document.body&&(t.disconnect(),e())}));t.observe(document.documentElement,{childList:!0})}}))}waitForDOMContentLoaded(){return"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}createProfilerModule(e){e("lwr/profiler/v/0_23_0",["exports"],(e=>{Object.assign(e,{logOperationStart:l,logOperationEnd:c})}),{})}mountApp(e){const{bootstrapModule:t,rootComponent:r,rootComponents:o,serverData:n,endpoints:i}=this.config,s=this.getImportMappingsWithUpdates();this.global.LWR=Object.freeze({define:e.define.bind(e),importMap:e.importMap.bind(e),rootComponent:r,rootComponents:o,serverData:n||{},importMappings:s,endpoints:i,env:this.global.LWR.env}),this.orderedDefs.forEach((t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])}));const{initDeferDOM:a}=this.config;e.registerImportMappings(s).then((()=>"undefined"==typeof window||"undefined"==typeof document?Promise.resolve():a?this.waitForDOMContentLoaded():this.waitForBody())).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r||t} could not be loaded: ${e}`))}))}enterErrorState(e){l({id:"lwr.bootstrap.error"}),this.errorHandler?this.errorHandler(e):M&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{const e=this.config.requiredModules&&this.config.requiredModules.filter((e=>!this.orderedDefs.includes(e)))||[];this.enterErrorState(new Error(`Failed to load required modules - timed out: ${e.join(", ")}`))}),6e4)}logWarnings(e){for(const t in e)e[t].length&&console.warn(t,e[t])}}const w=globalThis;w.LWR.requiredModules=w.LWR.requiredModules||[],w.LWR.requiredModules.indexOf("lwr/loaderLegacy/v/0_23_0")<0&&w.LWR.requiredModules.push("lwr/loaderLegacy/v/0_23_0"),new _(w)}(),LWR.define("lwr/loaderLegacy/v/0_23_0",["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}"});Object.freeze({code:3008,level:0,message:"Error loading empty code for {0}"});const 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"});Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"});const FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),EXPORTER_ERROR=Object.freeze({code:3021,level:0,message:'Error evaluating module "{0}", error was {1}'}),NO_IMPORT_LWC=Object.freeze({code:3022,level:0,message:'Cannot dynamically import "lwc" with importer "{0}"'}),NO_BLOB_IMPORT=Object.freeze({code:3023,level:0,message:"Cannot import a blob URL"}),NO_IMPORT_LOADER=Object.freeze({code:3024,level:0,message:'Cannot dynamically import the LWR loader with importer "{0}"'}),NO_IMPORT_TRANSPORT=Object.freeze({code:3025,level:0,message:'Cannot dynamically import "transport" with importer "{0}"'}),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,hasProcess="undefined"!=typeof process;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const n=o.slice(0,o.lastIndexOf("/")+1)+e,i=[];let s=-1;for(let e=0;e<n.length;e++)-1!==s?"/"===n[e]&&(i.push(n.slice(s,e+1)),s=-1):"."===n[e]?"."!==n[e+1]||"/"!==n[e+2]&&e+2!==n.length?"/"===n[e+1]||e+1===n.length?e+=1:s=e:(i.pop(),e+=2):s=e;return-1!==s&&i.push(n.slice(s)),t.slice(0,t.length-o.length)+i.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.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)}}))}hasProcess&&process.env,hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const MODULE_LOAD_TIMEOUT_TIMER=6e4;var MODULE_WARNING;!function(e){e.MODULE_REDEFINE="Module redefine attempted";e.MODULE_ALREADY_LOADED="Marking module(s) as externally loaded, but they are already loaded";e.ALIAS_UPDATE="Alias update attempt"}(MODULE_WARNING||(MODULE_WARNING={}));
|
|
9
9
|
/*!
|
|
10
10
|
* Copyright (C) 2023 salesforce.com, inc.
|
|
11
11
|
*/
|
|
@@ -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.
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.23.0 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -461,7 +461,7 @@
|
|
|
461
461
|
// Parse configuration
|
|
462
462
|
this.global = global;
|
|
463
463
|
this.config = global.LWR ;
|
|
464
|
-
this.loaderModule = 'lwr/loaderLegacy/v/
|
|
464
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_23_0';
|
|
465
465
|
|
|
466
466
|
// Set up error handler
|
|
467
467
|
this.errorHandler = this.config.onError ;
|
|
@@ -661,7 +661,7 @@
|
|
|
661
661
|
const exporter = (exports) => {
|
|
662
662
|
Object.assign(exports, { logOperationStart, logOperationEnd });
|
|
663
663
|
};
|
|
664
|
-
define('lwr/profiler/v/
|
|
664
|
+
define('lwr/profiler/v/0_23_0', ['exports'], exporter, {});
|
|
665
665
|
}
|
|
666
666
|
|
|
667
667
|
// Set up the application globals, import map, root custom element...
|
|
@@ -758,8 +758,8 @@
|
|
|
758
758
|
// The loader module is ALWAYS required
|
|
759
759
|
const GLOBAL = globalThis ;
|
|
760
760
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
761
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/
|
|
762
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/
|
|
761
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_23_0') < 0) {
|
|
762
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_23_0');
|
|
763
763
|
}
|
|
764
764
|
new LoaderShim(GLOBAL);
|
|
765
765
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Module Loader Shim v0.
|
|
7
|
+
/* LWR Module Loader Shim v0.23.0 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -283,6 +283,7 @@
|
|
|
283
283
|
|
|
284
284
|
|
|
285
285
|
|
|
286
|
+
|
|
286
287
|
/* eslint-disable lwr/no-unguarded-apis */
|
|
287
288
|
const hasSetTimeout = typeof setTimeout === 'function';
|
|
288
289
|
const hasConsole = typeof console !== 'undefined';
|
|
@@ -309,7 +310,7 @@
|
|
|
309
310
|
// Parse configuration
|
|
310
311
|
this.global = global;
|
|
311
312
|
this.config = global.LWR ;
|
|
312
|
-
this.loaderSpecifier = 'lwr/loader/v/
|
|
313
|
+
this.loaderSpecifier = 'lwr/loader/v/0_23_0';
|
|
313
314
|
|
|
314
315
|
// Set up error handler
|
|
315
316
|
this.errorHandler = this.config.onError ;
|
|
@@ -317,7 +318,7 @@
|
|
|
317
318
|
// Set up onAppInit handler
|
|
318
319
|
this.initAppHandler = this.config.onInitApp ;
|
|
319
320
|
|
|
320
|
-
// Set up the temporary LWR.define function
|
|
321
|
+
// Set up the temporary LWR.define function
|
|
321
322
|
const tempDefine = this.tempDefine.bind(this);
|
|
322
323
|
global.LWR.define = tempDefine;
|
|
323
324
|
this.bootReady = this.config.autoBoot;
|
|
@@ -474,7 +475,7 @@
|
|
|
474
475
|
const exporter = (exports) => {
|
|
475
476
|
Object.assign(exports, { logOperationStart, logOperationEnd });
|
|
476
477
|
};
|
|
477
|
-
define('lwr/profiler/v/
|
|
478
|
+
define('lwr/profiler/v/0_23_0', ['exports'], exporter);
|
|
478
479
|
}
|
|
479
480
|
|
|
480
481
|
// Set up the application globals, import map, root custom element...
|
|
@@ -483,9 +484,13 @@
|
|
|
483
484
|
this.config;
|
|
484
485
|
|
|
485
486
|
const importsObj = imports || {};
|
|
486
|
-
|
|
487
|
+
|
|
488
|
+
// Set global LWR.define to loader.define and expose the public-only importMap.
|
|
489
|
+
// The wrapper intentionally omits the internal rootSpecifiers parameter so external
|
|
490
|
+
// callers cannot bypass runtime validation by triggering the bootstrap path.
|
|
487
491
|
this.global.LWR = Object.freeze({
|
|
488
492
|
define: loader.define.bind(loader),
|
|
493
|
+
importMap: (update) => loader.importMap(update),
|
|
489
494
|
rootComponent,
|
|
490
495
|
rootComponents,
|
|
491
496
|
serverData: serverData || {},
|
|
@@ -508,10 +513,7 @@
|
|
|
508
513
|
|
|
509
514
|
// Load the import mappings and application bootstrap module
|
|
510
515
|
loader
|
|
511
|
-
.
|
|
512
|
-
bootstrapModule,
|
|
513
|
-
rootComponent ,
|
|
514
|
-
])
|
|
516
|
+
.importMap({ imports: importsObj, index }, [bootstrapModule, rootComponent ])
|
|
515
517
|
.then(() => {
|
|
516
518
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
517
519
|
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
@@ -574,14 +576,14 @@
|
|
|
574
576
|
// The loader module is ALWAYS required
|
|
575
577
|
const GLOBAL = globalThis ;
|
|
576
578
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
577
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/
|
|
578
|
-
GLOBAL.LWR.requiredModules.push('lwr/loader/v/
|
|
579
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_23_0') < 0) {
|
|
580
|
+
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_23_0');
|
|
579
581
|
}
|
|
580
582
|
new LoaderShim(GLOBAL);
|
|
581
583
|
|
|
582
584
|
})();
|
|
583
585
|
|
|
584
|
-
LWR.define('lwr/loader/v/
|
|
586
|
+
LWR.define('lwr/loader/v/0_23_0', ['exports'], (function (exports) { 'use strict';
|
|
585
587
|
|
|
586
588
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
587
589
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1014,11 +1016,7 @@ LWR.define('lwr/loader/v/0_22_12', ['exports'], (function (exports) { 'use stric
|
|
|
1014
1016
|
return this.config.baseUrl || '';
|
|
1015
1017
|
}
|
|
1016
1018
|
|
|
1017
|
-
registerImportMappings(newImportMetadata, rootSpecifiers) {
|
|
1018
|
-
if (!rootSpecifiers || rootSpecifiers.length === 0) {
|
|
1019
|
-
const imports = newImportMetadata ? JSON.stringify(newImportMetadata) : 'undefined';
|
|
1020
|
-
throw new LoaderError(BAD_IMPORT_METADATA, [imports, rootSpecifiers ? '[]' : 'undefined']);
|
|
1021
|
-
}
|
|
1019
|
+
registerImportMappings(newImportMetadata, rootSpecifiers = []) {
|
|
1022
1020
|
if (!newImportMetadata) {
|
|
1023
1021
|
throw new LoaderError(BAD_IMPORT_METADATA, ['undefined', JSON.stringify(rootSpecifiers)]);
|
|
1024
1022
|
}
|
|
@@ -1028,6 +1026,8 @@ LWR.define('lwr/loader/v/0_22_12', ['exports'], (function (exports) { 'use stric
|
|
|
1028
1026
|
JSON.stringify(rootSpecifiers),
|
|
1029
1027
|
]);
|
|
1030
1028
|
}
|
|
1029
|
+
// An empty rootSpecifiers list is valid for non-bootstrap registrations;
|
|
1030
|
+
// any specifier not in the list receives isRoot: false.
|
|
1031
1031
|
const index = newImportMetadata.index || {};
|
|
1032
1032
|
for (const [uri, specifiers] of Object.entries(newImportMetadata.imports)) {
|
|
1033
1033
|
specifiers.forEach((specifier) => {
|
|
@@ -1050,6 +1050,16 @@ LWR.define('lwr/loader/v/0_22_12', ['exports'], (function (exports) { 'use stric
|
|
|
1050
1050
|
}
|
|
1051
1051
|
}
|
|
1052
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
* Returns the raw URI stored for a specifier, or `undefined` if not yet mapped.
|
|
1055
|
+
* Used by the runtime `importMap()` path to detect cross-call duplicates while
|
|
1056
|
+
* allowing truly idempotent re-registrations (same specifier, same URI) to pass
|
|
1057
|
+
* through silently.
|
|
1058
|
+
*/
|
|
1059
|
+
getMappingUri(specifier) {
|
|
1060
|
+
return _optionalChain([this, 'access', _ => _.importURICache, 'access', _2 => _2.get, 'call', _3 => _3(specifier), 'optionalAccess', _4 => _4.uri]);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1053
1063
|
// Get URL from the local cache or return undefiend
|
|
1054
1064
|
getURI(specifier) {
|
|
1055
1065
|
return this.importURICache && this.importURICache.has(specifier)
|
|
@@ -1147,7 +1157,7 @@ LWR.define('lwr/loader/v/0_22_12', ['exports'], (function (exports) { 'use stric
|
|
|
1147
1157
|
}
|
|
1148
1158
|
|
|
1149
1159
|
async fetchNewMappings(specifier) {
|
|
1150
|
-
if (!hasSetTimeout || !_optionalChain([this, 'access',
|
|
1160
|
+
if (!hasSetTimeout || !_optionalChain([this, 'access', _5 => _5.config, 'optionalAccess', _6 => _6.flags, 'optionalAccess', _7 => _7.batchMappings])) {
|
|
1151
1161
|
return this.fetchNewMappingsInner(specifier);
|
|
1152
1162
|
}
|
|
1153
1163
|
|
|
@@ -2236,6 +2246,101 @@ LWR.define('lwr/loader/v/0_22_12', ['exports'], (function (exports) { 'use stric
|
|
|
2236
2246
|
}
|
|
2237
2247
|
}
|
|
2238
2248
|
|
|
2249
|
+
/**
|
|
2250
|
+
* Ensures the update object key is a safe, loader-supported script URL (not a bare specifier).
|
|
2251
|
+
* Covers dangerous schemes and URL-key shape in one place.
|
|
2252
|
+
*/
|
|
2253
|
+
function assertValidImportMapUrlKey(moduleScriptURL) {
|
|
2254
|
+
const lowerUri = moduleScriptURL.toLowerCase();
|
|
2255
|
+
|
|
2256
|
+
if (lowerUri.startsWith('blob:')) {
|
|
2257
|
+
throw new Error(`Cannot map ${moduleScriptURL} to blob: URL`);
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
if (lowerUri.startsWith('data:')) {
|
|
2261
|
+
throw new Error(`Cannot map ${moduleScriptURL} to data: URL`);
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
if (!/^[./]|^https?:/.test(moduleScriptURL)) {
|
|
2265
|
+
throw new Error(
|
|
2266
|
+
`LWR.importMap(): "${moduleScriptURL}" is not a valid URL key. Keys must be URL paths (e.g. "/path/to/module.js"), not module specifiers. Transitive specifier aliasing is not supported by this loader.`,
|
|
2267
|
+
);
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
/**
|
|
2272
|
+
* Validates an ImportMapUpdate and wraps it as ImportMetadata for the fingerprints loader.
|
|
2273
|
+
*
|
|
2274
|
+
* Does not apply legacy-style protected-specifier blocking; system modules are expected to be
|
|
2275
|
+
* defined at bootstrap, and `importMap` write-once semantics handle redundant runtime entries.
|
|
2276
|
+
*
|
|
2277
|
+
* Duplicate specifiers in the same update are de-duplicated silently (first occurrence wins).
|
|
2278
|
+
* An empty object is a silent no-op (returns null).
|
|
2279
|
+
*/
|
|
2280
|
+
function validateAndWrapAsImportMetadata(update) {
|
|
2281
|
+
if (!update || typeof update !== 'object') {
|
|
2282
|
+
throw new Error('LWR.importMap() requires an object argument');
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
const entries = Object.entries(update);
|
|
2286
|
+
if (entries.length === 0) {
|
|
2287
|
+
return null;
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
const seenSpecifiers = new Set();
|
|
2291
|
+
const validatedImports = {};
|
|
2292
|
+
|
|
2293
|
+
for (const [moduleScriptURL, moduleNames] of entries) {
|
|
2294
|
+
if (!moduleScriptURL || typeof moduleScriptURL !== 'string') {
|
|
2295
|
+
throw new Error('moduleScriptURL must be a string');
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
if (!Array.isArray(moduleNames)) {
|
|
2299
|
+
throw new Error('moduleNames must be an array');
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
assertValidImportMapUrlKey(moduleScriptURL);
|
|
2303
|
+
|
|
2304
|
+
const validatedNames = [];
|
|
2305
|
+
for (const moduleName of moduleNames) {
|
|
2306
|
+
if (typeof moduleName !== 'string' || moduleName.length === 0) {
|
|
2307
|
+
throw new Error('Specifier must be a non-empty string');
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2310
|
+
if (!seenSpecifiers.has(moduleName)) {
|
|
2311
|
+
seenSpecifiers.add(moduleName);
|
|
2312
|
+
validatedNames.push(moduleName);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
if (validatedNames.length > 0) {
|
|
2317
|
+
validatedImports[moduleScriptURL] = validatedNames;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
if (Object.keys(validatedImports).length === 0) {
|
|
2322
|
+
return null;
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
return { imports: validatedImports };
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
/**
|
|
2329
|
+
* Returns true when `update` carries the `ImportMetadata` shape (an `imports` object key),
|
|
2330
|
+
* signalling that it should be passed through to the resolver directly rather than treated
|
|
2331
|
+
* as a public-API `ImportMapUpdate`.
|
|
2332
|
+
*/
|
|
2333
|
+
function isImportMetadata(update) {
|
|
2334
|
+
const candidate = update ;
|
|
2335
|
+
return (
|
|
2336
|
+
candidate !== null &&
|
|
2337
|
+
typeof candidate === 'object' &&
|
|
2338
|
+
'imports' in candidate &&
|
|
2339
|
+
typeof candidate.imports === 'object' &&
|
|
2340
|
+
!Array.isArray(candidate.imports)
|
|
2341
|
+
);
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2239
2344
|
/**
|
|
2240
2345
|
* The LWR loader is inspired and borrows from the algorithms and native browser principles of https://github.com/systemjs/systemjs
|
|
2241
2346
|
*/
|
|
@@ -2369,8 +2474,75 @@ LWR.define('lwr/loader/v/0_22_12', ['exports'], (function (exports) { 'use stric
|
|
|
2369
2474
|
return this.registry.resolve(id, importer);
|
|
2370
2475
|
}
|
|
2371
2476
|
|
|
2477
|
+
/**
|
|
2478
|
+
* Apply import map updates at runtime, or register bootstrap import mappings.
|
|
2479
|
+
*
|
|
2480
|
+
* **Runtime usage** (public API, consistent with `LWR.importMap()` on the legacy loader):
|
|
2481
|
+
* `importMap({ [moduleScriptURL]: [moduleName1, moduleName2, ...] })`
|
|
2482
|
+
* Validates the update and registers the new mappings dynamically.
|
|
2483
|
+
*
|
|
2484
|
+
* **Bootstrap / internal usage** (replaces `registerImportMappings`):
|
|
2485
|
+
* `importMap(importMetadata)` or `importMap(importMetadata, rootSpecifiers)`
|
|
2486
|
+
* Detected at runtime by the `ImportMetadata` shape (presence of an `imports` object).
|
|
2487
|
+
* This branch **does not** run `validateAndWrapAsImportMetadata` (URL-key checks /
|
|
2488
|
+
* runtime-payload dedupe). That is intentional: bootstrap must preserve
|
|
2489
|
+
* `index` fingerprints and use `ImportMetadataResolver.registerImportMappings` merge
|
|
2490
|
+
* semantics unchanged from the pre-`importMap` API.
|
|
2491
|
+
*
|
|
2492
|
+
* **Who may use this branch:** Platform/shim code with trusted config (see
|
|
2493
|
+
* `shim/shim.ts`, which calls `loader.importMap({ imports, index }, roots)`). The
|
|
2494
|
+
* public `LWR.importMap` wrapper only forwards the flat runtime update shape; any
|
|
2495
|
+
* code with a direct `Loader` reference could still pass an `ImportMetadata`-shaped
|
|
2496
|
+
* object — same trust boundary as calling `registerImportMappings` before.
|
|
2497
|
+
*
|
|
2498
|
+
* @param update - Runtime: `ImportMapUpdate` mapping script URLs to the module names they define.
|
|
2499
|
+
* Bootstrap: `ImportMetadata` with an `imports` object (and optional `index`).
|
|
2500
|
+
* @param rootSpecifiers - Bootstrap only: root module specifiers for the initial registration.
|
|
2501
|
+
* Optional — omit when the root specifiers are not known.
|
|
2502
|
+
*/
|
|
2503
|
+
async importMap(update, rootSpecifiers) {
|
|
2504
|
+
if (isImportMetadata(update)) {
|
|
2505
|
+
this.registry.getImportMetadataResolver().registerImportMappings(update, rootSpecifiers);
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
const resolver = this.registry.getImportMetadataResolver();
|
|
2509
|
+
const importMetadata = validateAndWrapAsImportMetadata(update );
|
|
2510
|
+
if (!importMetadata) {
|
|
2511
|
+
return;
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
const dedupedImports = {};
|
|
2515
|
+
for (const [uri, specifiers] of Object.entries(importMetadata.imports)) {
|
|
2516
|
+
const newSpecifiers = [];
|
|
2517
|
+
for (const specifier of specifiers) {
|
|
2518
|
+
const existingUri = resolver.getMappingUri(specifier);
|
|
2519
|
+
if (existingUri !== undefined) ; else {
|
|
2520
|
+
newSpecifiers.push(specifier);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
if (newSpecifiers.length > 0) {
|
|
2524
|
+
dedupedImports[uri] = newSpecifiers;
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
if (Object.keys(dedupedImports).length === 0) {
|
|
2529
|
+
return;
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
const filtered = { imports: dedupedImports };
|
|
2533
|
+
const specs = Object.values(filtered.imports).flat();
|
|
2534
|
+
resolver.registerImportMappings(filtered, specs);
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
/**
|
|
2538
|
+
* @deprecated Use `importMap(metadata, rootSpecifiers)` instead.
|
|
2539
|
+
*/
|
|
2372
2540
|
async registerImportMappings(mappings, rootSpecifiers) {
|
|
2373
|
-
|
|
2541
|
+
if (hasConsole) {
|
|
2542
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
2543
|
+
console.warn('registerImportMappings() is deprecated. Use importMap() instead.');
|
|
2544
|
+
}
|
|
2545
|
+
return this.importMap(mappings, rootSpecifiers);
|
|
2374
2546
|
}
|
|
2375
2547
|
|
|
2376
2548
|
/**
|