@lwrjs/loader 0.17.2-alpha.3 → 0.17.2-alpha.30

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.
Files changed (33) hide show
  1. package/README.md +1 -0
  2. package/build/assets/prod/lwr-error-shim.js +1 -1
  3. package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +168 -46
  4. package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +4 -3
  5. package/build/assets/prod/lwr-loader-shim-legacy.js +58 -16
  6. package/build/assets/prod/lwr-loader-shim.bundle.js +180 -54
  7. package/build/assets/prod/lwr-loader-shim.bundle.min.js +4 -3
  8. package/build/assets/prod/lwr-loader-shim.js +58 -16
  9. package/build/cjs/modules/lwr/loader/constants/constants.cjs +8 -1
  10. package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +2 -2
  11. package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +49 -7
  12. package/build/cjs/modules/lwr/loaderLegacy/constants/constants.cjs +8 -1
  13. package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +50 -8
  14. package/build/modules/lwr/esmLoader/esmLoader.js +1 -1
  15. package/build/modules/lwr/loader/constants/constants.d.ts +5 -0
  16. package/build/modules/lwr/loader/constants/constants.js +6 -0
  17. package/build/modules/lwr/loader/loader.d.ts +1 -0
  18. package/build/modules/lwr/loader/loader.js +122 -38
  19. package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.js +7 -7
  20. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.d.ts +4 -0
  21. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.js +66 -15
  22. package/build/modules/lwr/loaderLegacy/constants/constants.d.ts +5 -0
  23. package/build/modules/lwr/loaderLegacy/constants/constants.js +6 -0
  24. package/build/modules/lwr/loaderLegacy/loaderLegacy.d.ts +1 -0
  25. package/build/modules/lwr/loaderLegacy/loaderLegacy.js +110 -30
  26. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.d.ts +4 -0
  27. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.js +67 -16
  28. package/build/shim/shim.d.ts +2 -0
  29. package/build/shim/shim.js +45 -8
  30. package/build/shim-legacy/shimLegacy.d.ts +2 -0
  31. package/build/shim-legacy/shimLegacy.js +45 -8
  32. package/build/types.d.ts +1 -0
  33. package/package.json +8 -8
@@ -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.17.2-alpha.3 */
7
+ /* LWR Legacy Module Loader Shim v0.17.2-alpha.30 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -25,6 +25,7 @@
25
25
 
26
26
  // Check if the Performance API is available
27
27
  // e.g. JSDom (used in Jest) doesn't implement these
28
+ // eslint-disable-next-line
28
29
  const perf = globalThis.performance;
29
30
  const isPerfSupported = typeof perf !== 'undefined' && typeof perf.mark === 'function' && typeof perf.clearMarks === 'function' && typeof perf.measure === 'function' && typeof perf.clearMeasures === 'function';
30
31
  function getMeasureName(id, specifier) {
@@ -57,7 +58,8 @@
57
58
  id,
58
59
  phase: Phase.Start,
59
60
  specifier,
60
- metadata
61
+ metadata,
62
+ specifierIndex
61
63
  });
62
64
  return;
63
65
  }
@@ -84,7 +86,8 @@
84
86
  id,
85
87
  phase: Phase.End,
86
88
  specifier,
87
- metadata
89
+ metadata,
90
+ specifierIndex
88
91
  });
89
92
  } else if (isPerfSupported) {
90
93
  const markName = getMarkName(id, specifier, specifierIndex);
@@ -178,13 +181,14 @@
178
181
  }
179
182
  }
180
183
 
181
- /* global document */
184
+ /* global document, process, console */
182
185
 
183
186
 
184
187
 
185
188
  /* eslint-disable lwr/no-unguarded-apis */
186
189
  const hasSetTimeout = typeof setTimeout === 'function';
187
190
  const hasConsole = typeof console !== 'undefined';
191
+ const hasProcess = typeof process !== 'undefined';
188
192
  /* eslint-enable lwr/no-unguarded-apis */
189
193
 
190
194
  class LoaderShim {
@@ -206,7 +210,7 @@
206
210
  // Parse configuration
207
211
  this.global = global;
208
212
  this.config = global.LWR ;
209
- this.loaderModule = 'lwr/loaderLegacy/v/0_17_2-alpha_3';
213
+ this.loaderModule = 'lwr/loaderLegacy/v/0_17_2-alpha_30';
210
214
 
211
215
  // Set up error handler
212
216
  this.errorHandler = this.config.onError ;
@@ -303,17 +307,40 @@
303
307
  this.config.preloadModules,
304
308
  );
305
309
  this.mountApp(loader);
310
+ if (
311
+ loader &&
312
+ typeof loader.getModuleWarnings === 'function' &&
313
+ hasProcess &&
314
+ hasConsole &&
315
+ // eslint-disable-next-line lwr/no-unguarded-apis
316
+ process.env.NODE_ENV !== 'production'
317
+ ) {
318
+ this.logWarnings(loader.getModuleWarnings(true)); // the true indicates the app is mounted
319
+ }
306
320
  } catch (e) {
307
321
  this.enterErrorState(e);
308
322
  }
309
323
  }
310
324
 
311
- waitForDOMContentLoaded() {
312
- // eslint-disable-next-line lwr/no-unguarded-apis
313
- if (typeof document === undefined) {
314
- return Promise.resolve();
315
- }
325
+ waitForBody() {
326
+ return new Promise((resolve) => {
327
+ // eslint-disable-next-line lwr/no-unguarded-apis
328
+ if (document.body) {
329
+ resolve();
330
+ } else {
331
+ const observer = new MutationObserver(() => {
332
+ // eslint-disable-next-line lwr/no-unguarded-apis
333
+ if (document.body) {
334
+ observer.disconnect();
335
+ resolve();
336
+ }
337
+ });
338
+ observer.observe(document.documentElement, { childList: true });
339
+ }
340
+ });
341
+ }
316
342
 
343
+ waitForDOMContentLoaded() {
317
344
  // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
318
345
  // eslint-disable-next-line lwr/no-unguarded-apis
319
346
  if (document.readyState === 'interactive' || document.readyState === 'complete') {
@@ -333,7 +360,7 @@
333
360
  const exporter = (exports) => {
334
361
  Object.assign(exports, { logOperationStart, logOperationEnd });
335
362
  };
336
- define('lwr/profiler/v/0_17_2-alpha_3', ['exports'], exporter, {});
363
+ define('lwr/profiler/v/0_17_2-alpha_30', ['exports'], exporter, {});
337
364
  }
338
365
 
339
366
  // Set up the application globals, import map, root custom element...
@@ -359,16 +386,22 @@
359
386
  }
360
387
  });
361
388
 
362
- // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
363
- const { disableInitDefer } = this.config;
389
+ // by default, app initialization is gated on waiting for body to be available
390
+ // this flag uses the DOMContentLoaded event instead
391
+ const { initDeferDOM } = this.config;
364
392
 
365
393
  // Load the import mappings and application bootstrap module
366
394
  loader
367
395
  .registerImportMappings(importMappings)
368
396
  .then(() => {
369
- if (!disableInitDefer) {
397
+ // eslint-disable-next-line lwr/no-unguarded-apis
398
+ if (typeof window === 'undefined' || typeof document === undefined) {
399
+ return Promise.resolve();
400
+ }
401
+ if (initDeferDOM) {
370
402
  return this.waitForDOMContentLoaded();
371
403
  }
404
+ return this.waitForBody();
372
405
  })
373
406
  .then(() => loader.load(bootstrapModule))
374
407
  .catch((reason) => {
@@ -400,13 +433,22 @@
400
433
  this.enterErrorState(new Error('Failed to load required modules - timed out'));
401
434
  }, REQUIRED_MODULES_TIMEOUT);
402
435
  }
436
+
437
+ logWarnings(warnings) {
438
+ for (const warningKey in warnings) {
439
+ if (warnings[warningKey].length) {
440
+ // eslint-disable-next-line lwr/no-unguarded-apis
441
+ console.warn(warningKey, warnings[warningKey]);
442
+ }
443
+ }
444
+ }
403
445
  }
404
446
 
405
447
  // The loader module is ALWAYS required
406
448
  const GLOBAL = globalThis ;
407
449
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
408
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_17_2-alpha_3') < 0) {
409
- GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_17_2-alpha_3');
450
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_17_2-alpha_30') < 0) {
451
+ GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_17_2-alpha_30');
410
452
  }
411
453
  new LoaderShim(GLOBAL);
412
454
 
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- /* LWR Module Loader Shim v0.17.2-alpha.3 */
7
+ /* LWR Module Loader Shim v0.17.2-alpha.30 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -25,6 +25,7 @@
25
25
 
26
26
  // Check if the Performance API is available
27
27
  // e.g. JSDom (used in Jest) doesn't implement these
28
+ // eslint-disable-next-line
28
29
  const perf = globalThis.performance;
29
30
  const isPerfSupported = typeof perf !== 'undefined' && typeof perf.mark === 'function' && typeof perf.clearMarks === 'function' && typeof perf.measure === 'function' && typeof perf.clearMeasures === 'function';
30
31
  function getMeasureName(id, specifier) {
@@ -57,7 +58,8 @@
57
58
  id,
58
59
  phase: Phase.Start,
59
60
  specifier,
60
- metadata
61
+ metadata,
62
+ specifierIndex
61
63
  });
62
64
  return;
63
65
  }
@@ -84,7 +86,8 @@
84
86
  id,
85
87
  phase: Phase.End,
86
88
  specifier,
87
- metadata
89
+ metadata,
90
+ specifierIndex
88
91
  });
89
92
  } else if (isPerfSupported) {
90
93
  const markName = getMarkName(id, specifier, specifierIndex);
@@ -175,7 +178,7 @@
175
178
  }
176
179
  }
177
180
 
178
- /* global document */
181
+ /* global document, process, console */
179
182
 
180
183
 
181
184
 
@@ -188,6 +191,7 @@
188
191
  /* eslint-disable lwr/no-unguarded-apis */
189
192
  const hasSetTimeout = typeof setTimeout === 'function';
190
193
  const hasConsole = typeof console !== 'undefined';
194
+ const hasProcess = typeof process !== 'undefined';
191
195
  /* eslint-enable lwr/no-unguarded-apis */
192
196
 
193
197
  class LoaderShim {
@@ -209,7 +213,7 @@
209
213
  // Parse configuration
210
214
  this.global = global;
211
215
  this.config = global.LWR ;
212
- this.loaderSpecifier = 'lwr/loader/v/0_17_2-alpha_3';
216
+ this.loaderSpecifier = 'lwr/loader/v/0_17_2-alpha_30';
213
217
 
214
218
  // Set up error handler
215
219
  this.errorHandler = this.config.onError ;
@@ -307,17 +311,40 @@
307
311
  this.config.preloadModules,
308
312
  );
309
313
  this.mountApp(loader);
314
+ if (
315
+ loader &&
316
+ typeof loader.getModuleWarnings === 'function' &&
317
+ hasProcess &&
318
+ hasConsole &&
319
+ // eslint-disable-next-line lwr/no-unguarded-apis
320
+ process.env.NODE_ENV !== 'production'
321
+ ) {
322
+ this.logWarnings(loader.getModuleWarnings(true)); // the true indicates the app is mounted
323
+ }
310
324
  } catch (e) {
311
325
  this.enterErrorState(e);
312
326
  }
313
327
  }
314
328
 
315
- waitForDOMContentLoaded() {
316
- // eslint-disable-next-line lwr/no-unguarded-apis
317
- if (typeof document === undefined) {
318
- return Promise.resolve();
319
- }
329
+ waitForBody() {
330
+ return new Promise((resolve) => {
331
+ // eslint-disable-next-line lwr/no-unguarded-apis
332
+ if (document.body) {
333
+ resolve();
334
+ } else {
335
+ const observer = new MutationObserver(() => {
336
+ // eslint-disable-next-line lwr/no-unguarded-apis
337
+ if (document.body) {
338
+ observer.disconnect();
339
+ resolve();
340
+ }
341
+ });
342
+ observer.observe(document.documentElement, { childList: true });
343
+ }
344
+ });
345
+ }
320
346
 
347
+ waitForDOMContentLoaded() {
321
348
  // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
322
349
  // eslint-disable-next-line lwr/no-unguarded-apis
323
350
  if (document.readyState === 'interactive' || document.readyState === 'complete') {
@@ -337,7 +364,7 @@
337
364
  const exporter = (exports) => {
338
365
  Object.assign(exports, { logOperationStart, logOperationEnd });
339
366
  };
340
- define('lwr/profiler/v/0_17_2-alpha_3', ['exports'], exporter);
367
+ define('lwr/profiler/v/0_17_2-alpha_30', ['exports'], exporter);
341
368
  }
342
369
 
343
370
  // Set up the application globals, import map, root custom element...
@@ -365,8 +392,9 @@
365
392
  }
366
393
  });
367
394
 
368
- // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
369
- const { disableInitDefer } = this.config;
395
+ // by default, app initialization is gated on waiting for body to be available
396
+ // this flag uses the DOMContentLoaded event instead
397
+ const { initDeferDOM } = this.config;
370
398
 
371
399
  // Load the import mappings and application bootstrap module
372
400
  loader
@@ -375,9 +403,14 @@
375
403
  rootComponent ,
376
404
  ])
377
405
  .then(() => {
378
- if (!disableInitDefer) {
406
+ // eslint-disable-next-line lwr/no-unguarded-apis
407
+ if (typeof window === 'undefined' || typeof document === undefined) {
408
+ return Promise.resolve();
409
+ }
410
+ if (initDeferDOM) {
379
411
  return this.waitForDOMContentLoaded();
380
412
  }
413
+ return this.waitForBody();
381
414
  })
382
415
  .then(() => loader.load(bootstrapModule))
383
416
  .catch((reason) => {
@@ -409,19 +442,28 @@
409
442
  this.enterErrorState(new Error('Failed to load required modules - timed out'));
410
443
  }, REQUIRED_MODULES_TIMEOUT);
411
444
  }
445
+
446
+ logWarnings(warnings) {
447
+ for (const warningKey in warnings) {
448
+ if (warnings[warningKey].length) {
449
+ // eslint-disable-next-line lwr/no-unguarded-apis
450
+ console.warn(warningKey, warnings[warningKey]);
451
+ }
452
+ }
453
+ }
412
454
  }
413
455
 
414
456
  // The loader module is ALWAYS required
415
457
  const GLOBAL = globalThis ;
416
458
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
417
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_17_2-alpha_3') < 0) {
418
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_17_2-alpha_3');
459
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_17_2-alpha_30') < 0) {
460
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_17_2-alpha_30');
419
461
  }
420
462
  new LoaderShim(GLOBAL);
421
463
 
422
464
  })();
423
465
 
424
- LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'use strict';
466
+ LWR.define('lwr/loader/v/0_17_2-alpha_30', ['exports'], (function (exports) { 'use strict';
425
467
 
426
468
  const templateRegex = /\{([0-9]+)\}/g;
427
469
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -526,7 +568,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
526
568
  level: 0,
527
569
  message: 'An error occurred handling module conflict',
528
570
  });
529
- const MODULE_ALREADY_LOADED = Object.freeze({
571
+ Object.freeze({
530
572
  code: 3017,
531
573
  level: 0,
532
574
  message: 'Marking module(s) as externally loaded, but they are already loaded:',
@@ -956,20 +998,21 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
956
998
  if (!uri) {
957
999
  throw new LoaderError(UNRESOLVEABLE_MAPPING_ERROR, [specifier]);
958
1000
  }
959
- return globalThis.fetch(uri).then((res) => {
960
- if (!res.ok) {
961
- this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
962
- throw new LoaderError(UNRESOLVED, [specifier]);
963
- }
964
- return res
965
- .json()
966
- .then((ret) => {
967
- return ret ;
968
- })
969
- .catch((err) => {
1001
+
1002
+ return globalThis
1003
+ .fetch(uri)
1004
+ .then((res) => {
1005
+ if (!res.ok) {
1006
+ this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
970
1007
  throw new LoaderError(UNRESOLVED, [specifier]);
1008
+ }
1009
+ return res.json().then((ret) => {
1010
+ return ret ;
971
1011
  });
972
- });
1012
+ })
1013
+ .catch((err) => {
1014
+ throw new LoaderError(UNRESOLVED, [specifier]);
1015
+ });
973
1016
  }
974
1017
 
975
1018
  saveImportURIRecord(specifier, uri, identity, isRoot) {
@@ -1015,20 +1058,39 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1015
1058
 
1016
1059
  const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
1017
1060
 
1061
+ var MODULE_WARNING; (function (MODULE_WARNING) {
1062
+ const MODULE_REDEFINE = 'Module redefine attempted'; MODULE_WARNING["MODULE_REDEFINE"] = MODULE_REDEFINE;
1063
+ const MODULE_ALREADY_LOADED = 'Marking module(s) as externally loaded, but they are already loaded'; MODULE_WARNING["MODULE_ALREADY_LOADED"] = MODULE_ALREADY_LOADED;
1064
+ const ALIAS_UPDATE = 'Alias update attempt'; MODULE_WARNING["ALIAS_UPDATE"] = ALIAS_UPDATE;
1065
+ })(MODULE_WARNING || (MODULE_WARNING = {}));
1066
+
1018
1067
  /*!
1019
1068
  * Copyright (C) 2023 salesforce.com, inc.
1020
1069
  */
1021
1070
  // @ts-ignore: Prevent cannot find name 'trustedTypes' error.
1022
1071
  const SUPPORTS_TRUSTED_TYPES = typeof trustedTypes !== 'undefined';
1023
- function createTrustedTypesPolicy(name, options) {
1072
+ const trustedTypePolicyRegistry = {
1073
+ __proto__: null
1074
+ };
1075
+ function createDuplicateSafeTrustedTypesPolicy(name, options) {
1076
+ // istanbul ignore next: not testable in coverage collection
1077
+ if (trustedTypePolicyRegistry[name]) {
1078
+ return trustedTypePolicyRegistry[name];
1079
+ }
1024
1080
  // @ts-ignore: Prevent cannot find name 'trustedTypes' error.
1025
- return trustedTypes.createPolicy(name, options);
1081
+ // eslint-disable-next-line no-return-assign
1082
+ return trustedTypePolicyRegistry[name] = trustedTypes.createPolicy(name, options);
1026
1083
  }
1027
- function createFallbackPolicy(_name, options) {
1028
- return options;
1084
+ function createDuplicateSafeFallbackPolicy(name, options) {
1085
+ if (trustedTypePolicyRegistry[name]) {
1086
+ return trustedTypePolicyRegistry[name];
1087
+ }
1088
+ // @ts-ignore: Prevent cannot find name 'trustedTypes' error.
1089
+ // eslint-disable-next-line no-return-assign
1090
+ return trustedTypePolicyRegistry[name] = options;
1029
1091
  }
1030
1092
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
1031
- const createPolicy = SUPPORTS_TRUSTED_TYPES ? createTrustedTypesPolicy : createFallbackPolicy;
1093
+ const createPolicy = SUPPORTS_TRUSTED_TYPES ? createDuplicateSafeTrustedTypesPolicy : createDuplicateSafeFallbackPolicy;
1032
1094
  const policyOptions = {
1033
1095
  createHTML(value) {
1034
1096
  return value;
@@ -1076,7 +1138,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1076
1138
  // swallow
1077
1139
  }
1078
1140
  const trusted = createPolicy('trusted', policyOptions);
1079
- /*! version: 0.23.6 */
1141
+ /*! version: 0.24.6 */
1080
1142
 
1081
1143
  /* global console,process */
1082
1144
 
@@ -1146,7 +1208,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1146
1208
  code = `${code}\n//# sourceURL=${id}`; // append sourceURL for debugging
1147
1209
  try {
1148
1210
  // TODO eval source maps for debugging
1149
- eval(trusted.createScript(code));
1211
+ eval(trusted.createScript(code) );
1150
1212
  } catch (e) {
1151
1213
  // eslint-disable-next-line lwr/no-unguarded-apis
1152
1214
  if (process.env.NODE_ENV !== 'production' && hasConsole) {
@@ -1190,7 +1252,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1190
1252
  });
1191
1253
  }
1192
1254
 
1193
- /* global console,process */
1255
+ /* global process console */
1194
1256
 
1195
1257
 
1196
1258
 
@@ -1237,13 +1299,20 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1237
1299
 
1238
1300
  class ModuleRegistry {
1239
1301
 
1302
+
1303
+ __init() {this.isAppMounted = false;}
1240
1304
 
1241
- constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);
1305
+ constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);ModuleRegistry.prototype.__init4.call(this);
1242
1306
  this.profiler = config.profiler;
1243
1307
  this.resolver = new ImportMetadataResolver(
1244
1308
  config,
1245
1309
  this.importMetadataInvalidationCallback.bind(this),
1246
1310
  );
1311
+ this.warnings = {
1312
+ [MODULE_WARNING.MODULE_REDEFINE]: [],
1313
+ [MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
1314
+ [MODULE_WARNING.ALIAS_UPDATE]: [],
1315
+ };
1247
1316
  }
1248
1317
 
1249
1318
  async load(id, importer) {
@@ -1375,11 +1444,14 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1375
1444
  // eslint-disable-next-line lwr/no-unguarded-apis
1376
1445
  process.env.NODE_ENV !== 'production' &&
1377
1446
  // eslint-disable-next-line lwr/no-unguarded-apis
1378
- process.env.MRT_HMR !== 'true' &&
1379
- hasConsole
1447
+ process.env.MRT_HMR !== 'true'
1380
1448
  ) {
1381
- // eslint-disable-next-line lwr/no-unguarded-apis
1382
- console.warn(`Module redefine attempted: ${name}`);
1449
+ if (!this.warnings[MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
1450
+ this.warnings[MODULE_WARNING.MODULE_REDEFINE].push(name);
1451
+ }
1452
+ if (this.isAppMounted) {
1453
+ this.logMessage('warning', `${MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
1454
+ }
1383
1455
  }
1384
1456
  this.lastDefine = mod;
1385
1457
  return;
@@ -1433,9 +1505,13 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1433
1505
  };
1434
1506
  this.namedDefineRegistry.set(id, moduleDef );
1435
1507
  // eslint-disable-next-line lwr/no-unguarded-apis
1436
- } else if (process.env.NODE_ENV !== 'production' && hasConsole) {
1437
- // eslint-disable-next-line lwr/no-unguarded-apis
1438
- console.warn(MODULE_ALREADY_LOADED.message, id);
1508
+ } else if (process.env.NODE_ENV !== 'production') {
1509
+ if (!this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
1510
+ this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
1511
+ }
1512
+ if (this.isAppMounted) {
1513
+ this.logMessage('warning', `${MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
1514
+ }
1439
1515
  }
1440
1516
  });
1441
1517
  }
@@ -1443,13 +1519,13 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1443
1519
 
1444
1520
 
1445
1521
  // A registry for named AMD defines containing the *metadata* of AMD module
1446
- __init() {this.namedDefineRegistry = new Map();}
1522
+ __init2() {this.namedDefineRegistry = new Map();}
1447
1523
 
1448
1524
  // The evaluated module registry where the module identifier (name or URL?) is the key
1449
- __init2() {this.moduleRegistry = new Map();}
1525
+ __init3() {this.moduleRegistry = new Map();}
1450
1526
 
1451
1527
  // Aliases of modules in the registry
1452
- __init3() {this.aliases = new Map();}
1528
+ __init4() {this.aliases = new Map();}
1453
1529
 
1454
1530
 
1455
1531
 
@@ -1529,10 +1605,12 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1529
1605
  // Warn the user if they were not aliasing to the resolvedId
1530
1606
  const currentResolvedId = this.aliases.get(aliasId);
1531
1607
  if (currentResolvedId !== resolvedId) {
1532
- // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
1533
- if (process.env.NODE_ENV !== 'production' && hasConsole) {
1534
- // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
1535
- console.warn(`Alias update attempt: ${aliasId}=>${currentResolvedId}, ${resolvedId}`);
1608
+ const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
1609
+ if (!this.warnings[MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
1610
+ this.warnings[MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
1611
+ }
1612
+ if (this.isAppMounted) {
1613
+ this.logMessage('warning', `${MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
1536
1614
  }
1537
1615
  }
1538
1616
  }
@@ -1540,7 +1618,25 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1540
1618
  }
1541
1619
 
1542
1620
  async getModuleDependencyRecord(dependency) {
1543
- const resolvedDepId = await this.resolve(dependency);
1621
+ // Initially resolve the dependency to get its ID, which may be a bundle URL.
1622
+ let resolvedDepId = await this.resolve(dependency);
1623
+
1624
+ // If the resolved dependency ID is a URL, it indicates that the dependency
1625
+ // is provided by a bundle that hasn't been fully instantiated yet.
1626
+ if (isUrl(resolvedDepId)) {
1627
+ // Retrieve the module record corresponding to the bundle URL.
1628
+ const existingRecord = this.moduleRegistry.get(resolvedDepId);
1629
+
1630
+ // If a module record for the bundle exists and we haven't already created an alias for this dependency,
1631
+ // then the bundle is still pending instantiation.
1632
+ if (existingRecord && !this.aliases.has(dependency)) {
1633
+ // Wait for the bundle's instantiation promise to resolve.
1634
+ await existingRecord.instantiation;
1635
+ // After instantiation, re-resolve the dependency.
1636
+ // This should now return the final alias (the logical module ID) instead of the raw bundle URL.
1637
+ resolvedDepId = await this.resolve(dependency);
1638
+ }
1639
+ }
1544
1640
  return this.getModuleRecord(resolvedDepId, dependency);
1545
1641
  }
1546
1642
 
@@ -1764,6 +1860,10 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1764
1860
 
1765
1861
  // Fallback to the last loader.define call
1766
1862
  if (!moduleDef) {
1863
+ this.logMessage(
1864
+ 'warning',
1865
+ `${moduleName} not found, falling back to the last loader.define call`,
1866
+ );
1767
1867
  moduleDef = this.lastDefine;
1768
1868
  }
1769
1869
 
@@ -1845,6 +1945,28 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1845
1945
  res === null || typeof res === 'string' || (res && typeof (res ).url === 'string')
1846
1946
  );
1847
1947
  }
1948
+
1949
+ getModuleWarnings(isAppMounted = false) {
1950
+ this.isAppMounted = isAppMounted;
1951
+ return this.warnings;
1952
+ }
1953
+
1954
+ logMessage(logType, message) {
1955
+ if (
1956
+ !hasProcessEnv ||
1957
+ !hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
1958
+ process.env.NODE_ENV === 'production'
1959
+ ) {
1960
+ return;
1961
+ }
1962
+ if (logType == 'warning') {
1963
+ // eslint-disable-next-line lwr/no-unguarded-apis
1964
+ console.warn(message);
1965
+ } else {
1966
+ // eslint-disable-next-line lwr/no-unguarded-apis
1967
+ console.log(message);
1968
+ }
1969
+ }
1848
1970
  }
1849
1971
 
1850
1972
  /**
@@ -1978,6 +2100,10 @@ LWR.define('lwr/loader/v/0_17_2-alpha_3', ['exports'], (function (exports) { 'us
1978
2100
  registerExternalModules(modules) {
1979
2101
  this.registry.registerExternalModules(modules);
1980
2102
  }
2103
+
2104
+ getModuleWarnings(isAppMounted = false) {
2105
+ return this.registry.getModuleWarnings(isAppMounted);
2106
+ }
1981
2107
  }
1982
2108
 
1983
2109
  exports.Loader = Loader;