@lwrjs/loader 0.5.9 → 0.6.0-alpha.2

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 (41) hide show
  1. package/build/assets/prod/lwr-loader-shim-legacy.bundle.js +12 -9
  2. package/build/assets/prod/lwr-loader-shim-legacy.bundle.min.js +2 -25
  3. package/build/assets/prod/lwr-loader-shim-legacy.js +4 -4
  4. package/build/assets/prod/lwr-loader-shim.bundle.js +14 -9
  5. package/build/assets/prod/lwr-loader-shim.bundle.min.js +2 -25
  6. package/build/assets/prod/lwr-loader-shim.js +4 -4
  7. package/build/bundle/prod/lwr/esmLoader/esmLoader.js +1 -1
  8. package/build/cjs/index.cjs +12 -13
  9. package/build/cjs/modules/lwr/esmLoader/esmLoader.cjs +23 -14
  10. package/build/cjs/modules/lwr/esmLoader/importResolver.cjs +4 -5
  11. package/build/cjs/modules/lwr/esmLoader/importResolverLegacy.cjs +5 -6
  12. package/build/cjs/modules/lwr/loader/constants/constants.cjs +3 -3
  13. package/build/cjs/modules/lwr/loader/errors/messages.cjs +8 -8
  14. package/build/cjs/modules/lwr/loader/errors/reportError.cjs +8 -8
  15. package/build/cjs/modules/lwr/loader/errors/utils.cjs +3 -3
  16. package/build/cjs/modules/lwr/loader/hooks/moduleInvalidation.cjs +10 -10
  17. package/build/cjs/modules/lwr/loader/hooks/resolveAndLoadHook.cjs +19 -19
  18. package/build/cjs/modules/lwr/loader/moduleRegistry/importMetadataResolver.cjs +9 -9
  19. package/build/cjs/modules/lwr/loader/moduleRegistry/moduleRegistry.cjs +30 -27
  20. package/build/cjs/modules/lwr/loader/moduleRegistry/scriptLoad.cjs +8 -8
  21. package/build/cjs/modules/lwr/loader/utils/dom.cjs +3 -3
  22. package/build/cjs/modules/lwr/loader/utils/url.cjs +8 -8
  23. package/build/cjs/modules/lwr/loaderLegacy/constants/constants.cjs +3 -3
  24. package/build/cjs/modules/lwr/loaderLegacy/errors/messages.cjs +8 -8
  25. package/build/cjs/modules/lwr/loaderLegacy/errors/reportError.cjs +8 -8
  26. package/build/cjs/modules/lwr/loaderLegacy/errors/utils.cjs +3 -3
  27. package/build/cjs/modules/lwr/loaderLegacy/hooks/moduleInvalidation.cjs +10 -10
  28. package/build/cjs/modules/lwr/loaderLegacy/hooks/resolveAndLoadHook.cjs +19 -19
  29. package/build/cjs/modules/lwr/loaderLegacy/importMap/dom.cjs +9 -9
  30. package/build/cjs/modules/lwr/loaderLegacy/importMap/importMap.cjs +9 -9
  31. package/build/cjs/modules/lwr/loaderLegacy/importMap/importMapResolver.cjs +8 -8
  32. package/build/cjs/modules/lwr/loaderLegacy/importMap/utils.cjs +8 -8
  33. package/build/cjs/modules/lwr/loaderLegacy/importResolver/importResolver.cjs +1 -1
  34. package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/moduleRegistry.cjs +28 -25
  35. package/build/cjs/modules/lwr/loaderLegacy/moduleRegistry/scriptLoad.cjs +8 -8
  36. package/build/cjs/modules/lwr/loaderLegacy/utils/dom.cjs +3 -3
  37. package/build/cjs/modules/lwr/loaderLegacy/utils/url.cjs +8 -8
  38. package/build/modules/lwr/esmLoader/esmLoader.js +17 -7
  39. package/build/modules/lwr/loader/loader.js +10 -5
  40. package/build/modules/lwr/loaderLegacy/loaderLegacy.js +8 -5
  41. package/package.json +5 -5
@@ -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 ESM Module Loader v0.5.9 */
7
+ /* LWR ESM Module Loader v0.6.0-alpha.2 */
8
8
  /**
9
9
  * Simplified version of the AMD Import Metadata Resolver.
10
10
  * Just reads the ImportMetadata at construction time.
@@ -47,17 +47,26 @@ class ImportResolverLegacy {
47
47
  }
48
48
  }
49
49
 
50
- const endpoints = globalThis.LWR && globalThis.LWR.endpoints;
51
- const imports = (globalThis.LWR && globalThis.LWR.imports) || {};
52
- const index = (globalThis.LWR && globalThis.LWR.index) || {};
53
- const resolver = new ImportResolver({ imports, index });
54
- const resolverLegacy = new ImportResolverLegacy(globalThis.LWR && globalThis.LWR.importMappings);
50
+ // Singleton state:
51
+ let esmLoaderConfig;
52
+ let resolver;
53
+ let resolverLegacy;
54
+ function init(config) {
55
+ // Save config from globalThis.LWR
56
+ esmLoaderConfig = config;
57
+ const { imports, index, importMappings } = config;
58
+ resolver = new ImportResolver({ imports, index });
59
+ resolverLegacy = new ImportResolverLegacy(importMappings);
60
+ }
55
61
  function load(specifier, importer) {
56
62
  const uri = resolveUrl(specifier, importer);
57
63
  return import(uri);
58
64
  }
59
65
  function resolveUrl(specifier, importer) {
60
66
  let uri;
67
+ if (!resolver || !resolverLegacy) {
68
+ throw new Error('The ESM Loader was not initialized');
69
+ }
61
70
  // Check if the URI is in the import metadata
62
71
  uri = resolver.resolve(specifier);
63
72
  if (uri) {
@@ -73,6 +82,7 @@ function resolveUrl(specifier, importer) {
73
82
  // do not alter the specifier if it is already a URL
74
83
  if (uri.indexOf('://') < 0 && !uri.startsWith('/')) {
75
84
  // add the specifier and importer to the default URI
85
+ const { endpoints } = esmLoaderConfig;
76
86
  if (endpoints && endpoints.uris && endpoints.uris.module) {
77
87
  uri = endpoints.uris.module + encodeURIComponent(specifier);
78
88
  if (importer) {
@@ -83,4 +93,4 @@ function resolveUrl(specifier, importer) {
83
93
  return uri;
84
94
  }
85
95
 
86
- export { load };
96
+ export { init, load };
@@ -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 v0.5.9 */
7
+ /* LWR Module Loader v0.6.0-alpha.2 */
8
8
  const templateRegex = /\{([0-9]+)\}/g;
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  function templateString(template, args) {
@@ -686,10 +686,11 @@ class ModuleRegistry {
686
686
  }
687
687
  const resolvedUrl = this.resolver.resolveLocal(resolvedOrPlain);
688
688
  if (resolvedUrl) {
689
- // return the plain id IFF its already defined && the resolvedUrl is NOT already in the module registry
690
- if (this.namedDefineRegistry.has(resolvedOrPlain)) {
689
+ // return the plain id if it is already defined && the resolvedUrl is NOT already in the module registry
690
+ if (this.namedDefineRegistry.has(resolvedOrPlain) &&
691
+ this.namedDefineRegistry.get(resolvedOrPlain).defined) {
691
692
  const record = this.moduleRegistry.get(resolvedUrl);
692
- if (!record || record.originalId !== resolvedOrPlain) {
693
+ if (!record || !record.aliases.has(resolvedOrPlain)) {
693
694
  return resolvedOrPlain;
694
695
  }
695
696
  }
@@ -790,6 +791,10 @@ class ModuleRegistry {
790
791
  getModuleRecord(resolvedId, id) {
791
792
  let moduleRecord = this.moduleRegistry.get(resolvedId);
792
793
  if (moduleRecord) {
794
+ // Make sure the original id is in the alias set
795
+ if (!moduleRecord.aliases.has(id)) {
796
+ moduleRecord.aliases.add(id);
797
+ }
793
798
  return moduleRecord;
794
799
  }
795
800
  const instantiation = this.getModuleDef(resolvedId, id);
@@ -809,7 +814,7 @@ class ModuleRegistry {
809
814
  });
810
815
  moduleRecord = {
811
816
  id: resolvedId,
812
- originalId: id,
817
+ aliases: new Set([id]),
813
818
  module: Object.create(null),
814
819
  dependencyRecords,
815
820
  instantiation,
@@ -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.5.9 */
7
+ /* LWR Legacy Module Loader v0.6.0-alpha.2 */
8
8
  const templateRegex = /\{([0-9]+)\}/g;
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  function templateString(template, args) {
@@ -474,15 +474,14 @@ class ModuleRegistry {
474
474
  }
475
475
  if (this.resolver) {
476
476
  resolved = this.resolver.resolve(resolvedOrPlain, parentUrl);
477
- // return the plain id IFF its already defined && the resolvedUrl is NOT already in the module registry
477
+ // return the plain id if it is already defined && the resolvedUrl is NOT already in the module registry
478
478
  if (this.namedDefineRegistry.has(resolvedOrPlain) &&
479
479
  this.namedDefineRegistry.get(resolvedOrPlain).defined) {
480
480
  const record = this.moduleRegistry.get(resolved);
481
- if (!record || record.originalId !== resolvedOrPlain) {
481
+ if (!record || !record.aliases.has(resolvedOrPlain)) {
482
482
  return resolvedOrPlain;
483
483
  }
484
484
  }
485
- // return resolved;
486
485
  }
487
486
  else {
488
487
  resolved = resolvedOrPlain;
@@ -612,6 +611,10 @@ class ModuleRegistry {
612
611
  getModuleRecord(resolvedId, id) {
613
612
  let moduleRecord = this.moduleRegistry.get(resolvedId);
614
613
  if (moduleRecord) {
614
+ // Make sure the original id is in the alias set
615
+ if (!moduleRecord.aliases.has(id)) {
616
+ moduleRecord.aliases.add(id);
617
+ }
615
618
  return moduleRecord;
616
619
  }
617
620
  const instantiation = this.getModuleDef(resolvedId, id);
@@ -631,7 +634,7 @@ class ModuleRegistry {
631
634
  });
632
635
  moduleRecord = {
633
636
  id: resolvedId,
634
- originalId: id,
637
+ aliases: new Set([id]),
635
638
  module: Object.create(null),
636
639
  dependencyRecords,
637
640
  instantiation,
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.5.9",
8
+ "version": "0.6.0-alpha.2",
9
9
  "homepage": "https://lwr.dev/",
10
10
  "repository": {
11
11
  "type": "git",
@@ -54,12 +54,12 @@
54
54
  "build": "tsc -b; yarn build:shim && yarn build:loader && yarn build:shim:bundle && yarn build:shim:bundle:minify"
55
55
  },
56
56
  "devDependencies": {
57
- "@lwrjs/compiler": "0.5.9",
58
- "@lwrjs/types": "0.5.9",
57
+ "@lwrjs/compiler": "0.6.0-alpha.2",
58
+ "@lwrjs/types": "0.6.0-alpha.2",
59
59
  "rollup-plugin-terser": "^7.0.2"
60
60
  },
61
61
  "dependencies": {
62
- "@lwrjs/shared-utils": "0.5.9"
62
+ "@lwrjs/shared-utils": "0.6.0-alpha.2"
63
63
  },
64
64
  "lwc": {
65
65
  "modules": [
@@ -76,5 +76,5 @@
76
76
  "engines": {
77
77
  "node": ">=14.15.4 <17"
78
78
  },
79
- "gitHead": "0374b5f8c25aabf3a845e438a3171cbb0c229513"
79
+ "gitHead": "5b0f761312e566fdaeec26ac3dbb704f8421b1a9"
80
80
  }