@lwrjs/loader 0.13.0-alpha.2 → 0.13.0-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 (119) hide show
  1. package/build/assets/prod/lwr-error-shim.js +2 -2
  2. package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +34 -29
  3. package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +3 -3
  4. package/build/assets/prod/lwr-loader-shim-legacy.js +21 -16
  5. package/build/assets/prod/lwr-loader-shim.bundle.js +45 -23
  6. package/build/assets/prod/lwr-loader-shim.bundle.min.js +3 -3
  7. package/build/assets/prod/lwr-loader-shim.js +27 -12
  8. package/build/bundle/prod/lwr/esmLoader/esmLoader.js +1 -1
  9. package/build/cjs/index.cjs +28 -1
  10. package/build/cjs/modules/lwr/esmLoader/esmLoader.cjs +2 -2
  11. package/build/cjs/modules/lwr/esmLoader/importResolver.cjs +0 -17
  12. package/build/cjs/modules/lwr/esmLoader/importResolverLegacy.cjs +1 -18
  13. package/build/cjs/modules/lwr/loader/errors/messages.cjs +7 -1
  14. package/build/cjs/modules/lwr/loader/errors/reportError.cjs +1 -2
  15. package/build/cjs/modules/lwr/loader/hooks/moduleInvalidation.cjs +2 -3
  16. package/build/cjs/modules/lwr/loader/hooks/resolveAndLoadHook.cjs +3 -4
  17. package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +7 -6
  18. package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +8 -10
  19. package/build/cjs/modules/lwr/loader/moduleRegistry/scriptLoad.cjs +2 -2
  20. package/build/cjs/modules/lwr/loader/utils/url.cjs +1 -1
  21. package/build/cjs/modules/lwr/loaderLegacy/errors/messages.cjs +1 -1
  22. package/build/cjs/modules/lwr/loaderLegacy/errors/reportError.cjs +1 -2
  23. package/build/cjs/modules/lwr/loaderLegacy/hooks/moduleInvalidation.cjs +2 -3
  24. package/build/cjs/modules/lwr/loaderLegacy/hooks/resolveAndLoadHook.cjs +3 -4
  25. package/build/cjs/modules/lwr/loaderLegacy/importMap/dom.cjs +4 -4
  26. package/build/cjs/modules/lwr/loaderLegacy/importMap/importMap.cjs +2 -2
  27. package/build/cjs/modules/lwr/loaderLegacy/importMap/importMapResolver.cjs +1 -2
  28. package/build/cjs/modules/lwr/loaderLegacy/importMap/utils.cjs +1 -1
  29. package/build/cjs/modules/lwr/loaderLegacy/importResolver/importResolver.cjs +0 -17
  30. package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +7 -10
  31. package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/scriptLoad.cjs +2 -2
  32. package/build/cjs/modules/lwr/loaderLegacy/utils/url.cjs +1 -1
  33. package/build/cjs/package.d.cjs +0 -0
  34. package/build/cjs/types.cjs +5 -0
  35. package/build/error-shim/index.d.ts +2 -0
  36. package/build/error-shim/index.js +17 -0
  37. package/build/index.d.ts +1 -1
  38. package/build/index.js +28 -1
  39. package/build/modules/lwr/esmLoader/esmLoader.d.ts +6 -0
  40. package/build/modules/lwr/esmLoader/esmLoader.js +2 -2
  41. package/build/modules/lwr/esmLoader/importResolver.d.ts +17 -0
  42. package/build/modules/lwr/esmLoader/importResolver.js +47 -0
  43. package/build/modules/lwr/esmLoader/importResolverLegacy.d.ts +16 -0
  44. package/build/modules/lwr/esmLoader/importResolverLegacy.js +18 -0
  45. package/build/modules/lwr/loader/constants/constants.d.ts +2 -0
  46. package/build/modules/lwr/loader/constants/constants.js +2 -0
  47. package/build/modules/lwr/loader/errors/messages.d.ts +33 -0
  48. package/build/modules/lwr/loader/errors/messages.js +128 -0
  49. package/build/modules/lwr/loader/errors/reportError.d.ts +4 -0
  50. package/build/modules/lwr/loader/errors/reportError.js +9 -0
  51. package/build/modules/lwr/loader/errors/utils.d.ts +2 -0
  52. package/build/modules/lwr/loader/errors/utils.js +8 -0
  53. package/build/modules/lwr/loader/hooks/moduleInvalidation.d.ts +3 -0
  54. package/build/modules/lwr/loader/hooks/moduleInvalidation.js +19 -0
  55. package/build/modules/lwr/loader/hooks/resolveAndLoadHook.d.ts +7 -0
  56. package/build/modules/lwr/loader/hooks/resolveAndLoadHook.js +94 -0
  57. package/build/modules/lwr/loader/loader.d.ts +53 -0
  58. package/build/modules/lwr/loader/loader.js +18 -11
  59. package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.d.ts +44 -0
  60. package/build/modules/lwr/loader/moduleRegistry/importMetadataResolver.js +211 -0
  61. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.d.ts +47 -0
  62. package/build/modules/lwr/loader/moduleRegistry/moduleRegistry.js +530 -0
  63. package/build/modules/lwr/loader/moduleRegistry/scriptLoad.d.ts +3 -0
  64. package/build/modules/lwr/loader/moduleRegistry/scriptLoad.js +43 -0
  65. package/build/modules/lwr/loader/utils/dom.d.ts +4 -0
  66. package/build/modules/lwr/loader/utils/dom.js +6 -0
  67. package/build/modules/lwr/loader/utils/url.d.ts +28 -0
  68. package/build/modules/lwr/loader/utils/url.js +128 -0
  69. package/build/modules/lwr/loaderLegacy/constants/constants.d.ts +2 -0
  70. package/build/modules/lwr/loaderLegacy/constants/constants.js +2 -0
  71. package/build/modules/lwr/loaderLegacy/errors/messages.d.ts +30 -0
  72. package/build/modules/lwr/loaderLegacy/errors/messages.js +113 -0
  73. package/build/modules/lwr/loaderLegacy/errors/reportError.d.ts +4 -0
  74. package/build/modules/lwr/loaderLegacy/errors/reportError.js +9 -0
  75. package/build/modules/lwr/loaderLegacy/errors/utils.d.ts +2 -0
  76. package/build/modules/lwr/loaderLegacy/errors/utils.js +8 -0
  77. package/build/modules/lwr/loaderLegacy/hooks/moduleInvalidation.d.ts +3 -0
  78. package/build/modules/lwr/loaderLegacy/hooks/moduleInvalidation.js +19 -0
  79. package/build/modules/lwr/loaderLegacy/hooks/resolveAndLoadHook.d.ts +7 -0
  80. package/build/modules/lwr/loaderLegacy/hooks/resolveAndLoadHook.js +94 -0
  81. package/build/modules/lwr/loaderLegacy/importMap/dom.d.ts +10 -0
  82. package/build/modules/lwr/loaderLegacy/importMap/dom.js +63 -0
  83. package/build/modules/lwr/loaderLegacy/importMap/importMap.d.ts +22 -0
  84. package/build/modules/lwr/loaderLegacy/importMap/importMap.js +108 -0
  85. package/build/modules/lwr/loaderLegacy/importMap/importMapResolver.d.ts +8 -0
  86. package/build/modules/lwr/loaderLegacy/importMap/importMapResolver.js +11 -0
  87. package/build/modules/lwr/loaderLegacy/importMap/utils.d.ts +4 -0
  88. package/build/modules/lwr/loaderLegacy/importMap/utils.js +23 -0
  89. package/build/modules/lwr/loaderLegacy/importResolver/importResolver.d.ts +6 -0
  90. package/build/modules/lwr/loaderLegacy/importResolver/importResolver.js +2 -0
  91. package/build/modules/lwr/loaderLegacy/loaderLegacy.d.ts +57 -0
  92. package/build/modules/lwr/loaderLegacy/loaderLegacy.js +13 -13
  93. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.d.ts +53 -0
  94. package/build/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.js +544 -0
  95. package/build/modules/lwr/loaderLegacy/moduleRegistry/scriptLoad.d.ts +3 -0
  96. package/build/modules/lwr/loaderLegacy/moduleRegistry/scriptLoad.js +43 -0
  97. package/build/modules/lwr/loaderLegacy/utils/dom.d.ts +4 -0
  98. package/build/modules/lwr/loaderLegacy/utils/dom.js +6 -0
  99. package/build/modules/lwr/loaderLegacy/utils/url.d.ts +28 -0
  100. package/build/modules/lwr/loaderLegacy/utils/url.js +128 -0
  101. package/build/shim/constants.d.ts +2 -0
  102. package/build/shim/constants.js +2 -0
  103. package/build/shim/customInit.d.ts +4 -0
  104. package/build/shim/customInit.js +29 -0
  105. package/build/shim/index.d.ts +2 -0
  106. package/build/shim/index.js +9 -0
  107. package/build/shim/loader.d.ts +3 -0
  108. package/build/shim/loader.js +27 -0
  109. package/build/shim/shim.d.ts +31 -0
  110. package/build/shim/shim.js +194 -0
  111. package/build/shim-legacy/index.d.ts +2 -0
  112. package/build/shim-legacy/index.js +9 -0
  113. package/build/shim-legacy/loaderLegacy.d.ts +3 -0
  114. package/build/shim-legacy/loaderLegacy.js +29 -0
  115. package/build/shim-legacy/shimLegacy.d.ts +31 -0
  116. package/build/shim-legacy/shimLegacy.js +188 -0
  117. package/build/types.d.ts +56 -0
  118. package/build/types.js +2 -0
  119. package/package.json +9 -10
@@ -0,0 +1,4 @@
1
+ declare function getMatch(path: string, matchObj: Record<string, unknown>): string | undefined;
2
+ declare function targetWarning(match: string, target: string, msg: string): void;
3
+ export { getMatch, targetWarning };
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { hasConsole } from '../utils/dom.js';
2
+ // find the longest set of segments from path which are a key in matchObj
3
+ // eg: getMatch('/a/b/c', { '/a/b': ..., '/a': ..., '/d/e/f': ...}) => '/a/b'
4
+ function getMatch(path, matchObj) {
5
+ if (matchObj[path]) {
6
+ return path;
7
+ }
8
+ let sepIndex = path.length;
9
+ do {
10
+ const segment = path.slice(0, sepIndex + 1);
11
+ if (segment in matchObj) {
12
+ return segment;
13
+ }
14
+ } while (path.length > 1 && (sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
15
+ }
16
+ function targetWarning(match, target, msg) {
17
+ if (hasConsole) {
18
+ // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
19
+ console.warn('Package target ' + msg + ", resolving target '" + target + "' for " + match);
20
+ }
21
+ }
22
+ export { getMatch, targetWarning };
23
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,6 @@
1
+ import type { ImportDefinition, ImportMap } from '../importMap/importMap.js';
2
+ export interface ImportResolver {
3
+ importMap: ImportMap;
4
+ resolve(resolvedOrPlain: string, parentUrl: string): ImportDefinition | undefined;
5
+ }
6
+ //# sourceMappingURL=importResolver.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=importResolver.js.map
@@ -0,0 +1,57 @@
1
+ import { Module, ModuleDefinitionSignatures } from './moduleRegistry/moduleRegistry.js';
2
+ import { ImportMap } from './importMap/importMap.js';
3
+ import type { ServiceAPI } from '@lwrjs/types';
4
+ import type { LoaderConfig } from '../../../types.js';
5
+ /**
6
+ * The LWR loader is inspired and borrows from the algorithms and native browser principles of https://github.com/systemjs/systemjs
7
+ */
8
+ export declare class Loader {
9
+ private registry;
10
+ private baseUrl;
11
+ readonly services: Readonly<Pick<ServiceAPI, 'addLoaderPlugin' | 'handleStaleModule' | 'appMetadata'>>;
12
+ constructor(config?: LoaderConfig);
13
+ /**
14
+ * Defines/registers a single named AMD module definition.
15
+ *
16
+ * @param {string} name The module name
17
+ * @param {string[]} dependencies A list of module dependencies (module imports)
18
+ * @param {Function} execute The function containing the module code. AKA exporter as it also returns the modules exports when executed
19
+ * @param {ModuleDefinitionSignatures} signatures Object containing the module signature and the signatures of its dependencies
20
+ * @return {void}
21
+ */
22
+ define(name: string, dependencies: string[], execute: Function, signatures: ModuleDefinitionSignatures): void;
23
+ /**
24
+ * Retrieves/loads a module, returning it from the registry if it exists and fetching it if it doesn't.
25
+ *
26
+ * @param {string} id - A module identifier or URL
27
+ * @param {string} importer - The versioned specifier of the module importer
28
+ * Used when the ID is not versioned (eg: variable dynamic imports)
29
+ * @return {Promise<Module>}
30
+ */
31
+ load(id: string, importer?: string): Promise<Module>;
32
+ /**
33
+ * 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).
34
+ *
35
+ * @param {string} id - A module identifier or URL
36
+ * @return {boolean}
37
+ */
38
+ has(id: string): boolean;
39
+ /**
40
+ * Resolves the module identifier or URL. Returns the module identifier if the moduleDefinition exists, or the full resolved URL if a URL is given.
41
+ *
42
+ * @param {string} id - A module identifier or URL
43
+ * @param {string} importer - The versioned specifier of the module importer
44
+ * Used when the ID is not versioned (eg: variable dynamic imports)
45
+ * @return {string}
46
+ */
47
+ resolve(id: string, importer?: string): Promise<string>;
48
+ private parentImportMap?;
49
+ registerImportMappings(mappings?: ImportMap): Promise<void>;
50
+ /**
51
+ * Marks modules as "externally" loaded/provided (e.g. preloaded), so that the loader does not attempt to load them.
52
+ *
53
+ * @param modules - list of module identifiers
54
+ */
55
+ registerExternalModules(modules: string[]): void;
56
+ }
57
+ //# sourceMappingURL=loaderLegacy.d.ts.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 Legacy Module Loader v0.13.0-alpha.2 */
7
+ /* LWR Legacy Module Loader v0.13.0-alpha.21 */
8
8
  const templateRegex = /\{([0-9]+)\}/g;
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  function templateString(template, args) {
@@ -377,7 +377,7 @@ try {
377
377
  // swallow
378
378
  }
379
379
  const trusted = createPolicy('trusted', policyOptions);
380
- /*! version: 0.22.1 */
380
+ /*! version: 0.22.3 */
381
381
 
382
382
  /* global console,process */
383
383
 
@@ -519,7 +519,7 @@ function evaluateHandleStaleModuleHooks(
519
519
  // Loader: modules
520
520
  const LOADER_PREFIX = 'lwr.loader.';
521
521
  const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
522
- const MODULE_DYNAMIC_LOAD = `${LOADER_PREFIX}moduleRegistry.dynamicLoad`;
522
+ const MODULE_DYNAMIC_LOAD = `${LOADER_PREFIX}module.dynamicLoad`;
523
523
  const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
524
524
  const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
525
525
 
@@ -572,8 +572,6 @@ const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
572
572
 
573
573
 
574
574
 
575
-
576
-
577
575
 
578
576
 
579
577
 
@@ -620,7 +618,7 @@ class ModuleRegistry {
620
618
  // eslint-disable-next-line no-await-in-loop
621
619
  result = isResponseAPromise(response) ? await response : response;
622
620
  }
623
- if (!this.isValidResolveResponse(result)) {
621
+ if (!this.isValidResolveResponse(result )) {
624
622
  throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);
625
623
  }
626
624
 
@@ -674,7 +672,7 @@ class ModuleRegistry {
674
672
  resolvedOrPlain,
675
673
  ) ;
676
674
  if (namedDefineRecord.external || namedDefineRecord.defined) {
677
- const record = this.moduleRegistry.get(resolved);
675
+ const record = this.moduleRegistry.get(resolved );
678
676
  if (!record || !this.aliases.has(resolvedOrPlain)) {
679
677
  return resolvedOrPlain;
680
678
  }
@@ -759,7 +757,7 @@ class ModuleRegistry {
759
757
  // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
760
758
  timer = setTimeout(() => {
761
759
  reject(new LoaderError(MODULE_LOAD_TIMEOUT, [id]));
762
- }, MODULE_LOAD_TIMEOUT_TIMER);
760
+ }, MODULE_LOAD_TIMEOUT_TIMER) ;
763
761
  }).finally(() => {
764
762
  // eslint-disable-next-line lwr/no-unguarded-apis, no-undef
765
763
  clearTimeout(timer);
@@ -1464,6 +1462,9 @@ async function evaluateImportMaps(baseUrl) {
1464
1462
  return importMapPromise;
1465
1463
  }
1466
1464
 
1465
+ 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; }
1466
+
1467
+
1467
1468
  /**
1468
1469
  * The LWR loader is inspired and borrows from the algorithms and native browser principles of https://github.com/systemjs/systemjs
1469
1470
  */
@@ -1473,9 +1474,9 @@ class Loader {
1473
1474
 
1474
1475
 
1475
1476
  constructor(config) {
1476
- config = config || {};
1477
- let baseUrl = config.baseUrl;
1478
- let profiler = config.profiler;
1477
+ const loaderConfig = config || {};
1478
+ let baseUrl = loaderConfig.baseUrl;
1479
+ let profiler = loaderConfig.profiler;
1479
1480
  if (baseUrl) {
1480
1481
  // add a trailing slash, if it does not exist
1481
1482
  baseUrl = baseUrl.replace(/\/?$/, '/');
@@ -1506,8 +1507,7 @@ class Loader {
1506
1507
  this.services = Object.freeze({
1507
1508
  addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
1508
1509
  handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
1509
- appMetadata: config.appMetadata,
1510
- serverData: config.serverData || {},
1510
+ appMetadata: _optionalChain([config, 'optionalAccess', _ => _.appMetadata]) ,
1511
1511
  });
1512
1512
  }
1513
1513
 
@@ -0,0 +1,53 @@
1
+ import type { ImportMapResolver } from '../importMap/importMapResolver.js';
2
+ import type { HandleStaleModuleHook, LoaderHooks, ResolveHookResponse } from '@lwrjs/types';
3
+ import type { LoaderConfig } from '../../../../types.js';
4
+ export type ModuleDefinitionSignatures = {
5
+ ownHash: string;
6
+ hashes: {
7
+ [key: string]: string;
8
+ };
9
+ };
10
+ export type Module = {
11
+ [key: string]: any;
12
+ __useDefault?: boolean;
13
+ };
14
+ export declare class ModuleRegistry {
15
+ private profiler;
16
+ constructor(config: LoaderConfig);
17
+ load(id: string, importer?: string): Promise<Module>;
18
+ resolve(id: string, importer?: string): Promise<string>;
19
+ has(id: string): boolean;
20
+ define(name: string, dependencies: string[], exporter: Function, signatures: ModuleDefinitionSignatures): void;
21
+ /**
22
+ * Marks modules as "externally" loaded/provided, so that the loader does not attempt to fetch them.
23
+ *
24
+ * @param modules - list of module identifiers
25
+ */
26
+ registerExternalModules(modules: string[]): void;
27
+ private checkModuleSignature;
28
+ private resolver?;
29
+ setImportResolver(resolver: ImportMapResolver): void;
30
+ private baseUrl;
31
+ private namedDefineRegistry;
32
+ private moduleRegistry;
33
+ aliases: Map<string, string>;
34
+ private lastDefine;
35
+ private getExistingModuleRecord;
36
+ private getModuleRecord;
37
+ private storeModuleAlias;
38
+ private getModuleDependencyRecord;
39
+ private topLevelEvaluation;
40
+ private instantiateAll;
41
+ private evaluateModule;
42
+ private isNamedExportDefaultOnly;
43
+ private getCircularDependencyWrapper;
44
+ private evaluateModuleDependencies;
45
+ private getModuleDef;
46
+ private resolveHook?;
47
+ private loadHook?;
48
+ addLoaderPlugin(hooks: LoaderHooks): void;
49
+ private handleStaleModuleHook?;
50
+ registerHandleStaleModuleHook(handleStaleModule: HandleStaleModuleHook): void;
51
+ isValidResolveResponse(res: ResolveHookResponse): boolean;
52
+ }
53
+ //# sourceMappingURL=moduleRegistry.d.ts.map