@lwrjs/loader 0.17.2-alpha.2 → 0.17.2-alpha.21

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 (32) hide show
  1. package/build/assets/prod/lwr-error-shim.js +1 -1
  2. package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +134 -47
  3. package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +4 -3
  4. package/build/assets/prod/lwr-loader-shim-legacy.js +45 -18
  5. package/build/assets/prod/lwr-loader-shim.bundle.js +163 -56
  6. package/build/assets/prod/lwr-loader-shim.bundle.min.js +4 -3
  7. package/build/assets/prod/lwr-loader-shim.js +45 -18
  8. package/build/cjs/modules/lwr/loader/constants/constants.cjs +8 -1
  9. package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +2 -2
  10. package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +48 -7
  11. package/build/cjs/modules/lwr/loaderLegacy/constants/constants.cjs +8 -1
  12. package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +41 -7
  13. package/build/modules/lwr/esmLoader/esmLoader.js +1 -1
  14. package/build/modules/lwr/loader/constants/constants.d.ts +5 -0
  15. package/build/modules/lwr/loader/constants/constants.js +6 -0
  16. package/build/modules/lwr/loader/loader.d.ts +1 -0
  17. package/build/modules/lwr/loader/loader.js +118 -38
  18. package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.js +7 -7
  19. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.d.ts +4 -0
  20. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.js +65 -15
  21. package/build/modules/lwr/loaderLegacy/constants/constants.d.ts +5 -0
  22. package/build/modules/lwr/loaderLegacy/constants/constants.js +6 -0
  23. package/build/modules/lwr/loaderLegacy/loaderLegacy.d.ts +1 -0
  24. package/build/modules/lwr/loaderLegacy/loaderLegacy.js +89 -29
  25. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.d.ts +4 -0
  26. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.js +50 -15
  27. package/build/shim/shim.d.ts +2 -1
  28. package/build/shim/shim.js +33 -11
  29. package/build/shim-legacy/shimLegacy.d.ts +2 -1
  30. package/build/shim-legacy/shimLegacy.js +33 -11
  31. package/build/types.d.ts +1 -0
  32. 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.2 */
7
+ /* LWR Legacy Module Loader Shim v0.17.2-alpha.21 */
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_2';
213
+ this.loaderModule = 'lwr/loaderLegacy/v/0_17_2-alpha_21';
210
214
 
211
215
  // Set up error handler
212
216
  this.errorHandler = this.config.onError ;
@@ -303,27 +307,41 @@
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() {
325
+ waitForBody() {
312
326
  // eslint-disable-next-line lwr/no-unguarded-apis
313
327
  if (typeof document === undefined) {
314
328
  return Promise.resolve();
315
329
  }
316
330
 
317
- // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
318
- // eslint-disable-next-line lwr/no-unguarded-apis
319
- if (document.readyState === 'interactive' || document.readyState === 'complete') {
320
- return Promise.resolve();
321
- }
322
331
  return new Promise((resolve) => {
323
332
  // eslint-disable-next-line lwr/no-unguarded-apis
324
- document.addEventListener('DOMContentLoaded', () => {
333
+ if (document.body) {
325
334
  resolve();
326
- });
335
+ } else {
336
+ const observer = new MutationObserver(() => {
337
+ // eslint-disable-next-line lwr/no-unguarded-apis
338
+ if (document.body) {
339
+ observer.disconnect();
340
+ resolve();
341
+ }
342
+ });
343
+ observer.observe(document.documentElement, { childList: true });
344
+ }
327
345
  });
328
346
  }
329
347
 
@@ -333,7 +351,7 @@
333
351
  const exporter = (exports) => {
334
352
  Object.assign(exports, { logOperationStart, logOperationEnd });
335
353
  };
336
- define('lwr/profiler/v/0_17_2-alpha_2', ['exports'], exporter, {});
354
+ define('lwr/profiler/v/0_17_2-alpha_21', ['exports'], exporter, {});
337
355
  }
338
356
 
339
357
  // Set up the application globals, import map, root custom element...
@@ -359,7 +377,7 @@
359
377
  }
360
378
  });
361
379
 
362
- // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
380
+ // by default, app initialization is gated on waiting for body to be available
363
381
  const { disableInitDefer } = this.config;
364
382
 
365
383
  // Load the import mappings and application bootstrap module
@@ -367,7 +385,7 @@
367
385
  .registerImportMappings(importMappings)
368
386
  .then(() => {
369
387
  if (!disableInitDefer) {
370
- return this.waitForDOMContentLoaded();
388
+ return this.waitForBody();
371
389
  }
372
390
  })
373
391
  .then(() => loader.load(bootstrapModule))
@@ -400,13 +418,22 @@
400
418
  this.enterErrorState(new Error('Failed to load required modules - timed out'));
401
419
  }, REQUIRED_MODULES_TIMEOUT);
402
420
  }
421
+
422
+ logWarnings(warnings) {
423
+ for (const warningKey in warnings) {
424
+ if (warnings[warningKey].length) {
425
+ // eslint-disable-next-line lwr/no-unguarded-apis
426
+ console.warn(warningKey, warnings[warningKey]);
427
+ }
428
+ }
429
+ }
403
430
  }
404
431
 
405
432
  // The loader module is ALWAYS required
406
433
  const GLOBAL = globalThis ;
407
434
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
408
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_17_2-alpha_2') < 0) {
409
- GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_17_2-alpha_2');
435
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loaderLegacy/v/0_17_2-alpha_21') < 0) {
436
+ GLOBAL.LWR.requiredModules.push('lwr/loaderLegacy/v/0_17_2-alpha_21');
410
437
  }
411
438
  new LoaderShim(GLOBAL);
412
439
 
@@ -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.2 */
7
+ /* LWR Module Loader Shim v0.17.2-alpha.21 */
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_2';
216
+ this.loaderSpecifier = 'lwr/loader/v/0_17_2-alpha_21';
213
217
 
214
218
  // Set up error handler
215
219
  this.errorHandler = this.config.onError ;
@@ -307,27 +311,41 @@
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() {
329
+ waitForBody() {
316
330
  // eslint-disable-next-line lwr/no-unguarded-apis
317
331
  if (typeof document === undefined) {
318
332
  return Promise.resolve();
319
333
  }
320
334
 
321
- // Resolve if document is already "ready" https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
322
- // eslint-disable-next-line lwr/no-unguarded-apis
323
- if (document.readyState === 'interactive' || document.readyState === 'complete') {
324
- return Promise.resolve();
325
- }
326
335
  return new Promise((resolve) => {
327
336
  // eslint-disable-next-line lwr/no-unguarded-apis
328
- document.addEventListener('DOMContentLoaded', () => {
337
+ if (document.body) {
329
338
  resolve();
330
- });
339
+ } else {
340
+ const observer = new MutationObserver(() => {
341
+ // eslint-disable-next-line lwr/no-unguarded-apis
342
+ if (document.body) {
343
+ observer.disconnect();
344
+ resolve();
345
+ }
346
+ });
347
+ observer.observe(document.documentElement, { childList: true });
348
+ }
331
349
  });
332
350
  }
333
351
 
@@ -337,7 +355,7 @@
337
355
  const exporter = (exports) => {
338
356
  Object.assign(exports, { logOperationStart, logOperationEnd });
339
357
  };
340
- define('lwr/profiler/v/0_17_2-alpha_2', ['exports'], exporter);
358
+ define('lwr/profiler/v/0_17_2-alpha_21', ['exports'], exporter);
341
359
  }
342
360
 
343
361
  // Set up the application globals, import map, root custom element...
@@ -365,7 +383,7 @@
365
383
  }
366
384
  });
367
385
 
368
- // by default, app initialization is gated on waiting for document to be parsed (via DOMContentLoaded)
386
+ // by default, app initialization is gated on waiting for body to be available (via DOMContentLoaded)
369
387
  const { disableInitDefer } = this.config;
370
388
 
371
389
  // Load the import mappings and application bootstrap module
@@ -376,7 +394,7 @@
376
394
  ])
377
395
  .then(() => {
378
396
  if (!disableInitDefer) {
379
- return this.waitForDOMContentLoaded();
397
+ return this.waitForBody();
380
398
  }
381
399
  })
382
400
  .then(() => loader.load(bootstrapModule))
@@ -409,19 +427,28 @@
409
427
  this.enterErrorState(new Error('Failed to load required modules - timed out'));
410
428
  }, REQUIRED_MODULES_TIMEOUT);
411
429
  }
430
+
431
+ logWarnings(warnings) {
432
+ for (const warningKey in warnings) {
433
+ if (warnings[warningKey].length) {
434
+ // eslint-disable-next-line lwr/no-unguarded-apis
435
+ console.warn(warningKey, warnings[warningKey]);
436
+ }
437
+ }
438
+ }
412
439
  }
413
440
 
414
441
  // The loader module is ALWAYS required
415
442
  const GLOBAL = globalThis ;
416
443
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
417
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_17_2-alpha_2') < 0) {
418
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_17_2-alpha_2');
444
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_17_2-alpha_21') < 0) {
445
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_17_2-alpha_21');
419
446
  }
420
447
  new LoaderShim(GLOBAL);
421
448
 
422
449
  })();
423
450
 
424
- LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'use strict';
451
+ LWR.define('lwr/loader/v/0_17_2-alpha_21', ['exports'], (function (exports) { 'use strict';
425
452
 
426
453
  const templateRegex = /\{([0-9]+)\}/g;
427
454
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -526,7 +553,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
526
553
  level: 0,
527
554
  message: 'An error occurred handling module conflict',
528
555
  });
529
- const MODULE_ALREADY_LOADED = Object.freeze({
556
+ Object.freeze({
530
557
  code: 3017,
531
558
  level: 0,
532
559
  message: 'Marking module(s) as externally loaded, but they are already loaded:',
@@ -956,20 +983,21 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
956
983
  if (!uri) {
957
984
  throw new LoaderError(UNRESOLVEABLE_MAPPING_ERROR, [specifier]);
958
985
  }
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) => {
986
+
987
+ return globalThis
988
+ .fetch(uri)
989
+ .then((res) => {
990
+ if (!res.ok) {
991
+ this.config.profiler.logOperationStart({ id: MAPPINGS_ERROR, specifier });
970
992
  throw new LoaderError(UNRESOLVED, [specifier]);
993
+ }
994
+ return res.json().then((ret) => {
995
+ return ret ;
971
996
  });
972
- });
997
+ })
998
+ .catch((err) => {
999
+ throw new LoaderError(UNRESOLVED, [specifier]);
1000
+ });
973
1001
  }
974
1002
 
975
1003
  saveImportURIRecord(specifier, uri, identity, isRoot) {
@@ -1015,20 +1043,39 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1015
1043
 
1016
1044
  const MODULE_LOAD_TIMEOUT_TIMER = 60 * 1000; // 1m
1017
1045
 
1046
+ var MODULE_WARNING; (function (MODULE_WARNING) {
1047
+ const MODULE_REDEFINE = 'Module redefine attempted'; MODULE_WARNING["MODULE_REDEFINE"] = MODULE_REDEFINE;
1048
+ const MODULE_ALREADY_LOADED = 'Marking module(s) as externally loaded, but they are already loaded'; MODULE_WARNING["MODULE_ALREADY_LOADED"] = MODULE_ALREADY_LOADED;
1049
+ const ALIAS_UPDATE = 'Alias update attempt'; MODULE_WARNING["ALIAS_UPDATE"] = ALIAS_UPDATE;
1050
+ })(MODULE_WARNING || (MODULE_WARNING = {}));
1051
+
1018
1052
  /*!
1019
1053
  * Copyright (C) 2023 salesforce.com, inc.
1020
1054
  */
1021
1055
  // @ts-ignore: Prevent cannot find name 'trustedTypes' error.
1022
1056
  const SUPPORTS_TRUSTED_TYPES = typeof trustedTypes !== 'undefined';
1023
- function createTrustedTypesPolicy(name, options) {
1057
+ const trustedTypePolicyRegistry = {
1058
+ __proto__: null
1059
+ };
1060
+ function createDuplicateSafeTrustedTypesPolicy(name, options) {
1061
+ // istanbul ignore next: not testable in coverage collection
1062
+ if (trustedTypePolicyRegistry[name]) {
1063
+ return trustedTypePolicyRegistry[name];
1064
+ }
1024
1065
  // @ts-ignore: Prevent cannot find name 'trustedTypes' error.
1025
- return trustedTypes.createPolicy(name, options);
1066
+ // eslint-disable-next-line no-return-assign
1067
+ return trustedTypePolicyRegistry[name] = trustedTypes.createPolicy(name, options);
1026
1068
  }
1027
- function createFallbackPolicy(_name, options) {
1028
- return options;
1069
+ function createDuplicateSafeFallbackPolicy(name, options) {
1070
+ if (trustedTypePolicyRegistry[name]) {
1071
+ return trustedTypePolicyRegistry[name];
1072
+ }
1073
+ // @ts-ignore: Prevent cannot find name 'trustedTypes' error.
1074
+ // eslint-disable-next-line no-return-assign
1075
+ return trustedTypePolicyRegistry[name] = options;
1029
1076
  }
1030
1077
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
1031
- const createPolicy = SUPPORTS_TRUSTED_TYPES ? createTrustedTypesPolicy : createFallbackPolicy;
1078
+ const createPolicy = SUPPORTS_TRUSTED_TYPES ? createDuplicateSafeTrustedTypesPolicy : createDuplicateSafeFallbackPolicy;
1032
1079
  const policyOptions = {
1033
1080
  createHTML(value) {
1034
1081
  return value;
@@ -1076,7 +1123,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1076
1123
  // swallow
1077
1124
  }
1078
1125
  const trusted = createPolicy('trusted', policyOptions);
1079
- /*! version: 0.23.6 */
1126
+ /*! version: 0.24.6 */
1080
1127
 
1081
1128
  /* global console,process */
1082
1129
 
@@ -1146,7 +1193,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1146
1193
  code = `${code}\n//# sourceURL=${id}`; // append sourceURL for debugging
1147
1194
  try {
1148
1195
  // TODO eval source maps for debugging
1149
- eval(trusted.createScript(code));
1196
+ eval(trusted.createScript(code) );
1150
1197
  } catch (e) {
1151
1198
  // eslint-disable-next-line lwr/no-unguarded-apis
1152
1199
  if (process.env.NODE_ENV !== 'production' && hasConsole) {
@@ -1190,7 +1237,7 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1190
1237
  });
1191
1238
  }
1192
1239
 
1193
- /* global console,process */
1240
+ /* global process console */
1194
1241
 
1195
1242
 
1196
1243
 
@@ -1237,13 +1284,20 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1237
1284
 
1238
1285
  class ModuleRegistry {
1239
1286
 
1287
+
1288
+ __init() {this.isAppMounted = false;}
1240
1289
 
1241
- constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);
1290
+ constructor(config) {ModuleRegistry.prototype.__init.call(this);ModuleRegistry.prototype.__init2.call(this);ModuleRegistry.prototype.__init3.call(this);ModuleRegistry.prototype.__init4.call(this);
1242
1291
  this.profiler = config.profiler;
1243
1292
  this.resolver = new ImportMetadataResolver(
1244
1293
  config,
1245
1294
  this.importMetadataInvalidationCallback.bind(this),
1246
1295
  );
1296
+ this.warnings = {
1297
+ [MODULE_WARNING.MODULE_REDEFINE]: [],
1298
+ [MODULE_WARNING.MODULE_ALREADY_LOADED]: [],
1299
+ [MODULE_WARNING.ALIAS_UPDATE]: [],
1300
+ };
1247
1301
  }
1248
1302
 
1249
1303
  async load(id, importer) {
@@ -1375,11 +1429,14 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1375
1429
  // eslint-disable-next-line lwr/no-unguarded-apis
1376
1430
  process.env.NODE_ENV !== 'production' &&
1377
1431
  // eslint-disable-next-line lwr/no-unguarded-apis
1378
- process.env.MRT_HMR !== 'true' &&
1379
- hasConsole
1432
+ process.env.MRT_HMR !== 'true'
1380
1433
  ) {
1381
- // eslint-disable-next-line lwr/no-unguarded-apis
1382
- console.warn(`Module redefine attempted: ${name}`);
1434
+ if (!this.warnings[MODULE_WARNING.MODULE_REDEFINE].includes(name)) {
1435
+ this.warnings[MODULE_WARNING.MODULE_REDEFINE].push(name);
1436
+ }
1437
+ if (this.isAppMounted) {
1438
+ this.logMessage('warning', `${MODULE_WARNING.MODULE_REDEFINE}: ${name}`);
1439
+ }
1383
1440
  }
1384
1441
  this.lastDefine = mod;
1385
1442
  return;
@@ -1433,9 +1490,13 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1433
1490
  };
1434
1491
  this.namedDefineRegistry.set(id, moduleDef );
1435
1492
  // 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);
1493
+ } else if (process.env.NODE_ENV !== 'production') {
1494
+ if (!this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].includes(id)) {
1495
+ this.warnings[MODULE_WARNING.MODULE_ALREADY_LOADED].push(id);
1496
+ }
1497
+ if (this.isAppMounted) {
1498
+ this.logMessage('warning', `${MODULE_WARNING.MODULE_ALREADY_LOADED}: ${id}`);
1499
+ }
1439
1500
  }
1440
1501
  });
1441
1502
  }
@@ -1443,13 +1504,13 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1443
1504
 
1444
1505
 
1445
1506
  // A registry for named AMD defines containing the *metadata* of AMD module
1446
- __init() {this.namedDefineRegistry = new Map();}
1507
+ __init2() {this.namedDefineRegistry = new Map();}
1447
1508
 
1448
1509
  // The evaluated module registry where the module identifier (name or URL?) is the key
1449
- __init2() {this.moduleRegistry = new Map();}
1510
+ __init3() {this.moduleRegistry = new Map();}
1450
1511
 
1451
1512
  // Aliases of modules in the registry
1452
- __init3() {this.aliases = new Map();}
1513
+ __init4() {this.aliases = new Map();}
1453
1514
 
1454
1515
 
1455
1516
 
@@ -1529,10 +1590,12 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1529
1590
  // Warn the user if they were not aliasing to the resolvedId
1530
1591
  const currentResolvedId = this.aliases.get(aliasId);
1531
1592
  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}`);
1593
+ const warningMsg = `${aliasId}=>${currentResolvedId}, ${resolvedId}`;
1594
+ if (!this.warnings[MODULE_WARNING.ALIAS_UPDATE].includes(warningMsg)) {
1595
+ this.warnings[MODULE_WARNING.ALIAS_UPDATE].push(warningMsg);
1596
+ }
1597
+ if (this.isAppMounted) {
1598
+ this.logMessage('warning', `${MODULE_WARNING.ALIAS_UPDATE}: ${warningMsg}`);
1536
1599
  }
1537
1600
  }
1538
1601
  }
@@ -1540,7 +1603,25 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1540
1603
  }
1541
1604
 
1542
1605
  async getModuleDependencyRecord(dependency) {
1543
- const resolvedDepId = await this.resolve(dependency);
1606
+ // Initially resolve the dependency to get its ID, which may be a bundle URL.
1607
+ let resolvedDepId = await this.resolve(dependency);
1608
+
1609
+ // If the resolved dependency ID is a URL, it indicates that the dependency
1610
+ // is provided by a bundle that hasn't been fully instantiated yet.
1611
+ if (isUrl(resolvedDepId)) {
1612
+ // Retrieve the module record corresponding to the bundle URL.
1613
+ const existingRecord = this.moduleRegistry.get(resolvedDepId);
1614
+
1615
+ // If a module record for the bundle exists and we haven't already created an alias for this dependency,
1616
+ // then the bundle is still pending instantiation.
1617
+ if (existingRecord && !this.aliases.has(dependency)) {
1618
+ // Wait for the bundle's instantiation promise to resolve.
1619
+ await existingRecord.instantiation;
1620
+ // After instantiation, re-resolve the dependency.
1621
+ // This should now return the final alias (the logical module ID) instead of the raw bundle URL.
1622
+ resolvedDepId = await this.resolve(dependency);
1623
+ }
1624
+ }
1544
1625
  return this.getModuleRecord(resolvedDepId, dependency);
1545
1626
  }
1546
1627
 
@@ -1845,6 +1926,28 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1845
1926
  res === null || typeof res === 'string' || (res && typeof (res ).url === 'string')
1846
1927
  );
1847
1928
  }
1929
+
1930
+ getModuleWarnings(isAppMounted = false) {
1931
+ this.isAppMounted = isAppMounted;
1932
+ return this.warnings;
1933
+ }
1934
+
1935
+ logMessage(logType, message) {
1936
+ if (
1937
+ !hasProcessEnv ||
1938
+ !hasConsole || // eslint-disable-next-line lwr/no-unguarded-apis
1939
+ process.env.NODE_ENV === 'production'
1940
+ ) {
1941
+ return;
1942
+ }
1943
+ if (logType == 'warning') {
1944
+ // eslint-disable-next-line lwr/no-unguarded-apis
1945
+ console.warn(message);
1946
+ } else {
1947
+ // eslint-disable-next-line lwr/no-unguarded-apis
1948
+ console.log(message);
1949
+ }
1950
+ }
1848
1951
  }
1849
1952
 
1850
1953
  /**
@@ -1978,6 +2081,10 @@ LWR.define('lwr/loader/v/0_17_2-alpha_2', ['exports'], (function (exports) { 'us
1978
2081
  registerExternalModules(modules) {
1979
2082
  this.registry.registerExternalModules(modules);
1980
2083
  }
2084
+
2085
+ getModuleWarnings(isAppMounted = false) {
2086
+ return this.registry.getModuleWarnings(isAppMounted);
2087
+ }
1981
2088
  }
1982
2089
 
1983
2090
  exports.Loader = Loader;