@lwrjs/core 0.5.11-alpha.2 → 0.6.0-alpha.11

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.
@@ -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 = 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(DEFAULT_ASSET_PROVIDERS, rootDir),
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,
@@ -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 = (0, import_shared_utils.deepFreeze)({
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,13 +212,19 @@ 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
- await (0, import_server_warmup.warmupServer)(config, app.getInternalRequestKey());
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
  });
208
225
  }
209
226
  async close() {
210
- await this.server.close();
227
+ this.server?.close && await this.server.close();
211
228
  }
212
229
  getInternalServer() {
213
230
  return this.app.getImpl();
@@ -220,7 +237,21 @@ async function generateStaticSite(config) {
220
237
  config = config || {};
221
238
  config.serverType = "fs";
222
239
  const lwrApp = createServer(config);
240
+ overrideConfigAsSrc(lwrApp);
223
241
  await lwrApp.init();
224
242
  const dispatcher = lwrApp.getInternalServer();
225
243
  await new import_static_generation.default().buildStaticApplication(lwrApp.getConfig(), dispatcher);
226
244
  }
245
+ function overrideConfigAsSrc(lwrApp) {
246
+ if ((0, import_shared_utils.getExperimentalFeatures)().ENABLE_FINGERPRINTS) {
247
+ const normalizedConfig = lwrApp.getConfig();
248
+ const routes = normalizedConfig.routes || [];
249
+ for (const route of routes) {
250
+ route.bootstrap = {
251
+ ...import_shared_utils.DEFAULT_LWR_BOOTSTRAP_CONFIG,
252
+ ...route.bootstrap,
253
+ configAsSrc: true
254
+ };
255
+ }
256
+ }
257
+ }
@@ -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 (let index = 0; index < bundleDef.bundleRecord.imports.length; index++) {
86
- const theImport = bundleDef.bundleRecord.imports[index];
87
- const id = await (0, import_shared_utils.getVersionedModuleId)(theImport.specifier, moduleRegistry);
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 (let index = 0; index < bundleDef.bundleRecord.dynamicImports.length; index++) {
94
- const theImport = bundleDef.bundleRecord.dynamicImports[index];
95
- const id = await (0, import_shared_utils.getVersionedModuleId)(theImport.specifier, moduleRegistry);
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
  }
@@ -278,7 +278,8 @@ function apiMiddleware(app, context) {
278
278
  ({moduleIds} = (0, import_shared_utils.getMappingIdentity)(req));
279
279
  const {runtimeEnvironment, runtimeParams} = requestContext;
280
280
  const importMetadata = await (0, import_shared_utils.getImportMetadataMappings)(moduleIds, runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler);
281
- res.type("application/json").send(importMetadata);
281
+ res.setMetadata({importMetadata});
282
+ res.status(200).type("application/json").send(importMetadata);
282
283
  } catch (e) {
283
284
  console.log(e);
284
285
  const error = (0, import_utils.createReturnStatus)(`mappings for "${JSON.stringify(moduleIds || req.params?.specifiers)}"`, e);
@@ -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};