@lwrjs/module-registry 0.6.0-alpha.3 → 0.6.0-alpha.7
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.
package/build/cjs/index.cjs
CHANGED
|
@@ -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
|
-
|
|
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: {
|
|
@@ -37,7 +37,7 @@ function linkEsm(moduleId, environment, params = {}, signature) {
|
|
|
37
37
|
const encodedVSpecifier = encodeURIComponent(vSpecifier);
|
|
38
38
|
const latestSignature = signature === void 0 || signature === LATEST_SIG;
|
|
39
39
|
const sigilSignature = latestSignature ? LATEST_SIG : `${SIGNATURE_SIGIL}/${signature}`;
|
|
40
|
-
const prettyUrl = (bundle ? "bundle_" : "") +
|
|
40
|
+
const prettyUrl = (bundle ? "bundle_" : "") + (0, import_shared_utils.prettyModuleUriSuffix)(specifier);
|
|
41
41
|
const debugModifier = debug ? "?debug=true" : "";
|
|
42
42
|
return `${uriPrefix}${encodedVSpecifier}/${sigilSignature}/${prettyUrl}.js${debugModifier}`;
|
|
43
43
|
}
|
package/build/es/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
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: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getModuleUriPrefix, getSpecifier, normalizeVersionToUri } from '@lwrjs/shared-utils';
|
|
1
|
+
import { getModuleUriPrefix, getSpecifier, normalizeVersionToUri, prettyModuleUriSuffix, } from '@lwrjs/shared-utils';
|
|
2
2
|
const SIGNATURE_SIGIL = 's';
|
|
3
3
|
const LATEST_SIG = 'latest';
|
|
4
4
|
export default function linkEsm(moduleId, environment, params = {}, signature) {
|
|
@@ -9,8 +9,7 @@ export default function linkEsm(moduleId, environment, params = {}, signature) {
|
|
|
9
9
|
const encodedVSpecifier = encodeURIComponent(vSpecifier);
|
|
10
10
|
const latestSignature = signature === undefined || signature === LATEST_SIG;
|
|
11
11
|
const sigilSignature = latestSignature ? LATEST_SIG : `${SIGNATURE_SIGIL}/${signature}`;
|
|
12
|
-
|
|
13
|
-
const prettyUrl = (bundle ? 'bundle_' : '') + `${specifier.replace(/[\/\.\#]/g, '_')}`;
|
|
12
|
+
const prettyUrl = (bundle ? 'bundle_' : '') + prettyModuleUriSuffix(specifier);
|
|
14
13
|
const debugModifier = debug ? '?debug=true' : '';
|
|
15
14
|
return `${uriPrefix}${encodedVSpecifier}/${sigilSignature}/${prettyUrl}.js${debugModifier}`;
|
|
16
15
|
}
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.0-alpha.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.7",
|
|
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.
|
|
34
|
-
"@lwrjs/shared-utils": "0.6.0-alpha.
|
|
33
|
+
"@lwrjs/diagnostics": "0.6.0-alpha.7",
|
|
34
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.7",
|
|
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.
|
|
39
|
+
"@lwrjs/types": "0.6.0-alpha.7",
|
|
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": "
|
|
46
|
+
"gitHead": "dc066450384dc1e27064b46ddd5f24543758a414"
|
|
47
47
|
}
|