@lwrjs/core 0.8.0-alpha.1 → 0.8.0-alpha.4

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.
@@ -27,7 +27,7 @@ __export(exports, {
27
27
  runConfigurationsHook: () => runConfigurationsHook
28
28
  });
29
29
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
- var import_app_config = __toModule(require("../validation/app-config.cjs"));
30
+ var import_config = __toModule(require("@lwrjs/config"));
31
31
  function normalizeRoutesBootstrap({routes, errorRoutes}) {
32
32
  [...routes, ...errorRoutes].forEach((route) => {
33
33
  if (!route.bootstrap) {
@@ -40,7 +40,7 @@ async function runConfigurationsHook(hookPlugins, lwrConfig, dataConfig, runtime
40
40
  await hookPlugin.initConfigs(lwrConfig, dataConfig, runtimeConfig);
41
41
  }
42
42
  try {
43
- (0, import_app_config.validateLwrAppConfig)(JSON.stringify(lwrConfig), "post");
43
+ (0, import_config.validateLwrAppConfig)(JSON.stringify(lwrConfig), "post");
44
44
  } catch (e) {
45
45
  if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
46
46
  console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
@@ -36,7 +36,7 @@ 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
38
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
39
- var import_env_config = __toModule(require("./env-config.cjs"));
39
+ var import_config = __toModule(require("@lwrjs/config"));
40
40
  var import_lwr_app_observer = __toModule(require("./lwr-app-observer.cjs"));
41
41
  var import_locale_middleware = __toModule(require("./middlewares/locale-middleware.cjs"));
42
42
  var import_api_middleware = __toModule(require("./middlewares/api-middleware.cjs"));
@@ -69,7 +69,7 @@ async function initContext(app, server, rawLwrConfig) {
69
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
- ...(0, import_env_config.explodeMode)(serverMode),
72
+ ...(0, import_config.explodeMode)(serverMode),
73
73
  apiVersion,
74
74
  basePath,
75
75
  lwrVersion,
@@ -95,7 +95,7 @@ async function initContext(app, server, rawLwrConfig) {
95
95
  appEmitter,
96
96
  runtimeEnvironment: runtimeConfig
97
97
  }, lwrConfig);
98
- const moduleBundler = new import_module_bundler.LwrModuleBundler({moduleRegistry, appObserver}, lwrConfig);
98
+ const moduleBundler = new import_module_bundler.LwrModuleBundler({compiler, moduleRegistry, appObserver}, lwrConfig);
99
99
  const resourceRegistry = new import_resource_registry.LwrResourceRegistry();
100
100
  const viewRegistry = new import_view_registry.LwrViewRegistry({
101
101
  moduleRegistry,
@@ -186,13 +186,13 @@ async function initContext(app, server, rawLwrConfig) {
186
186
  var LwrApp = class {
187
187
  constructor(config) {
188
188
  this.initialized = false;
189
- this.config = (0, import_env_config.normalizeConfig)(config);
189
+ this.config = (0, import_config.normalizeConfig)(config);
190
190
  const {basePath} = this.config;
191
191
  this.app = (0, import_server.createInternalServer)(this.config.serverType, {basePath});
192
192
  this.server = this.app.createHttpServer();
193
193
  }
194
194
  setConfig(config) {
195
- this.config = (0, import_env_config.normalizeConfig)(config);
195
+ this.config = (0, import_config.normalizeConfig)(config);
196
196
  }
197
197
  getConfig() {
198
198
  return this.config;
@@ -29,14 +29,14 @@ __export(exports, {
29
29
  var import_static_generation = __toModule(require("./static-generation.cjs"));
30
30
  var import_dir = __toModule(require("./utils/dir.cjs"));
31
31
  var import_network_dispatcher = __toModule(require("./utils/network-dispatcher.cjs"));
32
- var import_env_config = __toModule(require("../env-config.cjs"));
32
+ var import_config = __toModule(require("@lwrjs/config"));
33
33
  async function warmupServer(config, internalRequestKey) {
34
34
  console.log("[Server Warmup] starting");
35
35
  const {routes, staticSiteGenerator, port, apiVersion, basePath, lwrVersion, serverMode} = config;
36
36
  staticSiteGenerator.outputDir = import_dir.skipDirCreation;
37
37
  const urlRewriteMap = new Map();
38
38
  const runtimeEnvironment = {
39
- ...(0, import_env_config.explodeMode)(serverMode),
39
+ ...(0, import_config.explodeMode)(serverMode),
40
40
  apiVersion,
41
41
  basePath,
42
42
  lwrVersion,
@@ -33,7 +33,7 @@ var import_path = __toModule(require("path"));
33
33
  var import_fs_extra = __toModule(require("fs-extra"));
34
34
  var import_stream = __toModule(require("./utils/stream.cjs"));
35
35
  var import_dir = __toModule(require("./utils/dir.cjs"));
36
- var import_env_config = __toModule(require("../env-config.cjs"));
36
+ var import_config = __toModule(require("@lwrjs/config"));
37
37
  var SiteGenerator = class {
38
38
  async buildStaticApplication(config, dispatcher) {
39
39
  const startTime = import_perf_hooks.performance.now();
@@ -48,7 +48,7 @@ var SiteGenerator = class {
48
48
  const urlRewriteMap = new Map();
49
49
  const {apiVersion, basePath, lwrVersion, serverMode} = config;
50
50
  const runtimeEnvironment = {
51
- ...(0, import_env_config.explodeMode)(serverMode),
51
+ ...(0, import_config.explodeMode)(serverMode),
52
52
  apiVersion,
53
53
  basePath,
54
54
  lwrVersion,
@@ -101,8 +101,8 @@ var SiteGenerator = class {
101
101
  const {visitedUrls} = siteConfig;
102
102
  if (!visitedUrls.has(url)) {
103
103
  visitedUrls.add(url);
104
- if (url.indexOf("/:") !== -1) {
105
- console.error("Skipped url with variable path segment: " + url);
104
+ if (url.indexOf("/:") !== -1 || url.indexOf("*") !== -1) {
105
+ console.error("Skipped generation of url with variable path segment: " + url);
106
106
  return;
107
107
  }
108
108
  let context;
@@ -183,7 +183,7 @@ var SiteGenerator = class {
183
183
  const {outputDir} = siteConfig;
184
184
  let fileName = "index.html";
185
185
  let directoryPath = url;
186
- if (url.endsWith(".html")) {
186
+ if (url.endsWith(".html") || url.endsWith(".xml")) {
187
187
  const lastPathIndex = url.lastIndexOf("/") + 1;
188
188
  fileName = url.substring(lastPathIndex, url.length);
189
189
  directoryPath = url.substring(0, lastPathIndex);
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_LWR_BOOTSTRAP_CONFIG } from '@lwrjs/shared-utils';
2
- import { validateLwrAppConfig } from '../validation/app-config.js';
2
+ import { validateLwrAppConfig } from '@lwrjs/config';
3
3
  // Add missing bootstrap objects to routes
4
4
  function normalizeRoutesBootstrap({ routes, errorRoutes }) {
5
5
  [...routes, ...errorRoutes].forEach((route) => {
package/build/es/index.js CHANGED
@@ -6,7 +6,7 @@ import { LwrResourceRegistry } from '@lwrjs/resource-registry';
6
6
  import { LwrAssetRegistry } from '@lwrjs/asset-registry';
7
7
  import { LwrViewRegistry } from '@lwrjs/view-registry';
8
8
  import { LwrServerError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
9
- import { normalizeConfig, explodeMode } from './env-config.js';
9
+ import { normalizeConfig, explodeMode } from '@lwrjs/config';
10
10
  import { LwrApplicationObserver } from './lwr-app-observer.js';
11
11
  import localeMiddleware from './middlewares/locale-middleware.js';
12
12
  import apiMiddleware from './middlewares/api-middleware.js';
@@ -70,7 +70,7 @@ async function initContext(app, server, rawLwrConfig) {
70
70
  appEmitter,
71
71
  runtimeEnvironment: runtimeConfig,
72
72
  }, lwrConfig);
73
- const moduleBundler = new LwrModuleBundler({ moduleRegistry, appObserver }, lwrConfig);
73
+ const moduleBundler = new LwrModuleBundler({ compiler, moduleRegistry, appObserver }, lwrConfig);
74
74
  const resourceRegistry = new LwrResourceRegistry();
75
75
  const viewRegistry = new LwrViewRegistry({
76
76
  moduleRegistry,
@@ -1,7 +1,7 @@
1
1
  import SiteGenerator from './static-generation.js';
2
2
  import { skipDirCreation } from './utils/dir.js';
3
3
  import NetworkDispatcher from './utils/network-dispatcher.js';
4
- import { explodeMode } from '../env-config.js';
4
+ import { explodeMode } from '@lwrjs/config';
5
5
  export async function warmupServer(config, internalRequestKey) {
6
6
  console.log('[Server Warmup] starting');
7
7
  const { routes, staticSiteGenerator, port, apiVersion, basePath, lwrVersion, serverMode } = config;
@@ -4,7 +4,7 @@ import { join, dirname, extname } from 'path';
4
4
  import fs from 'fs-extra';
5
5
  import { writeResponse } from './utils/stream.js';
6
6
  import { createDir, createResourceDir } from './utils/dir.js';
7
- import { explodeMode } from '../env-config.js';
7
+ import { explodeMode } from '@lwrjs/config';
8
8
  export default class SiteGenerator {
9
9
  /**
10
10
  * Build a static site in the configured directory
@@ -108,8 +108,8 @@ export default class SiteGenerator {
108
108
  visitedUrls.add(url); // Maintain a list of visited urls here to avoid potential infinite loops
109
109
  // Skip urls with path segment variables (i.e. '/custom/:bar')
110
110
  // Users can specify specific urls via the '_additionalRoutePaths' config property
111
- if (url.indexOf('/:') !== -1) {
112
- console.error('Skipped url with variable path segment: ' + url);
111
+ if (url.indexOf('/:') !== -1 || url.indexOf('*') !== -1) {
112
+ console.error('Skipped generation of url with variable path segment: ' + url);
113
113
  return;
114
114
  }
115
115
  // Generate resource
@@ -255,9 +255,9 @@ export default class SiteGenerator {
255
255
  const { outputDir } = siteConfig;
256
256
  let fileName = 'index.html';
257
257
  let directoryPath = url;
258
- // If we have a route path that ends with a .html file extension,
258
+ // If we have a route path that ends with a html or xml file extension,
259
259
  // use that last path segment for the file name
260
- if (url.endsWith('.html')) {
260
+ if (url.endsWith('.html') || url.endsWith('.xml')) {
261
261
  const lastPathIndex = url.lastIndexOf('/') + 1;
262
262
  fileName = url.substring(lastPathIndex, url.length);
263
263
  directoryPath = url.substring(0, lastPathIndex);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.1",
7
+ "version": "0.8.0-alpha.4",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -29,43 +29,42 @@
29
29
  "build/**/*.js",
30
30
  "build/**/*.cjs",
31
31
  "build/**/*.d.ts",
32
- "runtime-configs",
33
32
  "package.cjs"
34
33
  ],
35
34
  "dependencies": {
36
- "@lwrjs/app-service": "0.8.0-alpha.1",
37
- "@lwrjs/asset-registry": "0.8.0-alpha.1",
38
- "@lwrjs/asset-transformer": "0.8.0-alpha.1",
39
- "@lwrjs/base-template-engine": "0.8.0-alpha.1",
40
- "@lwrjs/base-view-provider": "0.8.0-alpha.1",
41
- "@lwrjs/base-view-transformer": "0.8.0-alpha.1",
42
- "@lwrjs/client-modules": "0.8.0-alpha.1",
43
- "@lwrjs/compiler": "0.8.0-alpha.1",
44
- "@lwrjs/diagnostics": "0.8.0-alpha.1",
45
- "@lwrjs/fs-asset-provider": "0.8.0-alpha.1",
46
- "@lwrjs/html-view-provider": "0.8.0-alpha.1",
47
- "@lwrjs/loader": "0.8.0-alpha.1",
48
- "@lwrjs/lwc-module-provider": "0.8.0-alpha.1",
49
- "@lwrjs/lwc-ssr": "0.8.0-alpha.1",
50
- "@lwrjs/markdown-view-provider": "0.8.0-alpha.1",
51
- "@lwrjs/module-bundler": "0.8.0-alpha.1",
52
- "@lwrjs/module-registry": "0.8.0-alpha.1",
53
- "@lwrjs/npm-module-provider": "0.8.0-alpha.1",
54
- "@lwrjs/nunjucks-view-provider": "0.8.0-alpha.1",
55
- "@lwrjs/o11y": "0.8.0-alpha.1",
56
- "@lwrjs/resource-registry": "0.8.0-alpha.1",
57
- "@lwrjs/router": "0.8.0-alpha.1",
58
- "@lwrjs/server": "0.8.0-alpha.1",
59
- "@lwrjs/shared-utils": "0.8.0-alpha.1",
60
- "@lwrjs/view-registry": "0.8.0-alpha.1",
35
+ "@lwrjs/app-service": "0.8.0-alpha.4",
36
+ "@lwrjs/asset-registry": "0.8.0-alpha.4",
37
+ "@lwrjs/asset-transformer": "0.8.0-alpha.4",
38
+ "@lwrjs/base-template-engine": "0.8.0-alpha.4",
39
+ "@lwrjs/base-view-provider": "0.8.0-alpha.4",
40
+ "@lwrjs/base-view-transformer": "0.8.0-alpha.4",
41
+ "@lwrjs/client-modules": "0.8.0-alpha.4",
42
+ "@lwrjs/compiler": "0.8.0-alpha.4",
43
+ "@lwrjs/config": "0.8.0-alpha.4",
44
+ "@lwrjs/diagnostics": "0.8.0-alpha.4",
45
+ "@lwrjs/fs-asset-provider": "0.8.0-alpha.4",
46
+ "@lwrjs/html-view-provider": "0.8.0-alpha.4",
47
+ "@lwrjs/loader": "0.8.0-alpha.4",
48
+ "@lwrjs/lwc-module-provider": "0.8.0-alpha.4",
49
+ "@lwrjs/lwc-ssr": "0.8.0-alpha.4",
50
+ "@lwrjs/markdown-view-provider": "0.8.0-alpha.4",
51
+ "@lwrjs/module-bundler": "0.8.0-alpha.4",
52
+ "@lwrjs/module-registry": "0.8.0-alpha.4",
53
+ "@lwrjs/npm-module-provider": "0.8.0-alpha.4",
54
+ "@lwrjs/nunjucks-view-provider": "0.8.0-alpha.4",
55
+ "@lwrjs/o11y": "0.8.0-alpha.4",
56
+ "@lwrjs/resource-registry": "0.8.0-alpha.4",
57
+ "@lwrjs/router": "0.8.0-alpha.4",
58
+ "@lwrjs/server": "0.8.0-alpha.4",
59
+ "@lwrjs/shared-utils": "0.8.0-alpha.4",
60
+ "@lwrjs/view-registry": "0.8.0-alpha.4",
61
61
  "fs-extra": "^10.1.0",
62
- "jsonc-parser": "^3.0.0",
63
62
  "ms": "^2.1.3",
64
63
  "path-to-regexp": "^6.2.0",
65
64
  "qs": "^6.9.4"
66
65
  },
67
66
  "devDependencies": {
68
- "@lwrjs/types": "0.8.0-alpha.1"
67
+ "@lwrjs/types": "0.8.0-alpha.4"
69
68
  },
70
69
  "peerDependencies": {
71
70
  "lwc": ">= 1.x <= 2.x"
@@ -73,5 +72,5 @@
73
72
  "engines": {
74
73
  "node": ">=14.15.4 <19"
75
74
  },
76
- "gitHead": "2718cc5abe11d0d6fd5375cf9205167b6f69e244"
75
+ "gitHead": "a0cca59d2ab1e7596f03812d00180f898217ce4d"
77
76
  }
@@ -1,339 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
11
- };
12
- var __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
- }
18
- return target;
19
- };
20
- var __toModule = (module2) => {
21
- return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
- };
23
-
24
- // packages/@lwrjs/core/src/env-config.ts
25
- __markAsModule(exports);
26
- __export(exports, {
27
- explodeMode: () => explodeMode,
28
- normalizeConfig: () => normalizeConfig
29
- });
30
- var import_fs = __toModule(require("fs"));
31
- var import_path = __toModule(require("path"));
32
- var import_module = __toModule(require("module"));
33
- var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
- var import_package = __toModule(require("@lwrjs/core/package"));
35
- var import_app_config = __toModule(require("./validation/app-config.cjs"));
36
- var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
37
- var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
38
- var MODE = process.env.MODE || "dev";
39
- var DEFAULT_BASE_PATH = "";
40
- var DEFAULT_API_VERSION = "1";
41
- var LWR_VERSION = import_package.version;
42
- var DEFAULT_SERVER_TYPE = "express";
43
- var DEFAULT_LWR_CONFIG_JSON = "$rootDir/lwr.config.json";
44
- var DEFAULT_GENERATOR_CONFIG = {
45
- outputDir: "__generated_site__",
46
- locales: ["en-US"],
47
- _additionalRoutePaths: []
48
- };
49
- var DEFAULT_ROOT_DIR = process.cwd();
50
- var DEFAULT_CACHE_FOLDER = "$rootDir/__lwr_cache__";
51
- var DEFAULT_ASSETS_DIR = "$rootDir/src/assets";
52
- var DEFAULT_CONTENT_DIR = "$rootDir/src/content";
53
- var DEFAULT_LAYOUTS_DIR = "$rootDir/src/layouts";
54
- var DEFAULT_DATA_DIR = "$rootDir/src/data";
55
- var DEFAULT_MODULE_PROVIDERS = [
56
- "@lwrjs/app-service/moduleProvider",
57
- "@lwrjs/lwc-ssr/moduleProvider",
58
- "@lwrjs/router/module-provider",
59
- "@lwrjs/lwc-module-provider",
60
- "@lwrjs/npm-module-provider"
61
- ];
62
- var DEFAULT_RESOURCE_PROVIDERS = ["@lwrjs/loader"];
63
- var DEFAULT_VIEW_PROVIDERS = [
64
- "@lwrjs/nunjucks-view-provider",
65
- "@lwrjs/html-view-provider",
66
- "@lwrjs/markdown-view-provider",
67
- "@lwrjs/base-view-provider"
68
- ];
69
- var DEFAULT_VIEW_TRANFORM_PLUGINS = ["@lwrjs/base-view-transformer", "@lwrjs/lwc-ssr/viewTransformer"];
70
- var DEFAULT_ASSET_PROVIDERS = ["@lwrjs/fs-asset-provider"];
71
- var DEFAULT_ASSET_TRANFORM_PLUGINS = ["@lwrjs/asset-transformer"];
72
- var DEFAULT_TEMPLATE_ENGINE = "@lwrjs/base-template-engine";
73
- var DEFAULT_AMD_LOADER = "lwr/loader";
74
- var DEFAULT_AMD_LOADER_LEGACY = "lwr/loaderLegacy";
75
- var DEFAULT_ESM_LOADER = "lwr/esmLoader";
76
- var DEFAULT_SERVICE_PACKAGE_NAME = /lwr-(\w+)-service/;
77
- var DEFAULT_LWR_MODULES = [
78
- {npm: getLWCEngineSpecifier()},
79
- {npm: "@lwrjs/client-modules"},
80
- {npm: "@lwrjs/loader"},
81
- {npm: "@lwrjs/o11y"},
82
- {npm: "@lwrjs/router"},
83
- {npm: "@lwc/synthetic-shadow"}
84
- ];
85
- var DEFAULT_BUNDLE_EXCLUSIONS = [
86
- "lwc",
87
- "@lwc/synthetic-shadow",
88
- "lwr/navigation",
89
- "lwr/esmLoader",
90
- "lwr/profiler"
91
- ];
92
- var DEFAULT_LWR_CONFIG = {
93
- port: PORT,
94
- ignoreLwrConfigFile: false,
95
- lwrConfigFile: DEFAULT_LWR_CONFIG_JSON,
96
- basePath: DEFAULT_BASE_PATH,
97
- rootDir: DEFAULT_ROOT_DIR,
98
- cacheDir: DEFAULT_CACHE_FOLDER,
99
- serverMode: MODE,
100
- apiVersion: DEFAULT_API_VERSION,
101
- assets: DEFAULT_ASSETS_DIR,
102
- assetProviders: DEFAULT_ASSET_PROVIDERS,
103
- assetTransformers: DEFAULT_ASSET_TRANFORM_PLUGINS,
104
- contentDir: DEFAULT_CONTENT_DIR,
105
- layoutsDir: DEFAULT_LAYOUTS_DIR,
106
- staticSiteGenerator: DEFAULT_GENERATOR_CONFIG,
107
- globalDataDir: DEFAULT_DATA_DIR,
108
- globalData: {},
109
- hooks: [],
110
- moduleProviders: DEFAULT_MODULE_PROVIDERS,
111
- resourceProviders: DEFAULT_RESOURCE_PROVIDERS,
112
- viewProviders: DEFAULT_VIEW_PROVIDERS,
113
- viewTransformers: DEFAULT_VIEW_TRANFORM_PLUGINS,
114
- templateEngine: DEFAULT_TEMPLATE_ENGINE,
115
- environment: {},
116
- lwc: {modules: []},
117
- routes: [],
118
- errorRoutes: [],
119
- bundleConfig: {exclude: DEFAULT_BUNDLE_EXCLUSIONS},
120
- serverType: DEFAULT_SERVER_TYPE,
121
- locker: import_shared_utils.DEFAULT_LWR_LOCKER_CONFIG
122
- };
123
- function createCacheFolder(cache, rootDir) {
124
- const cacheDir = (0, import_shared_utils.normalizeDirectory)(cache, rootDir);
125
- const absPath = import_path.default.resolve(cacheDir);
126
- import_fs.default.mkdirSync(import_path.default.join(absPath, import_shared_utils.ASSETS_CACHE_DIR), {recursive: true});
127
- return absPath;
128
- }
129
- function getLwrConfigFromFile(rootDir, customDir = DEFAULT_LWR_CONFIG_JSON) {
130
- const lwrConfigPath = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(customDir, rootDir));
131
- if (import_fs.default.existsSync(lwrConfigPath)) {
132
- const configAsString = (0, import_shared_utils.readFile)(lwrConfigPath);
133
- try {
134
- return (0, import_app_config.validateLwrAppConfig)(configAsString, "file");
135
- } catch (e) {
136
- if (e instanceof import_diagnostics.LwrConfigValidationError) {
137
- if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
138
- console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
139
- console.dir(e, {depth: null});
140
- return JSON.parse(configAsString);
141
- } else {
142
- throw e;
143
- }
144
- }
145
- return void 0;
146
- }
147
- } else {
148
- console.log(`[Warning] LWR Config not found on "${lwrConfigPath}"`);
149
- return void 0;
150
- }
151
- }
152
- function explodeMode(mode) {
153
- const modeConfigFile = import_path.default.join(import_package.rootPath, `./runtime-configs/${mode}.json`);
154
- if (!import_fs.default.existsSync(modeConfigFile)) {
155
- throw new Error(`No configuration found for server mode - ${mode}`);
156
- }
157
- const modeConfig = JSON.parse((0, import_shared_utils.readFile)(modeConfigFile));
158
- return modeConfig;
159
- }
160
- function normalizeServices(services, rootDir) {
161
- return services.map((service) => {
162
- const [serviceName, serviceConfig = void 0] = Array.isArray(service) ? service : [service];
163
- let rawServiceName = (0, import_shared_utils.normalizeDirectory)(serviceName, rootDir);
164
- if (!rawServiceName.startsWith("@") && !DEFAULT_SERVICE_PACKAGE_NAME.test(rawServiceName)) {
165
- rawServiceName = import_path.default.resolve(rawServiceName);
166
- }
167
- return [rawServiceName, serviceConfig];
168
- });
169
- }
170
- function normalizeModules(modules, rootDir) {
171
- return modules.map((m) => {
172
- const dirRecord = m;
173
- if (dirRecord.dir) {
174
- dirRecord.dir = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(dirRecord.dir, rootDir));
175
- }
176
- const aliasRecord = m;
177
- if (aliasRecord.path) {
178
- aliasRecord.path = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(aliasRecord.path, rootDir));
179
- }
180
- return m;
181
- });
182
- }
183
- function normalizeRoutes(routes, resourcePaths) {
184
- return routes.map((route) => {
185
- const {routeHandler, contentTemplate, layoutTemplate} = route;
186
- const bootstrap = {
187
- ...import_shared_utils.DEFAULT_LWR_BOOTSTRAP_CONFIG,
188
- ...route.bootstrap
189
- };
190
- return {
191
- ...route,
192
- bootstrap,
193
- routeHandler: routeHandler && import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(routeHandler, resourcePaths.rootDir)),
194
- contentTemplate: contentTemplate && import_path.default.resolve((0, import_shared_utils.normalizeResourcePath)(contentTemplate, resourcePaths)),
195
- layoutTemplate: layoutTemplate && import_path.default.resolve((0, import_shared_utils.normalizeResourcePath)(layoutTemplate, resourcePaths))
196
- };
197
- });
198
- }
199
- function normalizeAssetsDir(assets, rootDir) {
200
- if (typeof assets === "string") {
201
- return [
202
- {
203
- alias: "assetsDir",
204
- dir: (0, import_shared_utils.normalizeDirectory)(assets, rootDir),
205
- urlPath: "/public/assets"
206
- }
207
- ];
208
- } else {
209
- return assets.map((asset) => {
210
- const assetDir = asset.dir;
211
- const assetFile = asset.file;
212
- return {
213
- ...asset,
214
- dir: assetDir && (0, import_shared_utils.normalizeDirectory)(assetDir, rootDir),
215
- file: assetFile && (0, import_shared_utils.normalizeDirectory)(assetFile, rootDir)
216
- };
217
- });
218
- }
219
- }
220
- function mergeLWCConfigs(config1, config2) {
221
- const modules1 = config1?.lwc?.modules || [];
222
- const modules2 = config2?.lwc?.modules || [];
223
- const interchangeable1 = config1?.lwc?.interchangeable || [];
224
- const interchangeable2 = config2?.lwc?.interchangeable || [];
225
- const mergedInterchangeable = [...interchangeable1, ...interchangeable2];
226
- const interchangeableModules1 = config1?.lwc?.interchangeableModules || [];
227
- const interchangeableModules2 = config2?.lwc?.interchangeableModules || [];
228
- const mergedInterchangeableModules = [...interchangeableModules1, ...interchangeableModules2];
229
- return {
230
- modules: [...modules1, ...modules2],
231
- interchangeable: mergedInterchangeable.length ? mergedInterchangeable : void 0,
232
- interchangeableModules: mergedInterchangeableModules.length ? mergedInterchangeableModules : void 0
233
- };
234
- }
235
- function mergeBundleConfig(jsonConfig, config) {
236
- const defaultExclusions = config?.bundleConfig?.UNSAFE_lwrDefaultExclude || jsonConfig?.bundleConfig?.UNSAFE_lwrDefaultExclude || DEFAULT_BUNDLE_EXCLUSIONS;
237
- const configExclusions = config?.bundleConfig?.exclude || jsonConfig?.bundleConfig?.exclude || [];
238
- return {
239
- ...jsonConfig?.bundleConfig,
240
- ...config?.bundleConfig,
241
- exclude: [...new Set([...defaultExclusions, ...configExclusions])]
242
- };
243
- }
244
- function mergeLockerConfig(jsonConfig, config) {
245
- const defaultNamespaces = import_shared_utils.DEFAULT_LOCKER_TRUSTED_CMP;
246
- const configNamespaces = config?.locker?.trustedComponents || jsonConfig?.locker?.trustedComponents || [];
247
- return {
248
- ...import_shared_utils.DEFAULT_LWR_LOCKER_CONFIG,
249
- ...jsonConfig?.locker,
250
- ...config?.locker,
251
- trustedComponents: [...new Set([...defaultNamespaces, ...configNamespaces])]
252
- };
253
- }
254
- function getLWCEngineSpecifier() {
255
- const require2 = (0, import_module.createRequire)(import_path.default.join(process.cwd(), "./env-config.js"));
256
- const {version: version2} = require2("lwc/package.json");
257
- if (version2 && version2.startsWith("1")) {
258
- return "@lwc/engine";
259
- }
260
- return "@lwc/engine-dom";
261
- }
262
- function normalizeLwcConfig(config) {
263
- return {
264
- ...config,
265
- interchangeableModulesMap: config.interchangeableModules ? (0, import_shared_utils.normalizeInterchangeableModuleConfig)(config.interchangeableModules) : void 0
266
- };
267
- }
268
- function trimLwrConfig(config) {
269
- Object.keys(config).forEach((k) => {
270
- if (config[k] === void 0)
271
- delete config[k];
272
- });
273
- return config;
274
- }
275
- function normalizeConfig(config) {
276
- if (config !== void 0) {
277
- config = trimLwrConfig(config);
278
- try {
279
- (0, import_app_config.validateLwrAppConfig)(JSON.stringify(config), "pre");
280
- } catch (e) {
281
- if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
282
- console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
283
- console.dir(e, {depth: null});
284
- } else {
285
- throw e;
286
- }
287
- }
288
- }
289
- const rootDir = import_path.default.resolve(config?.rootDir || DEFAULT_ROOT_DIR);
290
- const lwrJsonConfig = config?.ignoreLwrConfigFile === true ? void 0 : getLwrConfigFromFile(rootDir, config?.lwrConfigFile);
291
- const mergedLwrGlobalConfig = {
292
- ...DEFAULT_LWR_CONFIG,
293
- ...lwrJsonConfig,
294
- ...config,
295
- lwc: normalizeLwcConfig(mergeLWCConfigs(lwrJsonConfig, config)),
296
- bundleConfig: mergeBundleConfig(lwrJsonConfig, config),
297
- locker: mergeLockerConfig(lwrJsonConfig, config),
298
- staticSiteGenerator: {
299
- ...DEFAULT_GENERATOR_CONFIG,
300
- ...lwrJsonConfig?.staticSiteGenerator,
301
- ...config?.staticSiteGenerator
302
- },
303
- rootDir
304
- };
305
- const assets = normalizeAssetsDir(mergedLwrGlobalConfig.assets, rootDir);
306
- const contentDir = (0, import_shared_utils.normalizeDirectory)(mergedLwrGlobalConfig.contentDir, rootDir);
307
- const layoutsDir = (0, import_shared_utils.normalizeDirectory)(mergedLwrGlobalConfig.layoutsDir, rootDir);
308
- const amdLoader = (0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER ? DEFAULT_AMD_LOADER_LEGACY : DEFAULT_AMD_LOADER;
309
- return {
310
- ...mergedLwrGlobalConfig,
311
- assets,
312
- contentDir,
313
- layoutsDir,
314
- globalDataDir: (0, import_shared_utils.normalizeDirectory)(mergedLwrGlobalConfig.globalDataDir, rootDir),
315
- hooks: normalizeServices(mergedLwrGlobalConfig.hooks, rootDir),
316
- cacheDir: createCacheFolder(mergedLwrGlobalConfig.cacheDir, rootDir),
317
- lwc: {
318
- modules: normalizeModules([...DEFAULT_LWR_MODULES, ...mergedLwrGlobalConfig.lwc.modules], rootDir),
319
- interchangeable: mergedLwrGlobalConfig.lwc.interchangeable,
320
- interchangeableModulesMap: mergedLwrGlobalConfig.lwc.interchangeableModulesMap
321
- },
322
- moduleProviders: normalizeServices(mergedLwrGlobalConfig.moduleProviders, rootDir),
323
- assetProviders: normalizeServices(mergedLwrGlobalConfig.assetProviders, rootDir),
324
- assetTransformers: normalizeServices(mergedLwrGlobalConfig.assetTransformers, rootDir),
325
- resourceProviders: normalizeServices(mergedLwrGlobalConfig.resourceProviders, rootDir),
326
- viewProviders: normalizeServices(mergedLwrGlobalConfig.viewProviders, rootDir),
327
- viewTransformers: normalizeServices(mergedLwrGlobalConfig.viewTransformers, rootDir),
328
- routes: normalizeRoutes(mergedLwrGlobalConfig.routes, {rootDir, assets, contentDir, layoutsDir}),
329
- errorRoutes: normalizeRoutes(mergedLwrGlobalConfig.errorRoutes, {
330
- rootDir,
331
- assets,
332
- contentDir,
333
- layoutsDir
334
- }),
335
- amdLoader,
336
- esmLoader: DEFAULT_ESM_LOADER,
337
- lwrVersion: LWR_VERSION
338
- };
339
- }