@lwrjs/config 0.8.0-alpha.8 → 0.8.0

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.
@@ -29,16 +29,70 @@ __export(exports, {
29
29
  });
30
30
  var import_fs = __toModule(require("fs"));
31
31
  var import_path = __toModule(require("path"));
32
- var import_module = __toModule(require("module"));
33
32
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
33
  var import_package = __toModule(require("@lwrjs/config/package"));
35
34
  var import_app_config = __toModule(require("./validation/app-config.cjs"));
36
35
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
36
+ var RUNTIME_CONFIGS = {
37
+ dev: {
38
+ bundle: false,
39
+ minify: false,
40
+ format: "esm",
41
+ compat: "0",
42
+ watchFiles: true,
43
+ defaultLocale: "en_US",
44
+ hmrEnabled: true,
45
+ immutableAssets: false,
46
+ env: {
47
+ NODE_ENV: "development"
48
+ }
49
+ },
50
+ prod: {
51
+ bundle: true,
52
+ minify: true,
53
+ format: "esm",
54
+ compat: "0",
55
+ watchFiles: false,
56
+ defaultLocale: "en_US",
57
+ hmrEnabled: false,
58
+ immutableAssets: true,
59
+ env: {
60
+ NODE_ENV: "production"
61
+ }
62
+ },
63
+ compat: {
64
+ bundle: false,
65
+ minify: false,
66
+ format: "amd",
67
+ compat: "1",
68
+ watchFiles: true,
69
+ defaultLocale: "en_US",
70
+ hmrEnabled: false,
71
+ immutableAssets: false,
72
+ env: {
73
+ NODE_ENV: "development"
74
+ }
75
+ },
76
+ "prod-compat": {
77
+ bundle: true,
78
+ minify: true,
79
+ format: "amd",
80
+ compat: "1",
81
+ watchFiles: false,
82
+ defaultLocale: "en_US",
83
+ hmrEnabled: false,
84
+ immutableAssets: true,
85
+ env: {
86
+ NODE_ENV: "production"
87
+ }
88
+ }
89
+ };
37
90
  var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
38
91
  var MODE = process.env.MODE || "dev";
39
92
  var DEFAULT_BASE_PATH = "";
40
93
  var DEFAULT_API_VERSION = "1";
41
94
  var LWR_VERSION = import_package.version;
95
+ import_shared_utils.logger.info(`LWR Version: ${LWR_VERSION}`);
42
96
  var DEFAULT_SERVER_TYPE = "express";
43
97
  var DEFAULT_LWR_CONFIG_JSON = "$rootDir/lwr.config.json";
44
98
  var DEFAULT_GENERATOR_CONFIG = {
@@ -135,7 +189,7 @@ function getLwrConfigFromFile(rootDir, customDir = DEFAULT_LWR_CONFIG_JSON) {
135
189
  } catch (e) {
136
190
  if (e instanceof import_diagnostics.LwrConfigValidationError) {
137
191
  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");
192
+ import_shared_utils.logger.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
139
193
  console.dir(e, {depth: null});
140
194
  return JSON.parse(configAsString);
141
195
  } else {
@@ -145,17 +199,16 @@ function getLwrConfigFromFile(rootDir, customDir = DEFAULT_LWR_CONFIG_JSON) {
145
199
  return void 0;
146
200
  }
147
201
  } else {
148
- console.log(`[Warning] LWR Config not found on "${lwrConfigPath}"`);
202
+ import_shared_utils.logger.warn(`LWR Config not found on "${lwrConfigPath}"`);
149
203
  return void 0;
150
204
  }
151
205
  }
152
206
  function explodeMode(mode) {
153
- const modeConfigFile = import_path.default.join(import_package.rootPath, `./runtime-configs/${mode}.json`);
154
- if (!import_fs.default.existsSync(modeConfigFile)) {
207
+ const selectedMode = RUNTIME_CONFIGS[mode];
208
+ if (!selectedMode) {
155
209
  throw new Error(`No configuration found for server mode - ${mode}`);
156
210
  }
157
- const modeConfig = JSON.parse((0, import_shared_utils.readFile)(modeConfigFile));
158
- return modeConfig;
211
+ return selectedMode;
159
212
  }
160
213
  function normalizeServices(services, rootDir) {
161
214
  return services.map((service) => {
@@ -182,7 +235,7 @@ function normalizeModules(modules, rootDir) {
182
235
  }
183
236
  function normalizeRoutes(routes, resourcePaths) {
184
237
  return routes.map((route) => {
185
- const {routeHandler, contentTemplate, layoutTemplate} = route;
238
+ const {routeHandler, contentTemplate, layoutTemplate, subRoutes} = route;
186
239
  const bootstrap = {
187
240
  ...import_shared_utils.DEFAULT_LWR_BOOTSTRAP_CONFIG,
188
241
  ...route.bootstrap
@@ -192,7 +245,8 @@ function normalizeRoutes(routes, resourcePaths) {
192
245
  bootstrap,
193
246
  routeHandler: routeHandler && import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(routeHandler, resourcePaths.rootDir)),
194
247
  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))
248
+ layoutTemplate: layoutTemplate && import_path.default.resolve((0, import_shared_utils.normalizeResourcePath)(layoutTemplate, resourcePaths)),
249
+ subRoutes: subRoutes && import_path.default.resolve((0, import_shared_utils.normalizeResourcePath)(subRoutes, resourcePaths))
196
250
  };
197
251
  });
198
252
  }
@@ -252,11 +306,6 @@ function mergeLockerConfig(jsonConfig, config) {
252
306
  };
253
307
  }
254
308
  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
309
  return "@lwc/engine-dom";
261
310
  }
262
311
  function normalizeLwcConfig(config) {
@@ -279,7 +328,7 @@ function normalizeConfig(config) {
279
328
  (0, import_app_config.validateLwrAppConfig)(JSON.stringify(config), "pre");
280
329
  } catch (e) {
281
330
  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");
331
+ import_shared_utils.logger.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
283
332
  console.dir(e, {depth: null});
284
333
  } else {
285
334
  throw e;
@@ -79,6 +79,7 @@ var ASSET_FILE_ATTRIBUTE_KEYS = createKeys("assetFile", ["alias", "file", "urlPa
79
79
  var LOCKER_ATTRIBUTE_KEYS = createKeys("locker", ["enabled", "trustedComponents", "clientOnly"]);
80
80
  var ROUTE_ATTRIBUTE_KEYS = createKeys("routes", [
81
81
  "bootstrap",
82
+ "subRoutes",
82
83
  "contentTemplate",
83
84
  "id",
84
85
  "cache",
@@ -91,6 +92,7 @@ var ROUTE_ATTRIBUTE_KEYS = createKeys("routes", [
91
92
  ]);
92
93
  var ERROR_ROUTE_ATTRIBUTE_KEYS = createKeys("errorRoutes", [
93
94
  "bootstrap",
95
+ "subRoutes",
94
96
  "contentTemplate",
95
97
  "id",
96
98
  "layoutTemplate",
@@ -1,15 +1,69 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { createRequire } from 'module';
4
- import { ASSETS_CACHE_DIR, readFile, normalizeDirectory, normalizeResourcePath, DEFAULT_LWR_BOOTSTRAP_CONFIG, DEFAULT_LWR_LOCKER_CONFIG, DEFAULT_LOCKER_TRUSTED_CMP, normalizeInterchangeableModuleConfig, getFeatureFlags, } from '@lwrjs/shared-utils';
5
- import { rootPath, version } from '@lwrjs/config/package';
3
+ import { ASSETS_CACHE_DIR, readFile, normalizeDirectory, normalizeResourcePath, DEFAULT_LWR_BOOTSTRAP_CONFIG, DEFAULT_LWR_LOCKER_CONFIG, DEFAULT_LOCKER_TRUSTED_CMP, normalizeInterchangeableModuleConfig, getFeatureFlags, logger, } from '@lwrjs/shared-utils';
4
+ import { version } from '@lwrjs/config/package';
6
5
  import { validateLwrAppConfig } from './validation/app-config.js';
7
6
  import { LwrConfigValidationError } from '@lwrjs/diagnostics';
7
+ const RUNTIME_CONFIGS = {
8
+ dev: {
9
+ bundle: false,
10
+ minify: false,
11
+ format: 'esm',
12
+ compat: '0',
13
+ watchFiles: true,
14
+ defaultLocale: 'en_US',
15
+ hmrEnabled: true,
16
+ immutableAssets: false,
17
+ env: {
18
+ NODE_ENV: 'development',
19
+ },
20
+ },
21
+ prod: {
22
+ bundle: true,
23
+ minify: true,
24
+ format: 'esm',
25
+ compat: '0',
26
+ watchFiles: false,
27
+ defaultLocale: 'en_US',
28
+ hmrEnabled: false,
29
+ immutableAssets: true,
30
+ env: {
31
+ NODE_ENV: 'production',
32
+ },
33
+ },
34
+ compat: {
35
+ bundle: false,
36
+ minify: false,
37
+ format: 'amd',
38
+ compat: '1',
39
+ watchFiles: true,
40
+ defaultLocale: 'en_US',
41
+ hmrEnabled: false,
42
+ immutableAssets: false,
43
+ env: {
44
+ NODE_ENV: 'development',
45
+ },
46
+ },
47
+ 'prod-compat': {
48
+ bundle: true,
49
+ minify: true,
50
+ format: 'amd',
51
+ compat: '1',
52
+ watchFiles: false,
53
+ defaultLocale: 'en_US',
54
+ hmrEnabled: false,
55
+ immutableAssets: true,
56
+ env: {
57
+ NODE_ENV: 'production',
58
+ },
59
+ },
60
+ };
8
61
  const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
9
62
  const MODE = process.env.MODE || 'dev';
10
63
  const DEFAULT_BASE_PATH = '';
11
64
  const DEFAULT_API_VERSION = '1';
12
65
  const LWR_VERSION = version;
66
+ logger.info(`LWR Version: ${LWR_VERSION}`);
13
67
  const DEFAULT_SERVER_TYPE = 'express';
14
68
  const DEFAULT_LWR_CONFIG_JSON = '$rootDir/lwr.config.json';
15
69
  const DEFAULT_GENERATOR_CONFIG = {
@@ -112,7 +166,7 @@ function getLwrConfigFromFile(rootDir, customDir = DEFAULT_LWR_CONFIG_JSON) {
112
166
  if (e instanceof LwrConfigValidationError) {
113
167
  // TODO: temporary workaround for https://github.com/salesforce/lwr/issues/825
114
168
  if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
115
- console.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
169
+ logger.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
116
170
  console.dir(e, { depth: null });
117
171
  return JSON.parse(configAsString);
118
172
  }
@@ -124,17 +178,16 @@ function getLwrConfigFromFile(rootDir, customDir = DEFAULT_LWR_CONFIG_JSON) {
124
178
  }
125
179
  }
126
180
  else {
127
- console.log(`[Warning] LWR Config not found on "${lwrConfigPath}"`);
181
+ logger.warn(`LWR Config not found on "${lwrConfigPath}"`);
128
182
  return undefined;
129
183
  }
130
184
  }
131
185
  export function explodeMode(mode) {
132
- const modeConfigFile = path.join(rootPath, `./runtime-configs/${mode}.json`);
133
- if (!fs.existsSync(modeConfigFile)) {
186
+ const selectedMode = RUNTIME_CONFIGS[mode];
187
+ if (!selectedMode) {
134
188
  throw new Error(`No configuration found for server mode - ${mode}`);
135
189
  }
136
- const modeConfig = JSON.parse(readFile(modeConfigFile));
137
- return modeConfig;
190
+ return selectedMode;
138
191
  }
139
192
  function normalizeServices(services, rootDir) {
140
193
  return services.map((service) => {
@@ -163,7 +216,7 @@ function normalizeModules(modules, rootDir) {
163
216
  }
164
217
  function normalizeRoutes(routes, resourcePaths) {
165
218
  return routes.map((route) => {
166
- const { routeHandler, contentTemplate, layoutTemplate } = route;
219
+ const { routeHandler, contentTemplate, layoutTemplate, subRoutes } = route;
167
220
  const bootstrap = {
168
221
  ...DEFAULT_LWR_BOOTSTRAP_CONFIG,
169
222
  ...route.bootstrap,
@@ -175,6 +228,7 @@ function normalizeRoutes(routes, resourcePaths) {
175
228
  routeHandler: routeHandler && path.resolve(normalizeDirectory(routeHandler, resourcePaths.rootDir)),
176
229
  contentTemplate: contentTemplate && path.resolve(normalizeResourcePath(contentTemplate, resourcePaths)),
177
230
  layoutTemplate: layoutTemplate && path.resolve(normalizeResourcePath(layoutTemplate, resourcePaths)),
231
+ subRoutes: subRoutes && path.resolve(normalizeResourcePath(subRoutes, resourcePaths)),
178
232
  };
179
233
  });
180
234
  }
@@ -241,16 +295,8 @@ function mergeLockerConfig(jsonConfig, config) {
241
295
  trustedComponents: [...new Set([...defaultNamespaces, ...configNamespaces])],
242
296
  };
243
297
  }
244
- // Ensure correct engine since LWC 2+ changed engine packaging, see https://github.com/salesforce/lwr/issues/791
245
298
  function getLWCEngineSpecifier() {
246
- const require = createRequire(path.join(process.cwd(), './env-config.js'));
247
- // eslint-disable-next-line @typescript-eslint/no-var-requires
248
- const { version } = require('lwc/package.json');
249
- if (version && version.startsWith('1')) {
250
- return '@lwc/engine';
251
- }
252
- // default to engine for LWC version 2+
253
- return '@lwc/engine-dom';
299
+ return '@lwc/engine-dom'; // only support LWC version 2+
254
300
  }
255
301
  function normalizeLwcConfig(config) {
256
302
  return {
@@ -286,7 +332,7 @@ export function normalizeConfig(config) {
286
332
  catch (e) {
287
333
  // TODO: temporary workaround for https://github.com/salesforce/lwr/issues/825
288
334
  if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
289
- console.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
335
+ logger.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
290
336
  console.dir(e, { depth: null });
291
337
  }
292
338
  else {
@@ -19,8 +19,8 @@ export declare const ROOT_ATTRIBUTE_KEYS: ["amdLoader", "apiVersion", "assets",
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"];
22
- export declare const ROUTE_ATTRIBUTE_KEYS: ["bootstrap", "contentTemplate", "id", "cache", "layoutTemplate", "method", "path", "rootComponent", "routeHandler", "properties"];
23
- export declare const ERROR_ROUTE_ATTRIBUTE_KEYS: ["bootstrap", "contentTemplate", "id", "layoutTemplate", "rootComponent", "routeHandler", "status", "properties", "cache"];
22
+ export declare const ROUTE_ATTRIBUTE_KEYS: ["bootstrap", "subRoutes", "contentTemplate", "id", "cache", "layoutTemplate", "method", "path", "rootComponent", "routeHandler", "properties"];
23
+ export declare const ERROR_ROUTE_ATTRIBUTE_KEYS: ["bootstrap", "subRoutes", "contentTemplate", "id", "layoutTemplate", "rootComponent", "routeHandler", "status", "properties", "cache"];
24
24
  export declare const BOOTSTRAP_ATTRIBUTE_KEYS: ["autoBoot", "syntheticShadow", "workers", "services", "configAsSrc", "ssr"];
25
25
  export declare const BASE_PATH_REGEX: RegExp;
26
26
  export declare class ValidationContext {
@@ -45,6 +45,7 @@ export const ASSET_FILE_ATTRIBUTE_KEYS = createKeys('assetFile', ['alias', 'file
45
45
  export const LOCKER_ATTRIBUTE_KEYS = createKeys('locker', ['enabled', 'trustedComponents', 'clientOnly']);
46
46
  export const ROUTE_ATTRIBUTE_KEYS = createKeys('routes', [
47
47
  'bootstrap',
48
+ 'subRoutes',
48
49
  'contentTemplate',
49
50
  'id',
50
51
  'cache',
@@ -57,6 +58,7 @@ export const ROUTE_ATTRIBUTE_KEYS = createKeys('routes', [
57
58
  ]);
58
59
  export const ERROR_ROUTE_ATTRIBUTE_KEYS = createKeys('errorRoutes', [
59
60
  'bootstrap',
61
+ 'subRoutes',
60
62
  'contentTemplate',
61
63
  'id',
62
64
  'layoutTemplate',
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.8",
7
+ "version": "0.8.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -29,20 +29,19 @@
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/diagnostics": "0.8.0-alpha.8",
37
- "@lwrjs/shared-utils": "0.8.0-alpha.8",
35
+ "@lwrjs/diagnostics": "0.8.0",
36
+ "@lwrjs/shared-utils": "0.8.0",
38
37
  "fs-extra": "^10.1.0",
39
38
  "jsonc-parser": "^3.0.0"
40
39
  },
41
40
  "devDependencies": {
42
- "@lwrjs/types": "0.8.0-alpha.8"
41
+ "@lwrjs/types": "0.8.0"
43
42
  },
44
43
  "engines": {
45
44
  "node": ">=14.15.4 <19"
46
45
  },
47
- "gitHead": "345e7545d2d1d1f587567aacf0a072473c746d9e"
46
+ "gitHead": "6db460e470fb149ca282aaa293ad4f0be03ae4e8"
48
47
  }
@@ -1,13 +0,0 @@
1
- {
2
- "bundle": false,
3
- "minify": false,
4
- "format": "amd",
5
- "compat": "1",
6
- "watchFiles": true,
7
- "defaultLocale": "en_US",
8
- "hmrEnabled": false,
9
- "immutableAssets": false,
10
- "env": {
11
- "NODE_ENV": "development"
12
- }
13
- }
@@ -1,13 +0,0 @@
1
- {
2
- "bundle": false,
3
- "minify": false,
4
- "format": "esm",
5
- "compat": "0",
6
- "watchFiles": true,
7
- "defaultLocale": "en_US",
8
- "hmrEnabled": true,
9
- "immutableAssets": false,
10
- "env": {
11
- "NODE_ENV": "development"
12
- }
13
- }
@@ -1,13 +0,0 @@
1
- {
2
- "bundle": true,
3
- "minify": true,
4
- "format": "amd",
5
- "compat": "1",
6
- "watchFiles": false,
7
- "defaultLocale": "en_US",
8
- "hmrEnabled": false,
9
- "immutableAssets": true,
10
- "env": {
11
- "NODE_ENV": "production"
12
- }
13
- }
@@ -1,13 +0,0 @@
1
- {
2
- "bundle": true,
3
- "minify": true,
4
- "format": "esm",
5
- "compat": "0",
6
- "watchFiles": false,
7
- "defaultLocale": "en_US",
8
- "hmrEnabled": false,
9
- "immutableAssets": true,
10
- "env": {
11
- "NODE_ENV": "production"
12
- }
13
- }