@lwrjs/module-registry 0.6.0-alpha.11 → 0.6.0-alpha.15
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
|
@@ -161,7 +161,7 @@ var LwrModuleRegistry = class {
|
|
|
161
161
|
id,
|
|
162
162
|
code: linkedES6,
|
|
163
163
|
linkedModuleRecord
|
|
164
|
-
} = 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, {
|
|
165
165
|
amdLoaderModule: loaderModuleEntry
|
|
166
166
|
}, this.interchangeableModules);
|
|
167
167
|
const {code: amdSource} = await this.context.compiler.convertToAmd(linkedES6, {
|
|
@@ -185,10 +185,10 @@ var LwrModuleRegistry = class {
|
|
|
185
185
|
} else {
|
|
186
186
|
let loaderModuleEntry;
|
|
187
187
|
const dynamicImports = moduleDef.moduleRecord.dynamicImports;
|
|
188
|
-
if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports
|
|
188
|
+
if (moduleDef.moduleEntry.specifier !== esmLoader && dynamicImports) {
|
|
189
189
|
loaderModuleEntry = await this.getModuleEntry({specifier: esmLoader}, runtimeParams);
|
|
190
190
|
}
|
|
191
|
-
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 && {
|
|
192
192
|
esmLoaderModule: loaderModuleEntry
|
|
193
193
|
}, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
|
|
194
194
|
let transformedEsmCode = esmLinkedSource;
|
|
@@ -29,12 +29,13 @@ __export(exports, {
|
|
|
29
29
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
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
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 = [];
|
|
@@ -84,14 +85,14 @@ async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironment, run
|
|
|
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) {
|
package/build/es/index.js
CHANGED
|
@@ -147,7 +147,7 @@ export class LwrModuleRegistry {
|
|
|
147
147
|
// Resolve the loader entry
|
|
148
148
|
const loaderModuleEntry = await this.getModuleEntry({ specifier: amdLoader }, runtimeParams);
|
|
149
149
|
// transforms compiledModule into linkedModule (which means the imports may have changed)
|
|
150
|
-
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, {
|
|
151
151
|
amdLoaderModule: loaderModuleEntry,
|
|
152
152
|
}, this.interchangeableModules);
|
|
153
153
|
// convert the linkedSource to the transport AMD format.
|
|
@@ -175,14 +175,12 @@ export class LwrModuleRegistry {
|
|
|
175
175
|
// resolve the loader entry if there are VARIABLE dynamic imports
|
|
176
176
|
let loaderModuleEntry;
|
|
177
177
|
const dynamicImports = moduleDef.moduleRecord.dynamicImports;
|
|
178
|
-
if (moduleDef.moduleEntry.specifier !== esmLoader &&
|
|
179
|
-
|
|
180
|
-
dynamicImports.some((d) => d.moduleNameType === ModuleNameType.unresolved)) {
|
|
181
|
-
// 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
|
|
182
180
|
// AND this is not the ESM loader itself (it uses a variable dynamic import we DO NOT want to link)
|
|
183
181
|
loaderModuleEntry = await this.getModuleEntry({ specifier: esmLoader }, runtimeParams);
|
|
184
182
|
}
|
|
185
|
-
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 && {
|
|
186
184
|
esmLoaderModule: loaderModuleEntry,
|
|
187
185
|
}, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
|
|
188
186
|
let transformedEsmCode = esmLinkedSource;
|
|
@@ -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
|
|
@@ -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
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;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.0-alpha.
|
|
7
|
+
"version": "0.6.0-alpha.15",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "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.15",
|
|
34
|
+
"@lwrjs/shared-utils": "0.6.0-alpha.15",
|
|
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.15",
|
|
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": "ebff01c190ee6f2777028f103e51446a1a8f00f7"
|
|
47
47
|
}
|