@lwrjs/core 0.11.3 → 0.11.5
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 +4 -1
- package/build/cjs/middleware/hmr-middleware.cjs +3 -3
- package/build/cjs/middleware/request-processor-middleware.cjs +12 -3
- package/build/cjs/middleware/view-middleware.cjs +10 -8
- package/build/cjs/tools/server-warmup.cjs +2 -2
- package/build/cjs/tools/static-generation.cjs +59 -24
- package/build/cjs/tools/utils/network-dispatcher.cjs +38 -9
- package/build/es/index.js +4 -1
- package/build/es/middleware/hmr-middleware.js +3 -3
- package/build/es/middleware/request-processor-middleware.js +12 -3
- package/build/es/middleware/view-middleware.js +13 -10
- package/build/es/tools/server-warmup.js +2 -2
- package/build/es/tools/static-generation.js +59 -26
- package/build/es/tools/utils/network-dispatcher.js +38 -9
- package/package.json +30 -30
package/build/cjs/index.cjs
CHANGED
|
@@ -192,7 +192,10 @@ async function generateStaticSite(config) {
|
|
|
192
192
|
config.serverType = "fs";
|
|
193
193
|
const {serverMode} = config;
|
|
194
194
|
if (serverMode === "dev" || serverMode === "compat") {
|
|
195
|
-
import_diagnostics.logger.warn(
|
|
195
|
+
import_diagnostics.logger.warn({
|
|
196
|
+
label: `ssg`,
|
|
197
|
+
message: `static generation in 'dev' or 'compat' mode is currently not fully supported'`
|
|
198
|
+
});
|
|
196
199
|
}
|
|
197
200
|
const lwrApp = createServer(config);
|
|
198
201
|
overrideConfigAsSrc(lwrApp);
|
|
@@ -79,7 +79,7 @@ var Hmr = class {
|
|
|
79
79
|
runtimeParams
|
|
80
80
|
} = moduleDefinition;
|
|
81
81
|
const {format, debug, compat} = runtimeEnvironment;
|
|
82
|
-
import_diagnostics.logger.info(`Recompiled module: ${specifier}, ${signature}`);
|
|
82
|
+
import_diagnostics.logger.info({label: `hmr`, message: `Recompiled module: ${specifier}, ${signature}`});
|
|
83
83
|
const moduleId = {
|
|
84
84
|
specifier,
|
|
85
85
|
namespace,
|
|
@@ -107,7 +107,7 @@ var Hmr = class {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
updateTemplateOnClients(compiledView) {
|
|
110
|
-
import_diagnostics.logger.info(
|
|
110
|
+
import_diagnostics.logger.info({label: `hmr`, message: `Recompiled view source`, additionalInfo: compiledView.viewId});
|
|
111
111
|
const {contentTemplate} = compiledView.viewId;
|
|
112
112
|
if (this.connectedClients && contentTemplate) {
|
|
113
113
|
for (const ws of this.connectedClients.keys()) {
|
|
@@ -122,7 +122,7 @@ var Hmr = class {
|
|
|
122
122
|
}
|
|
123
123
|
updateAssetOnClients(asset) {
|
|
124
124
|
const assetId = asset.entry;
|
|
125
|
-
import_diagnostics.logger.info(`Updated asset: ${assetId}`);
|
|
125
|
+
import_diagnostics.logger.info({label: `hmr`, message: `Updated asset: ${assetId}`});
|
|
126
126
|
if (this.connectedClients) {
|
|
127
127
|
for (const ws of this.connectedClients.keys()) {
|
|
128
128
|
ws.send(JSON.stringify({
|
|
@@ -36,18 +36,27 @@ function requestProcessorMiddleware(app, context) {
|
|
|
36
36
|
if (req.headers) {
|
|
37
37
|
if (import_diagnostics.logger.isDebugEnabled()) {
|
|
38
38
|
for (const headerName in req.headers) {
|
|
39
|
-
import_diagnostics.logger.debug(
|
|
39
|
+
import_diagnostics.logger.debug({
|
|
40
|
+
label: `request-processor-middleware`,
|
|
41
|
+
message: `Header ${headerName}: ${req.headers[headerName]}`
|
|
42
|
+
});
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
requestClass = req.headers[MRT_REQUEST_CLASS_KEY];
|
|
43
46
|
}
|
|
44
47
|
if (req.headers && typeof requestClass === "string") {
|
|
45
48
|
const parsedRequestClass = parseRequestClass(requestClass);
|
|
46
|
-
import_diagnostics.logger.debug(
|
|
49
|
+
import_diagnostics.logger.debug({
|
|
50
|
+
label: `request-processor-middleware`,
|
|
51
|
+
message: `parsedRequestClass?.basePath: ${parsedRequestClass?.basePath}`
|
|
52
|
+
});
|
|
47
53
|
const pathValue = parsedRequestClass?.basePath || basePath || "";
|
|
48
54
|
req.basePath = pathValue === "" || pathValue.indexOf("/") === 0 ? pathValue : `/${pathValue}`;
|
|
49
55
|
} else {
|
|
50
|
-
import_diagnostics.logger.debug(
|
|
56
|
+
import_diagnostics.logger.debug({
|
|
57
|
+
label: `request-processor-middleware`,
|
|
58
|
+
message: `${MRT_REQUEST_CLASS_KEY} ignored ${req.headers ? req.headers[MRT_REQUEST_CLASS_KEY] : "no-headers"}`
|
|
59
|
+
});
|
|
51
60
|
req.basePath = basePath;
|
|
52
61
|
}
|
|
53
62
|
await next();
|
|
@@ -168,22 +168,24 @@ function viewMiddleware(app, context) {
|
|
|
168
168
|
subRoutes.routes.forEach((subRoute) => subRoute.uri !== route.path && paths.push(`${prefix}${subRoute.uri}`));
|
|
169
169
|
}
|
|
170
170
|
if (i18n.uriPattern === "path-prefix") {
|
|
171
|
-
const defaultLocalePaths = paths.map((routePath) => `/${i18n.defaultLocale}${routePath}`);
|
|
172
171
|
const supportedStr = i18n.locales.map((l) => l.id).filter((id) => id !== i18n.defaultLocale).join("|");
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
paths.
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
if (supportedStr) {
|
|
173
|
+
const defaultLocalePaths = paths.map((routePath) => `/${i18n.defaultLocale}${routePath}`);
|
|
174
|
+
paths.forEach((routePath) => {
|
|
175
|
+
const localizedPath = `/:locale(${supportedStr})${routePath}`;
|
|
176
|
+
paths.push(localizedPath);
|
|
177
|
+
});
|
|
178
|
+
addDefaultLocaleRedirects(i18n.defaultLocale, defaultLocalePaths, app);
|
|
179
|
+
}
|
|
178
180
|
}
|
|
179
|
-
import_diagnostics.logger.debug(`
|
|
181
|
+
import_diagnostics.logger.debug({label: `view-middleware`, message: `Add view paths ${paths}`});
|
|
180
182
|
app.get(paths, (0, import_error_handling.handleErrors)(createViewMiddleware(route, errorRoutes, context, viewHandler)));
|
|
181
183
|
}
|
|
182
184
|
app.get((0, import_shared_utils.getClientBootstrapConfigurationRoutes)(), (0, import_error_handling.handleErrors)(createConfigMiddleware(routes, context, viewHandler)));
|
|
183
185
|
app.get("/" + app.getRegexWildcard(), (0, import_error_handling.handleErrors)(createNotFoundMiddleware(errorRoutes, context, viewHandler)));
|
|
184
186
|
}
|
|
185
187
|
function addDefaultLocaleRedirects(defaultLocale, defaultLocalePaths, app) {
|
|
186
|
-
import_diagnostics.logger.debug(`
|
|
188
|
+
import_diagnostics.logger.debug({label: `view-middleware`, message: `Add default localized paths ${defaultLocalePaths}`});
|
|
187
189
|
app.get(defaultLocalePaths, (req, res) => {
|
|
188
190
|
let modifiedPath = req.originalUrl.replace(`/${defaultLocale}`, "");
|
|
189
191
|
if (modifiedPath.indexOf("/") !== 0) {
|
|
@@ -35,11 +35,11 @@ async function warmupServer(config, internalRequestKey) {
|
|
|
35
35
|
if (import_diagnostics.logger.isWarnEnabled()) {
|
|
36
36
|
import_diagnostics.logger.setOptions({dedupe: new Set(["warn"])});
|
|
37
37
|
}
|
|
38
|
-
import_diagnostics.logger.info(
|
|
38
|
+
import_diagnostics.logger.info({label: `server-warmup`, message: `starting`});
|
|
39
39
|
const {basePath, port, routes, staticSiteGenerator} = config;
|
|
40
40
|
staticSiteGenerator.outputDir = import_dir.skipDirCreation;
|
|
41
41
|
const urlRewriteMap = new Map();
|
|
42
42
|
const runtimeEnvironment = (0, import_config.getRuntimeEnvironment)(config);
|
|
43
43
|
await new import_static_generation.default().generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, new import_network_dispatcher.default(port, internalRequestKey), staticSiteGenerator.outputDir, urlRewriteMap);
|
|
44
|
-
import_diagnostics.logger.info(
|
|
44
|
+
import_diagnostics.logger.info({label: `server-warmup`, message: `complete`});
|
|
45
45
|
}
|
|
@@ -39,7 +39,7 @@ var import_config = __toModule(require("@lwrjs/config"));
|
|
|
39
39
|
var SiteGenerator = class {
|
|
40
40
|
async buildStaticApplication(config, dispatcher) {
|
|
41
41
|
const startTime = import_perf_hooks.performance.now();
|
|
42
|
-
import_diagnostics.logger.info(
|
|
42
|
+
import_diagnostics.logger.info({label: `ssg`, message: `Static Site Generation`});
|
|
43
43
|
if (import_diagnostics.logger.isWarnEnabled()) {
|
|
44
44
|
import_diagnostics.logger.setOptions({dedupe: new Set(["warn"])});
|
|
45
45
|
}
|
|
@@ -49,20 +49,23 @@ var SiteGenerator = class {
|
|
|
49
49
|
}
|
|
50
50
|
const outputDir = (0, import_path.join)(rootDir, staticSiteGenerator.outputDir);
|
|
51
51
|
if (!staticSiteGenerator.skipCleanOutputDir) {
|
|
52
|
-
import_diagnostics.logger.info(`
|
|
52
|
+
import_diagnostics.logger.info({label: `ssg`, message: `Clearing output directory: ${outputDir}`});
|
|
53
53
|
import_fs_extra.default.rmSync(outputDir, {recursive: true, force: true});
|
|
54
54
|
} else if (import_fs_extra.default.existsSync(outputDir)) {
|
|
55
|
-
import_diagnostics.logger.info(`
|
|
55
|
+
import_diagnostics.logger.info({label: `ssg`, message: `Reusing existing output directory: ${outputDir}`});
|
|
56
56
|
}
|
|
57
57
|
const urlRewriteMap = new Map();
|
|
58
58
|
const runtimeEnvironment = (0, import_config.getRuntimeEnvironment)(config);
|
|
59
|
-
import_diagnostics.logger.info(`
|
|
59
|
+
import_diagnostics.logger.info({label: `ssg`, message: `Building routes (this may take some time to complete)`});
|
|
60
60
|
await this.generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, dispatcher, outputDir, urlRewriteMap);
|
|
61
61
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
62
62
|
await this.copyAssets(assets, outputDir, config);
|
|
63
63
|
const endTime = import_perf_hooks.performance.now();
|
|
64
64
|
const timeDiff = (endTime - startTime) / 1e3;
|
|
65
|
-
import_diagnostics.logger.info(
|
|
65
|
+
import_diagnostics.logger.info({
|
|
66
|
+
label: `ssg`,
|
|
67
|
+
message: `Static Site Generation complete in ${Math.round(timeDiff)} seconds`
|
|
68
|
+
});
|
|
66
69
|
}
|
|
67
70
|
async generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, dispatcher, outputDir, urlRewriteMap = new Map()) {
|
|
68
71
|
const generateUrl = this.createGenerateURLFunction(dispatcher);
|
|
@@ -73,7 +76,7 @@ var SiteGenerator = class {
|
|
|
73
76
|
} else {
|
|
74
77
|
const sortedLocales = (0, import_shared_utils.sortLocalesByFallback)(i18n);
|
|
75
78
|
for (const locale of sortedLocales) {
|
|
76
|
-
import_diagnostics.logger.debug(`
|
|
79
|
+
import_diagnostics.logger.debug({label: `ssg`, message: `Generate routes of locale: ${locale.id}`});
|
|
77
80
|
await this.generateRoutesForLocale(routes, outputDir, locale, urlRewriteMap, skipBaseDocumentGeneration, runtimeEnvironment, basePath, generateUrl, staticSiteGenerator, dispatcher);
|
|
78
81
|
}
|
|
79
82
|
}
|
|
@@ -94,27 +97,30 @@ var SiteGenerator = class {
|
|
|
94
97
|
const {_additionalModules} = staticSiteGenerator;
|
|
95
98
|
if (_additionalModules) {
|
|
96
99
|
for (const specifier of _additionalModules) {
|
|
97
|
-
import_diagnostics.logger.debug(`
|
|
100
|
+
import_diagnostics.logger.debug({label: `ssg`, message: `Additional Module: ${locale.id} ${specifier}`});
|
|
98
101
|
const startTime = import_perf_hooks.performance.now();
|
|
99
102
|
const siteConfig = this.createSiteConfig(outputDir, locale.id, urlRewriteMap, skipBaseDocumentGeneration, runtimeEnvironment, i18n);
|
|
100
103
|
await this.dispatchJSResourceRecursive(specifier, dispatcher, siteConfig, true);
|
|
101
104
|
await this.captureAdditionalRouteMetadata(siteConfig);
|
|
102
105
|
const endTime = import_perf_hooks.performance.now();
|
|
103
106
|
const timeDiff = endTime - startTime;
|
|
104
|
-
import_diagnostics.logger.info(
|
|
107
|
+
import_diagnostics.logger.info({
|
|
108
|
+
label: `ssg`,
|
|
109
|
+
message: `Additional Module ${locale.id} ${specifier} in ${Math.round(timeDiff)} ms`
|
|
110
|
+
});
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
createGenerateURLFunction(dispatcher) {
|
|
109
115
|
const generateRoute = async (uri, siteConfig) => {
|
|
110
116
|
const locale = siteConfig.locale;
|
|
111
|
-
import_diagnostics.logger.debug(`
|
|
117
|
+
import_diagnostics.logger.debug({label: `ssg`, message: `Start Generate: ${locale} ${uri}`});
|
|
112
118
|
const startTime = import_perf_hooks.performance.now();
|
|
113
119
|
await this.dispatchResourceRecursive(uri, dispatcher, {resourceType: "route"}, siteConfig);
|
|
114
120
|
await this.captureAdditionalRouteMetadata(siteConfig);
|
|
115
121
|
const endTime = import_perf_hooks.performance.now();
|
|
116
122
|
const timeDiff = endTime - startTime;
|
|
117
|
-
import_diagnostics.logger.info(`
|
|
123
|
+
import_diagnostics.logger.info({label: `ssg`, message: `${locale} ${uri} in ${Math.round(timeDiff)} ms`});
|
|
118
124
|
};
|
|
119
125
|
return generateRoute.bind(this);
|
|
120
126
|
}
|
|
@@ -123,11 +129,14 @@ var SiteGenerator = class {
|
|
|
123
129
|
if (!visitedUrls.has(url)) {
|
|
124
130
|
visitedUrls.add(url);
|
|
125
131
|
if ((0, import_shared_utils.isExternalUrl)(url)) {
|
|
126
|
-
import_diagnostics.logger.warn(
|
|
132
|
+
import_diagnostics.logger.warn({label: `ssg`, message: `Skipped generation of external url: ${url}`});
|
|
127
133
|
return;
|
|
128
134
|
}
|
|
129
135
|
if (url.indexOf("/:") !== -1 || url.indexOf("*") !== -1) {
|
|
130
|
-
import_diagnostics.logger.warn(
|
|
136
|
+
import_diagnostics.logger.warn({
|
|
137
|
+
label: `ssg`,
|
|
138
|
+
message: `Skipped generation of url with variable path segment: ${url}`
|
|
139
|
+
});
|
|
131
140
|
return;
|
|
132
141
|
}
|
|
133
142
|
let context;
|
|
@@ -206,7 +215,11 @@ var SiteGenerator = class {
|
|
|
206
215
|
addResourceToSiteMetadata(resourceDefinition, url, siteConfig) {
|
|
207
216
|
if (siteConfig.siteMetadata) {
|
|
208
217
|
if (!resourceDefinition.specifier) {
|
|
209
|
-
import_diagnostics.logger.warn(
|
|
218
|
+
import_diagnostics.logger.warn({
|
|
219
|
+
label: `ssg`,
|
|
220
|
+
message: `Could not save resource metadata. There was no specifier.`,
|
|
221
|
+
additionalInfo: resourceDefinition
|
|
222
|
+
});
|
|
210
223
|
} else {
|
|
211
224
|
const specifier = resourceDefinition.specifier;
|
|
212
225
|
const resourceMetadata = {
|
|
@@ -222,7 +235,11 @@ var SiteGenerator = class {
|
|
|
222
235
|
addAssetToSiteMetadata(assetDefinition, url, siteConfig) {
|
|
223
236
|
if (siteConfig.siteMetadata) {
|
|
224
237
|
if (!assetDefinition.uri) {
|
|
225
|
-
import_diagnostics.logger.warn(
|
|
238
|
+
import_diagnostics.logger.warn({
|
|
239
|
+
label: `ssg`,
|
|
240
|
+
message: `Could not save asset metadata. There was no uri.`,
|
|
241
|
+
additionalInfo: assetDefinition
|
|
242
|
+
});
|
|
226
243
|
} else {
|
|
227
244
|
const specifier = assetDefinition.uri;
|
|
228
245
|
const resourceMetadata = {
|
|
@@ -233,7 +250,7 @@ var SiteGenerator = class {
|
|
|
233
250
|
if (!siteAssets.assets[specifier]) {
|
|
234
251
|
siteAssets.assets[specifier] = resourceMetadata;
|
|
235
252
|
} else {
|
|
236
|
-
import_diagnostics.logger.debug(`
|
|
253
|
+
import_diagnostics.logger.debug({label: `ssg`, message: `Ignore asset redefinition ${specifier}`});
|
|
237
254
|
}
|
|
238
255
|
}
|
|
239
256
|
}
|
|
@@ -256,7 +273,7 @@ var SiteGenerator = class {
|
|
|
256
273
|
await Promise.all(dispatchRequests);
|
|
257
274
|
} else {
|
|
258
275
|
const body = context.fs?.body;
|
|
259
|
-
import_diagnostics.logger.warn(`
|
|
276
|
+
import_diagnostics.logger.warn({label: `ssg`, message: `Failed to fetch ${url}: (${statusCode}) ${body}`});
|
|
260
277
|
}
|
|
261
278
|
}
|
|
262
279
|
async handleHtmlResource(url, context, siteConfig, dispatcher) {
|
|
@@ -315,7 +332,7 @@ var SiteGenerator = class {
|
|
|
315
332
|
siteConfig.viewConfigPath = this.getResourcePathFromUrl(siteConfig, resourceUri);
|
|
316
333
|
}
|
|
317
334
|
} else {
|
|
318
|
-
import_diagnostics.logger.warn(
|
|
335
|
+
import_diagnostics.logger.warn({label: `ssg`, message: `Skipped inline bootstrap resource: ${resource}`});
|
|
319
336
|
}
|
|
320
337
|
}
|
|
321
338
|
}
|
|
@@ -325,7 +342,7 @@ var SiteGenerator = class {
|
|
|
325
342
|
if (resourceUri.startsWith("/")) {
|
|
326
343
|
dispatchRequests.push(this.dispatchResourceRecursive(resourceUri, dispatcher, {resourceType: "resource"}, siteConfig));
|
|
327
344
|
} else {
|
|
328
|
-
import_diagnostics.logger.warn(
|
|
345
|
+
import_diagnostics.logger.warn({label: `ssg`, message: `Skipped resource: ${resource}`});
|
|
329
346
|
}
|
|
330
347
|
}
|
|
331
348
|
await Promise.all(dispatchRequests);
|
|
@@ -341,7 +358,10 @@ var SiteGenerator = class {
|
|
|
341
358
|
const mappingURL = siteConfig.endpoints?.uris?.mapping + encodeURIComponent(jsUri);
|
|
342
359
|
await this.dispatchResourceRecursive(mappingURL, dispatcher, {resourceType: "mapping"}, siteConfig);
|
|
343
360
|
} else {
|
|
344
|
-
import_diagnostics.logger.warn(
|
|
361
|
+
import_diagnostics.logger.warn({
|
|
362
|
+
label: `ssg`,
|
|
363
|
+
message: `Unable to fetch mapping for bare specifier or variable dynamic import: "${jsUri}"`
|
|
364
|
+
});
|
|
345
365
|
}
|
|
346
366
|
} else if (isAdditionalModulesRequest) {
|
|
347
367
|
const uri = `${siteConfig.endpoints?.uris.legacyDefault}${encodeURIComponent(jsUri)}`;
|
|
@@ -363,7 +383,11 @@ var SiteGenerator = class {
|
|
|
363
383
|
for (const ref of assetReferences) {
|
|
364
384
|
const refUrl = ref.override?.uri || ref.url;
|
|
365
385
|
dispatchRequests.push(this.dispatchResourceRecursive(refUrl, dispatcher, {resourceType: "asset", asset: metadata?.asset}, siteConfig).catch((err) => {
|
|
366
|
-
import_diagnostics.logger.warn(
|
|
386
|
+
import_diagnostics.logger.warn({
|
|
387
|
+
label: `ssg`,
|
|
388
|
+
message: `Failed to fetch asset reference => ${refUrl} from ${url}`,
|
|
389
|
+
additionalInfo: err
|
|
390
|
+
});
|
|
367
391
|
}));
|
|
368
392
|
}
|
|
369
393
|
return Promise.all(dispatchRequests);
|
|
@@ -423,10 +447,13 @@ var SiteGenerator = class {
|
|
|
423
447
|
import_fs_extra.default.copySync(assetSrcFile, assetsPath);
|
|
424
448
|
this.addAssetToMetadata(assetsPath, siteConfig);
|
|
425
449
|
} else {
|
|
426
|
-
import_diagnostics.logger.warn(
|
|
450
|
+
import_diagnostics.logger.warn({
|
|
451
|
+
label: `ssg`,
|
|
452
|
+
message: `Could not find assets to copy at path: ${assetsPath}`
|
|
453
|
+
});
|
|
427
454
|
}
|
|
428
455
|
} catch (e) {
|
|
429
|
-
import_diagnostics.logger.error(
|
|
456
|
+
import_diagnostics.logger.error(`[ssg] Error occurred processing asset config: ${JSON.stringify(asset)}`);
|
|
430
457
|
import_diagnostics.logger.error(e);
|
|
431
458
|
}
|
|
432
459
|
}
|
|
@@ -444,7 +471,11 @@ var SiteGenerator = class {
|
|
|
444
471
|
}
|
|
445
472
|
}
|
|
446
473
|
} catch (err) {
|
|
447
|
-
import_diagnostics.logger.warn(
|
|
474
|
+
import_diagnostics.logger.warn({
|
|
475
|
+
label: `ssg`,
|
|
476
|
+
message: `Unexpected error collecting asset directory metadata for ${directoryPath}`,
|
|
477
|
+
additionalInfo: err
|
|
478
|
+
});
|
|
448
479
|
}
|
|
449
480
|
}
|
|
450
481
|
addAssetToMetadata(filePath, siteConfig) {
|
|
@@ -465,7 +496,11 @@ var SiteGenerator = class {
|
|
|
465
496
|
}
|
|
466
497
|
}, uri, siteConfig);
|
|
467
498
|
} catch (err) {
|
|
468
|
-
import_diagnostics.logger.warn(
|
|
499
|
+
import_diagnostics.logger.warn({
|
|
500
|
+
label: `ssg`,
|
|
501
|
+
message: `Unexpected error collecting asset metadata for ${filePath}`,
|
|
502
|
+
additionalInfo: err
|
|
503
|
+
});
|
|
469
504
|
}
|
|
470
505
|
}
|
|
471
506
|
createSiteConfig(outputDir, locale, urlRewriteMap, skipBaseDocumentGeneration, runtimeEnvironment, i18n) {
|
|
@@ -60,13 +60,19 @@ var NetworkDispatcher = class {
|
|
|
60
60
|
return new Promise((resolve, reject) => {
|
|
61
61
|
const httpClient = options.port == 443 ? import_https.default : import_http.default;
|
|
62
62
|
const bodyChunks = [];
|
|
63
|
-
import_diagnostics.logger.verbose(
|
|
63
|
+
import_diagnostics.logger.verbose({
|
|
64
|
+
label: `NetworkDispatcher`,
|
|
65
|
+
message: `Request: [${method}][${lang}] ${url}`
|
|
66
|
+
});
|
|
64
67
|
const req = httpClient.request(options, (res) => {
|
|
65
68
|
res.on("data", (chunk) => {
|
|
66
69
|
bodyChunks.push(chunk);
|
|
67
70
|
});
|
|
68
71
|
res.on("end", () => {
|
|
69
|
-
import_diagnostics.logger.verbose(
|
|
72
|
+
import_diagnostics.logger.verbose({
|
|
73
|
+
label: `NetworkDispatcher`,
|
|
74
|
+
message: `[END] Request: [${method}][${lang}] ${url}`
|
|
75
|
+
});
|
|
70
76
|
if (!res.statusCode || res.statusCode >= 200 && res.statusCode < 300) {
|
|
71
77
|
const body = Buffer.concat(bodyChunks).toString();
|
|
72
78
|
try {
|
|
@@ -74,32 +80,55 @@ var NetworkDispatcher = class {
|
|
|
74
80
|
resolve(jsonResponse);
|
|
75
81
|
} catch (err) {
|
|
76
82
|
if (import_diagnostics.logger.isDebugEnabled()) {
|
|
77
|
-
import_diagnostics.logger.warn(
|
|
83
|
+
import_diagnostics.logger.warn({
|
|
84
|
+
label: `NetworkDispatcher`,
|
|
85
|
+
message: `unexpected response body: [${method}][${lang}] ${url}: '${body}'`,
|
|
86
|
+
additionalInfo: err
|
|
87
|
+
});
|
|
78
88
|
} else {
|
|
79
|
-
import_diagnostics.logger.warn(
|
|
89
|
+
import_diagnostics.logger.warn({
|
|
90
|
+
label: `NetworkDispatcher`,
|
|
91
|
+
message: `unexpected response body: [${method}][${lang}] ${url}: '${body}'`
|
|
92
|
+
});
|
|
80
93
|
}
|
|
81
94
|
resolve({});
|
|
82
95
|
}
|
|
83
96
|
} else if (res.statusCode === 301 || res.statusCode === 302) {
|
|
84
97
|
if (res.headers?.location && (0, import_shared_utils.isModuleOrBundleUrl)(res.headers?.location)) {
|
|
85
|
-
import_diagnostics.logger.debug(
|
|
98
|
+
import_diagnostics.logger.debug({
|
|
99
|
+
label: `NetworkDispatcher`,
|
|
100
|
+
message: `Follow redirect: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`
|
|
101
|
+
});
|
|
86
102
|
const location = res.headers.location;
|
|
87
103
|
return this.handleRequest(this.createRequestOptions(location, method, lang), location, method, lang).then((resRedirect) => resolve(resRedirect)).catch((rejectRedirect) => reject(rejectRedirect));
|
|
88
104
|
} else {
|
|
89
|
-
import_diagnostics.logger.warn(
|
|
105
|
+
import_diagnostics.logger.warn({
|
|
106
|
+
label: `NetworkDispatcher`,
|
|
107
|
+
message: `Redirect not followed: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`
|
|
108
|
+
});
|
|
90
109
|
resolve({});
|
|
91
110
|
}
|
|
92
111
|
} else {
|
|
93
|
-
import_diagnostics.logger.warn(
|
|
112
|
+
import_diagnostics.logger.warn({
|
|
113
|
+
label: `NetworkDispatcher`,
|
|
114
|
+
message: `Unexpected status code: [${method}][${lang}][${res.statusCode}] ${url}`
|
|
115
|
+
});
|
|
94
116
|
resolve({});
|
|
95
117
|
}
|
|
96
118
|
});
|
|
97
119
|
});
|
|
98
120
|
req.on("error", (err) => {
|
|
99
121
|
if (import_diagnostics.logger.isDebugEnabled()) {
|
|
100
|
-
import_diagnostics.logger.warn(
|
|
122
|
+
import_diagnostics.logger.warn({
|
|
123
|
+
label: `NetworkDispatcher`,
|
|
124
|
+
message: `Request Failed: [${method}][${lang}] ${url}`,
|
|
125
|
+
additionalInfo: err
|
|
126
|
+
});
|
|
101
127
|
} else {
|
|
102
|
-
import_diagnostics.logger.warn(
|
|
128
|
+
import_diagnostics.logger.warn({
|
|
129
|
+
label: `NetworkDispatcher`,
|
|
130
|
+
message: `Request Failed: [${method}][${lang}] ${url}`
|
|
131
|
+
});
|
|
103
132
|
}
|
|
104
133
|
resolve({});
|
|
105
134
|
});
|
package/build/es/index.js
CHANGED
|
@@ -191,7 +191,10 @@ export async function generateStaticSite(config) {
|
|
|
191
191
|
if (serverMode === 'dev' || serverMode === 'compat') {
|
|
192
192
|
// TODO: dynamic imports are not generated in dev mode
|
|
193
193
|
// https://github.com/salesforce-experience-platform-emu/lwr/issues/1111
|
|
194
|
-
logger.warn(
|
|
194
|
+
logger.warn({
|
|
195
|
+
label: `ssg`,
|
|
196
|
+
message: `static generation in 'dev' or 'compat' mode is currently not fully supported'`,
|
|
197
|
+
});
|
|
195
198
|
}
|
|
196
199
|
const lwrApp = createServer(config);
|
|
197
200
|
overrideConfigAsSrc(lwrApp);
|
|
@@ -45,7 +45,7 @@ class Hmr {
|
|
|
45
45
|
const { moduleRegistry } = this;
|
|
46
46
|
const { specifier, namespace, name, version, ownHash: signature, runtimeEnvironment, runtimeParams, } = moduleDefinition;
|
|
47
47
|
const { format, debug, compat } = runtimeEnvironment;
|
|
48
|
-
logger.info(`Recompiled module: ${specifier}, ${signature}`);
|
|
48
|
+
logger.info({ label: `hmr`, message: `Recompiled module: ${specifier}, ${signature}` });
|
|
49
49
|
const moduleId = {
|
|
50
50
|
specifier,
|
|
51
51
|
namespace,
|
|
@@ -73,7 +73,7 @@ class Hmr {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
updateTemplateOnClients(compiledView) {
|
|
76
|
-
logger.info(
|
|
76
|
+
logger.info({ label: `hmr`, message: `Recompiled view source`, additionalInfo: compiledView.viewId });
|
|
77
77
|
const { contentTemplate } = compiledView.viewId;
|
|
78
78
|
if (this.connectedClients && contentTemplate) {
|
|
79
79
|
for (const ws of this.connectedClients.keys()) {
|
|
@@ -88,7 +88,7 @@ class Hmr {
|
|
|
88
88
|
}
|
|
89
89
|
updateAssetOnClients(asset) {
|
|
90
90
|
const assetId = asset.entry;
|
|
91
|
-
logger.info(`Updated asset: ${assetId}`);
|
|
91
|
+
logger.info({ label: `hmr`, message: `Updated asset: ${assetId}` });
|
|
92
92
|
if (this.connectedClients) {
|
|
93
93
|
for (const ws of this.connectedClients.keys()) {
|
|
94
94
|
ws.send(JSON.stringify({
|
|
@@ -18,20 +18,29 @@ export function requestProcessorMiddleware(app, context) {
|
|
|
18
18
|
if (logger.isDebugEnabled()) {
|
|
19
19
|
// Loop through and print each header
|
|
20
20
|
for (const headerName in req.headers) {
|
|
21
|
-
logger.debug(
|
|
21
|
+
logger.debug({
|
|
22
|
+
label: `request-processor-middleware`,
|
|
23
|
+
message: `Header ${headerName}: ${req.headers[headerName]}`,
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
requestClass = req.headers[MRT_REQUEST_CLASS_KEY];
|
|
25
28
|
}
|
|
26
29
|
if (req.headers && typeof requestClass === 'string') {
|
|
27
30
|
const parsedRequestClass = parseRequestClass(requestClass);
|
|
28
|
-
logger.debug(
|
|
31
|
+
logger.debug({
|
|
32
|
+
label: `request-processor-middleware`,
|
|
33
|
+
message: `parsedRequestClass?.basePath: ${parsedRequestClass?.basePath}`,
|
|
34
|
+
});
|
|
29
35
|
const pathValue = parsedRequestClass?.basePath || basePath || '';
|
|
30
36
|
// If base path is '' or starts with / leave it alone
|
|
31
37
|
req.basePath = pathValue === '' || pathValue.indexOf('/') === 0 ? pathValue : `/${pathValue}`;
|
|
32
38
|
}
|
|
33
39
|
else {
|
|
34
|
-
logger.debug(
|
|
40
|
+
logger.debug({
|
|
41
|
+
label: `request-processor-middleware`,
|
|
42
|
+
message: `${MRT_REQUEST_CLASS_KEY} ignored ${req.headers ? req.headers[MRT_REQUEST_CLASS_KEY] : 'no-headers'}`,
|
|
43
|
+
});
|
|
35
44
|
req.basePath = basePath;
|
|
36
45
|
}
|
|
37
46
|
// await is required when calling next to support koa
|
|
@@ -152,20 +152,23 @@ export function viewMiddleware(app, context) {
|
|
|
152
152
|
}
|
|
153
153
|
// Add localized routes
|
|
154
154
|
if (i18n.uriPattern === 'path-prefix') {
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
// Map all supported locale ids into an array. Filter out the default one. It will be handled separately
|
|
155
|
+
// Map all supported locale ids into an or patter /:locale(es|es-MX|fr|rd-CA).
|
|
156
|
+
// Filter out the default locale. It will be handled separately
|
|
158
157
|
const supportedStr = i18n.locales
|
|
159
158
|
.map((l) => l.id)
|
|
160
159
|
.filter((id) => id !== i18n.defaultLocale)
|
|
161
160
|
.join('|');
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
paths.
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
if (supportedStr) {
|
|
162
|
+
// Add a redirect handler for the default locale for each route /en-US/home -> 301 /home
|
|
163
|
+
const defaultLocalePaths = paths.map((routePath) => `/${i18n.defaultLocale}${routePath}`);
|
|
164
|
+
paths.forEach((routePath) => {
|
|
165
|
+
const localizedPath = `/:locale(${supportedStr})${routePath}`;
|
|
166
|
+
paths.push(localizedPath);
|
|
167
|
+
});
|
|
168
|
+
addDefaultLocaleRedirects(i18n.defaultLocale, defaultLocalePaths, app);
|
|
169
|
+
}
|
|
167
170
|
}
|
|
168
|
-
logger.debug(`
|
|
171
|
+
logger.debug({ label: `view-middleware`, message: `Add view paths ${paths}` });
|
|
169
172
|
app.get(paths, handleErrors(createViewMiddleware(route, errorRoutes, context, viewHandler)));
|
|
170
173
|
}
|
|
171
174
|
// create and attach middleware for bootstrap configurations
|
|
@@ -178,7 +181,7 @@ export function viewMiddleware(app, context) {
|
|
|
178
181
|
* Adds a 301 redirect if attempting to route with default locale as the path prefix
|
|
179
182
|
*/
|
|
180
183
|
function addDefaultLocaleRedirects(defaultLocale, defaultLocalePaths, app) {
|
|
181
|
-
logger.debug(`
|
|
184
|
+
logger.debug({ label: `view-middleware`, message: `Add default localized paths ${defaultLocalePaths}` });
|
|
182
185
|
app.get(defaultLocalePaths, (req, res) => {
|
|
183
186
|
// Get the original URL path and split it into segments
|
|
184
187
|
let modifiedPath = req.originalUrl.replace(`/${defaultLocale}`, '');
|
|
@@ -8,13 +8,13 @@ export async function warmupServer(config, internalRequestKey) {
|
|
|
8
8
|
if (logger.isWarnEnabled()) {
|
|
9
9
|
logger.setOptions({ dedupe: new Set(['warn']) });
|
|
10
10
|
}
|
|
11
|
-
logger.info(
|
|
11
|
+
logger.info({ label: `server-warmup`, message: `starting` });
|
|
12
12
|
const { basePath, port, routes, staticSiteGenerator } = config;
|
|
13
13
|
staticSiteGenerator.outputDir = skipDirCreation;
|
|
14
14
|
const urlRewriteMap = new Map();
|
|
15
15
|
const runtimeEnvironment = getRuntimeEnvironment(config);
|
|
16
16
|
// For each locale, generate all the modules
|
|
17
17
|
await new SiteGenerator().generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, new NetworkDispatcher(port, internalRequestKey), staticSiteGenerator.outputDir, urlRewriteMap);
|
|
18
|
-
logger.info(
|
|
18
|
+
logger.info({ label: `server-warmup`, message: `complete` });
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=server-warmup.js.map
|
|
@@ -19,7 +19,7 @@ export default class SiteGenerator {
|
|
|
19
19
|
*/
|
|
20
20
|
async buildStaticApplication(config, dispatcher) {
|
|
21
21
|
const startTime = performance.now();
|
|
22
|
-
logger.info(
|
|
22
|
+
logger.info({ label: `ssg`, message: `Static Site Generation` });
|
|
23
23
|
// De-duplicate warming messages if log level is warn or info
|
|
24
24
|
if (logger.isWarnEnabled()) {
|
|
25
25
|
logger.setOptions({ dedupe: new Set(['warn']) });
|
|
@@ -30,16 +30,16 @@ export default class SiteGenerator {
|
|
|
30
30
|
}
|
|
31
31
|
const outputDir = join(rootDir, staticSiteGenerator.outputDir);
|
|
32
32
|
if (!staticSiteGenerator.skipCleanOutputDir) {
|
|
33
|
-
logger.info(`
|
|
33
|
+
logger.info({ label: `ssg`, message: `Clearing output directory: ${outputDir}` });
|
|
34
34
|
fs.rmSync(outputDir, { recursive: true, force: true });
|
|
35
35
|
}
|
|
36
36
|
else if (fs.existsSync(outputDir)) {
|
|
37
|
-
logger.info(`
|
|
37
|
+
logger.info({ label: `ssg`, message: `Reusing existing output directory: ${outputDir}` });
|
|
38
38
|
}
|
|
39
39
|
const urlRewriteMap = new Map();
|
|
40
40
|
const runtimeEnvironment = getRuntimeEnvironment(config);
|
|
41
41
|
// For each locale, generate all the modules
|
|
42
|
-
logger.info(`
|
|
42
|
+
logger.info({ label: `ssg`, message: `Building routes (this may take some time to complete)` });
|
|
43
43
|
await this.generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, dispatcher, outputDir, urlRewriteMap);
|
|
44
44
|
// Write redirect files
|
|
45
45
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
@@ -47,7 +47,10 @@ export default class SiteGenerator {
|
|
|
47
47
|
await this.copyAssets(assets, outputDir, config);
|
|
48
48
|
const endTime = performance.now();
|
|
49
49
|
const timeDiff = (endTime - startTime) / 1000;
|
|
50
|
-
logger.info(
|
|
50
|
+
logger.info({
|
|
51
|
+
label: `ssg`,
|
|
52
|
+
message: `Static Site Generation complete in ${Math.round(timeDiff)} seconds`,
|
|
53
|
+
});
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
53
56
|
* Crawl all view routes for a site
|
|
@@ -67,7 +70,7 @@ export default class SiteGenerator {
|
|
|
67
70
|
const sortedLocales = sortLocalesByFallback(i18n);
|
|
68
71
|
// Generate all the routes
|
|
69
72
|
for (const locale of sortedLocales) {
|
|
70
|
-
logger.debug(`
|
|
73
|
+
logger.debug({ label: `ssg`, message: `Generate routes of locale: ${locale.id}` });
|
|
71
74
|
// eslint-disable-next-line no-await-in-loop
|
|
72
75
|
await this.generateRoutesForLocale(routes, outputDir, locale, urlRewriteMap, skipBaseDocumentGeneration, runtimeEnvironment, basePath, generateUrl, staticSiteGenerator, dispatcher);
|
|
73
76
|
}
|
|
@@ -96,7 +99,7 @@ export default class SiteGenerator {
|
|
|
96
99
|
const { _additionalModules } = staticSiteGenerator;
|
|
97
100
|
if (_additionalModules) {
|
|
98
101
|
for (const specifier of _additionalModules) {
|
|
99
|
-
logger.debug(`
|
|
102
|
+
logger.debug({ label: `ssg`, message: `Additional Module: ${locale.id} ${specifier}` });
|
|
100
103
|
const startTime = performance.now();
|
|
101
104
|
const siteConfig = this.createSiteConfig(outputDir, locale.id, urlRewriteMap, skipBaseDocumentGeneration, runtimeEnvironment, i18n);
|
|
102
105
|
// eslint-disable-next-line no-await-in-loop
|
|
@@ -106,7 +109,10 @@ export default class SiteGenerator {
|
|
|
106
109
|
await this.captureAdditionalRouteMetadata(siteConfig);
|
|
107
110
|
const endTime = performance.now();
|
|
108
111
|
const timeDiff = endTime - startTime;
|
|
109
|
-
logger.info(
|
|
112
|
+
logger.info({
|
|
113
|
+
label: `ssg`,
|
|
114
|
+
message: `Additional Module ${locale.id} ${specifier} in ${Math.round(timeDiff)} ms`,
|
|
115
|
+
});
|
|
110
116
|
}
|
|
111
117
|
}
|
|
112
118
|
}
|
|
@@ -116,7 +122,7 @@ export default class SiteGenerator {
|
|
|
116
122
|
createGenerateURLFunction(dispatcher) {
|
|
117
123
|
const generateRoute = async (uri, siteConfig) => {
|
|
118
124
|
const locale = siteConfig.locale;
|
|
119
|
-
logger.debug(`
|
|
125
|
+
logger.debug({ label: `ssg`, message: `Start Generate: ${locale} ${uri}` });
|
|
120
126
|
const startTime = performance.now();
|
|
121
127
|
// Kick off site generation for the current route
|
|
122
128
|
await this.dispatchResourceRecursive(uri, dispatcher, { resourceType: 'route' }, siteConfig);
|
|
@@ -124,7 +130,7 @@ export default class SiteGenerator {
|
|
|
124
130
|
await this.captureAdditionalRouteMetadata(siteConfig);
|
|
125
131
|
const endTime = performance.now();
|
|
126
132
|
const timeDiff = endTime - startTime;
|
|
127
|
-
logger.info(`
|
|
133
|
+
logger.info({ label: `ssg`, message: `${locale} ${uri} in ${Math.round(timeDiff)} ms` });
|
|
128
134
|
};
|
|
129
135
|
return generateRoute.bind(this);
|
|
130
136
|
}
|
|
@@ -142,13 +148,16 @@ export default class SiteGenerator {
|
|
|
142
148
|
visitedUrls.add(url); // Maintain a list of visited urls here to avoid potential infinite loops
|
|
143
149
|
// Skip remote urls (i.e. http://) the static view would call the remote url at runtime
|
|
144
150
|
if (isExternalUrl(url)) {
|
|
145
|
-
logger.warn(
|
|
151
|
+
logger.warn({ label: `ssg`, message: `Skipped generation of external url: ${url}` });
|
|
146
152
|
return;
|
|
147
153
|
}
|
|
148
154
|
// Skip urls with path segment variables (i.e. '/custom/:bar')
|
|
149
155
|
// Users can specify specific urls via the '_additionalRoutePaths' config property
|
|
150
156
|
if (url.indexOf('/:') !== -1 || url.indexOf('*') !== -1) {
|
|
151
|
-
logger.warn(
|
|
157
|
+
logger.warn({
|
|
158
|
+
label: `ssg`,
|
|
159
|
+
message: `Skipped generation of url with variable path segment: ${url}`,
|
|
160
|
+
});
|
|
152
161
|
return;
|
|
153
162
|
}
|
|
154
163
|
// Generate resource
|
|
@@ -270,7 +279,11 @@ export default class SiteGenerator {
|
|
|
270
279
|
addResourceToSiteMetadata(resourceDefinition, url, siteConfig) {
|
|
271
280
|
if (siteConfig.siteMetadata) {
|
|
272
281
|
if (!resourceDefinition.specifier) {
|
|
273
|
-
logger.warn(
|
|
282
|
+
logger.warn({
|
|
283
|
+
label: `ssg`,
|
|
284
|
+
message: `Could not save resource metadata. There was no specifier.`,
|
|
285
|
+
additionalInfo: resourceDefinition,
|
|
286
|
+
});
|
|
274
287
|
}
|
|
275
288
|
else {
|
|
276
289
|
const specifier = resourceDefinition.specifier;
|
|
@@ -287,7 +300,11 @@ export default class SiteGenerator {
|
|
|
287
300
|
addAssetToSiteMetadata(assetDefinition, url, siteConfig) {
|
|
288
301
|
if (siteConfig.siteMetadata) {
|
|
289
302
|
if (!assetDefinition.uri) {
|
|
290
|
-
logger.warn(
|
|
303
|
+
logger.warn({
|
|
304
|
+
label: `ssg`,
|
|
305
|
+
message: `Could not save asset metadata. There was no uri.`,
|
|
306
|
+
additionalInfo: assetDefinition,
|
|
307
|
+
});
|
|
291
308
|
}
|
|
292
309
|
else {
|
|
293
310
|
const specifier = assetDefinition.uri;
|
|
@@ -301,7 +318,7 @@ export default class SiteGenerator {
|
|
|
301
318
|
siteAssets.assets[specifier] = resourceMetadata;
|
|
302
319
|
}
|
|
303
320
|
else {
|
|
304
|
-
logger.debug(`
|
|
321
|
+
logger.debug({ label: `ssg`, message: `Ignore asset redefinition ${specifier}` });
|
|
305
322
|
}
|
|
306
323
|
}
|
|
307
324
|
}
|
|
@@ -341,7 +358,7 @@ export default class SiteGenerator {
|
|
|
341
358
|
}
|
|
342
359
|
else {
|
|
343
360
|
const body = context.fs?.body;
|
|
344
|
-
logger.warn(`
|
|
361
|
+
logger.warn({ label: `ssg`, message: `Failed to fetch ${url}: (${statusCode}) ${body}` });
|
|
345
362
|
}
|
|
346
363
|
}
|
|
347
364
|
/**
|
|
@@ -435,7 +452,7 @@ export default class SiteGenerator {
|
|
|
435
452
|
}
|
|
436
453
|
}
|
|
437
454
|
else {
|
|
438
|
-
logger.warn(
|
|
455
|
+
logger.warn({ label: `ssg`, message: `Skipped inline bootstrap resource: ${resource}` });
|
|
439
456
|
}
|
|
440
457
|
}
|
|
441
458
|
}
|
|
@@ -447,7 +464,7 @@ export default class SiteGenerator {
|
|
|
447
464
|
dispatchRequests.push(this.dispatchResourceRecursive(resourceUri, dispatcher, { resourceType: 'resource' }, siteConfig));
|
|
448
465
|
}
|
|
449
466
|
else {
|
|
450
|
-
logger.warn(
|
|
467
|
+
logger.warn({ label: `ssg`, message: `Skipped resource: ${resource}` });
|
|
451
468
|
}
|
|
452
469
|
}
|
|
453
470
|
// -- Dispatch dependencies
|
|
@@ -467,9 +484,10 @@ export default class SiteGenerator {
|
|
|
467
484
|
await this.dispatchResourceRecursive(mappingURL, dispatcher, { resourceType: 'mapping' }, siteConfig);
|
|
468
485
|
}
|
|
469
486
|
else {
|
|
470
|
-
logger.warn(
|
|
471
|
-
|
|
472
|
-
|
|
487
|
+
logger.warn({
|
|
488
|
+
label: `ssg`,
|
|
489
|
+
message: `Unable to fetch mapping for bare specifier or variable dynamic import: "${jsUri}"`,
|
|
490
|
+
});
|
|
473
491
|
}
|
|
474
492
|
}
|
|
475
493
|
// TODO: this code path was still being hit prior to _additionalModules
|
|
@@ -507,7 +525,11 @@ export default class SiteGenerator {
|
|
|
507
525
|
const refUrl = ref.override?.uri || ref.url;
|
|
508
526
|
dispatchRequests.push(this.dispatchResourceRecursive(refUrl, dispatcher, { resourceType: 'asset', asset: metadata?.asset }, siteConfig).catch((err) => {
|
|
509
527
|
// Warn the user that the we failed to fetch a referenced asset
|
|
510
|
-
logger.warn(
|
|
528
|
+
logger.warn({
|
|
529
|
+
label: `ssg`,
|
|
530
|
+
message: `Failed to fetch asset reference => ${refUrl} from ${url}`,
|
|
531
|
+
additionalInfo: err,
|
|
532
|
+
});
|
|
511
533
|
}));
|
|
512
534
|
}
|
|
513
535
|
return Promise.all(dispatchRequests);
|
|
@@ -594,11 +616,14 @@ export default class SiteGenerator {
|
|
|
594
616
|
this.addAssetToMetadata(assetsPath, siteConfig);
|
|
595
617
|
}
|
|
596
618
|
else {
|
|
597
|
-
logger.warn(
|
|
619
|
+
logger.warn({
|
|
620
|
+
label: `ssg`,
|
|
621
|
+
message: `Could not find assets to copy at path: ${assetsPath}`,
|
|
622
|
+
});
|
|
598
623
|
}
|
|
599
624
|
}
|
|
600
625
|
catch (e) {
|
|
601
|
-
logger.error(
|
|
626
|
+
logger.error(`[ssg] Error occurred processing asset config: ${JSON.stringify(asset)}`);
|
|
602
627
|
logger.error(e);
|
|
603
628
|
}
|
|
604
629
|
}
|
|
@@ -618,7 +643,11 @@ export default class SiteGenerator {
|
|
|
618
643
|
}
|
|
619
644
|
}
|
|
620
645
|
catch (err) {
|
|
621
|
-
logger.warn(
|
|
646
|
+
logger.warn({
|
|
647
|
+
label: `ssg`,
|
|
648
|
+
message: `Unexpected error collecting asset directory metadata for ${directoryPath}`,
|
|
649
|
+
additionalInfo: err,
|
|
650
|
+
});
|
|
622
651
|
}
|
|
623
652
|
}
|
|
624
653
|
addAssetToMetadata(filePath, siteConfig) {
|
|
@@ -640,7 +669,11 @@ export default class SiteGenerator {
|
|
|
640
669
|
}, uri, siteConfig);
|
|
641
670
|
}
|
|
642
671
|
catch (err) {
|
|
643
|
-
logger.warn(
|
|
672
|
+
logger.warn({
|
|
673
|
+
label: `ssg`,
|
|
674
|
+
message: `Unexpected error collecting asset metadata for ${filePath}`,
|
|
675
|
+
additionalInfo: err,
|
|
676
|
+
});
|
|
644
677
|
}
|
|
645
678
|
}
|
|
646
679
|
/**
|
|
@@ -33,13 +33,19 @@ export default class NetworkDispatcher {
|
|
|
33
33
|
return new Promise((resolve, reject) => {
|
|
34
34
|
const httpClient = options.port == 443 ? https : http;
|
|
35
35
|
const bodyChunks = [];
|
|
36
|
-
logger.verbose(
|
|
36
|
+
logger.verbose({
|
|
37
|
+
label: `NetworkDispatcher`,
|
|
38
|
+
message: `Request: [${method}][${lang}] ${url}`,
|
|
39
|
+
});
|
|
37
40
|
const req = httpClient.request(options, (res) => {
|
|
38
41
|
res.on('data', (chunk) => {
|
|
39
42
|
bodyChunks.push(chunk);
|
|
40
43
|
});
|
|
41
44
|
res.on('end', () => {
|
|
42
|
-
logger.verbose(
|
|
45
|
+
logger.verbose({
|
|
46
|
+
label: `NetworkDispatcher`,
|
|
47
|
+
message: `[END] Request: [${method}][${lang}] ${url}`,
|
|
48
|
+
});
|
|
43
49
|
if (!res.statusCode || (res.statusCode >= 200 && res.statusCode < 300)) {
|
|
44
50
|
const body = Buffer.concat(bodyChunks).toString();
|
|
45
51
|
try {
|
|
@@ -48,10 +54,17 @@ export default class NetworkDispatcher {
|
|
|
48
54
|
}
|
|
49
55
|
catch (err) {
|
|
50
56
|
if (logger.isDebugEnabled()) {
|
|
51
|
-
logger.warn(
|
|
57
|
+
logger.warn({
|
|
58
|
+
label: `NetworkDispatcher`,
|
|
59
|
+
message: `unexpected response body: [${method}][${lang}] ${url}: '${body}'`,
|
|
60
|
+
additionalInfo: err,
|
|
61
|
+
});
|
|
52
62
|
}
|
|
53
63
|
else {
|
|
54
|
-
logger.warn(
|
|
64
|
+
logger.warn({
|
|
65
|
+
label: `NetworkDispatcher`,
|
|
66
|
+
message: `unexpected response body: [${method}][${lang}] ${url}: '${body}'`,
|
|
67
|
+
});
|
|
55
68
|
}
|
|
56
69
|
resolve({});
|
|
57
70
|
}
|
|
@@ -59,7 +72,10 @@ export default class NetworkDispatcher {
|
|
|
59
72
|
else if (res.statusCode === 301 || res.statusCode === 302) {
|
|
60
73
|
// Lets follw if we know it is a module or bundle refrence
|
|
61
74
|
if (res.headers?.location && isModuleOrBundleUrl(res.headers?.location)) {
|
|
62
|
-
logger.debug(
|
|
75
|
+
logger.debug({
|
|
76
|
+
label: `NetworkDispatcher`,
|
|
77
|
+
message: `Follow redirect: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`,
|
|
78
|
+
});
|
|
63
79
|
const location = res.headers.location;
|
|
64
80
|
return (this.handleRequest(this.createRequestOptions(location, method, lang), location, method, lang)
|
|
65
81
|
// Send nested response to the resolve or reject functions defined above
|
|
@@ -68,23 +84,36 @@ export default class NetworkDispatcher {
|
|
|
68
84
|
.catch((rejectRedirect) => reject(rejectRedirect)));
|
|
69
85
|
}
|
|
70
86
|
else {
|
|
71
|
-
logger.warn(
|
|
87
|
+
logger.warn({
|
|
88
|
+
label: `NetworkDispatcher`,
|
|
89
|
+
message: `Redirect not followed: [${method}][${lang}][${res.statusCode}] ${url} -> ${res.headers.location}`,
|
|
90
|
+
});
|
|
72
91
|
resolve({});
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
// if any other status codes are returned, those needed to be added here
|
|
76
95
|
else {
|
|
77
|
-
logger.warn(
|
|
96
|
+
logger.warn({
|
|
97
|
+
label: `NetworkDispatcher`,
|
|
98
|
+
message: `Unexpected status code: [${method}][${lang}][${res.statusCode}] ${url}`,
|
|
99
|
+
});
|
|
78
100
|
resolve({});
|
|
79
101
|
}
|
|
80
102
|
});
|
|
81
103
|
});
|
|
82
104
|
req.on('error', (err) => {
|
|
83
105
|
if (logger.isDebugEnabled()) {
|
|
84
|
-
logger.warn(
|
|
106
|
+
logger.warn({
|
|
107
|
+
label: `NetworkDispatcher`,
|
|
108
|
+
message: `Request Failed: [${method}][${lang}] ${url}`,
|
|
109
|
+
additionalInfo: err,
|
|
110
|
+
});
|
|
85
111
|
}
|
|
86
112
|
else {
|
|
87
|
-
logger.warn(
|
|
113
|
+
logger.warn({
|
|
114
|
+
label: `NetworkDispatcher`,
|
|
115
|
+
message: `Request Failed: [${method}][${lang}] ${url}`,
|
|
116
|
+
});
|
|
88
117
|
}
|
|
89
118
|
resolve({});
|
|
90
119
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.
|
|
7
|
+
"version": "0.11.5",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -39,33 +39,33 @@
|
|
|
39
39
|
"build": "tsc -b"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@lwrjs/app-service": "0.11.
|
|
43
|
-
"@lwrjs/asset-registry": "0.11.
|
|
44
|
-
"@lwrjs/asset-transformer": "0.11.
|
|
45
|
-
"@lwrjs/base-view-provider": "0.11.
|
|
46
|
-
"@lwrjs/base-view-transformer": "0.11.
|
|
47
|
-
"@lwrjs/client-modules": "0.11.
|
|
48
|
-
"@lwrjs/config": "0.11.
|
|
49
|
-
"@lwrjs/diagnostics": "0.11.
|
|
50
|
-
"@lwrjs/esbuild": "0.11.
|
|
51
|
-
"@lwrjs/fs-asset-provider": "0.11.
|
|
52
|
-
"@lwrjs/fs-watch": "0.11.
|
|
53
|
-
"@lwrjs/html-view-provider": "0.11.
|
|
54
|
-
"@lwrjs/instrumentation": "0.11.
|
|
55
|
-
"@lwrjs/loader": "0.11.
|
|
56
|
-
"@lwrjs/lwc-module-provider": "0.11.
|
|
57
|
-
"@lwrjs/markdown-view-provider": "0.11.
|
|
58
|
-
"@lwrjs/module-bundler": "0.11.
|
|
59
|
-
"@lwrjs/module-registry": "0.11.
|
|
60
|
-
"@lwrjs/npm-module-provider": "0.11.
|
|
61
|
-
"@lwrjs/nunjucks-view-provider": "0.11.
|
|
62
|
-
"@lwrjs/o11y": "0.11.
|
|
63
|
-
"@lwrjs/resource-registry": "0.11.
|
|
64
|
-
"@lwrjs/router": "0.11.
|
|
65
|
-
"@lwrjs/server": "0.11.
|
|
66
|
-
"@lwrjs/shared-utils": "0.11.
|
|
67
|
-
"@lwrjs/static": "0.11.
|
|
68
|
-
"@lwrjs/view-registry": "0.11.
|
|
42
|
+
"@lwrjs/app-service": "0.11.5",
|
|
43
|
+
"@lwrjs/asset-registry": "0.11.5",
|
|
44
|
+
"@lwrjs/asset-transformer": "0.11.5",
|
|
45
|
+
"@lwrjs/base-view-provider": "0.11.5",
|
|
46
|
+
"@lwrjs/base-view-transformer": "0.11.5",
|
|
47
|
+
"@lwrjs/client-modules": "0.11.5",
|
|
48
|
+
"@lwrjs/config": "0.11.5",
|
|
49
|
+
"@lwrjs/diagnostics": "0.11.5",
|
|
50
|
+
"@lwrjs/esbuild": "0.11.5",
|
|
51
|
+
"@lwrjs/fs-asset-provider": "0.11.5",
|
|
52
|
+
"@lwrjs/fs-watch": "0.11.5",
|
|
53
|
+
"@lwrjs/html-view-provider": "0.11.5",
|
|
54
|
+
"@lwrjs/instrumentation": "0.11.5",
|
|
55
|
+
"@lwrjs/loader": "0.11.5",
|
|
56
|
+
"@lwrjs/lwc-module-provider": "0.11.5",
|
|
57
|
+
"@lwrjs/markdown-view-provider": "0.11.5",
|
|
58
|
+
"@lwrjs/module-bundler": "0.11.5",
|
|
59
|
+
"@lwrjs/module-registry": "0.11.5",
|
|
60
|
+
"@lwrjs/npm-module-provider": "0.11.5",
|
|
61
|
+
"@lwrjs/nunjucks-view-provider": "0.11.5",
|
|
62
|
+
"@lwrjs/o11y": "0.11.5",
|
|
63
|
+
"@lwrjs/resource-registry": "0.11.5",
|
|
64
|
+
"@lwrjs/router": "0.11.5",
|
|
65
|
+
"@lwrjs/server": "0.11.5",
|
|
66
|
+
"@lwrjs/shared-utils": "0.11.5",
|
|
67
|
+
"@lwrjs/static": "0.11.5",
|
|
68
|
+
"@lwrjs/view-registry": "0.11.5",
|
|
69
69
|
"chokidar": "^3.5.3",
|
|
70
70
|
"esbuild": "^0.9.7",
|
|
71
71
|
"fs-extra": "^11.1.1",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"ws": "^8.8.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@lwrjs/types": "0.11.
|
|
78
|
+
"@lwrjs/types": "0.11.5",
|
|
79
79
|
"@types/ws": "^8.5.3"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"volta": {
|
|
88
88
|
"extends": "../../../package.json"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "b1a54889dd55baed1bf61ceb497d251958415595"
|
|
91
91
|
}
|