@lwrjs/lwc-ssr 0.24.2 → 0.24.4
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/__mocks__/renderer.cjs +17 -5
- package/build/cjs/__mocks__/undici.cjs +23 -10
- package/build/cjs/dataViewTransformer/index.cjs +53 -47
- package/build/cjs/directFetch.cjs +27 -28
- package/build/cjs/fetchController.cjs +119 -97
- package/build/cjs/moduleLoader.cjs +82 -49
- package/build/cjs/renderer.cjs +290 -189
- package/build/cjs/resourceProvider.cjs +61 -51
- package/build/cjs/serverBootstrapServices.cjs +34 -31
- package/build/cjs/utils.cjs +51 -44
- package/build/cjs/viewProvider/index.cjs +82 -56
- package/build/cjs/viewTransformer/index.cjs +81 -64
- package/package.json +8 -8
|
@@ -1,47 +1,62 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
10
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
16
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
17
|
+
return to;
|
|
22
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
28
|
|
|
24
29
|
// packages/@lwrjs/lwc-ssr/src/moduleLoader.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
30
|
+
var moduleLoader_exports = {};
|
|
31
|
+
__export(moduleLoader_exports, {
|
|
27
32
|
FETCH_ABORT_KEY: () => FETCH_ABORT_KEY,
|
|
28
33
|
createModuleLoader: () => createModuleLoader
|
|
29
34
|
});
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
35
|
+
module.exports = __toCommonJS(moduleLoader_exports);
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_crypto = __toESM(require("crypto"));
|
|
38
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
39
|
+
var import_utils = require("./utils.cjs");
|
|
40
|
+
var import_fetchController = require("./fetchController.cjs");
|
|
41
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
36
42
|
var FETCH_ABORT_KEY = "__fetchAbortId__";
|
|
37
43
|
var BOOTSTRAP_SPECIFIER = "@lwrjs/ssr-bootstrap";
|
|
38
|
-
function createModuleLoader(
|
|
39
|
-
const createLoader =
|
|
40
|
-
return createLoader(
|
|
44
|
+
function createModuleLoader(config2, resourceRegistry2, bundleRegistry2, runtimeEnvironment2, runtimeParams2, serverData2, bootstrapConfig2, abortController2) {
|
|
45
|
+
const createLoader = runtimeEnvironment2.format === "amd" ? createAMDModuleLoader : createESMModuleLoader;
|
|
46
|
+
return createLoader(
|
|
47
|
+
config2,
|
|
48
|
+
resourceRegistry2,
|
|
49
|
+
bundleRegistry2,
|
|
50
|
+
runtimeEnvironment2,
|
|
51
|
+
runtimeParams2,
|
|
52
|
+
serverData2,
|
|
53
|
+
bootstrapConfig2,
|
|
54
|
+
abortController2
|
|
55
|
+
);
|
|
41
56
|
}
|
|
42
57
|
async function createAMDModuleLoader(config, resourceRegistry, bundleRegistry, runtimeEnvironment, runtimeParams, serverData, bootstrapConfig, abortController) {
|
|
43
58
|
const loaderConfig = (0, import_utils.getLoaderConfig)(BOOTSTRAP_SPECIFIER, config, runtimeParams, serverData);
|
|
44
|
-
const {context, controller} = createContext(loaderConfig, runtimeParams, abortController);
|
|
59
|
+
const { context, controller } = createContext(loaderConfig, runtimeParams, abortController);
|
|
45
60
|
const contextKeyMap = new Map(Object.keys(context).map((key) => [key, true]));
|
|
46
61
|
let run;
|
|
47
62
|
context.LWR.customInit = async (lwr) => {
|
|
@@ -64,13 +79,17 @@ async function createAMDModuleLoader(config, resourceRegistry, bundleRegistry, r
|
|
|
64
79
|
throw new Error("Failed to init loader shim: custom init not called");
|
|
65
80
|
}
|
|
66
81
|
const p = new Promise((resolve) => {
|
|
67
|
-
context.LWR.define(
|
|
82
|
+
context.LWR.define(
|
|
83
|
+
BOOTSTRAP_SPECIFIER,
|
|
84
|
+
[(0, import_utils.getLoaderId)(context.LWR, bootstrapConfig)],
|
|
85
|
+
(l) => resolve(l)
|
|
86
|
+
);
|
|
68
87
|
});
|
|
69
88
|
run();
|
|
70
|
-
const {load, define, services, clearRegistry} = await p;
|
|
71
|
-
const visited = new Map();
|
|
72
|
-
const evaluatedBundleFilePaths = new Set();
|
|
73
|
-
const bundleDefs = new Set();
|
|
89
|
+
const { load, define, services, clearRegistry } = await p;
|
|
90
|
+
const visited = /* @__PURE__ */ new Map();
|
|
91
|
+
const evaluatedBundleFilePaths = /* @__PURE__ */ new Set();
|
|
92
|
+
const bundleDefs = /* @__PURE__ */ new Set();
|
|
74
93
|
let loaderHooks = [];
|
|
75
94
|
return {
|
|
76
95
|
services: {
|
|
@@ -103,9 +122,13 @@ async function createAMDModuleLoader(config, resourceRegistry, bundleRegistry, r
|
|
|
103
122
|
const def2 = await bundleRegistry.getModuleBundle(moduleId, runtimeEnvironment, {
|
|
104
123
|
...runtimeParams,
|
|
105
124
|
ssr: true
|
|
125
|
+
// get a server bundle for SSR
|
|
106
126
|
});
|
|
107
127
|
if (!def2) {
|
|
108
|
-
throw new import_diagnostics.LwrUnresolvableError(
|
|
128
|
+
throw new import_diagnostics.LwrUnresolvableError(
|
|
129
|
+
import_diagnostics.descriptions.UNRESOLVABLE.BUNDLE(bundleRootSpecifier),
|
|
130
|
+
"bundle"
|
|
131
|
+
);
|
|
109
132
|
}
|
|
110
133
|
let code = await def2.getCode();
|
|
111
134
|
if (typeof def2.src === "string" && !code.includes("//# sourceURL=")) {
|
|
@@ -116,9 +139,11 @@ async function createAMDModuleLoader(config, resourceRegistry, bundleRegistry, r
|
|
|
116
139
|
const staticImports = def2.bundleRecord.imports?.map((dep) => (0, import_shared_utils.getSpecifier)(dep)) ?? [];
|
|
117
140
|
const dynamicImports = def2.bundleRecord.dynamicImports?.map((dep) => (0, import_shared_utils.getSpecifier)(dep)) ?? [];
|
|
118
141
|
if (staticImports.length || dynamicImports.length) {
|
|
119
|
-
const resolvedDeps = await Promise.all(
|
|
120
|
-
|
|
121
|
-
|
|
142
|
+
const resolvedDeps = await Promise.all(
|
|
143
|
+
[...staticImports, ...dynamicImports].map((dep) => {
|
|
144
|
+
return resolveModuleSpecifier(loaderHooks, dep);
|
|
145
|
+
})
|
|
146
|
+
);
|
|
122
147
|
const missingDeps = resolvedDeps.filter((dep) => !visited.has(dep));
|
|
123
148
|
for (const dep of missingDeps) {
|
|
124
149
|
await injectBundle(dep);
|
|
@@ -146,7 +171,9 @@ async function createAMDModuleLoader(config, resourceRegistry, bundleRegistry, r
|
|
|
146
171
|
}
|
|
147
172
|
}
|
|
148
173
|
}
|
|
149
|
-
if ((def2.specifier.startsWith("@app") || def2.specifier.startsWith("@salesforce")) &&
|
|
174
|
+
if ((def2.specifier.startsWith("@app") || def2.specifier.startsWith("@salesforce")) && // the module id is versioned(ie. the visited index), but the define in the source is un-versioned.
|
|
175
|
+
// this alias will apply the inverse: un-versioned module id with a versioned define
|
|
176
|
+
!visited.has(def2.specifier)) {
|
|
150
177
|
define(definedId, [def2.specifier], (mod2) => mod2);
|
|
151
178
|
visited.set(def2.specifier, def2);
|
|
152
179
|
}
|
|
@@ -182,18 +209,19 @@ async function createAMDModuleLoader(config, resourceRegistry, bundleRegistry, r
|
|
|
182
209
|
serverData: void 0
|
|
183
210
|
};
|
|
184
211
|
},
|
|
212
|
+
// Note: only used for testing
|
|
185
213
|
getContext: () => {
|
|
186
214
|
return context;
|
|
187
215
|
}
|
|
188
216
|
};
|
|
189
217
|
}
|
|
190
|
-
async function resolveModuleSpecifier(
|
|
191
|
-
if (
|
|
192
|
-
for (const element of
|
|
218
|
+
async function resolveModuleSpecifier(loaderHooks2, bundleSpecifier) {
|
|
219
|
+
if (loaderHooks2) {
|
|
220
|
+
for (const element of loaderHooks2) {
|
|
193
221
|
const loaderHook = element;
|
|
194
222
|
const resolveHook = loaderHook.resolveModule;
|
|
195
223
|
if (resolveHook) {
|
|
196
|
-
const response = resolveHook(bundleSpecifier, {parentUrl: "not supported"});
|
|
224
|
+
const response = resolveHook(bundleSpecifier, { parentUrl: "not supported" });
|
|
197
225
|
let result;
|
|
198
226
|
if (response || response === null) {
|
|
199
227
|
result = isPromise(response) ? await response : response;
|
|
@@ -218,20 +246,25 @@ function isValidResolveResponse(res) {
|
|
|
218
246
|
async function createESMModuleLoader() {
|
|
219
247
|
throw new Error("ESM support coming soon.");
|
|
220
248
|
}
|
|
221
|
-
function createContext(LWR,
|
|
222
|
-
const fetchController = new import_fetchController.FetchController(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
249
|
+
function createContext(LWR, runtimeParams2, abortController2) {
|
|
250
|
+
const fetchController = new import_fetchController.FetchController(
|
|
251
|
+
{
|
|
252
|
+
host: runtimeParams2.host,
|
|
253
|
+
abortController: abortController2
|
|
254
|
+
},
|
|
255
|
+
runtimeParams2.coreProxy
|
|
256
|
+
);
|
|
257
|
+
const context2 = {
|
|
227
258
|
LWR,
|
|
228
|
-
lwcRuntimeFlags: {ENABLE_WIRE_SYNC_EMIT: true},
|
|
259
|
+
lwcRuntimeFlags: { ENABLE_WIRE_SYNC_EMIT: true },
|
|
260
|
+
// browser api polyfills
|
|
229
261
|
crypto: import_crypto.default,
|
|
230
262
|
CustomEvent: Event,
|
|
263
|
+
// global fetch api override
|
|
231
264
|
fetch: fetchController.controlledFetch
|
|
232
265
|
};
|
|
233
266
|
return {
|
|
234
|
-
context,
|
|
267
|
+
context: context2,
|
|
235
268
|
controller: {
|
|
236
269
|
enableNoOpFetch: () => {
|
|
237
270
|
fetchController.activateNoOp();
|
|
@@ -245,8 +278,8 @@ function createContext(LWR, runtimeParams, abortController) {
|
|
|
245
278
|
disableFetchKillSwitch: () => {
|
|
246
279
|
fetchController.deactivateKillSwitch();
|
|
247
280
|
},
|
|
248
|
-
setFetchRequestContext: (
|
|
249
|
-
fetchController.setFetchRequestContext(
|
|
281
|
+
setFetchRequestContext: (context3) => {
|
|
282
|
+
fetchController.setFetchRequestContext(context3);
|
|
250
283
|
}
|
|
251
284
|
}
|
|
252
285
|
};
|