@lwrjs/module-registry 0.9.9-alpha.8 → 0.10.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.
@@ -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"));
@@ -66,10 +67,17 @@ var LwrModuleRegistry = class {
66
67
  }
67
68
  });
68
69
  }
69
- resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
70
+ resolveModuleUriSync(moduleId, signature, runtimeEnvironment, runtimeParams) {
71
+ const uri = (0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, signature);
72
+ return uri;
73
+ }
74
+ async resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
70
75
  if (signature !== void 0) {
71
- const uri = (0, import_esm_strategy.default)(moduleId, runtimeEnvironment, runtimeParams, signature);
72
- return uri;
76
+ return this.resolveModuleUriSync(moduleId, signature, runtimeEnvironment, runtimeParams);
77
+ }
78
+ const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
79
+ if (moduleEntry.src) {
80
+ return moduleEntry.src;
73
81
  }
74
82
  const {bundle, format} = runtimeEnvironment;
75
83
  if (bundle) {
@@ -109,23 +117,16 @@ var LwrModuleRegistry = class {
109
117
  const {runtimeEnvironment} = this.context;
110
118
  const {minify, sourceMapUrl} = runtimeEnvironment;
111
119
  const sourcemap = typeof sourceMapUrl === "string" || !minify;
112
- const {code: lockerizedCode} = this.context.compiler.lockerize(moduleCompiled, locker, sourcemap);
120
+ const {code: lockerizedCode} = (0, import_compiler.lockerize)(moduleCompiled, locker, sourcemap);
113
121
  moduleCompiled.compiledSource = lockerizedCode;
114
122
  }
115
- const moduleRecord = await (0, import_module_record.getModuleRecord)(moduleCompiled, this, this.context.compiler);
123
+ const moduleRecord = await (0, import_module_record.getModuleRecord)(moduleCompiled, this);
116
124
  return {...moduleCompiled, moduleRecord};
117
125
  }
118
126
  async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
119
127
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
120
128
  const id = moduleEntry.id;
121
- const {
122
- format,
123
- compat,
124
- debug,
125
- minify,
126
- bundle,
127
- env: {NODE_ENV: envMode}
128
- } = runtimeEnvironment;
129
+ const {format, compat, debug, minify, bundle} = runtimeEnvironment;
129
130
  const locale = runtimeParams?.["locale"];
130
131
  const environment = runtimeParams?.["environment"];
131
132
  const {
@@ -152,17 +153,10 @@ var LwrModuleRegistry = class {
152
153
  const moduleDef = await this.getModule(moduleId, runtimeParams);
153
154
  const moduleLinked = await this.createLinkedModuleDefinition(moduleDef, runtimeEnvironment, runtimeParams);
154
155
  if (format === "amd" && !bundle) {
155
- moduleLinked.linkedSource = (await this.context.compiler.convertToAmd(moduleLinked.linkedSource, {
156
+ moduleLinked.linkedSource = (await (0, import_compiler.convertToAmd)(moduleLinked.linkedSource, {
156
157
  id: moduleLinked.id
157
158
  })).code;
158
159
  }
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
160
  if (cacheDisabled === false) {
167
161
  const linkedMap = this.moduleLinkedCache.get(id) || new Map();
168
162
  linkedMap.set((0, import_shared_utils.getCacheKeyFromJson)({
@@ -255,6 +249,7 @@ var LwrModuleRegistry = class {
255
249
  return {
256
250
  getModuleEntry: this.getModuleEntry.bind(this),
257
251
  getModule: this.getModule.bind(this),
252
+ getLinkedModule: this.getLinkedModule.bind(this),
258
253
  resolveModuleUri: this.resolveModuleUri.bind(this)
259
254
  };
260
255
  }
@@ -47,12 +47,12 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
47
47
  const context = runtimeParams.environment;
48
48
  if (contextMap?.has(context)) {
49
49
  const overrideSpecifier = contextMap.get(context);
50
- const overrideEntry = await moduleRegistry.getModuleEntry({
51
- specifier: overrideSpecifier
52
- });
50
+ const moduleId = (0, import_shared_utils2.explodeSpecifier)(overrideSpecifier);
51
+ const overrideEntry = await moduleRegistry.getModuleEntry(moduleId);
53
52
  if (overrideEntry) {
54
53
  importRef = {
55
54
  ...importRef,
55
+ ...moduleId,
56
56
  ...overrideEntry
57
57
  };
58
58
  }
@@ -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,11 +27,10 @@ __export(exports, {
27
27
  getBundleSignature: () => getBundleSignature
28
28
  });
29
29
  var import_crypto = __toModule(require("crypto"));
30
- var import_resolve = __toModule(require("resolve"));
31
30
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
- var LWC_VERSION = getLWCVersion();
31
+ var import_config = __toModule(require("@lwrjs/config"));
33
32
  var ENABLED_FINGERPRINTS = !(0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER;
34
- var ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
33
+ var ENV_KEY = `LWC:${import_config.LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
35
34
  async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set(), excludes = new Set()) {
36
35
  if (!modules.length) {
37
36
  return;
@@ -62,8 +61,3 @@ async function getBundleSignature(moduleId, registry, excludes) {
62
61
  await getRecursiveModuleHash([moduleId], registry, hash, new Set(), new Set(excludes));
63
62
  return hash.digest("hex");
64
63
  }
65
- function getLWCVersion() {
66
- const packageJsonPath = import_resolve.default.sync(`lwc/package.json`);
67
- const {version} = JSON.parse((0, import_shared_utils.readFile)(packageJsonPath));
68
- return version;
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 {
@@ -16,7 +15,8 @@ export declare class LwrModuleRegistry implements ModuleRegistry {
16
15
  private interchangeableModules?;
17
16
  private inflightModuleDefinitions;
18
17
  constructor(context: RegistryContext, globalConfig: NormalizedLwrGlobalConfig, registries?: ModuleProvider[]);
19
- resolveModuleUri<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: R, runtimeParams?: RuntimeParams, signature?: S): S extends string ? string : Promise<string>;
18
+ resolveModuleUriSync<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, signature: S, runtimeEnvironment: R, runtimeParams?: RuntimeParams): string;
19
+ resolveModuleUri<R extends RuntimeEnvironment, S extends string | undefined>(moduleId: Required<Pick<ModuleId, 'specifier' | 'version'>>, runtimeEnvironment: R, runtimeParams?: RuntimeParams, signature?: S): Promise<string>;
20
20
  addModuleProviders(registries: ModuleProvider[]): void;
21
21
  getModuleEntry<T extends AbstractModuleId>(moduleId: T, runtimeParams?: RuntimeParams): Promise<ModuleEntry>;
22
22
  getModule<T extends AbstractModuleId>(moduleId: T, runtimeParams?: RuntimeParams): Promise<ModuleDefinition>;
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';
@@ -41,11 +43,21 @@ export class LwrModuleRegistry {
41
43
  }
42
44
  });
43
45
  }
44
- resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
46
+ resolveModuleUriSync(moduleId, signature, runtimeEnvironment, runtimeParams) {
47
+ const uri = esmLinkingStrategy(moduleId, runtimeEnvironment, runtimeParams, signature);
48
+ return uri;
49
+ }
50
+ async resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
51
+ // If we have a signature just sync resolve the uri
45
52
  if (signature !== undefined) {
46
- const uri = esmLinkingStrategy(moduleId, runtimeEnvironment, runtimeParams, signature);
47
- return uri;
53
+ return this.resolveModuleUriSync(moduleId, signature, runtimeEnvironment, runtimeParams);
54
+ }
55
+ // Get the module entry to see if the src is provided by the provider.
56
+ const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
57
+ if (moduleEntry.src) {
58
+ return moduleEntry.src;
48
59
  }
60
+ // Else compute the URL from source
49
61
  const { bundle, format } = runtimeEnvironment;
50
62
  if (bundle) {
51
63
  return new Promise((resolve, reject) => {
@@ -53,7 +65,7 @@ export class LwrModuleRegistry {
53
65
  .then((bundleSignature) => resolve(esmLinkingStrategy(moduleId, runtimeEnvironment, runtimeParams, bundleSignature)))
54
66
  .catch(reject);
55
67
  });
56
- // For individual files we a module URL
68
+ // For individual files we return a module URL
57
69
  }
58
70
  else {
59
71
  return new Promise((resolve, reject) => {
@@ -98,17 +110,17 @@ export class LwrModuleRegistry {
98
110
  // in addition to being explicitly enabled.
99
111
  const { minify, sourceMapUrl } = runtimeEnvironment;
100
112
  const sourcemap = typeof sourceMapUrl === 'string' || !minify;
101
- const { code: lockerizedCode } = this.context.compiler.lockerize(moduleCompiled, locker, sourcemap);
113
+ const { code: lockerizedCode } = lockerize(moduleCompiled, locker, sourcemap);
102
114
  moduleCompiled.compiledSource = lockerizedCode;
103
115
  }
104
- const moduleRecord = await getModuleRecord(moduleCompiled, this, this.context.compiler);
116
+ const moduleRecord = await getModuleRecord(moduleCompiled, this);
105
117
  return { ...moduleCompiled, moduleRecord };
106
118
  }
107
119
  async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
108
120
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
109
121
  const id = moduleEntry.id;
110
122
  // cache key pivots from the runtimeEnvironment
111
- const { format, compat, debug, minify, bundle, env: { NODE_ENV: envMode }, } = runtimeEnvironment;
123
+ const { format, compat, debug, minify, bundle } = runtimeEnvironment;
112
124
  const locale = runtimeParams?.['locale'];
113
125
  const environment = runtimeParams?.['environment'];
114
126
  const { locker: { enabled: lockerEnabled }, } = this.globalConfig;
@@ -135,19 +147,10 @@ export class LwrModuleRegistry {
135
147
  // the bundler will convert the linked source to AMD when bundling is enabled
136
148
  if (format === 'amd' && !bundle) {
137
149
  // convert the linkedSource to the transport AMD format
138
- moduleLinked.linkedSource = (await this.context.compiler.convertToAmd(moduleLinked.linkedSource, {
150
+ moduleLinked.linkedSource = (await convertToAmd(moduleLinked.linkedSource, {
139
151
  id: moduleLinked.id,
140
152
  })).code;
141
153
  }
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
154
  // Add to cache
152
155
  if (cacheDisabled === false) {
153
156
  const linkedMap = this.moduleLinkedCache.get(id) || new Map();
@@ -245,6 +248,7 @@ export class LwrModuleRegistry {
245
248
  return {
246
249
  getModuleEntry: this.getModuleEntry.bind(this),
247
250
  getModule: this.getModule.bind(this),
251
+ getLinkedModule: this.getLinkedModule.bind(this),
248
252
  resolveModuleUri: this.resolveModuleUri.bind(this),
249
253
  };
250
254
  }
@@ -27,12 +27,12 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
27
27
  const context = runtimeParams.environment;
28
28
  if (contextMap?.has(context)) {
29
29
  const overrideSpecifier = contextMap.get(context);
30
- const overrideEntry = await moduleRegistry.getModuleEntry({
31
- specifier: overrideSpecifier,
32
- });
30
+ const moduleId = explodeSpecifier(overrideSpecifier);
31
+ const overrideEntry = await moduleRegistry.getModuleEntry(moduleId);
33
32
  if (overrideEntry) {
34
33
  importRef = {
35
34
  ...importRef,
35
+ ...moduleId,
36
36
  ...overrideEntry,
37
37
  };
38
38
  }
@@ -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,7 +1,6 @@
1
1
  import crypto from 'crypto';
2
- import resolve from 'resolve';
3
- import { getFeatureFlags, getSpecifier, readFile } from '@lwrjs/shared-utils';
4
- const LWC_VERSION = getLWCVersion();
2
+ import { getFeatureFlags, getSpecifier } from '@lwrjs/shared-utils';
3
+ import { LWC_VERSION } from '@lwrjs/config';
5
4
  const ENABLED_FINGERPRINTS = !getFeatureFlags().LEGACY_LOADER;
6
5
  const ENV_KEY = `LWC:${LWC_VERSION},FINGERPRINTS:${ENABLED_FINGERPRINTS}`;
7
6
  async function getRecursiveModuleHash(modules, registry, hash, visitedDefinitions = new Set(), excludes = new Set()) {
@@ -65,12 +64,4 @@ export async function getBundleSignature(moduleId, registry, excludes) {
65
64
  await getRecursiveModuleHash([moduleId], registry, hash, new Set(), new Set(excludes));
66
65
  return hash.digest('hex');
67
66
  }
68
- /**
69
- * Get the configured LWC version
70
- */
71
- function getLWCVersion() {
72
- const packageJsonPath = resolve.sync(`lwc/package.json`);
73
- const { version } = JSON.parse(readFile(packageJsonPath));
74
- return version;
75
- }
76
67
  //# 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.9-alpha.8",
7
+ "version": "0.10.0-alpha.1",
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.9-alpha.8",
34
- "@lwrjs/shared-utils": "0.9.9-alpha.8",
35
- "es-module-lexer": "^0.3.18"
33
+ "@locker/compiler": "0.18.14",
34
+ "@lwrjs/diagnostics": "0.10.0-alpha.1",
35
+ "@lwrjs/shared-utils": "0.10.0-alpha.1",
36
+ "es-module-lexer": "^0.3.18",
37
+ "rollup": "~2.45.2"
36
38
  },
37
39
  "devDependencies": {
38
- "@lwrjs/types": "0.9.9-alpha.8",
40
+ "@lwrjs/types": "0.10.0-alpha.1",
39
41
  "@types/es-module-lexer": "^0.3.0"
40
42
  },
41
43
  "engines": {
42
- "node": ">=14.15.4 <19"
44
+ "node": ">=16.0.0 <20"
43
45
  },
44
- "gitHead": "ac15f9c862f53f0fab34ea229c8c27b1d66c9f7e"
46
+ "gitHead": "2683dd5839b4da2ed93d42874cfceb78cbb5bf0d"
45
47
  }