@lwrjs/module-registry 0.10.0-alpha.14 → 0.10.0-alpha.16
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.
|
@@ -31,7 +31,7 @@ var import_shared_utils2 = __toModule(require("@lwrjs/shared-utils"));
|
|
|
31
31
|
var import_signature = __toModule(require("../signature.cjs"));
|
|
32
32
|
async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
|
|
33
33
|
const {specifier, version, compiledSource, moduleRecord} = moduleDef;
|
|
34
|
-
const {imports, dynamicImports} = moduleRecord;
|
|
34
|
+
const {imports, dynamicImports, importMeta} = moduleRecord;
|
|
35
35
|
const codeStringBuilder = (0, import_shared_utils.createStringBuilder)(compiledSource);
|
|
36
36
|
const amdLoaderModule = config?.amdLoaderModule;
|
|
37
37
|
const esmLoaderModule = config?.esmLoaderModule;
|
|
@@ -115,6 +115,7 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
115
115
|
return {...importRef, sourceSpecifier, specifier: link2, locations: linkedLocations};
|
|
116
116
|
}));
|
|
117
117
|
}
|
|
118
|
+
let loaderImportOffset = 0;
|
|
118
119
|
if (dynamicImports && dynamicImports.length > 0 && (amdLoaderModule || esmLoaderModule)) {
|
|
119
120
|
const {version: version2, specifier: specifier2} = amdLoaderModule || esmLoaderModule;
|
|
120
121
|
const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(specifier2);
|
|
@@ -123,8 +124,10 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
123
124
|
signature = await (0, import_signature.getBundleSignature)({version: version2, specifier: specifier2}, moduleRegistry, exclude);
|
|
124
125
|
}
|
|
125
126
|
const loaderLink = strategy({specifier: specifier2, version: version2}, runtimeEnvironment, runtimeParams, signature);
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
const loaderImport = `import { load } from "${loaderLink}";
|
|
128
|
+
`;
|
|
129
|
+
loaderImportOffset = loaderImport.length;
|
|
130
|
+
codeStringBuilder.prepend(loaderImport);
|
|
128
131
|
linkedImports.unshift({
|
|
129
132
|
name,
|
|
130
133
|
namespace,
|
|
@@ -139,6 +142,32 @@ async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, run
|
|
|
139
142
|
]
|
|
140
143
|
});
|
|
141
144
|
}
|
|
145
|
+
if (importMeta && importMeta.length > 0) {
|
|
146
|
+
importMeta.forEach(({statement, location}) => {
|
|
147
|
+
if (statement === "import.meta.env.SSR") {
|
|
148
|
+
codeStringBuilder.overwrite(location.startColumn, location.endColumn, "isServer");
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const envSpecifier = "lwr/environment";
|
|
152
|
+
const {namespace, name} = (0, import_shared_utils2.explodeSpecifier)(envSpecifier);
|
|
153
|
+
const envLink = strategy({specifier: envSpecifier, version: runtimeEnvironment.lwrVersion}, runtimeEnvironment, runtimeParams);
|
|
154
|
+
const envImport = `import { isServer } from "${envLink}";
|
|
155
|
+
`;
|
|
156
|
+
codeStringBuilder.prepend(envImport);
|
|
157
|
+
linkedImports.unshift({
|
|
158
|
+
name,
|
|
159
|
+
namespace,
|
|
160
|
+
sourceSpecifier: specifier,
|
|
161
|
+
specifier: envLink,
|
|
162
|
+
version,
|
|
163
|
+
locations: [
|
|
164
|
+
{
|
|
165
|
+
startColumn: 26 + loaderImportOffset,
|
|
166
|
+
endColumn: 26 + envLink.length + loaderImportOffset
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
142
171
|
return {
|
|
143
172
|
id,
|
|
144
173
|
code: codeStringBuilder.toString(),
|
|
@@ -74,7 +74,11 @@ async function getModuleRecord(compiledModule, registry) {
|
|
|
74
74
|
const dynamicImports = [];
|
|
75
75
|
const {compiledMetadata: defaultCompilerMetadata, moduleEntry, version} = compiledModule;
|
|
76
76
|
const compiledMetadata = defaultCompilerMetadata || {};
|
|
77
|
-
const {
|
|
77
|
+
const {
|
|
78
|
+
imports: compiledModuleImports,
|
|
79
|
+
dynamicImports: compiledModuleDynamicImports,
|
|
80
|
+
importMeta
|
|
81
|
+
} = await (0, import_shared_utils.getImportMetadata)(compiledModule.compiledSource);
|
|
78
82
|
Object.assign(compiledMetadata, {
|
|
79
83
|
imports: compiledModuleImports,
|
|
80
84
|
dynamicImports: compiledModuleDynamicImports
|
|
@@ -158,6 +162,7 @@ async function getModuleRecord(compiledModule, registry) {
|
|
|
158
162
|
}
|
|
159
163
|
return {
|
|
160
164
|
imports,
|
|
161
|
-
dynamicImports
|
|
165
|
+
dynamicImports,
|
|
166
|
+
importMeta
|
|
162
167
|
};
|
|
163
168
|
}
|
|
@@ -9,7 +9,7 @@ import { getBundleSignature } from '../signature.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrategy, runtimeEnvironment, runtimeParams, config, interchangeableModules, exclude) {
|
|
11
11
|
const { specifier, version, compiledSource, moduleRecord } = moduleDef;
|
|
12
|
-
const { imports, dynamicImports } = moduleRecord;
|
|
12
|
+
const { imports, dynamicImports, importMeta } = moduleRecord;
|
|
13
13
|
const codeStringBuilder = createStringBuilder(compiledSource);
|
|
14
14
|
const amdLoaderModule = config?.amdLoaderModule;
|
|
15
15
|
const esmLoaderModule = config?.esmLoaderModule;
|
|
@@ -112,6 +112,7 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
112
112
|
}));
|
|
113
113
|
}
|
|
114
114
|
// (optionally) add loader module import link if necessary
|
|
115
|
+
let loaderImportOffset = 0;
|
|
115
116
|
if (dynamicImports && dynamicImports.length > 0 && (amdLoaderModule || esmLoaderModule)) {
|
|
116
117
|
// mutate ModuleEntry to ImportModuleRecord
|
|
117
118
|
const { version, specifier } = amdLoaderModule || esmLoaderModule;
|
|
@@ -123,7 +124,9 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
123
124
|
}
|
|
124
125
|
const loaderLink = strategy({ specifier, version }, runtimeEnvironment, runtimeParams, signature);
|
|
125
126
|
// import {load} from 'loader/loader'
|
|
126
|
-
|
|
127
|
+
const loaderImport = `import { load } from "${loaderLink}";\n`;
|
|
128
|
+
loaderImportOffset = loaderImport.length;
|
|
129
|
+
codeStringBuilder.prepend(loaderImport);
|
|
127
130
|
linkedImports.unshift({
|
|
128
131
|
name,
|
|
129
132
|
namespace,
|
|
@@ -138,6 +141,34 @@ export async function link(moduleRegistry, moduleDef, versionStrategy, uriStrate
|
|
|
138
141
|
],
|
|
139
142
|
});
|
|
140
143
|
}
|
|
144
|
+
// replace "import.meta.env.SSR" statements with the "isServer" boolean from "lwr/environment"
|
|
145
|
+
if (importMeta && importMeta.length > 0) {
|
|
146
|
+
// Replace each "import.meta.env.SSR" statement with "isServer"
|
|
147
|
+
importMeta.forEach(({ statement, location }) => {
|
|
148
|
+
if (statement === 'import.meta.env.SSR') {
|
|
149
|
+
codeStringBuilder.overwrite(location.startColumn, location.endColumn, 'isServer');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
// Add import { isServer } from 'lwr/environment'
|
|
153
|
+
const envSpecifier = 'lwr/environment';
|
|
154
|
+
const { namespace, name } = explodeSpecifier(envSpecifier);
|
|
155
|
+
const envLink = strategy({ specifier: envSpecifier, version: runtimeEnvironment.lwrVersion }, runtimeEnvironment, runtimeParams);
|
|
156
|
+
const envImport = `import { isServer } from "${envLink}";\n`;
|
|
157
|
+
codeStringBuilder.prepend(envImport);
|
|
158
|
+
linkedImports.unshift({
|
|
159
|
+
name,
|
|
160
|
+
namespace,
|
|
161
|
+
sourceSpecifier: specifier,
|
|
162
|
+
specifier: envLink,
|
|
163
|
+
version,
|
|
164
|
+
locations: [
|
|
165
|
+
{
|
|
166
|
+
startColumn: 26 + loaderImportOffset,
|
|
167
|
+
endColumn: 26 + envLink.length + loaderImportOffset,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
}
|
|
141
172
|
return {
|
|
142
173
|
id,
|
|
143
174
|
code: codeStringBuilder.toString(),
|
|
@@ -57,7 +57,7 @@ export async function getModuleRecord(compiledModule, registry) {
|
|
|
57
57
|
const { compiledMetadata: defaultCompilerMetadata, moduleEntry, version } = compiledModule;
|
|
58
58
|
const compiledMetadata = defaultCompilerMetadata || {};
|
|
59
59
|
// Get imports metadata and merge with rest of compiledModule metadata
|
|
60
|
-
const { imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports } = await getImportMetadata(compiledModule.compiledSource);
|
|
60
|
+
const { imports: compiledModuleImports, dynamicImports: compiledModuleDynamicImports, importMeta, } = await getImportMetadata(compiledModule.compiledSource);
|
|
61
61
|
Object.assign(compiledMetadata, {
|
|
62
62
|
imports: compiledModuleImports,
|
|
63
63
|
dynamicImports: compiledModuleDynamicImports,
|
|
@@ -153,6 +153,7 @@ export async function getModuleRecord(compiledModule, registry) {
|
|
|
153
153
|
return {
|
|
154
154
|
imports,
|
|
155
155
|
dynamicImports,
|
|
156
|
+
importMeta,
|
|
156
157
|
};
|
|
157
158
|
}
|
|
158
159
|
//# sourceMappingURL=module-record.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.0-alpha.
|
|
7
|
+
"version": "0.10.0-alpha.16",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@locker/compiler": "0.19.5",
|
|
34
|
-
"@lwrjs/diagnostics": "0.10.0-alpha.
|
|
35
|
-
"@lwrjs/shared-utils": "0.10.0-alpha.
|
|
34
|
+
"@lwrjs/diagnostics": "0.10.0-alpha.16",
|
|
35
|
+
"@lwrjs/shared-utils": "0.10.0-alpha.16",
|
|
36
36
|
"rollup": "^2.78.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.10.0-alpha.
|
|
39
|
+
"@lwrjs/types": "0.10.0-alpha.16"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=16.0.0 <20"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "c5a13d471330c0f738d0c783fd1b69f456c544bd"
|
|
45
45
|
}
|