@lwrjs/module-registry 0.13.6 → 0.15.0-alpha.1

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.
@@ -33,7 +33,6 @@ var import_linker = __toModule(require("./linker/linker.cjs"));
33
33
  var import_module_record = __toModule(require("./module-record.cjs"));
34
34
  var import_amd_strategy = __toModule(require("./linker/strategies/amd-strategy.cjs"));
35
35
  var import_esm_strategy = __toModule(require("./linker/strategies/esm-strategy.cjs"));
36
- var import_signature = __toModule(require("./signature.cjs"));
37
36
  var LwrModuleRegistry = class {
38
37
  constructor(context, globalConfig, registries) {
39
38
  this.providers = [];
@@ -90,7 +89,7 @@ var LwrModuleRegistry = class {
90
89
  bundleId = bundleGroups && (0, import_shared_utils.getGroupName)(moduleId.specifier, bundleGroups);
91
90
  }
92
91
  return new Promise((resolve, reject) => {
93
- (0, import_signature.getBundleSignature)(moduleId, this, runtimeParams, this.globalConfig?.bundleConfig?.exclude).then((bundleSignature) => resolve((0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, bundleSignature, bundleId))).catch(reject);
92
+ this.bundleSigner.getBundleSignature(moduleId, runtimeEnvironment, runtimeParams, this.globalConfig?.bundleConfig?.exclude).then((bundleSignature) => resolve((0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, bundleSignature, bundleId))).catch(reject);
94
93
  });
95
94
  } else {
96
95
  return new Promise((resolve, reject) => {
@@ -98,6 +97,12 @@ var LwrModuleRegistry = class {
98
97
  });
99
98
  }
100
99
  }
100
+ setBundleSigner(bundleSigner) {
101
+ this.bundleSigner = bundleSigner;
102
+ }
103
+ getBundleSigner() {
104
+ return this.bundleSigner;
105
+ }
101
106
  addModuleProviders(registries) {
102
107
  this.providers.push(...registries);
103
108
  }
@@ -28,7 +28,6 @@ __export(exports, {
28
28
  });
29
29
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
30
  var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
31
- var import_signature = __toModule(require("../signature.cjs"));
32
31
  async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, bundleConfig) {
33
32
  const {specifier, version, compiledSource, moduleRecord} = moduleDef;
34
33
  const {imports, dynamicImports, importMeta} = moduleRecord;
@@ -62,7 +61,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
62
61
  }
63
62
  let signature;
64
63
  if (runtimeEnvironment.bundle && runtimeEnvironment.format === "esm" && exclude?.includes(importRef.specifier)) {
65
- signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry, runtimeParams, exclude);
64
+ signature = await moduleRegistry.getBundleSigner().getBundleSignature(importRef, runtimeEnvironment, runtimeParams, exclude);
66
65
  }
67
66
  const {locations, sourceSpecifier} = importRef;
68
67
  const link2 = strategy(importRef, runtimeEnvironment, runtimeParams, signature, void 0, external);
@@ -84,7 +83,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
84
83
  let signature;
85
84
  const isStringLiteral = importRef.moduleNameType === import_shared_utils2.ModuleNameType.string;
86
85
  if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === "esm") {
87
- signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry, runtimeParams, exclude);
86
+ signature = await moduleRegistry.getBundleSigner().getBundleSignature(importRef, runtimeEnvironment, runtimeParams, exclude);
88
87
  }
89
88
  const link2 = isStringLiteral ? versionStrategy(importRef, runtimeEnvironment, runtimeParams, signature) : importRef.specifier;
90
89
  const linkedLocations = locations.map(({location, importLocation}) => {
@@ -122,7 +121,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
122
121
  const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(specifier2);
123
122
  let signature;
124
123
  if (esmLoaderModule && runtimeEnvironment.bundle) {
125
- signature = await (0, import_signature.getBundleSignature)({version: version2, specifier: specifier2}, moduleRegistry, runtimeParams, exclude);
124
+ signature = await moduleRegistry.getBundleSigner().getBundleSignature({version: version2, specifier: specifier2}, runtimeEnvironment, runtimeParams, exclude);
126
125
  }
127
126
  const loaderLink = strategy({specifier: specifier2, version: version2}, runtimeEnvironment, runtimeParams, signature);
128
127
  const loaderImport = `import { load } from "${loaderLink}";
@@ -1,4 +1,4 @@
1
- import type { AbstractModuleId, LinkedModuleDefinition, LwrAppEmitter, LwrAppObserver, ModuleDefinition, ModuleEntry, ModuleId, ModuleProvider, ModuleRegistry, ModuleRegistryConfig, NormalizedLwrGlobalConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
1
+ import type { AbstractModuleId, BundleSigner, LinkedModuleDefinition, LwrAppEmitter, LwrAppObserver, ModuleDefinition, ModuleEntry, ModuleId, ModuleProvider, ModuleRegistry, ModuleRegistryConfig, NormalizedLwrGlobalConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
2
  interface RegistryContext {
3
3
  appObserver: LwrAppObserver;
4
4
  appEmitter: LwrAppEmitter;
@@ -14,9 +14,12 @@ export declare class LwrModuleRegistry implements ModuleRegistry {
14
14
  globalConfig: NormalizedLwrGlobalConfig;
15
15
  private interchangeableModules?;
16
16
  private inflightModuleDefinitions;
17
+ private bundleSigner;
17
18
  constructor(context: RegistryContext, globalConfig: NormalizedLwrGlobalConfig, registries?: ModuleProvider[]);
18
19
  resolveModuleUriSync<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, signature: S, runtimeEnvironment: R, runtimeParams: RuntimeParams): string;
19
20
  resolveModuleUri<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: R, runtimeParams: RuntimeParams, signature?: S): Promise<string>;
21
+ setBundleSigner(bundleSigner: BundleSigner): void;
22
+ getBundleSigner(): BundleSigner;
20
23
  addModuleProviders(registries: ModuleProvider[]): void;
21
24
  getConfig(): ModuleRegistryConfig;
22
25
  getModuleEntry<T extends AbstractModuleId>(moduleId: T, runtimeParams: RuntimeParams): Promise<ModuleEntry>;
package/build/es/index.js CHANGED
@@ -6,7 +6,6 @@ import { link } from './linker/linker.js';
6
6
  import { getModuleRecord } from './module-record.js';
7
7
  import amdLinkingStrategy from './linker/strategies/amd-strategy.js';
8
8
  import esmLinkingStrategy from './linker/strategies/esm-strategy.js';
9
- import { getBundleSignature } from './signature.js';
10
9
  export class LwrModuleRegistry {
11
10
  constructor(context, globalConfig, registries) {
12
11
  this.providers = [];
@@ -70,7 +69,8 @@ export class LwrModuleRegistry {
70
69
  bundleId = bundleGroups && getGroupName(moduleId.specifier, bundleGroups);
71
70
  }
72
71
  return new Promise((resolve, reject) => {
73
- getBundleSignature(moduleId, this, runtimeParams, this.globalConfig?.bundleConfig?.exclude)
72
+ this.bundleSigner
73
+ .getBundleSignature(moduleId, runtimeEnvironment, runtimeParams, this.globalConfig?.bundleConfig?.exclude)
74
74
  .then((bundleSignature) => resolve(esmLinkingStrategy(moduleId, runtimeEnvironment, runtimeParams, bundleSignature, bundleId)))
75
75
  .catch(reject);
76
76
  });
@@ -86,6 +86,12 @@ export class LwrModuleRegistry {
86
86
  });
87
87
  }
88
88
  }
89
+ setBundleSigner(bundleSigner) {
90
+ this.bundleSigner = bundleSigner;
91
+ }
92
+ getBundleSigner() {
93
+ return this.bundleSigner;
94
+ }
89
95
  // -- Public API --------------------------------------------------------------------
90
96
  addModuleProviders(registries) {
91
97
  this.providers.push(...registries);
@@ -1,6 +1,5 @@
1
1
  import { createStringBuilder } from '@lwrjs/shared-utils';
2
2
  import { explodeSpecifier, getSpecifier, ModuleNameType } from '@lwrjs/shared-utils';
3
- import { getBundleSignature } from '../signature.js';
4
3
  /**
5
4
  * Link the compiledSource of a module source with the versioned ModuleRecord imports using a specific linking strategy
6
5
  * @param moduleDef
@@ -45,7 +44,9 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
45
44
  if (runtimeEnvironment.bundle &&
46
45
  runtimeEnvironment.format === 'esm' &&
47
46
  exclude?.includes(importRef.specifier)) {
48
- signature = await getBundleSignature(importRef, moduleRegistry, runtimeParams, exclude);
47
+ signature = await moduleRegistry
48
+ .getBundleSigner()
49
+ .getBundleSignature(importRef, runtimeEnvironment, runtimeParams, exclude);
49
50
  }
50
51
  const { locations, sourceSpecifier } = importRef;
51
52
  const link = strategy(importRef, runtimeEnvironment, runtimeParams, signature, undefined, external);
@@ -70,7 +71,9 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
70
71
  const isStringLiteral = importRef.moduleNameType === ModuleNameType.string;
71
72
  // get signature for dynamic imports when bundling esm
72
73
  if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === 'esm') {
73
- signature = await getBundleSignature(importRef, moduleRegistry, runtimeParams, exclude);
74
+ signature = await moduleRegistry
75
+ .getBundleSigner()
76
+ .getBundleSignature(importRef, runtimeEnvironment, runtimeParams, exclude);
74
77
  }
75
78
  // always link [literal] dynamic imports as versioned specifiers (AMD strategy)
76
79
  // linking them as URIs (ESM strategy) causes caching issues since they can contain stale signatures
@@ -121,7 +124,9 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
121
124
  let signature;
122
125
  if (esmLoaderModule && runtimeEnvironment.bundle) {
123
126
  // Ensure the ESM loader is signed, or there may be a clash between this import and an existing one
124
- signature = await getBundleSignature({ version, specifier }, moduleRegistry, runtimeParams, exclude);
127
+ signature = await moduleRegistry
128
+ .getBundleSigner()
129
+ .getBundleSignature({ version, specifier }, runtimeEnvironment, runtimeParams, exclude);
125
130
  }
126
131
  const loaderLink = strategy({ specifier, version }, runtimeEnvironment, runtimeParams, signature);
127
132
  // import {load} from 'loader/loader'
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.13.6",
7
+ "version": "0.15.0-alpha.1",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -37,18 +37,18 @@
37
37
  "build": "tsc -b"
38
38
  },
39
39
  "dependencies": {
40
- "@lwrjs/config": "0.13.6",
41
- "@lwrjs/diagnostics": "0.13.6",
42
- "@lwrjs/shared-utils": "0.13.6",
40
+ "@lwrjs/config": "0.15.0-alpha.1",
41
+ "@lwrjs/diagnostics": "0.15.0-alpha.1",
42
+ "@lwrjs/shared-utils": "0.15.0-alpha.1",
43
43
  "fs-extra": "^11.1.1",
44
44
  "rollup": "^2.78.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@lwrjs/types": "0.13.6",
47
+ "@lwrjs/types": "0.15.0-alpha.1",
48
48
  "memfs": "^4.9.3"
49
49
  },
50
50
  "engines": {
51
51
  "node": ">=18.0.0"
52
52
  },
53
- "gitHead": "b6558d6ff644c035b3191eea00dfd6c625dc5efa"
53
+ "gitHead": "4547b6c6a7c9e9f33f829d4fdf2082caf4c9c44b"
54
54
  }
@@ -1,63 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
11
- };
12
- var __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
- }
18
- return target;
19
- };
20
- var __toModule = (module2) => {
21
- return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
- };
23
-
24
- // packages/@lwrjs/module-registry/src/signature.ts
25
- __markAsModule(exports);
26
- __export(exports, {
27
- getBundleSignature: () => getBundleSignature
28
- });
29
- var import_crypto = __toModule(require("crypto"));
30
- var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
- var import_config = __toModule(require("@lwrjs/config"));
32
- var ENABLED_FINGERPRINTS = !(0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER;
33
- var ENV_KEY = `LWC:${import_config.LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
34
- async function getRecursiveModuleHash(modules, registry, hash, runtimeParams, visitedDefinitions = new Set(), excludes = new Set()) {
35
- if (!modules.length) {
36
- return;
37
- }
38
- const definitions = await Promise.all(modules.map((module2) => registry.getModule(module2, runtimeParams)));
39
- const imports = new Map();
40
- for (const definition of definitions) {
41
- const {specifier, version, ownHash, moduleRecord} = definition;
42
- if (excludes.has(specifier)) {
43
- hash.update(`${specifier}@${version}@${ownHash}`);
44
- visitedDefinitions.add(specifier);
45
- } else {
46
- hash.update(ownHash);
47
- visitedDefinitions.add((0, import_shared_utils.getSpecifier)(definition));
48
- moduleRecord.imports?.forEach((importReference) => {
49
- imports.set((0, import_shared_utils.getSpecifier)(importReference), importReference);
50
- });
51
- }
52
- }
53
- const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) => !visitedDefinitions.has(dependency.specifier) && !visitedDefinitions.has((0, import_shared_utils.getSpecifier)(dependency)));
54
- if (dependencies.length) {
55
- return getRecursiveModuleHash(dependencies, registry, hash, runtimeParams, visitedDefinitions, excludes);
56
- }
57
- }
58
- async function getBundleSignature(moduleId, registry, runtimeParams, excludes) {
59
- const hash = import_crypto.default.createHash("sha1");
60
- hash.update(ENV_KEY);
61
- await getRecursiveModuleHash([moduleId], registry, hash, runtimeParams, new Set(), new Set(excludes));
62
- return hash.digest("hex");
63
- }
@@ -1,16 +0,0 @@
1
- import type { ModuleRegistry, ModuleId, RuntimeParams } from '@lwrjs/types';
2
- /**
3
- * Generate a bundle signature
4
- *
5
- * Traverses the module graph from the specified root module to generate a
6
- * signature. Modules that are marked for exclusion will be skipped. The
7
- * bundle signature will be generated based on the environment
8
- * keys(i.e. LWC version) and the ownHash of each module in the graph.
9
- *
10
- * @param moduleId - root module id
11
- * @param registry - module registry
12
- * @param exclude - bundle config exclusions
13
- * @returns a bungle signature
14
- */
15
- export declare function getBundleSignature(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, registry: ModuleRegistry, runtimeParams: RuntimeParams, excludes?: string[]): Promise<string>;
16
- //# sourceMappingURL=signature.d.ts.map
@@ -1,67 +0,0 @@
1
- import crypto from 'crypto';
2
- import { getFeatureFlags, getSpecifier } from '@lwrjs/shared-utils';
3
- import { LWC_VERSION } from '@lwrjs/config';
4
- const ENABLED_FINGERPRINTS = !getFeatureFlags().LEGACY_LOADER;
5
- const ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
6
- async function getRecursiveModuleHash(modules, registry, hash, runtimeParams, visitedDefinitions = new Set(), excludes = new Set()) {
7
- if (!modules.length) {
8
- return;
9
- }
10
- // Fetch all the definitions from the registry
11
- const definitions = await Promise.all(modules.map((module) => registry.getModule(module, runtimeParams)));
12
- const imports = new Map();
13
- for (const definition of definitions) {
14
- const { specifier, version, ownHash, moduleRecord } = definition;
15
- // check if this definition was in the bundle excludes
16
- if (excludes.has(specifier)) {
17
- // add the version do not worry about crawling its dependents
18
- hash.update(`${specifier}@${version}@${ownHash}`);
19
- // add just the specifier to the visited list
20
- visitedDefinitions.add(specifier);
21
- }
22
- else {
23
- // include module in the bundle signature
24
- hash.update(ownHash);
25
- // track the module to ensure it is only processed once
26
- visitedDefinitions.add(getSpecifier(definition));
27
- // map imports to prevent processing duplicates
28
- moduleRecord.imports?.forEach((importReference) => {
29
- imports.set(getSpecifier(importReference), importReference);
30
- });
31
- }
32
- }
33
- // filter out bundle config exclusions and already visited dependencies
34
- const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) =>
35
- // exclusions are not versioned
36
- !visitedDefinitions.has(dependency.specifier) &&
37
- // already visited dependencies will be versioned
38
- !visitedDefinitions.has(getSpecifier(dependency)));
39
- if (dependencies.length) {
40
- return getRecursiveModuleHash(dependencies, registry, hash, runtimeParams, visitedDefinitions, excludes);
41
- }
42
- }
43
- /**
44
- * Generate a bundle signature
45
- *
46
- * Traverses the module graph from the specified root module to generate a
47
- * signature. Modules that are marked for exclusion will be skipped. The
48
- * bundle signature will be generated based on the environment
49
- * keys(i.e. LWC version) and the ownHash of each module in the graph.
50
- *
51
- * @param moduleId - root module id
52
- * @param registry - module registry
53
- * @param exclude - bundle config exclusions
54
- * @returns a bungle signature
55
- */
56
- export async function getBundleSignature(moduleId, registry, runtimeParams, excludes) {
57
- const hash = crypto.createHash('sha1');
58
- // Add the environment key
59
- hash.update(ENV_KEY);
60
- // add bundle config exclusions to visited definitions to prevent including
61
- // them in the bundle signature
62
- // Note: if the root module is an excluded module, it will be included in
63
- // the signature
64
- await getRecursiveModuleHash([moduleId], registry, hash, runtimeParams, new Set(), new Set(excludes));
65
- return hash.digest('hex');
66
- }
67
- //# sourceMappingURL=signature.js.map