@lwrjs/module-registry 0.5.11 → 0.6.0-0.6.0-alpha.15.0
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 +19 -9
- package/build/cjs/linker/linker.cjs +14 -9
- package/build/cjs/linker/strategies/esm-strategy.cjs +1 -1
- package/build/cjs/module-record.cjs +2 -2
- package/build/cjs/signature.cjs +2 -1
- package/build/es/index.d.ts +2 -0
- package/build/es/index.js +25 -13
- package/build/es/linker/linker.d.ts +1 -1
- package/build/es/linker/linker.js +15 -8
- package/build/es/linker/strategies/esm-strategy.js +2 -3
- package/build/es/module-record.js +2 -2
- package/build/es/signature.js +2 -1
- package/package.json +6 -7
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);
|
|
@@ -153,7 +161,7 @@ var LwrModuleRegistry = class {
|
|
|
153
161
|
id,
|
|
154
162
|
code: linkedES6,
|
|
155
163
|
linkedModuleRecord
|
|
156
|
-
} = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, runtimeEnvironment, runtimeParams, {
|
|
164
|
+
} = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, {
|
|
157
165
|
amdLoaderModule: loaderModuleEntry
|
|
158
166
|
}, this.interchangeableModules);
|
|
159
167
|
const {code: amdSource} = await this.context.compiler.convertToAmd(linkedES6, {
|
|
@@ -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,
|
|
@@ -176,10 +185,10 @@ var LwrModuleRegistry = class {
|
|
|
176
185
|
} else {
|
|
177
186
|
let loaderModuleEntry;
|
|
178
187
|
const dynamicImports = moduleDef.moduleRecord.dynamicImports;
|
|
179
|
-
if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports
|
|
188
|
+
if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports) {
|
|
180
189
|
loaderModuleEntry = await this.getModuleEntry({specifier: esmLoader}, runtimeParams);
|
|
181
190
|
}
|
|
182
|
-
const {code: esmLinkedSource, linkedModuleRecord} = await (0, import_linker.link)(this, moduleDef, import_esm_strategy.default, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
|
|
191
|
+
const {code: esmLinkedSource, linkedModuleRecord} = await (0, import_linker.link)(this, moduleDef, import_amd_strategy.default, import_esm_strategy.default, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
|
|
183
192
|
esmLoaderModule: loaderModuleEntry
|
|
184
193
|
}, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
|
|
185
194
|
let transformedEsmCode = esmLinkedSource;
|
|
@@ -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: {
|
|
@@ -26,15 +26,16 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
link: () => link
|
|
28
28
|
});
|
|
29
|
-
var import_magic_string = __toModule(require("magic-string"));
|
|
30
29
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
|
+
var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
|
|
31
31
|
var import_signature = __toModule(require("../signature.cjs"));
|
|
32
|
-
async function link(moduleRegistry, moduleDef,
|
|
32
|
+
async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
|
|
33
33
|
const {specifier, version, compiledSource, moduleRecord} = moduleDef;
|
|
34
34
|
const {imports, dynamicImports} = moduleRecord;
|
|
35
|
-
const codeStringBuilder =
|
|
35
|
+
const codeStringBuilder = (0, import_shared_utils.createStringBuilder)(compiledSource);
|
|
36
36
|
const amdLoaderModule = config?.amdLoaderModule;
|
|
37
37
|
const esmLoaderModule = config?.esmLoaderModule;
|
|
38
|
+
const strategy = amdLoaderModule ? versionStrategy : uriStrategy;
|
|
38
39
|
const id = strategy({specifier, version}, runtimeEnvironment, runtimeParams);
|
|
39
40
|
let linkedImports = [];
|
|
40
41
|
let linkedDynamicImports = [];
|
|
@@ -80,22 +81,22 @@ async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironment, run
|
|
|
80
81
|
linkedDynamicImports = await Promise.all(dynamicImports.map(async (importRef) => {
|
|
81
82
|
const {locations, sourceSpecifier} = importRef;
|
|
82
83
|
let signature;
|
|
83
|
-
const isStringLiteral = importRef.moduleNameType ===
|
|
84
|
+
const isStringLiteral = importRef.moduleNameType === import_shared_utils2.ModuleNameType.string;
|
|
84
85
|
if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === "esm") {
|
|
85
86
|
signature = await (0, import_signature.getBundleSignature)(importRef, moduleRegistry);
|
|
86
87
|
}
|
|
87
|
-
const link2 = isStringLiteral ?
|
|
88
|
+
const link2 = isStringLiteral ? versionStrategy(importRef, runtimeEnvironment, runtimeParams, signature) : importRef.specifier;
|
|
88
89
|
const linkedLocations = locations.map(({location, importLocation}) => {
|
|
89
90
|
const {startColumn, endColumn} = location;
|
|
90
91
|
const {startColumn: importStart, endColumn: importEnd} = importLocation;
|
|
91
92
|
if (isStringLiteral) {
|
|
92
93
|
codeStringBuilder.overwrite(startColumn + 1, endColumn - 1, link2);
|
|
93
94
|
}
|
|
94
|
-
if (amdLoaderModule || esmLoaderModule
|
|
95
|
+
if (amdLoaderModule || esmLoaderModule) {
|
|
95
96
|
codeStringBuilder.overwrite(importStart, importEnd, "load(");
|
|
96
97
|
loaderSizeOffset = 2;
|
|
97
98
|
if (!isStringLiteral) {
|
|
98
|
-
const importerSpecifier = (0,
|
|
99
|
+
const importerSpecifier = (0, import_shared_utils2.getSpecifier)({specifier, version});
|
|
99
100
|
codeStringBuilder.overwrite(endColumn, endColumn + 1, `, '${importerSpecifier}')`);
|
|
100
101
|
loaderSizeOffset = -1 * importerSpecifier.length - 2;
|
|
101
102
|
}
|
|
@@ -116,8 +117,12 @@ async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironment, run
|
|
|
116
117
|
}
|
|
117
118
|
if (dynamicImports && dynamicImports.length > 0 && (amdLoaderModule || esmLoaderModule)) {
|
|
118
119
|
const {version: version2, specifier: specifier2} = amdLoaderModule || esmLoaderModule;
|
|
119
|
-
const {namespace, name} = (0,
|
|
120
|
-
|
|
120
|
+
const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(specifier2);
|
|
121
|
+
let signature;
|
|
122
|
+
if (esmLoaderModule && runtimeEnvironment.bundle) {
|
|
123
|
+
signature = await (0, import_signature.getBundleSignature)({version: version2, specifier: specifier2}, moduleRegistry);
|
|
124
|
+
}
|
|
125
|
+
const loaderLink = strategy({specifier: specifier2, version: version2}, runtimeEnvironment, runtimeParams, signature);
|
|
121
126
|
codeStringBuilder.prepend(`import { load } from "${loaderLink}";
|
|
122
127
|
`);
|
|
123
128
|
linkedImports.unshift({
|
|
@@ -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
|
}
|
|
@@ -79,7 +79,7 @@ async function getModuleRecord(compiledModule, registry, compiler) {
|
|
|
79
79
|
imports: compiledModuleImports,
|
|
80
80
|
dynamicImports: compiledModuleDynamicImports
|
|
81
81
|
});
|
|
82
|
-
if (compiledMetadata && compiledMetadata.imports) {
|
|
82
|
+
if (compiledMetadata && compiledMetadata.imports && compiledMetadata.imports.length > 0) {
|
|
83
83
|
const visitedImports = new Set();
|
|
84
84
|
for (const {moduleSpecifier, location} of compiledMetadata.imports) {
|
|
85
85
|
if (!visitedImports.has(moduleSpecifier)) {
|
|
@@ -99,7 +99,7 @@ async function getModuleRecord(compiledModule, registry, compiler) {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
if (compiledMetadata && compiledMetadata.dynamicImports) {
|
|
102
|
+
if (compiledMetadata && compiledMetadata.dynamicImports && compiledMetadata.dynamicImports.length > 0) {
|
|
103
103
|
const visitedDynamicImports = new Set();
|
|
104
104
|
for (const {
|
|
105
105
|
moduleSpecifier,
|
package/build/cjs/signature.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_crypto = __toModule(require("crypto"));
|
|
30
30
|
var import_path = __toModule(require("path"));
|
|
31
|
+
var import_process = __toModule(require("process"));
|
|
31
32
|
var import_module = __toModule(require("module"));
|
|
32
33
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
33
34
|
var LWC_VERSION = getLWCVersion();
|
|
@@ -62,7 +63,7 @@ async function getBundleSignature(moduleId, registry) {
|
|
|
62
63
|
return hash.digest("hex");
|
|
63
64
|
}
|
|
64
65
|
function getLWCVersion() {
|
|
65
|
-
const require2 = (0, import_module.createRequire)(import_path.default.join(
|
|
66
|
+
const require2 = (0, import_module.createRequire)(import_path.default.join((0, import_process.cwd)(), "./env-config.js"));
|
|
66
67
|
const {version} = require2("lwc/package.json");
|
|
67
68
|
return version;
|
|
68
69
|
}
|
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);
|
|
@@ -137,7 +147,7 @@ export class LwrModuleRegistry {
|
|
|
137
147
|
// Resolve the loader entry
|
|
138
148
|
const loaderModuleEntry = await this.getModuleEntry({ specifier: amdLoader }, runtimeParams);
|
|
139
149
|
// transforms compiledModule into linkedModule (which means the imports may have changed)
|
|
140
|
-
const { id, code: linkedES6, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, runtimeEnvironment, runtimeParams, {
|
|
150
|
+
const { id, code: linkedES6, linkedModuleRecord, } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, {
|
|
141
151
|
amdLoaderModule: loaderModuleEntry,
|
|
142
152
|
}, this.interchangeableModules);
|
|
143
153
|
// convert the linkedSource to the transport AMD format.
|
|
@@ -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,
|
|
@@ -163,14 +175,12 @@ export class LwrModuleRegistry {
|
|
|
163
175
|
// resolve the loader entry if there are VARIABLE dynamic imports
|
|
164
176
|
let loaderModuleEntry;
|
|
165
177
|
const dynamicImports = moduleDef.moduleRecord.dynamicImports;
|
|
166
|
-
if (moduleDef.moduleEntry.specifier !== esmLoader &&
|
|
167
|
-
|
|
168
|
-
dynamicImports.some((d) => d.moduleNameType === ModuleNameType.unresolved)) {
|
|
169
|
-
// ONLY include the ESM loader if there are VARIABLE dynamic imports
|
|
178
|
+
if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports) {
|
|
179
|
+
// ONLY include the ESM loader if there are dynamic imports
|
|
170
180
|
// AND this is not the ESM loader itself (it uses a variable dynamic import we DO NOT want to link)
|
|
171
181
|
loaderModuleEntry = await this.getModuleEntry({ specifier: esmLoader }, runtimeParams);
|
|
172
182
|
}
|
|
173
|
-
const { code: esmLinkedSource, linkedModuleRecord } = await link(this, moduleDef, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
|
|
183
|
+
const { code: esmLinkedSource, linkedModuleRecord } = await link(this, moduleDef, amdLinkingStrategy, esmLinkingStrategy, runtimeEnvironment, runtimeParams, loaderModuleEntry && {
|
|
174
184
|
esmLoaderModule: loaderModuleEntry,
|
|
175
185
|
}, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
|
|
176
186
|
let transformedEsmCode = esmLinkedSource;
|
|
@@ -178,6 +188,8 @@ export class LwrModuleRegistry {
|
|
|
178
188
|
const { code: minifiedEsm } = await this.context.compiler.minifyJavascript(transformedEsmCode);
|
|
179
189
|
transformedEsmCode = minifiedEsm;
|
|
180
190
|
}
|
|
191
|
+
// Filter out variable dynamic imports
|
|
192
|
+
linkedModuleRecord.dynamicImports = linkedModuleRecord.dynamicImports?.filter((imp) => imp.moduleNameType !== ModuleNameType.unresolved);
|
|
181
193
|
return {
|
|
182
194
|
...moduleDef,
|
|
183
195
|
linkedConfig: {
|
|
@@ -24,6 +24,6 @@ export interface ModuleLinkResult {
|
|
|
24
24
|
* @param moduleRecord
|
|
25
25
|
* @param strategy
|
|
26
26
|
*/
|
|
27
|
-
export declare function link(moduleRegistry: LwrModuleRegistry, moduleDef: ModuleDefinition,
|
|
27
|
+
export declare function link(moduleRegistry: LwrModuleRegistry, moduleDef: ModuleDefinition, versionStrategy: LinkingStrategy, uriStrategy: LinkingStrategy, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, config?: LinkerConfig, interchangeableModules?: InterchangeableModuleMap, exclude?: string[]): Promise<ModuleLinkResult>;
|
|
28
28
|
export {};
|
|
29
29
|
//# sourceMappingURL=linker.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createStringBuilder } from '@lwrjs/shared-utils';
|
|
2
2
|
import { explodeSpecifier, getSpecifier, ModuleNameType } from '@lwrjs/shared-utils';
|
|
3
3
|
import { getBundleSignature } from '../signature.js';
|
|
4
4
|
/**
|
|
@@ -7,12 +7,13 @@ import { getBundleSignature } from '../signature.js';
|
|
|
7
7
|
* @param moduleRecord
|
|
8
8
|
* @param strategy
|
|
9
9
|
*/
|
|
10
|
-
export async function link(moduleRegistry, moduleDef,
|
|
10
|
+
export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
|
|
11
11
|
const { specifier, version, compiledSource, moduleRecord } = moduleDef;
|
|
12
12
|
const { imports, dynamicImports } = moduleRecord;
|
|
13
|
-
const codeStringBuilder =
|
|
13
|
+
const codeStringBuilder = createStringBuilder(compiledSource);
|
|
14
14
|
const amdLoaderModule = config?.amdLoaderModule;
|
|
15
15
|
const esmLoaderModule = config?.esmLoaderModule;
|
|
16
|
+
const strategy = amdLoaderModule ? versionStrategy : uriStrategy;
|
|
16
17
|
const id = strategy({ specifier, version }, runtimeEnvironment, runtimeParams);
|
|
17
18
|
// transform each import using the provided linking strategy.
|
|
18
19
|
let linkedImports = [];
|
|
@@ -70,9 +71,11 @@ export async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironme
|
|
|
70
71
|
if (isStringLiteral && runtimeEnvironment.bundle && runtimeEnvironment.format === 'esm') {
|
|
71
72
|
signature = await getBundleSignature(importRef, moduleRegistry);
|
|
72
73
|
}
|
|
74
|
+
// always link [literal] dynamic imports as versioned specifiers (AMD strategy)
|
|
75
|
+
// linking them as URIs (ESM strategy) causes caching issues since they can contain stale signatures
|
|
73
76
|
const link = isStringLiteral
|
|
74
|
-
?
|
|
75
|
-
: importRef.specifier; // variable dynamic
|
|
77
|
+
? versionStrategy(importRef, runtimeEnvironment, runtimeParams, signature) // dynamic import of a static string
|
|
78
|
+
: importRef.specifier; // variable dynamic imports: keep the variable name as-is
|
|
76
79
|
// transform locations
|
|
77
80
|
// replace all locations of importee with the link
|
|
78
81
|
const linkedLocations = locations.map(({ location, importLocation }) => {
|
|
@@ -82,9 +85,8 @@ export async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironme
|
|
|
82
85
|
if (isStringLiteral) {
|
|
83
86
|
codeStringBuilder.overwrite(startColumn + 1, endColumn - 1, link);
|
|
84
87
|
}
|
|
85
|
-
if (amdLoaderModule ||
|
|
88
|
+
if (amdLoaderModule || esmLoaderModule) {
|
|
86
89
|
// replace the dynamic import with a configured loader
|
|
87
|
-
// ONLY do this in ESM if the dynamic import is VARIABLE
|
|
88
90
|
// e.g. - await import('dynamic/module'); -> await load('dynamic/module');
|
|
89
91
|
codeStringBuilder.overwrite(importStart, importEnd, 'load(');
|
|
90
92
|
loaderSizeOffset = 2;
|
|
@@ -114,7 +116,12 @@ export async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironme
|
|
|
114
116
|
// mutate ModuleEntry to ImportModuleRecord
|
|
115
117
|
const { version, specifier } = amdLoaderModule || esmLoaderModule;
|
|
116
118
|
const { namespace, name } = explodeSpecifier(specifier);
|
|
117
|
-
|
|
119
|
+
let signature;
|
|
120
|
+
if (esmLoaderModule && runtimeEnvironment.bundle) {
|
|
121
|
+
// Ensure the ESM loader is signed, or there may be a clash between this import and an existing one
|
|
122
|
+
signature = await getBundleSignature({ version, specifier }, moduleRegistry);
|
|
123
|
+
}
|
|
124
|
+
const loaderLink = strategy({ specifier, version }, runtimeEnvironment, runtimeParams, signature);
|
|
118
125
|
// import {load} from 'loader/loader'
|
|
119
126
|
codeStringBuilder.prepend(`import { load } from "${loaderLink}";\n`);
|
|
120
127
|
linkedImports.unshift({
|
|
@@ -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
|
}
|
|
@@ -63,7 +63,7 @@ export async function getModuleRecord(compiledModule, registry, compiler) {
|
|
|
63
63
|
dynamicImports: compiledModuleDynamicImports,
|
|
64
64
|
});
|
|
65
65
|
// Process imports
|
|
66
|
-
if (compiledMetadata && compiledMetadata.imports) {
|
|
66
|
+
if (compiledMetadata && compiledMetadata.imports && compiledMetadata.imports.length > 0) {
|
|
67
67
|
const visitedImports = new Set(); // Avoids multiple imports to the same specifier
|
|
68
68
|
for (const { moduleSpecifier, location } of compiledMetadata.imports) {
|
|
69
69
|
// Check for dupes first
|
|
@@ -90,7 +90,7 @@ export async function getModuleRecord(compiledModule, registry, compiler) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
// Process dynamic imports
|
|
93
|
-
if (compiledMetadata && compiledMetadata.dynamicImports) {
|
|
93
|
+
if (compiledMetadata && compiledMetadata.dynamicImports && compiledMetadata.dynamicImports.length > 0) {
|
|
94
94
|
const visitedDynamicImports = new Set(); // Avoids multiple imports to the same specifier
|
|
95
95
|
for (const { moduleSpecifier, location, importLocation, moduleNameType, } of compiledMetadata.dynamicImports) {
|
|
96
96
|
// Check for dupes first
|
package/build/es/signature.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { cwd } from 'process';
|
|
3
4
|
import { createRequire } from 'module';
|
|
4
5
|
import { getExperimentalFeatures } from '@lwrjs/shared-utils';
|
|
5
6
|
const LWC_VERSION = getLWCVersion();
|
|
@@ -37,7 +38,7 @@ export async function getBundleSignature(moduleId, registry) {
|
|
|
37
38
|
* Get the configured LWC version
|
|
38
39
|
*/
|
|
39
40
|
function getLWCVersion() {
|
|
40
|
-
const require = createRequire(path.join(
|
|
41
|
+
const require = createRequire(path.join(cwd(), './env-config.js'));
|
|
41
42
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
42
43
|
const { version } = require('lwc/package.json');
|
|
43
44
|
return version;
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-0.6.0-alpha.15.0",
|
|
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,19 +30,18 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/diagnostics": "0.
|
|
34
|
-
"@lwrjs/shared-utils": "0.
|
|
33
|
+
"@lwrjs/diagnostics": "0.6.0-0.6.0-alpha.15.0",
|
|
34
|
+
"@lwrjs/shared-utils": "0.6.0-0.6.0-alpha.15.0",
|
|
35
35
|
"es-module-lexer": "^0.3.18",
|
|
36
|
-
"magic-string": "^0.25.7",
|
|
37
36
|
"ws": "^7.2.5"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@lwrjs/types": "0.
|
|
39
|
+
"@lwrjs/types": "0.6.0-0.6.0-alpha.15.0",
|
|
41
40
|
"@types/es-module-lexer": "^0.3.0",
|
|
42
41
|
"@types/ws": "^7.2.4"
|
|
43
42
|
},
|
|
44
43
|
"engines": {
|
|
45
44
|
"node": ">=14.15.4 <17"
|
|
46
45
|
},
|
|
47
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "101ad971f5a7b0631dd149ee4e3aa1d1799a7af2"
|
|
48
47
|
}
|