@lwrjs/config 0.12.0-alpha.29 → 0.12.0-alpha.30

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.
@@ -52,7 +52,11 @@ function getLwrConfigFromFile(rootDir, lwrConfigPath = import_defaults.DEFAULT_L
52
52
  }
53
53
  const configSource = (0, import_shared_utils.readFile)(resolvedLwrConfigPath);
54
54
  (0, import_app_config.validateLwrAppConfig)(configSource, "file");
55
- return (0, import_jsonc_parser.parse)(configSource);
55
+ let parsedConfig = (0, import_jsonc_parser.parse)(configSource);
56
+ if (parsedConfig?.routes) {
57
+ parsedConfig.routes = parsedConfig.routes.filter((route) => route.path !== "/lwr-info");
58
+ }
59
+ return parsedConfig;
56
60
  }
57
61
  function createCacheFolder(cache, rootDir) {
58
62
  const cacheDir = (0, import_shared_utils.normalizeDirectory)(cache, rootDir);
@@ -68,7 +72,7 @@ function mergeConfig(configArg) {
68
72
  const rootDir = import_path.default.resolve(configArg?.rootDir || import_defaults.DEFAULT_ROOT_DIR);
69
73
  const configFile = !configArg?.ignoreLwrConfigFile ? getLwrConfigFromFile(rootDir, configArg?.lwrConfigFile) : void 0;
70
74
  if (configFile) {
71
- configFile.routes = (configFile?.routes ?? []).concat(import_defaults.DEFAULT_LWR_CONFIG.routes);
75
+ configFile.routes = [...import_defaults.DEFAULT_LWR_CONFIG.routes, ...configFile?.routes ?? []];
72
76
  }
73
77
  const bundleConfig = (0, import_merge.mergeBundleConfig)(configFile, configArg);
74
78
  if (bundleConfig.external) {
@@ -33,6 +33,17 @@ var import_routes = __toModule(require("./utils/routes.cjs"));
33
33
  var import_app_config = __toModule(require("./validation/app-config.cjs"));
34
34
  var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
35
35
  var import_defaults = __toModule(require("./defaults.cjs"));
36
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
37
+ function isInfoRoute(route) {
38
+ if (route.path === import_defaults.LWR_INFO_ROUTE.path && route.id === import_defaults.LWR_INFO_ROUTE.id) {
39
+ if (Array.isArray(route.routeHandler)) {
40
+ return route.routeHandler?.includes(`${import_defaults.LWR_INFO_ROUTE.routeHandler}`);
41
+ } else if (typeof route.routeHandler === "string") {
42
+ return route.routeHandler === import_defaults.LWR_INFO_ROUTE.routeHandler;
43
+ }
44
+ }
45
+ return false;
46
+ }
36
47
  async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globalData, skipValidate = false) {
37
48
  const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteConfigHooks});
38
49
  if (!hooks.length) {
@@ -45,11 +56,22 @@ async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globa
45
56
  }
46
57
  await hook.initConfigs(globalConfig, globalData, runtimeEnvironment);
47
58
  }
48
- const hasInfoRoute = globalConfig.routes.some((route) => route.id === import_defaults.LWR_INFO_ROUTE.id);
59
+ let filteredRoutes = globalConfig.routes.filter((e) => e.path !== "/lwr-info" || isInfoRoute(e));
60
+ if (filteredRoutes.length < globalConfig.routes.length) {
61
+ import_diagnostics.logger.warn({
62
+ label: "config hooks",
63
+ message: "config hook attempted to redefine protected /lwr-info path"
64
+ });
65
+ }
66
+ const hasInfoRoute = filteredRoutes.some((route) => isInfoRoute(route));
49
67
  if (!hasInfoRoute) {
50
- globalConfig.routes = [...globalConfig.routes, import_defaults.LWR_INFO_ROUTE];
68
+ filteredRoutes = [import_defaults.LWR_INFO_ROUTE, ...filteredRoutes];
69
+ import_diagnostics.logger.warn({
70
+ label: "config hooks",
71
+ message: "config hook attempted to remove /lwr-info route"
72
+ });
51
73
  }
52
- globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
74
+ globalConfig.routes = (0, import_routes.normalizeRoutes)(filteredRoutes, globalConfig.routeHandlers);
53
75
  globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes, globalConfig.routeHandlers);
54
76
  if (!skipValidate) {
55
77
  (0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
@@ -78,11 +100,22 @@ function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipValidate
78
100
  globalConfig.routes = onStartConfig.routes || [];
79
101
  globalConfig.errorRoutes = onStartConfig.errorRoutes || [];
80
102
  }
81
- const hasInfoRoute = globalConfig.routes.some((route) => route.id === import_defaults.LWR_INFO_ROUTE.id);
103
+ let filteredRoutes = globalConfig.routes.filter((e) => e.path !== "/lwr-info" || isInfoRoute(e));
104
+ if (filteredRoutes.length < globalConfig.routes.length) {
105
+ import_diagnostics.logger.warn({
106
+ label: "start hooks",
107
+ message: "onStart hook attempted to redefine protected /lwr-info path"
108
+ });
109
+ }
110
+ const hasInfoRoute = filteredRoutes.some((route) => isInfoRoute(route));
82
111
  if (!hasInfoRoute) {
83
- globalConfig.routes = [...globalConfig.routes, import_defaults.LWR_INFO_ROUTE];
112
+ filteredRoutes = [import_defaults.LWR_INFO_ROUTE, ...filteredRoutes];
113
+ import_diagnostics.logger.warn({
114
+ label: "start hooks",
115
+ message: "onStart hook attempted to remove /lwr-info route"
116
+ });
84
117
  }
85
- globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
118
+ globalConfig.routes = (0, import_routes.normalizeRoutes)(filteredRoutes, globalConfig.routeHandlers);
86
119
  globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes, globalConfig.routeHandlers);
87
120
  if (!skipValidate) {
88
121
  (0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
@@ -288,6 +288,9 @@ function validateLwrAppConfig(config, phase) {
288
288
  if (validationContext.diagnostics.length) {
289
289
  throw new import_diagnostics2.LwrConfigValidationError(`Configuration validation errors in ${SOURCE_BY_PHASE[phase]}`, validationContext.diagnostics);
290
290
  }
291
+ if (phase === "file" && jsonSourceText.includes("/lwr-info")) {
292
+ import_diagnostics.logger.warn({label: `config`, message: `LWR Config file attempted to override "/lwr-info" path`});
293
+ }
291
294
  span.end();
292
295
  return;
293
296
  } catch (err) {
@@ -35,7 +35,11 @@ export function getLwrConfigFromFile(rootDir, lwrConfigPath = DEFAULT_LWR_CONFIG
35
35
  }
36
36
  const configSource = readFile(resolvedLwrConfigPath);
37
37
  validateLwrAppConfig(configSource, 'file');
38
- return parse(configSource);
38
+ let parsedConfig = parse(configSource);
39
+ if (parsedConfig?.routes) {
40
+ parsedConfig.routes = parsedConfig.routes.filter(route => route.path !== '/lwr-info');
41
+ }
42
+ return parsedConfig;
39
43
  }
40
44
  /**
41
45
  * Normalize the cache directory path and create the directory
@@ -79,7 +83,7 @@ function mergeConfig(configArg) {
79
83
  : undefined;
80
84
  // merge default routes with the config file routes
81
85
  if (configFile) {
82
- configFile.routes = (configFile?.routes ?? []).concat(DEFAULT_LWR_CONFIG.routes);
86
+ configFile.routes = [...DEFAULT_LWR_CONFIG.routes, ...(configFile?.routes ?? [])];
83
87
  }
84
88
  // Merge the bundle configs
85
89
  const bundleConfig = mergeBundleConfig(configFile, configArg);
@@ -1,18 +1,4 @@
1
1
  import type { GlobalData, HooksPlugin, Instrumentation, NormalizedLwrGlobalConfig, RuntimeEnvironment, ServerContext } from '@lwrjs/types';
2
- /**
3
- * Run `initConfigs` hooks
4
- *
5
- * @remarks
6
- * Route normalization and validation will be executed after all config hooks have been executed.
7
- *
8
- * @privateRemarks
9
- * Changes to configurations are made by reference.
10
- *
11
- * @param hooks - hooks plugins
12
- * @param globalConfig - global configuration
13
- * @param runtimeEnvironment - runtime environment resolved from programmatic config and config file
14
- * @param globalData - resolved global data
15
- */
16
2
  export declare function executeConfigHooks(hooks: HooksPlugin[], globalConfig: NormalizedLwrGlobalConfig, runtimeEnvironment: RuntimeEnvironment, globalData: GlobalData, skipValidate?: boolean): Promise<void>;
17
3
  /**
18
4
  * Run `onStart` hooks
package/build/es/hooks.js CHANGED
@@ -2,7 +2,19 @@ import { normalizeRoutes } from './utils/routes.js';
2
2
  import { validateLwrAppConfig } from './validation/app-config.js';
3
3
  import { getTracer, ConfigSpan } from '@lwrjs/instrumentation';
4
4
  import { LWR_INFO_ROUTE } from './defaults.js';
5
- /**
5
+ import { logger } from '@lwrjs/diagnostics';
6
+ function isInfoRoute(route) {
7
+ if (route.path === LWR_INFO_ROUTE.path && route.id === LWR_INFO_ROUTE.id) {
8
+ if (Array.isArray(route.routeHandler)) {
9
+ return route.routeHandler?.includes(`${LWR_INFO_ROUTE.routeHandler}`);
10
+ }
11
+ else if (typeof route.routeHandler === 'string') {
12
+ return route.routeHandler === LWR_INFO_ROUTE.routeHandler;
13
+ }
14
+ }
15
+ return false;
16
+ }
17
+ /*
6
18
  * Run `initConfigs` hooks
7
19
  *
8
20
  * @remarks
@@ -29,11 +41,24 @@ export async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment
29
41
  // eslint-disable-next-line no-await-in-loop
30
42
  await hook.initConfigs(globalConfig, globalData, runtimeEnvironment);
31
43
  }
32
- const hasInfoRoute = globalConfig.routes.some(route => route.id === LWR_INFO_ROUTE.id);
44
+ // Check if /lwr-info was redefined
45
+ let filteredRoutes = globalConfig.routes.filter(e => e.path !== "/lwr-info" || isInfoRoute(e));
46
+ if (filteredRoutes.length < globalConfig.routes.length) {
47
+ logger.warn({
48
+ label: 'config hooks',
49
+ message: 'config hook attempted to redefine protected /lwr-info path',
50
+ });
51
+ }
52
+ // Check if /lwr-info was removed
53
+ const hasInfoRoute = filteredRoutes.some(route => isInfoRoute(route));
33
54
  if (!hasInfoRoute) {
34
- globalConfig.routes = [...globalConfig.routes, LWR_INFO_ROUTE];
55
+ filteredRoutes = [LWR_INFO_ROUTE, ...filteredRoutes];
56
+ logger.warn({
57
+ label: 'config hooks',
58
+ message: 'config hook attempted to remove /lwr-info route',
59
+ });
35
60
  }
36
- globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
61
+ globalConfig.routes = normalizeRoutes(filteredRoutes, globalConfig.routeHandlers);
37
62
  globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes, globalConfig.routeHandlers);
38
63
  if (!skipValidate) {
39
64
  validateLwrAppConfig(globalConfig, 'post');
@@ -77,12 +102,24 @@ export function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipV
77
102
  globalConfig.routes = (onStartConfig.routes || []);
78
103
  globalConfig.errorRoutes = (onStartConfig.errorRoutes || []);
79
104
  }
80
- // Check if Info Route was removed
81
- const hasInfoRoute = globalConfig.routes.some(route => route.id === LWR_INFO_ROUTE.id);
105
+ // Check if /lwr-info was redefined
106
+ let filteredRoutes = globalConfig.routes.filter(e => e.path !== "/lwr-info" || isInfoRoute(e));
107
+ if (filteredRoutes.length < globalConfig.routes.length) {
108
+ logger.warn({
109
+ label: 'start hooks',
110
+ message: 'onStart hook attempted to redefine protected /lwr-info path',
111
+ });
112
+ }
113
+ // Check if /lwr-info was removed
114
+ const hasInfoRoute = filteredRoutes.some(route => isInfoRoute(route));
82
115
  if (!hasInfoRoute) {
83
- globalConfig.routes = [...globalConfig.routes, LWR_INFO_ROUTE];
116
+ filteredRoutes = [LWR_INFO_ROUTE, ...filteredRoutes];
117
+ logger.warn({
118
+ label: 'start hooks',
119
+ message: 'onStart hook attempted to remove /lwr-info route',
120
+ });
84
121
  }
85
- globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
122
+ globalConfig.routes = normalizeRoutes(filteredRoutes, globalConfig.routeHandlers);
86
123
  globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes, globalConfig.routeHandlers);
87
124
  if (!skipValidate) {
88
125
  validateLwrAppConfig(globalConfig, 'post');
@@ -356,6 +356,9 @@ export function validateLwrAppConfig(config, phase) {
356
356
  if (validationContext.diagnostics.length) {
357
357
  throw new LwrConfigValidationError(`Configuration validation errors in ${SOURCE_BY_PHASE[phase]}`, validationContext.diagnostics);
358
358
  }
359
+ if (phase === 'file' && jsonSourceText.includes("/lwr-info")) {
360
+ logger.warn({ label: `config`, message: `LWR Config file attempted to override "/lwr-info" path` });
361
+ }
359
362
  span.end();
360
363
  return;
361
364
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.29",
7
+ "version": "0.12.0-alpha.30",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -42,14 +42,14 @@
42
42
  "test": "jest"
43
43
  },
44
44
  "dependencies": {
45
- "@lwrjs/diagnostics": "0.12.0-alpha.29",
46
- "@lwrjs/instrumentation": "0.12.0-alpha.29",
47
- "@lwrjs/shared-utils": "0.12.0-alpha.29",
45
+ "@lwrjs/diagnostics": "0.12.0-alpha.30",
46
+ "@lwrjs/instrumentation": "0.12.0-alpha.30",
47
+ "@lwrjs/shared-utils": "0.12.0-alpha.30",
48
48
  "fs-extra": "^11.2.0",
49
49
  "jsonc-parser": "^3.2.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@lwrjs/types": "0.12.0-alpha.29",
52
+ "@lwrjs/types": "0.12.0-alpha.30",
53
53
  "jest": "^26.6.3",
54
54
  "ts-jest": "^26.5.6"
55
55
  },
@@ -70,5 +70,5 @@
70
70
  "volta": {
71
71
  "extends": "../../../package.json"
72
72
  },
73
- "gitHead": "452c6d4343b2139e03147100eec8aed7d17d7c51"
73
+ "gitHead": "5273cb7ece90a3a28645cb1dfde9d315548605db"
74
74
  }