@lwrjs/core 0.6.0-alpha.1 → 0.6.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/env-config.cjs +37 -3
- package/build/cjs/index.cjs +26 -9
- package/build/cjs/middlewares/api-middleware.cjs +6 -6
- package/build/cjs/middlewares/utils.cjs +1 -1
- package/build/cjs/tools/static-generation.cjs +73 -55
- package/build/cjs/tools/utils/network-dispatcher.cjs +22 -2
- package/build/cjs/validation/app-config-context.cjs +5 -2
- package/build/cjs/validation/app-config.cjs +1 -0
- package/build/es/env-config.js +40 -3
- package/build/es/index.js +29 -9
- package/build/es/middlewares/api-middleware.js +6 -6
- package/build/es/middlewares/ui-middleware.js +2 -2
- package/build/es/middlewares/utils.d.ts +2 -5
- package/build/es/middlewares/utils.js +3 -3
- package/build/es/tools/static-generation.d.ts +34 -2
- package/build/es/tools/static-generation.js +101 -74
- package/build/es/tools/types.d.ts +13 -2
- package/build/es/tools/utils/network-dispatcher.d.ts +3 -0
- package/build/es/tools/utils/network-dispatcher.js +26 -2
- package/build/es/validation/app-config-context.d.ts +2 -2
- package/build/es/validation/app-config-context.js +3 -0
- package/build/es/validation/app-config.js +1 -0
- package/package.json +29 -25
package/build/cjs/env-config.cjs
CHANGED
|
@@ -53,6 +53,7 @@ var DEFAULT_LAYOUTS_DIR = "$rootDir/src/layouts";
|
|
|
53
53
|
var DEFAULT_DATA_DIR = "$rootDir/src/data";
|
|
54
54
|
var DEFAULT_MODULE_PROVIDERS = [
|
|
55
55
|
"@lwrjs/app-service/moduleProvider",
|
|
56
|
+
"@lwrjs/lwc-ssr/moduleProvider",
|
|
56
57
|
"@lwrjs/lwc-module-provider",
|
|
57
58
|
"@lwrjs/npm-module-provider"
|
|
58
59
|
];
|
|
@@ -63,7 +64,9 @@ var DEFAULT_VIEW_PROVIDERS = [
|
|
|
63
64
|
"@lwrjs/markdown-view-provider",
|
|
64
65
|
"@lwrjs/base-view-provider"
|
|
65
66
|
];
|
|
67
|
+
var DEFAULT_VIEW_TRANFORM_PLUGINS = ["@lwrjs/base-view-transformer", "@lwrjs/lwc-ssr/viewTransformer"];
|
|
66
68
|
var DEFAULT_ASSET_PROVIDERS = ["@lwrjs/fs-asset-provider"];
|
|
69
|
+
var DEFAULT_ASSET_TRANFORM_PLUGINS = ["@lwrjs/asset-transformer"];
|
|
67
70
|
var DEFAULT_TEMPLATE_ENGINE = "@lwrjs/base-template-engine";
|
|
68
71
|
var DEFAULT_AMD_LOADER = "lwr/loader";
|
|
69
72
|
var DEFAULT_AMD_LOADER_LEGACY = "lwr/loaderLegacy";
|
|
@@ -73,9 +76,17 @@ var DEFAULT_LWR_MODULES = [
|
|
|
73
76
|
{npm: getLWCEngineSpecifier()},
|
|
74
77
|
{npm: "@lwrjs/client-modules"},
|
|
75
78
|
{npm: "@lwrjs/loader"},
|
|
79
|
+
{npm: "@lwrjs/o11y"},
|
|
76
80
|
{npm: "@lwrjs/router"},
|
|
77
81
|
{npm: "@lwc/synthetic-shadow"}
|
|
78
82
|
];
|
|
83
|
+
var DEFAULT_BUNDLE_EXCLUSIONS = [
|
|
84
|
+
"lwc",
|
|
85
|
+
"@lwc/synthetic-shadow",
|
|
86
|
+
"lwr/navigation",
|
|
87
|
+
"lwr/esmLoader",
|
|
88
|
+
"lwr/profiler"
|
|
89
|
+
];
|
|
79
90
|
var DEFAULT_LWR_CONFIG = {
|
|
80
91
|
port: PORT,
|
|
81
92
|
ignoreLwrConfigFile: false,
|
|
@@ -85,6 +96,8 @@ var DEFAULT_LWR_CONFIG = {
|
|
|
85
96
|
serverMode: MODE,
|
|
86
97
|
apiVersion: DEFAULT_API_VERSION,
|
|
87
98
|
assets: DEFAULT_ASSETS_DIR,
|
|
99
|
+
assetProviders: DEFAULT_ASSET_PROVIDERS,
|
|
100
|
+
assetTransformers: DEFAULT_ASSET_TRANFORM_PLUGINS,
|
|
88
101
|
contentDir: DEFAULT_CONTENT_DIR,
|
|
89
102
|
layoutsDir: DEFAULT_LAYOUTS_DIR,
|
|
90
103
|
staticSiteGenerator: DEFAULT_GENERATOR_CONFIG,
|
|
@@ -94,12 +107,13 @@ var DEFAULT_LWR_CONFIG = {
|
|
|
94
107
|
moduleProviders: DEFAULT_MODULE_PROVIDERS,
|
|
95
108
|
resourceProviders: DEFAULT_RESOURCE_PROVIDERS,
|
|
96
109
|
viewProviders: DEFAULT_VIEW_PROVIDERS,
|
|
110
|
+
viewTransformers: DEFAULT_VIEW_TRANFORM_PLUGINS,
|
|
97
111
|
templateEngine: DEFAULT_TEMPLATE_ENGINE,
|
|
98
112
|
environment: {},
|
|
99
113
|
lwc: {modules: []},
|
|
100
114
|
routes: [],
|
|
101
115
|
errorRoutes: [],
|
|
102
|
-
bundleConfig: {},
|
|
116
|
+
bundleConfig: {exclude: DEFAULT_BUNDLE_EXCLUSIONS},
|
|
103
117
|
serverType: DEFAULT_SERVER_TYPE,
|
|
104
118
|
locker: import_shared_utils.DEFAULT_LWR_LOCKER_CONFIG
|
|
105
119
|
};
|
|
@@ -208,6 +222,15 @@ function mergeLWCConfigs(config1, config2) {
|
|
|
208
222
|
interchangeableModules: mergedInterchangeableModules.length ? mergedInterchangeableModules : void 0
|
|
209
223
|
};
|
|
210
224
|
}
|
|
225
|
+
function mergeBundleConfig(jsonConfig, config) {
|
|
226
|
+
const defaultExclusions = config?.bundleConfig?.UNSAFE_lwrDefaultExclude || jsonConfig?.bundleConfig?.UNSAFE_lwrDefaultExclude || DEFAULT_BUNDLE_EXCLUSIONS;
|
|
227
|
+
const configExclusions = config?.bundleConfig?.exclude || jsonConfig?.bundleConfig?.exclude || [];
|
|
228
|
+
return {
|
|
229
|
+
...jsonConfig?.bundleConfig,
|
|
230
|
+
...config?.bundleConfig,
|
|
231
|
+
exclude: [...new Set([...defaultExclusions, ...configExclusions])]
|
|
232
|
+
};
|
|
233
|
+
}
|
|
211
234
|
function mergeLockerConfig(jsonConfig, config) {
|
|
212
235
|
const defaultNamespaces = import_shared_utils.DEFAULT_LOCKER_TRUSTED_CMP;
|
|
213
236
|
const configNamespaces = config?.locker?.trustedComponents || jsonConfig?.locker?.trustedComponents || [];
|
|
@@ -232,8 +255,16 @@ function normalizeLwcConfig(config) {
|
|
|
232
255
|
interchangeableModulesMap: config.interchangeableModules ? (0, import_shared_utils.normalizeInterchangeableModuleConfig)(config.interchangeableModules) : void 0
|
|
233
256
|
};
|
|
234
257
|
}
|
|
258
|
+
function trimLwrConfig(config) {
|
|
259
|
+
Object.keys(config).forEach((k) => {
|
|
260
|
+
if (config[k] === void 0)
|
|
261
|
+
delete config[k];
|
|
262
|
+
});
|
|
263
|
+
return config;
|
|
264
|
+
}
|
|
235
265
|
function normalizeConfig(config) {
|
|
236
|
-
if (config) {
|
|
266
|
+
if (config !== void 0) {
|
|
267
|
+
config = trimLwrConfig(config);
|
|
237
268
|
(0, import_app_config.validateLwrAppConfig)(JSON.stringify(config), "pre");
|
|
238
269
|
}
|
|
239
270
|
const rootDir = import_path.default.resolve(config?.rootDir || DEFAULT_ROOT_DIR);
|
|
@@ -243,6 +274,7 @@ function normalizeConfig(config) {
|
|
|
243
274
|
...lwrJsonConfig,
|
|
244
275
|
...config,
|
|
245
276
|
lwc: normalizeLwcConfig(mergeLWCConfigs(lwrJsonConfig, config)),
|
|
277
|
+
bundleConfig: mergeBundleConfig(lwrJsonConfig, config),
|
|
246
278
|
locker: mergeLockerConfig(lwrJsonConfig, config),
|
|
247
279
|
rootDir
|
|
248
280
|
};
|
|
@@ -264,9 +296,11 @@ function normalizeConfig(config) {
|
|
|
264
296
|
interchangeableModulesMap: mergedLwrGlobalConfig.lwc.interchangeableModulesMap
|
|
265
297
|
},
|
|
266
298
|
moduleProviders: normalizeServices(mergedLwrGlobalConfig.moduleProviders, rootDir),
|
|
267
|
-
assetProviders: normalizeServices(
|
|
299
|
+
assetProviders: normalizeServices(mergedLwrGlobalConfig.assetProviders, rootDir),
|
|
300
|
+
assetTransformers: normalizeServices(mergedLwrGlobalConfig.assetTransformers, rootDir),
|
|
268
301
|
resourceProviders: normalizeServices(mergedLwrGlobalConfig.resourceProviders, rootDir),
|
|
269
302
|
viewProviders: normalizeServices(mergedLwrGlobalConfig.viewProviders, rootDir),
|
|
303
|
+
viewTransformers: normalizeServices(mergedLwrGlobalConfig.viewTransformers, rootDir),
|
|
270
304
|
routes: normalizeRoutes(mergedLwrGlobalConfig.routes, {rootDir, assets, contentDir, layoutsDir}),
|
|
271
305
|
errorRoutes: normalizeRoutes(mergedLwrGlobalConfig.errorRoutes, {
|
|
272
306
|
rootDir,
|
package/build/cjs/index.cjs
CHANGED
|
@@ -35,6 +35,7 @@ var import_module_registry = __toModule(require("@lwrjs/module-registry"));
|
|
|
35
35
|
var import_resource_registry = __toModule(require("@lwrjs/resource-registry"));
|
|
36
36
|
var import_asset_registry = __toModule(require("@lwrjs/asset-registry"));
|
|
37
37
|
var import_view_registry = __toModule(require("@lwrjs/view-registry"));
|
|
38
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
38
39
|
var import_env_config = __toModule(require("./env-config.cjs"));
|
|
39
40
|
var import_lwr_app_observer = __toModule(require("./lwr-app-observer.cjs"));
|
|
40
41
|
var import_locale_middleware = __toModule(require("./middlewares/locale-middleware.cjs"));
|
|
@@ -77,10 +78,12 @@ async function initContext(app, server, rawLwrConfig) {
|
|
|
77
78
|
};
|
|
78
79
|
const hookProviders = await getServices(rawLwrConfig.hooks, void 0, rawLwrConfig);
|
|
79
80
|
const {lwrConfig, dataConfig, runtimeConfig} = await (0, import_hooks.runConfigurationsHook)(hookProviders, rawLwrConfig, rawDataConfig, rawRuntimeEnvConfig);
|
|
81
|
+
const assetTransformers = await getServices(rawLwrConfig.assetTransformers, void 0, rawLwrConfig);
|
|
80
82
|
const appObserver = new import_lwr_app_observer.LwrApplicationObserver();
|
|
81
83
|
const appEmitter = appObserver.createLwrEmitter();
|
|
82
84
|
const compiler = new import_compiler.LwrCompiler();
|
|
83
85
|
const assetRegistry = new import_asset_registry.LwrAssetRegistry({
|
|
86
|
+
assetTransformers,
|
|
84
87
|
appObserver,
|
|
85
88
|
appEmitter,
|
|
86
89
|
runtimeEnvironment: runtimeConfig
|
|
@@ -136,9 +139,9 @@ async function initContext(app, server, rawLwrConfig) {
|
|
|
136
139
|
notifyViewSourceChanged,
|
|
137
140
|
notifyAssetSourceChanged
|
|
138
141
|
} = appEmitter;
|
|
139
|
-
const providerContext =
|
|
142
|
+
const providerContext = {
|
|
140
143
|
compiler,
|
|
141
|
-
appObserver: {onModuleDefinitionChange, onModuleSourceChange},
|
|
144
|
+
appObserver: (0, import_shared_utils.deepFreeze)({onModuleDefinitionChange, onModuleSourceChange}),
|
|
142
145
|
appEmitter: {
|
|
143
146
|
notifyModuleDefinitionChanged: (payload) => notifyModuleDefinitionChanged.call(appEmitter, payload),
|
|
144
147
|
notifyModuleSourceChanged: (payload) => notifyModuleSourceChanged.call(appEmitter, payload),
|
|
@@ -146,10 +149,11 @@ async function initContext(app, server, rawLwrConfig) {
|
|
|
146
149
|
notifyAssetSourceChanged: (payload) => notifyAssetSourceChanged.call(appEmitter, payload)
|
|
147
150
|
},
|
|
148
151
|
moduleRegistry: moduleRegistry.getPublicApi(),
|
|
152
|
+
moduleBundler,
|
|
149
153
|
resourceRegistry: resourceRegistry.getPublicApi(),
|
|
150
154
|
viewRegistry: viewRegistry.getPublicApi(),
|
|
151
155
|
assetRegistry: assetRegistry.getPublicApi(),
|
|
152
|
-
config: {
|
|
156
|
+
config: (0, import_shared_utils.deepFreeze)({
|
|
153
157
|
cacheDir,
|
|
154
158
|
modules,
|
|
155
159
|
routes,
|
|
@@ -161,15 +165,17 @@ async function initContext(app, server, rawLwrConfig) {
|
|
|
161
165
|
amdLoader,
|
|
162
166
|
esmLoader,
|
|
163
167
|
environment
|
|
164
|
-
},
|
|
165
|
-
runtimeEnvironment: runtimeConfig
|
|
166
|
-
}
|
|
168
|
+
}),
|
|
169
|
+
runtimeEnvironment: (0, import_shared_utils.deepFreeze)(runtimeConfig)
|
|
170
|
+
};
|
|
167
171
|
const moduleProviders = await getServices(lwrConfig.moduleProviders, providerContext, lwrConfig);
|
|
168
172
|
moduleRegistry.addModuleProviders(moduleProviders);
|
|
169
173
|
const resourceProviders = await getServices(lwrConfig.resourceProviders, providerContext, lwrConfig);
|
|
170
174
|
resourceRegistry.addResourceProviders(resourceProviders);
|
|
171
175
|
const viewProviders = await getServices(lwrConfig.viewProviders, providerContext, lwrConfig);
|
|
176
|
+
const viewTransformers = await getServices(rawLwrConfig.viewTransformers, providerContext, rawLwrConfig);
|
|
172
177
|
viewRegistry.addViewProviders(viewProviders);
|
|
178
|
+
viewRegistry.addViewTransformers(viewTransformers);
|
|
173
179
|
await viewRegistry.initializeViewProviders();
|
|
174
180
|
const assetProviders = await getServices(lwrConfig.assetProviders, providerContext, lwrConfig);
|
|
175
181
|
assetRegistry.addAssetProviders(assetProviders);
|
|
@@ -190,9 +196,14 @@ var LwrApp = class {
|
|
|
190
196
|
}
|
|
191
197
|
async init() {
|
|
192
198
|
if (!this.initialized) {
|
|
193
|
-
const context = await initContext(this.app, this.server, this.config);
|
|
194
|
-
initMiddlewares(this.app, this.server, context);
|
|
195
199
|
this.initialized = true;
|
|
200
|
+
try {
|
|
201
|
+
const context = await initContext(this.app, this.server, this.config);
|
|
202
|
+
initMiddlewares(this.app, this.server, context);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
this.initialized = false;
|
|
205
|
+
throw e;
|
|
206
|
+
}
|
|
196
207
|
}
|
|
197
208
|
}
|
|
198
209
|
async listen(callback) {
|
|
@@ -201,7 +212,13 @@ var LwrApp = class {
|
|
|
201
212
|
const {serverMode, port} = config;
|
|
202
213
|
server.listen(port || config.port, async () => {
|
|
203
214
|
if (process.env.WARMUP?.toLowerCase() === "true") {
|
|
204
|
-
|
|
215
|
+
try {
|
|
216
|
+
await (0, import_server_warmup.warmupServer)(config, app.getInternalRequestKey());
|
|
217
|
+
} catch (err) {
|
|
218
|
+
throw (0, import_diagnostics.createSingleDiagnosticError)({
|
|
219
|
+
description: import_diagnostics.descriptions.SERVER.WARMUP_ERROR(err.message)
|
|
220
|
+
}, import_diagnostics.LwrServerError);
|
|
221
|
+
}
|
|
205
222
|
}
|
|
206
223
|
callback?.({serverMode, port});
|
|
207
224
|
});
|
|
@@ -82,17 +82,17 @@ function apiMiddleware(app, context) {
|
|
|
82
82
|
const resolvedUris = [];
|
|
83
83
|
if (req.isSiteGeneration()) {
|
|
84
84
|
if (bundleDef.bundleRecord.imports) {
|
|
85
|
-
for (
|
|
86
|
-
const
|
|
87
|
-
const id = await (0, import_shared_utils.getVersionedModuleId)(
|
|
85
|
+
for (const theImport of bundleDef.bundleRecord.imports) {
|
|
86
|
+
const childSpecifier = theImport.specifier;
|
|
87
|
+
const id = await (0, import_shared_utils.getVersionedModuleId)(childSpecifier, moduleRegistry);
|
|
88
88
|
const uri = await moduleRegistry.resolveModuleUri(id, runtimeEnvironment, runtimeParams);
|
|
89
89
|
resolvedUris.push(uri);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
if (bundleDef.bundleRecord.dynamicImports) {
|
|
93
|
-
for (
|
|
94
|
-
const
|
|
95
|
-
const id = await (0, import_shared_utils.getVersionedModuleId)(
|
|
93
|
+
for (const theImport of bundleDef.bundleRecord.dynamicImports) {
|
|
94
|
+
const childSpecifier = theImport.specifier;
|
|
95
|
+
const id = await (0, import_shared_utils.getVersionedModuleId)(childSpecifier, moduleRegistry);
|
|
96
96
|
const uri = await moduleRegistry.resolveModuleUri(id, runtimeEnvironment, runtimeParams);
|
|
97
97
|
resolvedUris.push(uri);
|
|
98
98
|
}
|
|
@@ -37,7 +37,7 @@ var window = new import_jsdom.JSDOM("").window;
|
|
|
37
37
|
var DOMPurify = (0, import_dompurify.default)(window);
|
|
38
38
|
function createReturnStatus(name, error) {
|
|
39
39
|
let returnStatus = {status: 501, message: ""};
|
|
40
|
-
if (error.code === "NO_LWC_MODULE_FOUND") {
|
|
40
|
+
if ((0, import_diagnostics.isNodeError)(error) && error.code === "NO_LWC_MODULE_FOUND") {
|
|
41
41
|
returnStatus = {status: 404, message: import_diagnostics.descriptions.UNRESOLVABLE.LWC_MODULE(name).message};
|
|
42
42
|
} else if (error instanceof import_diagnostics.LwrUnresolvableError && error.diagnostics[0].description.category === "lwrUnresolvable/invalid") {
|
|
43
43
|
returnStatus = {status: 400, message: error.message};
|
|
@@ -24,6 +24,7 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/core/src/tools/static-generation.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
ViewImportMetadataImpl: () => ViewImportMetadataImpl,
|
|
27
28
|
default: () => static_generation_default
|
|
28
29
|
});
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
@@ -39,7 +40,8 @@ var SiteGenerator = class {
|
|
|
39
40
|
staticSiteGenerator.outputDir = "__generated_site__";
|
|
40
41
|
}
|
|
41
42
|
const outputDir = (0, import_path.join)(rootDir, staticSiteGenerator.outputDir);
|
|
42
|
-
console.log(`[INFO] Output Location: ${outputDir}`);
|
|
43
|
+
console.log(`[INFO] Clear Output Location: ${outputDir}`);
|
|
44
|
+
import_fs_extra.default.rmSync(outputDir, {recursive: true, force: true});
|
|
43
45
|
const urlRewriteMap = new Map();
|
|
44
46
|
await this.generateRoutes(staticSiteGenerator, routes, dispatcher, outputDir, urlRewriteMap);
|
|
45
47
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
@@ -54,12 +56,12 @@ var SiteGenerator = class {
|
|
|
54
56
|
const generateUrl = this.createGenerateURLFunction(dispatcher);
|
|
55
57
|
for (const locale of staticSiteGenerator.locales) {
|
|
56
58
|
for (const route of routes) {
|
|
57
|
-
const siteConfig = createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
59
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
58
60
|
dispatchRequests.push(generateUrl(route.path, siteConfig));
|
|
59
61
|
}
|
|
60
62
|
if (staticSiteGenerator._additionalRoutePaths) {
|
|
61
63
|
for (const uri of staticSiteGenerator._additionalRoutePaths) {
|
|
62
|
-
const siteConfig = createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
64
|
+
const siteConfig = this.createSiteConfig(outputDir, locale, urlRewriteMap);
|
|
63
65
|
dispatchRequests.push(generateUrl(uri, siteConfig));
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -71,7 +73,7 @@ var SiteGenerator = class {
|
|
|
71
73
|
const locale = siteConfig.locale;
|
|
72
74
|
console.log(`[INFO] Start Generate: ${locale} ${uri}`);
|
|
73
75
|
await this.dispatchResourceRecursive(uri, dispatcher, {resourceType: "route"}, siteConfig);
|
|
74
|
-
addAdditionalImportMetadataToViewConfig(siteConfig);
|
|
76
|
+
this.addAdditionalImportMetadataToViewConfig(siteConfig);
|
|
75
77
|
console.log(`[INFO] End Generate ${locale} ${uri}`);
|
|
76
78
|
};
|
|
77
79
|
return generateRoute.bind(this);
|
|
@@ -130,12 +132,15 @@ var SiteGenerator = class {
|
|
|
130
132
|
await Promise.all(dispatchRequests);
|
|
131
133
|
}
|
|
132
134
|
async handleMappingResource(url, context, siteConfig, dispatcher) {
|
|
133
|
-
const {
|
|
135
|
+
const {importMetadata: importMetatdata} = siteConfig;
|
|
134
136
|
const statusCode = context.response?.status;
|
|
135
137
|
if (statusCode === 200) {
|
|
136
138
|
const newImportMetadata = context.fs?.body;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
if (!importMetatdata) {
|
|
140
|
+
console.warn("[WARN] Import metadata collector was never initialized");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const filteredImportMetadata = importMetatdata.addAdditionalMetadata(newImportMetadata);
|
|
139
144
|
const dispatchRequests = [];
|
|
140
145
|
for (const uri of Object.keys(filteredImportMetadata.imports)) {
|
|
141
146
|
dispatchRequests.push(this.dispatchResourceRecursive(uri, dispatcher, {resourceType: "js"}, siteConfig));
|
|
@@ -165,7 +170,7 @@ var SiteGenerator = class {
|
|
|
165
170
|
async handleViewDefinition(viewDefinition, siteConfig, dispatcher) {
|
|
166
171
|
siteConfig.endpoints = viewDefinition.viewRecord.endpoints;
|
|
167
172
|
if (viewDefinition.viewRecord.importMetadata) {
|
|
168
|
-
|
|
173
|
+
siteConfig.importMetadata = new ViewImportMetadataImpl(viewDefinition.viewRecord.importMetadata);
|
|
169
174
|
}
|
|
170
175
|
const dispatchRequests = [];
|
|
171
176
|
const assets = viewDefinition.viewRecord.assetReferences || [];
|
|
@@ -276,58 +281,71 @@ var SiteGenerator = class {
|
|
|
276
281
|
}
|
|
277
282
|
}
|
|
278
283
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
284
|
+
createSiteConfig(outputDir, locale, urlRewriteMap) {
|
|
285
|
+
const experimentalFeatures = this.filterExperimentalFeatures();
|
|
286
|
+
return {
|
|
287
|
+
outputDir,
|
|
288
|
+
visitedUrls: new Set(),
|
|
289
|
+
locale,
|
|
290
|
+
urlRewriteMap,
|
|
291
|
+
...experimentalFeatures
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
filterExperimentalFeatures() {
|
|
295
|
+
if ((0, import_shared_utils.getExperimentalFeatures)().ENABLE_FINGERPRINTS) {
|
|
296
|
+
return {experimentalFeatures: {ENABLE_FINGERPRINTS: true}};
|
|
297
|
+
} else {
|
|
298
|
+
return void 0;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
addAdditionalImportMetadataToViewConfig(siteConfig) {
|
|
302
|
+
const supportsFingerprints = siteConfig.experimentalFeatures?.ENABLE_FINGERPRINTS;
|
|
303
|
+
const additionalImportMetadata = siteConfig?.importMetadata?.getAdditionalImportMetadata();
|
|
304
|
+
if (supportsFingerprints && siteConfig.viewConfigPath && additionalImportMetadata?.imports && Object.keys(additionalImportMetadata.imports).length > 0) {
|
|
305
|
+
const imports = additionalImportMetadata.imports ? JSON.stringify(additionalImportMetadata.imports) : "{}";
|
|
306
|
+
const initImports = `if (!globalThis.LWR.imports) { globalThis.LWR.imports = {}; }`;
|
|
307
|
+
const mergeImports = `Object.assign(globalThis.LWR.imports, ${imports})`;
|
|
308
|
+
const index = additionalImportMetadata.index ? JSON.stringify(additionalImportMetadata.index) : "{}";
|
|
309
|
+
const initIndex = `if (!globalThis.LWR.index) { globalThis.LWR.index = {}; }`;
|
|
310
|
+
const mergeIndex = `Object.assign(globalThis.LWR.index, ${index})`;
|
|
311
|
+
import_fs_extra.default.appendFileSync(siteConfig.viewConfigPath, `
|
|
291
312
|
// Appended by Static Site Generator
|
|
292
313
|
${initImports}
|
|
293
314
|
${mergeImports}
|
|
294
315
|
${initIndex}
|
|
295
316
|
${mergeIndex}
|
|
296
317
|
`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
var static_generation_default = SiteGenerator;
|
|
322
|
+
var ViewImportMetadataImpl = class {
|
|
323
|
+
constructor(existingImportMetadata, additionalImportMetadata) {
|
|
324
|
+
this.existing = existingImportMetadata;
|
|
325
|
+
this.additional = additionalImportMetadata || {imports: {}, index: {}};
|
|
326
|
+
}
|
|
327
|
+
getAdditionalImportMetadata() {
|
|
328
|
+
return this.additional;
|
|
297
329
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
outputDir,
|
|
303
|
-
visitedUrls: new Set(),
|
|
304
|
-
locale,
|
|
305
|
-
urlRewriteMap,
|
|
306
|
-
existingImportMetadata: {imports: {}, index: {}},
|
|
307
|
-
additionalImportMetadata: {imports: {}, index: {}},
|
|
308
|
-
...experimentalFeatures
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
function filterExperimentalFeatures() {
|
|
312
|
-
if ((0, import_shared_utils.getExperimentalFeatures)().ENABLE_FINGERPRINTS) {
|
|
313
|
-
return {experimentalFeatures: {ENABLE_FINGERPRINTS: true}};
|
|
314
|
-
} else {
|
|
315
|
-
return void 0;
|
|
330
|
+
addAdditionalMetadata(newMetadata) {
|
|
331
|
+
const filteredImports = this.filterMetadata(newMetadata);
|
|
332
|
+
this.mergeImportMetadata(this.additional, filteredImports);
|
|
333
|
+
return filteredImports;
|
|
316
334
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
imports,
|
|
331
|
-
index
|
|
332
|
-
}
|
|
333
|
-
}
|
|
335
|
+
filterMetadata(newMetadata) {
|
|
336
|
+
const importsArray = Object.entries(newMetadata.imports);
|
|
337
|
+
const filteredImports = importsArray.filter(([key]) => !this.existing.imports[key]);
|
|
338
|
+
const imports = Object.fromEntries(filteredImports);
|
|
339
|
+
const indexArray = Object.entries(newMetadata.index || {});
|
|
340
|
+
const filteredIndex = indexArray.filter(([key]) => !this.existing.index || !this.existing.index[key]);
|
|
341
|
+
const index = Object.fromEntries(filteredIndex);
|
|
342
|
+
return {
|
|
343
|
+
imports,
|
|
344
|
+
index
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
mergeImportMetadata(targetImportMetdadata, newImportMetadata) {
|
|
348
|
+
Object.assign(targetImportMetdadata.imports, newImportMetadata.imports);
|
|
349
|
+
Object.assign(targetImportMetdadata.index, newImportMetadata.index);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
@@ -28,9 +28,14 @@ __export(exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var import_http = __toModule(require("http"));
|
|
30
30
|
var import_https = __toModule(require("https"));
|
|
31
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
32
|
var NetworkDispatcher = class {
|
|
32
33
|
constructor(port, internalRequestKey) {
|
|
33
34
|
this.port = port || 3e3;
|
|
35
|
+
const httpClient = this.port == 443 ? import_https.default : import_http.default;
|
|
36
|
+
this.pool = new httpClient.Agent({
|
|
37
|
+
maxSockets: 25
|
|
38
|
+
});
|
|
34
39
|
this.internalRequestKey = internalRequestKey || "";
|
|
35
40
|
}
|
|
36
41
|
dispatchUrl(url, method, lang) {
|
|
@@ -39,6 +44,7 @@ var NetworkDispatcher = class {
|
|
|
39
44
|
host: "localhost",
|
|
40
45
|
port: this.port,
|
|
41
46
|
path: url,
|
|
47
|
+
agent: this.pool,
|
|
42
48
|
headers: {
|
|
43
49
|
"Accept-Language": lang,
|
|
44
50
|
"lwr-metadata-request": this.internalRequestKey
|
|
@@ -57,13 +63,27 @@ var NetworkDispatcher = class {
|
|
|
57
63
|
const jsonResponse = JSON.parse(body);
|
|
58
64
|
resolve(jsonResponse);
|
|
59
65
|
} catch (e) {
|
|
60
|
-
console.error(`[NetworkDispatcher] unexpected response body: '${body}'
|
|
66
|
+
console.error(`[ERROR][NetworkDispatcher] unexpected response body: [${method}][${lang}] ${url}: '${body}'`);
|
|
67
|
+
if (e instanceof import_diagnostics.DiagnosticsError) {
|
|
68
|
+
console.log("LWR Diagnostic Error: ");
|
|
69
|
+
console.log(e.diagnostics);
|
|
70
|
+
console.log(e.stack);
|
|
71
|
+
} else {
|
|
72
|
+
console.error(e);
|
|
73
|
+
}
|
|
61
74
|
resolve({});
|
|
62
75
|
}
|
|
63
76
|
});
|
|
64
77
|
});
|
|
65
78
|
req.on("error", (err) => {
|
|
66
|
-
console.error(
|
|
79
|
+
console.error(`[ERROR][NetworkDispatcher] Request: [${method}][${lang}] ${url}`);
|
|
80
|
+
if (err instanceof import_diagnostics.DiagnosticsError) {
|
|
81
|
+
console.log("LWR Diagnostic Error: ");
|
|
82
|
+
console.log(err.diagnostics);
|
|
83
|
+
console.log(err.stack);
|
|
84
|
+
} else {
|
|
85
|
+
console.error(err);
|
|
86
|
+
}
|
|
67
87
|
reject(err);
|
|
68
88
|
});
|
|
69
89
|
req.end();
|
|
@@ -44,6 +44,7 @@ var ROOT_ATTRIBUTE_KEYS = createKeys("root", [
|
|
|
44
44
|
"apiVersion",
|
|
45
45
|
"assets",
|
|
46
46
|
"assetProviders",
|
|
47
|
+
"assetTransformers",
|
|
47
48
|
"bundleConfig",
|
|
48
49
|
"cacheDir",
|
|
49
50
|
"contentDir",
|
|
@@ -68,7 +69,8 @@ var ROOT_ATTRIBUTE_KEYS = createKeys("root", [
|
|
|
68
69
|
"serverMode",
|
|
69
70
|
"serverType",
|
|
70
71
|
"templateEngine",
|
|
71
|
-
"viewProviders"
|
|
72
|
+
"viewProviders",
|
|
73
|
+
"viewTransformers"
|
|
72
74
|
]);
|
|
73
75
|
var ASSET_DIR_ATTRIBUTE_KEYS = createKeys("assetDir", ["alias", "dir", "urlPath"]);
|
|
74
76
|
var ASSET_FILE_ATTRIBUTE_KEYS = createKeys("assetFile", ["alias", "file", "urlPath"]);
|
|
@@ -101,7 +103,8 @@ var BOOTSTRAP_ATTRIBUTE_KEYS = createKeys("bootstrap", [
|
|
|
101
103
|
"syntheticShadow",
|
|
102
104
|
"workers",
|
|
103
105
|
"services",
|
|
104
|
-
"configAsSrc"
|
|
106
|
+
"configAsSrc",
|
|
107
|
+
"experimentalSSR"
|
|
105
108
|
]);
|
|
106
109
|
var SPECIFIER_REGEX = /^@?[\w-]+(\/[\w-]+)*$/;
|
|
107
110
|
function isNotEmptyString(node) {
|
|
@@ -42,6 +42,7 @@ function validateBootstrap(node, validationContext, propPrefix) {
|
|
|
42
42
|
validationContext.assertValidKeys(node, "bootstrap", import_app_config_context.BOOTSTRAP_ATTRIBUTE_KEYS);
|
|
43
43
|
validationContext.assertArrayOfSpecifiers((0, import_jsonc_parser.findNodeAtLocation)(node, ["services"]), `${propPrefix}.services`);
|
|
44
44
|
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["autoBoot"]), `${propPrefix}.autoBoot`);
|
|
45
|
+
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["experimentalSSR"]), `${propPrefix}.experimentalSSR`);
|
|
45
46
|
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["configAsSrc"]), `${propPrefix}.configAsSrc`);
|
|
46
47
|
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["syntheticShadow"]), `${propPrefix}.syntheticShadow`);
|
|
47
48
|
const workers = (0, import_jsonc_parser.findNodeAtLocation)(node, ["workers"]);
|
package/build/es/env-config.js
CHANGED
|
@@ -26,6 +26,7 @@ const DEFAULT_DATA_DIR = '$rootDir/src/data';
|
|
|
26
26
|
// Providers
|
|
27
27
|
const DEFAULT_MODULE_PROVIDERS = [
|
|
28
28
|
'@lwrjs/app-service/moduleProvider',
|
|
29
|
+
'@lwrjs/lwc-ssr/moduleProvider',
|
|
29
30
|
'@lwrjs/lwc-module-provider',
|
|
30
31
|
'@lwrjs/npm-module-provider',
|
|
31
32
|
];
|
|
@@ -36,7 +37,9 @@ const DEFAULT_VIEW_PROVIDERS = [
|
|
|
36
37
|
'@lwrjs/markdown-view-provider',
|
|
37
38
|
'@lwrjs/base-view-provider',
|
|
38
39
|
];
|
|
40
|
+
const DEFAULT_VIEW_TRANFORM_PLUGINS = ['@lwrjs/base-view-transformer', '@lwrjs/lwc-ssr/viewTransformer'];
|
|
39
41
|
const DEFAULT_ASSET_PROVIDERS = ['@lwrjs/fs-asset-provider'];
|
|
42
|
+
const DEFAULT_ASSET_TRANFORM_PLUGINS = ['@lwrjs/asset-transformer'];
|
|
40
43
|
// Packages/modules
|
|
41
44
|
const DEFAULT_TEMPLATE_ENGINE = '@lwrjs/base-template-engine';
|
|
42
45
|
const DEFAULT_AMD_LOADER = 'lwr/loader';
|
|
@@ -47,9 +50,17 @@ const DEFAULT_LWR_MODULES = [
|
|
|
47
50
|
{ npm: getLWCEngineSpecifier() },
|
|
48
51
|
{ npm: '@lwrjs/client-modules' },
|
|
49
52
|
{ npm: '@lwrjs/loader' },
|
|
53
|
+
{ npm: '@lwrjs/o11y' },
|
|
50
54
|
{ npm: '@lwrjs/router' },
|
|
51
55
|
{ npm: '@lwc/synthetic-shadow' },
|
|
52
56
|
];
|
|
57
|
+
const DEFAULT_BUNDLE_EXCLUSIONS = [
|
|
58
|
+
'lwc',
|
|
59
|
+
'@lwc/synthetic-shadow',
|
|
60
|
+
'lwr/navigation',
|
|
61
|
+
'lwr/esmLoader',
|
|
62
|
+
'lwr/profiler',
|
|
63
|
+
];
|
|
53
64
|
// Default config objects
|
|
54
65
|
const DEFAULT_LWR_CONFIG = {
|
|
55
66
|
port: PORT,
|
|
@@ -60,6 +71,8 @@ const DEFAULT_LWR_CONFIG = {
|
|
|
60
71
|
serverMode: MODE,
|
|
61
72
|
apiVersion: DEFAULT_API_VERSION,
|
|
62
73
|
assets: DEFAULT_ASSETS_DIR,
|
|
74
|
+
assetProviders: DEFAULT_ASSET_PROVIDERS,
|
|
75
|
+
assetTransformers: DEFAULT_ASSET_TRANFORM_PLUGINS,
|
|
63
76
|
contentDir: DEFAULT_CONTENT_DIR,
|
|
64
77
|
layoutsDir: DEFAULT_LAYOUTS_DIR,
|
|
65
78
|
staticSiteGenerator: DEFAULT_GENERATOR_CONFIG,
|
|
@@ -69,12 +82,13 @@ const DEFAULT_LWR_CONFIG = {
|
|
|
69
82
|
moduleProviders: DEFAULT_MODULE_PROVIDERS,
|
|
70
83
|
resourceProviders: DEFAULT_RESOURCE_PROVIDERS,
|
|
71
84
|
viewProviders: DEFAULT_VIEW_PROVIDERS,
|
|
85
|
+
viewTransformers: DEFAULT_VIEW_TRANFORM_PLUGINS,
|
|
72
86
|
templateEngine: DEFAULT_TEMPLATE_ENGINE,
|
|
73
87
|
environment: {},
|
|
74
88
|
lwc: { modules: [] },
|
|
75
89
|
routes: [],
|
|
76
90
|
errorRoutes: [],
|
|
77
|
-
bundleConfig: {},
|
|
91
|
+
bundleConfig: { exclude: DEFAULT_BUNDLE_EXCLUSIONS },
|
|
78
92
|
serverType: DEFAULT_SERVER_TYPE,
|
|
79
93
|
locker: DEFAULT_LWR_LOCKER_CONFIG,
|
|
80
94
|
};
|
|
@@ -192,6 +206,18 @@ function mergeLWCConfigs(config1, config2) {
|
|
|
192
206
|
: undefined,
|
|
193
207
|
};
|
|
194
208
|
}
|
|
209
|
+
// merge default bundle exclusions with any bundle exclusions specified in config
|
|
210
|
+
function mergeBundleConfig(jsonConfig, config) {
|
|
211
|
+
const defaultExclusions = config?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
|
|
212
|
+
jsonConfig?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
|
|
213
|
+
DEFAULT_BUNDLE_EXCLUSIONS;
|
|
214
|
+
const configExclusions = config?.bundleConfig?.exclude || jsonConfig?.bundleConfig?.exclude || [];
|
|
215
|
+
return {
|
|
216
|
+
...jsonConfig?.bundleConfig,
|
|
217
|
+
...config?.bundleConfig,
|
|
218
|
+
exclude: [...new Set([...defaultExclusions, ...configExclusions])],
|
|
219
|
+
};
|
|
220
|
+
}
|
|
195
221
|
// merge default locker trusted namespaces/cmps with any trusted namespaces/cmps specified in config
|
|
196
222
|
function mergeLockerConfig(jsonConfig, config) {
|
|
197
223
|
const defaultNamespaces = DEFAULT_LOCKER_TRUSTED_CMP;
|
|
@@ -222,6 +248,13 @@ function normalizeLwcConfig(config) {
|
|
|
222
248
|
: undefined,
|
|
223
249
|
};
|
|
224
250
|
}
|
|
251
|
+
function trimLwrConfig(config) {
|
|
252
|
+
Object.keys(config).forEach((k) => {
|
|
253
|
+
if (config[k] === undefined)
|
|
254
|
+
delete config[k];
|
|
255
|
+
});
|
|
256
|
+
return config;
|
|
257
|
+
}
|
|
225
258
|
/**
|
|
226
259
|
* Merge and normalize all LWR configurations.
|
|
227
260
|
*
|
|
@@ -233,7 +266,8 @@ function normalizeLwcConfig(config) {
|
|
|
233
266
|
* @returns the merged and normalized LWR configuration
|
|
234
267
|
*/
|
|
235
268
|
export function normalizeConfig(config) {
|
|
236
|
-
if (config) {
|
|
269
|
+
if (config !== undefined) {
|
|
270
|
+
config = trimLwrConfig(config);
|
|
237
271
|
validateLwrAppConfig(JSON.stringify(config), 'pre');
|
|
238
272
|
}
|
|
239
273
|
// Merge all configurations together, and return
|
|
@@ -246,6 +280,7 @@ export function normalizeConfig(config) {
|
|
|
246
280
|
...lwrJsonConfig,
|
|
247
281
|
...config,
|
|
248
282
|
lwc: normalizeLwcConfig(mergeLWCConfigs(lwrJsonConfig, config)),
|
|
283
|
+
bundleConfig: mergeBundleConfig(lwrJsonConfig, config),
|
|
249
284
|
locker: mergeLockerConfig(lwrJsonConfig, config),
|
|
250
285
|
rootDir,
|
|
251
286
|
};
|
|
@@ -270,9 +305,11 @@ export function normalizeConfig(config) {
|
|
|
270
305
|
interchangeableModulesMap: mergedLwrGlobalConfig.lwc.interchangeableModulesMap,
|
|
271
306
|
},
|
|
272
307
|
moduleProviders: normalizeServices(mergedLwrGlobalConfig.moduleProviders, rootDir),
|
|
273
|
-
assetProviders: normalizeServices(
|
|
308
|
+
assetProviders: normalizeServices(mergedLwrGlobalConfig.assetProviders, rootDir),
|
|
309
|
+
assetTransformers: normalizeServices(mergedLwrGlobalConfig.assetTransformers, rootDir),
|
|
274
310
|
resourceProviders: normalizeServices(mergedLwrGlobalConfig.resourceProviders, rootDir),
|
|
275
311
|
viewProviders: normalizeServices(mergedLwrGlobalConfig.viewProviders, rootDir),
|
|
312
|
+
viewTransformers: normalizeServices(mergedLwrGlobalConfig.viewTransformers, rootDir),
|
|
276
313
|
routes: normalizeRoutes(mergedLwrGlobalConfig.routes, { rootDir, assets, contentDir, layoutsDir }),
|
|
277
314
|
errorRoutes: normalizeRoutes(mergedLwrGlobalConfig.errorRoutes, {
|
|
278
315
|
rootDir,
|