@lwrjs/everywhere 0.10.0-alpha.4 → 0.10.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/__generated_site_amd_modules__/1/application/amd/l/en-US/ai/amd-bootstrap/configuration/ci/-/-/s/7b0c61d0b2d8909f14cb1696902a019c/config.js +10 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/@lwrjs/app-service/amd-bootstrap/module/amd/v/{0_10_0-alpha_4 → 0_10_0-alpha_7}/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js +5 -5
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwc/v/2_38_1/s/8cf6b94d9c0b398c70c97fdca2759caa/lwc.js +2 -2
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/everywhereAmd/v/{0_10_0-alpha_4 → 0_10_0-alpha_7}/s/c538071acf5bde58e816967a14c465c3/lwr_everywhereAmd.js +4 -4
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/init/v/{0_10_0-alpha_4/s/40ee427a297bdafb395afc6780a220ca → 0_10_0-alpha_7/s/d26177a61a766e129dee91ebcadb74d7}/lwr_init.js +36 -7
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/loader/v/{0_10_0-alpha_4/s/e2d690cbeb4c1efcceba285be35492db → 0_10_0-alpha_7/s/554e119a3f34b1362ff4ceb3a97b0d25}/lwr_loader.js +74 -11
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/metrics/v/{0_10_0-alpha_4 → 0_10_0-alpha_7}/s/3426e42c3e22ce07ab2adc62c4c523a0/lwr_metrics.js +2 -2
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/profiler/v/{0_10_0-alpha_4/s/e25f3b0b8b5c096acebf847d0a83ea62 → 0_10_0-alpha_7/s/4e65d4b97b3cc3d2f06a4cc284f3dd68}/lwr_profiler.js +5 -5
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/vault/v/{0_10_0-alpha_4 → 0_10_0-alpha_7}/s/c92abd8c1fec2d7eff62e4b097abbe14/lwr_vault.js +2 -2
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-error-shim.js/v/{0_10_0-alpha_4 → 0_10_0-alpha_7}/lwr-error-shim.js +2 -1
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-loader-shim.bundle.js/v/{0_10_0-alpha_4 → 0_10_0-alpha_7}/lwr-loader-shim.bundle.js +510 -246
- package/build/assets/amd/lwr-everywhere-debug.js +506 -276
- package/build/assets/amd/lwr-everywhere-min.js +1 -1
- package/build/assets/amd/lwr-everywhere.js +506 -276
- package/build/assets/core/lwr-everywhere-debug.js +504 -274
- package/build/assets/core/lwr-everywhere-min.js +1 -1
- package/build/assets/core/lwr-everywhere.js +504 -274
- package/build/assets/esm/lwr-everywhere-debug.js +10 -3
- package/build/assets/esm/lwr-everywhere-min.js +1 -1
- package/build/assets/esm/lwr-everywhere.js +10 -3
- package/build/generate.js +4 -9
- package/build/modules/@salesforce/lds-default-luvio/lds-default-luvio.d.ts +3 -3
- package/build/modules/lwr/host/host.js +1 -1
- package/build/modules/lwr/vault/vault.d.ts +1 -1
- package/build/utils.d.ts +1 -1
- package/package.json +8 -8
- package/src/generate.ts +6 -10
- package/build/__generated_site_amd_modules__/1/application/amd/l/en-US/ai/amd-bootstrap/configuration/ci/-/-/s/a5fe072e90fba19b6824bf2df53a28b6/config.js +0 -10
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
function getConfiguration(options) {
|
|
10
10
|
const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
|
|
11
11
|
const thisUrl = new URL(import.meta.url);
|
|
12
|
+
|
|
12
13
|
// URLs
|
|
13
14
|
const ORIGIN = server || thisUrl.origin || '';
|
|
14
15
|
const PREFIX = `${apiPrefix}/${apiVersion}`;
|
|
@@ -17,9 +18,11 @@ function getConfiguration(options) {
|
|
|
17
18
|
const ENDPOINT = bundle
|
|
18
19
|
? `${ORIGIN}${PREFIX}/bundle/${format}/${POSTFIX}${BUNDLE_ID}-0/module/mi/`
|
|
19
20
|
: `${ORIGIN}${PREFIX}/module/${format}/${POSTFIX}/mi/`;
|
|
21
|
+
|
|
20
22
|
// Component specifiers and URIs
|
|
21
|
-
const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_10_0-
|
|
23
|
+
const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_10_0-alpha_7`;
|
|
22
24
|
const BOOT_URI = `${ENDPOINT}${encodeURIComponent(BOOT_MODULE)}/latest${debug ? '?debug' : ''}`;
|
|
25
|
+
|
|
23
26
|
// Client Bootstrap Config
|
|
24
27
|
const config = {
|
|
25
28
|
appId: 'lwre',
|
|
@@ -39,6 +42,7 @@ function getConfiguration(options) {
|
|
|
39
42
|
if (debug && config.endpoints) {
|
|
40
43
|
config.endpoints.modifiers = { debug: 'true' };
|
|
41
44
|
}
|
|
45
|
+
|
|
42
46
|
return config;
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -48,7 +52,7 @@ function getConfiguration(options) {
|
|
|
48
52
|
* SPDX-License-Identifier: MIT
|
|
49
53
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
50
54
|
*/
|
|
51
|
-
/* LWR Module Loader v0.10.0-alpha.
|
|
55
|
+
/* LWR Module Loader v0.10.0-alpha.7 */
|
|
52
56
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
53
57
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
58
|
function templateString(template, args) {
|
|
@@ -62,17 +66,26 @@ function generateErrorMessage(errorInfo, args) {
|
|
|
62
66
|
const message = Array.isArray(args) ? templateString(errorInfo.message, args) : errorInfo.message;
|
|
63
67
|
return `LWR${errorInfo.code}: ${message}`;
|
|
64
68
|
}
|
|
69
|
+
|
|
65
70
|
class LoaderError extends Error {
|
|
66
71
|
constructor(errorInfo, errorArgs) {
|
|
67
72
|
super();
|
|
68
73
|
this.message = generateErrorMessage(errorInfo, errorArgs);
|
|
69
74
|
}
|
|
70
75
|
}
|
|
76
|
+
|
|
71
77
|
function invariant(condition, errorInfo) {
|
|
72
78
|
if (!condition) {
|
|
73
79
|
throw new LoaderError(errorInfo);
|
|
74
80
|
}
|
|
75
81
|
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
76
89
|
const MISSING_NAME = Object.freeze({
|
|
77
90
|
code: 3000,
|
|
78
91
|
message: 'A module name is required.',
|
|
@@ -163,6 +176,7 @@ const BAD_IMPORT_METADATA = Object.freeze({
|
|
|
163
176
|
level: 0,
|
|
164
177
|
message: 'Invalid import metadata: {0} {1}',
|
|
165
178
|
});
|
|
179
|
+
|
|
166
180
|
/* importMap errors */
|
|
167
181
|
Object.freeze({
|
|
168
182
|
code: 3011,
|
|
@@ -172,7 +186,9 @@ Object.freeze({
|
|
|
172
186
|
|
|
173
187
|
/* eslint-disable lwr/no-unguarded-apis */
|
|
174
188
|
const hasDocument = typeof document !== 'undefined';
|
|
189
|
+
|
|
175
190
|
const hasSetTimeout = typeof setTimeout === 'function';
|
|
191
|
+
|
|
176
192
|
const hasConsole = typeof console !== 'undefined';
|
|
177
193
|
/* eslint-enable lwr/no-unguarded-apis */
|
|
178
194
|
|
|
@@ -180,7 +196,7 @@ function getBaseUrl() {
|
|
|
180
196
|
let baseUrl = undefined;
|
|
181
197
|
if (hasDocument) {
|
|
182
198
|
// eslint-disable-next-line lwr/no-unguarded-apis, no-undef
|
|
183
|
-
const baseEl = document.querySelector('base[href]');
|
|
199
|
+
const baseEl = document.querySelector('base[href]') ;
|
|
184
200
|
baseUrl = baseEl && baseEl.href;
|
|
185
201
|
}
|
|
186
202
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
@@ -192,8 +208,10 @@ function getBaseUrl() {
|
|
|
192
208
|
baseUrl = baseUrl.slice(0, lastSepIndex + 1);
|
|
193
209
|
}
|
|
194
210
|
}
|
|
211
|
+
|
|
195
212
|
return baseUrl;
|
|
196
213
|
}
|
|
214
|
+
|
|
197
215
|
/**
|
|
198
216
|
* Check if a string is a URL based on Common Internet Scheme Syntax
|
|
199
217
|
* https://www.ietf.org/rfc/rfc1738.txt
|
|
@@ -220,24 +238,26 @@ function getBaseUrl() {
|
|
|
220
238
|
function isUrl(url) {
|
|
221
239
|
return url.indexOf('://') !== -1;
|
|
222
240
|
}
|
|
241
|
+
|
|
223
242
|
// Borrowed and adapted from https://github.com/systemjs/systemjs/blob/master/src/common.js
|
|
224
243
|
// Resolves the first path segment relative to the second/parent URL
|
|
225
244
|
// eg: resolveIfNotPlainOrUrl('../test', 'http://www.site.com/one/two') => 'http://www.site.com/test'
|
|
226
245
|
// eg: resolveIfNotPlainOrUrl('./x/y/z', 'https://my.com/segment')).toBe('https://my.com/x/y/z')
|
|
227
246
|
function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
228
247
|
const backslashRegEx = /\\/g;
|
|
229
|
-
if (relUrl.indexOf('\\') !== -1)
|
|
230
|
-
relUrl = relUrl.replace(backslashRegEx, '/');
|
|
248
|
+
if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
|
|
231
249
|
// protocol-relative
|
|
232
250
|
if (relUrl[0] === '/' && relUrl[1] === '/') {
|
|
233
251
|
return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
|
|
234
252
|
}
|
|
235
253
|
// relative-url
|
|
236
|
-
else if (
|
|
237
|
-
(relUrl[
|
|
238
|
-
(relUrl[1] === '
|
|
239
|
-
|
|
240
|
-
|
|
254
|
+
else if (
|
|
255
|
+
(relUrl[0] === '.' &&
|
|
256
|
+
(relUrl[1] === '/' ||
|
|
257
|
+
(relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
|
|
258
|
+
(relUrl.length === 1 && (relUrl += '/')))) ||
|
|
259
|
+
relUrl[0] === '/'
|
|
260
|
+
) {
|
|
241
261
|
const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
|
|
242
262
|
let pathname;
|
|
243
263
|
if (parentUrl[parentProtocol.length + 1] === '/') {
|
|
@@ -245,21 +265,23 @@ function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
|
245
265
|
if (parentProtocol !== 'file:') {
|
|
246
266
|
pathname = parentUrl.slice(parentProtocol.length + 2);
|
|
247
267
|
pathname = pathname.slice(pathname.indexOf('/') + 1);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
268
|
+
} else {
|
|
250
269
|
pathname = parentUrl.slice(8);
|
|
251
270
|
}
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
271
|
+
} else {
|
|
254
272
|
// resolving to :/ so pathname is the /... part
|
|
255
|
-
pathname = parentUrl.slice(
|
|
273
|
+
pathname = parentUrl.slice(
|
|
274
|
+
parentProtocol.length + (parentUrl[parentProtocol.length] === '/' ? 1 : 0),
|
|
275
|
+
);
|
|
256
276
|
}
|
|
257
|
-
|
|
258
|
-
|
|
277
|
+
|
|
278
|
+
if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
|
|
279
|
+
|
|
259
280
|
// join together and split for removal of .. and . segments
|
|
260
281
|
// looping the string instead of anything fancy for perf reasons
|
|
261
282
|
// '../../../../../z' resolved to 'x/y' is just 'z'
|
|
262
283
|
const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
|
|
284
|
+
|
|
263
285
|
const output = [];
|
|
264
286
|
let segmentIndex = -1;
|
|
265
287
|
for (let i = 0; i < segmented.length; i++) {
|
|
@@ -270,6 +292,7 @@ function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
|
270
292
|
segmentIndex = -1;
|
|
271
293
|
}
|
|
272
294
|
}
|
|
295
|
+
|
|
273
296
|
// new segment - check if it is relative
|
|
274
297
|
else if (segmented[i] === '.') {
|
|
275
298
|
// ../ segment
|
|
@@ -280,8 +303,7 @@ function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
|
280
303
|
// ./ segment
|
|
281
304
|
else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
|
|
282
305
|
i += 1;
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
306
|
+
} else {
|
|
285
307
|
// the start of a new segment as below
|
|
286
308
|
segmentIndex = i;
|
|
287
309
|
}
|
|
@@ -292,13 +314,14 @@ function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
|
|
|
292
314
|
}
|
|
293
315
|
}
|
|
294
316
|
// finish reading out the last segment
|
|
295
|
-
if (segmentIndex !== -1)
|
|
296
|
-
output.push(segmented.slice(segmentIndex));
|
|
317
|
+
if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
|
|
297
318
|
return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
|
|
298
319
|
}
|
|
299
320
|
}
|
|
321
|
+
|
|
300
322
|
function resolveUrl(relUrl, parentUrl) {
|
|
301
|
-
const resolvedUrl =
|
|
323
|
+
const resolvedUrl =
|
|
324
|
+
resolveIfNotPlainOrUrl(relUrl, parentUrl) ||
|
|
302
325
|
(isUrl(relUrl) ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
|
|
303
326
|
return resolvedUrl;
|
|
304
327
|
}
|
|
@@ -311,6 +334,7 @@ function createScript(url) {
|
|
|
311
334
|
script.src = url;
|
|
312
335
|
return script;
|
|
313
336
|
}
|
|
337
|
+
|
|
314
338
|
let lastWindowError$1, lastWindowErrorUrl;
|
|
315
339
|
function loadModuleDef(url) {
|
|
316
340
|
return new Promise(function (resolve, reject) {
|
|
@@ -324,8 +348,7 @@ function loadModuleDef(url) {
|
|
|
324
348
|
document.head.removeChild(script);
|
|
325
349
|
if (lastWindowErrorUrl === url) {
|
|
326
350
|
reject(lastWindowError$1);
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
351
|
+
} else {
|
|
329
352
|
resolve();
|
|
330
353
|
}
|
|
331
354
|
});
|
|
@@ -334,6 +357,7 @@ function loadModuleDef(url) {
|
|
|
334
357
|
}
|
|
335
358
|
});
|
|
336
359
|
}
|
|
360
|
+
|
|
337
361
|
if (hasDocument) {
|
|
338
362
|
// When a script is executed, runtime errors are on the global/window scope which are NOT caught by the script's onerror handler.
|
|
339
363
|
// eslint-disable-next-line lwr/no-unguarded-apis, no-undef
|
|
@@ -357,44 +381,53 @@ const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
|
|
|
357
381
|
|
|
358
382
|
/* spec based import map resolver */
|
|
359
383
|
class ImportMetadataResolver {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
384
|
+
// Default to empty mappings
|
|
385
|
+
__init() {this.importURICache = new Map();}
|
|
386
|
+
__init2() {this.pendingURICache = new Map();}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
__init3() {this.loadMappingHooks = [];}
|
|
390
|
+
|
|
391
|
+
constructor(config, invalidationCallback) {ImportMetadataResolver.prototype.__init.call(this);ImportMetadataResolver.prototype.__init2.call(this);ImportMetadataResolver.prototype.__init3.call(this);
|
|
365
392
|
this.config = config;
|
|
366
393
|
this.invalidationCallback = invalidationCallback;
|
|
367
394
|
}
|
|
395
|
+
|
|
368
396
|
addLoadMappingHook(hook) {
|
|
369
397
|
this.loadMappingHooks.push(hook);
|
|
370
398
|
}
|
|
399
|
+
|
|
371
400
|
getMappingEndpoint() {
|
|
372
401
|
return this.config.endpoints && this.config.endpoints.uris
|
|
373
402
|
? this.config.endpoints.uris.mapping
|
|
374
403
|
: undefined;
|
|
375
404
|
}
|
|
405
|
+
|
|
376
406
|
getModifiersAsUrlParams() {
|
|
377
407
|
const modifiers = this.config.endpoints ? this.config.endpoints.modifiers : undefined;
|
|
408
|
+
|
|
378
409
|
if (!modifiers) {
|
|
379
410
|
// No modifiers return an empty string to append to the URL
|
|
380
411
|
return '';
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
412
|
+
} else {
|
|
383
413
|
const qs = Object.keys(modifiers)
|
|
384
414
|
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(modifiers[key])}`)
|
|
385
415
|
.join('&');
|
|
386
416
|
return `?${qs}`;
|
|
387
417
|
}
|
|
388
418
|
}
|
|
419
|
+
|
|
389
420
|
buildMappingUrl(specifier) {
|
|
390
421
|
const mappingEndpoint = this.getMappingEndpoint();
|
|
391
422
|
const specifiers = encodeURIComponent(specifier);
|
|
392
423
|
const modifiers = this.getModifiersAsUrlParams();
|
|
393
424
|
return `${mappingEndpoint}${specifiers}${modifiers}`;
|
|
394
425
|
}
|
|
426
|
+
|
|
395
427
|
getBaseUrl() {
|
|
396
428
|
return this.config.baseUrl;
|
|
397
429
|
}
|
|
430
|
+
|
|
398
431
|
registerImportMappings(newImportMetadata, rootSpecifiers) {
|
|
399
432
|
if (!rootSpecifiers || rootSpecifiers.length === 0) {
|
|
400
433
|
const imports = newImportMetadata ? JSON.stringify(newImportMetadata) : 'undefined';
|
|
@@ -416,8 +449,7 @@ class ImportMetadataResolver {
|
|
|
416
449
|
const existing = this.importURICache.get(specifier);
|
|
417
450
|
if (!existing) {
|
|
418
451
|
this.saveImportURIRecord(specifier, uri, indexValue, rootSpecifiers.includes(specifier));
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
452
|
+
} else {
|
|
421
453
|
const identity = indexValue || uri;
|
|
422
454
|
const existingIdentity = existing.identity || existing.uri;
|
|
423
455
|
if (existingIdentity !== identity) {
|
|
@@ -431,22 +463,24 @@ class ImportMetadataResolver {
|
|
|
431
463
|
});
|
|
432
464
|
}
|
|
433
465
|
}
|
|
466
|
+
|
|
434
467
|
// Get URL from the local cache or return undefiend
|
|
435
|
-
|
|
468
|
+
getURI(specifier) {
|
|
436
469
|
return this.importURICache.has(specifier)
|
|
437
470
|
? resolveUrl(this.importURICache.get(specifier).uri, this.getBaseUrl())
|
|
438
471
|
: undefined;
|
|
439
472
|
}
|
|
473
|
+
|
|
440
474
|
resolveLocal(specifier) {
|
|
441
475
|
const uri = this.getURI(specifier);
|
|
442
476
|
if (uri) {
|
|
443
477
|
return uri;
|
|
444
|
-
}
|
|
445
|
-
else if (isUrl(specifier) || specifier.startsWith('/')) {
|
|
478
|
+
} else if (isUrl(specifier) || specifier.startsWith('/')) {
|
|
446
479
|
return specifier;
|
|
447
480
|
}
|
|
448
481
|
return undefined;
|
|
449
482
|
}
|
|
483
|
+
|
|
450
484
|
/**
|
|
451
485
|
* Resolves a the URI for a specified module. It will return the value in this order:
|
|
452
486
|
*
|
|
@@ -461,15 +495,14 @@ class ImportMetadataResolver {
|
|
|
461
495
|
let uri = this.getURI(specifier);
|
|
462
496
|
if (uri) {
|
|
463
497
|
return uri;
|
|
464
|
-
}
|
|
465
|
-
else if (isUrl(specifier) || specifier.startsWith('/')) {
|
|
498
|
+
} else if (isUrl(specifier) || specifier.startsWith('/')) {
|
|
466
499
|
return specifier;
|
|
467
|
-
}
|
|
468
|
-
else {
|
|
500
|
+
} else {
|
|
469
501
|
const pending = this.pendingURICache.get(specifier);
|
|
470
502
|
if (pending) {
|
|
471
503
|
return pending;
|
|
472
504
|
}
|
|
505
|
+
|
|
473
506
|
this.config.profiler.logOperationStart({ id: MAPPINGS_FETCH, specifier });
|
|
474
507
|
const fetchMappingService = this.hasMappingHooks()
|
|
475
508
|
? this.evaluateMappingHooks
|
|
@@ -477,33 +510,37 @@ class ImportMetadataResolver {
|
|
|
477
510
|
const promise = fetchMappingService
|
|
478
511
|
.bind(this)(specifier)
|
|
479
512
|
.then((importMetadata) => {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
513
|
+
if (!importMetadata || !importMetadata.imports) {
|
|
514
|
+
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
515
|
+
}
|
|
516
|
+
this.registerImportMappings(importMetadata, [specifier]);
|
|
517
|
+
uri = this.getURI(specifier);
|
|
518
|
+
if (!uri) {
|
|
519
|
+
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
this.config.profiler.logOperationEnd({ id: MAPPINGS_FETCH, specifier });
|
|
523
|
+
return uri;
|
|
524
|
+
})
|
|
491
525
|
.finally(() => {
|
|
492
|
-
|
|
493
|
-
|
|
526
|
+
this.pendingURICache.delete(specifier);
|
|
527
|
+
});
|
|
528
|
+
|
|
494
529
|
this.pendingURICache.set(specifier, promise);
|
|
495
530
|
return promise;
|
|
496
531
|
}
|
|
497
532
|
}
|
|
498
|
-
|
|
533
|
+
|
|
534
|
+
hasMappingHooks() {
|
|
499
535
|
return this.loadMappingHooks.length > 0;
|
|
500
536
|
}
|
|
537
|
+
|
|
501
538
|
/**
|
|
502
539
|
* Evaluates mapping hooks. Returns first match. If all hooks return null call the mapping service.
|
|
503
540
|
* @param specifier Request module identifier
|
|
504
541
|
* @returns Import Metadata from the module root
|
|
505
542
|
*/
|
|
506
|
-
|
|
543
|
+
async evaluateMappingHooks(specifier) {
|
|
507
544
|
// Check with any registered loadMappingHooks
|
|
508
545
|
const loadMappingHooks = this.loadMappingHooks;
|
|
509
546
|
if (loadMappingHooks.length) {
|
|
@@ -518,13 +555,16 @@ class ImportMetadataResolver {
|
|
|
518
555
|
}
|
|
519
556
|
}
|
|
520
557
|
}
|
|
558
|
+
|
|
521
559
|
// If we still do not have a match call the mapping service
|
|
522
560
|
return this.fetchNewMappings(specifier);
|
|
523
561
|
}
|
|
524
|
-
|
|
562
|
+
|
|
563
|
+
async fetchNewMappings(specifier) {
|
|
525
564
|
if (typeof globalThis.fetch !== 'function') {
|
|
526
565
|
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
527
566
|
}
|
|
567
|
+
|
|
528
568
|
// TODO For module invalidation with bundles it is recommended we have to send back all loaded root specified
|
|
529
569
|
// to ensure we detect all conflicts.
|
|
530
570
|
const uri = resolveUrl(this.buildMappingUrl(specifier), this.getBaseUrl());
|
|
@@ -536,21 +576,21 @@ class ImportMetadataResolver {
|
|
|
536
576
|
return res
|
|
537
577
|
.json()
|
|
538
578
|
.then((ret) => {
|
|
539
|
-
|
|
540
|
-
|
|
579
|
+
return ret ;
|
|
580
|
+
})
|
|
541
581
|
.catch((err) => {
|
|
542
|
-
|
|
543
|
-
|
|
582
|
+
throw new LoaderError(UNRESOLVED, [specifier]);
|
|
583
|
+
});
|
|
544
584
|
});
|
|
545
585
|
}
|
|
546
|
-
|
|
586
|
+
|
|
587
|
+
saveImportURIRecord(specifier, uri, identity, isRoot) {
|
|
547
588
|
if (!identity || uri === identity) {
|
|
548
589
|
this.importURICache.set(specifier, {
|
|
549
590
|
uri,
|
|
550
591
|
isRoot: isRoot,
|
|
551
592
|
});
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
593
|
+
} else {
|
|
554
594
|
this.importURICache.set(specifier, {
|
|
555
595
|
uri,
|
|
556
596
|
identity,
|
|
@@ -563,11 +603,13 @@ class ImportMetadataResolver {
|
|
|
563
603
|
function reportError(error) {
|
|
564
604
|
// TODO eventually this should be configurable instrumentation to send this somewhere
|
|
565
605
|
// eslint-disable-next-line lwr/no-unguarded-apis, no-undef
|
|
566
|
-
if (hasConsole)
|
|
567
|
-
console.error(error);
|
|
606
|
+
if (hasConsole) console.error(error);
|
|
568
607
|
}
|
|
569
608
|
|
|
570
|
-
function evaluateHandleStaleModuleHooks(
|
|
609
|
+
function evaluateHandleStaleModuleHooks(
|
|
610
|
+
handleStaleModuleHooks,
|
|
611
|
+
hookArgs,
|
|
612
|
+
) {
|
|
571
613
|
const { name, oldUrl, newUrl } = hookArgs;
|
|
572
614
|
// keep evaluating hooks if return value is null
|
|
573
615
|
for (let i = 0; i < handleStaleModuleHooks.length; i++) {
|
|
@@ -577,8 +619,7 @@ function evaluateHandleStaleModuleHooks(handleStaleModuleHooks, hookArgs) {
|
|
|
577
619
|
if (hookResult !== null) {
|
|
578
620
|
break;
|
|
579
621
|
}
|
|
580
|
-
}
|
|
581
|
-
catch (e) {
|
|
622
|
+
} catch (e) {
|
|
582
623
|
reportError(new LoaderError(STALE_HOOK_ERROR));
|
|
583
624
|
}
|
|
584
625
|
}
|
|
@@ -587,29 +628,45 @@ function evaluateHandleStaleModuleHooks(handleStaleModuleHooks, hookArgs) {
|
|
|
587
628
|
const MODULE_LOAD_TIMEOUT_TIMER = 300000;
|
|
588
629
|
|
|
589
630
|
/* global console,process */
|
|
631
|
+
|
|
632
|
+
|
|
590
633
|
let lastWindowError;
|
|
591
634
|
if (hasDocument) {
|
|
592
635
|
globalThis.addEventListener('error', (evt) => {
|
|
593
636
|
lastWindowError = evt.error;
|
|
594
637
|
});
|
|
595
638
|
}
|
|
639
|
+
|
|
596
640
|
if (process.env.NODE_ENV !== 'production') {
|
|
597
641
|
if (!hasSetTimeout && hasConsole) {
|
|
598
642
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
599
643
|
console.warn('setTimeout API is not available, watchdog timer on load hook will not be set');
|
|
600
644
|
}
|
|
601
645
|
}
|
|
646
|
+
|
|
602
647
|
function isCustomResponse(response) {
|
|
603
|
-
return (
|
|
604
|
-
|
|
648
|
+
return (
|
|
649
|
+
Object.prototype.hasOwnProperty.call(response, 'data') &&
|
|
650
|
+
!Object.prototype.hasOwnProperty.call(response, 'blob')
|
|
651
|
+
);
|
|
605
652
|
}
|
|
606
|
-
function isFetchResponse(
|
|
653
|
+
function isFetchResponse(
|
|
654
|
+
response,
|
|
655
|
+
) {
|
|
607
656
|
// if it quacks like a duck...
|
|
608
|
-
return typeof response.blob === 'function';
|
|
657
|
+
return typeof (response ).blob === 'function';
|
|
609
658
|
}
|
|
610
|
-
|
|
611
|
-
|
|
659
|
+
|
|
660
|
+
function isResponseAPromise(
|
|
661
|
+
response
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
,
|
|
666
|
+
) {
|
|
667
|
+
return !!(response && (response ).then);
|
|
612
668
|
}
|
|
669
|
+
|
|
613
670
|
async function evaluateLoadHookResponse(response, id) {
|
|
614
671
|
return Promise.resolve().then(async () => {
|
|
615
672
|
if (!response.status) {
|
|
@@ -618,36 +675,41 @@ async function evaluateLoadHookResponse(response, id) {
|
|
|
618
675
|
if (response.status !== 200) {
|
|
619
676
|
throw new LoaderError(HTTP_FAIL_LOAD, [id, `${response.status}`]);
|
|
620
677
|
}
|
|
678
|
+
|
|
621
679
|
const isResponse = isFetchResponse(response);
|
|
622
680
|
let code;
|
|
623
681
|
if (isCustomResponse(response)) {
|
|
624
682
|
code = response.data;
|
|
625
|
-
}
|
|
626
|
-
else if (isResponse) {
|
|
683
|
+
} else if (isResponse) {
|
|
627
684
|
// handle fetch response
|
|
628
|
-
code = await response.text();
|
|
629
|
-
}
|
|
630
|
-
else {
|
|
685
|
+
code = await (response ).text();
|
|
686
|
+
} else {
|
|
631
687
|
throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
|
|
632
688
|
}
|
|
689
|
+
|
|
633
690
|
if (!code) {
|
|
634
691
|
throw new LoaderError(FAIL_LOAD, [id]);
|
|
635
692
|
}
|
|
693
|
+
|
|
636
694
|
code = `${code}\n//# sourceURL=${id}`; // append sourceURL for debugging
|
|
637
695
|
try {
|
|
638
696
|
// TODO eval source maps for debugging
|
|
639
697
|
eval(code);
|
|
640
|
-
}
|
|
641
|
-
catch (e) {
|
|
698
|
+
} catch (e) {
|
|
642
699
|
throw new LoaderError(FAIL_LOAD, [id]);
|
|
643
700
|
}
|
|
701
|
+
|
|
644
702
|
if (lastWindowError) {
|
|
645
703
|
throw new LoaderError(FAIL_LOAD, [id]);
|
|
646
704
|
}
|
|
647
705
|
return true;
|
|
648
706
|
});
|
|
649
707
|
}
|
|
650
|
-
|
|
708
|
+
|
|
709
|
+
async function evaluateLoadHook(
|
|
710
|
+
id,
|
|
711
|
+
hookPromise,
|
|
712
|
+
) {
|
|
651
713
|
if (!hasSetTimeout) {
|
|
652
714
|
return hookPromise;
|
|
653
715
|
}
|
|
@@ -659,45 +721,91 @@ async function evaluateLoadHook(id, hookPromise) {
|
|
|
659
721
|
}, MODULE_LOAD_TIMEOUT_TIMER);
|
|
660
722
|
hookPromise
|
|
661
723
|
.then((response) => {
|
|
662
|
-
|
|
663
|
-
|
|
724
|
+
resolve(response);
|
|
725
|
+
})
|
|
664
726
|
.catch(() => {
|
|
665
|
-
|
|
666
|
-
|
|
727
|
+
reject(new LoaderError(FAIL_HOOK_LOAD, [id]));
|
|
728
|
+
})
|
|
667
729
|
.finally(() => {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
730
|
+
// eslint-disable-next-line lwr/no-unguarded-apis, no-undef
|
|
731
|
+
clearTimeout(timer);
|
|
732
|
+
});
|
|
671
733
|
});
|
|
672
734
|
}
|
|
673
735
|
|
|
674
736
|
/* global console,process */
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
675
782
|
class ModuleRegistry {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
680
|
-
this.moduleRegistry = new Map();
|
|
681
|
-
// Aliases of modules in the registry
|
|
682
|
-
this.aliases = new Map();
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);
|
|
683
786
|
this.profiler = config.profiler;
|
|
684
|
-
this.resolver = new ImportMetadataResolver(
|
|
787
|
+
this.resolver = new ImportMetadataResolver(
|
|
788
|
+
config,
|
|
789
|
+
this.importMetadataInvalidationCallback.bind(this),
|
|
790
|
+
);
|
|
685
791
|
}
|
|
792
|
+
|
|
686
793
|
async load(id, importer) {
|
|
687
794
|
const resolvedId = await this.resolve(id, importer);
|
|
688
795
|
const moduleRecord = this.getModuleRecord(resolvedId, id);
|
|
689
796
|
if (moduleRecord.evaluated) {
|
|
690
797
|
return moduleRecord.module;
|
|
691
|
-
}
|
|
692
|
-
else {
|
|
798
|
+
} else {
|
|
693
799
|
if (!moduleRecord.evaluationPromise) {
|
|
694
800
|
moduleRecord.evaluationPromise = this.topLevelEvaluation(moduleRecord);
|
|
695
801
|
}
|
|
696
802
|
return moduleRecord.evaluationPromise;
|
|
697
803
|
}
|
|
698
804
|
}
|
|
805
|
+
|
|
699
806
|
async resolve(id, importer) {
|
|
700
807
|
const parentUrl = this.resolver.getBaseUrl(); // only support baseUrl for now
|
|
808
|
+
|
|
701
809
|
let resolved;
|
|
702
810
|
let aliasedId = id;
|
|
703
811
|
const resolveHooks = this.resolveHook;
|
|
@@ -710,6 +818,7 @@ class ModuleRegistry {
|
|
|
710
818
|
// eslint-disable-next-line no-await-in-loop
|
|
711
819
|
result = isResponseAPromise(response) ? await response : response;
|
|
712
820
|
}
|
|
821
|
+
|
|
713
822
|
// if result is not null, attempt resolution
|
|
714
823
|
if (result !== null) {
|
|
715
824
|
if (typeof result === 'string') {
|
|
@@ -720,6 +829,7 @@ class ModuleRegistry {
|
|
|
720
829
|
aliasedId = result; // the next hook will receive the new id
|
|
721
830
|
continue;
|
|
722
831
|
}
|
|
832
|
+
|
|
723
833
|
resolved =
|
|
724
834
|
result && result.url && (resolveIfNotPlainOrUrl(result.url, parentUrl) || result.url);
|
|
725
835
|
if (!resolved) {
|
|
@@ -729,27 +839,32 @@ class ModuleRegistry {
|
|
|
729
839
|
break;
|
|
730
840
|
}
|
|
731
841
|
}
|
|
842
|
+
|
|
732
843
|
if (aliasedId !== id) {
|
|
733
844
|
// resolved module id is the aliased module if it has already been defined
|
|
734
845
|
if (!resolved && this.namedDefineRegistry.has(aliasedId)) {
|
|
735
846
|
return aliasedId;
|
|
736
|
-
}
|
|
737
|
-
else {
|
|
847
|
+
} else {
|
|
738
848
|
id = aliasedId;
|
|
739
849
|
}
|
|
740
850
|
}
|
|
741
851
|
}
|
|
852
|
+
|
|
742
853
|
if (!resolved) {
|
|
743
854
|
const resolvedOrPlain = resolveIfNotPlainOrUrl(id, parentUrl) || id;
|
|
855
|
+
|
|
744
856
|
// if module registry already has named module the resolved id is the plain id
|
|
745
857
|
if (this.moduleRegistry.has(resolvedOrPlain)) {
|
|
746
858
|
return resolvedOrPlain;
|
|
747
859
|
}
|
|
860
|
+
|
|
748
861
|
const resolvedUrl = this.resolver.resolveLocal(resolvedOrPlain);
|
|
749
862
|
if (resolvedUrl) {
|
|
750
863
|
// return the plain id if it is already defined && the resolvedUrl is NOT already in the module registry
|
|
751
|
-
if (
|
|
752
|
-
this.namedDefineRegistry.
|
|
864
|
+
if (
|
|
865
|
+
this.namedDefineRegistry.has(resolvedOrPlain) &&
|
|
866
|
+
this.namedDefineRegistry.get(resolvedOrPlain).defined
|
|
867
|
+
) {
|
|
753
868
|
const record = this.moduleRegistry.get(resolvedUrl);
|
|
754
869
|
if (!record || !this.aliases.has(resolvedOrPlain)) {
|
|
755
870
|
return resolvedOrPlain;
|
|
@@ -757,13 +872,13 @@ class ModuleRegistry {
|
|
|
757
872
|
}
|
|
758
873
|
return resolvedUrl;
|
|
759
874
|
}
|
|
875
|
+
|
|
760
876
|
if (this.namedDefineRegistry.has(resolvedOrPlain)) {
|
|
761
877
|
return resolvedOrPlain;
|
|
762
878
|
}
|
|
763
879
|
try {
|
|
764
880
|
resolved = await this.resolver.resolve(resolvedOrPlain);
|
|
765
|
-
}
|
|
766
|
-
catch (e) {
|
|
881
|
+
} catch (e) {
|
|
767
882
|
// defer to error handling below for unresolved
|
|
768
883
|
}
|
|
769
884
|
}
|
|
@@ -771,6 +886,7 @@ class ModuleRegistry {
|
|
|
771
886
|
if (this.namedDefineRegistry.has(id)) {
|
|
772
887
|
return id;
|
|
773
888
|
}
|
|
889
|
+
|
|
774
890
|
throw new LoaderError(UNRESOLVED, [id]);
|
|
775
891
|
}
|
|
776
892
|
if (importer && isUrl(resolved)) {
|
|
@@ -778,9 +894,11 @@ class ModuleRegistry {
|
|
|
778
894
|
}
|
|
779
895
|
return resolved;
|
|
780
896
|
}
|
|
897
|
+
|
|
781
898
|
has(id) {
|
|
782
899
|
return this.moduleRegistry.has(id);
|
|
783
900
|
}
|
|
901
|
+
|
|
784
902
|
define(name, dependencies, exporter) {
|
|
785
903
|
const mod = this.namedDefineRegistry.get(name);
|
|
786
904
|
// Don't allow redefining a module.
|
|
@@ -792,6 +910,7 @@ class ModuleRegistry {
|
|
|
792
910
|
this.lastDefine = mod;
|
|
793
911
|
return;
|
|
794
912
|
}
|
|
913
|
+
|
|
795
914
|
const moduleDef = {
|
|
796
915
|
name,
|
|
797
916
|
dependencies,
|
|
@@ -802,10 +921,12 @@ class ModuleRegistry {
|
|
|
802
921
|
// if module is "external", resolve the external promise to notify any dependees
|
|
803
922
|
mod.external.resolveExternal(moduleDef);
|
|
804
923
|
}
|
|
924
|
+
|
|
805
925
|
this.profiler.logOperationStart({ id: MODULE_DEFINE, specifier: name });
|
|
806
926
|
this.namedDefineRegistry.set(name, moduleDef);
|
|
807
927
|
this.lastDefine = moduleDef;
|
|
808
928
|
}
|
|
929
|
+
|
|
809
930
|
/**
|
|
810
931
|
* Marks modules as "externally" loaded/provided, so that the loader does not attempt to fetch them.
|
|
811
932
|
*
|
|
@@ -818,6 +939,7 @@ class ModuleRegistry {
|
|
|
818
939
|
let timer;
|
|
819
940
|
const moduleDefPromise = new Promise((resolve, reject) => {
|
|
820
941
|
resolveExternal = resolve;
|
|
942
|
+
|
|
821
943
|
// watch the external for timeout
|
|
822
944
|
// eslint-disable-next-line lwr/no-unguarded-apis, no-undef
|
|
823
945
|
timer = setTimeout(() => {
|
|
@@ -835,24 +957,39 @@ class ModuleRegistry {
|
|
|
835
957
|
moduleDefPromise,
|
|
836
958
|
},
|
|
837
959
|
};
|
|
838
|
-
this.namedDefineRegistry.set(id, moduleDef);
|
|
839
|
-
}
|
|
840
|
-
else if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
960
|
+
this.namedDefineRegistry.set(id, moduleDef );
|
|
961
|
+
} else if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
841
962
|
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
842
963
|
console.warn(MODULE_ALREADY_LOADED.message, id);
|
|
843
964
|
}
|
|
844
965
|
});
|
|
845
966
|
}
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
// A registry for named AMD defines containing the *metadata* of AMD module
|
|
971
|
+
__init() {this.namedDefineRegistry = new Map();}
|
|
972
|
+
|
|
973
|
+
// The evaluated module registry where the module identifier (name or URL?) is the key
|
|
974
|
+
__init2() {this.moduleRegistry = new Map();}
|
|
975
|
+
|
|
976
|
+
// Aliases of modules in the registry
|
|
977
|
+
__init3() {this.aliases = new Map();}
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
846
981
|
getImportMetadataResolver() {
|
|
847
982
|
return this.resolver;
|
|
848
983
|
}
|
|
984
|
+
|
|
849
985
|
// Returns an existing module record by the resolvedId or aliased id
|
|
850
|
-
|
|
986
|
+
getExistingModuleRecord(resolvedId, aliasId) {
|
|
851
987
|
const moduleRecord = this.moduleRegistry.get(resolvedId);
|
|
852
988
|
if (moduleRecord) {
|
|
853
989
|
this.storeModuleAlias(aliasId, resolvedId);
|
|
854
990
|
return moduleRecord;
|
|
855
991
|
}
|
|
992
|
+
|
|
856
993
|
// Check if this is a known alias
|
|
857
994
|
if (resolvedId !== aliasId) {
|
|
858
995
|
const alias = this.aliases.get(aliasId);
|
|
@@ -865,13 +1002,15 @@ class ModuleRegistry {
|
|
|
865
1002
|
}
|
|
866
1003
|
return moduleRecord;
|
|
867
1004
|
}
|
|
868
|
-
|
|
1005
|
+
|
|
1006
|
+
getModuleRecord(resolvedId, id) {
|
|
869
1007
|
// Look for an existing record
|
|
870
1008
|
const existingRecord = this.getExistingModuleRecord(resolvedId, id);
|
|
871
1009
|
if (existingRecord) {
|
|
872
1010
|
// return existing
|
|
873
1011
|
return existingRecord;
|
|
874
1012
|
}
|
|
1013
|
+
|
|
875
1014
|
// Create a new Module Record
|
|
876
1015
|
const instantiation = this.getModuleDef(resolvedId, id);
|
|
877
1016
|
const dependencyRecords = instantiation.then((moduleDef) => {
|
|
@@ -879,15 +1018,17 @@ class ModuleRegistry {
|
|
|
879
1018
|
// get dep and filter out exports
|
|
880
1019
|
const filtered = dependencies
|
|
881
1020
|
.map((dep) => {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
.filter((depRecord) => depRecord !== undefined);
|
|
1021
|
+
if (dep === 'exports') {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
invariant(dep !== 'require', NO_AMD_REQUIRE);
|
|
1025
|
+
return this.getModuleDependencyRecord.call(this, dep);
|
|
1026
|
+
})
|
|
1027
|
+
.filter((depRecord) => depRecord !== undefined) ;
|
|
1028
|
+
|
|
889
1029
|
return Promise.all(filtered);
|
|
890
1030
|
});
|
|
1031
|
+
|
|
891
1032
|
const newModuleRecord = {
|
|
892
1033
|
id: resolvedId,
|
|
893
1034
|
module: Object.create(null),
|
|
@@ -896,16 +1037,17 @@ class ModuleRegistry {
|
|
|
896
1037
|
evaluated: false,
|
|
897
1038
|
evaluationPromise: null,
|
|
898
1039
|
};
|
|
1040
|
+
|
|
899
1041
|
this.moduleRegistry.set(resolvedId, newModuleRecord);
|
|
900
1042
|
this.storeModuleAlias(id, resolvedId);
|
|
901
1043
|
return newModuleRecord;
|
|
902
1044
|
}
|
|
903
|
-
|
|
1045
|
+
|
|
1046
|
+
storeModuleAlias(aliasId, resolvedId) {
|
|
904
1047
|
if (aliasId !== resolvedId) {
|
|
905
1048
|
if (!this.aliases.has(aliasId)) {
|
|
906
1049
|
this.aliases.set(aliasId, resolvedId);
|
|
907
|
-
}
|
|
908
|
-
else if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
1050
|
+
} else if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
909
1051
|
// Warn the user if they were not aliasing to the resolvedId
|
|
910
1052
|
const currentResolvedId = this.aliases.get(aliasId);
|
|
911
1053
|
if (currentResolvedId !== resolvedId) {
|
|
@@ -915,17 +1057,23 @@ class ModuleRegistry {
|
|
|
915
1057
|
}
|
|
916
1058
|
}
|
|
917
1059
|
}
|
|
918
|
-
|
|
1060
|
+
|
|
1061
|
+
async getModuleDependencyRecord(dependency) {
|
|
919
1062
|
const resolvedDepId = await this.resolve(dependency);
|
|
920
1063
|
return this.getModuleRecord(resolvedDepId, dependency);
|
|
921
1064
|
}
|
|
1065
|
+
|
|
922
1066
|
// execute the "top-level code" (the code outside of functions) of a module
|
|
923
|
-
|
|
1067
|
+
async topLevelEvaluation(moduleRecord) {
|
|
924
1068
|
await this.instantiateAll(moduleRecord, {});
|
|
925
1069
|
return this.evaluateModule(moduleRecord, {});
|
|
926
1070
|
}
|
|
1071
|
+
|
|
927
1072
|
// Returns a promise when a module and all of it's dependencies have finished instantiation
|
|
928
|
-
|
|
1073
|
+
async instantiateAll(
|
|
1074
|
+
moduleRecord,
|
|
1075
|
+
instantiatedMap,
|
|
1076
|
+
) {
|
|
929
1077
|
if (!instantiatedMap[moduleRecord.id]) {
|
|
930
1078
|
instantiatedMap[moduleRecord.id] = true;
|
|
931
1079
|
const dependencyModuleRecords = await moduleRecord.dependencyRecords;
|
|
@@ -938,46 +1086,61 @@ class ModuleRegistry {
|
|
|
938
1086
|
}
|
|
939
1087
|
}
|
|
940
1088
|
}
|
|
941
|
-
|
|
1089
|
+
|
|
1090
|
+
async evaluateModule(
|
|
1091
|
+
moduleRecord,
|
|
1092
|
+
evaluationMap,
|
|
1093
|
+
) {
|
|
942
1094
|
const dependencyModuleRecords = await moduleRecord.dependencyRecords;
|
|
943
1095
|
if (dependencyModuleRecords.length > 0) {
|
|
944
1096
|
evaluationMap[moduleRecord.id] = true;
|
|
945
1097
|
// evaluate dependencies first
|
|
946
1098
|
await this.evaluateModuleDependencies(dependencyModuleRecords, evaluationMap);
|
|
947
1099
|
}
|
|
1100
|
+
|
|
948
1101
|
const { exporter, dependencies } = await moduleRecord.instantiation;
|
|
949
1102
|
// The exports object automatically gets filled in by the exporter evaluation
|
|
950
1103
|
const exports = {};
|
|
951
|
-
const depsMapped = await Promise.all(
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1104
|
+
const depsMapped = await Promise.all(
|
|
1105
|
+
dependencies.map(async (dep) => {
|
|
1106
|
+
if (dep === 'exports') {
|
|
1107
|
+
return exports;
|
|
1108
|
+
}
|
|
1109
|
+
const resolvedDepId = await this.resolve(dep);
|
|
1110
|
+
|
|
1111
|
+
const moduleRecord = this.moduleRegistry.get(resolvedDepId) ;
|
|
1112
|
+
if (!moduleRecord) {
|
|
1113
|
+
throw new LoaderError(FAILED_DEP, [resolvedDepId]);
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
const module = moduleRecord.module;
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Circular dependencies are handled properly when named exports are used,
|
|
1120
|
+
* however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
|
|
1121
|
+
*
|
|
1122
|
+
* The workaround below applies for circular dependencies (!moduleRecord.evaluated)
|
|
1123
|
+
*/
|
|
1124
|
+
if (!moduleRecord.evaluated) {
|
|
1125
|
+
return this.getCircularDependencyWrapper(module);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
if (module) {
|
|
1129
|
+
return module.__defaultInterop ? module.default : module;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
958
1132
|
throw new LoaderError(FAILED_DEP, [resolvedDepId]);
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
* Circular dependencies are handled properly when named exports are used,
|
|
963
|
-
* however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
|
|
964
|
-
*
|
|
965
|
-
* The workaround below applies for circular dependencies (!moduleRecord.evaluated)
|
|
966
|
-
*/
|
|
967
|
-
if (!moduleRecord.evaluated) {
|
|
968
|
-
return this.getCircularDependencyWrapper(module);
|
|
969
|
-
}
|
|
970
|
-
if (module) {
|
|
971
|
-
return module.__defaultInterop ? module.default : module;
|
|
972
|
-
}
|
|
973
|
-
throw new LoaderError(FAILED_DEP, [resolvedDepId]);
|
|
974
|
-
}));
|
|
1133
|
+
}),
|
|
1134
|
+
);
|
|
1135
|
+
|
|
975
1136
|
// W-10029836 - In the case where we could be instantiating multiple graphs at the same time lets make sure the module have not already been evaluated
|
|
976
1137
|
if (moduleRecord.evaluated) {
|
|
977
1138
|
return moduleRecord.module;
|
|
978
1139
|
}
|
|
1140
|
+
|
|
979
1141
|
// evaluates the module function
|
|
980
1142
|
let moduleDefault = exporter(...depsMapped);
|
|
1143
|
+
|
|
981
1144
|
// value is returned from exporter, then we are not using named exports
|
|
982
1145
|
if (moduleDefault !== undefined) {
|
|
983
1146
|
moduleDefault = { default: moduleDefault };
|
|
@@ -993,7 +1156,9 @@ class ModuleRegistry {
|
|
|
993
1156
|
Object.defineProperty(exports, '__useDefault', { value: true });
|
|
994
1157
|
}
|
|
995
1158
|
}
|
|
1159
|
+
|
|
996
1160
|
const moduleExports = moduleDefault || exports;
|
|
1161
|
+
|
|
997
1162
|
// update the module record
|
|
998
1163
|
// copy over enumerable public methods to module
|
|
999
1164
|
for (const key in moduleExports) {
|
|
@@ -1007,6 +1172,7 @@ class ModuleRegistry {
|
|
|
1007
1172
|
},
|
|
1008
1173
|
});
|
|
1009
1174
|
}
|
|
1175
|
+
|
|
1010
1176
|
// copy non-enumerable to module
|
|
1011
1177
|
if (moduleExports.__useDefault) {
|
|
1012
1178
|
Object.defineProperty(moduleRecord.module, '__useDefault', { value: true });
|
|
@@ -1017,27 +1183,36 @@ class ModuleRegistry {
|
|
|
1017
1183
|
if (moduleExports.__esModule) {
|
|
1018
1184
|
Object.defineProperty(moduleRecord.module, '__esModule', { value: true });
|
|
1019
1185
|
}
|
|
1186
|
+
|
|
1020
1187
|
moduleRecord.evaluated = true;
|
|
1021
1188
|
Object.freeze(moduleRecord.module);
|
|
1022
1189
|
return moduleRecord.module;
|
|
1023
1190
|
}
|
|
1191
|
+
|
|
1024
1192
|
// Determines if named exports module has only default export
|
|
1025
|
-
|
|
1026
|
-
return (
|
|
1193
|
+
isNamedExportDefaultOnly(exports) {
|
|
1194
|
+
return (
|
|
1195
|
+
exports !== undefined &&
|
|
1027
1196
|
Object.getOwnPropertyNames(exports).length === 2 &&
|
|
1028
1197
|
Object.prototype.hasOwnProperty.call(exports, 'default') &&
|
|
1029
|
-
Object.prototype.hasOwnProperty.call(exports, '__esModule')
|
|
1198
|
+
Object.prototype.hasOwnProperty.call(exports, '__esModule')
|
|
1199
|
+
);
|
|
1030
1200
|
}
|
|
1201
|
+
|
|
1031
1202
|
// Wrap the dependency in a function that can be called and detected by __circular__ property.
|
|
1032
1203
|
// The LWC engine checks for __circular__ to detect circular dependencies.
|
|
1033
|
-
|
|
1204
|
+
getCircularDependencyWrapper(module) {
|
|
1034
1205
|
const tmp = () => {
|
|
1035
1206
|
return module.__useDefault || module.__defaultInterop ? module.default : module;
|
|
1036
1207
|
};
|
|
1037
1208
|
tmp.__circular__ = true;
|
|
1038
1209
|
return tmp;
|
|
1039
1210
|
}
|
|
1040
|
-
|
|
1211
|
+
|
|
1212
|
+
async evaluateModuleDependencies(
|
|
1213
|
+
dependencyModuleRecords,
|
|
1214
|
+
evaluationMap,
|
|
1215
|
+
) {
|
|
1041
1216
|
for (let i = 0; i < dependencyModuleRecords.length; i++) {
|
|
1042
1217
|
const depRecord = dependencyModuleRecords[i];
|
|
1043
1218
|
if (!depRecord.evaluated && !evaluationMap[depRecord.id]) {
|
|
@@ -1047,15 +1222,17 @@ class ModuleRegistry {
|
|
|
1047
1222
|
}
|
|
1048
1223
|
}
|
|
1049
1224
|
}
|
|
1050
|
-
|
|
1225
|
+
|
|
1226
|
+
async getModuleDef(resolvedId, originalId) {
|
|
1051
1227
|
// reset lastDefine
|
|
1052
1228
|
this.lastDefine = undefined;
|
|
1229
|
+
|
|
1053
1230
|
// the module name can be the resolved ID or the original ID if neither are URL's.
|
|
1054
1231
|
const moduleName = !isUrl(resolvedId)
|
|
1055
1232
|
? resolvedId
|
|
1056
1233
|
: originalId !== resolvedId
|
|
1057
|
-
|
|
1058
|
-
|
|
1234
|
+
? originalId
|
|
1235
|
+
: undefined;
|
|
1059
1236
|
let moduleDef = moduleName && this.namedDefineRegistry.get(moduleName);
|
|
1060
1237
|
if (moduleDef && moduleDef.external) {
|
|
1061
1238
|
return moduleDef.external.moduleDefPromise;
|
|
@@ -1068,67 +1245,75 @@ class ModuleRegistry {
|
|
|
1068
1245
|
this.profiler.logOperationStart({ id: MODULE_FETCH, specifier });
|
|
1069
1246
|
return Promise.resolve()
|
|
1070
1247
|
.then(async () => {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1248
|
+
const loadHooks = this.loadHook;
|
|
1249
|
+
if (loadHooks) {
|
|
1250
|
+
for (let i = 0; i < loadHooks.length; i++) {
|
|
1251
|
+
const loadHook = loadHooks[i];
|
|
1252
|
+
const response = loadHook(resolvedId, parentUrl);
|
|
1253
|
+
const result = (
|
|
1254
|
+
isResponseAPromise(response)
|
|
1255
|
+
? // eslint-disable-next-line no-await-in-loop
|
|
1256
|
+
await evaluateLoadHook(resolvedId, response)
|
|
1257
|
+
: response
|
|
1258
|
+
) ;
|
|
1259
|
+
if (result === undefined) {
|
|
1260
|
+
throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
|
|
1261
|
+
}
|
|
1262
|
+
if (result && result !== null) {
|
|
1263
|
+
return evaluateLoadHookResponse(result, resolvedId);
|
|
1264
|
+
}
|
|
1085
1265
|
}
|
|
1086
1266
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
})
|
|
1267
|
+
return false;
|
|
1268
|
+
})
|
|
1090
1269
|
.then((result) => {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1270
|
+
if (result !== true && hasDocument) {
|
|
1271
|
+
return loadModuleDef(resolvedId);
|
|
1272
|
+
}
|
|
1273
|
+
})
|
|
1095
1274
|
.then(() => {
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
moduleDef
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1275
|
+
// Attempt to retrieve the module definition by name first
|
|
1276
|
+
moduleDef = moduleName && this.namedDefineRegistry.get(moduleName);
|
|
1277
|
+
|
|
1278
|
+
// Fallback to the last loader.define call
|
|
1279
|
+
if (!moduleDef) {
|
|
1280
|
+
moduleDef = this.lastDefine;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// This should not happen
|
|
1284
|
+
if (!moduleDef) {
|
|
1285
|
+
throw new LoaderError(FAIL_INSTANTIATE, [resolvedId]);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
this.profiler.logOperationEnd({ id: MODULE_FETCH, specifier });
|
|
1289
|
+
return moduleDef;
|
|
1290
|
+
})
|
|
1109
1291
|
.catch((e) => {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1292
|
+
this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
|
|
1293
|
+
throw e;
|
|
1294
|
+
});
|
|
1113
1295
|
}
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
|
|
1114
1300
|
addLoaderPlugin(hooks) {
|
|
1115
1301
|
if (typeof hooks !== 'object') {
|
|
1116
1302
|
throw new LoaderError(INVALID_HOOK);
|
|
1117
1303
|
}
|
|
1118
1304
|
const { loadModule: loadHook, resolveModule: resolveHook, loadMapping } = hooks;
|
|
1305
|
+
|
|
1119
1306
|
if (resolveHook) {
|
|
1120
1307
|
if (this.resolveHook) {
|
|
1121
1308
|
this.resolveHook.push(resolveHook);
|
|
1122
|
-
}
|
|
1123
|
-
else {
|
|
1309
|
+
} else {
|
|
1124
1310
|
this.resolveHook = [resolveHook];
|
|
1125
1311
|
}
|
|
1126
1312
|
}
|
|
1127
1313
|
if (loadHook) {
|
|
1128
1314
|
if (this.loadHook) {
|
|
1129
1315
|
this.loadHook.push(loadHook);
|
|
1130
|
-
}
|
|
1131
|
-
else {
|
|
1316
|
+
} else {
|
|
1132
1317
|
this.loadHook = [loadHook];
|
|
1133
1318
|
}
|
|
1134
1319
|
}
|
|
@@ -1136,7 +1321,8 @@ class ModuleRegistry {
|
|
|
1136
1321
|
this.resolver.addLoadMappingHook(loadMapping);
|
|
1137
1322
|
}
|
|
1138
1323
|
}
|
|
1139
|
-
|
|
1324
|
+
|
|
1325
|
+
importMetadataInvalidationCallback({ name, oldUrl, newUrl }) {
|
|
1140
1326
|
const handleStaleModuleHooks = this.handleStaleModuleHook;
|
|
1141
1327
|
if (handleStaleModuleHooks) {
|
|
1142
1328
|
evaluateHandleStaleModuleHooks(handleStaleModuleHooks, {
|
|
@@ -1144,19 +1330,19 @@ class ModuleRegistry {
|
|
|
1144
1330
|
oldUrl,
|
|
1145
1331
|
newUrl,
|
|
1146
1332
|
});
|
|
1147
|
-
}
|
|
1148
|
-
else {
|
|
1333
|
+
} else {
|
|
1149
1334
|
if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
1150
1335
|
// eslint-disable-next-line lwr/no-unguarded-apis, no-undef
|
|
1151
1336
|
console.warn(`stale module detected ${name}, current URL:${oldUrl}, new URL:${newUrl}`);
|
|
1152
1337
|
}
|
|
1153
1338
|
}
|
|
1154
1339
|
}
|
|
1340
|
+
|
|
1341
|
+
|
|
1155
1342
|
registerHandleStaleModuleHook(handleStaleModule) {
|
|
1156
1343
|
if (this.handleStaleModuleHook) {
|
|
1157
1344
|
this.handleStaleModuleHook.push(handleStaleModule);
|
|
1158
|
-
}
|
|
1159
|
-
else {
|
|
1345
|
+
} else {
|
|
1160
1346
|
this.handleStaleModuleHook = [handleStaleModule];
|
|
1161
1347
|
}
|
|
1162
1348
|
}
|
|
@@ -1166,15 +1352,21 @@ class ModuleRegistry {
|
|
|
1166
1352
|
* The LWR loader is inspired and borrows from the algorithms and native browser principles of https://github.com/systemjs/systemjs
|
|
1167
1353
|
*/
|
|
1168
1354
|
class Loader {
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1169
1358
|
constructor(config) {
|
|
1170
1359
|
let baseUrl = config.baseUrl;
|
|
1171
1360
|
const mappingEndpoint = config.endpoints ? config.endpoints.uris.mapping : undefined;
|
|
1172
1361
|
let profiler = config.profiler;
|
|
1362
|
+
|
|
1173
1363
|
if (!mappingEndpoint) {
|
|
1174
1364
|
throw new LoaderError(NO_MAPPING_URL);
|
|
1175
1365
|
}
|
|
1366
|
+
|
|
1176
1367
|
// add a trailing slash, if it does not exist
|
|
1177
1368
|
config.endpoints.uris.mapping = mappingEndpoint.replace(/\/?$/, '/');
|
|
1369
|
+
|
|
1178
1370
|
if (baseUrl) {
|
|
1179
1371
|
// add a trailing slash, if it does not exist
|
|
1180
1372
|
baseUrl = baseUrl.replace(/\/?$/, '/');
|
|
@@ -1185,6 +1377,7 @@ class Loader {
|
|
|
1185
1377
|
if (!baseUrl) {
|
|
1186
1378
|
throw new LoaderError(NO_BASE_URL);
|
|
1187
1379
|
}
|
|
1380
|
+
|
|
1188
1381
|
if (!profiler) {
|
|
1189
1382
|
// default noop profiler
|
|
1190
1383
|
profiler = {
|
|
@@ -1196,7 +1389,9 @@ class Loader {
|
|
|
1196
1389
|
},
|
|
1197
1390
|
};
|
|
1198
1391
|
}
|
|
1392
|
+
|
|
1199
1393
|
this.registry = new ModuleRegistry(Object.freeze({ endpoints: config.endpoints, baseUrl, profiler }));
|
|
1394
|
+
|
|
1200
1395
|
// TODO: W-10539691 - temp workaround for LWR-Java -- remove once appId is implemented there
|
|
1201
1396
|
if (config.appMetadata && !config.appMetadata.appId) {
|
|
1202
1397
|
// Parse the appId from the bootstrapModule
|
|
@@ -1205,6 +1400,7 @@ class Loader {
|
|
|
1205
1400
|
const appId = match && match[1];
|
|
1206
1401
|
config.appMetadata.appId = appId;
|
|
1207
1402
|
}
|
|
1403
|
+
|
|
1208
1404
|
// TODO: https://github.com/salesforce-experience-platform-emu/lwr/issues/1087
|
|
1209
1405
|
this.services = Object.freeze({
|
|
1210
1406
|
addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
|
|
@@ -1212,6 +1408,7 @@ class Loader {
|
|
|
1212
1408
|
appMetadata: config.appMetadata,
|
|
1213
1409
|
});
|
|
1214
1410
|
}
|
|
1411
|
+
|
|
1215
1412
|
/**
|
|
1216
1413
|
* Defines/registers a single named AMD module definition.
|
|
1217
1414
|
*
|
|
@@ -1224,14 +1421,18 @@ class Loader {
|
|
|
1224
1421
|
invariant(typeof name === 'string', MISSING_NAME);
|
|
1225
1422
|
let ctor = execute;
|
|
1226
1423
|
let deps = dependencies;
|
|
1424
|
+
|
|
1227
1425
|
// Convert no dependencies form `define('name', function(){}, {});` to: `define('name', [], function(){}, {})`
|
|
1228
1426
|
if (typeof deps === 'function') {
|
|
1229
1427
|
ctor = dependencies;
|
|
1230
1428
|
deps = [];
|
|
1231
1429
|
}
|
|
1430
|
+
|
|
1232
1431
|
invariant(Array.isArray(deps), INVALID_DEPS);
|
|
1233
|
-
|
|
1432
|
+
|
|
1433
|
+
this.registry.define(name, deps, ctor );
|
|
1234
1434
|
}
|
|
1435
|
+
|
|
1235
1436
|
/**
|
|
1236
1437
|
* Retrieves/loads a module, returning it from the registry if it exists and fetching it if it doesn't.
|
|
1237
1438
|
*
|
|
@@ -1243,6 +1444,7 @@ class Loader {
|
|
|
1243
1444
|
async load(id, importer) {
|
|
1244
1445
|
return this.registry.load(id, importer);
|
|
1245
1446
|
}
|
|
1447
|
+
|
|
1246
1448
|
/**
|
|
1247
1449
|
* Checks if a Module exists in the registry. Note, returns false even if the ModuleDefinition exists but the Module has not been instantiated yet (executed).
|
|
1248
1450
|
*
|
|
@@ -1252,6 +1454,7 @@ class Loader {
|
|
|
1252
1454
|
has(id) {
|
|
1253
1455
|
return this.registry.has(id);
|
|
1254
1456
|
}
|
|
1457
|
+
|
|
1255
1458
|
/**
|
|
1256
1459
|
* Resolves the module identifier or URL. Returns the module identifier if the moduleDefinition exists, or the full resolved URL if a URL is given.
|
|
1257
1460
|
*
|
|
@@ -1263,9 +1466,11 @@ class Loader {
|
|
|
1263
1466
|
async resolve(id, importer) {
|
|
1264
1467
|
return this.registry.resolve(id, importer);
|
|
1265
1468
|
}
|
|
1469
|
+
|
|
1266
1470
|
async registerImportMappings(mappings, rootSpecifiers) {
|
|
1267
1471
|
this.registry.getImportMetadataResolver().registerImportMappings(mappings, rootSpecifiers);
|
|
1268
1472
|
}
|
|
1473
|
+
|
|
1269
1474
|
/**
|
|
1270
1475
|
* Marks modules as "externally" loaded/provided (e.g. preloaded), so that the loader does not attempt to load them.
|
|
1271
1476
|
*
|
|
@@ -1276,103 +1481,128 @@ class Loader {
|
|
|
1276
1481
|
}
|
|
1277
1482
|
}
|
|
1278
1483
|
|
|
1484
|
+
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1485
|
+
|
|
1279
1486
|
/** LWR Everywhere module for AMD **/
|
|
1487
|
+
|
|
1280
1488
|
// Process the LWR Client Bootstrap Config
|
|
1281
|
-
const configOptions = {
|
|
1489
|
+
const configOptions = {"format":"amd","apiVersion":"1","apiPrefix":"","bundle":false,"debug":true} ;
|
|
1282
1490
|
const configuration = getConfiguration(configOptions);
|
|
1283
1491
|
const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration;
|
|
1492
|
+
|
|
1284
1493
|
// Initialize the AMD loader (its code is bundled into the LWR Everywhere module)
|
|
1285
1494
|
const loader = new Loader({ endpoints, baseUrl });
|
|
1286
|
-
loader.define('lwr/loader/v/0_10_0-
|
|
1495
|
+
loader.define('lwr/loader/v/0_10_0-alpha_7', ['exports'], (exports) => {
|
|
1287
1496
|
Object.assign(exports, {
|
|
1288
1497
|
define: loader.define.bind(loader),
|
|
1289
1498
|
load: loader.load.bind(loader),
|
|
1290
1499
|
});
|
|
1291
1500
|
});
|
|
1292
1501
|
await loader.registerImportMappings({ imports, index }, [bootstrapModule]);
|
|
1293
|
-
globalThis.LWR = Object.freeze({ define: loader.define.bind(loader) });
|
|
1502
|
+
(globalThis ).LWR = Object.freeze({ define: loader.define.bind(loader) });
|
|
1503
|
+
|
|
1294
1504
|
// Define preload modules (ie: ABS, vault, etc) BEFORE loading them
|
|
1295
|
-
LWR.define('lwr/everywhereAmd/v/0_10_0-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
return null; // defer to loader
|
|
1309
|
-
}
|
|
1310
|
-
// Add a hook for adding OAuth headers to module and mapping requests
|
|
1311
|
-
// Workaround: core does not have proper versioning; replace all versions with 0_0_1
|
|
1312
|
-
function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
|
|
1313
|
-
serviceAPI.addLoaderPlugin({
|
|
1314
|
-
loadModule: async (url) => {
|
|
1315
|
-
return authFetch(url);
|
|
1316
|
-
},
|
|
1317
|
-
loadMapping: async (specifier) => {
|
|
1318
|
-
const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`, 'json');
|
|
1319
|
-
if (res && res.ok) {
|
|
1320
|
-
return res.json();
|
|
1321
|
-
}
|
|
1322
|
-
return null;
|
|
1323
|
-
},
|
|
1324
|
-
resolveModule: specifier => {
|
|
1325
|
-
// Workaround W-8010259 (dynamic imports without versions)
|
|
1326
|
-
// by adding a default version to version-less specifiers
|
|
1327
|
-
if (specifier && !/\/v\/[^/]+?$/.test(specifier)) {
|
|
1328
|
-
return `${specifier}/v/${coreVersion}`;
|
|
1329
|
-
}
|
|
1330
|
-
return null; // defer to loader
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
function initAmd(services, mappingEndpoint, coreVersion) {
|
|
1335
|
-
// Initialize the loader hooks for LWR-S endpoints
|
|
1336
|
-
if (mappingEndpoint.match(/\/v5\d\.0\//)) {
|
|
1337
|
-
everywhereHooks(services, mappingEndpoint, coreVersion);
|
|
1338
|
-
}
|
|
1505
|
+
LWR.define('lwr/everywhereAmd/v/0_10_0-alpha_7', ['exports', 'lwr/vault/v/0_10_0-alpha_7'], (function (exports, _0_10_0Alpha_7) {
|
|
1506
|
+
// IMPORTANT: Do not add any static imports to this file that are not bundled with the amd-client
|
|
1507
|
+
|
|
1508
|
+
// Do an OAuthed fetch
|
|
1509
|
+
async function authFetch(url, accept = 'javascript') {
|
|
1510
|
+
const authInfo = _0_10_0Alpha_7.getAuthInfo();
|
|
1511
|
+
if (authInfo) {
|
|
1512
|
+
return fetch(url, {
|
|
1513
|
+
headers: {
|
|
1514
|
+
Accept: `application/${accept}`,
|
|
1515
|
+
Authorization: `Bearer ${authInfo.access_token}`
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1339
1518
|
}
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1519
|
+
return null; // defer to loader
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
// Add a hook for adding OAuth headers to module and mapping requests
|
|
1523
|
+
// Workaround: core does not have proper versioning; replace all versions with 0_0_1
|
|
1524
|
+
function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
|
|
1525
|
+
serviceAPI.addLoaderPlugin({
|
|
1526
|
+
loadModule: async url => {
|
|
1527
|
+
return authFetch(url);
|
|
1528
|
+
},
|
|
1529
|
+
loadMapping: async specifier => {
|
|
1530
|
+
const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`, 'json');
|
|
1531
|
+
if (res && res.ok) {
|
|
1532
|
+
return res.json();
|
|
1533
|
+
}
|
|
1534
|
+
return null;
|
|
1535
|
+
},
|
|
1536
|
+
resolveModule: specifier => {
|
|
1537
|
+
// Workaround W-8010259 (dynamic imports without versions)
|
|
1538
|
+
// by adding a default version to version-less specifiers
|
|
1539
|
+
if (specifier && !/\/v\/[^/]+?$/.test(specifier)) {
|
|
1540
|
+
return `${specifier}/v/${coreVersion}`;
|
|
1347
1541
|
}
|
|
1542
|
+
return null; // defer to loader
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
function initAmd(services, mappingEndpoint, coreVersion) {
|
|
1548
|
+
// Initialize the loader hooks for LWR-S endpoints
|
|
1549
|
+
if (mappingEndpoint.match(/\/v5\d\.0\//)) {
|
|
1550
|
+
everywhereHooks(services, mappingEndpoint, coreVersion);
|
|
1348
1551
|
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
//
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
function getAuthInfo() {
|
|
1359
|
-
return authInfo;
|
|
1360
|
-
}
|
|
1361
|
-
function setAuthInfo(ai) {
|
|
1362
|
-
authInfo = ai;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// Export the LWRE authenticate() API
|
|
1555
|
+
// This is a duplicate of the function exported from "lwr/everywhere"
|
|
1556
|
+
// because it MUST be bundled into the LWRE module via "lwr/everywhereAmd"
|
|
1557
|
+
function authenticate(authInfo) {
|
|
1558
|
+
// Put OAuth info into the vault
|
|
1559
|
+
if (authInfo) {
|
|
1560
|
+
_0_10_0Alpha_7.setAuthInfo(authInfo);
|
|
1363
1561
|
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
exports.authenticate = authenticate;
|
|
1565
|
+
exports.initAmd = initAmd;
|
|
1566
|
+
|
|
1567
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1568
|
+
|
|
1569
|
+
}));
|
|
1570
|
+
LWR.define('lwr/vault/v/0_10_0-alpha_7', ['exports'], (function (exports) {
|
|
1571
|
+
// Credential vault for storing setters and subscribers for OAuth info
|
|
1572
|
+
// This module is a SINGLETON and must be excluded from ESM bundling
|
|
1573
|
+
|
|
1574
|
+
let authInfo;
|
|
1575
|
+
|
|
1576
|
+
// Get and set the OAuth info
|
|
1577
|
+
function getAuthInfo() {
|
|
1578
|
+
return authInfo;
|
|
1579
|
+
}
|
|
1580
|
+
function setAuthInfo(ai) {
|
|
1581
|
+
authInfo = ai;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
exports.getAuthInfo = getAuthInfo;
|
|
1585
|
+
exports.setAuthInfo = setAuthInfo;
|
|
1586
|
+
|
|
1587
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1588
|
+
|
|
1589
|
+
}));
|
|
1590
|
+
|
|
1591
|
+
|
|
1368
1592
|
// Set up the AMD loader hooks for OAuth
|
|
1369
1593
|
const { initAmd, authenticate } = await loader.load(bootstrapModule);
|
|
1370
|
-
initAmd(loader.services, endpoints
|
|
1594
|
+
initAmd(loader.services, _optionalChain([endpoints, 'optionalAccess', _ => _.uris, 'access', _2 => _2.mapping]), '0_10_0-alpha_7');
|
|
1595
|
+
|
|
1371
1596
|
// Wrap the createComponent API to allow proper ordering of module definitions:
|
|
1372
1597
|
// 1. LWRE module bundle (this): lwr/loader, lwr/everywhereAmd, lwr/vault
|
|
1373
1598
|
// 2. lwr/everywhere (deps: lwc, synthetic shadow, lwr/host, etc)
|
|
1374
1599
|
// 3. Salesforce hosted UI content (i.e. embedded components and deps)
|
|
1375
|
-
async function createComponent(
|
|
1600
|
+
async function createComponent(
|
|
1601
|
+
specifier,
|
|
1602
|
+
nodeId,
|
|
1603
|
+
properties = {},
|
|
1604
|
+
config,
|
|
1605
|
+
) {
|
|
1376
1606
|
// Do not load the "lwr/everywhere" API module ahead of time
|
|
1377
1607
|
// This import MUST be done AFTER the loader hooks are in place via authenticate() so
|
|
1378
1608
|
// modules [statically] imported from core have the appropriate Authorization headers
|