@lwrjs/module-registry 0.9.0-alpha.2 → 0.9.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.
@@ -28,6 +28,7 @@ __export(exports, {
28
28
  });
29
29
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
30
30
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
+ var import_compiler = __toModule(require("@lwrjs/shared-utils/compiler"));
31
32
  var import_linker = __toModule(require("./linker/linker.cjs"));
32
33
  var import_module_record = __toModule(require("./module-record.cjs"));
33
34
  var import_amd_strategy = __toModule(require("./linker/strategies/amd-strategy.cjs"));
@@ -109,23 +110,16 @@ var LwrModuleRegistry = class {
109
110
  const {runtimeEnvironment} = this.context;
110
111
  const {minify, sourceMapUrl} = runtimeEnvironment;
111
112
  const sourcemap = typeof sourceMapUrl === "string" || !minify;
112
- const {code: lockerizedCode} = this.context.compiler.lockerize(moduleCompiled, locker, sourcemap);
113
+ const {code: lockerizedCode} = (0, import_compiler.lockerize)(moduleCompiled, locker, sourcemap);
113
114
  moduleCompiled.compiledSource = lockerizedCode;
114
115
  }
115
- const moduleRecord = await (0, import_module_record.getModuleRecord)(moduleCompiled, this, this.context.compiler);
116
+ const moduleRecord = await (0, import_module_record.getModuleRecord)(moduleCompiled, this);
116
117
  return {...moduleCompiled, moduleRecord};
117
118
  }
118
119
  async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
119
120
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
120
121
  const id = moduleEntry.id;
121
- const {
122
- format,
123
- compat,
124
- debug,
125
- minify,
126
- bundle,
127
- env: {NODE_ENV: envMode}
128
- } = runtimeEnvironment;
122
+ const {format, compat, debug, minify, bundle} = runtimeEnvironment;
129
123
  const locale = runtimeParams?.["locale"];
130
124
  const environment = runtimeParams?.["environment"];
131
125
  const {
@@ -152,17 +146,10 @@ var LwrModuleRegistry = class {
152
146
  const moduleDef = await this.getModule(moduleId, runtimeParams);
153
147
  const moduleLinked = await this.createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams);
154
148
  if (format === "amd" && !bundle) {
155
- moduleLinked.linkedSource = (await this.context.compiler.convertToAmd(moduleLinked.linkedSource, {
149
+ moduleLinked.linkedSource = (await (0, import_compiler.convertToAmd)(moduleLinked.linkedSource, {
156
150
  id: moduleLinked.id
157
151
  })).code;
158
152
  }
159
- const minified = !!minify && !debug;
160
- if (minified && !bundle) {
161
- moduleLinked.linkedSource = (await this.context.compiler.minifyJavascript(moduleLinked.linkedSource)).code;
162
- moduleLinked.linkedConfig.minified = true;
163
- } else {
164
- moduleLinked.linkedSource = (await this.context.compiler.parseJavascript(moduleLinked.linkedSource, {envMode})).code;
165
- }
166
153
  if (cacheDisabled === false) {
167
154
  const linkedMap = this.moduleLinkedCache.get(id) || new Map();
168
155
  linkedMap.set((0, import_shared_utils.getCacheKeyFromJson)({
@@ -255,6 +242,7 @@ var LwrModuleRegistry = class {
255
242
  return {
256
243
  getModuleEntry: this.getModuleEntry.bind(this),
257
244
  getModule: this.getModule.bind(this),
245
+ getLinkedModule: this.getLinkedModule.bind(this),
258
246
  resolveModuleUri: this.resolveModuleUri.bind(this)
259
247
  };
260
248
  }
@@ -69,12 +69,12 @@ async function resolveExternalImport(registry, moduleSpecifier, importeeEntry, l
69
69
  interchangeable: dependencyModuleEntry.interchangeable
70
70
  };
71
71
  }
72
- async function getModuleRecord(compiledModule, registry, compiler) {
72
+ async function getModuleRecord(compiledModule, registry) {
73
73
  const imports = [];
74
74
  const dynamicImports = [];
75
75
  const {compiledMetadata: defaultCompilerMetadata, moduleEntry, version} = compiledModule;
76
76
  const compiledMetadata = defaultCompilerMetadata || {};
77
- const {imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports} = await compiler.getModuleMetadata(compiledModule.compiledSource);
77
+ const {imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports} = await (0, import_shared_utils.getImportMetadata)(compiledModule.compiledSource);
78
78
  Object.assign(compiledMetadata, {
79
79
  imports: compiledModuleImports,
80
80
  dynamicImports: compiledModuleDynamicImports
@@ -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,8 +1,7 @@
1
- import { ModuleProvider, LinkedModuleDefinition, LwrAppObserver, Compiler, RuntimeEnvironment, LwrAppEmitter, ModuleRegistry, ModuleEntry, PublicModuleRegistry, NormalizedLwrGlobalConfig, ModuleDefinition, AbstractModuleId, ModuleId, RuntimeParams } from '@lwrjs/types';
1
+ import type { AbstractModuleId, LinkedModuleDefinition, LwrAppEmitter, LwrAppObserver, ModuleDefinition, ModuleEntry, ModuleId, ModuleProvider, ModuleRegistry, NormalizedLwrGlobalConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
2
2
  interface RegistryContext {
3
3
  appObserver: LwrAppObserver;
4
4
  appEmitter: LwrAppEmitter;
5
- compiler: Compiler;
6
5
  runtimeEnvironment: RuntimeEnvironment;
7
6
  }
8
7
  export declare class LwrModuleRegistry implements ModuleRegistry {
package/build/es/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
2
2
  import { discoverInterchangeableModules, getCacheKeyFromJson, InflightTasks, LATEST_SIGNATURE, ModuleNameType, } from '@lwrjs/shared-utils';
3
+ // dependencies @locker/compiler and rollup are in this package.json is to satisfy the shared-utils/compiler optional dependencies
4
+ import { convertToAmd, lockerize } from '@lwrjs/shared-utils/compiler';
3
5
  import { link } from './linker/linker.js';
4
6
  import { getModuleRecord } from './module-record.js';
5
7
  import amdLinkingStrategy from './linker/strategies/amd-strategy.js';
@@ -98,17 +100,17 @@ export class LwrModuleRegistry {
98
100
  // in addition to being explicitly enabled.
99
101
  const { minify, sourceMapUrl } = runtimeEnvironment;
100
102
  const sourcemap = typeof sourceMapUrl === 'string' || !minify;
101
- const { code: lockerizedCode } = this.context.compiler.lockerize(moduleCompiled, locker, sourcemap);
103
+ const { code: lockerizedCode } = lockerize(moduleCompiled, locker, sourcemap);
102
104
  moduleCompiled.compiledSource = lockerizedCode;
103
105
  }
104
- const moduleRecord = await getModuleRecord(moduleCompiled, this, this.context.compiler);
106
+ const moduleRecord = await getModuleRecord(moduleCompiled, this);
105
107
  return { ...moduleCompiled, moduleRecord };
106
108
  }
107
109
  async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
108
110
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
109
111
  const id = moduleEntry.id;
110
112
  // cache key pivots from the runtimeEnvironment
111
- const { format, compat, debug, minify, bundle, env: { NODE_ENV: envMode }, } = runtimeEnvironment;
113
+ const { format, compat, debug, minify, bundle } = runtimeEnvironment;
112
114
  const locale = runtimeParams?.['locale'];
113
115
  const environment = runtimeParams?.['environment'];
114
116
  const { locker: { enabled: lockerEnabled }, } = this.globalConfig;
@@ -135,19 +137,10 @@ export class LwrModuleRegistry {
135
137
  // the bundler will convert the linked source to AMD when bundling is enabled
136
138
  if (format === 'amd' && !bundle) {
137
139
  // convert the linkedSource to the transport AMD format
138
- moduleLinked.linkedSource = (await this.context.compiler.convertToAmd(moduleLinked.linkedSource, {
140
+ moduleLinked.linkedSource = (await convertToAmd(moduleLinked.linkedSource, {
139
141
  id: moduleLinked.id,
140
142
  })).code;
141
143
  }
142
- const minified = !!minify && !debug;
143
- // the bundler will minify when bundling is enabled
144
- if (minified && !bundle) {
145
- moduleLinked.linkedSource = (await this.context.compiler.minifyJavascript(moduleLinked.linkedSource)).code;
146
- moduleLinked.linkedConfig.minified = true;
147
- }
148
- else {
149
- moduleLinked.linkedSource = (await this.context.compiler.parseJavascript(moduleLinked.linkedSource, { envMode })).code;
150
- }
151
144
  // Add to cache
152
145
  if (cacheDisabled === false) {
153
146
  const linkedMap = this.moduleLinkedCache.get(id) || new Map();
@@ -245,6 +238,7 @@ export class LwrModuleRegistry {
245
238
  return {
246
239
  getModuleEntry: this.getModuleEntry.bind(this),
247
240
  getModule: this.getModule.bind(this),
241
+ getLinkedModule: this.getLinkedModule.bind(this),
248
242
  resolveModuleUri: this.resolveModuleUri.bind(this),
249
243
  };
250
244
  }
@@ -1,3 +1,3 @@
1
- import { ModuleCompiled, ModuleRecord, ModuleRegistry, Compiler } from '@lwrjs/types';
2
- export declare function getModuleRecord(compiledModule: ModuleCompiled, registry: ModuleRegistry, compiler: Compiler): Promise<ModuleRecord>;
1
+ import type { ModuleCompiled, ModuleRecord, ModuleRegistry } from '@lwrjs/types';
2
+ export declare function getModuleRecord(compiledModule: ModuleCompiled, registry: ModuleRegistry): Promise<ModuleRecord>;
3
3
  //# sourceMappingURL=module-record.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { explodeSpecifier, ModuleNameType } from '@lwrjs/shared-utils';
2
+ import { explodeSpecifier, getImportMetadata, ModuleNameType } from '@lwrjs/shared-utils';
3
3
  async function resolveRelativeImport(registry, moduleSpecifier, importeeEntry, version, location) {
4
4
  // Resolve any relative parts in the import specifier
5
5
  // eg: "c/app#app.html" => "c/app"
@@ -51,13 +51,13 @@ async function resolveExternalImport(registry, moduleSpecifier, importeeEntry, l
51
51
  interchangeable: dependencyModuleEntry.interchangeable,
52
52
  };
53
53
  }
54
- export async function getModuleRecord(compiledModule, registry, compiler) {
54
+ export async function getModuleRecord(compiledModule, registry) {
55
55
  const imports = [];
56
56
  const dynamicImports = [];
57
57
  const { compiledMetadata: defaultCompilerMetadata, moduleEntry, version } = compiledModule;
58
58
  const compiledMetadata = defaultCompilerMetadata || {};
59
59
  // Get imports metadata and merge with rest of compiledModule metadata
60
- const { imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports } = await compiler.getModuleMetadata(compiledModule.compiledSource);
60
+ const { imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports } = await getImportMetadata(compiledModule.compiledSource);
61
61
  Object.assign(compiledMetadata, {
62
62
  imports: compiledModuleImports,
63
63
  dynamicImports: compiledModuleDynamicImports,
@@ -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,15 +4,15 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.2",
7
+ "version": "0.9.0-alpha.21",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/salesforce/lwr.git",
11
+ "url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
12
12
  "directory": "packages/@lwrjs/module-registry"
13
13
  },
14
14
  "bugs": {
15
- "url": "https://github.com/salesforce/lwr/issues"
15
+ "url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
16
16
  },
17
17
  "type": "module",
18
18
  "types": "build/es/index.d.ts",
@@ -30,16 +30,18 @@
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",
35
- "es-module-lexer": "^0.3.18"
33
+ "@locker/compiler": "0.18.9",
34
+ "@lwrjs/diagnostics": "0.9.0-alpha.21",
35
+ "@lwrjs/shared-utils": "0.9.0-alpha.21",
36
+ "es-module-lexer": "^0.3.18",
37
+ "rollup": "~2.45.2"
36
38
  },
37
39
  "devDependencies": {
38
- "@lwrjs/types": "0.9.0-alpha.2",
40
+ "@lwrjs/types": "0.9.0-alpha.21",
39
41
  "@types/es-module-lexer": "^0.3.0"
40
42
  },
41
43
  "engines": {
42
44
  "node": ">=14.15.4 <19"
43
45
  },
44
- "gitHead": "bcf63de23d1a2a53fb0e961dba4396e8753710dd"
46
+ "gitHead": "a89adcac80601f657becd6fd734c765e6b2a2745"
45
47
  }