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