@lwrjs/loader 0.5.11-alpha.2 → 0.6.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/build/__tests__/shim/browser/test_server.js +2 -1
- package/build/__tests__/shim-legacy/browser/test_server.js +2 -1
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +28 -6
- package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +2 -25
- package/build/assets/prod/lwr-loader-shim-legacy.js +23 -4
- package/build/assets/prod/lwr-loader-shim.bundle.js +113 -9
- package/build/assets/prod/lwr-loader-shim.bundle.min.js +2 -25
- package/build/assets/prod/lwr-loader-shim.js +75 -7
- package/build/bundle/prod/lwr/esmLoader/esmLoader.js +1 -1
- package/build/cjs/metrics.cjs +43 -0
- package/build/cjs/modules/lwr/esmLoader/esmLoader.cjs +14 -5
- package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +4 -0
- package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +10 -0
- package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +3 -0
- package/build/metrics.d.ts +18 -0
- package/build/metrics.js +20 -0
- package/build/modules/lwr/esmLoader/esmLoader.js +17 -7
- package/build/modules/lwr/loader/loader.js +38 -2
- package/build/modules/lwr/loaderLegacy/loaderLegacy.js +5 -2
- package/build/shim/profiler.d.ts +23 -0
- package/build/shim/profiler.js +47 -0
- package/package.json +22 -7
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ LWR's AMD-like module format support. Unlike generic AMD, all modules in LWR mus
|
|
|
66
66
|
- `name` - The module name
|
|
67
67
|
- `dependencies` - A list of module dependencies (module imports)
|
|
68
68
|
- `execute` - The function containing the module code.
|
|
69
|
-
- `signatures` - An argument unique to LWR's AMD loader. The object containing the "signature" of the module and the signatures for each of its dependencies. Signatures are used to identify module changes from the server and is discussed at length in the [Module API RFC](https://rfcs.lwc.dev/rfcs/
|
|
69
|
+
- `signatures` - An argument unique to LWR's AMD loader. The object containing the "signature" of the module and the signatures for each of its dependencies. Signatures are used to identify module changes from the server and is discussed at length in the [Module API RFC](https://rfcs.lwc.dev/rfcs/lwr/0002-component-api#signatures).
|
|
70
70
|
|
|
71
71
|
In order to load modules from the server, you must set the define on the global scope matching the module define call from the server:
|
|
72
72
|
|
|
@@ -306,7 +306,7 @@ A web client provides the following HTML document to bootstrap a LWR application
|
|
|
306
306
|
</body>
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
-
Read more in the [bootstrap RFC](https://rfcs.lwc.dev/rfcs/
|
|
309
|
+
Read more in the [bootstrap RFC](https://rfcs.lwc.dev/rfcs/lwr/0000-lwr-bootstrap#web-client-bootstrap-flow).
|
|
310
310
|
|
|
311
311
|
### Client Bootstrap Config
|
|
312
312
|
|
|
@@ -335,7 +335,7 @@ globalThis.LWR: {
|
|
|
335
335
|
}
|
|
336
336
|
```
|
|
337
337
|
|
|
338
|
-
Read more in the [bootstrap RFC](https://rfcs.lwc.dev/rfcs/
|
|
338
|
+
Read more in the [bootstrap RFC](https://rfcs.lwc.dev/rfcs/lwr/0000-lwr-bootstrap#client-bootstrap-config).
|
|
339
339
|
|
|
340
340
|
### Custom Initialization
|
|
341
341
|
|
|
@@ -353,6 +353,8 @@ type CustomInitAPI = {
|
|
|
353
353
|
initializeApp: InitializeApp;
|
|
354
354
|
// register bootstrap error state callback
|
|
355
355
|
onBootstrapError: RegisterBootstrapErrorHandler;
|
|
356
|
+
// Register a dispatcher for the metrics profiler
|
|
357
|
+
attachDispatcher: (dispatcher: LogDispatcher) => void;
|
|
356
358
|
// A convenience pointer to the globally available LWR.define
|
|
357
359
|
define: Function;
|
|
358
360
|
};
|
|
@@ -396,7 +398,7 @@ The loader shim calls the `customInit` hook and **will not** start the applicati
|
|
|
396
398
|
</body>
|
|
397
399
|
```
|
|
398
400
|
|
|
399
|
-
Read more in the [bootstrap RFC](https://rfcs.lwc.dev/rfcs/
|
|
401
|
+
Read more in the [bootstrap RFC](https://rfcs.lwc.dev/rfcs/lwr/0000-lwr-bootstrap#custominit-hook).
|
|
400
402
|
|
|
401
403
|
### Output
|
|
402
404
|
|
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import { once } from 'events';
|
|
7
7
|
import { pathToFileURL, fileURLToPath, URL } from 'url';
|
|
8
|
+
import { isNodeError } from '@lwrjs/diagnostics';
|
|
8
9
|
import { getAMDModule } from '../../../modules/lwr/loader/__tests__/utils/amd.js';
|
|
9
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
11
|
const baseUrl = pathToFileURL(path.resolve(__dirname, '../../../../') + '/');
|
|
@@ -36,7 +37,7 @@ http.createServer(async function (req, res) {
|
|
|
36
37
|
await once(fileStream, 'readable');
|
|
37
38
|
}
|
|
38
39
|
catch (e) {
|
|
39
|
-
if (e.code === 'EISDIR' || e.code === 'ENOENT') {
|
|
40
|
+
if (isNodeError(e) && (e.code === 'EISDIR' || e.code === 'ENOENT')) {
|
|
40
41
|
res.writeHead(404, {
|
|
41
42
|
'content-type': 'text/html',
|
|
42
43
|
});
|
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import { once } from 'events';
|
|
7
7
|
import { pathToFileURL, fileURLToPath, URL } from 'url';
|
|
8
|
+
import { isNodeError } from '@lwrjs/diagnostics';
|
|
8
9
|
import { getAMDModule } from '../../../modules/lwr/loaderLegacy/__tests__/utils/amd.js';
|
|
9
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
11
|
const baseUrl = pathToFileURL(path.resolve(__dirname, '../../../../') + '/');
|
|
@@ -36,7 +37,7 @@ http.createServer(async function (req, res) {
|
|
|
36
37
|
await once(fileStream, 'readable');
|
|
37
38
|
}
|
|
38
39
|
catch (e) {
|
|
39
|
-
if (e.code === 'EISDIR' || e.code === 'ENOENT') {
|
|
40
|
+
if (isNodeError(e) && (e.code === 'EISDIR' || e.code === 'ENOENT')) {
|
|
40
41
|
res.writeHead(404, {
|
|
41
42
|
'content-type': 'text/html',
|
|
42
43
|
});
|
|
@@ -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.6.0-alpha.11 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -36,6 +36,14 @@
|
|
|
36
36
|
|
|
37
37
|
const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
|
|
38
38
|
|
|
39
|
+
var Phase;
|
|
40
|
+
(function (Phase) {
|
|
41
|
+
Phase[Phase["Start"] = 0] = "Start";
|
|
42
|
+
Phase[Phase["End"] = 1] = "End";
|
|
43
|
+
})(Phase || (Phase = {}));
|
|
44
|
+
function attachDispatcher(dispatcher) {
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
// Check for errors with autoBoot and customInit
|
|
40
48
|
function validatePreInit(autoBoot, customInit) {
|
|
41
49
|
// If autoBoot === false, there must be a customInit hook
|
|
@@ -58,6 +66,7 @@
|
|
|
58
66
|
initializeApp,
|
|
59
67
|
define,
|
|
60
68
|
onBootstrapError,
|
|
69
|
+
attachDispatcher,
|
|
61
70
|
};
|
|
62
71
|
customInit(lwr, config);
|
|
63
72
|
}
|
|
@@ -75,7 +84,7 @@
|
|
|
75
84
|
// Parse configuration
|
|
76
85
|
this.global = global;
|
|
77
86
|
this.config = global.LWR;
|
|
78
|
-
this.loaderModule = 'lwr/loaderLegacy/v/
|
|
87
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_11';
|
|
79
88
|
// Set up the temporary LWR.define function and customInit hook
|
|
80
89
|
const tempDefine = this.tempDefine.bind(this);
|
|
81
90
|
global.LWR.define = tempDefine;
|
|
@@ -175,6 +184,16 @@
|
|
|
175
184
|
loader.define(...this.defineCache[specifier]);
|
|
176
185
|
}
|
|
177
186
|
});
|
|
187
|
+
// Define a dummy profiler since the "lwr/profiler" module is used in "lwr/init" (which is global to all server modes)
|
|
188
|
+
const profilerExporter = (exports) => {
|
|
189
|
+
Object.assign(exports, {
|
|
190
|
+
logOperationStart: () => {
|
|
191
|
+
/* noop */
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
};
|
|
196
|
+
loader.define('lwr/profiler/v/0_6_0-alpha_11', ['exports'], profilerExporter, {});
|
|
178
197
|
// by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
|
|
179
198
|
const { disableInitDefer } = this.config;
|
|
180
199
|
// Load the import mappings and application bootstrap module
|
|
@@ -214,14 +233,14 @@
|
|
|
214
233
|
// The loader module is ALWAYS required
|
|
215
234
|
const GLOBAL = globalThis;
|
|
216
235
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
217
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/
|
|
218
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/
|
|
236
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_11') < 0) {
|
|
237
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_11');
|
|
219
238
|
}
|
|
220
239
|
new LoaderShim(GLOBAL);
|
|
221
240
|
|
|
222
241
|
}());
|
|
223
242
|
|
|
224
|
-
LWR.define('lwr/loaderLegacy/v/
|
|
243
|
+
LWR.define('lwr/loaderLegacy/v/0_6_0-alpha_11', ['exports'], function (exports) { 'use strict';
|
|
225
244
|
|
|
226
245
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
227
246
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -961,6 +980,9 @@ LWR.define('lwr/loaderLegacy/v/0_5_11-alpha_2', ['exports'], function (exports)
|
|
|
961
980
|
if (moduleExports.__defaultInterop) {
|
|
962
981
|
Object.defineProperty(moduleRecord.module, '__defaultInterop', { value: true });
|
|
963
982
|
}
|
|
983
|
+
if (moduleExports.__esModule) {
|
|
984
|
+
Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
|
|
985
|
+
}
|
|
964
986
|
moduleRecord.evaluated = true;
|
|
965
987
|
Object.freeze(moduleRecord.module);
|
|
966
988
|
return moduleRecord.module;
|
|
@@ -1133,7 +1155,7 @@ LWR.define('lwr/loaderLegacy/v/0_5_11-alpha_2', ['exports'], function (exports)
|
|
|
1133
1155
|
}
|
|
1134
1156
|
else if (defaultUri) {
|
|
1135
1157
|
// When a specifier's URI cannot be resolved via the imports, fallback to "default".
|
|
1136
|
-
// -> https://rfcs.lwc.dev/rfcs/
|
|
1158
|
+
// -> https://rfcs.lwc.dev/rfcs/lwr/0000-import-metadata#json-schema
|
|
1137
1159
|
// However, if `id` is already a fully resolved url,
|
|
1138
1160
|
// we cannot prepend the defaultUri -> https://github.com/salesforce/lwr/issues/378.
|
|
1139
1161
|
// In this case we do not apply any package mappings and allow the caller (resolveImportMapEntry) to handle it.
|
|
@@ -4,28 +4,5 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Legacy Module Loader Shim v0.
|
|
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_11-alpha_2")<0&&o.LWR.requiredModules.push("lwr/loaderLegacy/v/0_5_11-alpha_2"),new class{constructor(r){this.defineCache={},this.orderedDefs=[],this.global=r,this.config=r.LWR,this.loaderModule="lwr/loaderLegacy/v/0_5_11-alpha_2";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_11-alpha_2",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),BAD_IMPORT_MAP=Object.freeze({code:3011,level:0,message:"import map is not valid"}),hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}
|
|
9
|
-
/**
|
|
10
|
-
* Check if a string is a URL based on Common Internet Scheme Syntax
|
|
11
|
-
* https://www.ietf.org/rfc/rfc1738.txt
|
|
12
|
-
*
|
|
13
|
-
* URL Format:
|
|
14
|
-
* <scheme>:<scheme-specific-part>
|
|
15
|
-
* Common Internet Scheme Syntax:
|
|
16
|
-
* The scheme specific part starts with a double slash('//')
|
|
17
|
-
*
|
|
18
|
-
* A valid URL has a colon that is followed by a double slash.
|
|
19
|
-
*
|
|
20
|
-
* @param url - the url that is being checked
|
|
21
|
-
* @returns boolean
|
|
22
|
-
*
|
|
23
|
-
* @example Valid URLs
|
|
24
|
-
* 'https://salesforce.com'
|
|
25
|
-
* 'http://localhost:3000'
|
|
26
|
-
*
|
|
27
|
-
* @example Invalid URLs
|
|
28
|
-
* 'salesforce.com'
|
|
29
|
-
* 'localhost:3000'
|
|
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 s=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let i=-1;for(let e=0;e<s.length;e++)-1!==i?"/"===s[e]&&(n.push(s.slice(i,e+1)),i=-1):"."===s[e]?"."!==s[e+1]||"/"!==s[e+2]&&e+2!==s.length?"/"===s[e+1]||e+1===s.length?e+=1:i=e:(n.pop(),e+=2):i=e;return-1!==i&&n.push(s.slice(i)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0})).finally((()=>{}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const s=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(s)}))})):t}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldHash:o,newHash:s}=t;for(let t=0;t<e.length;t++){const n=e[t];try{if(null!==n({name:r,oldHash:o,newHash:s}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.baseUrl=e}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.baseUrl;let o,s=e;const n=this.resolveHook;if(n){for(let e=0;e<n.length;e++){const t=(0,n[e])(s,{parentUrl:r});let i;if((t||null===t)&&(i=isResponseAPromise(t)?await t:t),null!==i){if("string"==typeof i){if(resolveIfNotPlainOrUrl(i,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);s=i;continue}if(o=i&&i.url&&(resolveIfNotPlainOrUrl(i.url,r)||i.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(s!==e){if(!o&&this.namedDefineRegistry.has(s))return s;e=s}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;if(this.resolver){if(o=this.resolver.resolve(t,r),this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){const e=this.moduleRegistry.get(o);if(!e||!e.aliases.has(t))return t}}else o=t}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r,o){const s=this.namedDefineRegistry.get(e);if(s&&s.defined)return void(this.lastDefine=s);const n={name:e,dependencies:t,exporter:r,signatures:o,defined:!0};s&&s.external&&s.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n,o.hashes&&Object.entries(o.hashes).forEach((([e,t])=>{this.checkModuleSignature(e,t)}))}registerExternalModules(e){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise(((o,s)=>{t=o,r=setTimeout((()=>{s(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),s={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,s)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}checkModuleSignature(e,t){const r=this.namedDefineRegistry.get(e);if(!r){const r={name:e,signatures:{ownHash:t},defined:!1};return void this.namedDefineRegistry.set(e,r)}const o=r.signatures?r.signatures.ownHash:void 0;if(o&&t!==o){const r=this.handleStaleModuleHook;r?evaluateHandleStaleModuleHooks(r,{name:e,oldHash:o,newHash:t}):hasConsole&&console.warn(`stale module detected ${e}, current sig:${o}, new sig:${t}`)}}setImportResolver(e){this.resolver=e}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r.aliases.has(t)||r.aliases.add(t),r;const o=this.getModuleDef(e,t),s=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)}));return r={id:e,aliases:new Set([t]),module:Object.create(null),dependencyRecords:s,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:s}=await e.instantiation,n={},i=await Promise.all(s.map((async e=>{if("exports"===e)return n;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...i);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(n)&&Object.defineProperty(n,"__useDefault",{value:!0});const l=a||n;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const s=this.baseUrl;return Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,s),n=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===n)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(n&&null!==n)return evaluateLoadHookResponse(n,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o})).catch((e=>{throw e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t])}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}function getMatch(e,t){if(t[e])return e;let r=e.length;do{const o=e.slice(0,r+1);if(o in t)return o}while(-1!==(r=e.lastIndexOf("/",r-1)))}function targetWarning(e,t,r){hasConsole&&console.warn("Package target "+r+", resolving target '"+t+"' for "+e)}function applyPackages(e,t,r){const o=getMatch(e,t);if(o){const r=t[o];if(null===r)return;if(!(e.length>o.length&&"/"!==r[r.length-1])){return e.length>o.length&&"/"===r[r.length-1]&&r.lastIndexOf(o)===r.length-o.length?r.substring(0,r.lastIndexOf(o))+encodeURIComponent(e):r+e.slice(o.length)}targetWarning(o,r,"should have a trailing '/'")}else if(r&&!isUrl(e))return r+encodeURIComponent(e)}function resolveImportMapEntry(e,t,r){e.scopes||(e.scopes={}),e.imports||(e.imports={});const o=e.scopes;let s=r&&getMatch(r,o);for(;s;){const e=applyPackages(t,o[s]);if(e)return e;s=getMatch(s.slice(0,s.lastIndexOf("/")),o)}return applyPackages(t,e.imports,e.default)||isUrl(t)&&t||void 0}function resolveAndComposePackages(e,t,r,o,s){for(const n in e){const i=resolveIfNotPlainOrUrl(n,r)||n,a=e[n];if("string"!=typeof a)continue;const l=resolveImportMapEntry(o,resolveIfNotPlainOrUrl(a,r)||a,s);l?t[i]=l:targetWarning(n,a,"bare specifier did not resolve")}}function resolveAndComposeImportMap(e,t,r={imports:{},scopes:{}}){const o={imports:Object.assign({},r.imports),scopes:Object.assign({},r.scopes),default:e.default};if(e.imports&&resolveAndComposePackages(e.imports,o.imports,t,r),e.scopes)for(const s in e.scopes){const n=resolveUrl(s,t);resolveAndComposePackages(e.scopes[s],o.scopes[n]||(o.scopes[n]={}),t,r,n)}return e.default&&(o.default=resolveIfNotPlainOrUrl(e.default,t)),o}class ImportMapResolver{constructor(e){this.importMap=e}resolve(e,t){return resolveImportMapEntry(this.importMap,e,t)}}const IMPORTMAP_SCRIPT_TYPE="lwr-importmap";function iterateDocumentImportMaps(e,t){const r=document.querySelectorAll(`script[type="${IMPORTMAP_SCRIPT_TYPE}"]`+t),o=Array.from(r).filter((e=>!e.src||(hasConsole&&console.warn("LWR does not support import maps from script src"),!1)));Array.prototype.forEach.call(o,e)}async function getImportMapFromScript(e){return Promise.resolve(e.innerHTML)}async function evaluateImportMaps(e){let t={imports:{},scopes:{}},r=Promise.resolve(t);if(hasDocument){if(e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);iterateDocumentImportMaps((o=>{r=r.then((()=>getImportMapFromScript(o))).then((e=>{try{return JSON.parse(e)}catch(e){throw new LoaderError(BAD_IMPORT_MAP)}})).then((r=>(t=resolveAndComposeImportMap(r,o.src||e,t),t)))}),"")}return r}class Loader{constructor(e){if(e&&(e=e.replace(/\/?$/,"/")),e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);this.baseUrl=e,this.registry=new ModuleRegistry(e),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r,o){invariant("string"==typeof e,MISSING_NAME);let s=r,n=t,i=o;"function"==typeof n&&(s=t,n=[],i=r),i=i||{},invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,s,i)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e){let t;if(t=e?resolveAndComposeImportMap(e,this.baseUrl,this.parentImportMap):await evaluateImportMaps(this.baseUrl),this.parentImportMap=t,this.parentImportMap){const e=new ImportMapResolver(this.parentImportMap);this.registry.setImportResolver(e)}}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.6.0-alpha.11 */
|
|
8
|
+
!function(){"use strict";var e;function t(e){}function r(e,r,o,s){const{autoBoot:n,customInit:i}=e;if(function(e,t){if(!e&&!t)throw new Error("The customInit hook is required when autoBoot is false");if(e&&t)throw new Error("The customInit hook must not be defined when autoBoot is true")}(n,i),i){i({initializeApp:r,define:o,onBootstrapError:s,attachDispatcher:t},e)}}!function(e){e[e.Start=0]="Start",e[e.End=1]="End"}(e||(e={}));const o="function"==typeof setTimeout,s="undefined"!=typeof console;const n=globalThis;n.LWR.requiredModules=n.LWR.requiredModules||[],n.LWR.requiredModules.indexOf("lwr/loaderLegacy/v/0_6_0-alpha_11")<0&&n.LWR.requiredModules.push("lwr/loaderLegacy/v/0_6_0-alpha_11"),new class{constructor(e){this.defineCache={},this.orderedDefs=[],this.global=e,this.config=e.LWR,this.loaderModule="lwr/loaderLegacy/v/0_6_0-alpha_11";const t=this.tempDefine.bind(this);e.LWR.define=t,this.bootReady=this.config.autoBoot,o&&(this.watchdogTimerId=this.startWatchdogTimer());try{r(Object.freeze(this.config),this.postCustomInit.bind(this),t,(e=>{this.errorHandler=e}))}catch(e){this.enterErrorState(e)}}canInit(){const e=this.config.requiredModules.every((e=>this.orderedDefs.includes(e)));return this.bootReady&&e}tempDefine(...e){const t=e[0];this.defineCache[t]=e,this.orderedDefs.push(t),this.canInit()&&(o&&clearTimeout(this.watchdogTimerId),this.initApp())}postCustomInit(){this.bootReady=!0,this.canInit()&&this.initApp()}initApp(){try{const e=function(e,t,r,o){if(!t||"function"!=typeof t[2])throw new Error(`Expected loader with specifier "${e}" to be a module`);const s={};t[2].call(null,s);const{Loader:n}=s,i=new n(r);return o&&o.length&&i.registerExternalModules(o),i.define(e,["exports"],(e=>{Object.assign(e,{define:i.define.bind(i),load:i.load.bind(i),services:i.services})}),t[3]),i}(this.loaderModule,this.defineCache[this.loaderModule],this.config.baseUrl,this.config.preloadModules);this.mountApp(e)}catch(e){this.enterErrorState(e)}}waitForDOMContentLoaded(){return void 0===typeof document||"interactive"===document.readyState||"complete"===document.readyState?Promise.resolve():new Promise((e=>{document.addEventListener("DOMContentLoaded",(()=>{e()}))}))}mountApp(e){const{bootstrapModule:t,rootComponent:r,importMappings:o,rootComponents:s,endpoints:n}=this.config;this.global.LWR=Object.freeze({define:e.define.bind(e),rootComponent:r,rootComponents:s,importMappings:o,endpoints:n}),this.orderedDefs.forEach((t=>{t!==this.loaderModule&&e.define(...this.defineCache[t])}));e.define("lwr/profiler/v/0_6_0-alpha_11",["exports"],(e=>{Object.assign(e,{logOperationStart:()=>{}})}),{});const{disableInitDefer:i}=this.config;e.registerImportMappings(o).then((()=>{if(!i)return this.waitForDOMContentLoaded()})).then((()=>e.load(t))).catch((e=>{this.enterErrorState(new Error(`Application ${r} could not be loaded: ${e}`))}))}enterErrorState(e){this.errorHandler?this.errorHandler(e):s&&console.error(`An error occurred during LWR bootstrap. ${e.message}`,e.stack)}startWatchdogTimer(){return setTimeout((()=>{this.enterErrorState(new Error("Failed to load required modules - timed out"))}),3e5)}}(n)}(),LWR.define("lwr/loaderLegacy/v/0_6_0-alpha_11",["exports"],(function(exports){"use strict";const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),BAD_IMPORT_MAP=Object.freeze({code:3011,level:0,message:"import map is not valid"}),hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const s=o.slice(0,o.lastIndexOf("/")+1)+e,n=[];let i=-1;for(let e=0;e<s.length;e++)-1!==i?"/"===s[e]&&(n.push(s.slice(i,e+1)),i=-1):"."===s[e]?"."!==s[e+1]||"/"!==s[e+2]&&e+2!==s.length?"/"===s[e+1]||e+1===s.length?e+=1:i=e:(n.pop(),e+=2):i=e;return-1!==i&&n.push(s.slice(i)),t.slice(0,t.length-o.length)+n.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.charset="utf-8",t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0})).finally((()=>{}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const s=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(s)}))})):t}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldHash:o,newHash:s}=t;for(let t=0;t<e.length;t++){const n=e[t];try{if(null!==n({name:r,oldHash:o,newHash:s}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.baseUrl=e}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.baseUrl;let o,s=e;const n=this.resolveHook;if(n){for(let e=0;e<n.length;e++){const t=(0,n[e])(s,{parentUrl:r});let i;if((t||null===t)&&(i=isResponseAPromise(t)?await t:t),null!==i){if("string"==typeof i){if(resolveIfNotPlainOrUrl(i,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);s=i;continue}if(o=i&&i.url&&(resolveIfNotPlainOrUrl(i.url,r)||i.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(s!==e){if(!o&&this.namedDefineRegistry.has(s))return s;e=s}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;if(this.resolver){if(o=this.resolver.resolve(t,r),this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){const e=this.moduleRegistry.get(o);if(!e||!e.aliases.has(t))return t}}else o=t}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r,o){const s=this.namedDefineRegistry.get(e);if(s&&s.defined)return void(this.lastDefine=s);const n={name:e,dependencies:t,exporter:r,signatures:o,defined:!0};s&&s.external&&s.external.resolveExternal(n),this.namedDefineRegistry.set(e,n),this.lastDefine=n,o.hashes&&Object.entries(o.hashes).forEach((([e,t])=>{this.checkModuleSignature(e,t)}))}registerExternalModules(e){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise(((o,s)=>{t=o,r=setTimeout((()=>{s(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),s={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,s)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}checkModuleSignature(e,t){const r=this.namedDefineRegistry.get(e);if(!r){const r={name:e,signatures:{ownHash:t},defined:!1};return void this.namedDefineRegistry.set(e,r)}const o=r.signatures?r.signatures.ownHash:void 0;if(o&&t!==o){const r=this.handleStaleModuleHook;r?evaluateHandleStaleModuleHooks(r,{name:e,oldHash:o,newHash:t}):hasConsole&&console.warn(`stale module detected ${e}, current sig:${o}, new sig:${t}`)}}setImportResolver(e){this.resolver=e}getModuleRecord(e,t){let r=this.moduleRegistry.get(e);if(r)return r.aliases.has(t)||r.aliases.add(t),r;const o=this.getModuleDef(e,t),s=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)}));return r={id:e,aliases:new Set([t]),module:Object.create(null),dependencyRecords:s,instantiation:o,evaluated:!1,evaluationPromise:null},this.moduleRegistry.set(e,r),r}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:s}=await e.instantiation,n={},i=await Promise.all(s.map((async e=>{if("exports"===e)return n;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...i);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(n)&&Object.defineProperty(n,"__useDefault",{value:!0});const l=a||n;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),l.__esModule&&Object.defineProperty(e.module,"__esModule",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const s=this.baseUrl;return Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,s),n=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===n)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(n&&null!==n)return evaluateLoadHookResponse(n,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return o})).catch((e=>{throw e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t])}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}function getMatch(e,t){if(t[e])return e;let r=e.length;do{const o=e.slice(0,r+1);if(o in t)return o}while(-1!==(r=e.lastIndexOf("/",r-1)))}function targetWarning(e,t,r){hasConsole&&console.warn("Package target "+r+", resolving target '"+t+"' for "+e)}function applyPackages(e,t,r){const o=getMatch(e,t);if(o){const r=t[o];if(null===r)return;if(!(e.length>o.length&&"/"!==r[r.length-1])){return e.length>o.length&&"/"===r[r.length-1]&&r.lastIndexOf(o)===r.length-o.length?r.substring(0,r.lastIndexOf(o))+encodeURIComponent(e):r+e.slice(o.length)}targetWarning(o,r,"should have a trailing '/'")}else if(r&&!isUrl(e))return r+encodeURIComponent(e)}function resolveImportMapEntry(e,t,r){e.scopes||(e.scopes={}),e.imports||(e.imports={});const o=e.scopes;let s=r&&getMatch(r,o);for(;s;){const e=applyPackages(t,o[s]);if(e)return e;s=getMatch(s.slice(0,s.lastIndexOf("/")),o)}return applyPackages(t,e.imports,e.default)||isUrl(t)&&t||void 0}function resolveAndComposePackages(e,t,r,o,s){for(const n in e){const i=resolveIfNotPlainOrUrl(n,r)||n,a=e[n];if("string"!=typeof a)continue;const l=resolveImportMapEntry(o,resolveIfNotPlainOrUrl(a,r)||a,s);l?t[i]=l:targetWarning(n,a,"bare specifier did not resolve")}}function resolveAndComposeImportMap(e,t,r={imports:{},scopes:{}}){const o={imports:Object.assign({},r.imports),scopes:Object.assign({},r.scopes),default:e.default};if(e.imports&&resolveAndComposePackages(e.imports,o.imports,t,r),e.scopes)for(const s in e.scopes){const n=resolveUrl(s,t);resolveAndComposePackages(e.scopes[s],o.scopes[n]||(o.scopes[n]={}),t,r,n)}return e.default&&(o.default=resolveIfNotPlainOrUrl(e.default,t)),o}class ImportMapResolver{constructor(e){this.importMap=e}resolve(e,t){return resolveImportMapEntry(this.importMap,e,t)}}const IMPORTMAP_SCRIPT_TYPE="lwr-importmap";function iterateDocumentImportMaps(e,t){const r=document.querySelectorAll(`script[type="${IMPORTMAP_SCRIPT_TYPE}"]`+t),o=Array.from(r).filter((e=>!e.src||(hasConsole&&console.warn("LWR does not support import maps from script src"),!1)));Array.prototype.forEach.call(o,e)}async function getImportMapFromScript(e){return Promise.resolve(e.innerHTML)}async function evaluateImportMaps(e){let t={imports:{},scopes:{}},r=Promise.resolve(t);if(hasDocument){if(e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);iterateDocumentImportMaps((o=>{r=r.then((()=>getImportMapFromScript(o))).then((e=>{try{return JSON.parse(e)}catch(e){throw new LoaderError(BAD_IMPORT_MAP)}})).then((r=>(t=resolveAndComposeImportMap(r,o.src||e,t),t)))}),"")}return r}class Loader{constructor(e){if(e&&(e=e.replace(/\/?$/,"/")),e||(e=getBaseUrl()),!e)throw new LoaderError(NO_BASE_URL);this.baseUrl=e,this.registry=new ModuleRegistry(e),this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry)})}define(e,t,r,o){invariant("string"==typeof e,MISSING_NAME);let s=r,n=t,i=o;"function"==typeof n&&(s=t,n=[],i=r),i=i||{},invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,s,i)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e){let t;if(t=e?resolveAndComposeImportMap(e,this.baseUrl,this.parentImportMap):await evaluateImportMaps(this.baseUrl),this.parentImportMap=t,this.parentImportMap){const e=new ImportMapResolver(this.parentImportMap);this.registry.setImportResolver(e)}}registerExternalModules(e){this.registry.registerExternalModules(e)}}exports.Loader=Loader,Object.defineProperty(exports,"__esModule",{value:!0})}));
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Legacy Module Loader Shim v0.
|
|
7
|
+
/* LWR Legacy Module Loader Shim v0.6.0-alpha.11 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
@@ -36,6 +36,14 @@
|
|
|
36
36
|
|
|
37
37
|
const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
|
|
38
38
|
|
|
39
|
+
var Phase;
|
|
40
|
+
(function (Phase) {
|
|
41
|
+
Phase[Phase["Start"] = 0] = "Start";
|
|
42
|
+
Phase[Phase["End"] = 1] = "End";
|
|
43
|
+
})(Phase || (Phase = {}));
|
|
44
|
+
function attachDispatcher(dispatcher) {
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
// Check for errors with autoBoot and customInit
|
|
40
48
|
function validatePreInit(autoBoot, customInit) {
|
|
41
49
|
// If autoBoot === false, there must be a customInit hook
|
|
@@ -58,6 +66,7 @@
|
|
|
58
66
|
initializeApp,
|
|
59
67
|
define,
|
|
60
68
|
onBootstrapError,
|
|
69
|
+
attachDispatcher,
|
|
61
70
|
};
|
|
62
71
|
customInit(lwr, config);
|
|
63
72
|
}
|
|
@@ -75,7 +84,7 @@
|
|
|
75
84
|
// Parse configuration
|
|
76
85
|
this.global = global;
|
|
77
86
|
this.config = global.LWR;
|
|
78
|
-
this.loaderModule = 'lwr/loaderLegacy/v/
|
|
87
|
+
this.loaderModule = 'lwr/loaderLegacy/v/0_6_0-alpha_11';
|
|
79
88
|
// Set up the temporary LWR.define function and customInit hook
|
|
80
89
|
const tempDefine = this.tempDefine.bind(this);
|
|
81
90
|
global.LWR.define = tempDefine;
|
|
@@ -175,6 +184,16 @@
|
|
|
175
184
|
loader.define(...this.defineCache[specifier]);
|
|
176
185
|
}
|
|
177
186
|
});
|
|
187
|
+
// Define a dummy profiler since the "lwr/profiler" module is used in "lwr/init" (which is global to all server modes)
|
|
188
|
+
const profilerExporter = (exports) => {
|
|
189
|
+
Object.assign(exports, {
|
|
190
|
+
logOperationStart: () => {
|
|
191
|
+
/* noop */
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
};
|
|
196
|
+
loader.define('lwr/profiler/v/0_6_0-alpha_11', ['exports'], profilerExporter, {});
|
|
178
197
|
// by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
|
|
179
198
|
const { disableInitDefer } = this.config;
|
|
180
199
|
// Load the import mappings and application bootstrap module
|
|
@@ -214,8 +233,8 @@
|
|
|
214
233
|
// The loader module is ALWAYS required
|
|
215
234
|
const GLOBAL = globalThis;
|
|
216
235
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
217
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/
|
|
218
|
-
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/
|
|
236
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_6_0-alpha_11') < 0) {
|
|
237
|
+
GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_6_0-alpha_11');
|
|
219
238
|
}
|
|
220
239
|
new LoaderShim(GLOBAL);
|
|
221
240
|
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
-
/* LWR Module Loader Shim v0.
|
|
7
|
+
/* LWR Module Loader Shim v0.6.0-alpha.11 */
|
|
8
8
|
(function () {
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
+
// Bootstrap / shim
|
|
12
|
+
const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
|
|
13
|
+
const BOOTSTRAP_ERROR = `${BOOTSTRAP_PREFIX}error`;
|
|
14
|
+
|
|
11
15
|
function createLoader(name, definition, config, externalModules) {
|
|
12
16
|
if (!definition || typeof definition[2] !== 'function') {
|
|
13
17
|
throw new Error(`Expected loader with specifier "${name}" to be a module`);
|
|
@@ -27,7 +31,6 @@
|
|
|
27
31
|
load: loader.load.bind(loader),
|
|
28
32
|
services: loader.services,
|
|
29
33
|
});
|
|
30
|
-
return;
|
|
31
34
|
};
|
|
32
35
|
loader.define(name, ['exports'], exporter);
|
|
33
36
|
return loader;
|
|
@@ -35,6 +38,53 @@
|
|
|
35
38
|
|
|
36
39
|
const REQUIRED_MODULES_TIMEOUT = 300 * 1000;
|
|
37
40
|
|
|
41
|
+
var Phase;
|
|
42
|
+
(function (Phase) {
|
|
43
|
+
Phase[Phase["Start"] = 0] = "Start";
|
|
44
|
+
Phase[Phase["End"] = 1] = "End";
|
|
45
|
+
})(Phase || (Phase = {}));
|
|
46
|
+
// Attach a custom dispatcher
|
|
47
|
+
let customDispatcher;
|
|
48
|
+
function attachDispatcher(dispatcher) {
|
|
49
|
+
customDispatcher = dispatcher;
|
|
50
|
+
}
|
|
51
|
+
// Check if the Performance API is available
|
|
52
|
+
// e.g. JSDom (used in Jest) doesn't implement these
|
|
53
|
+
const perf = globalThis.performance;
|
|
54
|
+
const isPerfSupported = typeof perf !== 'undefined' &&
|
|
55
|
+
typeof perf.mark === 'function' &&
|
|
56
|
+
typeof perf.clearMarks === 'function' &&
|
|
57
|
+
typeof perf.measure === 'function' &&
|
|
58
|
+
typeof perf.clearMeasures === 'function';
|
|
59
|
+
// For marking request metrics
|
|
60
|
+
// Fallback to the Performance API if there is no custom dispatcher
|
|
61
|
+
function logOperationStart({ id, specifier }) {
|
|
62
|
+
if (customDispatcher) {
|
|
63
|
+
customDispatcher({ id, phase: Phase.Start, specifier });
|
|
64
|
+
}
|
|
65
|
+
else if (isPerfSupported) {
|
|
66
|
+
perf.mark(id + (specifier ? `.${specifier}` : ''));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// For measuring duration metrics
|
|
70
|
+
// Fallback to the Performance API if there is no custom dispatcher
|
|
71
|
+
/* istanbul ignore next */
|
|
72
|
+
function logOperationEnd({ id, specifier }) {
|
|
73
|
+
if (customDispatcher) {
|
|
74
|
+
customDispatcher({ id, phase: Phase.End, specifier });
|
|
75
|
+
}
|
|
76
|
+
else if (isPerfSupported) {
|
|
77
|
+
const suffix = specifier ? `.${specifier}` : '';
|
|
78
|
+
const markName = id + suffix;
|
|
79
|
+
const measureName = `${id}.duration${suffix}`;
|
|
80
|
+
perf.measure(measureName, markName);
|
|
81
|
+
// Clear the created mark and measure to avoid filling the performance entry buffer
|
|
82
|
+
// Even if they get deleted, existing PerformanceObservers preserve copies of the entries
|
|
83
|
+
perf.clearMarks(markName);
|
|
84
|
+
perf.clearMeasures(measureName);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
38
88
|
// Check for errors with autoBoot and customInit
|
|
39
89
|
function validatePreInit(autoBoot, customInit) {
|
|
40
90
|
// If autoBoot === false, there must be a customInit hook
|
|
@@ -57,6 +107,7 @@
|
|
|
57
107
|
initializeApp,
|
|
58
108
|
define,
|
|
59
109
|
onBootstrapError,
|
|
110
|
+
attachDispatcher,
|
|
60
111
|
};
|
|
61
112
|
customInit(lwr, config);
|
|
62
113
|
}
|
|
@@ -74,7 +125,7 @@
|
|
|
74
125
|
// Parse configuration
|
|
75
126
|
this.global = global;
|
|
76
127
|
this.config = global.LWR;
|
|
77
|
-
this.
|
|
128
|
+
this.loaderSpecifier = 'lwr/loader/v/0_6_0-alpha_11';
|
|
78
129
|
// Set up the temporary LWR.define function and customInit hook
|
|
79
130
|
const tempDefine = this.tempDefine.bind(this);
|
|
80
131
|
global.LWR.define = tempDefine;
|
|
@@ -136,8 +187,16 @@
|
|
|
136
187
|
const loaderConfig = {
|
|
137
188
|
endpoints: this.config.endpoints,
|
|
138
189
|
baseUrl: this.config.baseUrl,
|
|
190
|
+
profiler: { logOperationStart, logOperationEnd },
|
|
191
|
+
// TODO: can be removed following https://github.com/salesforce/lwr/issues/1087
|
|
192
|
+
appMetadata: {
|
|
193
|
+
bootstrapModule: this.config.bootstrapModule,
|
|
194
|
+
rootComponent: this.config.rootComponent,
|
|
195
|
+
rootComponents: this.config.rootComponents,
|
|
196
|
+
},
|
|
139
197
|
};
|
|
140
|
-
const loader = createLoader(this.
|
|
198
|
+
const loader = createLoader(this.loaderSpecifier, this.defineCache[this.loaderSpecifier], loaderConfig, this.config.preloadModules);
|
|
199
|
+
this.createProfilerModule(loader);
|
|
141
200
|
this.mountApp(loader);
|
|
142
201
|
}
|
|
143
202
|
catch (e) {
|
|
@@ -161,6 +220,14 @@
|
|
|
161
220
|
});
|
|
162
221
|
});
|
|
163
222
|
}
|
|
223
|
+
// Create a module out of the profiler
|
|
224
|
+
// Note: The profiler is also available as a module through lwc module resolution (see package.json)
|
|
225
|
+
createProfilerModule(loader) {
|
|
226
|
+
const exporter = (exports) => {
|
|
227
|
+
Object.assign(exports, { logOperationStart, logOperationEnd });
|
|
228
|
+
};
|
|
229
|
+
loader.define('lwr/profiler/v/0_6_0-alpha_11', ['exports'], exporter);
|
|
230
|
+
}
|
|
164
231
|
// Set up the application globals, import map, root custom element...
|
|
165
232
|
mountApp(loader) {
|
|
166
233
|
const { bootstrapModule, rootComponent, rootComponents, endpoints, imports, index } = this.config;
|
|
@@ -175,7 +242,7 @@
|
|
|
175
242
|
});
|
|
176
243
|
// Redefine all modules in the temporary cache
|
|
177
244
|
this.orderedDefs.forEach((specifier) => {
|
|
178
|
-
if (specifier !== this.
|
|
245
|
+
if (specifier !== this.loaderSpecifier) {
|
|
179
246
|
loader.define(...this.defineCache[specifier]);
|
|
180
247
|
}
|
|
181
248
|
});
|
|
@@ -196,6 +263,7 @@
|
|
|
196
263
|
}
|
|
197
264
|
// Trigger bootstrap error state, and call error handler if registered
|
|
198
265
|
enterErrorState(error) {
|
|
266
|
+
logOperationStart({ id: BOOTSTRAP_ERROR });
|
|
199
267
|
if (this.errorHandler) {
|
|
200
268
|
this.errorHandler(error);
|
|
201
269
|
}
|
|
@@ -218,14 +286,14 @@
|
|
|
218
286
|
// The loader module is ALWAYS required
|
|
219
287
|
const GLOBAL = globalThis;
|
|
220
288
|
GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
|
|
221
|
-
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/
|
|
222
|
-
GLOBAL.LWR.requiredModules.push('lwr/loader/v/
|
|
289
|
+
if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_6_0-alpha_11') < 0) {
|
|
290
|
+
GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_6_0-alpha_11');
|
|
223
291
|
}
|
|
224
292
|
new LoaderShim(GLOBAL);
|
|
225
293
|
|
|
226
294
|
}());
|
|
227
295
|
|
|
228
|
-
LWR.define('lwr/loader/v/
|
|
296
|
+
LWR.define('lwr/loader/v/0_6_0-alpha_11', ['exports'], function (exports) { 'use strict';
|
|
229
297
|
|
|
230
298
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
231
299
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -522,6 +590,16 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
522
590
|
});
|
|
523
591
|
}
|
|
524
592
|
|
|
593
|
+
// Bootstrap / shim
|
|
594
|
+
// Loader: modules
|
|
595
|
+
const LOADER_PREFIX = 'lwr.loader.';
|
|
596
|
+
const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
|
|
597
|
+
const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
|
|
598
|
+
const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
|
|
599
|
+
// Loader: mappings
|
|
600
|
+
const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
|
|
601
|
+
const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
|
|
602
|
+
|
|
525
603
|
/* spec based import map resolver */
|
|
526
604
|
class ImportMetadataResolver {
|
|
527
605
|
constructor(config, invalidationCallback) {
|
|
@@ -637,6 +715,7 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
637
715
|
if (pending) {
|
|
638
716
|
return pending;
|
|
639
717
|
}
|
|
718
|
+
this.config.profiler.logOperationStart({ id: MAPPINGS_FETCH, specifier });
|
|
640
719
|
const fetchMappingService = this.hasMappingHooks()
|
|
641
720
|
? this.evaluateMappingHooks
|
|
642
721
|
: this.fetchNewMappings;
|
|
@@ -651,6 +730,7 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
651
730
|
if (!uri) {
|
|
652
731
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
653
732
|
}
|
|
733
|
+
this.config.profiler.logOperationEnd({ id: MAPPINGS_FETCH, specifier });
|
|
654
734
|
return uri;
|
|
655
735
|
})
|
|
656
736
|
.finally(() => {
|
|
@@ -695,6 +775,7 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
695
775
|
const uri = resolveUrl(this.buildMappingUrl(specifier), this.getBaseUrl());
|
|
696
776
|
return globalThis.fetch(uri).then((res) => {
|
|
697
777
|
if (!res.ok) {
|
|
778
|
+
this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
|
|
698
779
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
699
780
|
}
|
|
700
781
|
return res
|
|
@@ -842,6 +923,7 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
842
923
|
this.namedDefineRegistry = new Map();
|
|
843
924
|
// The evaluted module registry where the module identifier (name or URL?) is the key
|
|
844
925
|
this.moduleRegistry = new Map();
|
|
926
|
+
this.profiler = config.profiler;
|
|
845
927
|
this.resolver = new ImportMetadataResolver(config, this.importMetadataInvalidationCallback.bind(this));
|
|
846
928
|
}
|
|
847
929
|
async load(id, importer) {
|
|
@@ -963,6 +1045,7 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
963
1045
|
// if module is "external", resolve the external promise to notify any dependees
|
|
964
1046
|
mod.external.resolveExternal(moduleDef);
|
|
965
1047
|
}
|
|
1048
|
+
this.profiler.logOperationStart({ id: MODULE_DEFINE, specifier: name });
|
|
966
1049
|
this.namedDefineRegistry.set(name, moduleDef);
|
|
967
1050
|
this.lastDefine = moduleDef;
|
|
968
1051
|
}
|
|
@@ -1145,6 +1228,9 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
1145
1228
|
if (moduleExports.__defaultInterop) {
|
|
1146
1229
|
Object.defineProperty(moduleRecord.module, '__defaultInterop', { value: true });
|
|
1147
1230
|
}
|
|
1231
|
+
if (moduleExports.__esModule) {
|
|
1232
|
+
Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
|
|
1233
|
+
}
|
|
1148
1234
|
moduleRecord.evaluated = true;
|
|
1149
1235
|
Object.freeze(moduleRecord.module);
|
|
1150
1236
|
return moduleRecord.module;
|
|
@@ -1192,6 +1278,8 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
1192
1278
|
return moduleDef;
|
|
1193
1279
|
}
|
|
1194
1280
|
const parentUrl = this.resolver.getBaseUrl(); // only support baseUrl for now
|
|
1281
|
+
const specifier = moduleName || originalId;
|
|
1282
|
+
this.profiler.logOperationStart({ id: MODULE_FETCH, specifier });
|
|
1195
1283
|
return Promise.resolve()
|
|
1196
1284
|
.then(async () => {
|
|
1197
1285
|
const loadHooks = this.loadHook;
|
|
@@ -1229,9 +1317,11 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
1229
1317
|
if (!moduleDef) {
|
|
1230
1318
|
throw new LoaderError(FAIL_INSTANTIATE, [resolvedId]);
|
|
1231
1319
|
}
|
|
1320
|
+
this.profiler.logOperationEnd({ id: MODULE_FETCH, specifier });
|
|
1232
1321
|
return moduleDef;
|
|
1233
1322
|
})
|
|
1234
1323
|
.catch((e) => {
|
|
1324
|
+
this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
|
|
1235
1325
|
throw e;
|
|
1236
1326
|
});
|
|
1237
1327
|
}
|
|
@@ -1293,6 +1383,7 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
1293
1383
|
constructor(config) {
|
|
1294
1384
|
let baseUrl = config.baseUrl;
|
|
1295
1385
|
const mappingEndpoint = config.endpoints ? config.endpoints.uris.mapping : undefined;
|
|
1386
|
+
let profiler = config.profiler;
|
|
1296
1387
|
if (!mappingEndpoint) {
|
|
1297
1388
|
throw new LoaderError(NO_MAPPING_URL);
|
|
1298
1389
|
}
|
|
@@ -1308,10 +1399,23 @@ LWR.define('lwr/loader/v/0_5_11-alpha_2', ['exports'], function (exports) { 'use
|
|
|
1308
1399
|
if (!baseUrl) {
|
|
1309
1400
|
throw new LoaderError(NO_BASE_URL);
|
|
1310
1401
|
}
|
|
1311
|
-
|
|
1402
|
+
if (!profiler) {
|
|
1403
|
+
// default noop profiler
|
|
1404
|
+
profiler = {
|
|
1405
|
+
logOperationStart: () => {
|
|
1406
|
+
/* noop */
|
|
1407
|
+
},
|
|
1408
|
+
logOperationEnd: () => {
|
|
1409
|
+
/* noop */
|
|
1410
|
+
},
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
this.registry = new ModuleRegistry(Object.freeze({ endpoints: config.endpoints, baseUrl, profiler }));
|
|
1414
|
+
// TODO: https://github.com/salesforce/lwr/issues/1087
|
|
1312
1415
|
this.services = Object.freeze({
|
|
1313
1416
|
addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
|
|
1314
1417
|
handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
|
|
1418
|
+
appMetadata: config.appMetadata,
|
|
1315
1419
|
});
|
|
1316
1420
|
}
|
|
1317
1421
|
/**
|