@lwrjs/core 0.7.0-alpha.1 → 0.7.0-alpha.12
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/env-config.cjs +5 -0
- package/build/cjs/middlewares/api-middleware.cjs +9 -9
- package/build/cjs/middlewares/utils.cjs +0 -20
- package/build/cjs/tools/server-warmup.cjs +11 -2
- package/build/cjs/tools/static-generation.cjs +46 -12
- package/build/es/env-config.js +5 -0
- package/build/es/middlewares/api-middleware.js +2 -2
- package/build/es/middlewares/utils.d.ts +0 -10
- package/build/es/middlewares/utils.js +0 -29
- package/build/es/tools/server-warmup.js +11 -2
- package/build/es/tools/static-generation.d.ts +2 -2
- package/build/es/tools/static-generation.js +59 -14
- package/build/es/tools/types.d.ts +1 -0
- package/package.json +28 -29
- package/runtime-configs/compat.json +4 -1
- package/runtime-configs/dev.json +4 -1
- package/runtime-configs/prod-compat.json +4 -1
- package/runtime-configs/prod.json +4 -1
package/build/cjs/env-config.cjs
CHANGED
|
@@ -295,6 +295,11 @@ function normalizeConfig(config) {
|
|
|
295
295
|
lwc: normalizeLwcConfig(mergeLWCConfigs(lwrJsonConfig, config)),
|
|
296
296
|
bundleConfig: mergeBundleConfig(lwrJsonConfig, config),
|
|
297
297
|
locker: mergeLockerConfig(lwrJsonConfig, config),
|
|
298
|
+
staticSiteGenerator: {
|
|
299
|
+
...DEFAULT_GENERATOR_CONFIG,
|
|
300
|
+
...lwrJsonConfig?.staticSiteGenerator,
|
|
301
|
+
...config?.staticSiteGenerator
|
|
302
|
+
},
|
|
298
303
|
rootDir
|
|
299
304
|
};
|
|
300
305
|
const assets = normalizeAssetsDir(mergedLwrGlobalConfig.assets, rootDir);
|
|
@@ -102,7 +102,7 @@ function apiMiddleware(app, context) {
|
|
|
102
102
|
res.type("application/javascript").send(bundleDef.code);
|
|
103
103
|
} catch (e) {
|
|
104
104
|
console.log(e);
|
|
105
|
-
const error = (0,
|
|
105
|
+
const error = (0, import_diagnostics.createReturnStatus)(`bundle for "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
106
106
|
res.status(error.status).send(error.message);
|
|
107
107
|
}
|
|
108
108
|
});
|
|
@@ -138,7 +138,7 @@ function apiMiddleware(app, context) {
|
|
|
138
138
|
}
|
|
139
139
|
} catch (e) {
|
|
140
140
|
console.log(e);
|
|
141
|
-
const error = (0,
|
|
141
|
+
const error = (0, import_diagnostics.createReturnStatus)(`bundle for "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
142
142
|
res.status(error.status).send(error.message);
|
|
143
143
|
}
|
|
144
144
|
});
|
|
@@ -169,7 +169,7 @@ function apiMiddleware(app, context) {
|
|
|
169
169
|
res.type("application/json").send(bundleDef.map);
|
|
170
170
|
} catch (e) {
|
|
171
171
|
console.log(e);
|
|
172
|
-
const error = (0,
|
|
172
|
+
const error = (0, import_diagnostics.createReturnStatus)(`bundle sourcemap for "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
173
173
|
res.status(error.status).send(error.message);
|
|
174
174
|
}
|
|
175
175
|
});
|
|
@@ -211,7 +211,7 @@ function apiMiddleware(app, context) {
|
|
|
211
211
|
}
|
|
212
212
|
} catch (e) {
|
|
213
213
|
console.log(e);
|
|
214
|
-
const error = (0,
|
|
214
|
+
const error = (0, import_diagnostics.createReturnStatus)(`module "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
215
215
|
res.status(error.status).send(error.message);
|
|
216
216
|
}
|
|
217
217
|
});
|
|
@@ -247,7 +247,7 @@ function apiMiddleware(app, context) {
|
|
|
247
247
|
}
|
|
248
248
|
} catch (e) {
|
|
249
249
|
console.log(e);
|
|
250
|
-
const error = (0,
|
|
250
|
+
const error = (0, import_diagnostics.createReturnStatus)(`module "${moduleId?.specifier || req.params?.specifier}"`, e);
|
|
251
251
|
res.status(error.status).send(error.message);
|
|
252
252
|
}
|
|
253
253
|
});
|
|
@@ -276,7 +276,7 @@ function apiMiddleware(app, context) {
|
|
|
276
276
|
res.status(200).type("application/json").send(importMetadata);
|
|
277
277
|
} catch (e) {
|
|
278
278
|
console.log(e);
|
|
279
|
-
const error = (0,
|
|
279
|
+
const error = (0, import_diagnostics.createReturnStatus)(`mappings for "${JSON.stringify(moduleIds || req.params?.specifiers)}"`, e);
|
|
280
280
|
res.status(error.status).send(error.message);
|
|
281
281
|
}
|
|
282
282
|
});
|
|
@@ -307,7 +307,7 @@ function apiMiddleware(app, context) {
|
|
|
307
307
|
res.setMetadata({resource});
|
|
308
308
|
} catch (e) {
|
|
309
309
|
console.log(e);
|
|
310
|
-
const error = (0,
|
|
310
|
+
const error = (0, import_diagnostics.createReturnStatus)(`resource "${resourceId?.specifier || req.params?.specifier}"`, e);
|
|
311
311
|
res.status(error.status).send(error.message);
|
|
312
312
|
}
|
|
313
313
|
});
|
|
@@ -330,7 +330,7 @@ function apiMiddleware(app, context) {
|
|
|
330
330
|
res.stream(assetObj.stream());
|
|
331
331
|
} catch (e) {
|
|
332
332
|
console.log(e);
|
|
333
|
-
const error = (0,
|
|
333
|
+
const error = (0, import_diagnostics.createReturnStatus)(`asset at "${specifier}"`, e);
|
|
334
334
|
res.status(error.status).send(error.message);
|
|
335
335
|
}
|
|
336
336
|
});
|
|
@@ -352,7 +352,7 @@ function apiMiddleware(app, context) {
|
|
|
352
352
|
res.stream(assetObj.stream());
|
|
353
353
|
} catch (e) {
|
|
354
354
|
console.log(e);
|
|
355
|
-
const error = (0,
|
|
355
|
+
const error = (0, import_diagnostics.createReturnStatus)(`asset at "${specifier}"`, e);
|
|
356
356
|
res.status(error.status).send(error.message);
|
|
357
357
|
}
|
|
358
358
|
});
|
|
@@ -24,31 +24,11 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/core/src/middlewares/utils.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
-
createReturnStatus: () => createReturnStatus,
|
|
28
27
|
getRequestProperties: () => getRequestProperties,
|
|
29
28
|
isSupportedEnvironment: () => isSupportedEnvironment
|
|
30
29
|
});
|
|
31
|
-
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
30
|
var import_path_to_regexp = __toModule(require("path-to-regexp"));
|
|
33
31
|
var import_qs = __toModule(require("qs"));
|
|
34
|
-
var import_dompurify = __toModule(require("dompurify"));
|
|
35
|
-
var import_jsdom = __toModule(require("jsdom"));
|
|
36
|
-
var window = new import_jsdom.JSDOM("").window;
|
|
37
|
-
var DOMPurify = (0, import_dompurify.default)(window);
|
|
38
|
-
function createReturnStatus(name, error) {
|
|
39
|
-
let returnStatus = {status: 501, message: ""};
|
|
40
|
-
if ((0, import_diagnostics.isNodeError)(error) && error.code === "NO_LWC_MODULE_FOUND") {
|
|
41
|
-
returnStatus = {status: 404, message: import_diagnostics.descriptions.UNRESOLVABLE.LWC_MODULE(name).message};
|
|
42
|
-
} else if (error instanceof import_diagnostics.LwrUnresolvableError && error.diagnostics[0].description.category === "lwrUnresolvable/invalid") {
|
|
43
|
-
returnStatus = {status: 400, message: error.message};
|
|
44
|
-
} else if (error instanceof import_diagnostics.LwrUnresolvableError) {
|
|
45
|
-
returnStatus = {status: 404, message: error.message};
|
|
46
|
-
} else {
|
|
47
|
-
returnStatus = {status: 500, message: import_diagnostics.descriptions.UNRESOLVABLE.SERVER_ERROR(name).message};
|
|
48
|
-
}
|
|
49
|
-
returnStatus.message = DOMPurify.sanitize(returnStatus.message);
|
|
50
|
-
return returnStatus;
|
|
51
|
-
}
|
|
52
32
|
function getRequestProperties(pattern, req) {
|
|
53
33
|
const {url = "/"} = req;
|
|
54
34
|
const [pathname, search] = url.split("?");
|
|
@@ -29,11 +29,20 @@ __export(exports, {
|
|
|
29
29
|
var import_static_generation = __toModule(require("./static-generation.cjs"));
|
|
30
30
|
var import_dir = __toModule(require("./utils/dir.cjs"));
|
|
31
31
|
var import_network_dispatcher = __toModule(require("./utils/network-dispatcher.cjs"));
|
|
32
|
+
var import_env_config = __toModule(require("../env-config.cjs"));
|
|
32
33
|
async function warmupServer(config, internalRequestKey) {
|
|
33
34
|
console.log("[Server Warmup] starting");
|
|
34
|
-
const {routes, staticSiteGenerator, port} = config;
|
|
35
|
+
const {routes, staticSiteGenerator, port, apiVersion, basePath, lwrVersion, serverMode} = config;
|
|
35
36
|
staticSiteGenerator.outputDir = import_dir.skipDirCreation;
|
|
36
37
|
const urlRewriteMap = new Map();
|
|
37
|
-
|
|
38
|
+
const runtimeEnvironment = {
|
|
39
|
+
...(0, import_env_config.explodeMode)(serverMode),
|
|
40
|
+
apiVersion,
|
|
41
|
+
basePath,
|
|
42
|
+
lwrVersion,
|
|
43
|
+
debug: false,
|
|
44
|
+
serverMode
|
|
45
|
+
};
|
|
46
|
+
await new import_static_generation.default().generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, new import_network_dispatcher.default(port, internalRequestKey), staticSiteGenerator.outputDir, urlRewriteMap);
|
|
38
47
|
console.log("[Server Warmup] complete");
|
|
39
48
|
}
|
|
@@ -33,6 +33,7 @@ var import_path = __toModule(require("path"));
|
|
|
33
33
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
34
34
|
var import_stream = __toModule(require("./utils/stream.cjs"));
|
|
35
35
|
var import_dir = __toModule(require("./utils/dir.cjs"));
|
|
36
|
+
var import_env_config = __toModule(require("../env-config.cjs"));
|
|
36
37
|
var SiteGenerator = class {
|
|
37
38
|
async buildStaticApplication(config, dispatcher) {
|
|
38
39
|
const startTime = import_perf_hooks.performance.now();
|
|
@@ -45,29 +46,45 @@ var SiteGenerator = class {
|
|
|
45
46
|
console.log(`[INFO] Clear Output Location: ${outputDir}`);
|
|
46
47
|
import_fs_extra.default.rmSync(outputDir, {recursive: true, force: true});
|
|
47
48
|
const urlRewriteMap = new Map();
|
|
48
|
-
|
|
49
|
+
const {apiVersion, basePath, lwrVersion, serverMode} = config;
|
|
50
|
+
const runtimeEnvironment = {
|
|
51
|
+
...(0, import_env_config.explodeMode)(serverMode),
|
|
52
|
+
apiVersion,
|
|
53
|
+
basePath,
|
|
54
|
+
lwrVersion,
|
|
55
|
+
debug: false,
|
|
56
|
+
serverMode
|
|
57
|
+
};
|
|
58
|
+
await this.generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap);
|
|
49
59
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
50
60
|
this.copyAssets(assets, outputDir);
|
|
51
61
|
const endTime = import_perf_hooks.performance.now();
|
|
52
62
|
const timeDiff = (endTime - startTime) / 1e3;
|
|
53
63
|
console.log(`[Static Generation] complete in ${Math.round(timeDiff)} seconds`);
|
|
54
64
|
}
|
|
55
|
-
async generateRoutes(staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap = new Map()) {
|
|
65
|
+
async generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap = new Map()) {
|
|
56
66
|
if (!staticSiteGenerator.locales) {
|
|
57
67
|
staticSiteGenerator.locales = ["en-US"];
|
|
58
68
|
}
|
|
59
69
|
const generateUrl = this.createGenerateURLFunction(dispatcher);
|
|
60
70
|
for (const locale of staticSiteGenerator.locales) {
|
|
61
71
|
for (const route of routes) {
|
|
62
|
-
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
72
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment);
|
|
63
73
|
await generateUrl(route.path, siteConfig);
|
|
64
74
|
}
|
|
65
75
|
if (staticSiteGenerator._additionalRoutePaths) {
|
|
66
76
|
for (const uri of staticSiteGenerator._additionalRoutePaths) {
|
|
67
|
-
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
77
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment);
|
|
68
78
|
await generateUrl(uri, siteConfig);
|
|
69
79
|
}
|
|
70
80
|
}
|
|
81
|
+
const {_additionalModules} = staticSiteGenerator;
|
|
82
|
+
if (_additionalModules) {
|
|
83
|
+
for (const specifier of _additionalModules) {
|
|
84
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment);
|
|
85
|
+
await this.dispatchJSResourceRecursive(specifier, dispatcher, siteConfig, true);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
71
88
|
}
|
|
72
89
|
}
|
|
73
90
|
createGenerateURLFunction(dispatcher) {
|
|
@@ -88,7 +105,14 @@ var SiteGenerator = class {
|
|
|
88
105
|
console.error("Skipped url with variable path segment: " + url);
|
|
89
106
|
return;
|
|
90
107
|
}
|
|
91
|
-
|
|
108
|
+
let context;
|
|
109
|
+
context = await dispatcher.dispatchUrl(url, "GET", siteConfig.locale);
|
|
110
|
+
if (context?.fs?.headers?.Location) {
|
|
111
|
+
const redirectUrl = context?.fs?.headers?.Location;
|
|
112
|
+
url = redirectUrl;
|
|
113
|
+
const redirectContext = await dispatcher.dispatchUrl(url, "GET", siteConfig.locale);
|
|
114
|
+
context = redirectContext;
|
|
115
|
+
}
|
|
92
116
|
const {resourceType} = resourceOpts;
|
|
93
117
|
if (resourceType === "route") {
|
|
94
118
|
await this.handleHtmlResource(url, context, siteConfig, dispatcher);
|
|
@@ -139,11 +163,12 @@ var SiteGenerator = class {
|
|
|
139
163
|
const statusCode = context.response?.status;
|
|
140
164
|
if (statusCode === 200) {
|
|
141
165
|
const newImportMetadata = context.fs?.body;
|
|
166
|
+
let filteredImportMetadata;
|
|
142
167
|
if (!importMetatdata) {
|
|
143
|
-
|
|
144
|
-
|
|
168
|
+
filteredImportMetadata = newImportMetadata;
|
|
169
|
+
} else {
|
|
170
|
+
filteredImportMetadata = importMetatdata.addAdditionalMetadata(newImportMetadata);
|
|
145
171
|
}
|
|
146
|
-
const filteredImportMetadata = importMetatdata.addAdditionalMetadata(newImportMetadata);
|
|
147
172
|
const dispatchRequests = [];
|
|
148
173
|
for (const uri of Object.keys(filteredImportMetadata.imports)) {
|
|
149
174
|
dispatchRequests.push(this.dispatchResourceRecursive(uri, dispatcher, {resourceType: "js"}, siteConfig));
|
|
@@ -173,7 +198,6 @@ var SiteGenerator = class {
|
|
|
173
198
|
}
|
|
174
199
|
}
|
|
175
200
|
async handleViewDefinition(viewDefinition, siteConfig, dispatcher) {
|
|
176
|
-
siteConfig.endpoints = viewDefinition.viewRecord.endpoints;
|
|
177
201
|
if (viewDefinition.viewRecord.importMetadata) {
|
|
178
202
|
siteConfig.importMetadata = new ViewImportMetadataImpl(viewDefinition.viewRecord.importMetadata);
|
|
179
203
|
}
|
|
@@ -224,7 +248,7 @@ var SiteGenerator = class {
|
|
|
224
248
|
}
|
|
225
249
|
await Promise.all(dispatchRequests);
|
|
226
250
|
}
|
|
227
|
-
async dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig) {
|
|
251
|
+
async dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig, isAdditionalModulesRequest) {
|
|
228
252
|
if (jsUri.startsWith("/")) {
|
|
229
253
|
await this.dispatchResourceRecursive(jsUri, dispatcher, {resourceType: "js"}, siteConfig);
|
|
230
254
|
} else {
|
|
@@ -237,6 +261,9 @@ var SiteGenerator = class {
|
|
|
237
261
|
} else {
|
|
238
262
|
console.warn('[WARN] Unable to fetch mapping for bare specifier or variable dynamic import: "' + jsUri + '"');
|
|
239
263
|
}
|
|
264
|
+
} else if (isAdditionalModulesRequest) {
|
|
265
|
+
const uri = `${siteConfig.endpoints?.uris.legacyDefault}${encodeURIComponent(jsUri)}`;
|
|
266
|
+
await this.dispatchResourceRecursive(uri, dispatcher, {resourceType: "js"}, siteConfig);
|
|
240
267
|
}
|
|
241
268
|
}
|
|
242
269
|
}
|
|
@@ -279,19 +306,26 @@ var SiteGenerator = class {
|
|
|
279
306
|
throw new Error("Could not find assets to copy at path: " + assetSrcDir);
|
|
280
307
|
}
|
|
281
308
|
} catch (e) {
|
|
282
|
-
console.error("Error occurred processing asset config: " + asset);
|
|
309
|
+
console.error("Error occurred processing asset config: " + JSON.stringify(asset));
|
|
283
310
|
console.error(e);
|
|
284
311
|
}
|
|
285
312
|
}
|
|
286
313
|
}
|
|
287
|
-
createSiteConfig(outputDir, locale, urlRewriteMap) {
|
|
314
|
+
createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment) {
|
|
288
315
|
const featureFlags = this.filterFeatureFlags();
|
|
316
|
+
const endpoints = {
|
|
317
|
+
uris: {
|
|
318
|
+
legacyDefault: (0, import_shared_utils.getModuleUriPrefix)(runtimeEnvironment, {locale}),
|
|
319
|
+
mapping: (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, {locale})
|
|
320
|
+
}
|
|
321
|
+
};
|
|
289
322
|
return {
|
|
290
323
|
outputDir,
|
|
291
324
|
viewPaths: new Set(),
|
|
292
325
|
visitedUrls: new Set(),
|
|
293
326
|
locale,
|
|
294
327
|
urlRewriteMap,
|
|
328
|
+
endpoints,
|
|
295
329
|
...featureFlags
|
|
296
330
|
};
|
|
297
331
|
}
|
package/build/es/env-config.js
CHANGED
|
@@ -306,6 +306,11 @@ export function normalizeConfig(config) {
|
|
|
306
306
|
lwc: normalizeLwcConfig(mergeLWCConfigs(lwrJsonConfig, config)),
|
|
307
307
|
bundleConfig: mergeBundleConfig(lwrJsonConfig, config),
|
|
308
308
|
locker: mergeLockerConfig(lwrJsonConfig, config),
|
|
309
|
+
staticSiteGenerator: {
|
|
310
|
+
...DEFAULT_GENERATOR_CONFIG,
|
|
311
|
+
...lwrJsonConfig?.staticSiteGenerator,
|
|
312
|
+
...config?.staticSiteGenerator,
|
|
313
|
+
},
|
|
309
314
|
rootDir,
|
|
310
315
|
};
|
|
311
316
|
// Normalize entries (eg: parse full file paths, etc)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LwrUnresolvableError, createSingleDiagnosticError as createDiagnostic, descriptions, } from '@lwrjs/diagnostics';
|
|
1
|
+
import { createReturnStatus, LwrUnresolvableError, createSingleDiagnosticError as createDiagnostic, descriptions, } from '@lwrjs/diagnostics';
|
|
2
2
|
import { LATEST_SIGNATURE, explodeSpecifier, getImportMetadataMappings, serializeModuleToJson, getModuleIdentity, getResourceIdentity, getAssetIdentity, getMappingIdentity, getVersionedModuleId, } from '@lwrjs/shared-utils';
|
|
3
|
-
import {
|
|
3
|
+
import { isSupportedEnvironment } from './utils.js';
|
|
4
4
|
export default function apiMiddleware(app, context) {
|
|
5
5
|
const { appConfig: { environment: environmentConfig }, moduleRegistry, moduleBundler, resourceRegistry, runtimeEnvironment: defaultRuntimeEnvironment, } = context;
|
|
6
6
|
const errors = descriptions.UNRESOLVABLE;
|
|
@@ -2,16 +2,6 @@
|
|
|
2
2
|
import http from 'http';
|
|
3
3
|
import { EnvironmentConfig } from '@lwrjs/types';
|
|
4
4
|
import qs from 'qs';
|
|
5
|
-
/**
|
|
6
|
-
* Create a status object Express can return when there is an error
|
|
7
|
-
*
|
|
8
|
-
* @param name - string name of the problem module/resource
|
|
9
|
-
* @param error - an Error/Diagnostic object; thrown from try/catch
|
|
10
|
-
*/
|
|
11
|
-
export declare function createReturnStatus(name: string, error: unknown): {
|
|
12
|
-
status: number;
|
|
13
|
-
message: string;
|
|
14
|
-
};
|
|
15
5
|
interface Params {
|
|
16
6
|
[key: string]: string;
|
|
17
7
|
}
|
|
@@ -1,34 +1,5 @@
|
|
|
1
|
-
import { LwrUnresolvableError, descriptions, isNodeError } from '@lwrjs/diagnostics';
|
|
2
1
|
import { pathToRegexp } from 'path-to-regexp';
|
|
3
2
|
import qs from 'qs';
|
|
4
|
-
import createDOMPurify from 'dompurify';
|
|
5
|
-
import { JSDOM } from 'jsdom';
|
|
6
|
-
const window = new JSDOM('').window;
|
|
7
|
-
const DOMPurify = createDOMPurify(window);
|
|
8
|
-
/**
|
|
9
|
-
* Create a status object Express can return when there is an error
|
|
10
|
-
*
|
|
11
|
-
* @param name - string name of the problem module/resource
|
|
12
|
-
* @param error - an Error/Diagnostic object; thrown from try/catch
|
|
13
|
-
*/
|
|
14
|
-
export function createReturnStatus(name, error) {
|
|
15
|
-
let returnStatus = { status: 501, message: '' };
|
|
16
|
-
if (isNodeError(error) && error.code === 'NO_LWC_MODULE_FOUND') {
|
|
17
|
-
returnStatus = { status: 404, message: descriptions.UNRESOLVABLE.LWC_MODULE(name).message };
|
|
18
|
-
}
|
|
19
|
-
else if (error instanceof LwrUnresolvableError &&
|
|
20
|
-
error.diagnostics[0].description.category === 'lwrUnresolvable/invalid') {
|
|
21
|
-
returnStatus = { status: 400, message: error.message };
|
|
22
|
-
}
|
|
23
|
-
else if (error instanceof LwrUnresolvableError) {
|
|
24
|
-
returnStatus = { status: 404, message: error.message };
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
returnStatus = { status: 500, message: descriptions.UNRESOLVABLE.SERVER_ERROR(name).message };
|
|
28
|
-
}
|
|
29
|
-
returnStatus.message = DOMPurify.sanitize(returnStatus.message);
|
|
30
|
-
return returnStatus;
|
|
31
|
-
}
|
|
32
3
|
// Adapted from https://github.com/expressjs/express/blob/master/lib/router/layer.js
|
|
33
4
|
export function getRequestProperties(pattern, req) {
|
|
34
5
|
const { url = '/' } = req;
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import SiteGenerator from './static-generation.js';
|
|
2
2
|
import { skipDirCreation } from './utils/dir.js';
|
|
3
3
|
import NetworkDispatcher from './utils/network-dispatcher.js';
|
|
4
|
+
import { explodeMode } from '../env-config.js';
|
|
4
5
|
export async function warmupServer(config, internalRequestKey) {
|
|
5
6
|
console.log('[Server Warmup] starting');
|
|
6
|
-
const { routes, staticSiteGenerator, port } = config;
|
|
7
|
+
const { routes, staticSiteGenerator, port, apiVersion, basePath, lwrVersion, serverMode } = config;
|
|
7
8
|
staticSiteGenerator.outputDir = skipDirCreation;
|
|
8
9
|
const urlRewriteMap = new Map();
|
|
10
|
+
const runtimeEnvironment = {
|
|
11
|
+
...explodeMode(serverMode),
|
|
12
|
+
apiVersion,
|
|
13
|
+
basePath,
|
|
14
|
+
lwrVersion,
|
|
15
|
+
debug: false,
|
|
16
|
+
serverMode,
|
|
17
|
+
};
|
|
9
18
|
// For each locale, generate all the modules
|
|
10
|
-
await new SiteGenerator().generateRoutes(staticSiteGenerator, routes, new NetworkDispatcher(port, internalRequestKey), staticSiteGenerator.outputDir, urlRewriteMap);
|
|
19
|
+
await new SiteGenerator().generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, new NetworkDispatcher(port, internalRequestKey), staticSiteGenerator.outputDir, urlRewriteMap);
|
|
11
20
|
console.log('[Server Warmup] complete');
|
|
12
21
|
}
|
|
13
22
|
//# sourceMappingURL=server-warmup.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ImportMetadata, LwrDispatcher, StaticSiteGenerator, LwrRoute, NormalizedLwrGlobalConfig } from '@lwrjs/types';
|
|
1
|
+
import { ImportMetadata, LwrDispatcher, StaticSiteGenerator, LwrRoute, NormalizedLwrGlobalConfig, RuntimeEnvironment } from '@lwrjs/types';
|
|
2
2
|
import { ResourceContextOpts, SiteConfig, ViewImportMetadata } from './types.js';
|
|
3
3
|
export default class SiteGenerator {
|
|
4
4
|
/**
|
|
@@ -13,7 +13,7 @@ export default class SiteGenerator {
|
|
|
13
13
|
/**
|
|
14
14
|
* Crawl all view routes for a site
|
|
15
15
|
*/
|
|
16
|
-
generateRoutes(staticSiteGenerator: StaticSiteGenerator, routes: LwrRoute[], dispatcher: LwrDispatcher, outputDir: string, urlRewriteMap?: Map<string, string>): Promise<void>;
|
|
16
|
+
generateRoutes(runtimeEnvironment: RuntimeEnvironment, staticSiteGenerator: StaticSiteGenerator, routes: LwrRoute[], dispatcher: LwrDispatcher, outputDir: string, urlRewriteMap?: Map<string, string>): Promise<void>;
|
|
17
17
|
/**
|
|
18
18
|
* Creates a function to dispatch the root requests for a given view url
|
|
19
19
|
*/
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { performance } from 'perf_hooks';
|
|
2
|
-
import { getSpecifier, getFeatureFlags, hashContent } from '@lwrjs/shared-utils';
|
|
2
|
+
import { getSpecifier, getFeatureFlags, hashContent, getModuleUriPrefix, getMappingUriPrefix, } from '@lwrjs/shared-utils';
|
|
3
3
|
import { join, dirname, extname } from 'path';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { writeResponse } from './utils/stream.js';
|
|
6
6
|
import { createDir, createResourceDir } from './utils/dir.js';
|
|
7
|
+
import { explodeMode } from '../env-config.js';
|
|
7
8
|
export default class SiteGenerator {
|
|
8
9
|
/**
|
|
9
10
|
* Build a static site in the configured directory
|
|
@@ -24,8 +25,17 @@ export default class SiteGenerator {
|
|
|
24
25
|
console.log(`[INFO] Clear Output Location: ${outputDir}`);
|
|
25
26
|
fs.rmSync(outputDir, { recursive: true, force: true });
|
|
26
27
|
const urlRewriteMap = new Map();
|
|
28
|
+
const { apiVersion, basePath, lwrVersion, serverMode } = config;
|
|
29
|
+
const runtimeEnvironment = {
|
|
30
|
+
...explodeMode(serverMode),
|
|
31
|
+
apiVersion,
|
|
32
|
+
basePath,
|
|
33
|
+
lwrVersion,
|
|
34
|
+
debug: false,
|
|
35
|
+
serverMode,
|
|
36
|
+
};
|
|
27
37
|
// For each locale, generate all the modules
|
|
28
|
-
await this.generateRoutes(staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap);
|
|
38
|
+
await this.generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap);
|
|
29
39
|
// Write redirect files
|
|
30
40
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
31
41
|
// Copy over assets
|
|
@@ -37,7 +47,7 @@ export default class SiteGenerator {
|
|
|
37
47
|
/**
|
|
38
48
|
* Crawl all view routes for a site
|
|
39
49
|
*/
|
|
40
|
-
async generateRoutes(staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap = new Map()) {
|
|
50
|
+
async generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap = new Map()) {
|
|
41
51
|
if (!staticSiteGenerator.locales) {
|
|
42
52
|
staticSiteGenerator.locales = ['en-US'];
|
|
43
53
|
}
|
|
@@ -46,18 +56,27 @@ export default class SiteGenerator {
|
|
|
46
56
|
for (const locale of staticSiteGenerator.locales) {
|
|
47
57
|
// Generate all the routes
|
|
48
58
|
for (const route of routes) {
|
|
49
|
-
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
59
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment);
|
|
50
60
|
// eslint-disable-next-line no-await-in-loop
|
|
51
61
|
await generateUrl(route.path, siteConfig);
|
|
52
62
|
}
|
|
53
63
|
// Generate any additional urls
|
|
54
64
|
if (staticSiteGenerator._additionalRoutePaths) {
|
|
55
65
|
for (const uri of staticSiteGenerator._additionalRoutePaths) {
|
|
56
|
-
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
66
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment);
|
|
57
67
|
// eslint-disable-next-line no-await-in-loop
|
|
58
68
|
await generateUrl(uri, siteConfig);
|
|
59
69
|
}
|
|
60
70
|
}
|
|
71
|
+
// Handle _additionalModules specifiers
|
|
72
|
+
const { _additionalModules } = staticSiteGenerator;
|
|
73
|
+
if (_additionalModules) {
|
|
74
|
+
for (const specifier of _additionalModules) {
|
|
75
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment);
|
|
76
|
+
// eslint-disable-next-line no-await-in-loop
|
|
77
|
+
await this.dispatchJSResourceRecursive(specifier, dispatcher, siteConfig, true);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
61
80
|
}
|
|
62
81
|
}
|
|
63
82
|
/**
|
|
@@ -94,7 +113,15 @@ export default class SiteGenerator {
|
|
|
94
113
|
return;
|
|
95
114
|
}
|
|
96
115
|
// Generate resource
|
|
97
|
-
|
|
116
|
+
let context;
|
|
117
|
+
context = await dispatcher.dispatchUrl(url, 'GET', siteConfig.locale);
|
|
118
|
+
// Handle 302 redirect if applicable
|
|
119
|
+
if (context?.fs?.headers?.Location) {
|
|
120
|
+
const redirectUrl = context?.fs?.headers?.Location;
|
|
121
|
+
url = redirectUrl;
|
|
122
|
+
const redirectContext = await dispatcher.dispatchUrl(url, 'GET', siteConfig.locale);
|
|
123
|
+
context = redirectContext;
|
|
124
|
+
}
|
|
98
125
|
const { resourceType } = resourceOpts;
|
|
99
126
|
// -- Routes (root resources) -------
|
|
100
127
|
if (resourceType === 'route') {
|
|
@@ -192,12 +219,16 @@ export default class SiteGenerator {
|
|
|
192
219
|
if (statusCode === 200) {
|
|
193
220
|
// Read JSON
|
|
194
221
|
const newImportMetadata = context.fs?.body;
|
|
222
|
+
let filteredImportMetadata;
|
|
195
223
|
if (!importMetatdata) {
|
|
196
|
-
|
|
197
|
-
|
|
224
|
+
filteredImportMetadata = newImportMetadata;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// need to handle importMetadata when generating from a view
|
|
228
|
+
filteredImportMetadata = importMetatdata.addAdditionalMetadata(newImportMetadata);
|
|
198
229
|
}
|
|
199
230
|
// Filter out and import metadata already included with the view
|
|
200
|
-
const filteredImportMetadata = importMetatdata.addAdditionalMetadata(newImportMetadata);
|
|
231
|
+
// const filteredImportMetadata = importMetatdata.addAdditionalMetadata(newImportMetadata);
|
|
201
232
|
// Build up a list of dispatch requests to kick off in parallel
|
|
202
233
|
const dispatchRequests = [];
|
|
203
234
|
// Iterate through the import mappings and return request uris
|
|
@@ -254,8 +285,6 @@ export default class SiteGenerator {
|
|
|
254
285
|
* @param dispatcher - Network dispatcher
|
|
255
286
|
*/
|
|
256
287
|
async handleViewDefinition(viewDefinition, siteConfig, dispatcher) {
|
|
257
|
-
// Save mapping endpoint for future
|
|
258
|
-
siteConfig.endpoints = viewDefinition.viewRecord.endpoints;
|
|
259
288
|
// Save existing import metadata
|
|
260
289
|
if (viewDefinition.viewRecord.importMetadata) {
|
|
261
290
|
// Initialize import metadata collector
|
|
@@ -320,7 +349,7 @@ export default class SiteGenerator {
|
|
|
320
349
|
// -- Dispatch dependencies
|
|
321
350
|
await Promise.all(dispatchRequests);
|
|
322
351
|
}
|
|
323
|
-
async dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig) {
|
|
352
|
+
async dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig, isAdditionalModulesRequest) {
|
|
324
353
|
if (jsUri.startsWith('/')) {
|
|
325
354
|
await this.dispatchResourceRecursive(jsUri, dispatcher, { resourceType: 'js' }, siteConfig);
|
|
326
355
|
}
|
|
@@ -339,6 +368,14 @@ export default class SiteGenerator {
|
|
|
339
368
|
'"');
|
|
340
369
|
}
|
|
341
370
|
}
|
|
371
|
+
// TODO: this code path was still being hit prior to _additionalModules
|
|
372
|
+
// flag for bare dynamic imports metadata. This flag keeps the behavior as
|
|
373
|
+
// before until we can figure out what to do with those requests.
|
|
374
|
+
else if (isAdditionalModulesRequest) {
|
|
375
|
+
// fallback to globalThis.LWR.imports.default
|
|
376
|
+
const uri = `${siteConfig.endpoints?.uris.legacyDefault}${encodeURIComponent(jsUri)}`;
|
|
377
|
+
await this.dispatchResourceRecursive(uri, dispatcher, { resourceType: 'js' }, siteConfig);
|
|
378
|
+
}
|
|
342
379
|
}
|
|
343
380
|
}
|
|
344
381
|
/**
|
|
@@ -408,7 +445,7 @@ export default class SiteGenerator {
|
|
|
408
445
|
}
|
|
409
446
|
}
|
|
410
447
|
catch (e) {
|
|
411
|
-
console.error('Error occurred processing asset config: ' + asset);
|
|
448
|
+
console.error('Error occurred processing asset config: ' + JSON.stringify(asset));
|
|
412
449
|
console.error(e);
|
|
413
450
|
}
|
|
414
451
|
}
|
|
@@ -416,14 +453,22 @@ export default class SiteGenerator {
|
|
|
416
453
|
/**
|
|
417
454
|
* Create a new site config for the current view
|
|
418
455
|
*/
|
|
419
|
-
createSiteConfig(outputDir, locale, urlRewriteMap) {
|
|
456
|
+
createSiteConfig(outputDir, locale, urlRewriteMap, runtimeEnvironment) {
|
|
420
457
|
const featureFlags = this.filterFeatureFlags();
|
|
458
|
+
const endpoints = {
|
|
459
|
+
uris: {
|
|
460
|
+
// legacy globalThis.LWR.importMappings.default
|
|
461
|
+
legacyDefault: getModuleUriPrefix(runtimeEnvironment, { locale }),
|
|
462
|
+
mapping: getMappingUriPrefix(runtimeEnvironment, { locale }),
|
|
463
|
+
},
|
|
464
|
+
};
|
|
421
465
|
return {
|
|
422
466
|
outputDir,
|
|
423
467
|
viewPaths: new Set(),
|
|
424
468
|
visitedUrls: new Set(),
|
|
425
469
|
locale,
|
|
426
470
|
urlRewriteMap,
|
|
471
|
+
endpoints,
|
|
427
472
|
// Only include LEGACY_LOADER if true
|
|
428
473
|
...featureFlags,
|
|
429
474
|
};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.7.0-alpha.
|
|
7
|
+
"version": "0.7.0-alpha.12",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -33,32 +33,31 @@
|
|
|
33
33
|
"package.cjs"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lwrjs/app-service": "0.7.0-alpha.
|
|
37
|
-
"@lwrjs/asset-registry": "0.7.0-alpha.
|
|
38
|
-
"@lwrjs/asset-transformer": "0.7.0-alpha.
|
|
39
|
-
"@lwrjs/base-template-engine": "0.7.0-alpha.
|
|
40
|
-
"@lwrjs/base-view-provider": "0.7.0-alpha.
|
|
41
|
-
"@lwrjs/base-view-transformer": "0.7.0-alpha.
|
|
42
|
-
"@lwrjs/client-modules": "0.7.0-alpha.
|
|
43
|
-
"@lwrjs/compiler": "0.7.0-alpha.
|
|
44
|
-
"@lwrjs/diagnostics": "0.7.0-alpha.
|
|
45
|
-
"@lwrjs/fs-asset-provider": "0.7.0-alpha.
|
|
46
|
-
"@lwrjs/html-view-provider": "0.7.0-alpha.
|
|
47
|
-
"@lwrjs/loader": "0.7.0-alpha.
|
|
48
|
-
"@lwrjs/lwc-module-provider": "0.7.0-alpha.
|
|
49
|
-
"@lwrjs/lwc-ssr": "0.7.0-alpha.
|
|
50
|
-
"@lwrjs/markdown-view-provider": "0.7.0-alpha.
|
|
51
|
-
"@lwrjs/module-bundler": "0.7.0-alpha.
|
|
52
|
-
"@lwrjs/module-registry": "0.7.0-alpha.
|
|
53
|
-
"@lwrjs/npm-module-provider": "0.7.0-alpha.
|
|
54
|
-
"@lwrjs/nunjucks-view-provider": "0.7.0-alpha.
|
|
55
|
-
"@lwrjs/o11y": "0.7.0-alpha.
|
|
56
|
-
"@lwrjs/resource-registry": "0.7.0-alpha.
|
|
57
|
-
"@lwrjs/router": "0.7.0-alpha.
|
|
58
|
-
"@lwrjs/server": "0.7.0-alpha.
|
|
59
|
-
"@lwrjs/shared-utils": "0.7.0-alpha.
|
|
60
|
-
"@lwrjs/view-registry": "0.7.0-alpha.
|
|
61
|
-
"dompurify": "^2.3.0",
|
|
36
|
+
"@lwrjs/app-service": "0.7.0-alpha.12",
|
|
37
|
+
"@lwrjs/asset-registry": "0.7.0-alpha.12",
|
|
38
|
+
"@lwrjs/asset-transformer": "0.7.0-alpha.12",
|
|
39
|
+
"@lwrjs/base-template-engine": "0.7.0-alpha.12",
|
|
40
|
+
"@lwrjs/base-view-provider": "0.7.0-alpha.12",
|
|
41
|
+
"@lwrjs/base-view-transformer": "0.7.0-alpha.12",
|
|
42
|
+
"@lwrjs/client-modules": "0.7.0-alpha.12",
|
|
43
|
+
"@lwrjs/compiler": "0.7.0-alpha.12",
|
|
44
|
+
"@lwrjs/diagnostics": "0.7.0-alpha.12",
|
|
45
|
+
"@lwrjs/fs-asset-provider": "0.7.0-alpha.12",
|
|
46
|
+
"@lwrjs/html-view-provider": "0.7.0-alpha.12",
|
|
47
|
+
"@lwrjs/loader": "0.7.0-alpha.12",
|
|
48
|
+
"@lwrjs/lwc-module-provider": "0.7.0-alpha.12",
|
|
49
|
+
"@lwrjs/lwc-ssr": "0.7.0-alpha.12",
|
|
50
|
+
"@lwrjs/markdown-view-provider": "0.7.0-alpha.12",
|
|
51
|
+
"@lwrjs/module-bundler": "0.7.0-alpha.12",
|
|
52
|
+
"@lwrjs/module-registry": "0.7.0-alpha.12",
|
|
53
|
+
"@lwrjs/npm-module-provider": "0.7.0-alpha.12",
|
|
54
|
+
"@lwrjs/nunjucks-view-provider": "0.7.0-alpha.12",
|
|
55
|
+
"@lwrjs/o11y": "0.7.0-alpha.12",
|
|
56
|
+
"@lwrjs/resource-registry": "0.7.0-alpha.12",
|
|
57
|
+
"@lwrjs/router": "0.7.0-alpha.12",
|
|
58
|
+
"@lwrjs/server": "0.7.0-alpha.12",
|
|
59
|
+
"@lwrjs/shared-utils": "0.7.0-alpha.12",
|
|
60
|
+
"@lwrjs/view-registry": "0.7.0-alpha.12",
|
|
62
61
|
"fs-extra": "^10.0.0",
|
|
63
62
|
"jsdom": "^16.7.0",
|
|
64
63
|
"jsonc-parser": "^3.0.0",
|
|
@@ -67,7 +66,7 @@
|
|
|
67
66
|
"qs": "^6.9.4"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
|
-
"@lwrjs/types": "0.7.0-alpha.
|
|
69
|
+
"@lwrjs/types": "0.7.0-alpha.12"
|
|
71
70
|
},
|
|
72
71
|
"peerDependencies": {
|
|
73
72
|
"lwc": ">= 1.x <= 2.x"
|
|
@@ -75,5 +74,5 @@
|
|
|
75
74
|
"engines": {
|
|
76
75
|
"node": ">=14.15.4 <17"
|
|
77
76
|
},
|
|
78
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "785b8380a821b43b7320783dddaf20d1433216e2"
|
|
79
78
|
}
|
package/runtime-configs/dev.json
CHANGED