@lwrjs/module-registry 0.6.0-alpha.14 → 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, {
|
|
@@ -188,7 +188,7 @@ var LwrModuleRegistry = class {
|
|
|
188
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,17 +85,17 @@ 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
|
-
if (isStringLiteral
|
|
92
|
+
if (isStringLiteral) {
|
|
92
93
|
codeStringBuilder.overwrite(startColumn + 1, endColumn - 1, link2);
|
|
93
94
|
}
|
|
94
95
|
if (amdLoaderModule || esmLoaderModule) {
|
|
95
96
|
codeStringBuilder.overwrite(importStart, importEnd, "load(");
|
|
96
97
|
loaderSizeOffset = 2;
|
|
97
|
-
if (!
|
|
98
|
+
if (!isStringLiteral) {
|
|
98
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;
|
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.
|
|
@@ -180,7 +180,7 @@ export class LwrModuleRegistry {
|
|
|
180
180
|
// AND this is not the ESM loader itself (it uses a variable dynamic import we DO NOT want to link)
|
|
181
181
|
loaderModuleEntry = await this.getModuleEntry({ specifier: esmLoader }, runtimeParams);
|
|
182
182
|
}
|
|
183
|
-
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 && {
|
|
184
184
|
esmLoaderModule: loaderModuleEntry,
|
|
185
185
|
}, this.interchangeableModules, this.globalConfig.bundleConfig?.exclude);
|
|
186
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,17 +71,18 @@ 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
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
76
|
+
const link = isStringLiteral
|
|
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 }) => {
|
|
79
82
|
const { startColumn, endColumn } = location;
|
|
80
83
|
const { startColumn: importStart, endColumn: importEnd } = importLocation;
|
|
81
|
-
// rewrite the importee link if it is a static string
|
|
82
|
-
|
|
83
|
-
if (isStringLiteral && amdLoaderModule) {
|
|
84
|
+
// rewrite the importee link if it is a static string
|
|
85
|
+
if (isStringLiteral) {
|
|
84
86
|
codeStringBuilder.overwrite(startColumn + 1, endColumn - 1, link);
|
|
85
87
|
}
|
|
86
88
|
if (amdLoaderModule || esmLoaderModule) {
|
|
@@ -88,10 +90,8 @@ export async function link(moduleRegistry, moduleDef, strategy, runtimeEnvironme
|
|
|
88
90
|
// e.g. - await import('dynamic/module'); -> await load('dynamic/module');
|
|
89
91
|
codeStringBuilder.overwrite(importStart, importEnd, 'load(');
|
|
90
92
|
loaderSizeOffset = 2;
|
|
91
|
-
if (!
|
|
92
|
-
// add the importer specifier as the 2nd arg to load() for
|
|
93
|
-
// - VARIABLE dynamic imports in AMD
|
|
94
|
-
// - ALL dynamic imports in ESM
|
|
93
|
+
if (!isStringLiteral) {
|
|
94
|
+
// add the importer specifier as the 2nd arg to load() for VARIABLE dynamic imports
|
|
95
95
|
const importerSpecifier = getSpecifier({ specifier, version });
|
|
96
96
|
codeStringBuilder.overwrite(endColumn, endColumn + 1, `, '${importerSpecifier}')`);
|
|
97
97
|
loaderSizeOffset = -1 * importerSpecifier.length - 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
|
}
|