@lwrjs/everywhere 0.11.0-alpha.4 → 0.11.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.
Files changed (23) hide show
  1. package/build/__generated_site_amd_modules__/1/application/amd/l/en-US/ai/amd-bootstrap/configuration/ci/-/-/s/78b653169a5192c4659563d9bb43ccad/config.js +11 -0
  2. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/@lwrjs/app-service/amd-bootstrap/module/amd/v/0_11_0-alpha_7/s/625ff96e920182ae7ef5b87f02964e6c/@lwrjs_app-service_amd-bootstrap_module_amd.js +18 -0
  3. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwc/v/{3_1_3/s/5ecae4481a6009197f93d4b83392ccba → 3_2_0/s/ab8f5848cd7c307feeeb8a995ab42add}/lwc.js +84 -32
  4. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/everywhereAmd/v/{0_11_0-alpha_4 → 0_11_0-alpha_7}/s/cb931ebef2b89dcf8ab51456e3a68864/lwr_everywhereAmd.js +3 -3
  5. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/init/v/{0_11_0-alpha_4/s/5e6db37af51f0d23be4893abe5eeb913 → 0_11_0-alpha_7/s/f30361ad8ff7af505bf4d465c8499181}/lwr_init.js +23 -23
  6. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/loader/v/{0_11_0-alpha_4/s/9157743ef20db59d5719497d0e030f2c → 0_11_0-alpha_7/s/db2848f0cffe03ff0c6a3124c73dc736}/lwr_loader.js +52 -18
  7. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/metrics/v/{0_11_0-alpha_4/s/7a802ee7a2430244c1f66bce2c2eafef → 0_11_0-alpha_7/s/274c8343f810353bbad085a79709395f}/lwr_metrics.js +5 -1
  8. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/profiler/v/{0_11_0-alpha_4 → 0_11_0-alpha_7}/s/a152b8d35f12ca1b5147c5cd1ee155fb/lwr_profiler.js +1 -1
  9. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/vault/v/{0_11_0-alpha_4 → 0_11_0-alpha_7}/s/c92abd8c1fec2d7eff62e4b097abbe14/lwr_vault.js +1 -1
  10. package/build/__generated_site_amd_modules__/1/resource/amd/lwr-error-shim.js/v/{0_11_0-alpha_4 → 0_11_0-alpha_7}/lwr-error-shim.js +1 -1
  11. package/build/__generated_site_amd_modules__/1/resource/amd/lwr-loader-shim.bundle.js/v/{0_11_0-alpha_4 → 0_11_0-alpha_7}/lwr-loader-shim.bundle.js +82 -49
  12. package/build/assets/amd/lwr-everywhere-debug.js +82 -49
  13. package/build/assets/amd/lwr-everywhere-min.js +2 -2
  14. package/build/assets/amd/lwr-everywhere.js +82 -49
  15. package/build/assets/core/lwr-everywhere-debug.js +78 -45
  16. package/build/assets/core/lwr-everywhere-min.js +2 -2
  17. package/build/assets/core/lwr-everywhere.js +78 -45
  18. package/build/assets/esm/lwr-everywhere-debug.js +1 -1
  19. package/build/assets/esm/lwr-everywhere-min.js +1 -1
  20. package/build/assets/esm/lwr-everywhere.js +1 -1
  21. package/package.json +11 -9
  22. package/build/__generated_site_amd_modules__/1/application/amd/l/en-US/ai/amd-bootstrap/configuration/ci/-/-/s/cb9e50b5ee47462a86c0eac92c706258/config.js +0 -11
  23. package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/@lwrjs/app-service/amd-bootstrap/module/amd/v/0_11_0-alpha_4/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js +0 -18
@@ -1,4 +1,4 @@
1
- LWR.define('lwr/metrics/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'use strict';
1
+ LWR.define('lwr/metrics/v/0_11_0-alpha_7', ['exports'], (function (exports) { 'use strict';
2
2
 
3
3
  // Bootstrap / shim
4
4
  const BOOTSTRAP_PREFIX = 'lwr.bootstrap.';
@@ -18,6 +18,8 @@ LWR.define('lwr/metrics/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'u
18
18
  const LOADER_PREFIX = 'lwr.loader.';
19
19
  const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
20
20
  const MODULE_DEFINE_COUNT = `${MODULE_DEFINE}.count`;
21
+ const MODULE_DYNAMIC_LOAD = `${LOADER_PREFIX}moduleRegistry.dynamicLoad`;
22
+ const MODULE_DYNAMIC_LOAD_COUNT = `${MODULE_DYNAMIC_LOAD}.count`;
21
23
  const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
22
24
  const MODULE_FETCH_COUNT = `${MODULE_FETCH}.count`;
23
25
  const MODULE_FETCH_DURATION = `${MODULE_FETCH}.duration`;
@@ -59,6 +61,8 @@ LWR.define('lwr/metrics/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'u
59
61
  exports.MAPPINGS_FETCH_DURATION = MAPPINGS_FETCH_DURATION;
60
62
  exports.MODULE_DEFINE = MODULE_DEFINE;
61
63
  exports.MODULE_DEFINE_COUNT = MODULE_DEFINE_COUNT;
64
+ exports.MODULE_DYNAMIC_LOAD = MODULE_DYNAMIC_LOAD;
65
+ exports.MODULE_DYNAMIC_LOAD_COUNT = MODULE_DYNAMIC_LOAD_COUNT;
62
66
  exports.MODULE_ERROR = MODULE_ERROR;
63
67
  exports.MODULE_ERROR_COUNT = MODULE_ERROR_COUNT;
64
68
  exports.MODULE_FETCH = MODULE_FETCH;
@@ -1,4 +1,4 @@
1
- LWR.define('lwr/profiler/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'use strict';
1
+ LWR.define('lwr/profiler/v/0_11_0-alpha_7', ['exports'], (function (exports) { 'use strict';
2
2
 
3
3
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
4
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -1,4 +1,4 @@
1
- LWR.define('lwr/vault/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'use strict';
1
+ LWR.define('lwr/vault/v/0_11_0-alpha_7', ['exports'], (function (exports) { 'use strict';
2
2
 
3
3
  // Credential vault for storing setters and subscribers for OAuth info
4
4
  // This module is a SINGLETON and must be excluded from ESM bundling
@@ -4,6 +4,6 @@
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 Error Shim v0.11.0-alpha.4 */
7
+ /* LWR Error Shim v0.11.0-alpha.7 */
8
8
  !function(){"use strict";if(!(globalThis.LWR&&globalThis.LWR.define)){const o=new Error("The LWR application failed to bootstrap");if(!globalThis.LWR||!globalThis.LWR.onError)throw o;globalThis.LWR.onError(o)}}();
9
9
  //# sourceMappingURL=lwr-error-shim.js.map
@@ -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.11.0-alpha.4 */
7
+ /* LWR Module Loader Shim v0.11.0-alpha.7 */
8
8
  (function () {
9
9
  'use strict';
10
10
 
@@ -205,7 +205,7 @@
205
205
  // Parse configuration
206
206
  this.global = global;
207
207
  this.config = global.LWR ;
208
- this.loaderSpecifier = 'lwr/loader/v/0_11_0-alpha_4';
208
+ this.loaderSpecifier = 'lwr/loader/v/0_11_0-alpha_7';
209
209
 
210
210
  // Set up error handler
211
211
  this.errorHandler = this.config.onError;
@@ -325,12 +325,12 @@
325
325
  const exporter = (exports) => {
326
326
  Object.assign(exports, { logOperationStart, logOperationEnd });
327
327
  };
328
- globalLWR.define('lwr/profiler/v/0_11_0-alpha_4', ['exports'], exporter);
328
+ globalLWR.define('lwr/profiler/v/0_11_0-alpha_7', ['exports'], exporter);
329
329
  }
330
330
 
331
331
  // Set up the application globals, import map, root custom element...
332
332
  mountApp(loader) {
333
- const { bootstrapModule, rootComponent, rootComponents, ssrProps, endpoints, imports, index } =
333
+ const { bootstrapModule, rootComponent, rootComponents, serverData, endpoints, imports, index } =
334
334
  this.config;
335
335
 
336
336
  // Set global LWR.define to loader.define
@@ -338,7 +338,7 @@
338
338
  define: loader.define.bind(loader),
339
339
  rootComponent,
340
340
  rootComponents,
341
- ssrProps,
341
+ serverData,
342
342
  endpoints,
343
343
  imports: imports || {},
344
344
  index: index || {},
@@ -397,15 +397,15 @@
397
397
  // The loader module is ALWAYS required
398
398
  const GLOBAL = globalThis ;
399
399
  GLOBAL.LWR.requiredModules = GLOBAL.LWR.requiredModules || [];
400
- if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_11_0-alpha_4') < 0) {
401
- GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_11_0-alpha_4');
400
+ if (GLOBAL.LWR.requiredModules.indexOf('lwr/loader/v/0_11_0-alpha_7') < 0) {
401
+ GLOBAL.LWR.requiredModules.push('lwr/loader/v/0_11_0-alpha_7');
402
402
  }
403
403
  new LoaderShim(GLOBAL);
404
404
 
405
405
  })();
406
406
  //# sourceMappingURL=lwr-loader-shim.js.map
407
407
 
408
- LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'use strict';
408
+ LWR.define('lwr/loader/v/0_11_0-alpha_7', ['exports'], (function (exports) { 'use strict';
409
409
 
410
410
  const templateRegex = /\{([0-9]+)\}/g;
411
411
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -530,6 +530,11 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
530
530
  level: 0,
531
531
  message: 'Invalid import metadata: {0} {1}',
532
532
  });
533
+ const EXPORTER_ERROR = Object.freeze({
534
+ code: 3021,
535
+ level: 0,
536
+ message: 'Error evaluating module "{0}", error was "{1}"',
537
+ });
533
538
 
534
539
  /* importMap errors */
535
540
  Object.freeze({
@@ -726,6 +731,7 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
726
731
  // Loader: modules
727
732
  const LOADER_PREFIX = 'lwr.loader.';
728
733
  const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
734
+ const MODULE_DYNAMIC_LOAD = `${LOADER_PREFIX}moduleRegistry.dynamicLoad`;
729
735
  const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
730
736
  const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
731
737
 
@@ -1086,7 +1092,7 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1086
1092
 
1087
1093
  async function evaluateLoadHookResponse(response, id) {
1088
1094
  return Promise.resolve().then(async () => {
1089
- if (!response.status) {
1095
+ if (!response || !response.status) {
1090
1096
  throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
1091
1097
  }
1092
1098
  if (response.status !== 200) {
@@ -1113,6 +1119,10 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1113
1119
  // TODO eval source maps for debugging
1114
1120
  eval(trusted.createScript(code));
1115
1121
  } catch (e) {
1122
+ if (process.env.NODE_ENV !== 'production' && hasConsole) {
1123
+ // eslint-disable-next-line lwr/no-unguarded-apis
1124
+ console.error(e);
1125
+ }
1116
1126
  throw new LoaderError(FAIL_LOAD, [id]);
1117
1127
  }
1118
1128
 
@@ -1193,7 +1203,6 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1193
1203
 
1194
1204
 
1195
1205
 
1196
-
1197
1206
 
1198
1207
 
1199
1208
  class ModuleRegistry {
@@ -1208,8 +1217,14 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1208
1217
  }
1209
1218
 
1210
1219
  async load(id, importer) {
1220
+ const metadata = importer ? { importer } : {};
1221
+ this.profiler.logOperationStart({
1222
+ id: MODULE_DYNAMIC_LOAD,
1223
+ specifier: id,
1224
+ metadata,
1225
+ });
1211
1226
  const resolvedId = await this.resolve(id, importer);
1212
- const moduleRecord = this.getModuleRecord(resolvedId, id);
1227
+ const moduleRecord = await this.getModuleRecord(resolvedId, id);
1213
1228
  if (moduleRecord.evaluated) {
1214
1229
  return moduleRecord.module;
1215
1230
  } else {
@@ -1283,6 +1298,8 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1283
1298
  // return the plain id if it is already defined && the resolvedUrl is NOT already in the module registry
1284
1299
  if (
1285
1300
  this.namedDefineRegistry.has(resolvedOrPlain) &&
1301
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1302
+ // @ts-ignore has check right above
1286
1303
  this.namedDefineRegistry.get(resolvedOrPlain).defined
1287
1304
  ) {
1288
1305
  const record = this.moduleRegistry.get(resolvedUrl);
@@ -1423,7 +1440,7 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1423
1440
  return moduleRecord;
1424
1441
  }
1425
1442
 
1426
- getModuleRecord(resolvedId, id) {
1443
+ async getModuleRecord(resolvedId, id) {
1427
1444
  // Look for an existing record
1428
1445
  const existingRecord = this.getExistingModuleRecord(resolvedId, id);
1429
1446
  if (existingRecord) {
@@ -1434,7 +1451,7 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1434
1451
  // Create a new Module Record
1435
1452
  const instantiation = this.getModuleDef(resolvedId, id);
1436
1453
  const dependencyRecords = instantiation.then((moduleDef) => {
1437
- const dependencies = moduleDef.dependencies;
1454
+ const dependencies = moduleDef.dependencies || [];
1438
1455
  // get dep and filter out exports
1439
1456
  const filtered = dependencies
1440
1457
  .map((dep) => {
@@ -1460,7 +1477,9 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1460
1477
 
1461
1478
  this.moduleRegistry.set(resolvedId, newModuleRecord);
1462
1479
  this.storeModuleAlias(id, resolvedId);
1463
- return newModuleRecord;
1480
+
1481
+ // Wait for the dependencies to resolve the return the moduleRecord
1482
+ return dependencyRecords.then(() => newModuleRecord);
1464
1483
  }
1465
1484
 
1466
1485
  storeModuleAlias(aliasId, resolvedId) {
@@ -1472,7 +1491,10 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1472
1491
  const currentResolvedId = this.aliases.get(aliasId);
1473
1492
  if (currentResolvedId !== resolvedId) {
1474
1493
  // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
1475
- console.warn(`Alias update attempt: ${aliasId}=>${currentResolvedId}, ${resolvedId}`);
1494
+ if (process.env.NODE_ENV !== 'production' && hasConsole) {
1495
+ // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
1496
+ console.warn(`Alias update attempt: ${aliasId}=>${currentResolvedId}, ${resolvedId}`);
1497
+ }
1476
1498
  }
1477
1499
  }
1478
1500
  }
@@ -1521,37 +1543,39 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1521
1543
  const { exporter, dependencies } = await moduleRecord.instantiation;
1522
1544
  // The exports object automatically gets filled in by the exporter evaluation
1523
1545
  const exports = {};
1524
- const depsMapped = await Promise.all(
1525
- dependencies.map(async (dep) => {
1526
- if (dep === 'exports') {
1527
- return exports;
1528
- }
1529
- const resolvedDepId = await this.resolve(dep);
1530
-
1531
- const moduleRecord = this.moduleRegistry.get(resolvedDepId) ;
1532
- if (!moduleRecord) {
1533
- throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1534
- }
1535
-
1536
- const module = moduleRecord.module;
1537
-
1538
- /**
1539
- * Circular dependencies are handled properly when named exports are used,
1540
- * however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
1541
- *
1542
- * The workaround below applies for circular dependencies (!moduleRecord.evaluated)
1543
- */
1544
- if (!moduleRecord.evaluated) {
1545
- return this.getCircularDependencyWrapper(module);
1546
- }
1547
-
1548
- if (module) {
1549
- return module.__defaultInterop ? module.default : module;
1550
- }
1551
-
1552
- throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1553
- }),
1554
- );
1546
+ const depsMapped = dependencies
1547
+ ? await Promise.all(
1548
+ dependencies.map(async (dep) => {
1549
+ if (dep === 'exports') {
1550
+ return exports;
1551
+ }
1552
+ const resolvedDepId = await this.resolve(dep);
1553
+
1554
+ const moduleRecord = this.moduleRegistry.get(resolvedDepId) ;
1555
+ if (!moduleRecord) {
1556
+ throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1557
+ }
1558
+
1559
+ const module = moduleRecord.module;
1560
+
1561
+ /**
1562
+ * Circular dependencies are handled properly when named exports are used,
1563
+ * however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
1564
+ *
1565
+ * The workaround below applies for circular dependencies (!moduleRecord.evaluated)
1566
+ */
1567
+ if (!moduleRecord.evaluated) {
1568
+ return this.getCircularDependencyWrapper(module);
1569
+ }
1570
+
1571
+ if (module) {
1572
+ return module.__defaultInterop ? module.default : module;
1573
+ }
1574
+
1575
+ throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1576
+ }),
1577
+ )
1578
+ : [];
1555
1579
 
1556
1580
  // 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
1557
1581
  if (moduleRecord.evaluated) {
@@ -1559,8 +1583,12 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1559
1583
  }
1560
1584
 
1561
1585
  // evaluates the module function
1562
- let moduleDefault = exporter(...depsMapped);
1563
-
1586
+ let moduleDefault;
1587
+ try {
1588
+ moduleDefault = exporter(...depsMapped);
1589
+ } catch (e) {
1590
+ throw new LoaderError(EXPORTER_ERROR, [moduleRecord.id, e.message || e]);
1591
+ }
1564
1592
  // value is returned from exporter, then we are not using named exports
1565
1593
  if (moduleDefault !== undefined) {
1566
1594
  moduleDefault = { default: moduleDefault };
@@ -1709,7 +1737,12 @@ LWR.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (function (exports) { 'us
1709
1737
  return moduleDef;
1710
1738
  })
1711
1739
  .catch((e) => {
1712
- this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
1740
+ // Create module error marks for all errors caused by the loader
1741
+ // Note: these marks do not include errors caused by invalid server responses or loader hooks
1742
+ if (!(e instanceof LoaderError)) {
1743
+ this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
1744
+ }
1745
+
1713
1746
  throw e;
1714
1747
  });
1715
1748
  }
@@ -20,7 +20,7 @@ function getConfiguration(options) {
20
20
  : `${ORIGIN}${PREFIX}/module/${format}/${POSTFIX}/mi/`;
21
21
 
22
22
  // Component specifiers and URIs
23
- const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_11_0-alpha_4`;
23
+ const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_11_0-alpha_7`;
24
24
  const BOOT_URI = `${ENDPOINT}${encodeURIComponent(BOOT_MODULE)}/latest${debug ? '?debug' : ''}`;
25
25
 
26
26
  // Client Bootstrap Config
@@ -52,7 +52,7 @@ function getConfiguration(options) {
52
52
  * SPDX-License-Identifier: MIT
53
53
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
54
54
  */
55
- /* LWR Module Loader v0.11.0-alpha.4 */
55
+ /* LWR Module Loader v0.11.0-alpha.7 */
56
56
  const templateRegex = /\{([0-9]+)\}/g;
57
57
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
58
  function templateString(template, args) {
@@ -176,6 +176,11 @@ const BAD_IMPORT_METADATA = Object.freeze({
176
176
  level: 0,
177
177
  message: 'Invalid import metadata: {0} {1}',
178
178
  });
179
+ const EXPORTER_ERROR = Object.freeze({
180
+ code: 3021,
181
+ level: 0,
182
+ message: 'Error evaluating module "{0}", error was "{1}"',
183
+ });
179
184
 
180
185
  /* importMap errors */
181
186
  Object.freeze({
@@ -372,6 +377,7 @@ if (hasDocument) {
372
377
  // Loader: modules
373
378
  const LOADER_PREFIX = 'lwr.loader.';
374
379
  const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
380
+ const MODULE_DYNAMIC_LOAD = `${LOADER_PREFIX}moduleRegistry.dynamicLoad`;
375
381
  const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
376
382
  const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
377
383
 
@@ -732,7 +738,7 @@ function isResponseAPromise(
732
738
 
733
739
  async function evaluateLoadHookResponse(response, id) {
734
740
  return Promise.resolve().then(async () => {
735
- if (!response.status) {
741
+ if (!response || !response.status) {
736
742
  throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
737
743
  }
738
744
  if (response.status !== 200) {
@@ -759,6 +765,10 @@ async function evaluateLoadHookResponse(response, id) {
759
765
  // TODO eval source maps for debugging
760
766
  eval(trusted.createScript(code));
761
767
  } catch (e) {
768
+ if (process.env.NODE_ENV !== 'production' && hasConsole) {
769
+ // eslint-disable-next-line lwr/no-unguarded-apis
770
+ console.error(e);
771
+ }
762
772
  throw new LoaderError(FAIL_LOAD, [id]);
763
773
  }
764
774
 
@@ -839,7 +849,6 @@ async function evaluateLoadHook(
839
849
 
840
850
 
841
851
 
842
-
843
852
 
844
853
 
845
854
  class ModuleRegistry {
@@ -854,8 +863,14 @@ class ModuleRegistry {
854
863
  }
855
864
 
856
865
  async load(id, importer) {
866
+ const metadata = importer ? { importer } : {};
867
+ this.profiler.logOperationStart({
868
+ id: MODULE_DYNAMIC_LOAD,
869
+ specifier: id,
870
+ metadata,
871
+ });
857
872
  const resolvedId = await this.resolve(id, importer);
858
- const moduleRecord = this.getModuleRecord(resolvedId, id);
873
+ const moduleRecord = await this.getModuleRecord(resolvedId, id);
859
874
  if (moduleRecord.evaluated) {
860
875
  return moduleRecord.module;
861
876
  } else {
@@ -929,6 +944,8 @@ class ModuleRegistry {
929
944
  // return the plain id if it is already defined && the resolvedUrl is NOT already in the module registry
930
945
  if (
931
946
  this.namedDefineRegistry.has(resolvedOrPlain) &&
947
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
948
+ // @ts-ignore has check right above
932
949
  this.namedDefineRegistry.get(resolvedOrPlain).defined
933
950
  ) {
934
951
  const record = this.moduleRegistry.get(resolvedUrl);
@@ -1069,7 +1086,7 @@ class ModuleRegistry {
1069
1086
  return moduleRecord;
1070
1087
  }
1071
1088
 
1072
- getModuleRecord(resolvedId, id) {
1089
+ async getModuleRecord(resolvedId, id) {
1073
1090
  // Look for an existing record
1074
1091
  const existingRecord = this.getExistingModuleRecord(resolvedId, id);
1075
1092
  if (existingRecord) {
@@ -1080,7 +1097,7 @@ class ModuleRegistry {
1080
1097
  // Create a new Module Record
1081
1098
  const instantiation = this.getModuleDef(resolvedId, id);
1082
1099
  const dependencyRecords = instantiation.then((moduleDef) => {
1083
- const dependencies = moduleDef.dependencies;
1100
+ const dependencies = moduleDef.dependencies || [];
1084
1101
  // get dep and filter out exports
1085
1102
  const filtered = dependencies
1086
1103
  .map((dep) => {
@@ -1106,7 +1123,9 @@ class ModuleRegistry {
1106
1123
 
1107
1124
  this.moduleRegistry.set(resolvedId, newModuleRecord);
1108
1125
  this.storeModuleAlias(id, resolvedId);
1109
- return newModuleRecord;
1126
+
1127
+ // Wait for the dependencies to resolve the return the moduleRecord
1128
+ return dependencyRecords.then(() => newModuleRecord);
1110
1129
  }
1111
1130
 
1112
1131
  storeModuleAlias(aliasId, resolvedId) {
@@ -1118,7 +1137,10 @@ class ModuleRegistry {
1118
1137
  const currentResolvedId = this.aliases.get(aliasId);
1119
1138
  if (currentResolvedId !== resolvedId) {
1120
1139
  // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
1121
- console.warn(`Alias update attempt: ${aliasId}=>${currentResolvedId}, ${resolvedId}`);
1140
+ if (process.env.NODE_ENV !== 'production' && hasConsole) {
1141
+ // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
1142
+ console.warn(`Alias update attempt: ${aliasId}=>${currentResolvedId}, ${resolvedId}`);
1143
+ }
1122
1144
  }
1123
1145
  }
1124
1146
  }
@@ -1167,37 +1189,39 @@ class ModuleRegistry {
1167
1189
  const { exporter, dependencies } = await moduleRecord.instantiation;
1168
1190
  // The exports object automatically gets filled in by the exporter evaluation
1169
1191
  const exports = {};
1170
- const depsMapped = await Promise.all(
1171
- dependencies.map(async (dep) => {
1172
- if (dep === 'exports') {
1173
- return exports;
1174
- }
1175
- const resolvedDepId = await this.resolve(dep);
1176
-
1177
- const moduleRecord = this.moduleRegistry.get(resolvedDepId) ;
1178
- if (!moduleRecord) {
1179
- throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1180
- }
1181
-
1182
- const module = moduleRecord.module;
1183
-
1184
- /**
1185
- * Circular dependencies are handled properly when named exports are used,
1186
- * however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
1187
- *
1188
- * The workaround below applies for circular dependencies (!moduleRecord.evaluated)
1189
- */
1190
- if (!moduleRecord.evaluated) {
1191
- return this.getCircularDependencyWrapper(module);
1192
- }
1193
-
1194
- if (module) {
1195
- return module.__defaultInterop ? module.default : module;
1196
- }
1197
-
1198
- throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1199
- }),
1200
- );
1192
+ const depsMapped = dependencies
1193
+ ? await Promise.all(
1194
+ dependencies.map(async (dep) => {
1195
+ if (dep === 'exports') {
1196
+ return exports;
1197
+ }
1198
+ const resolvedDepId = await this.resolve(dep);
1199
+
1200
+ const moduleRecord = this.moduleRegistry.get(resolvedDepId) ;
1201
+ if (!moduleRecord) {
1202
+ throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1203
+ }
1204
+
1205
+ const module = moduleRecord.module;
1206
+
1207
+ /**
1208
+ * Circular dependencies are handled properly when named exports are used,
1209
+ * however, for default exports there is a bug: https://github.com/rollup/rollup/issues/3384
1210
+ *
1211
+ * The workaround below applies for circular dependencies (!moduleRecord.evaluated)
1212
+ */
1213
+ if (!moduleRecord.evaluated) {
1214
+ return this.getCircularDependencyWrapper(module);
1215
+ }
1216
+
1217
+ if (module) {
1218
+ return module.__defaultInterop ? module.default : module;
1219
+ }
1220
+
1221
+ throw new LoaderError(FAILED_DEP, [resolvedDepId]);
1222
+ }),
1223
+ )
1224
+ : [];
1201
1225
 
1202
1226
  // 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
1203
1227
  if (moduleRecord.evaluated) {
@@ -1205,8 +1229,12 @@ class ModuleRegistry {
1205
1229
  }
1206
1230
 
1207
1231
  // evaluates the module function
1208
- let moduleDefault = exporter(...depsMapped);
1209
-
1232
+ let moduleDefault;
1233
+ try {
1234
+ moduleDefault = exporter(...depsMapped);
1235
+ } catch (e) {
1236
+ throw new LoaderError(EXPORTER_ERROR, [moduleRecord.id, e.message || e]);
1237
+ }
1210
1238
  // value is returned from exporter, then we are not using named exports
1211
1239
  if (moduleDefault !== undefined) {
1212
1240
  moduleDefault = { default: moduleDefault };
@@ -1355,7 +1383,12 @@ class ModuleRegistry {
1355
1383
  return moduleDef;
1356
1384
  })
1357
1385
  .catch((e) => {
1358
- this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
1386
+ // Create module error marks for all errors caused by the loader
1387
+ // Note: these marks do not include errors caused by invalid server responses or loader hooks
1388
+ if (!(e instanceof LoaderError)) {
1389
+ this.profiler.logOperationStart({ id: MODULE_ERROR, specifier });
1390
+ }
1391
+
1359
1392
  throw e;
1360
1393
  });
1361
1394
  }
@@ -1564,7 +1597,7 @@ const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration;
1564
1597
 
1565
1598
  // Initialize the AMD loader (its code is bundled into the LWR Everywhere module)
1566
1599
  const loader = new Loader({ endpoints, baseUrl });
1567
- loader.define('lwr/loader/v/0_11_0-alpha_4', ['exports'], (exports) => {
1600
+ loader.define('lwr/loader/v/0_11_0-alpha_7', ['exports'], (exports) => {
1568
1601
  Object.assign(exports, {
1569
1602
  define: loader.define.bind(loader),
1570
1603
  load: loader.load.bind(loader),
@@ -1574,12 +1607,12 @@ await loader.registerImportMappings({ imports, index }, [bootstrapModule]);
1574
1607
  (globalThis ).LWR = Object.freeze({ define: loader.define.bind(loader) });
1575
1608
 
1576
1609
  // Define preload modules (ie: ABS, vault, etc) BEFORE loading them
1577
- LWR.define('lwr/everywhereAmd/v/0_11_0-alpha_4', ['exports', 'lwr/vault/v/0_11_0-alpha_4'], (function (exports, _0_11_0Alpha_4) {
1610
+ LWR.define('lwr/everywhereAmd/v/0_11_0-alpha_7', ['exports', 'lwr/vault/v/0_11_0-alpha_7'], (function (exports, _0_11_0Alpha_7) {
1578
1611
  // IMPORTANT: Do not add any static imports to this file that are not bundled with the amd-client
1579
1612
 
1580
1613
  // Do an OAuthed fetch
1581
1614
  async function authFetch(url, accept = 'javascript') {
1582
- const authInfo = _0_11_0Alpha_4.getAuthInfo();
1615
+ const authInfo = _0_11_0Alpha_7.getAuthInfo();
1583
1616
  if (authInfo) {
1584
1617
  return fetch(url, {
1585
1618
  headers: {
@@ -1629,7 +1662,7 @@ LWR.define('lwr/everywhereAmd/v/0_11_0-alpha_4', ['exports', 'lwr/vault/v/0_11_0
1629
1662
  function authenticate(authInfo) {
1630
1663
  // Put OAuth info into the vault
1631
1664
  if (authInfo) {
1632
- _0_11_0Alpha_4.setAuthInfo(authInfo);
1665
+ _0_11_0Alpha_7.setAuthInfo(authInfo);
1633
1666
  }
1634
1667
  }
1635
1668
 
@@ -1639,7 +1672,7 @@ LWR.define('lwr/everywhereAmd/v/0_11_0-alpha_4', ['exports', 'lwr/vault/v/0_11_0
1639
1672
  Object.defineProperty(exports, '__esModule', { value: true });
1640
1673
 
1641
1674
  }));
1642
- LWR.define('lwr/vault/v/0_11_0-alpha_4', ['exports'], (function (exports) {
1675
+ LWR.define('lwr/vault/v/0_11_0-alpha_7', ['exports'], (function (exports) {
1643
1676
  // Credential vault for storing setters and subscribers for OAuth info
1644
1677
  // This module is a SINGLETON and must be excluded from ESM bundling
1645
1678
 
@@ -1663,7 +1696,7 @@ LWR.define('lwr/vault/v/0_11_0-alpha_4', ['exports'], (function (exports) {
1663
1696
 
1664
1697
  // Set up the AMD loader hooks for OAuth
1665
1698
  const { initAmd, authenticate } = await loader.load(bootstrapModule);
1666
- initAmd(loader.services, _optionalChain([endpoints, 'optionalAccess', _ => _.uris, 'access', _2 => _2.mapping]), '0_11_0-alpha_4');
1699
+ initAmd(loader.services, _optionalChain([endpoints, 'optionalAccess', _ => _.uris, 'access', _2 => _2.mapping]), '0_11_0-alpha_7');
1667
1700
 
1668
1701
  // Wrap the createComponent API to allow proper ordering of module definitions:
1669
1702
  // 1. LWRE module bundle (this): lwr/loader, lwr/everywhereAmd, lwr/vault