@lwrjs/loader 0.4.7 → 0.5.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/README.md +1 -0
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +10 -6
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +2 -2
- package/build/assets/prod/lwr-loader-shim-legacy.js +4 -4
- package/build/assets/prod/lwr-loader-shim.bundle.js +56 -28
- package/build/assets/prod/lwr-loader-shim.bundle.min.js +3 -3
- package/build/assets/prod/lwr-loader-shim.js +8 -7
- package/build/bundle/prod/lwr/esmLoader/esmLoader.js +1 -1
- package/build/cjs/modules/lwr/esmLoader/esmLoader.cjs +3 -1
- package/build/cjs/modules/lwr/esmLoader/importResolver.cjs +3 -3
- package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +38 -18
- package/build/modules/lwr/esmLoader/esmLoader.js +8 -6
- package/build/modules/lwr/loader/loader.js +48 -21
- package/build/modules/lwr/loaderLegacy/loaderLegacy.js +6 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -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.5.0 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
// Parse configuration
|
|
76
76
|
this.global = global;
|
|
77
77
|
this.config = global.LWR;
|
|
78
|
-
this.loaderModule = 'lwr/loaderLegacy/v/
|
|
78
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_5_0';
|
|
79
79
|
// Set up the temporary LWR.define function and customInit hook
|
|
80
80
|
const tempDefine = this.tempDefine.bind(this);
|
|
81
81
|
global.LWR.define = tempDefine;
|
|
@@ -214,14 +214,14 @@
|
|
|
214
214
|
// The loader module is ALWAYS required
|
|
215
215
|
const GLOBAL = globalThis;
|
|
216
216
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
217
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/
|
|
218
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/
|
|
217
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_5_0') < 0) {
|
|
218
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_5_0');
|
|
219
219
|
}
|
|
220
220
|
new LoaderShim(GLOBAL);
|
|
221
221
|
|
|
222
222
|
}());
|
|
223
223
|
|
|
224
|
-
LWR.define('lwr/loaderLegacy/v/
|
|
224
|
+
LWR.define('lwr/loaderLegacy/v/0_5_0', ['exports'], function (exports) { 'use strict';
|
|
225
225
|
|
|
226
226
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
227
227
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -652,6 +652,7 @@ LWR.define('lwr/loaderLegacy/v/0_4_7', ['exports'], function (exports) { 'use st
|
|
|
652
652
|
const response = resolveHook(aliasedId, { parentUrl });
|
|
653
653
|
let result;
|
|
654
654
|
if (response || response === null) {
|
|
655
|
+
// eslint-disable-next-line no-await-in-loop
|
|
655
656
|
result = isResponseAPromise(response) ? await response : response;
|
|
656
657
|
}
|
|
657
658
|
// if result is not null, attempt resolution
|
|
@@ -875,6 +876,7 @@ LWR.define('lwr/loaderLegacy/v/0_4_7', ['exports'], function (exports) { 'use st
|
|
|
875
876
|
if (dependencyModuleRecords) {
|
|
876
877
|
for (let i = 0; i < dependencyModuleRecords.length; i++) {
|
|
877
878
|
const depRecord = dependencyModuleRecords[i];
|
|
879
|
+
// eslint-disable-next-line no-await-in-loop
|
|
878
880
|
await this.instantiateAll(depRecord, instantiatedMap);
|
|
879
881
|
}
|
|
880
882
|
}
|
|
@@ -977,6 +979,7 @@ LWR.define('lwr/loaderLegacy/v/0_4_7', ['exports'], function (exports) { 'use st
|
|
|
977
979
|
const depRecord = dependencyModuleRecords[i];
|
|
978
980
|
if (!depRecord.evaluated && !evaluationMap[depRecord.id]) {
|
|
979
981
|
evaluationMap[depRecord.id] = true;
|
|
982
|
+
// eslint-disable-next-line no-await-in-loop
|
|
980
983
|
await this.evaluateModule(depRecord, evaluationMap);
|
|
981
984
|
}
|
|
982
985
|
}
|
|
@@ -1006,7 +1009,8 @@ LWR.define('lwr/loaderLegacy/v/0_4_7', ['exports'], function (exports) { 'use st
|
|
|
1006
1009
|
const loadHook = loadHooks[i];
|
|
1007
1010
|
const response = loadHook(resolvedId, parentUrl);
|
|
1008
1011
|
const result = (isResponseAPromise(response)
|
|
1009
|
-
?
|
|
1012
|
+
? // eslint-disable-next-line no-await-in-loop
|
|
1013
|
+
await evaluateLoadHook(resolvedId, response)
|
|
1010
1014
|
: response);
|
|
1011
1015
|
if (result === undefined) {
|
|
1012
1016
|
throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
|
|
@@ -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";function e(e,t,r,o){const{autoBoot:s,customInit:n}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(s,n),n){n({initializeApp:t,define:r,onBootstrapError:o},e)}}const t="function"==typeof setTimeout,r="undefined"!=typeof console;const o=globalThis;o.LWR.requiredModules=o.LWR.requiredModules||[],o.LWR.requiredModules.indexOf("lwr/loaderLegacy/v/
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.5.0 */
|
|
8
|
+
!function(){"use strict";function e(e,t,r,o){const{autoBoot:s,customInit:n}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(s,n),n){n({initializeApp:t,define:r,onBootstrapError:o},e)}}const t="function"==typeof setTimeout,r="undefined"!=typeof console;const o=globalThis;o.LWR.requiredModules=o.LWR.requiredModules||[],o.LWR.requiredModules.indexOf("lwr/loaderLegacy/v/0_5_0")<0&&o.LWR.requiredModules.push("lwr/loaderLegacy/v/0_5_0"),new class{constructor(r){this.defineCache={},this.orderedDefs=[],this.global=r,this.config=r.LWR,this.loaderModule="lwr/loaderLegacy/v/0_5_0";const o=this.tempDefine.bind(this);r.LWR.define=o,this.bootReady=this.config.autoBoot,t&&(this.watchdogTimerId=this.startWatchdogTimer());try{e(Object.freeze(this.config),this.postCustomInit.bind(this),o,e=>{this.errorHandler=e})}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every(e=>this.orderedDefs.includes(e));return this.bootReady&&e}tempDefine(...e){const r=e[0];this.defineCache[r]=e,this.orderedDefs.push(r),this.canInit()&&(t&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const s={};t[2].call(null,s);const{Loader:n}=s,i=new n(r);return o&&o.length&&i.registerExternalModules(o),i.define(e,["exports"],e=>{Object.assign(e,{define:i.define.bind(i),load:i.load.bind(i),services:i.services})},t[3]),i}(this.loaderModule,this.defineCache[this.loaderModule],this.config.baseUrl,this.config.preloadModules);this.mountApp(e)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise(e=>{document.addEventListener("DOMContentLoaded",()=>{e()})})}mountApp(e){const{bootstrapModule:t,rootComponent:r,importMappings:o,rootComponents:s,endpoints:n}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:s,importMappings:o,endpoints:n}),this.orderedDefs.forEach(t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])});const{disableInitDefer:i}=this.config;e.registerImportMappings(o).then(()=>{if(!i)return this.waitForDOMContentLoaded()}).then(()=>e.load(t)).catch(e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))})}enterErrorState(e){this.errorHandler?this.errorHandler(e):r&&console.error("An error occurred during LWR bootstrap. "+e.message,e.stack)}startWatchdogTimer(){return setTimeout(()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))},3e5)}}(o)}(),LWR.define("lwr/loaderLegacy/v/0_5_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}"}),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=void 0;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}
|
|
9
9
|
/**
|
|
10
10
|
* Check if a string is a URL based on Common Internet Scheme Syntax
|
|
11
11
|
* https://www.ietf.org/rfc/rfc1738.txt
|
|
@@ -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.5.0 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
// Parse configuration
|
|
76
76
|
this.global = global;
|
|
77
77
|
this.config = global.LWR;
|
|
78
|
-
this.loaderModule = 'lwr/loaderLegacy/v/
|
|
78
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_5_0';
|
|
79
79
|
// Set up the temporary LWR.define function and customInit hook
|
|
80
80
|
const tempDefine = this.tempDefine.bind(this);
|
|
81
81
|
global.LWR.define = tempDefine;
|
|
@@ -214,8 +214,8 @@
|
|
|
214
214
|
// The loader module is ALWAYS required
|
|
215
215
|
const GLOBAL = globalThis;
|
|
216
216
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
217
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/
|
|
218
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/
|
|
217
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_5_0') < 0) {
|
|
218
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_5_0');
|
|
219
219
|
}
|
|
220
220
|
new LoaderShim(GLOBAL);
|
|
221
221
|
|
|
@@ -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.5.0 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
// Parse configuration
|
|
75
75
|
this.global = global;
|
|
76
76
|
this.config = global.LWR;
|
|
77
|
-
this.loaderModule = 'lwr/loader/v/
|
|
77
|
+
this.loaderModule = 'lwr/loader/v/0_5_0';
|
|
78
78
|
// Set up the temporary LWR.define function and customInit hook
|
|
79
79
|
const tempDefine = this.tempDefine.bind(this);
|
|
80
80
|
global.LWR.define = tempDefine;
|
|
@@ -163,14 +163,15 @@
|
|
|
163
163
|
}
|
|
164
164
|
// Set up the application globals, import map, root custom element...
|
|
165
165
|
mountApp(loader) {
|
|
166
|
-
const { bootstrapModule, rootComponent, rootComponents, endpoints, imports } = this.config;
|
|
166
|
+
const { bootstrapModule, rootComponent, rootComponents, endpoints, imports, index } = this.config;
|
|
167
167
|
// Set global LWR.define to loader.define
|
|
168
168
|
this.global.LWR = Object.freeze({
|
|
169
169
|
define: loader.define.bind(loader),
|
|
170
170
|
rootComponent,
|
|
171
171
|
rootComponents,
|
|
172
|
-
imports,
|
|
173
172
|
endpoints,
|
|
173
|
+
imports: imports || {},
|
|
174
|
+
index: index || {},
|
|
174
175
|
});
|
|
175
176
|
// Redefine all modules in the temporary cache
|
|
176
177
|
this.orderedDefs.forEach((specifier) => {
|
|
@@ -182,7 +183,7 @@
|
|
|
182
183
|
const { disableInitDefer } = this.config;
|
|
183
184
|
// Load the import mappings and application bootstrap module
|
|
184
185
|
loader
|
|
185
|
-
.registerImportMappings(imports, [bootstrapModule, rootComponent])
|
|
186
|
+
.registerImportMappings({ imports, index }, [bootstrapModule, rootComponent])
|
|
186
187
|
.then(() => {
|
|
187
188
|
if (!disableInitDefer) {
|
|
188
189
|
return this.waitForDOMContentLoaded();
|
|
@@ -217,14 +218,14 @@
|
|
|
217
218
|
// The loader module is ALWAYS required
|
|
218
219
|
const GLOBAL = globalThis;
|
|
219
220
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
220
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/
|
|
221
|
-
GLOBAL.LWR.requiredModules.push('lwr/loader/v/
|
|
221
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_5_0') < 0) {
|
|
222
|
+
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_5_0');
|
|
222
223
|
}
|
|
223
224
|
new LoaderShim(GLOBAL);
|
|
224
225
|
|
|
225
226
|
}());
|
|
226
227
|
|
|
227
|
-
LWR.define('lwr/loader/v/
|
|
228
|
+
LWR.define('lwr/loader/v/0_5_0', ['exports'], function (exports) { 'use strict';
|
|
228
229
|
|
|
229
230
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
230
231
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -527,7 +528,6 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
527
528
|
// Default to empty mappings
|
|
528
529
|
this.importURICache = new Map();
|
|
529
530
|
this.pendingURICache = new Map();
|
|
530
|
-
this.importMetadata = { imports: {} };
|
|
531
531
|
this.loadMappingHooks = [];
|
|
532
532
|
this.config = config;
|
|
533
533
|
this.invalidationCallback = invalidationCallback;
|
|
@@ -565,36 +565,44 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
565
565
|
registerImportMappings(newImportMetadata, rootSpecifiers) {
|
|
566
566
|
if (!rootSpecifiers || rootSpecifiers.length === 0) {
|
|
567
567
|
const imports = newImportMetadata ? JSON.stringify(newImportMetadata) : 'undefined';
|
|
568
|
-
throw new LoaderError(BAD_IMPORT_METADATA, [imports, 'undefined']);
|
|
568
|
+
throw new LoaderError(BAD_IMPORT_METADATA, [imports, rootSpecifiers ? '[]' : 'undefined']);
|
|
569
569
|
}
|
|
570
|
-
if (!newImportMetadata
|
|
570
|
+
if (!newImportMetadata) {
|
|
571
571
|
throw new LoaderError(BAD_IMPORT_METADATA, ['undefined', JSON.stringify(rootSpecifiers)]);
|
|
572
572
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
573
|
+
if (!newImportMetadata.imports || Object.keys(newImportMetadata.imports).length === 0) {
|
|
574
|
+
throw new LoaderError(BAD_IMPORT_METADATA, [
|
|
575
|
+
JSON.stringify(newImportMetadata),
|
|
576
|
+
JSON.stringify(rootSpecifiers),
|
|
577
|
+
]);
|
|
578
|
+
}
|
|
579
|
+
const index = newImportMetadata.index || {};
|
|
580
|
+
for (const [uri, specifiers] of Object.entries(newImportMetadata.imports)) {
|
|
577
581
|
specifiers.forEach((specifier) => {
|
|
582
|
+
const indexValue = index[specifier];
|
|
578
583
|
const existing = this.importURICache.get(specifier);
|
|
579
584
|
if (!existing) {
|
|
580
|
-
this.
|
|
581
|
-
uri: resolvedUri,
|
|
582
|
-
isRoot: rootSpecifiers.includes(specifier),
|
|
583
|
-
});
|
|
585
|
+
this.saveImportURIRecord(specifier, uri, indexValue, rootSpecifiers.includes(specifier));
|
|
584
586
|
}
|
|
585
|
-
else
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
587
|
+
else {
|
|
588
|
+
const identity = indexValue || uri;
|
|
589
|
+
const existingIdentity = existing.identity || existing.uri;
|
|
590
|
+
if (existingIdentity !== identity) {
|
|
591
|
+
this.invalidationCallback({
|
|
592
|
+
name: specifier,
|
|
593
|
+
oldUrl: existingIdentity,
|
|
594
|
+
newUrl: identity,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
591
597
|
}
|
|
592
598
|
});
|
|
593
599
|
}
|
|
594
600
|
}
|
|
595
601
|
// Get URL from the local cache or return undefiend
|
|
596
602
|
getURI(specifier) {
|
|
597
|
-
return this.importURICache.has(specifier)
|
|
603
|
+
return this.importURICache.has(specifier)
|
|
604
|
+
? resolveUrl(this.importURICache.get(specifier).uri, this.getBaseUrl())
|
|
605
|
+
: undefined;
|
|
598
606
|
}
|
|
599
607
|
resolveLocal(specifier) {
|
|
600
608
|
const uri = this.getURI(specifier);
|
|
@@ -638,7 +646,7 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
638
646
|
if (!importMetadata || !importMetadata.imports) {
|
|
639
647
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
640
648
|
}
|
|
641
|
-
this.registerImportMappings(importMetadata
|
|
649
|
+
this.registerImportMappings(importMetadata, [specifier]);
|
|
642
650
|
uri = this.getURI(specifier);
|
|
643
651
|
if (!uri) {
|
|
644
652
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
@@ -667,6 +675,7 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
667
675
|
const knownModules = Array.from(this.importURICache.keys());
|
|
668
676
|
for (let i = 0; i < loadMappingHooks.length; i++) {
|
|
669
677
|
const loadMappingHook = loadMappingHooks[i];
|
|
678
|
+
// eslint-disable-next-line no-await-in-loop
|
|
670
679
|
const response = await loadMappingHook(specifier, { knownModules });
|
|
671
680
|
// undefined (but not null) is considered an un expected response so we will stop processing hooks here and throw an error
|
|
672
681
|
if (response || response === undefined) {
|
|
@@ -698,6 +707,21 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
698
707
|
});
|
|
699
708
|
});
|
|
700
709
|
}
|
|
710
|
+
saveImportURIRecord(specifier, uri, identity, isRoot) {
|
|
711
|
+
if (!identity || uri === identity) {
|
|
712
|
+
this.importURICache.set(specifier, {
|
|
713
|
+
uri,
|
|
714
|
+
isRoot: isRoot,
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
this.importURICache.set(specifier, {
|
|
719
|
+
uri,
|
|
720
|
+
identity,
|
|
721
|
+
isRoot: isRoot,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
701
725
|
}
|
|
702
726
|
|
|
703
727
|
function reportError(error) {
|
|
@@ -844,6 +868,7 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
844
868
|
const response = resolveHook(aliasedId, { parentUrl });
|
|
845
869
|
let result;
|
|
846
870
|
if (response || response === null) {
|
|
871
|
+
// eslint-disable-next-line no-await-in-loop
|
|
847
872
|
result = isResponseAPromise(response) ? await response : response;
|
|
848
873
|
}
|
|
849
874
|
// if result is not null, attempt resolution
|
|
@@ -1033,6 +1058,7 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
1033
1058
|
if (dependencyModuleRecords) {
|
|
1034
1059
|
for (let i = 0; i < dependencyModuleRecords.length; i++) {
|
|
1035
1060
|
const depRecord = dependencyModuleRecords[i];
|
|
1061
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1036
1062
|
await this.instantiateAll(depRecord, instantiatedMap);
|
|
1037
1063
|
}
|
|
1038
1064
|
}
|
|
@@ -1135,6 +1161,7 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
1135
1161
|
const depRecord = dependencyModuleRecords[i];
|
|
1136
1162
|
if (!depRecord.evaluated && !evaluationMap[depRecord.id]) {
|
|
1137
1163
|
evaluationMap[depRecord.id] = true;
|
|
1164
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1138
1165
|
await this.evaluateModule(depRecord, evaluationMap);
|
|
1139
1166
|
}
|
|
1140
1167
|
}
|
|
@@ -1164,7 +1191,8 @@ LWR.define('lwr/loader/v/0_4_7', ['exports'], function (exports) { 'use strict';
|
|
|
1164
1191
|
const loadHook = loadHooks[i];
|
|
1165
1192
|
const response = loadHook(resolvedId, parentUrl);
|
|
1166
1193
|
const result = (isResponseAPromise(response)
|
|
1167
|
-
?
|
|
1194
|
+
? // eslint-disable-next-line no-await-in-loop
|
|
1195
|
+
await evaluateLoadHook(resolvedId, response)
|
|
1168
1196
|
: response);
|
|
1169
1197
|
if (result === undefined) {
|
|
1170
1198
|
throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
|
|
@@ -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 Module Loader Shim v0.
|
|
8
|
-
!function(){"use strict";function e(e,t,r,o){const{autoBoot:n,customInit:
|
|
7
|
+
/* LWR Module Loader Shim v0.5.0 */
|
|
8
|
+
!function(){"use strict";function e(e,t,r,o){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:t,define:r,onBootstrapError:o},e)}}const t="function"==typeof setTimeout,r="undefined"!=typeof console;const o=globalThis;o.LWR.requiredModules=o.LWR.requiredModules||[],o.LWR.requiredModules.indexOf("lwr/loader/v/0_5_0")<0&&o.LWR.requiredModules.push("lwr/loader/v/0_5_0"),new class{constructor(r){this.defineCache={},this.orderedDefs=[],this.global=r,this.config=r.LWR,this.loaderModule="lwr/loader/v/0_5_0";const o=this.tempDefine.bind(this);r.LWR.define=o,this.bootReady=this.config.autoBoot,t&&(this.watchdogTimerId=this.startWatchdogTimer());try{e(Object.freeze(this.config),this.postCustomInit.bind(this),o,e=>{this.errorHandler=e})}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every(e=>this.orderedDefs.includes(e));return this.bootReady&&e}tempDefine(...e){const r=e[0];this.defineCache[r]=e,this.orderedDefs.push(r),this.canInit()&&(t&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e={endpoints:this.config.endpoints,baseUrl:this.config.baseUrl},t=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const n={};t[2].call(null,n);const{Loader:i}=n,s=new i(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:n,imports:i,index:s}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:o,endpoints:n,imports:i||{},index:s||{}}),this.orderedDefs.forEach(t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])});const{disableInitDefer:a}=this.config;e.registerImportMappings({imports:i,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){this.errorHandler?this.errorHandler(e):r&&console.error("An error occurred during LWR bootstrap. "+e.message,e.stack)}startWatchdogTimer(){return setTimeout(()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))},3e5)}}(o)}(),LWR.define("lwr/loader/v/0_5_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}"}),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=void 0;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}
|
|
9
9
|
/**
|
|
10
10
|
* Check if a string is a URL based on Common Internet Scheme Syntax
|
|
11
11
|
* https://www.ietf.org/rfc/rfc1738.txt
|
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
* 'salesforce.com'
|
|
29
29
|
* 'localhost:3000'
|
|
30
30
|
* '@salesforce/label/type:namespace:name'
|
|
31
|
-
*/function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const n=o.slice(0,o.lastIndexOf("/")+1)+e,s=[];let i=-1;for(let e=0;e<n.length;e++)-1!==i?"/"===n[e]&&(s.push(n.slice(i,e+1)),i=-1):"."===n[e]?"."!==n[e+1]||"/"!==n[e+2]&&e+2!==n.length?"/"===n[e+1]||e+1===n.length?e+=1:i=e:(s.pop(),e+=2):i=e;return-1!==i&&s.push(n.slice(i)),t.slice(0,t.length-o.length)+s.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",()=>{r(new LoaderError(FAIL_LOAD,[e]))}),o.addEventListener("load",()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()}),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error});class ImportMetadataResolver{constructor(e,t){this.importURICache=new Map,this.pendingURICache=new Map,this.importMetadata={imports:{}},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 t=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[t,"undefined"])}if(!e||0===Object.keys(e).length)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);for(const[r,o]of Object.entries(e)){this.importMetadata[r]=o;const e=resolveUrl(r,this.getBaseUrl());o.forEach(r=>{const o=this.importURICache.get(r);o?o&&o.uri!==e&&this.invalidationCallback({name:r,oldUrl:o.uri,newUrl:e}):this.importURICache.set(r,{uri:e,isRoot:t.includes(r)})})}}getURI(e){return this.importURICache.has(e)?this.importURICache.get(e).uri:void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then(r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r.imports,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return t}).finally(()=>{this.pendingURICache.delete(e)});return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const n=t[o],s=await n(e,{knownModules:r});if(s||void 0===s)return s}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then(t=>{if(!t.ok)throw new LoaderError(UNRESOLVED,[e]);return t.json().then(e=>e).catch(t=>{throw new LoaderError(UNRESOLVED,[e])})})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:n}=t;for(let t=0;t<e.length;t++){const s=e[t];try{if(null!==s({name:r,oldUrl:o,newUrl:n}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then(async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,""+response.status]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0}).finally(()=>{})}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise((r,o)=>{const n=setTimeout(()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))},MODULE_LOAD_TIMEOUT_TIMER);t.then(e=>{r(e)}).catch(()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))}).finally(()=>{clearTimeout(n)})}):t}hasDocument&&globalThis.addEventListener("error",e=>{lastWindowError=e.error}),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,n=e;const s=this.resolveHook;if(s){for(let e=0;e<s.length;e++){const t=(0,s[e])(n,{parentUrl:r});let i;if((t||null===t)&&(i=isResponseAPromise(t)?await t:t),null!==i){if("string"==typeof i){if(resolveIfNotPlainOrUrl(i,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);n=i;continue}if(o=i&&i.url&&(resolveIfNotPlainOrUrl(i.url,r)||i.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(n!==e){if(!o&&this.namedDefineRegistry.has(n))return n;e=n}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const n=this.resolver.resolveLocal(t);if(n){if(this.namedDefineRegistry.has(t)){const e=this.moduleRegistry.get(n);if(!e||e.originalId!==t)return t}return n}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+="?importer="+encodeURIComponent(t)),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return void(this.lastDefine=o);const n={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n}registerExternalModules(e){const t=[];if(e.map(e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise((o,n)=>{t=o,r=setTimeout(()=>{n(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))},MODULE_LOAD_TIMEOUT_TIMER)}).finally(()=>{clearTimeout(r)}),n={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,n)}}),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}getImportMetadataResolver(){return this.resolver}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r;const o=this.getModuleDef(e,t),n=o.then(e=>{const t=e.dependencies.map(e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)}).filter(e=>void 0!==e);return Promise.all(t)});return r={id:e,originalId:t,module:Object.create(null),dependencyRecords:n,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:n}=await e.instantiation,s={};let i=o(...await Promise.all(n.map(async e=>{if("exports"===e)return s;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));void 0!==i?(i={default:i},Object.defineProperty(i,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(s)&&Object.defineProperty(s,"__useDefault",{value:!0});const a=i||s;for(const t in a)Object.defineProperty(e.module,t,{enumerable:!0,set(e){a[t]=e},get:()=>a[t]});return a.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),a.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const n=this.resolver.getBaseUrl();return Promise.resolve().then(async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,n),s=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===s)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(s&&null!==s)return evaluateLoadHookResponse(s,e)}return!1}).then(t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)}).then(()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o}).catch(e=>{throw e})}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o?evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r}):hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${r}`)}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t})),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,n=t;"function"==typeof n&&(o=t,n=[]),invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
31
|
+
*/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.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",()=>{r(new LoaderError(FAIL_LOAD,[e]))}),o.addEventListener("load",()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()}),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error});class ImportMetadataResolver{constructor(e,t){this.importURICache=new Map,this.pendingURICache=new Map,this.loadMappingHooks=[],this.config=e,this.invalidationCallback=t}addLoadMappingHook(e){this.loadMappingHooks.push(e)}getMappingEndpoint(){return this.config.endpoints&&this.config.endpoints.uris?this.config.endpoints.uris.mapping:void 0}getModifiersAsUrlParams(){const e=this.config.endpoints?this.config.endpoints.modifiers:void 0;if(e){return"?"+Object.keys(e).map(t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`).join("&")}return""}buildMappingUrl(e){return`${this.getMappingEndpoint()}${encodeURIComponent(e)}${this.getModifiersAsUrlParams()}`}getBaseUrl(){return this.config.baseUrl}registerImportMappings(e,t){if(!t||0===t.length){const r=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[r,t?"[]":"undefined"])}if(!e)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);if(!e.imports||0===Object.keys(e.imports).length)throw new LoaderError(BAD_IMPORT_METADATA,[JSON.stringify(e),JSON.stringify(t)]);const r=e.index||{};for(const[o,n]of Object.entries(e.imports))n.forEach(e=>{const n=r[e],i=this.importURICache.get(e);if(i){const t=n||o,r=i.identity||i.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,n,t.includes(e))})}getURI(e){return this.importURICache.has(e)?resolveUrl(this.importURICache.get(e).uri,this.getBaseUrl()):void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then(r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return t}).finally(()=>{this.pendingURICache.delete(e)});return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const n=t[o],i=await n(e,{knownModules:r});if(i||void 0===i)return i}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then(t=>{if(!t.ok)throw new LoaderError(UNRESOLVED,[e]);return t.json().then(e=>e).catch(t=>{throw new LoaderError(UNRESOLVED,[e])})})}saveImportURIRecord(e,t,r,o){r&&t!==r?this.importURICache.set(e,{uri:t,identity:r,isRoot:o}):this.importURICache.set(e,{uri:t,isRoot:o})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:n}=t;for(let t=0;t<e.length;t++){const i=e[t];try{if(null!==i({name:r,oldUrl:o,newUrl:n}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then(async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,""+response.status]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0}).finally(()=>{})}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise((r,o)=>{const n=setTimeout(()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))},MODULE_LOAD_TIMEOUT_TIMER);t.then(e=>{r(e)}).catch(()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))}).finally(()=>{clearTimeout(n)})}):t}hasDocument&&globalThis.addEventListener("error",e=>{lastWindowError=e.error}),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,n=e;const i=this.resolveHook;if(i){for(let e=0;e<i.length;e++){const t=(0,i[e])(n,{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);n=s;continue}if(o=s&&s.url&&(resolveIfNotPlainOrUrl(s.url,r)||s.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(n!==e){if(!o&&this.namedDefineRegistry.has(n))return n;e=n}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const n=this.resolver.resolveLocal(t);if(n){if(this.namedDefineRegistry.has(t)){const e=this.moduleRegistry.get(n);if(!e||e.originalId!==t)return t}return n}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+="?importer="+encodeURIComponent(t)),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return void(this.lastDefine=o);const n={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n}registerExternalModules(e){const t=[];if(e.map(e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise((o,n)=>{t=o,r=setTimeout(()=>{n(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))},MODULE_LOAD_TIMEOUT_TIMER)}).finally(()=>{clearTimeout(r)}),n={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,n)}}),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}getImportMetadataResolver(){return this.resolver}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r;const o=this.getModuleDef(e,t),n=o.then(e=>{const t=e.dependencies.map(e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)}).filter(e=>void 0!==e);return Promise.all(t)});return r={id:e,originalId:t,module:Object.create(null),dependencyRecords:n,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:n}=await e.instantiation,i={};let s=o(...await Promise.all(n.map(async e=>{if("exports"===e)return i;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])})));void 0!==s?(s={default:s},Object.defineProperty(s,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(i)&&Object.defineProperty(i,"__useDefault",{value:!0});const a=s||i;for(const t in a)Object.defineProperty(e.module,t,{enumerable:!0,set(e){a[t]=e},get:()=>a[t]});return a.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),a.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const n=this.resolver.getBaseUrl();return Promise.resolve().then(async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,n),i=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===i)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(i&&null!==i)return evaluateLoadHookResponse(i,e)}return!1}).then(t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)}).then(()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o}).catch(e=>{throw e})}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o?evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r}):hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${r}`)}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t})),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,n=t;"function"==typeof n&&(o=t,n=[]),invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
@@ -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.5.0 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
// Parse configuration
|
|
75
75
|
this.global = global;
|
|
76
76
|
this.config = global.LWR;
|
|
77
|
-
this.loaderModule = 'lwr/loader/v/
|
|
77
|
+
this.loaderModule = 'lwr/loader/v/0_5_0';
|
|
78
78
|
// Set up the temporary LWR.define function and customInit hook
|
|
79
79
|
const tempDefine = this.tempDefine.bind(this);
|
|
80
80
|
global.LWR.define = tempDefine;
|
|
@@ -163,14 +163,15 @@
|
|
|
163
163
|
}
|
|
164
164
|
// Set up the application globals, import map, root custom element...
|
|
165
165
|
mountApp(loader) {
|
|
166
|
-
const { bootstrapModule, rootComponent, rootComponents, endpoints, imports } = this.config;
|
|
166
|
+
const { bootstrapModule, rootComponent, rootComponents, endpoints, imports, index } = this.config;
|
|
167
167
|
// Set global LWR.define to loader.define
|
|
168
168
|
this.global.LWR = Object.freeze({
|
|
169
169
|
define: loader.define.bind(loader),
|
|
170
170
|
rootComponent,
|
|
171
171
|
rootComponents,
|
|
172
|
-
imports,
|
|
173
172
|
endpoints,
|
|
173
|
+
imports: imports || {},
|
|
174
|
+
index: index || {},
|
|
174
175
|
});
|
|
175
176
|
// Redefine all modules in the temporary cache
|
|
176
177
|
this.orderedDefs.forEach((specifier) => {
|
|
@@ -182,7 +183,7 @@
|
|
|
182
183
|
const { disableInitDefer } = this.config;
|
|
183
184
|
// Load the import mappings and application bootstrap module
|
|
184
185
|
loader
|
|
185
|
-
.registerImportMappings(imports, [bootstrapModule, rootComponent])
|
|
186
|
+
.registerImportMappings({ imports, index }, [bootstrapModule, rootComponent])
|
|
186
187
|
.then(() => {
|
|
187
188
|
if (!disableInitDefer) {
|
|
188
189
|
return this.waitForDOMContentLoaded();
|
|
@@ -217,8 +218,8 @@
|
|
|
217
218
|
// The loader module is ALWAYS required
|
|
218
219
|
const GLOBAL = globalThis;
|
|
219
220
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
220
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/
|
|
221
|
-
GLOBAL.LWR.requiredModules.push('lwr/loader/v/
|
|
221
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_5_0') < 0) {
|
|
222
|
+
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_5_0');
|
|
222
223
|
}
|
|
223
224
|
new LoaderShim(GLOBAL);
|
|
224
225
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const o=globalThis.LWR&&globalThis.LWR.endpoints,t=new class{constructor(o){if(this.importURICache=new Map,o)for(const[t,r]of Object.entries(o))if(t&&r){(Array.isArray(r)?r:[]).forEach(o=>{this.importURICache.set(o,t)})}}resolve(o){return this.importURICache.get(o)}}(
|
|
1
|
+
const o=globalThis.LWR&&globalThis.LWR.endpoints,t=globalThis.LWR&&globalThis.LWR.imports||{},r=globalThis.LWR&&globalThis.LWR.index||{},i=new class{constructor(o){if(this.importURICache=new Map,o&&o.imports)for(const[t,r]of Object.entries(o.imports))if(t&&r){(Array.isArray(r)?r:[]).forEach(o=>{this.importURICache.set(o,t)})}}resolve(o){return this.importURICache.get(o)}}({imports:t,index:r}),e=new class{constructor(o){this.importURICache=o&&o.imports?o:{imports:{}}}legacyResolve(o){return this.importURICache.imports[o]}}(globalThis.LWR&&globalThis.LWR.importMappings);function s(t,r){const s=function(t,r){let s;if(s=i.resolve(t),s)return s;if(s=e.legacyResolve(t),s)return s;s=t,s.indexOf("://")<0&&!s.startsWith("/")&&o&&o.uris&&o.uris.module&&(s=o.uris.module+encodeURIComponent(t),r&&(s+="?importer="+encodeURIComponent(r)));return s}(t,r);return import(s)}export{s as load};
|
|
@@ -29,7 +29,9 @@ __export(exports, {
|
|
|
29
29
|
var import_importResolver = __toModule(require("./importResolver"));
|
|
30
30
|
var import_importResolverLegacy = __toModule(require("./importResolverLegacy"));
|
|
31
31
|
var endpoints = globalThis.LWR && globalThis.LWR.endpoints;
|
|
32
|
-
var
|
|
32
|
+
var imports = globalThis.LWR && globalThis.LWR.imports || {};
|
|
33
|
+
var index = globalThis.LWR && globalThis.LWR.index || {};
|
|
34
|
+
var resolver = new import_importResolver.default({imports, index});
|
|
33
35
|
var resolverLegacy = new import_importResolverLegacy.default(globalThis.LWR && globalThis.LWR.importMappings);
|
|
34
36
|
function load(specifier, importer) {
|
|
35
37
|
const uri = resolveUrl(specifier, importer);
|
|
@@ -11,10 +11,10 @@ __export(exports, {
|
|
|
11
11
|
default: () => importResolver_default
|
|
12
12
|
});
|
|
13
13
|
var ImportResolver = class {
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(importMetada) {
|
|
15
15
|
this.importURICache = new Map();
|
|
16
|
-
if (imports) {
|
|
17
|
-
for (const [uri, value] of Object.entries(imports)) {
|
|
16
|
+
if (importMetada && importMetada.imports) {
|
|
17
|
+
for (const [uri, value] of Object.entries(importMetada.imports)) {
|
|
18
18
|
if (uri && value) {
|
|
19
19
|
const specifiers = Array.isArray(value) ? value : [];
|
|
20
20
|
specifiers.forEach((specifier) => {
|
|
@@ -32,7 +32,6 @@ var ImportMetadataResolver = class {
|
|
|
32
32
|
constructor(config, invalidationCallback) {
|
|
33
33
|
this.importURICache = new Map();
|
|
34
34
|
this.pendingURICache = new Map();
|
|
35
|
-
this.importMetadata = {imports: {}};
|
|
36
35
|
this.loadMappingHooks = [];
|
|
37
36
|
this.config = config;
|
|
38
37
|
this.invalidationCallback = invalidationCallback;
|
|
@@ -64,33 +63,40 @@ var ImportMetadataResolver = class {
|
|
|
64
63
|
registerImportMappings(newImportMetadata, rootSpecifiers) {
|
|
65
64
|
if (!rootSpecifiers || rootSpecifiers.length === 0) {
|
|
66
65
|
const imports = newImportMetadata ? JSON.stringify(newImportMetadata) : "undefined";
|
|
67
|
-
throw new import_messages.LoaderError(import_messages.BAD_IMPORT_METADATA, [imports, "undefined"]);
|
|
66
|
+
throw new import_messages.LoaderError(import_messages.BAD_IMPORT_METADATA, [imports, rootSpecifiers ? "[]" : "undefined"]);
|
|
68
67
|
}
|
|
69
|
-
if (!newImportMetadata
|
|
68
|
+
if (!newImportMetadata) {
|
|
70
69
|
throw new import_messages.LoaderError(import_messages.BAD_IMPORT_METADATA, ["undefined", JSON.stringify(rootSpecifiers)]);
|
|
71
70
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
if (!newImportMetadata.imports || Object.keys(newImportMetadata.imports).length === 0) {
|
|
72
|
+
throw new import_messages.LoaderError(import_messages.BAD_IMPORT_METADATA, [
|
|
73
|
+
JSON.stringify(newImportMetadata),
|
|
74
|
+
JSON.stringify(rootSpecifiers)
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
const index = newImportMetadata.index || {};
|
|
78
|
+
for (const [uri, specifiers] of Object.entries(newImportMetadata.imports)) {
|
|
75
79
|
specifiers.forEach((specifier) => {
|
|
80
|
+
const indexValue = index[specifier];
|
|
76
81
|
const existing = this.importURICache.get(specifier);
|
|
77
82
|
if (!existing) {
|
|
78
|
-
this.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
this.saveImportURIRecord(specifier, uri, indexValue, rootSpecifiers.includes(specifier));
|
|
84
|
+
} else {
|
|
85
|
+
const identity = indexValue || uri;
|
|
86
|
+
const existingIdentity = existing.identity || existing.uri;
|
|
87
|
+
if (existingIdentity !== identity) {
|
|
88
|
+
this.invalidationCallback({
|
|
89
|
+
name: specifier,
|
|
90
|
+
oldUrl: existingIdentity,
|
|
91
|
+
newUrl: identity
|
|
92
|
+
});
|
|
93
|
+
}
|
|
88
94
|
}
|
|
89
95
|
});
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
getURI(specifier) {
|
|
93
|
-
return this.importURICache.has(specifier) ? this.importURICache.get(specifier).uri : void 0;
|
|
99
|
+
return this.importURICache.has(specifier) ? (0, import_url.resolveUrl)(this.importURICache.get(specifier).uri, this.getBaseUrl()) : void 0;
|
|
94
100
|
}
|
|
95
101
|
resolveLocal(specifier) {
|
|
96
102
|
const uri = this.getURI(specifier);
|
|
@@ -117,7 +123,7 @@ var ImportMetadataResolver = class {
|
|
|
117
123
|
if (!importMetadata || !importMetadata.imports) {
|
|
118
124
|
throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
|
|
119
125
|
}
|
|
120
|
-
this.registerImportMappings(importMetadata
|
|
126
|
+
this.registerImportMappings(importMetadata, [specifier]);
|
|
121
127
|
uri = this.getURI(specifier);
|
|
122
128
|
if (!uri) {
|
|
123
129
|
throw new import_messages.LoaderError(import_messages.UNRESOLVED, [specifier]);
|
|
@@ -163,4 +169,18 @@ var ImportMetadataResolver = class {
|
|
|
163
169
|
});
|
|
164
170
|
});
|
|
165
171
|
}
|
|
172
|
+
saveImportURIRecord(specifier, uri, identity, isRoot) {
|
|
173
|
+
if (!identity || uri === identity) {
|
|
174
|
+
this.importURICache.set(specifier, {
|
|
175
|
+
uri,
|
|
176
|
+
isRoot
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
this.importURICache.set(specifier, {
|
|
180
|
+
uri,
|
|
181
|
+
identity,
|
|
182
|
+
isRoot
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
166
186
|
};
|
|
@@ -4,17 +4,17 @@
|
|
|
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.
|
|
7
|
+
/* LWR ESM Module Loader v0.5.0 */
|
|
8
8
|
/**
|
|
9
9
|
* Simplified version of the AMD Import Metadata Resolver.
|
|
10
|
-
* Just reads the
|
|
10
|
+
* Just reads the ImportMetadata at construction time.
|
|
11
11
|
*/
|
|
12
12
|
class ImportResolver {
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(importMetada) {
|
|
14
14
|
this.importURICache = new Map();
|
|
15
15
|
// Normalize the URI cache to optimize retrieval
|
|
16
|
-
if (imports) {
|
|
17
|
-
for (const [uri, value] of Object.entries(imports)) {
|
|
16
|
+
if (importMetada && importMetada.imports) {
|
|
17
|
+
for (const [uri, value] of Object.entries(importMetada.imports)) {
|
|
18
18
|
if (uri && value) {
|
|
19
19
|
const specifiers = Array.isArray(value) ? value : [];
|
|
20
20
|
specifiers.forEach((specifier) => {
|
|
@@ -48,7 +48,9 @@ class ImportResolverLegacy {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const endpoints = globalThis.LWR && globalThis.LWR.endpoints;
|
|
51
|
-
const
|
|
51
|
+
const imports = (globalThis.LWR && globalThis.LWR.imports) || {};
|
|
52
|
+
const index = (globalThis.LWR && globalThis.LWR.index) || {};
|
|
53
|
+
const resolver = new ImportResolver({ imports, index });
|
|
52
54
|
const resolverLegacy = new ImportResolverLegacy(globalThis.LWR && globalThis.LWR.importMappings);
|
|
53
55
|
function load(specifier, importer) {
|
|
54
56
|
const uri = resolveUrl(specifier, importer);
|
|
@@ -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.
|
|
7
|
+
/* LWR Module Loader v0.5.0 */
|
|
8
8
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
function templateString(template, args) {
|
|
@@ -306,7 +306,6 @@ class ImportMetadataResolver {
|
|
|
306
306
|
// Default to empty mappings
|
|
307
307
|
this.importURICache = new Map();
|
|
308
308
|
this.pendingURICache = new Map();
|
|
309
|
-
this.importMetadata = { imports: {} };
|
|
310
309
|
this.loadMappingHooks = [];
|
|
311
310
|
this.config = config;
|
|
312
311
|
this.invalidationCallback = invalidationCallback;
|
|
@@ -344,36 +343,44 @@ class ImportMetadataResolver {
|
|
|
344
343
|
registerImportMappings(newImportMetadata, rootSpecifiers) {
|
|
345
344
|
if (!rootSpecifiers || rootSpecifiers.length === 0) {
|
|
346
345
|
const imports = newImportMetadata ? JSON.stringify(newImportMetadata) : 'undefined';
|
|
347
|
-
throw new LoaderError(BAD_IMPORT_METADATA, [imports, 'undefined']);
|
|
346
|
+
throw new LoaderError(BAD_IMPORT_METADATA, [imports, rootSpecifiers ? '[]' : 'undefined']);
|
|
348
347
|
}
|
|
349
|
-
if (!newImportMetadata
|
|
348
|
+
if (!newImportMetadata) {
|
|
350
349
|
throw new LoaderError(BAD_IMPORT_METADATA, ['undefined', JSON.stringify(rootSpecifiers)]);
|
|
351
350
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
351
|
+
if (!newImportMetadata.imports || Object.keys(newImportMetadata.imports).length === 0) {
|
|
352
|
+
throw new LoaderError(BAD_IMPORT_METADATA, [
|
|
353
|
+
JSON.stringify(newImportMetadata),
|
|
354
|
+
JSON.stringify(rootSpecifiers),
|
|
355
|
+
]);
|
|
356
|
+
}
|
|
357
|
+
const index = newImportMetadata.index || {};
|
|
358
|
+
for (const [uri, specifiers] of Object.entries(newImportMetadata.imports)) {
|
|
356
359
|
specifiers.forEach((specifier) => {
|
|
360
|
+
const indexValue = index[specifier];
|
|
357
361
|
const existing = this.importURICache.get(specifier);
|
|
358
362
|
if (!existing) {
|
|
359
|
-
this.
|
|
360
|
-
uri: resolvedUri,
|
|
361
|
-
isRoot: rootSpecifiers.includes(specifier),
|
|
362
|
-
});
|
|
363
|
+
this.saveImportURIRecord(specifier, uri, indexValue, rootSpecifiers.includes(specifier));
|
|
363
364
|
}
|
|
364
|
-
else
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
365
|
+
else {
|
|
366
|
+
const identity = indexValue || uri;
|
|
367
|
+
const existingIdentity = existing.identity || existing.uri;
|
|
368
|
+
if (existingIdentity !== identity) {
|
|
369
|
+
this.invalidationCallback({
|
|
370
|
+
name: specifier,
|
|
371
|
+
oldUrl: existingIdentity,
|
|
372
|
+
newUrl: identity,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
370
375
|
}
|
|
371
376
|
});
|
|
372
377
|
}
|
|
373
378
|
}
|
|
374
379
|
// Get URL from the local cache or return undefiend
|
|
375
380
|
getURI(specifier) {
|
|
376
|
-
return this.importURICache.has(specifier)
|
|
381
|
+
return this.importURICache.has(specifier)
|
|
382
|
+
? resolveUrl(this.importURICache.get(specifier).uri, this.getBaseUrl())
|
|
383
|
+
: undefined;
|
|
377
384
|
}
|
|
378
385
|
resolveLocal(specifier) {
|
|
379
386
|
const uri = this.getURI(specifier);
|
|
@@ -417,7 +424,7 @@ class ImportMetadataResolver {
|
|
|
417
424
|
if (!importMetadata || !importMetadata.imports) {
|
|
418
425
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
419
426
|
}
|
|
420
|
-
this.registerImportMappings(importMetadata
|
|
427
|
+
this.registerImportMappings(importMetadata, [specifier]);
|
|
421
428
|
uri = this.getURI(specifier);
|
|
422
429
|
if (!uri) {
|
|
423
430
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
@@ -446,6 +453,7 @@ class ImportMetadataResolver {
|
|
|
446
453
|
const knownModules = Array.from(this.importURICache.keys());
|
|
447
454
|
for (let i = 0; i < loadMappingHooks.length; i++) {
|
|
448
455
|
const loadMappingHook = loadMappingHooks[i];
|
|
456
|
+
// eslint-disable-next-line no-await-in-loop
|
|
449
457
|
const response = await loadMappingHook(specifier, { knownModules });
|
|
450
458
|
// undefined (but not null) is considered an un expected response so we will stop processing hooks here and throw an error
|
|
451
459
|
if (response || response === undefined) {
|
|
@@ -477,6 +485,21 @@ class ImportMetadataResolver {
|
|
|
477
485
|
});
|
|
478
486
|
});
|
|
479
487
|
}
|
|
488
|
+
saveImportURIRecord(specifier, uri, identity, isRoot) {
|
|
489
|
+
if (!identity || uri === identity) {
|
|
490
|
+
this.importURICache.set(specifier, {
|
|
491
|
+
uri,
|
|
492
|
+
isRoot: isRoot,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
this.importURICache.set(specifier, {
|
|
497
|
+
uri,
|
|
498
|
+
identity,
|
|
499
|
+
isRoot: isRoot,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
480
503
|
}
|
|
481
504
|
|
|
482
505
|
function reportError(error) {
|
|
@@ -623,6 +646,7 @@ class ModuleRegistry {
|
|
|
623
646
|
const response = resolveHook(aliasedId, { parentUrl });
|
|
624
647
|
let result;
|
|
625
648
|
if (response || response === null) {
|
|
649
|
+
// eslint-disable-next-line no-await-in-loop
|
|
626
650
|
result = isResponseAPromise(response) ? await response : response;
|
|
627
651
|
}
|
|
628
652
|
// if result is not null, attempt resolution
|
|
@@ -812,6 +836,7 @@ class ModuleRegistry {
|
|
|
812
836
|
if (dependencyModuleRecords) {
|
|
813
837
|
for (let i = 0; i < dependencyModuleRecords.length; i++) {
|
|
814
838
|
const depRecord = dependencyModuleRecords[i];
|
|
839
|
+
// eslint-disable-next-line no-await-in-loop
|
|
815
840
|
await this.instantiateAll(depRecord, instantiatedMap);
|
|
816
841
|
}
|
|
817
842
|
}
|
|
@@ -914,6 +939,7 @@ class ModuleRegistry {
|
|
|
914
939
|
const depRecord = dependencyModuleRecords[i];
|
|
915
940
|
if (!depRecord.evaluated && !evaluationMap[depRecord.id]) {
|
|
916
941
|
evaluationMap[depRecord.id] = true;
|
|
942
|
+
// eslint-disable-next-line no-await-in-loop
|
|
917
943
|
await this.evaluateModule(depRecord, evaluationMap);
|
|
918
944
|
}
|
|
919
945
|
}
|
|
@@ -943,7 +969,8 @@ class ModuleRegistry {
|
|
|
943
969
|
const loadHook = loadHooks[i];
|
|
944
970
|
const response = loadHook(resolvedId, parentUrl);
|
|
945
971
|
const result = (isResponseAPromise(response)
|
|
946
|
-
?
|
|
972
|
+
? // eslint-disable-next-line no-await-in-loop
|
|
973
|
+
await evaluateLoadHook(resolvedId, response)
|
|
947
974
|
: response);
|
|
948
975
|
if (result === undefined) {
|
|
949
976
|
throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
|
|
@@ -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.
|
|
7
|
+
/* LWR Legacy Module Loader v0.5.0 */
|
|
8
8
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
function templateString(template, args) {
|
|
@@ -434,6 +434,7 @@ class ModuleRegistry {
|
|
|
434
434
|
const response = resolveHook(aliasedId, { parentUrl });
|
|
435
435
|
let result;
|
|
436
436
|
if (response || response === null) {
|
|
437
|
+
// eslint-disable-next-line no-await-in-loop
|
|
437
438
|
result = isResponseAPromise(response) ? await response : response;
|
|
438
439
|
}
|
|
439
440
|
// if result is not null, attempt resolution
|
|
@@ -657,6 +658,7 @@ class ModuleRegistry {
|
|
|
657
658
|
if (dependencyModuleRecords) {
|
|
658
659
|
for (let i = 0; i < dependencyModuleRecords.length; i++) {
|
|
659
660
|
const depRecord = dependencyModuleRecords[i];
|
|
661
|
+
// eslint-disable-next-line no-await-in-loop
|
|
660
662
|
await this.instantiateAll(depRecord, instantiatedMap);
|
|
661
663
|
}
|
|
662
664
|
}
|
|
@@ -759,6 +761,7 @@ class ModuleRegistry {
|
|
|
759
761
|
const depRecord = dependencyModuleRecords[i];
|
|
760
762
|
if (!depRecord.evaluated && !evaluationMap[depRecord.id]) {
|
|
761
763
|
evaluationMap[depRecord.id] = true;
|
|
764
|
+
// eslint-disable-next-line no-await-in-loop
|
|
762
765
|
await this.evaluateModule(depRecord, evaluationMap);
|
|
763
766
|
}
|
|
764
767
|
}
|
|
@@ -788,7 +791,8 @@ class ModuleRegistry {
|
|
|
788
791
|
const loadHook = loadHooks[i];
|
|
789
792
|
const response = loadHook(resolvedId, parentUrl);
|
|
790
793
|
const result = (isResponseAPromise(response)
|
|
791
|
-
?
|
|
794
|
+
? // eslint-disable-next-line no-await-in-loop
|
|
795
|
+
await evaluateLoadHook(resolvedId, response)
|
|
792
796
|
: response);
|
|
793
797
|
if (result === undefined) {
|
|
794
798
|
throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.5.0",
|
|
9
9
|
"homepage": "https://lwr.dev/",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"build": "tsc -b; yarn build:shim && yarn build:loader && yarn build:shim:bundle && yarn build:shim:bundle:minify"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@lwrjs/compiler": "0.
|
|
58
|
-
"@lwrjs/types": "0.
|
|
57
|
+
"@lwrjs/compiler": "0.5.0",
|
|
58
|
+
"@lwrjs/types": "0.5.0",
|
|
59
59
|
"rollup-plugin-terser": "^5.1.2"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@lwrjs/shared-utils": "0.
|
|
62
|
+
"@lwrjs/shared-utils": "0.5.0"
|
|
63
63
|
},
|
|
64
64
|
"lwc": {
|
|
65
65
|
"modules": [
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=14.15.4 <15"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "8b46ed1d391c744926ad65b442e5a9f9969d832e"
|
|
80
80
|
}
|