@lwrjs/module-registry 0.6.0-alpha.5 → 0.6.0-alpha.6

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.
@@ -38,6 +38,7 @@ var LwrModuleRegistry = class {
38
38
  this.providers = [];
39
39
  this.moduleDefCache = new Map();
40
40
  this.moduleLinkedCache = new Map();
41
+ this.inflightModuleDefinitions = new import_shared_utils.InflightTasks();
41
42
  this.name = "lwr-module-registry";
42
43
  this.context = context;
43
44
  this.globalConfig = globalConfig;
@@ -88,12 +89,23 @@ var LwrModuleRegistry = class {
88
89
  return this.delegateGetModuleEntryOnServices(moduleId, runtimeParams);
89
90
  }
90
91
  async getModule(moduleId, runtimeParams) {
91
- const {locker} = this.globalConfig;
92
92
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
93
93
  const cacheDisabled = process.env.NOCACHE === "true";
94
94
  if (cacheDisabled === false && this.moduleDefCache.has(moduleEntry.id)) {
95
95
  return this.moduleDefCache.get(moduleEntry.id);
96
96
  }
97
+ const createModulePromiseCtor = async () => {
98
+ return this.createModuleDefinition(moduleId, runtimeParams).then((moduleDef) => {
99
+ if (cacheDisabled === false) {
100
+ this.moduleDefCache.set(moduleDef.id, moduleDef);
101
+ }
102
+ return moduleDef;
103
+ });
104
+ };
105
+ return this.inflightModuleDefinitions.execute(moduleEntry.id, createModulePromiseCtor, this);
106
+ }
107
+ async createModuleDefinition(moduleId, runtimeParams) {
108
+ const {locker} = this.globalConfig;
97
109
  const moduleCompiled = await this.delegateGetModuleOnProviders(moduleId, runtimeParams);
98
110
  if (locker.enabled && !locker.clientOnly) {
99
111
  const {runtimeEnvironment} = this.context;
@@ -102,11 +114,7 @@ var LwrModuleRegistry = class {
102
114
  moduleCompiled.compiledSource = lockerizedCode;
103
115
  }
104
116
  const moduleRecord = await (0, import_module_record.getModuleRecord)(moduleCompiled, this, this.context.compiler);
105
- const moduleDef = {...moduleCompiled, moduleRecord};
106
- if (cacheDisabled === false) {
107
- this.moduleDefCache.set(moduleDef.id, moduleDef);
108
- }
109
- return moduleDef;
117
+ return {...moduleCompiled, moduleRecord};
110
118
  }
111
119
  async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
112
120
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
@@ -164,6 +172,7 @@ var LwrModuleRegistry = class {
164
172
  const {code: minifiedCode} = await this.context.compiler.minifyJavascript(amdSource);
165
173
  linkedAmdSource = minifiedCode;
166
174
  }
175
+ linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== import_shared_utils.ModuleNameType.unresolved);
167
176
  return {
168
177
  ...moduleDef,
169
178
  linkedSource: linkedAmdSource,
@@ -187,6 +196,7 @@ var LwrModuleRegistry = class {
187
196
  const {code: minifiedEsm} = await this.context.compiler.minifyJavascript(transformedEsmCode);
188
197
  transformedEsmCode = minifiedEsm;
189
198
  }
199
+ linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== import_shared_utils.ModuleNameType.unresolved);
190
200
  return {
191
201
  ...moduleDef,
192
202
  linkedConfig: {
@@ -14,11 +14,13 @@ export declare class LwrModuleRegistry implements ModuleRegistry {
14
14
  emitter: LwrAppEmitter;
15
15
  globalConfig: NormalizedLwrGlobalConfig;
16
16
  private interchangeableModules?;
17
+ private inflightModuleDefinitions;
17
18
  constructor(context: RegistryContext, globalConfig: NormalizedLwrGlobalConfig, registries?: ModuleProvider[]);
18
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>;
19
20
  addModuleProviders(registries: ModuleProvider[]): void;
20
21
  getModuleEntry<T extends AbstractModuleId>(moduleId: T, runtimeParams?: RuntimeParams): Promise<ModuleEntry>;
21
22
  getModule<T extends AbstractModuleId>(moduleId: T, runtimeParams?: RuntimeParams): Promise<ModuleDefinition>;
23
+ private createModuleDefinition;
22
24
  getLinkedModule<T extends AbstractModuleId>(moduleId: T, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<LinkedModuleDefinition>;
23
25
  private createLinkedModuleDefinition;
24
26
  private delegateGetModuleEntryOnServices;
package/build/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
2
- import { discoverInterchangeableModules, getCacheKeyFromJson, LATEST_SIGNATURE, ModuleNameType, } from '@lwrjs/shared-utils';
2
+ import { discoverInterchangeableModules, getCacheKeyFromJson, InflightTasks, LATEST_SIGNATURE, ModuleNameType, } from '@lwrjs/shared-utils';
3
3
  import { link } from './linker/linker.js';
4
4
  import { getModuleRecord } from './module-record.js';
5
5
  import amdLinkingStrategy from './linker/strategies/amd-strategy.js';
@@ -10,6 +10,7 @@ export class LwrModuleRegistry {
10
10
  this.providers = [];
11
11
  this.moduleDefCache = new Map();
12
12
  this.moduleLinkedCache = new Map();
13
+ this.inflightModuleDefinitions = new InflightTasks();
13
14
  this.name = 'lwr-module-registry';
14
15
  this.context = context;
15
16
  this.globalConfig = globalConfig;
@@ -72,12 +73,25 @@ export class LwrModuleRegistry {
72
73
  return this.delegateGetModuleEntryOnServices(moduleId, runtimeParams);
73
74
  }
74
75
  async getModule(moduleId, runtimeParams) {
75
- const { locker } = this.globalConfig;
76
76
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
77
77
  const cacheDisabled = process.env.NOCACHE === 'true';
78
78
  if (cacheDisabled === false && this.moduleDefCache.has(moduleEntry.id)) {
79
+ // TODO add to profiling
80
+ // console.log('[INFO] Module Cache Hit: %s', moduleEntry.id);
79
81
  return this.moduleDefCache.get(moduleEntry.id);
80
82
  }
83
+ const createModulePromiseCtor = async () => {
84
+ return this.createModuleDefinition(moduleId, runtimeParams).then((moduleDef) => {
85
+ if (cacheDisabled === false) {
86
+ this.moduleDefCache.set(moduleDef.id, moduleDef);
87
+ }
88
+ return moduleDef;
89
+ });
90
+ };
91
+ return this.inflightModuleDefinitions.execute(moduleEntry.id, createModulePromiseCtor, this);
92
+ }
93
+ async createModuleDefinition(moduleId, runtimeParams) {
94
+ const { locker } = this.globalConfig;
81
95
  const moduleCompiled = await this.delegateGetModuleOnProviders(moduleId, runtimeParams); // provider source + hash
82
96
  /** Locker before collecting dep module records so locker imports are processed normally */
83
97
  if (locker.enabled && !locker.clientOnly) {
@@ -87,11 +101,7 @@ export class LwrModuleRegistry {
87
101
  moduleCompiled.compiledSource = lockerizedCode;
88
102
  }
89
103
  const moduleRecord = await getModuleRecord(moduleCompiled, this, this.context.compiler);
90
- const moduleDef = { ...moduleCompiled, moduleRecord };
91
- if (cacheDisabled === false) {
92
- this.moduleDefCache.set(moduleDef.id, moduleDef);
93
- }
94
- return moduleDef;
104
+ return { ...moduleCompiled, moduleRecord };
95
105
  }
96
106
  async getLinkedModule(moduleId, runtimeEnvironment, runtimeParams) {
97
107
  const moduleEntry = await this.getModuleEntry(moduleId, runtimeParams);
@@ -149,6 +159,8 @@ export class LwrModuleRegistry {
149
159
  const { code: minifiedCode } = await this.context.compiler.minifyJavascript(amdSource);
150
160
  linkedAmdSource = minifiedCode;
151
161
  }
162
+ // Filter out variable dynamic imports
163
+ linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== ModuleNameType.unresolved);
152
164
  return {
153
165
  ...moduleDef,
154
166
  linkedSource: linkedAmdSource,
@@ -178,6 +190,8 @@ export class LwrModuleRegistry {
178
190
  const { code: minifiedEsm } = await this.context.compiler.minifyJavascript(transformedEsmCode);
179
191
  transformedEsmCode = minifiedEsm;
180
192
  }
193
+ // Filter out variable dynamic imports
194
+ linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== ModuleNameType.unresolved);
181
195
  return {
182
196
  ...moduleDef,
183
197
  linkedConfig: {
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.5",
8
- "homepage": "https://lwr.dev/",
7
+ "version": "0.6.0-alpha.6",
8
+ "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/salesforce/lwr.git",
@@ -30,18 +30,18 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/diagnostics": "0.6.0-alpha.5",
34
- "@lwrjs/shared-utils": "0.6.0-alpha.5",
33
+ "@lwrjs/diagnostics": "0.6.0-alpha.6",
34
+ "@lwrjs/shared-utils": "0.6.0-alpha.6",
35
35
  "es-module-lexer": "^0.3.18",
36
36
  "ws": "^7.2.5"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.6.0-alpha.5",
39
+ "@lwrjs/types": "0.6.0-alpha.6",
40
40
  "@types/es-module-lexer": "^0.3.0",
41
41
  "@types/ws": "^7.2.4"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=14.15.4 <17"
45
45
  },
46
- "gitHead": "56b2b35fd0a2b519c548c0e98c5136b0993ce73f"
46
+ "gitHead": "5d624e196dd46787399e6a269479508abe236081"
47
47
  }