@lwrjs/module-registry 0.9.0-alpha.0 → 0.9.0-alpha.10

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.
@@ -27,51 +27,43 @@ __export(exports, {
27
27
  getBundleSignature: () => getBundleSignature
28
28
  });
29
29
  var import_crypto = __toModule(require("crypto"));
30
- var import_path = __toModule(require("path"));
31
- var import_process = __toModule(require("process"));
32
- var import_module = __toModule(require("module"));
30
+ var import_resolve = __toModule(require("resolve"));
33
31
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
32
  var LWC_VERSION = getLWCVersion();
35
33
  var ENABLED_FINGERPRINTS = !(0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER;
36
34
  var ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
37
- async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set()) {
35
+ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set(), excludes = new Set()) {
38
36
  if (!modules.length) {
39
37
  return;
40
38
  }
41
39
  const definitions = await Promise.all(modules.map((module2) => registry.getModule(module2)));
42
40
  const imports = new Map();
43
41
  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
- });
42
+ const {specifier, version, ownHash, moduleRecord} = definition;
43
+ if (excludes.has(specifier)) {
44
+ hash.update(`${specifier}@${version}@${ownHash}`);
45
+ visitedDefinitions.add(specifier);
46
+ } else {
47
+ hash.update(ownHash);
48
+ visitedDefinitions.add((0, import_shared_utils.getSpecifier)(definition));
49
+ moduleRecord.imports?.forEach((importReference) => {
50
+ imports.set((0, import_shared_utils.getSpecifier)(importReference), importReference);
51
+ });
52
+ }
50
53
  }
51
54
  const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) => !visitedDefinitions.has(dependency.specifier) && !visitedDefinitions.has((0, import_shared_utils.getSpecifier)(dependency)));
52
55
  if (dependencies.length) {
53
- return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions);
56
+ return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions, excludes);
54
57
  }
55
58
  }
56
- async function getBundleSignature(moduleId, registry, exclude) {
59
+ async function getBundleSignature(moduleId, registry, excludes) {
57
60
  const hash = import_crypto.default.createHash("sha1");
58
61
  hash.update(ENV_KEY);
59
- await getRecursiveModuleHash([moduleId], registry, hash, new Set(exclude));
62
+ await getRecursiveModuleHash([moduleId], registry, hash, new Set(), new Set(excludes));
60
63
  return hash.digest("hex");
61
64
  }
62
65
  function getLWCVersion() {
63
- let lwcVersion;
64
- try {
65
- if (LWR?.LWC_VERSION) {
66
- lwcVersion = LWR.LWC_VERSION;
67
- }
68
- } catch (err) {
69
- }
70
- if (!lwcVersion) {
71
- const require2 = (0, import_module.createRequire)(import_path.default.join((0, import_process.cwd)(), "./env-config.js"));
72
- const {version} = require2("lwc/package.json");
73
- lwcVersion = version;
74
- }
75
- import_shared_utils.logger.debug(`Signature LWC Version: ${lwcVersion}`);
76
- return lwcVersion;
66
+ const packageJsonPath = import_resolve.default.sync(`lwc/package.json`);
67
+ const {version} = JSON.parse((0, import_shared_utils.readFile)(packageJsonPath));
68
+ return version;
77
69
  }
@@ -1,4 +1,4 @@
1
- import { ModuleRegistry, ModuleId } from '@lwrjs/types';
1
+ import type { ModuleRegistry, ModuleId } from '@lwrjs/types';
2
2
  /**
3
3
  * Generate a bundle signature
4
4
  *
@@ -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
@@ -1,27 +1,35 @@
1
1
  import crypto from 'crypto';
2
- import path from 'path';
3
- import { cwd } from 'process';
4
- import { createRequire } from 'module';
5
- import { getFeatureFlags, getSpecifier, logger } from '@lwrjs/shared-utils';
2
+ import resolve from 'resolve';
3
+ import { getFeatureFlags, getSpecifier, readFile } from '@lwrjs/shared-utils';
6
4
  const LWC_VERSION = getLWCVersion();
7
5
  const ENABLED_FINGERPRINTS = !getFeatureFlags().LEGACY_LOADER;
8
6
  const ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
9
- async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set()) {
7
+ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set(), excludes = new Set()) {
10
8
  if (!modules.length) {
11
9
  return;
12
10
  }
11
+ // Fetch all the definitions from the registry
13
12
  const definitions = await Promise.all(modules.map((module) => registry.getModule(module)));
14
13
  const imports = new Map();
15
14
  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
- });
15
+ const { specifier, version, ownHash, moduleRecord } = definition;
16
+ // check if this definition was in the bundle excludes
17
+ if (excludes.has(specifier)) {
18
+ // add the version do not worry about crawling its dependents
19
+ hash.update(`${specifier}@${version}@${ownHash}`);
20
+ // add just the specifier to the visited list
21
+ visitedDefinitions.add(specifier);
22
+ }
23
+ else {
24
+ // include module in the bundle signature
25
+ hash.update(ownHash);
26
+ // track the module to ensure it is only processed once
27
+ visitedDefinitions.add(getSpecifier(definition));
28
+ // map imports to prevent processing duplicates
29
+ moduleRecord.imports?.forEach((importReference) => {
30
+ imports.set(getSpecifier(importReference), importReference);
31
+ });
32
+ }
25
33
  }
26
34
  // filter out bundle config exclusions and already visited dependencies
27
35
  const dependencies = Array.from(imports, ([_, dependency]) => dependency).filter((dependency) =>
@@ -30,7 +38,7 @@ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinition
30
38
  // already visited dependencies will be versioned
31
39
  !visitedDefinitions.has(getSpecifier(dependency)));
32
40
  if (dependencies.length) {
33
- return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions);
41
+ return getRecursiveModuleHash(dependencies, registry, hash, visitedDefinitions, excludes);
34
42
  }
35
43
  }
36
44
  /**
@@ -46,37 +54,23 @@ async function getRecursiveModuleHash(modules, registry, hash, visitedDefinition
46
54
  * @param exclude - bundle config exclusions
47
55
  * @returns a bungle signature
48
56
  */
49
- export async function getBundleSignature(moduleId, registry, exclude) {
57
+ export async function getBundleSignature(moduleId, registry, excludes) {
50
58
  const hash = crypto.createHash('sha1');
59
+ // Add the environment key
51
60
  hash.update(ENV_KEY);
52
61
  // add bundle config exclusions to visited definitions to prevent including
53
62
  // them in the bundle signature
54
63
  // Note: if the root module is an excluded module, it will be included in
55
64
  // the signature
56
- await getRecursiveModuleHash([moduleId], registry, hash, new Set(exclude));
65
+ await getRecursiveModuleHash([moduleId], registry, hash, new Set(), new Set(excludes));
57
66
  return hash.digest('hex');
58
67
  }
59
68
  /**
60
69
  * Get the configured LWC version
61
70
  */
62
71
  function getLWCVersion() {
63
- let lwcVersion;
64
- try {
65
- // check if it is set on the global shim
66
- if (LWR?.LWC_VERSION) {
67
- lwcVersion = LWR.LWC_VERSION;
68
- }
69
- }
70
- catch (err) {
71
- // No-op throws an error in cli when LWR versison not set in global
72
- }
73
- if (!lwcVersion) {
74
- const require = createRequire(path.join(cwd(), './env-config.js'));
75
- // eslint-disable-next-line @typescript-eslint/no-var-requires
76
- const { version } = require('lwc/package.json');
77
- lwcVersion = version;
78
- }
79
- logger.debug(`Signature LWC Version: ${lwcVersion}`);
80
- return lwcVersion;
72
+ const packageJsonPath = resolve.sync(`lwc/package.json`);
73
+ const { version } = JSON.parse(readFile(packageJsonPath));
74
+ return version;
81
75
  }
82
76
  //# sourceMappingURL=signature.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.0",
7
+ "version": "0.9.0-alpha.10",
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.0",
34
- "@lwrjs/shared-utils": "0.9.0-alpha.0",
33
+ "@lwrjs/diagnostics": "0.9.0-alpha.10",
34
+ "@lwrjs/shared-utils": "0.9.0-alpha.10",
35
35
  "es-module-lexer": "^0.3.18"
36
36
  },
37
37
  "devDependencies": {
38
- "@lwrjs/types": "0.9.0-alpha.0",
38
+ "@lwrjs/types": "0.9.0-alpha.10",
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": "6890d8619b295a49ee1ed8253a372337d83863be"
44
+ "gitHead": "ecbf031157dd87d2b1a3d528b7fae8f9142eba7e"
45
45
  }