@lwrjs/core 0.6.0-alpha.9 → 0.6.2
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/context/hooks.cjs +10 -1
- package/build/cjs/env-config.cjs +29 -5
- package/build/cjs/index.cjs +18 -2
- package/build/cjs/middlewares/api-middleware.cjs +9 -17
- package/build/cjs/tools/static-generation.cjs +30 -13
- package/build/cjs/validation/app-config-context.cjs +1 -0
- package/build/es/context/hooks.js +13 -1
- package/build/es/env-config.js +36 -5
- package/build/es/index.d.ts +2 -1
- package/build/es/index.js +22 -2
- package/build/es/middlewares/api-middleware.js +14 -21
- package/build/es/tools/static-generation.js +51 -20
- package/build/es/tools/types.d.ts +1 -0
- package/build/es/validation/app-config-context.d.ts +1 -1
- package/build/es/validation/app-config-context.js +1 -0
- package/package.json +28 -28
|
@@ -39,7 +39,16 @@ async function runConfigurationsHook(hookPlugins, lwrConfig, dataConfig, runtime
|
|
|
39
39
|
for (const hookPlugin of hookPlugins) {
|
|
40
40
|
await hookPlugin.initConfigs(lwrConfig, dataConfig, runtimeConfig);
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
try {
|
|
43
|
+
(0, import_app_config.validateLwrAppConfig)(JSON.stringify(lwrConfig), "post");
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
|
|
46
|
+
console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
|
|
47
|
+
console.dir(e, {depth: null});
|
|
48
|
+
} else {
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
43
52
|
normalizeRoutesBootstrap(lwrConfig);
|
|
44
53
|
return {
|
|
45
54
|
lwrConfig,
|
package/build/cjs/env-config.cjs
CHANGED
|
@@ -36,6 +36,7 @@ var import_app_config = __toModule(require("./validation/app-config.cjs"));
|
|
|
36
36
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
37
37
|
var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
|
|
38
38
|
var MODE = process.env.MODE || "dev";
|
|
39
|
+
var DEFAULT_BASE_PATH = "";
|
|
39
40
|
var DEFAULT_API_VERSION = "1";
|
|
40
41
|
var LWR_VERSION = import_package.version;
|
|
41
42
|
var DEFAULT_SERVER_TYPE = "express";
|
|
@@ -80,11 +81,18 @@ var DEFAULT_LWR_MODULES = [
|
|
|
80
81
|
{npm: "@lwrjs/router"},
|
|
81
82
|
{npm: "@lwc/synthetic-shadow"}
|
|
82
83
|
];
|
|
83
|
-
var DEFAULT_BUNDLE_EXCLUSIONS = [
|
|
84
|
+
var DEFAULT_BUNDLE_EXCLUSIONS = [
|
|
85
|
+
"lwc",
|
|
86
|
+
"@lwc/synthetic-shadow",
|
|
87
|
+
"lwr/navigation",
|
|
88
|
+
"lwr/esmLoader",
|
|
89
|
+
"lwr/profiler"
|
|
90
|
+
];
|
|
84
91
|
var DEFAULT_LWR_CONFIG = {
|
|
85
92
|
port: PORT,
|
|
86
93
|
ignoreLwrConfigFile: false,
|
|
87
94
|
lwrConfigFile: DEFAULT_LWR_CONFIG_JSON,
|
|
95
|
+
basePath: DEFAULT_BASE_PATH,
|
|
88
96
|
rootDir: DEFAULT_ROOT_DIR,
|
|
89
97
|
cacheDir: DEFAULT_CACHE_FOLDER,
|
|
90
98
|
serverMode: MODE,
|
|
@@ -120,11 +128,18 @@ function createCacheFolder(cache, rootDir) {
|
|
|
120
128
|
function getLwrConfigFromFile(rootDir, customDir = DEFAULT_LWR_CONFIG_JSON) {
|
|
121
129
|
const lwrConfigPath = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(customDir, rootDir));
|
|
122
130
|
if (import_fs.default.existsSync(lwrConfigPath)) {
|
|
131
|
+
const configAsString = (0, import_shared_utils.readFile)(lwrConfigPath);
|
|
123
132
|
try {
|
|
124
|
-
return (0, import_app_config.validateLwrAppConfig)(
|
|
133
|
+
return (0, import_app_config.validateLwrAppConfig)(configAsString, "file");
|
|
125
134
|
} catch (e) {
|
|
126
135
|
if (e instanceof import_diagnostics.LwrConfigValidationError) {
|
|
127
|
-
|
|
136
|
+
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
|
|
137
|
+
console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
|
|
138
|
+
console.dir(e, {depth: null});
|
|
139
|
+
return JSON.parse(configAsString);
|
|
140
|
+
} else {
|
|
141
|
+
throw e;
|
|
142
|
+
}
|
|
128
143
|
}
|
|
129
144
|
return void 0;
|
|
130
145
|
}
|
|
@@ -217,7 +232,7 @@ function mergeLWCConfigs(config1, config2) {
|
|
|
217
232
|
};
|
|
218
233
|
}
|
|
219
234
|
function mergeBundleConfig(jsonConfig, config) {
|
|
220
|
-
const defaultExclusions = DEFAULT_BUNDLE_EXCLUSIONS;
|
|
235
|
+
const defaultExclusions = config?.bundleConfig?.UNSAFE_lwrDefaultExclude || jsonConfig?.bundleConfig?.UNSAFE_lwrDefaultExclude || DEFAULT_BUNDLE_EXCLUSIONS;
|
|
221
236
|
const configExclusions = config?.bundleConfig?.exclude || jsonConfig?.bundleConfig?.exclude || [];
|
|
222
237
|
return {
|
|
223
238
|
...jsonConfig?.bundleConfig,
|
|
@@ -259,7 +274,16 @@ function trimLwrConfig(config) {
|
|
|
259
274
|
function normalizeConfig(config) {
|
|
260
275
|
if (config !== void 0) {
|
|
261
276
|
config = trimLwrConfig(config);
|
|
262
|
-
|
|
277
|
+
try {
|
|
278
|
+
(0, import_app_config.validateLwrAppConfig)(JSON.stringify(config), "pre");
|
|
279
|
+
} catch (e) {
|
|
280
|
+
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
|
|
281
|
+
console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
|
|
282
|
+
console.dir(e, {depth: null});
|
|
283
|
+
} else {
|
|
284
|
+
throw e;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
263
287
|
}
|
|
264
288
|
const rootDir = import_path.default.resolve(config?.rootDir || DEFAULT_ROOT_DIR);
|
|
265
289
|
const lwrJsonConfig = config?.ignoreLwrConfigFile === true ? void 0 : getLwrConfigFromFile(rootDir, config?.lwrConfigFile);
|
package/build/cjs/index.cjs
CHANGED
|
@@ -66,11 +66,12 @@ function initMiddlewares(app, server, serverContext) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
async function initContext(app, server, rawLwrConfig) {
|
|
69
|
-
const {apiVersion, lwrVersion, serverMode, globalDataDir, globalData} = rawLwrConfig;
|
|
69
|
+
const {apiVersion, basePath, lwrVersion, serverMode, globalDataDir, globalData} = rawLwrConfig;
|
|
70
70
|
const rawDataConfig = (0, import_global_data.getGlobalData)(globalDataDir, globalData);
|
|
71
71
|
const rawRuntimeEnvConfig = {
|
|
72
72
|
...(0, import_env_config.explodeMode)(serverMode),
|
|
73
73
|
apiVersion,
|
|
74
|
+
basePath,
|
|
74
75
|
lwrVersion,
|
|
75
76
|
debug: false,
|
|
76
77
|
serverMode,
|
|
@@ -159,6 +160,7 @@ async function initContext(app, server, rawLwrConfig) {
|
|
|
159
160
|
routes,
|
|
160
161
|
errorRoutes,
|
|
161
162
|
rootDir,
|
|
163
|
+
basePath,
|
|
162
164
|
contentDir,
|
|
163
165
|
layoutsDir,
|
|
164
166
|
locker,
|
|
@@ -185,7 +187,8 @@ var LwrApp = class {
|
|
|
185
187
|
constructor(config) {
|
|
186
188
|
this.initialized = false;
|
|
187
189
|
this.config = (0, import_env_config.normalizeConfig)(config);
|
|
188
|
-
|
|
190
|
+
const {basePath} = this.config;
|
|
191
|
+
this.app = (0, import_server.createInternalServer)(this.config.serverType, {basePath});
|
|
189
192
|
this.server = this.app.createHttpServer();
|
|
190
193
|
}
|
|
191
194
|
setConfig(config) {
|
|
@@ -229,6 +232,15 @@ var LwrApp = class {
|
|
|
229
232
|
getInternalServer() {
|
|
230
233
|
return this.app.getImpl();
|
|
231
234
|
}
|
|
235
|
+
getServer() {
|
|
236
|
+
return {
|
|
237
|
+
use: this.app.use.bind(this.app),
|
|
238
|
+
all: this.app.all.bind(this.app),
|
|
239
|
+
get: this.app.get.bind(this.app),
|
|
240
|
+
post: this.app.post.bind(this.app),
|
|
241
|
+
getRegexWildcard: this.app.getRegexWildcard.bind(this.app)
|
|
242
|
+
};
|
|
243
|
+
}
|
|
232
244
|
};
|
|
233
245
|
function createServer(config) {
|
|
234
246
|
return new LwrApp(config);
|
|
@@ -236,6 +248,10 @@ function createServer(config) {
|
|
|
236
248
|
async function generateStaticSite(config) {
|
|
237
249
|
config = config || {};
|
|
238
250
|
config.serverType = "fs";
|
|
251
|
+
const {serverMode} = config;
|
|
252
|
+
if (serverMode === "dev" || serverMode === "compat") {
|
|
253
|
+
console.warn("[WARN] static generation in `dev` or `compat` mode is currently not fully supported");
|
|
254
|
+
}
|
|
239
255
|
const lwrApp = createServer(config);
|
|
240
256
|
overrideConfigAsSrc(lwrApp);
|
|
241
257
|
await lwrApp.init();
|
|
@@ -127,17 +127,12 @@ function apiMiddleware(app, context) {
|
|
|
127
127
|
const {entry} = await moduleRegistry.getModuleEntry(importerModuleId);
|
|
128
128
|
moduleId = {...moduleId, importer: entry};
|
|
129
129
|
}
|
|
130
|
-
const {format, compat, locale, apiVersion} = req.params;
|
|
131
130
|
const {ownHash, moduleEntry} = await moduleRegistry.getModule(moduleId, ctx.runtimeParams);
|
|
132
131
|
if (ownHash) {
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
specifier: moduleEntry.specifier,
|
|
136
|
-
version: (0, import_shared_utils.normalizeVersionToUri)(moduleEntry.version)
|
|
137
|
-
}));
|
|
138
|
-
const jsonQuery = req.isJsonRequest() ? "?json" : "";
|
|
132
|
+
const jsonQuery = req.isJsonRequest() ? `${ctx.runtimeEnvironment.debug ? "&" : "?"}json` : "";
|
|
133
|
+
const uri = await moduleRegistry.resolveModuleUri({...moduleId, version: moduleEntry.version}, ctx.runtimeEnvironment, ctx.runtimeParams, ownHash);
|
|
139
134
|
res.set({
|
|
140
|
-
Location:
|
|
135
|
+
Location: `${uri}${jsonQuery}`
|
|
141
136
|
});
|
|
142
137
|
res.sendStatus(302);
|
|
143
138
|
}
|
|
@@ -241,17 +236,12 @@ function apiMiddleware(app, context) {
|
|
|
241
236
|
const {entry} = await moduleRegistry.getModuleEntry(importerModuleId);
|
|
242
237
|
moduleId = {...moduleId, importer: entry};
|
|
243
238
|
}
|
|
244
|
-
const {format, compat, locale, apiVersion} = req.params;
|
|
245
239
|
const {ownHash, moduleEntry} = await moduleRegistry.getModule(moduleId, ctx.runtimeParams);
|
|
246
240
|
if (ownHash) {
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
specifier: moduleEntry.specifier,
|
|
250
|
-
version: (0, import_shared_utils.normalizeVersionToUri)(moduleEntry.version)
|
|
251
|
-
}));
|
|
252
|
-
const jsonQuery = req.isJsonRequest() ? "?json" : "";
|
|
241
|
+
const jsonQuery = req.isJsonRequest() ? `${ctx.runtimeEnvironment.debug ? "&" : "?"}json` : "";
|
|
242
|
+
const uri = await moduleRegistry.resolveModuleUri({...moduleId, version: moduleEntry.version}, ctx.runtimeEnvironment, ctx.runtimeParams, ownHash);
|
|
253
243
|
res.set({
|
|
254
|
-
Location:
|
|
244
|
+
Location: `${uri}${jsonQuery}`
|
|
255
245
|
});
|
|
256
246
|
res.sendStatus(302);
|
|
257
247
|
}
|
|
@@ -342,11 +332,13 @@ function apiMiddleware(app, context) {
|
|
|
342
332
|
});
|
|
343
333
|
app.all("/:apiVersion/:assetType/:immutable?/s/:signature/" + app.getRegexWildcard(), async (req, res) => {
|
|
344
334
|
const {runtimeEnvironment} = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
335
|
+
const {basePath} = runtimeEnvironment;
|
|
345
336
|
const {signature} = req.params;
|
|
346
337
|
const {immutable, assetType: type} = req.params;
|
|
347
338
|
const specifier = req.params[0] ? `/${req.params[0]}` : req.originalUrl;
|
|
339
|
+
const basePathSpecifier = `${basePath}${specifier}`;
|
|
348
340
|
try {
|
|
349
|
-
const assetObj = await context.assetRegistry.getAsset({specifier, signature, type}, runtimeEnvironment);
|
|
341
|
+
const assetObj = await context.assetRegistry.getAsset({specifier: basePathSpecifier, signature, type}, runtimeEnvironment);
|
|
350
342
|
if (immutable) {
|
|
351
343
|
}
|
|
352
344
|
if (assetObj.mime) {
|
|
@@ -27,6 +27,7 @@ __export(exports, {
|
|
|
27
27
|
ViewImportMetadataImpl: () => ViewImportMetadataImpl,
|
|
28
28
|
default: () => static_generation_default
|
|
29
29
|
});
|
|
30
|
+
var import_perf_hooks = __toModule(require("perf_hooks"));
|
|
30
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
32
|
var import_path = __toModule(require("path"));
|
|
32
33
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
@@ -34,6 +35,7 @@ var import_stream = __toModule(require("./utils/stream.cjs"));
|
|
|
34
35
|
var import_dir = __toModule(require("./utils/dir.cjs"));
|
|
35
36
|
var SiteGenerator = class {
|
|
36
37
|
async buildStaticApplication(config, dispatcher) {
|
|
38
|
+
const startTime = import_perf_hooks.performance.now();
|
|
37
39
|
console.log("[Static Generation] starting");
|
|
38
40
|
const {routes, staticSiteGenerator, rootDir, assets} = config;
|
|
39
41
|
if (!staticSiteGenerator.outputDir) {
|
|
@@ -46,27 +48,27 @@ var SiteGenerator = class {
|
|
|
46
48
|
await this.generateRoutes(staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap);
|
|
47
49
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
48
50
|
this.copyAssets(assets, outputDir);
|
|
49
|
-
|
|
51
|
+
const endTime = import_perf_hooks.performance.now();
|
|
52
|
+
const timeDiff = (endTime - startTime) / 1e3;
|
|
53
|
+
console.log(`[Static Generation] complete in ${Math.round(timeDiff)} seconds`);
|
|
50
54
|
}
|
|
51
55
|
async generateRoutes(staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap = new Map()) {
|
|
52
56
|
if (!staticSiteGenerator.locales) {
|
|
53
57
|
staticSiteGenerator.locales = ["en-US"];
|
|
54
58
|
}
|
|
55
|
-
const dispatchRequests = [];
|
|
56
59
|
const generateUrl = this.createGenerateURLFunction(dispatcher);
|
|
57
60
|
for (const locale of staticSiteGenerator.locales) {
|
|
58
61
|
for (const route of routes) {
|
|
59
62
|
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
60
|
-
|
|
63
|
+
await generateUrl(route.path, siteConfig);
|
|
61
64
|
}
|
|
62
65
|
if (staticSiteGenerator._additionalRoutePaths) {
|
|
63
66
|
for (const uri of staticSiteGenerator._additionalRoutePaths) {
|
|
64
67
|
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
65
|
-
|
|
68
|
+
await generateUrl(uri, siteConfig);
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
|
-
await Promise.all(dispatchRequests);
|
|
70
72
|
}
|
|
71
73
|
createGenerateURLFunction(dispatcher) {
|
|
72
74
|
const generateRoute = async (uri, siteConfig) => {
|
|
@@ -108,20 +110,21 @@ var SiteGenerator = class {
|
|
|
108
110
|
await (0, import_stream.writeResponse)(context, fullPath);
|
|
109
111
|
const dispatchRequests = [];
|
|
110
112
|
if (normalizedUrl.indexOf("/s/") !== -1) {
|
|
111
|
-
|
|
112
|
-
siteConfig.urlRewriteMap.set(rewriteUrl, normalizedUrl);
|
|
113
|
+
siteConfig.urlRewriteMap.set(normalizedUrl.substring(0, normalizedUrl.indexOf("/s/")), normalizedUrl);
|
|
113
114
|
siteConfig.urlRewriteMap.set(url.substring(0, url.indexOf("/s/")), normalizedUrl);
|
|
115
|
+
siteConfig.urlRewriteMap.set(normalizedUrl.substring(0, normalizedUrl.indexOf("/v/")), normalizedUrl);
|
|
116
|
+
siteConfig.urlRewriteMap.set(url.substring(0, url.indexOf("%2Fv%2F")), normalizedUrl);
|
|
114
117
|
}
|
|
115
118
|
const moduleDefinition = context.fs?.metadata?.moduleDefinition;
|
|
116
119
|
if (moduleDefinition) {
|
|
117
120
|
const imports = moduleDefinition.linkedModuleRecord?.imports || moduleDefinition.bundleRecord?.imports || [];
|
|
118
121
|
for (const importModule of imports) {
|
|
119
|
-
const jsUri = (0, import_shared_utils.getSpecifier)(importModule);
|
|
122
|
+
const jsUri = importModule.specifier.startsWith("/") ? importModule.specifier : (0, import_shared_utils.getSpecifier)(importModule);
|
|
120
123
|
dispatchRequests.push(this.dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig));
|
|
121
124
|
}
|
|
122
125
|
const dynamicImports = moduleDefinition.linkedModuleRecord?.dynamicImports || moduleDefinition.bundleRecord?.dynamicImports || [];
|
|
123
126
|
for (const importModule of dynamicImports) {
|
|
124
|
-
const jsUri = (0, import_shared_utils.getSpecifier)(importModule);
|
|
127
|
+
const jsUri = importModule.specifier.startsWith("/") ? importModule.specifier : (0, import_shared_utils.getSpecifier)(importModule);
|
|
125
128
|
dispatchRequests.push(this.dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig));
|
|
126
129
|
}
|
|
127
130
|
}
|
|
@@ -158,9 +161,11 @@ var SiteGenerator = class {
|
|
|
158
161
|
const filePath = (0, import_path.join)(dir, "index.html");
|
|
159
162
|
const fileLocalePath = (0, import_path.join)(localeDir, "index.html");
|
|
160
163
|
if (siteConfig.locale.toLowerCase().startsWith("en")) {
|
|
164
|
+
siteConfig.viewPaths.add(filePath);
|
|
161
165
|
await (0, import_stream.writeResponse)(context, filePath);
|
|
162
166
|
}
|
|
163
167
|
(0, import_dir.createDir)(localeDir);
|
|
168
|
+
siteConfig.viewPaths.add(fileLocalePath);
|
|
164
169
|
await (0, import_stream.writeResponse)(context, fileLocalePath);
|
|
165
170
|
const viewDefinition = context.fs?.metadata?.viewDefinition;
|
|
166
171
|
if (viewDefinition) {
|
|
@@ -232,8 +237,6 @@ var SiteGenerator = class {
|
|
|
232
237
|
} else {
|
|
233
238
|
console.warn('[WARN] Unable to fetch mapping for bare specifier or variable dynamic import: "' + jsUri + '"');
|
|
234
239
|
}
|
|
235
|
-
} else {
|
|
236
|
-
console.warn('[WARN] Unable to resolve bare specifier or variable dynamic import: "' + jsUri + '"');
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
}
|
|
@@ -285,6 +288,7 @@ var SiteGenerator = class {
|
|
|
285
288
|
const experimentalFeatures = this.filterExperimentalFeatures();
|
|
286
289
|
return {
|
|
287
290
|
outputDir,
|
|
291
|
+
viewPaths: new Set(),
|
|
288
292
|
visitedUrls: new Set(),
|
|
289
293
|
locale,
|
|
290
294
|
urlRewriteMap,
|
|
@@ -308,13 +312,26 @@ var SiteGenerator = class {
|
|
|
308
312
|
const index = additionalImportMetadata.index ? JSON.stringify(additionalImportMetadata.index) : "{}";
|
|
309
313
|
const initIndex = `if (!globalThis.LWR.index) { globalThis.LWR.index = {}; }`;
|
|
310
314
|
const mergeIndex = `Object.assign(globalThis.LWR.index, ${index})`;
|
|
311
|
-
import_fs_extra.default.
|
|
315
|
+
const oldConfig = import_fs_extra.default.readFileSync(siteConfig.viewConfigPath, "utf-8");
|
|
316
|
+
const newConfig = `${oldConfig}
|
|
312
317
|
// Appended by Static Site Generator
|
|
313
318
|
${initImports}
|
|
314
319
|
${mergeImports}
|
|
315
320
|
${initIndex}
|
|
316
321
|
${mergeIndex}
|
|
317
|
-
|
|
322
|
+
`;
|
|
323
|
+
const configHash = (0, import_shared_utils.hashContent)(newConfig);
|
|
324
|
+
const sigRegex = /\/s\/[a-z0-9]+\/config\.js/i;
|
|
325
|
+
const configSuffix = `/s/${configHash}/config.js`;
|
|
326
|
+
const newConfigPath = siteConfig.viewConfigPath.replace(sigRegex, configSuffix);
|
|
327
|
+
import_fs_extra.default.mkdirSync((0, import_path.dirname)(newConfigPath), {recursive: true});
|
|
328
|
+
import_fs_extra.default.writeFileSync(newConfigPath, newConfig, "utf-8");
|
|
329
|
+
import_fs_extra.default.rmSync(siteConfig.viewConfigPath);
|
|
330
|
+
siteConfig.viewPaths.forEach((path) => {
|
|
331
|
+
const oldDoc = import_fs_extra.default.readFileSync(path, "utf-8");
|
|
332
|
+
const newDoc = oldDoc.toString().replace(sigRegex, configSuffix);
|
|
333
|
+
import_fs_extra.default.writeFileSync(path, newDoc, "utf-8");
|
|
334
|
+
});
|
|
318
335
|
}
|
|
319
336
|
}
|
|
320
337
|
};
|
|
@@ -13,7 +13,19 @@ export async function runConfigurationsHook(hookPlugins, lwrConfig, dataConfig,
|
|
|
13
13
|
// eslint-disable-next-line no-await-in-loop
|
|
14
14
|
await hookPlugin.initConfigs(lwrConfig, dataConfig, runtimeConfig);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
try {
|
|
17
|
+
validateLwrAppConfig(JSON.stringify(lwrConfig), 'post');
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
// TODO: temporary workaround for https://github.com/salesforce/lwr/issues/825
|
|
21
|
+
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
|
|
22
|
+
console.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
|
|
23
|
+
console.dir(e, { depth: null });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
17
29
|
normalizeRoutesBootstrap(lwrConfig);
|
|
18
30
|
return {
|
|
19
31
|
lwrConfig,
|
package/build/es/env-config.js
CHANGED
|
@@ -7,6 +7,7 @@ import { validateLwrAppConfig } from './validation/app-config.js';
|
|
|
7
7
|
import { LwrConfigValidationError } from '@lwrjs/diagnostics';
|
|
8
8
|
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
9
9
|
const MODE = process.env.MODE || 'dev';
|
|
10
|
+
const DEFAULT_BASE_PATH = '';
|
|
10
11
|
const DEFAULT_API_VERSION = '1';
|
|
11
12
|
const LWR_VERSION = version;
|
|
12
13
|
const DEFAULT_SERVER_TYPE = 'express';
|
|
@@ -54,12 +55,19 @@ const DEFAULT_LWR_MODULES = [
|
|
|
54
55
|
{ npm: '@lwrjs/router' },
|
|
55
56
|
{ npm: '@lwc/synthetic-shadow' },
|
|
56
57
|
];
|
|
57
|
-
const DEFAULT_BUNDLE_EXCLUSIONS = [
|
|
58
|
+
const DEFAULT_BUNDLE_EXCLUSIONS = [
|
|
59
|
+
'lwc',
|
|
60
|
+
'@lwc/synthetic-shadow',
|
|
61
|
+
'lwr/navigation',
|
|
62
|
+
'lwr/esmLoader',
|
|
63
|
+
'lwr/profiler',
|
|
64
|
+
];
|
|
58
65
|
// Default config objects
|
|
59
66
|
const DEFAULT_LWR_CONFIG = {
|
|
60
67
|
port: PORT,
|
|
61
68
|
ignoreLwrConfigFile: false,
|
|
62
69
|
lwrConfigFile: DEFAULT_LWR_CONFIG_JSON,
|
|
70
|
+
basePath: DEFAULT_BASE_PATH,
|
|
63
71
|
rootDir: DEFAULT_ROOT_DIR,
|
|
64
72
|
cacheDir: DEFAULT_CACHE_FOLDER,
|
|
65
73
|
serverMode: MODE,
|
|
@@ -95,12 +103,21 @@ function createCacheFolder(cache, rootDir) {
|
|
|
95
103
|
function getLwrConfigFromFile(rootDir, customDir = DEFAULT_LWR_CONFIG_JSON) {
|
|
96
104
|
const lwrConfigPath = path.resolve(normalizeDirectory(customDir, rootDir));
|
|
97
105
|
if (fs.existsSync(lwrConfigPath)) {
|
|
106
|
+
const configAsString = readFile(lwrConfigPath);
|
|
98
107
|
try {
|
|
99
|
-
return validateLwrAppConfig(
|
|
108
|
+
return validateLwrAppConfig(configAsString, 'file');
|
|
100
109
|
}
|
|
101
110
|
catch (e) {
|
|
102
111
|
if (e instanceof LwrConfigValidationError) {
|
|
103
|
-
|
|
112
|
+
// TODO: temporary workaround for https://github.com/salesforce/lwr/issues/825
|
|
113
|
+
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
|
|
114
|
+
console.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
|
|
115
|
+
console.dir(e, { depth: null });
|
|
116
|
+
return JSON.parse(configAsString);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
104
121
|
}
|
|
105
122
|
return undefined;
|
|
106
123
|
}
|
|
@@ -202,7 +219,9 @@ function mergeLWCConfigs(config1, config2) {
|
|
|
202
219
|
}
|
|
203
220
|
// merge default bundle exclusions with any bundle exclusions specified in config
|
|
204
221
|
function mergeBundleConfig(jsonConfig, config) {
|
|
205
|
-
const defaultExclusions =
|
|
222
|
+
const defaultExclusions = config?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
|
|
223
|
+
jsonConfig?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
|
|
224
|
+
DEFAULT_BUNDLE_EXCLUSIONS;
|
|
206
225
|
const configExclusions = config?.bundleConfig?.exclude || jsonConfig?.bundleConfig?.exclude || [];
|
|
207
226
|
return {
|
|
208
227
|
...jsonConfig?.bundleConfig,
|
|
@@ -260,7 +279,19 @@ function trimLwrConfig(config) {
|
|
|
260
279
|
export function normalizeConfig(config) {
|
|
261
280
|
if (config !== undefined) {
|
|
262
281
|
config = trimLwrConfig(config);
|
|
263
|
-
|
|
282
|
+
try {
|
|
283
|
+
validateLwrAppConfig(JSON.stringify(config), 'pre');
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
// TODO: temporary workaround for https://github.com/salesforce/lwr/issues/825
|
|
287
|
+
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
|
|
288
|
+
console.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
|
|
289
|
+
console.dir(e, { depth: null });
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
throw e;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
264
295
|
}
|
|
265
296
|
// Merge all configurations together, and return
|
|
266
297
|
const rootDir = path.resolve(config?.rootDir || DEFAULT_ROOT_DIR);
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LwrGlobalConfig, NormalizedLwrGlobalConfig, ServerTypeImpl, ServerTypes } from '@lwrjs/types';
|
|
1
|
+
import { LwrGlobalConfig, NormalizedLwrGlobalConfig, ServerTypeImpl, PublicAppServer, ServerTypes } from '@lwrjs/types';
|
|
2
2
|
export declare class LwrApp {
|
|
3
3
|
private app;
|
|
4
4
|
private server;
|
|
@@ -14,6 +14,7 @@ export declare class LwrApp {
|
|
|
14
14
|
}) => void) | undefined): Promise<void>;
|
|
15
15
|
close(): Promise<void>;
|
|
16
16
|
getInternalServer<S extends ServerTypes>(): ServerTypeImpl<S>;
|
|
17
|
+
getServer(): PublicAppServer<ServerTypes>;
|
|
17
18
|
}
|
|
18
19
|
export declare function createServer(config?: LwrGlobalConfig): LwrApp;
|
|
19
20
|
export declare function generateStaticSite(config?: LwrGlobalConfig): Promise<void>;
|
package/build/es/index.js
CHANGED
|
@@ -41,11 +41,12 @@ function initMiddlewares(app, server, serverContext) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
async function initContext(app, server, rawLwrConfig) {
|
|
44
|
-
const { apiVersion, lwrVersion, serverMode, globalDataDir, globalData } = rawLwrConfig;
|
|
44
|
+
const { apiVersion, basePath, lwrVersion, serverMode, globalDataDir, globalData } = rawLwrConfig;
|
|
45
45
|
const rawDataConfig = getGlobalData(globalDataDir, globalData);
|
|
46
46
|
const rawRuntimeEnvConfig = {
|
|
47
47
|
...explodeMode(serverMode),
|
|
48
48
|
apiVersion,
|
|
49
|
+
basePath,
|
|
49
50
|
lwrVersion,
|
|
50
51
|
debug: false,
|
|
51
52
|
serverMode,
|
|
@@ -119,6 +120,7 @@ async function initContext(app, server, rawLwrConfig) {
|
|
|
119
120
|
routes,
|
|
120
121
|
errorRoutes,
|
|
121
122
|
rootDir,
|
|
123
|
+
basePath,
|
|
122
124
|
contentDir,
|
|
123
125
|
layoutsDir,
|
|
124
126
|
locker,
|
|
@@ -150,7 +152,8 @@ export class LwrApp {
|
|
|
150
152
|
constructor(config) {
|
|
151
153
|
this.initialized = false;
|
|
152
154
|
this.config = normalizeConfig(config);
|
|
153
|
-
|
|
155
|
+
const { basePath } = this.config;
|
|
156
|
+
this.app = createInternalServer(this.config.serverType, { basePath });
|
|
154
157
|
this.server = this.app.createHttpServer();
|
|
155
158
|
}
|
|
156
159
|
setConfig(config) {
|
|
@@ -193,9 +196,20 @@ export class LwrApp {
|
|
|
193
196
|
async close() {
|
|
194
197
|
this.server?.close && (await this.server.close());
|
|
195
198
|
}
|
|
199
|
+
// Get the underlying server (e.g. express, koa...)
|
|
196
200
|
getInternalServer() {
|
|
197
201
|
return this.app.getImpl();
|
|
198
202
|
}
|
|
203
|
+
// Return the public server interface which is compatible with all server types
|
|
204
|
+
getServer() {
|
|
205
|
+
return {
|
|
206
|
+
use: this.app.use.bind(this.app),
|
|
207
|
+
all: this.app.all.bind(this.app),
|
|
208
|
+
get: this.app.get.bind(this.app),
|
|
209
|
+
post: this.app.post.bind(this.app),
|
|
210
|
+
getRegexWildcard: this.app.getRegexWildcard.bind(this.app),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
199
213
|
}
|
|
200
214
|
export function createServer(config) {
|
|
201
215
|
return new LwrApp(config);
|
|
@@ -203,6 +217,12 @@ export function createServer(config) {
|
|
|
203
217
|
export async function generateStaticSite(config) {
|
|
204
218
|
config = config || {};
|
|
205
219
|
config.serverType = 'fs'; // override serverType
|
|
220
|
+
const { serverMode } = config;
|
|
221
|
+
if (serverMode === 'dev' || serverMode === 'compat') {
|
|
222
|
+
// TODO: dynamic imports are not generated in dev mode
|
|
223
|
+
// https://github.com/salesforce/lwr/issues/1111
|
|
224
|
+
console.warn('[WARN] static generation in `dev` or `compat` mode is currently not fully supported');
|
|
225
|
+
}
|
|
206
226
|
const lwrApp = createServer(config);
|
|
207
227
|
overrideConfigAsSrc(lwrApp);
|
|
208
228
|
await lwrApp.init();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LwrUnresolvableError, createSingleDiagnosticError as createDiagnostic, descriptions, } from '@lwrjs/diagnostics';
|
|
2
|
-
import { LATEST_SIGNATURE, explodeSpecifier, getImportMetadataMappings,
|
|
2
|
+
import { LATEST_SIGNATURE, explodeSpecifier, getImportMetadataMappings, serializeModuleToJson, getModuleIdentity, getResourceIdentity, getAssetIdentity, getMappingIdentity, getVersionedModuleId, } from '@lwrjs/shared-utils';
|
|
3
3
|
import { createReturnStatus, isSupportedEnvironment } from './utils.js';
|
|
4
4
|
export default function apiMiddleware(app, context) {
|
|
5
5
|
const { appConfig: { environment: environmentConfig }, moduleRegistry, moduleBundler, resourceRegistry, runtimeEnvironment: defaultRuntimeEnvironment, } = context;
|
|
@@ -118,20 +118,15 @@ export default function apiMiddleware(app, context) {
|
|
|
118
118
|
const { entry } = await moduleRegistry.getModuleEntry(importerModuleId);
|
|
119
119
|
moduleId = { ...moduleId, importer: entry };
|
|
120
120
|
}
|
|
121
|
-
// const { ownHash, moduleEntry } = await moduleRegistry.getModule(moduleId, ctx.runtimeParams);
|
|
122
|
-
const { format, compat, locale, apiVersion } = req.params;
|
|
123
121
|
const { ownHash, moduleEntry } = await moduleRegistry.getModule(moduleId, ctx.runtimeParams);
|
|
124
122
|
if (ownHash) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})); // get specifier from registry, not req.params
|
|
130
|
-
const jsonQuery = req.isJsonRequest() ? '?json' : '';
|
|
123
|
+
const jsonQuery = req.isJsonRequest()
|
|
124
|
+
? `${ctx.runtimeEnvironment.debug ? '&' : '?'}json`
|
|
125
|
+
: '';
|
|
126
|
+
const uri = await moduleRegistry.resolveModuleUri({ ...moduleId, version: moduleEntry.version }, ctx.runtimeEnvironment, ctx.runtimeParams, ownHash);
|
|
131
127
|
res.set({
|
|
132
128
|
// This redirects to a signed URI
|
|
133
|
-
|
|
134
|
-
Location: `/${apiVersion}/bundle/${format}/${compat}${localeSegment}/bi/0/module/mi/${uriSpecifier}/s/${ownHash}/${moduleId.specifier.replace(/\//g, '_')}${jsonQuery}`,
|
|
129
|
+
Location: `${uri}${jsonQuery}`,
|
|
135
130
|
});
|
|
136
131
|
res.sendStatus(302);
|
|
137
132
|
}
|
|
@@ -261,19 +256,15 @@ export default function apiMiddleware(app, context) {
|
|
|
261
256
|
moduleId = { ...moduleId, importer: entry };
|
|
262
257
|
}
|
|
263
258
|
// Get the module's signature from the registry
|
|
264
|
-
const { format, compat, locale, apiVersion } = req.params;
|
|
265
259
|
const { ownHash, moduleEntry } = await moduleRegistry.getModule(moduleId, ctx.runtimeParams);
|
|
266
260
|
if (ownHash) {
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
})); // get specifier from registry, not req.params
|
|
272
|
-
const jsonQuery = req.isJsonRequest() ? '?json' : '';
|
|
261
|
+
const jsonQuery = req.isJsonRequest()
|
|
262
|
+
? `${ctx.runtimeEnvironment.debug ? '&' : '?'}json`
|
|
263
|
+
: '';
|
|
264
|
+
const uri = await moduleRegistry.resolveModuleUri({ ...moduleId, version: moduleEntry.version }, ctx.runtimeEnvironment, ctx.runtimeParams, ownHash);
|
|
273
265
|
res.set({
|
|
274
266
|
// This redirects to a signed URI
|
|
275
|
-
|
|
276
|
-
Location: `/${apiVersion}/module/${format}/${compat}${localeSegment}/mi/${uriSpecifier}/s/${ownHash}/${moduleId.specifier.replace(/\//g, '_')}${jsonQuery}`,
|
|
267
|
+
Location: `${uri}${jsonQuery}`,
|
|
277
268
|
});
|
|
278
269
|
res.sendStatus(302);
|
|
279
270
|
}
|
|
@@ -389,11 +380,13 @@ export default function apiMiddleware(app, context) {
|
|
|
389
380
|
// Koa routing (Path-To-RegExp) breaks compatibility with Express routing & asterisk wildcards
|
|
390
381
|
app.all('/:apiVersion/:assetType/:immutable?/s/:signature/' + app.getRegexWildcard(), async (req, res) => {
|
|
391
382
|
const { runtimeEnvironment } = req.getRuntimeContext(defaultRuntimeEnvironment);
|
|
383
|
+
const { basePath } = runtimeEnvironment;
|
|
392
384
|
const { signature } = req.params;
|
|
393
385
|
const { immutable, assetType: type } = req.params;
|
|
394
386
|
const specifier = req.params[0] ? `/${req.params[0]}` : req.originalUrl;
|
|
387
|
+
const basePathSpecifier = `${basePath}${specifier}`;
|
|
395
388
|
try {
|
|
396
|
-
const assetObj = await context.assetRegistry.getAsset({ specifier, signature, type: type }, runtimeEnvironment);
|
|
389
|
+
const assetObj = await context.assetRegistry.getAsset({ specifier: basePathSpecifier, signature, type: type }, runtimeEnvironment);
|
|
397
390
|
if (immutable) {
|
|
398
391
|
// WIP: ?
|
|
399
392
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { performance } from 'perf_hooks';
|
|
2
|
+
import { getSpecifier, getExperimentalFeatures, hashContent } from '@lwrjs/shared-utils';
|
|
2
3
|
import { join, dirname, extname } from 'path';
|
|
3
4
|
import fs from 'fs-extra';
|
|
4
5
|
import { writeResponse } from './utils/stream.js';
|
|
@@ -13,6 +14,7 @@ export default class SiteGenerator {
|
|
|
13
14
|
* @param dispatcher - Facilitate server requests
|
|
14
15
|
*/
|
|
15
16
|
async buildStaticApplication(config, dispatcher) {
|
|
17
|
+
const startTime = performance.now();
|
|
16
18
|
console.log('[Static Generation] starting');
|
|
17
19
|
const { routes, staticSiteGenerator, rootDir, assets } = config;
|
|
18
20
|
if (!staticSiteGenerator.outputDir) {
|
|
@@ -28,7 +30,9 @@ export default class SiteGenerator {
|
|
|
28
30
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
29
31
|
// Copy over assets
|
|
30
32
|
this.copyAssets(assets, outputDir);
|
|
31
|
-
|
|
33
|
+
const endTime = performance.now();
|
|
34
|
+
const timeDiff = (endTime - startTime) / 1000;
|
|
35
|
+
console.log(`[Static Generation] complete in ${Math.round(timeDiff)} seconds`);
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* Crawl all view routes for a site
|
|
@@ -37,25 +41,24 @@ export default class SiteGenerator {
|
|
|
37
41
|
if (!staticSiteGenerator.locales) {
|
|
38
42
|
staticSiteGenerator.locales = ['en-US'];
|
|
39
43
|
}
|
|
40
|
-
// Build up a list of dispatch requests to kick off in parallel
|
|
41
|
-
const dispatchRequests = [];
|
|
42
44
|
const generateUrl = this.createGenerateURLFunction(dispatcher);
|
|
45
|
+
// Note: generateUrl can consume a lot of memory so we need to do this sequentially
|
|
43
46
|
for (const locale of staticSiteGenerator.locales) {
|
|
44
47
|
// Generate all the routes
|
|
45
48
|
for (const route of routes) {
|
|
46
49
|
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
47
|
-
|
|
50
|
+
// eslint-disable-next-line no-await-in-loop
|
|
51
|
+
await generateUrl(route.path, siteConfig);
|
|
48
52
|
}
|
|
49
53
|
// Generate any additional urls
|
|
50
54
|
if (staticSiteGenerator._additionalRoutePaths) {
|
|
51
55
|
for (const uri of staticSiteGenerator._additionalRoutePaths) {
|
|
52
56
|
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
53
|
-
|
|
57
|
+
// eslint-disable-next-line no-await-in-loop
|
|
58
|
+
await generateUrl(uri, siteConfig);
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
}
|
|
57
|
-
// -- Dispatch routes
|
|
58
|
-
await Promise.all(dispatchRequests);
|
|
59
62
|
}
|
|
60
63
|
/**
|
|
61
64
|
* Creates a function to dispatch the root requests for a given view url
|
|
@@ -129,13 +132,20 @@ export default class SiteGenerator {
|
|
|
129
132
|
const dispatchRequests = [];
|
|
130
133
|
// Add URL re-writes for module redirects
|
|
131
134
|
if (normalizedUrl.indexOf('/s/') !== -1) {
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
siteConfig.urlRewriteMap.set(
|
|
135
|
-
// Redirect
|
|
135
|
+
// Redirect unsigned to signed URIs
|
|
136
|
+
// e.g. /1/bundle/amd/l/en-US/bi/0/module/mi/c/module/v/0_1_6 -> /1/bundle/amd/l/en-US/bi/0/module/mi/c/module/v/0_1_6/s/{signature}
|
|
137
|
+
siteConfig.urlRewriteMap.set(normalizedUrl.substring(0, normalizedUrl.indexOf('/s/')), normalizedUrl);
|
|
138
|
+
// Redirect encoded signed URIs to UNencoded signed URIs
|
|
139
|
+
// e.g. /1/bundle/amd/l/en-US/bi/0/module/mi/c%2Fmodule%2Fv%2F0_1_6/s/{signature} -> /1/bundle/amd/l/en-US/bi/0/module/mi/c/module/v/0_1_6/s/{signature}
|
|
136
140
|
siteConfig.urlRewriteMap.set(url.substring(0, url.indexOf('/s/')), normalizedUrl);
|
|
137
|
-
//
|
|
138
|
-
//
|
|
141
|
+
// Redirect unversioned/unsigned URIs to signed URIs
|
|
142
|
+
// e.g. /1/bundle/amd/l/en-US/bi/0/module/mi/c/module -> /1/bundle/amd/l/en-US/bi/0/module/mi/c/module/v/0_1_6/s/{signature}
|
|
143
|
+
// e.g. with importer /1/bundle/amd/l/en-US/bi/0/module/mi/c/module?importer=parent%2Fmodule%2Fv%2F2_1_0 -> /1/bundle/amd/l/en-US/bi/0/module/mi/c/module/v/0_1_6/s/{signature}
|
|
144
|
+
siteConfig.urlRewriteMap.set(normalizedUrl.substring(0, normalizedUrl.indexOf('/v/')), normalizedUrl);
|
|
145
|
+
// Redirect encoded unversioned/unsigned URIs to UNencoded signed URIs
|
|
146
|
+
// e.g. /1/bundle/amd/l/en-US/bi/0/module/mi/c%2Fmodule -> /1/bundle/amd/l/en-US/bi/0/module/mi/c/module/v/0_1_6/s/{signature}
|
|
147
|
+
// e.g. with importer /1/bundle/amd/l/en-US/bi/0/module/mi/c%2Fmodule?importer=parent%2Fmodule%2Fv%2F2_1_0 -> /1/bundle/amd/l/en-US/bi/0/module/mi/c/module/v/0_1_6/s/{signature}
|
|
148
|
+
siteConfig.urlRewriteMap.set(url.substring(0, url.indexOf('%2Fv%2F')), normalizedUrl);
|
|
139
149
|
}
|
|
140
150
|
// Recursively traverse dependencies
|
|
141
151
|
const moduleDefinition = context.fs?.metadata?.moduleDefinition; // LinkedModuleDefinition | BundleDefinition
|
|
@@ -144,7 +154,9 @@ export default class SiteGenerator {
|
|
|
144
154
|
const imports = moduleDefinition.linkedModuleRecord?.imports || moduleDefinition.bundleRecord?.imports || [];
|
|
145
155
|
// /1/module/esm/0/l/en-US/mi/lwc
|
|
146
156
|
for (const importModule of imports) {
|
|
147
|
-
const jsUri =
|
|
157
|
+
const jsUri = importModule.specifier.startsWith('/')
|
|
158
|
+
? importModule.specifier
|
|
159
|
+
: getSpecifier(importModule);
|
|
148
160
|
dispatchRequests.push(this.dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig));
|
|
149
161
|
}
|
|
150
162
|
// Dynamic imports
|
|
@@ -152,7 +164,9 @@ export default class SiteGenerator {
|
|
|
152
164
|
moduleDefinition.bundleRecord?.dynamicImports ||
|
|
153
165
|
[];
|
|
154
166
|
for (const importModule of dynamicImports) {
|
|
155
|
-
const jsUri =
|
|
167
|
+
const jsUri = importModule.specifier.startsWith('/')
|
|
168
|
+
? importModule.specifier
|
|
169
|
+
: getSpecifier(importModule);
|
|
156
170
|
dispatchRequests.push(this.dispatchJSResourceRecursive(jsUri, dispatcher, siteConfig));
|
|
157
171
|
}
|
|
158
172
|
}
|
|
@@ -219,10 +233,12 @@ export default class SiteGenerator {
|
|
|
219
233
|
// Default Path (only write once)
|
|
220
234
|
// The default locale is english
|
|
221
235
|
if (siteConfig.locale.toLowerCase().startsWith('en')) {
|
|
236
|
+
siteConfig.viewPaths.add(filePath);
|
|
222
237
|
await writeResponse(context, filePath);
|
|
223
238
|
}
|
|
224
239
|
// Language path (always write out)
|
|
225
240
|
createDir(localeDir);
|
|
241
|
+
siteConfig.viewPaths.add(fileLocalePath);
|
|
226
242
|
await writeResponse(context, fileLocalePath);
|
|
227
243
|
// Get the metadata
|
|
228
244
|
const viewDefinition = context.fs?.metadata?.viewDefinition;
|
|
@@ -323,9 +339,6 @@ export default class SiteGenerator {
|
|
|
323
339
|
'"');
|
|
324
340
|
}
|
|
325
341
|
}
|
|
326
|
-
else {
|
|
327
|
-
console.warn('[WARN] Unable to resolve bare specifier or variable dynamic import: "' + jsUri + '"');
|
|
328
|
-
}
|
|
329
342
|
}
|
|
330
343
|
}
|
|
331
344
|
/**
|
|
@@ -407,6 +420,7 @@ export default class SiteGenerator {
|
|
|
407
420
|
const experimentalFeatures = this.filterExperimentalFeatures();
|
|
408
421
|
return {
|
|
409
422
|
outputDir,
|
|
423
|
+
viewPaths: new Set(),
|
|
410
424
|
visitedUrls: new Set(),
|
|
411
425
|
locale,
|
|
412
426
|
urlRewriteMap,
|
|
@@ -432,6 +446,7 @@ export default class SiteGenerator {
|
|
|
432
446
|
siteConfig.viewConfigPath &&
|
|
433
447
|
additionalImportMetadata?.imports &&
|
|
434
448
|
Object.keys(additionalImportMetadata.imports).length > 0) {
|
|
449
|
+
// Build and stringify the new import metadata
|
|
435
450
|
const imports = additionalImportMetadata.imports
|
|
436
451
|
? JSON.stringify(additionalImportMetadata.imports)
|
|
437
452
|
: '{}';
|
|
@@ -442,7 +457,23 @@ export default class SiteGenerator {
|
|
|
442
457
|
: '{}';
|
|
443
458
|
const initIndex = `if (!globalThis.LWR.index) { globalThis.LWR.index = {}; }`;
|
|
444
459
|
const mergeIndex = `Object.assign(globalThis.LWR.index, ${index})`;
|
|
445
|
-
|
|
460
|
+
// Read in the old config and append the new import metadata
|
|
461
|
+
const oldConfig = fs.readFileSync(siteConfig.viewConfigPath, 'utf-8');
|
|
462
|
+
const newConfig = `${oldConfig}\n// Appended by Static Site Generator\n${initImports}\n${mergeImports}\n${initIndex}\n${mergeIndex}\n`;
|
|
463
|
+
const configHash = hashContent(newConfig);
|
|
464
|
+
// Write the updated config to a new filepath containing its hash signature, and delete the old config
|
|
465
|
+
const sigRegex = /\/s\/[a-z0-9]+\/config\.js/i;
|
|
466
|
+
const configSuffix = `/s/${configHash}/config.js`;
|
|
467
|
+
const newConfigPath = siteConfig.viewConfigPath.replace(sigRegex, configSuffix);
|
|
468
|
+
fs.mkdirSync(dirname(newConfigPath), { recursive: true }); // we know this dir does not exist
|
|
469
|
+
fs.writeFileSync(newConfigPath, newConfig, 'utf-8');
|
|
470
|
+
fs.rmSync(siteConfig.viewConfigPath);
|
|
471
|
+
// Update the config script src in the view document(s)
|
|
472
|
+
siteConfig.viewPaths.forEach((path) => {
|
|
473
|
+
const oldDoc = fs.readFileSync(path, 'utf-8');
|
|
474
|
+
const newDoc = oldDoc.toString().replace(sigRegex, configSuffix);
|
|
475
|
+
fs.writeFileSync(path, newDoc, 'utf-8');
|
|
476
|
+
});
|
|
446
477
|
}
|
|
447
478
|
}
|
|
448
479
|
}
|
|
@@ -15,7 +15,7 @@ interface ConfigMap {
|
|
|
15
15
|
bootstrap: NormalizedLwrAppBootstrapConfig;
|
|
16
16
|
locker: RequiredLwrLockerConfig;
|
|
17
17
|
}
|
|
18
|
-
export declare const ROOT_ATTRIBUTE_KEYS: ["amdLoader", "apiVersion", "assets", "assetProviders", "assetTransformers", "bundleConfig", "cacheDir", "contentDir", "environment", "errorRoutes", "esmLoader", "staticSiteGenerator", "globalData", "globalDataDir", "hooks", "ignoreLwrConfigFile", "lwrConfigFile", "layoutsDir", "locker", "lwc", "lwrVersion", "moduleProviders", "port", "resourceProviders", "rootDir", "routes", "serverMode", "serverType", "templateEngine", "viewProviders", "viewTransformers"];
|
|
18
|
+
export declare const ROOT_ATTRIBUTE_KEYS: ["amdLoader", "apiVersion", "assets", "assetProviders", "assetTransformers", "bundleConfig", "cacheDir", "contentDir", "environment", "errorRoutes", "esmLoader", "staticSiteGenerator", "globalData", "globalDataDir", "hooks", "ignoreLwrConfigFile", "lwrConfigFile", "layoutsDir", "locker", "lwc", "lwrVersion", "moduleProviders", "port", "basePath", "resourceProviders", "rootDir", "routes", "serverMode", "serverType", "templateEngine", "viewProviders", "viewTransformers"];
|
|
19
19
|
export declare const ASSET_DIR_ATTRIBUTE_KEYS: ["alias", "dir", "urlPath"];
|
|
20
20
|
export declare const ASSET_FILE_ATTRIBUTE_KEYS: ["alias", "file", "urlPath"];
|
|
21
21
|
export declare const LOCKER_ATTRIBUTE_KEYS: ["enabled", "trustedComponents", "clientOnly"];
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.
|
|
7
|
+
"version": "0.6.2",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -33,31 +33,31 @@
|
|
|
33
33
|
"package.cjs"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lwrjs/app-service": "0.6.
|
|
37
|
-
"@lwrjs/asset-registry": "0.6.
|
|
38
|
-
"@lwrjs/asset-transformer": "0.6.
|
|
39
|
-
"@lwrjs/base-template-engine": "0.6.
|
|
40
|
-
"@lwrjs/base-view-provider": "0.6.
|
|
41
|
-
"@lwrjs/base-view-transformer": "0.6.
|
|
42
|
-
"@lwrjs/client-modules": "0.6.
|
|
43
|
-
"@lwrjs/compiler": "0.6.
|
|
44
|
-
"@lwrjs/diagnostics": "0.6.
|
|
45
|
-
"@lwrjs/fs-asset-provider": "0.6.
|
|
46
|
-
"@lwrjs/html-view-provider": "0.6.
|
|
47
|
-
"@lwrjs/loader": "0.6.
|
|
48
|
-
"@lwrjs/lwc-module-provider": "0.6.
|
|
49
|
-
"@lwrjs/lwc-ssr": "0.6.
|
|
50
|
-
"@lwrjs/markdown-view-provider": "0.6.
|
|
51
|
-
"@lwrjs/module-bundler": "0.6.
|
|
52
|
-
"@lwrjs/module-registry": "0.6.
|
|
53
|
-
"@lwrjs/npm-module-provider": "0.6.
|
|
54
|
-
"@lwrjs/nunjucks-view-provider": "0.6.
|
|
55
|
-
"@lwrjs/o11y": "0.6.
|
|
56
|
-
"@lwrjs/resource-registry": "0.6.
|
|
57
|
-
"@lwrjs/router": "0.6.
|
|
58
|
-
"@lwrjs/server": "0.6.
|
|
59
|
-
"@lwrjs/shared-utils": "0.6.
|
|
60
|
-
"@lwrjs/view-registry": "0.6.
|
|
36
|
+
"@lwrjs/app-service": "0.6.2",
|
|
37
|
+
"@lwrjs/asset-registry": "0.6.2",
|
|
38
|
+
"@lwrjs/asset-transformer": "0.6.2",
|
|
39
|
+
"@lwrjs/base-template-engine": "0.6.2",
|
|
40
|
+
"@lwrjs/base-view-provider": "0.6.2",
|
|
41
|
+
"@lwrjs/base-view-transformer": "0.6.2",
|
|
42
|
+
"@lwrjs/client-modules": "0.6.2",
|
|
43
|
+
"@lwrjs/compiler": "0.6.2",
|
|
44
|
+
"@lwrjs/diagnostics": "0.6.2",
|
|
45
|
+
"@lwrjs/fs-asset-provider": "0.6.2",
|
|
46
|
+
"@lwrjs/html-view-provider": "0.6.2",
|
|
47
|
+
"@lwrjs/loader": "0.6.2",
|
|
48
|
+
"@lwrjs/lwc-module-provider": "0.6.2",
|
|
49
|
+
"@lwrjs/lwc-ssr": "0.6.2",
|
|
50
|
+
"@lwrjs/markdown-view-provider": "0.6.2",
|
|
51
|
+
"@lwrjs/module-bundler": "0.6.2",
|
|
52
|
+
"@lwrjs/module-registry": "0.6.2",
|
|
53
|
+
"@lwrjs/npm-module-provider": "0.6.2",
|
|
54
|
+
"@lwrjs/nunjucks-view-provider": "0.6.2",
|
|
55
|
+
"@lwrjs/o11y": "0.6.2",
|
|
56
|
+
"@lwrjs/resource-registry": "0.6.2",
|
|
57
|
+
"@lwrjs/router": "0.6.2",
|
|
58
|
+
"@lwrjs/server": "0.6.2",
|
|
59
|
+
"@lwrjs/shared-utils": "0.6.2",
|
|
60
|
+
"@lwrjs/view-registry": "0.6.2",
|
|
61
61
|
"dompurify": "^2.3.0",
|
|
62
62
|
"fs-extra": "^10.0.0",
|
|
63
63
|
"jsdom": "^16.7.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"qs": "^6.9.4"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@lwrjs/types": "0.6.
|
|
70
|
+
"@lwrjs/types": "0.6.2"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"lwc": ">= 1.x <= 2.x"
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=14.15.4 <17"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "ef85bdc48adde58b7c648561d67acbb408bbe189"
|
|
79
79
|
}
|