@lwrjs/core 0.15.0-alpha.32 → 0.15.0-alpha.34
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/middleware/view-middleware.cjs +36 -9
- package/build/cjs/tools/static-generation.cjs +23 -4
- package/build/cjs/tools/utils/stream.cjs +2 -0
- package/build/es/middleware/view-middleware.js +50 -10
- package/build/es/tools/static-generation.d.ts +4 -0
- package/build/es/tools/static-generation.js +38 -4
- package/build/es/tools/utils/stream.d.ts +1 -1
- package/build/es/tools/utils/stream.js +2 -0
- package/package.json +31 -31
|
@@ -26,6 +26,8 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
viewMiddleware: () => viewMiddleware
|
|
28
28
|
});
|
|
29
|
+
var import_util = __toModule(require("util"));
|
|
30
|
+
var import_url = __toModule(require("url"));
|
|
29
31
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
32
|
var import_router = __toModule(require("@lwrjs/router"));
|
|
31
33
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
@@ -81,9 +83,13 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
81
83
|
basePath: runtimeParams.basePath,
|
|
82
84
|
locale: runtimeParams.locale
|
|
83
85
|
}
|
|
84
|
-
}, (span) => {
|
|
86
|
+
}, async (span) => {
|
|
85
87
|
traceId = span.traceId;
|
|
86
|
-
|
|
88
|
+
const res2 = await resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
89
|
+
span.setAttributes({
|
|
90
|
+
size: byteSize(res2.body)
|
|
91
|
+
});
|
|
92
|
+
return res2;
|
|
87
93
|
});
|
|
88
94
|
resolvedRoute = route;
|
|
89
95
|
} catch (err) {
|
|
@@ -155,7 +161,7 @@ function createConfigMiddleware(routes, context, viewHandler) {
|
|
|
155
161
|
const query = {};
|
|
156
162
|
if (url.indexOf("?") !== -1) {
|
|
157
163
|
requestPath = url.substring(0, url.indexOf("?"));
|
|
158
|
-
const searchParams = new URLSearchParams(url.substring(url.indexOf("?")));
|
|
164
|
+
const searchParams = new import_url.URLSearchParams(url.substring(url.indexOf("?")));
|
|
159
165
|
for (const [key, value] of searchParams.entries()) {
|
|
160
166
|
query[key] = value;
|
|
161
167
|
}
|
|
@@ -187,7 +193,6 @@ function createConfigMiddleware(routes, context, viewHandler) {
|
|
|
187
193
|
res.setHeader("cache-control", `public, max-age=${cacheTtl}`);
|
|
188
194
|
}
|
|
189
195
|
}
|
|
190
|
-
res.status(200);
|
|
191
196
|
res.type("application/javascript");
|
|
192
197
|
res.status(viewResponse.status || 200);
|
|
193
198
|
res.send(viewResponse.body);
|
|
@@ -232,16 +237,30 @@ function viewMiddleware(app, context) {
|
|
|
232
237
|
}
|
|
233
238
|
function addDefaultLocaleRedirects(defaultLocale, defaultLocalePaths, defaultRedirectParams, app) {
|
|
234
239
|
import_diagnostics.logger.debug({label: `view-middleware`, message: `Add default localized paths ${defaultLocalePaths}`});
|
|
235
|
-
app.get(defaultLocalePaths, (req, res) => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
240
|
+
app.get(defaultLocalePaths, (req, res, next) => {
|
|
241
|
+
if (!req.originalUrl?.startsWith(`/${defaultLocale}`)) {
|
|
242
|
+
import_diagnostics.logger.warn({
|
|
243
|
+
label: "view-middleware",
|
|
244
|
+
message: `Attempted to redirect to a URL that did not start with the default locale: /${defaultLocale} ${req.originalUrl}`
|
|
245
|
+
});
|
|
246
|
+
return next();
|
|
247
|
+
}
|
|
248
|
+
const [originalPath, queryString] = req.originalUrl.split("?");
|
|
249
|
+
let modifiedPath = originalPath.replace(`/${defaultLocale}`, "");
|
|
250
|
+
if (req.basePath) {
|
|
251
|
+
modifiedPath = `${req.basePath}${modifiedPath}`;
|
|
239
252
|
}
|
|
253
|
+
const queryParams = new import_url.URLSearchParams(queryString);
|
|
240
254
|
if (defaultRedirectParams) {
|
|
241
255
|
Object.entries(defaultRedirectParams).forEach(([key, value]) => {
|
|
242
|
-
|
|
256
|
+
if (queryParams.has(key) && queryParams.get(key) !== value) {
|
|
257
|
+
queryParams.set(key, value);
|
|
258
|
+
} else if (!queryParams.has(key)) {
|
|
259
|
+
queryParams.set(key, value);
|
|
260
|
+
}
|
|
243
261
|
});
|
|
244
262
|
}
|
|
263
|
+
modifiedPath = queryParams.toString() ? `${modifiedPath}?${queryParams.toString()}` : modifiedPath;
|
|
245
264
|
res.setHeader("Location", modifiedPath);
|
|
246
265
|
return res.sendStatus(301);
|
|
247
266
|
});
|
|
@@ -252,3 +271,11 @@ function addRedirectQueryParam(redirectUrl, depth) {
|
|
|
252
271
|
url.searchParams.set(import_shared_utils.REQUEST_DEPTH_KEY, String(depth + 1));
|
|
253
272
|
return url.toString().replace(fakeOrigin, "");
|
|
254
273
|
}
|
|
274
|
+
function byteSize(body) {
|
|
275
|
+
if (Buffer.isBuffer(body)) {
|
|
276
|
+
return body.length;
|
|
277
|
+
} else if (typeof body === "string") {
|
|
278
|
+
return new import_util.TextEncoder().encode(body).length;
|
|
279
|
+
}
|
|
280
|
+
return -1;
|
|
281
|
+
}
|
|
@@ -143,6 +143,7 @@ var SiteGenerator = class {
|
|
|
143
143
|
let context;
|
|
144
144
|
context = await dispatcher.dispatchUrl(url, "GET", siteConfig.locale);
|
|
145
145
|
if (context?.fs?.headers?.Location) {
|
|
146
|
+
this.saveServerBundles(siteConfig, context.fs.metadata?.viewDefinition?.viewRecord.serverBundles);
|
|
146
147
|
const redirectUrl = context?.fs?.headers?.Location;
|
|
147
148
|
url = redirectUrl;
|
|
148
149
|
const redirectContext = await dispatcher.dispatchUrl(url, "GET", siteConfig.locale);
|
|
@@ -204,7 +205,7 @@ var SiteGenerator = class {
|
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
if (moduleDefinition.bundleRecord) {
|
|
207
|
-
this.addBundleToSiteMetadata(moduleDefinition, url, siteConfig);
|
|
208
|
+
this.addBundleToSiteMetadata(moduleDefinition, url, false, siteConfig);
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
211
|
const uris = context.fs?.metadata?.resolvedUris || [];
|
|
@@ -229,10 +230,10 @@ var SiteGenerator = class {
|
|
|
229
230
|
siteBundles[specifier] = bundleMetadata;
|
|
230
231
|
}
|
|
231
232
|
}
|
|
232
|
-
addBundleToSiteMetadata(bundleDefinition, url, siteConfig) {
|
|
233
|
+
addBundleToSiteMetadata(bundleDefinition, url, ssr, siteConfig) {
|
|
233
234
|
if (siteConfig.siteMetadata) {
|
|
234
235
|
const locale = siteConfig.locale;
|
|
235
|
-
const specifier = (0, import_site_metadata.getSiteBundleId)(bundleDefinition, locale,
|
|
236
|
+
const specifier = (0, import_site_metadata.getSiteBundleId)(bundleDefinition, locale, ssr, siteConfig.i18n);
|
|
236
237
|
const imports = bundleDefinition.bundleRecord.imports?.map((moduleRef) => (0, import_site_metadata.getSiteBundleId)(moduleRef, locale, false, siteConfig.i18n)) || [];
|
|
237
238
|
const dynamicImports = bundleDefinition.bundleRecord.dynamicImports?.map((moduleRef) => (0, import_site_metadata.getSiteBundleId)(moduleRef, locale, false, siteConfig.i18n));
|
|
238
239
|
const includedModules = bundleDefinition.bundleRecord.includedModules?.map((moduleRef) => {
|
|
@@ -363,6 +364,7 @@ var SiteGenerator = class {
|
|
|
363
364
|
dispatchRequests.push(this.dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig));
|
|
364
365
|
}
|
|
365
366
|
}
|
|
367
|
+
this.saveServerBundles(siteConfig, viewDefinition.viewRecord.serverBundles);
|
|
366
368
|
const bootstrapResources = viewDefinition.viewRecord.bootstrapModule?.resources || [];
|
|
367
369
|
for (const resource of bootstrapResources) {
|
|
368
370
|
if (!resource.inline) {
|
|
@@ -549,7 +551,8 @@ var SiteGenerator = class {
|
|
|
549
551
|
const endpoints = {
|
|
550
552
|
uris: {
|
|
551
553
|
legacyDefault: (0, import_shared_utils.getModuleUriPrefix)(runtimeEnvironment, {locale}),
|
|
552
|
-
mapping: (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, {locale})
|
|
554
|
+
mapping: (0, import_shared_utils.getMappingUriPrefix)(runtimeEnvironment, {locale}),
|
|
555
|
+
server: (0, import_shared_utils.getModuleUriPrefix)({...runtimeEnvironment, bundle: true}, {locale}).replace("/bundle/", "/bundle-server/")
|
|
553
556
|
}
|
|
554
557
|
};
|
|
555
558
|
return {
|
|
@@ -615,6 +618,22 @@ ${mergeIndex}
|
|
|
615
618
|
this.addAdditionalImportMetadataToViewConfig(siteConfig);
|
|
616
619
|
await siteConfig.siteMetadata?.persistSiteMetadata();
|
|
617
620
|
}
|
|
621
|
+
async saveServerBundles(siteConfig, bundles) {
|
|
622
|
+
if (bundles?.size) {
|
|
623
|
+
const {endpoints, outputDir} = siteConfig;
|
|
624
|
+
bundles.forEach(async (bundle) => {
|
|
625
|
+
const {specifier, version} = bundle;
|
|
626
|
+
const vSpecifier = (0, import_shared_utils.getSpecifier)({
|
|
627
|
+
specifier,
|
|
628
|
+
version: version ? (0, import_shared_utils.normalizeVersionToUri)(version) : void 0
|
|
629
|
+
});
|
|
630
|
+
const url = `${endpoints?.uris.server}${vSpecifier}/s/${(0, import_shared_utils.signBundle)(bundle)}/bundle_${(0, import_shared_utils.prettyModuleUriSuffix)(specifier)}.js`;
|
|
631
|
+
this.addBundleToSiteMetadata(bundle, url, true, siteConfig);
|
|
632
|
+
(0, import_dir.createResourceDir)((0, import_path.dirname)(url), outputDir);
|
|
633
|
+
await (0, import_stream.writeResponse)({fs: {body: await bundle.getCode()}}, (0, import_path.join)(outputDir, url));
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
618
637
|
};
|
|
619
638
|
var static_generation_default = SiteGenerator;
|
|
620
639
|
var ViewImportMetadataImpl = class {
|
|
@@ -38,6 +38,8 @@ async function writeStream(readStream, fullPath) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
async function writeResponse(context, fullPath) {
|
|
41
|
+
if (import_fs.default.existsSync(fullPath))
|
|
42
|
+
return;
|
|
41
43
|
if (context.fs?.stream) {
|
|
42
44
|
const stream = context.fs?.stream;
|
|
43
45
|
await writeStream(stream, fullPath);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TextEncoder } from 'util';
|
|
2
|
+
import { URLSearchParams } from 'url';
|
|
1
3
|
import { descriptions, logger } from '@lwrjs/diagnostics';
|
|
2
4
|
import { getClientRoutes } from '@lwrjs/router';
|
|
3
5
|
import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, isURL, parseRequestDepth, REQUEST_DEPTH_KEY, shortestTtl, } from '@lwrjs/shared-utils';
|
|
@@ -55,9 +57,14 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
|
55
57
|
basePath: runtimeParams.basePath,
|
|
56
58
|
locale: runtimeParams.locale,
|
|
57
59
|
},
|
|
58
|
-
}, (span) => {
|
|
60
|
+
}, async (span) => {
|
|
59
61
|
traceId = span.traceId;
|
|
60
|
-
|
|
62
|
+
const res = await resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
63
|
+
// Add the view size metric
|
|
64
|
+
span.setAttributes({
|
|
65
|
+
size: byteSize(res.body),
|
|
66
|
+
});
|
|
67
|
+
return res;
|
|
61
68
|
});
|
|
62
69
|
resolvedRoute = route;
|
|
63
70
|
}
|
|
@@ -177,7 +184,6 @@ function createConfigMiddleware(routes, context, viewHandler) {
|
|
|
177
184
|
res.setHeader('cache-control', `public, max-age=${cacheTtl}`);
|
|
178
185
|
}
|
|
179
186
|
}
|
|
180
|
-
res.status(200);
|
|
181
187
|
res.type('application/javascript');
|
|
182
188
|
res.status(viewResponse.status || 200);
|
|
183
189
|
res.send(viewResponse.body);
|
|
@@ -236,18 +242,41 @@ export function viewMiddleware(app, context) {
|
|
|
236
242
|
*/
|
|
237
243
|
function addDefaultLocaleRedirects(defaultLocale, defaultLocalePaths, defaultRedirectParams, app) {
|
|
238
244
|
logger.debug({ label: `view-middleware`, message: `Add default localized paths ${defaultLocalePaths}` });
|
|
239
|
-
app.get(defaultLocalePaths, (req, res) => {
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
+
app.get(defaultLocalePaths, (req, res, next) => {
|
|
246
|
+
// This middleware should only have been called with paths that start with /{defaultLocale}.
|
|
247
|
+
// If somehow that is not the case log a warning and do not re-direct
|
|
248
|
+
if (!req.originalUrl?.startsWith(`/${defaultLocale}`)) {
|
|
249
|
+
logger.warn({
|
|
250
|
+
label: 'view-middleware',
|
|
251
|
+
message: `Attempted to redirect to a URL that did not start with the default locale: /${defaultLocale} ${req.originalUrl}`,
|
|
252
|
+
});
|
|
253
|
+
return next();
|
|
254
|
+
}
|
|
255
|
+
// Separate the path and query string from the original URL
|
|
256
|
+
const [originalPath, queryString] = req.originalUrl.split('?');
|
|
257
|
+
// Remove the default locale from the original path
|
|
258
|
+
let modifiedPath = originalPath.replace(`/${defaultLocale}`, '');
|
|
259
|
+
// Ensure modifiedPath starts with req.basePath if set
|
|
260
|
+
if (req.basePath) {
|
|
261
|
+
modifiedPath = `${req.basePath}${modifiedPath}`;
|
|
245
262
|
}
|
|
263
|
+
// Parse existing query parameters into an object
|
|
264
|
+
const queryParams = new URLSearchParams(queryString);
|
|
265
|
+
// Merge in defaultRedirectParams, replacing values if the key exists with a different value
|
|
246
266
|
if (defaultRedirectParams) {
|
|
247
267
|
Object.entries(defaultRedirectParams).forEach(([key, value]) => {
|
|
248
|
-
|
|
268
|
+
// If the key exists but has a different value, replace it
|
|
269
|
+
if (queryParams.has(key) && queryParams.get(key) !== value) {
|
|
270
|
+
queryParams.set(key, value);
|
|
271
|
+
}
|
|
272
|
+
else if (!queryParams.has(key)) {
|
|
273
|
+
// Add the parameter if it doesn't exist
|
|
274
|
+
queryParams.set(key, value);
|
|
275
|
+
}
|
|
249
276
|
});
|
|
250
277
|
}
|
|
278
|
+
// Rebuild the modified path, adding query params only if they exist
|
|
279
|
+
modifiedPath = queryParams.toString() ? `${modifiedPath}?${queryParams.toString()}` : modifiedPath;
|
|
251
280
|
// Perform a 301 redirect to the modified URL
|
|
252
281
|
res.setHeader('Location', modifiedPath);
|
|
253
282
|
return res.sendStatus(301);
|
|
@@ -261,4 +290,15 @@ function addRedirectQueryParam(redirectUrl, depth) {
|
|
|
261
290
|
url.searchParams.set(REQUEST_DEPTH_KEY, String(depth + 1));
|
|
262
291
|
return url.toString().replace(fakeOrigin, '');
|
|
263
292
|
}
|
|
293
|
+
// Get number of bytes from a string. Different char encodings can effect size per char.
|
|
294
|
+
function byteSize(body) {
|
|
295
|
+
if (Buffer.isBuffer(body)) {
|
|
296
|
+
return body.length;
|
|
297
|
+
}
|
|
298
|
+
else if (typeof body === 'string') {
|
|
299
|
+
return new TextEncoder().encode(body).length; // Get byte size of the string
|
|
300
|
+
}
|
|
301
|
+
// Return -1 if JSON or undefined
|
|
302
|
+
return -1;
|
|
303
|
+
}
|
|
264
304
|
//# sourceMappingURL=view-middleware.js.map
|
|
@@ -114,6 +114,10 @@ export default class SiteGenerator {
|
|
|
114
114
|
* Capture additional metadata collected during the processing of a route or additional module
|
|
115
115
|
*/
|
|
116
116
|
private captureAdditionalRouteMetadata;
|
|
117
|
+
/**
|
|
118
|
+
* Save the server bundles gathered during view generation to the file system and metadata
|
|
119
|
+
*/
|
|
120
|
+
private saveServerBundles;
|
|
117
121
|
}
|
|
118
122
|
export declare class ViewImportMetadataImpl implements ViewImportMetadata {
|
|
119
123
|
private existing;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { performance } from 'perf_hooks';
|
|
2
2
|
import { logger } from '@lwrjs/diagnostics';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
// createIntegrityHash,
|
|
5
|
+
getSpecifier, getFeatureFlags, hashContent, isSelfUrl, getModuleUriPrefix, getMappingUriPrefix, isExternalUrl, mimeLookup, getViewUri, sortLocalesByFallback, VERSION_NOT_PROVIDED, PROTOCOL_FILE, normalizeFromFileURL, isExternalSpecifier, explodeSpecifier, prettyModuleUriSuffix, normalizeVersionToUri, signBundle, } from '@lwrjs/shared-utils';
|
|
4
6
|
import { SiteMetadataImpl, getSiteBundleId, getSiteResourceId } from '@lwrjs/static/site-metadata';
|
|
5
7
|
import { join, dirname, extname, normalize } from 'path';
|
|
6
8
|
import fs from 'fs-extra';
|
|
@@ -166,6 +168,7 @@ export default class SiteGenerator {
|
|
|
166
168
|
context = await dispatcher.dispatchUrl(url, 'GET', siteConfig.locale);
|
|
167
169
|
// Handle 302 redirect if applicable
|
|
168
170
|
if (context?.fs?.headers?.Location) {
|
|
171
|
+
this.saveServerBundles(siteConfig, context.fs.metadata?.viewDefinition?.viewRecord.serverBundles);
|
|
169
172
|
const redirectUrl = context?.fs?.headers?.Location;
|
|
170
173
|
url = redirectUrl;
|
|
171
174
|
const redirectContext = await dispatcher.dispatchUrl(url, 'GET', siteConfig.locale);
|
|
@@ -211,6 +214,12 @@ export default class SiteGenerator {
|
|
|
211
214
|
createResourceDir(dirname(normalizedUrl), outputDir);
|
|
212
215
|
const ext = extname(normalizedUrl);
|
|
213
216
|
const fullPath = join(outputDir, `${normalizedUrl}${ext ? '' : '.js'}`);
|
|
217
|
+
// TEMP: Code to force client bundles to fail fast during SSR for manual testing
|
|
218
|
+
// if (context.fs?.body) {
|
|
219
|
+
// const body = `if (typeof window === 'undefined') throw new Error('This is a client bundle! ${specifier}');\n${context.fs.body}`;
|
|
220
|
+
// if (moduleDefinition) moduleDefinition.integrity = createIntegrityHash(body);
|
|
221
|
+
// context.fs.body = body;
|
|
222
|
+
// }
|
|
214
223
|
await writeResponse(context, fullPath);
|
|
215
224
|
// Build up a list of dispatch requests to kick off in parallel
|
|
216
225
|
const dispatchRequests = [];
|
|
@@ -266,7 +275,7 @@ export default class SiteGenerator {
|
|
|
266
275
|
}
|
|
267
276
|
// If this is a bundle add it to the bundle metadata
|
|
268
277
|
if (moduleDefinition.bundleRecord) {
|
|
269
|
-
this.addBundleToSiteMetadata(moduleDefinition, url, siteConfig);
|
|
278
|
+
this.addBundleToSiteMetadata(moduleDefinition, url, false, siteConfig);
|
|
270
279
|
}
|
|
271
280
|
}
|
|
272
281
|
// Bundles with unresolved module uris
|
|
@@ -296,10 +305,10 @@ export default class SiteGenerator {
|
|
|
296
305
|
siteBundles[specifier] = bundleMetadata;
|
|
297
306
|
}
|
|
298
307
|
}
|
|
299
|
-
addBundleToSiteMetadata(bundleDefinition, url, siteConfig) {
|
|
308
|
+
addBundleToSiteMetadata(bundleDefinition, url, ssr, siteConfig) {
|
|
300
309
|
if (siteConfig.siteMetadata) {
|
|
301
310
|
const locale = siteConfig.locale;
|
|
302
|
-
const specifier = getSiteBundleId(bundleDefinition, locale,
|
|
311
|
+
const specifier = getSiteBundleId(bundleDefinition, locale, ssr, siteConfig.i18n);
|
|
303
312
|
const imports = bundleDefinition.bundleRecord.imports?.map((moduleRef) => getSiteBundleId(moduleRef, locale, false, siteConfig.i18n)) || [];
|
|
304
313
|
const dynamicImports = bundleDefinition.bundleRecord.dynamicImports?.map((moduleRef) => getSiteBundleId(moduleRef, locale, false, siteConfig.i18n));
|
|
305
314
|
const includedModules = bundleDefinition.bundleRecord.includedModules?.map((moduleRef) => {
|
|
@@ -482,6 +491,8 @@ export default class SiteGenerator {
|
|
|
482
491
|
dispatchRequests.push(this.dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig));
|
|
483
492
|
}
|
|
484
493
|
}
|
|
494
|
+
// Server bundles
|
|
495
|
+
this.saveServerBundles(siteConfig, viewDefinition.viewRecord.serverBundles);
|
|
485
496
|
// Bootstrap Resources
|
|
486
497
|
const bootstrapResources = viewDefinition.viewRecord.bootstrapModule?.resources || [];
|
|
487
498
|
for (const resource of bootstrapResources) {
|
|
@@ -730,6 +741,7 @@ export default class SiteGenerator {
|
|
|
730
741
|
// legacy globalThis.LWR.importMappings.default
|
|
731
742
|
legacyDefault: getModuleUriPrefix(runtimeEnvironment, { locale }),
|
|
732
743
|
mapping: getMappingUriPrefix(runtimeEnvironment, { locale }),
|
|
744
|
+
server: getModuleUriPrefix({ ...runtimeEnvironment, bundle: true }, { locale }).replace('/bundle/', '/bundle-server/'),
|
|
733
745
|
},
|
|
734
746
|
};
|
|
735
747
|
return {
|
|
@@ -810,6 +822,28 @@ export default class SiteGenerator {
|
|
|
810
822
|
// Save site meta data
|
|
811
823
|
await siteConfig.siteMetadata?.persistSiteMetadata();
|
|
812
824
|
}
|
|
825
|
+
/**
|
|
826
|
+
* Save the server bundles gathered during view generation to the file system and metadata
|
|
827
|
+
*/
|
|
828
|
+
async saveServerBundles(siteConfig, bundles) {
|
|
829
|
+
if (bundles?.size) {
|
|
830
|
+
const { endpoints, outputDir } = siteConfig;
|
|
831
|
+
bundles.forEach(async (bundle) => {
|
|
832
|
+
const { specifier, version } = bundle;
|
|
833
|
+
const vSpecifier = getSpecifier({
|
|
834
|
+
specifier,
|
|
835
|
+
version: version ? normalizeVersionToUri(version) : undefined,
|
|
836
|
+
});
|
|
837
|
+
const url = `${endpoints?.uris.server}${vSpecifier}/s/${signBundle(bundle)}/bundle_${prettyModuleUriSuffix(specifier)}.js`;
|
|
838
|
+
this.addBundleToSiteMetadata(bundle, url, true, siteConfig);
|
|
839
|
+
createResourceDir(dirname(url), outputDir);
|
|
840
|
+
// TEMP: Code to force server bundles to fail fast on the client during manual testing
|
|
841
|
+
// const body = `if (typeof window !== 'undefined') throw new Error('This is a server bundle! ${specifier}');\n${await bundle.getCode()}`;
|
|
842
|
+
// await writeResponse({ fs: { body } }, join(outputDir, url));
|
|
843
|
+
await writeResponse({ fs: { body: await bundle.getCode() } }, join(outputDir, url));
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
}
|
|
813
847
|
}
|
|
814
848
|
// Class used to track import metadata for a view
|
|
815
849
|
export class ViewImportMetadataImpl {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { Readable } from 'stream';
|
|
3
3
|
import type { FsContext } from '@lwrjs/types';
|
|
4
4
|
export declare function writeStream(readStream: Readable, fullPath: string): Promise<void>;
|
|
5
|
-
export declare function writeResponse(context: FsContext, fullPath: string): Promise<void>;
|
|
5
|
+
export declare function writeResponse(context: Pick<FsContext, 'fs'>, fullPath: string): Promise<void>;
|
|
6
6
|
/**
|
|
7
7
|
* @param {*} o - Item to check if it's an object
|
|
8
8
|
* @returns {boolean}
|
|
@@ -8,6 +8,8 @@ export async function writeStream(readStream, fullPath) {
|
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
export async function writeResponse(context, fullPath) {
|
|
11
|
+
if (fs.existsSync(fullPath))
|
|
12
|
+
return;
|
|
11
13
|
if (context.fs?.stream) {
|
|
12
14
|
const stream = context.fs?.stream;
|
|
13
15
|
await writeStream(stream, fullPath);
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.15.0-alpha.
|
|
7
|
+
"version": "0.15.0-alpha.34",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -43,34 +43,34 @@
|
|
|
43
43
|
"build": "tsc -b"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@lwrjs/app-service": "0.15.0-alpha.
|
|
47
|
-
"@lwrjs/asset-registry": "0.15.0-alpha.
|
|
48
|
-
"@lwrjs/asset-transformer": "0.15.0-alpha.
|
|
49
|
-
"@lwrjs/base-view-provider": "0.15.0-alpha.
|
|
50
|
-
"@lwrjs/base-view-transformer": "0.15.0-alpha.
|
|
51
|
-
"@lwrjs/client-modules": "0.15.0-alpha.
|
|
52
|
-
"@lwrjs/config": "0.15.0-alpha.
|
|
53
|
-
"@lwrjs/diagnostics": "0.15.0-alpha.
|
|
54
|
-
"@lwrjs/esbuild": "0.15.0-alpha.
|
|
55
|
-
"@lwrjs/fs-asset-provider": "0.15.0-alpha.
|
|
56
|
-
"@lwrjs/fs-watch": "0.15.0-alpha.
|
|
57
|
-
"@lwrjs/html-view-provider": "0.15.0-alpha.
|
|
58
|
-
"@lwrjs/instrumentation": "0.15.0-alpha.
|
|
59
|
-
"@lwrjs/loader": "0.15.0-alpha.
|
|
60
|
-
"@lwrjs/lwc-module-provider": "0.15.0-alpha.
|
|
61
|
-
"@lwrjs/lwc-ssr": "0.15.0-alpha.
|
|
62
|
-
"@lwrjs/markdown-view-provider": "0.15.0-alpha.
|
|
63
|
-
"@lwrjs/module-bundler": "0.15.0-alpha.
|
|
64
|
-
"@lwrjs/module-registry": "0.15.0-alpha.
|
|
65
|
-
"@lwrjs/npm-module-provider": "0.15.0-alpha.
|
|
66
|
-
"@lwrjs/nunjucks-view-provider": "0.15.0-alpha.
|
|
67
|
-
"@lwrjs/o11y": "0.15.0-alpha.
|
|
68
|
-
"@lwrjs/resource-registry": "0.15.0-alpha.
|
|
69
|
-
"@lwrjs/router": "0.15.0-alpha.
|
|
70
|
-
"@lwrjs/server": "0.15.0-alpha.
|
|
71
|
-
"@lwrjs/shared-utils": "0.15.0-alpha.
|
|
72
|
-
"@lwrjs/static": "0.15.0-alpha.
|
|
73
|
-
"@lwrjs/view-registry": "0.15.0-alpha.
|
|
46
|
+
"@lwrjs/app-service": "0.15.0-alpha.34",
|
|
47
|
+
"@lwrjs/asset-registry": "0.15.0-alpha.34",
|
|
48
|
+
"@lwrjs/asset-transformer": "0.15.0-alpha.34",
|
|
49
|
+
"@lwrjs/base-view-provider": "0.15.0-alpha.34",
|
|
50
|
+
"@lwrjs/base-view-transformer": "0.15.0-alpha.34",
|
|
51
|
+
"@lwrjs/client-modules": "0.15.0-alpha.34",
|
|
52
|
+
"@lwrjs/config": "0.15.0-alpha.34",
|
|
53
|
+
"@lwrjs/diagnostics": "0.15.0-alpha.34",
|
|
54
|
+
"@lwrjs/esbuild": "0.15.0-alpha.34",
|
|
55
|
+
"@lwrjs/fs-asset-provider": "0.15.0-alpha.34",
|
|
56
|
+
"@lwrjs/fs-watch": "0.15.0-alpha.34",
|
|
57
|
+
"@lwrjs/html-view-provider": "0.15.0-alpha.34",
|
|
58
|
+
"@lwrjs/instrumentation": "0.15.0-alpha.34",
|
|
59
|
+
"@lwrjs/loader": "0.15.0-alpha.34",
|
|
60
|
+
"@lwrjs/lwc-module-provider": "0.15.0-alpha.34",
|
|
61
|
+
"@lwrjs/lwc-ssr": "0.15.0-alpha.34",
|
|
62
|
+
"@lwrjs/markdown-view-provider": "0.15.0-alpha.34",
|
|
63
|
+
"@lwrjs/module-bundler": "0.15.0-alpha.34",
|
|
64
|
+
"@lwrjs/module-registry": "0.15.0-alpha.34",
|
|
65
|
+
"@lwrjs/npm-module-provider": "0.15.0-alpha.34",
|
|
66
|
+
"@lwrjs/nunjucks-view-provider": "0.15.0-alpha.34",
|
|
67
|
+
"@lwrjs/o11y": "0.15.0-alpha.34",
|
|
68
|
+
"@lwrjs/resource-registry": "0.15.0-alpha.34",
|
|
69
|
+
"@lwrjs/router": "0.15.0-alpha.34",
|
|
70
|
+
"@lwrjs/server": "0.15.0-alpha.34",
|
|
71
|
+
"@lwrjs/shared-utils": "0.15.0-alpha.34",
|
|
72
|
+
"@lwrjs/static": "0.15.0-alpha.34",
|
|
73
|
+
"@lwrjs/view-registry": "0.15.0-alpha.34",
|
|
74
74
|
"chokidar": "^3.6.0",
|
|
75
75
|
"esbuild": "^0.9.7",
|
|
76
76
|
"fs-extra": "^11.2.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"ws": "^8.18.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@lwrjs/types": "0.15.0-alpha.
|
|
83
|
+
"@lwrjs/types": "0.15.0-alpha.34",
|
|
84
84
|
"@types/ws": "^8.5.12",
|
|
85
85
|
"memfs": "^4.13.0"
|
|
86
86
|
},
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"volta": {
|
|
94
94
|
"extends": "../../../package.json"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "6b9d8e0b50272e646d177e4bda3eec2b2a253fbb"
|
|
97
97
|
}
|