@lwrjs/module-registry 0.9.0-alpha.2 → 0.9.0-alpha.4

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.
@@ -34,29 +34,34 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
34
  var LWC_VERSION = getLWCVersion();
35
35
  var ENABLED_FINGERPRINTS = !(0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER;
36
36
  var ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
37
- async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set()) {
37
+ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set(), excludes = new Set()) {
38
38
  if (!modules.length) {
39
39
  return;
40
40
  }
41
41
  const definitions = await Promise.all(modules.map((module2) => registry.getModule(module2)));
42
42
  const imports = new Map();
43
43
  for (const definition of definitions) {
44
- const {ownHash, moduleRecord} = definition;
45
- hash.update(ownHash);
46
- visitedDefinitions.add((0, import_shared_utils.getSpecifier)(definition));
47
- moduleRecord.imports?.forEach((importReference) => {
48
- imports.set((0, import_shared_utils.getSpecifier)(importReference), importReference);
49
- });
44
+ const {specifier, version, ownHash, moduleRecord} = definition;
45
+ if (excludes.has(specifier)) {
46
+ hash.update(`${specifier}@${version}@${ownHash}`);
47
+ visitedDefinitions.add(specifier);
48
+ } else {
49
+ hash.update(ownHash);
50
+ visitedDefinitions.add((0, import_shared_utils.getSpecifier)(definition));
51
+ moduleRecord.imports?.forEach((importReference) => {
52
+ imports.set((0, import_shared_utils.getSpecifier)(importReference), importReference);
53
+ });
54
+ }
50
55
  }
51
56
  const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) => !visitedDefinitions.has(dependency.specifier) && !visitedDefinitions.has((0, import_shared_utils.getSpecifier)(dependency)));
52
57
  if (dependencies.length) {
53
- return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions);
58
+ return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions, excludes);
54
59
  }
55
60
  }
56
- async function getBundleSignature(moduleId, registry, exclude) {
61
+ async function getBundleSignature(moduleId, registry, excludes) {
57
62
  const hash = import_crypto.default.createHash("sha1");
58
63
  hash.update(ENV_KEY);
59
- await getRecursiveModuleHash([moduleId], registry, hash, new Set(exclude));
64
+ await getRecursiveModuleHash([moduleId], registry, hash, new Set(), new Set(excludes));
60
65
  return hash.digest("hex");
61
66
  }
62
67
  function getLWCVersion() {
@@ -12,5 +12,5 @@ import { ModuleRegistry, ModuleId } from '@lwrjs/types';
12
12
  * @param exclude - bundle config exclusions
13
13
  * @returns a bungle signature
14
14
  */
15
- export declare function getBundleSignature(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, registry: ModuleRegistry, exclude?: string[]): Promise<string>;
15
+ export declare function getBundleSignature(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, registry: ModuleRegistry, excludes?: string[]): Promise<string>;
16
16
  //# sourceMappingURL=signature.d.ts.map
@@ -6,22 +6,32 @@ import { getFeatureFlags, getSpecifier, logger } from '@lwrjs/shared-utils';
6
6
  const LWC_VERSION = getLWCVersion();
7
7
  const ENABLED_FINGERPRINTS = !getFeatureFlags().LEGACY_LOADER;
8
8
  const ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
9
- async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set()) {
9
+ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set(), excludes = new Set()) {
10
10
  if (!modules.length) {
11
11
  return;
12
12
  }
13
+ // Fetch all the definitions from the registry
13
14
  const definitions = await Promise.all(modules.map((module) => registry.getModule(module)));
14
15
  const imports = new Map();
15
16
  for (const definition of definitions) {
16
- const { ownHash, moduleRecord } = definition;
17
- // include module in the bundle signature
18
- hash.update(ownHash);
19
- // track the module to ensure it is only processed once
20
- visitedDefinitions.add(getSpecifier(definition));
21
- // map imports to prevent processing duplicates
22
- moduleRecord.imports?.forEach((importReference) => {
23
- imports.set(getSpecifier(importReference), importReference);
24
- });
17
+ const { specifier, version, ownHash, moduleRecord } = definition;
18
+ // check if this definition was in the bundle excludes
19
+ if (excludes.has(specifier)) {
20
+ // add the version do not worry about crawling its dependents
21
+ hash.update(`${specifier}@${version}@${ownHash}`);
22
+ // add just the specifier to the visited list
23
+ visitedDefinitions.add(specifier);
24
+ }
25
+ else {
26
+ // include module in the bundle signature
27
+ hash.update(ownHash);
28
+ // track the module to ensure it is only processed once
29
+ visitedDefinitions.add(getSpecifier(definition));
30
+ // map imports to prevent processing duplicates
31
+ moduleRecord.imports?.forEach((importReference) => {
32
+ imports.set(getSpecifier(importReference), importReference);
33
+ });
34
+ }
25
35
  }
26
36
  // filter out bundle config exclusions and already visited dependencies
27
37
  const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) =>
@@ -30,7 +40,7 @@ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinition
30
40
  // already visited dependencies will be versioned
31
41
  !visitedDefinitions.has(getSpecifier(dependency)));
32
42
  if (dependencies.length) {
33
- return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions);
43
+ return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions, excludes);
34
44
  }
35
45
  }
36
46
  /**
@@ -46,14 +56,15 @@ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinition
46
56
  * @param exclude - bundle config exclusions
47
57
  * @returns a bungle signature
48
58
  */
49
- export async function getBundleSignature(moduleId, registry, exclude) {
59
+ export async function getBundleSignature(moduleId, registry, excludes) {
50
60
  const hash = crypto.createHash('sha1');
61
+ // Add the environment key
51
62
  hash.update(ENV_KEY);
52
63
  // add bundle config exclusions to visited definitions to prevent including
53
64
  // them in the bundle signature
54
65
  // Note: if the root module is an excluded module, it will be included in
55
66
  // the signature
56
- await getRecursiveModuleHash([moduleId], registry, hash, new Set(exclude));
67
+ await getRecursiveModuleHash([moduleId], registry, hash, new Set(), new Set(excludes));
57
68
  return hash.digest('hex');
58
69
  }
59
70
  /**
@@ -68,7 +79,7 @@ function getLWCVersion() {
68
79
  }
69
80
  }
70
81
  catch (err) {
71
- // No-op throws an error in cli when LWR versison not set in global
82
+ // No-op throws an error in cli when LWR version not set in global
72
83
  }
73
84
  if (!lwcVersion) {
74
85
  const require = createRequire(path.join(cwd(), './env-config.js'));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.2",
7
+ "version": "0.9.0-alpha.4",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,16 +30,16 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/diagnostics": "0.9.0-alpha.2",
34
- "@lwrjs/shared-utils": "0.9.0-alpha.2",
33
+ "@lwrjs/diagnostics": "0.9.0-alpha.4",
34
+ "@lwrjs/shared-utils": "0.9.0-alpha.4",
35
35
  "es-module-lexer": "^0.3.18"
36
36
  },
37
37
  "devDependencies": {
38
- "@lwrjs/types": "0.9.0-alpha.2",
38
+ "@lwrjs/types": "0.9.0-alpha.4",
39
39
  "@types/es-module-lexer": "^0.3.0"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=14.15.4 <19"
43
43
  },
44
- "gitHead": "bcf63de23d1a2a53fb0e961dba4396e8753710dd"
44
+ "gitHead": "cb4f98fad4279ac953edec73f3e28996e2523c67"
45
45
  }