@lwrjs/config 0.12.0-alpha.9 → 0.12.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.
@@ -35,6 +35,7 @@ __export(exports, {
35
35
  DEFAULT_LWR_MODULES: () => DEFAULT_LWR_MODULES,
36
36
  DEFAULT_ROOT_DIR: () => DEFAULT_ROOT_DIR,
37
37
  DEFAULT_SERVICE_PACKAGE_NAME: () => DEFAULT_SERVICE_PACKAGE_NAME,
38
+ LWR_INFO_ROUTE: () => LWR_INFO_ROUTE,
38
39
  LWR_VERSION: () => LWR_VERSION,
39
40
  getDefaultBundleConfig: () => getDefaultBundleConfig
40
41
  });
@@ -66,7 +67,8 @@ var DEFAULT_MODULE_PROVIDERS = [
66
67
  "@lwrjs/router/module-provider",
67
68
  "@lwrjs/lwc-module-provider",
68
69
  "@lwrjs/lwc-ssr/moduleProvider",
69
- "@lwrjs/npm-module-provider"
70
+ "@lwrjs/npm-module-provider",
71
+ "@lwrjs/module-registry/externals-module-provider"
70
72
  ];
71
73
  var DEFAULT_RESOURCE_PROVIDERS = ["@lwrjs/loader"];
72
74
  var DEFAULT_VIEW_PROVIDERS = [
@@ -110,12 +112,12 @@ var DEFAULT_ESM_BUNDLE_EXCLUSIONS = [
110
112
  var DEFAULT_AMD_BUNDLE_EXCLUSIONS = ["lwc", "lwr/navigation"];
111
113
  var DEFAULT_ESM_BUNDLE_EXTERNALS = {};
112
114
  var DEFAULT_AMD_BUNDLE_EXTERNALS = {
113
- "lwr/loader": "lwr-loader-shim.bundle.min.js",
114
- "lwr/profiler": "lwr-loader-shim.bundle.min.js"
115
+ "lwr/loader": "",
116
+ "lwr/profiler": ""
115
117
  };
116
118
  var DEFAULT_AMD_LEGACY_BUNDLE_EXTERNALS = {
117
- "lwr/loaderLegacy": "lwr-loader-shim-legacy.bundle.min.js",
118
- "lwr/profiler": "lwr-loader-shim-legacy.bundle.min.js"
119
+ "lwr/loaderLegacy": "",
120
+ "lwr/profiler": ""
119
121
  };
120
122
  function getDefaultBundleConfig(mode) {
121
123
  const format = (0, import_runtime_config.getServerModeConfig)(mode || MODE).format;
@@ -125,6 +127,11 @@ function getDefaultBundleConfig(mode) {
125
127
  external: format === "esm" ? DEFAULT_ESM_BUNDLE_EXTERNALS : loaderLegacy ? DEFAULT_AMD_LEGACY_BUNDLE_EXTERNALS : DEFAULT_AMD_BUNDLE_EXTERNALS
126
128
  };
127
129
  }
130
+ var LWR_INFO_ROUTE = {
131
+ id: "lwrInfo",
132
+ path: "/lwr-info",
133
+ routeHandler: `@lwrjs/core/info/route-handler`
134
+ };
128
135
  var DEFAULT_LWR_CONFIG = {
129
136
  port: PORT,
130
137
  ignoreLwrConfigFile: false,
@@ -152,11 +159,7 @@ var DEFAULT_LWR_CONFIG = {
152
159
  environment: {},
153
160
  lwc: {modules: []},
154
161
  routes: [
155
- {
156
- id: "lwrInfo",
157
- path: "/lwr-info",
158
- routeHandler: `@lwrjs/core/info/route-handler`
159
- }
162
+ LWR_INFO_ROUTE
160
163
  ],
161
164
  errorRoutes: [],
162
165
  routeHandlers: {},
@@ -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,14 +72,23 @@ 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 ?? []];
76
+ }
77
+ const bundleConfig = (0, import_merge.mergeBundleConfig)(configFile, configArg);
78
+ if (bundleConfig.external) {
79
+ for (const key of Object.keys(bundleConfig.external)) {
80
+ const path2 = bundleConfig.external[key];
81
+ if ((0, import_shared_utils.isLocalPath)(path2)) {
82
+ bundleConfig.external[key] = (0, import_shared_utils.normalizeToFileUrl)(path2, rootDir);
83
+ }
84
+ }
72
85
  }
73
86
  return {
74
87
  ...import_defaults.DEFAULT_LWR_CONFIG,
75
88
  ...configFile,
76
89
  ...configArg,
77
90
  lwc: (0, import_merge.mergeLwcConfig)(configFile, configArg),
78
- bundleConfig: (0, import_merge.mergeBundleConfig)(configFile, configArg),
91
+ bundleConfig,
79
92
  locker: (0, import_merge.mergeLockerConfig)(configFile, configArg),
80
93
  staticSiteGenerator: (0, import_merge.mergeStaticGenerationConfig)(configFile, configArg),
81
94
  rootDir
@@ -143,7 +156,8 @@ function applyStaticProviderConfig(config) {
143
156
  resourceProviders: [["@lwrjs/static/resource-provider", {}]],
144
157
  moduleProviders: [
145
158
  ["@lwrjs/static/module-provider", void 0],
146
- ["@lwrjs/lwc-ssr/moduleProvider", void 0]
159
+ ["@lwrjs/lwc-ssr/moduleProvider", void 0],
160
+ ["@lwrjs/module-registry/externals-module-provider", void 0]
147
161
  ],
148
162
  bundleProviders: [
149
163
  ["@lwrjs/static/bundle-provider", void 0],
@@ -25,12 +25,25 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  executeConfigHooks: () => executeConfigHooks,
28
+ executeContextHooks: () => executeContextHooks,
28
29
  executeInstrumentationHooks: () => executeInstrumentationHooks,
29
30
  executeStartHooks: () => executeStartHooks
30
31
  });
31
32
  var import_routes = __toModule(require("./utils/routes.cjs"));
32
33
  var import_app_config = __toModule(require("./validation/app-config.cjs"));
33
34
  var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
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
+ }
34
47
  async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globalData, skipValidate = false) {
35
48
  const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteConfigHooks});
36
49
  if (!hooks.length) {
@@ -43,7 +56,22 @@ async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globa
43
56
  }
44
57
  await hook.initConfigs(globalConfig, globalData, runtimeEnvironment);
45
58
  }
46
- globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
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));
67
+ if (!hasInfoRoute) {
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
+ });
73
+ }
74
+ globalConfig.routes = (0, import_routes.normalizeRoutes)(filteredRoutes, globalConfig.routeHandlers);
47
75
  globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes, globalConfig.routeHandlers);
48
76
  if (!skipValidate) {
49
77
  (0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
@@ -72,7 +100,22 @@ function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipValidate
72
100
  globalConfig.routes = onStartConfig.routes || [];
73
101
  globalConfig.errorRoutes = onStartConfig.errorRoutes || [];
74
102
  }
75
- globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
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));
111
+ if (!hasInfoRoute) {
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
+ });
117
+ }
118
+ globalConfig.routes = (0, import_routes.normalizeRoutes)(filteredRoutes, globalConfig.routeHandlers);
76
119
  globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes, globalConfig.routeHandlers);
77
120
  if (!skipValidate) {
78
121
  (0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
@@ -81,14 +124,33 @@ function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipValidate
81
124
  }
82
125
  function executeInstrumentationHooks(hooks) {
83
126
  const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteInstrHooks});
84
- let retVal = false;
127
+ const instrumentation = [];
85
128
  for (const hook of hooks) {
86
129
  if (!hook.initInstrumentation) {
87
130
  continue;
88
131
  }
89
- retVal = true;
90
- hook.initInstrumentation();
132
+ instrumentation.push(hook.initInstrumentation());
91
133
  }
92
134
  span.end();
93
- return retVal;
135
+ if (!instrumentation.length) {
136
+ return void 0;
137
+ }
138
+ return {
139
+ flush() {
140
+ for (const instance of instrumentation) {
141
+ instance.flush();
142
+ }
143
+ }
144
+ };
145
+ }
146
+ async function executeContextHooks(hooks, serverContext) {
147
+ if (!hooks.length) {
148
+ return;
149
+ }
150
+ for (const hook of hooks) {
151
+ if (!hook.setupServerContext) {
152
+ continue;
153
+ }
154
+ await hook.setupServerContext(serverContext, hooks);
155
+ }
94
156
  }
@@ -28,9 +28,6 @@ __export(exports, {
28
28
  LWR_VERSION: () => import_package.lwrVersion,
29
29
  NODE_VERSION: () => import_package.nodeVersion,
30
30
  PWA_KIT_RUNTIME_VERSION: () => import_package.pwaKitRuntimeVersion,
31
- executeConfigHooks: () => import_hooks.executeConfigHooks,
32
- executeInstrumentationHooks: () => import_hooks.executeInstrumentationHooks,
33
- executeStartHooks: () => import_hooks.executeStartHooks,
34
31
  getLwrConfigFromFile: () => import_global_config.getLwrConfigFromFile,
35
32
  getRuntimeEnvironment: () => import_runtime_config.getRuntimeEnvironment,
36
33
  loadConfig: () => import_global_config.loadConfig,
@@ -40,5 +37,5 @@ __export(exports, {
40
37
  var import_package = __toModule(require("@lwrjs/config/package"));
41
38
  var import_global_config = __toModule(require("./global-config.cjs"));
42
39
  var import_runtime_config = __toModule(require("./runtime-config.cjs"));
43
- var import_hooks = __toModule(require("./hooks.cjs"));
40
+ __exportStar(exports, __toModule(require("./hooks.cjs")));
44
41
  var import_app_config = __toModule(require("./validation/app-config.cjs"));
@@ -100,7 +100,7 @@ var RUNTIME_CONFIGS = {
100
100
  function getServerModeConfig(serverMode) {
101
101
  const selectedMode = RUNTIME_CONFIGS[serverMode];
102
102
  if (!selectedMode) {
103
- throw (0, import_diagnostics.createSingleDiagnosticError)({description: import_diagnostics.descriptions.SERVER.INVALID_MODE(serverMode)}, import_diagnostics.LwrServerError);
103
+ throw (0, import_diagnostics.createSingleDiagnosticError)({description: import_diagnostics.descriptions.UNRESOLVABLE.INVALID_MODE(serverMode)}, import_diagnostics.LwrServerError);
104
104
  }
105
105
  return selectedMode;
106
106
  }
@@ -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) {
@@ -1,4 +1,4 @@
1
- import type { BundleConfig, LwrGlobalConfig, StaticSiteGenerator } from '@lwrjs/types';
1
+ import type { BundleConfig, LwrGlobalConfig, LwrRoute, StaticSiteGenerator } from '@lwrjs/types';
2
2
  export declare const LWR_VERSION: string;
3
3
  export declare const DEFAULT_LWR_CONFIG_JSON = "$rootDir/lwr.config.json";
4
4
  export declare const DEFAULT_GENERATOR_CONFIG: StaticSiteGenerator;
@@ -13,5 +13,6 @@ export declare const DEFAULT_LWR_MODULES: {
13
13
  export declare const DEFAULT_ESM_BUNDLE_EXCLUSIONS: string[];
14
14
  export declare const DEFAULT_AMD_BUNDLE_EXCLUSIONS: string[];
15
15
  export declare function getDefaultBundleConfig(mode?: string): BundleConfig;
16
+ export declare const LWR_INFO_ROUTE: LwrRoute;
16
17
  export declare const DEFAULT_LWR_CONFIG: Required<LwrGlobalConfig>;
17
18
  //# sourceMappingURL=defaults.d.ts.map
@@ -29,6 +29,7 @@ const DEFAULT_MODULE_PROVIDERS = [
29
29
  '@lwrjs/lwc-module-provider',
30
30
  '@lwrjs/lwc-ssr/moduleProvider',
31
31
  '@lwrjs/npm-module-provider',
32
+ '@lwrjs/module-registry/externals-module-provider',
32
33
  ];
33
34
  const DEFAULT_RESOURCE_PROVIDERS = ['@lwrjs/loader'];
34
35
  const DEFAULT_VIEW_PROVIDERS = [
@@ -72,12 +73,12 @@ export const DEFAULT_ESM_BUNDLE_EXCLUSIONS = [
72
73
  export const DEFAULT_AMD_BUNDLE_EXCLUSIONS = ['lwc', 'lwr/navigation'];
73
74
  const DEFAULT_ESM_BUNDLE_EXTERNALS = {};
74
75
  const DEFAULT_AMD_BUNDLE_EXTERNALS = {
75
- 'lwr/loader': 'lwr-loader-shim.bundle.min.js',
76
- 'lwr/profiler': 'lwr-loader-shim.bundle.min.js',
76
+ 'lwr/loader': '',
77
+ 'lwr/profiler': '',
77
78
  };
78
79
  const DEFAULT_AMD_LEGACY_BUNDLE_EXTERNALS = {
79
- 'lwr/loaderLegacy': 'lwr-loader-shim-legacy.bundle.min.js',
80
- 'lwr/profiler': 'lwr-loader-shim-legacy.bundle.min.js',
80
+ 'lwr/loaderLegacy': '',
81
+ 'lwr/profiler': '',
81
82
  };
82
83
  export function getDefaultBundleConfig(mode) {
83
84
  const format = getServerModeConfig(mode || MODE).format;
@@ -91,6 +92,11 @@ export function getDefaultBundleConfig(mode) {
91
92
  : DEFAULT_AMD_BUNDLE_EXTERNALS,
92
93
  };
93
94
  }
95
+ export const LWR_INFO_ROUTE = {
96
+ id: 'lwrInfo',
97
+ path: '/lwr-info',
98
+ routeHandler: `@lwrjs/core/info/route-handler`
99
+ };
94
100
  export const DEFAULT_LWR_CONFIG = {
95
101
  port: PORT,
96
102
  ignoreLwrConfigFile: false,
@@ -118,11 +124,7 @@ export const DEFAULT_LWR_CONFIG = {
118
124
  environment: {},
119
125
  lwc: { modules: [] },
120
126
  routes: [
121
- {
122
- id: 'lwrInfo',
123
- path: '/lwr-info',
124
- routeHandler: `@lwrjs/core/info/route-handler`,
125
- },
127
+ LWR_INFO_ROUTE,
126
128
  ],
127
129
  errorRoutes: [],
128
130
  routeHandlers: {},
@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { parse } from 'jsonc-parser';
4
4
  import { logger } from '@lwrjs/diagnostics';
5
- import { readFile, normalizeDirectory, getFeatureFlags, ASSETS_CACHE_DIR } from '@lwrjs/shared-utils';
5
+ import { readFile, normalizeDirectory, getFeatureFlags, ASSETS_CACHE_DIR, isLocalPath, normalizeToFileUrl } from '@lwrjs/shared-utils';
6
6
  import { DEFAULT_AMD_LOADER, DEFAULT_AMD_LOADER_LEGACY, DEFAULT_ESM_LOADER, DEFAULT_LWR_CONFIG, DEFAULT_LWR_CONFIG_JSON, DEFAULT_ROOT_DIR, LWR_VERSION, } from './defaults.js';
7
7
  import { validateLwrAppConfig } from './validation/app-config.js';
8
8
  import { normalizeAssetPaths, normalizeAssets } from './utils/assets.js';
@@ -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,18 @@ 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 ?? [])];
87
+ }
88
+ // Merge the bundle configs
89
+ const bundleConfig = mergeBundleConfig(configFile, configArg);
90
+ // Normalize external file paths to absolute file URLs
91
+ if (bundleConfig.external) {
92
+ for (const key of Object.keys(bundleConfig.external)) {
93
+ const path = bundleConfig.external[key];
94
+ if (isLocalPath(path)) {
95
+ bundleConfig.external[key] = normalizeToFileUrl(path, rootDir);
96
+ }
97
+ }
83
98
  }
84
99
  // merge the various configs in order of priority
85
100
  return {
@@ -88,7 +103,7 @@ function mergeConfig(configArg) {
88
103
  ...configArg,
89
104
  // merge nested configurations
90
105
  lwc: mergeLwcConfig(configFile, configArg),
91
- bundleConfig: mergeBundleConfig(configFile, configArg),
106
+ bundleConfig,
92
107
  locker: mergeLockerConfig(configFile, configArg),
93
108
  staticSiteGenerator: mergeStaticGenerationConfig(configFile, configArg),
94
109
  // root dir set by the config file will be ignored
@@ -190,6 +205,7 @@ export function applyStaticProviderConfig(config) {
190
205
  moduleProviders: [
191
206
  ['@lwrjs/static/module-provider', undefined],
192
207
  ['@lwrjs/lwc-ssr/moduleProvider', undefined],
208
+ ['@lwrjs/module-registry/externals-module-provider', undefined],
193
209
  ],
194
210
  bundleProviders: [
195
211
  ['@lwrjs/static/bundle-provider', undefined],
@@ -1,18 +1,4 @@
1
- import type { GlobalData, HooksPlugin, NormalizedLwrGlobalConfig, RuntimeEnvironment } 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
- */
1
+ import type { GlobalData, HooksPlugin, Instrumentation, NormalizedLwrGlobalConfig, RuntimeEnvironment, ServerContext } from '@lwrjs/types';
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
@@ -29,5 +15,6 @@ export declare function executeConfigHooks(hooks: HooksPlugin[], globalConfig: N
29
15
  * @param globalConfig - global configuration
30
16
  */
31
17
  export declare function executeStartHooks(hooks: HooksPlugin[], globalConfig: NormalizedLwrGlobalConfig, runtimeEnvironment: RuntimeEnvironment, skipValidate?: boolean): void;
32
- export declare function executeInstrumentationHooks(hooks: HooksPlugin[]): boolean;
18
+ export declare function executeInstrumentationHooks(hooks: HooksPlugin[]): Instrumentation | undefined;
19
+ export declare function executeContextHooks(hooks: HooksPlugin[], serverContext: ServerContext): Promise<void>;
33
20
  //# sourceMappingURL=hooks.d.ts.map
package/build/es/hooks.js CHANGED
@@ -1,7 +1,20 @@
1
1
  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
+ 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
+ /*
5
18
  * Run `initConfigs` hooks
6
19
  *
7
20
  * @remarks
@@ -28,7 +41,24 @@ export async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment
28
41
  // eslint-disable-next-line no-await-in-loop
29
42
  await hook.initConfigs(globalConfig, globalData, runtimeEnvironment);
30
43
  }
31
- globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
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));
54
+ if (!hasInfoRoute) {
55
+ filteredRoutes = [LWR_INFO_ROUTE, ...filteredRoutes];
56
+ logger.warn({
57
+ label: 'config hooks',
58
+ message: 'config hook attempted to remove /lwr-info route',
59
+ });
60
+ }
61
+ globalConfig.routes = normalizeRoutes(filteredRoutes, globalConfig.routeHandlers);
32
62
  globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes, globalConfig.routeHandlers);
33
63
  if (!skipValidate) {
34
64
  validateLwrAppConfig(globalConfig, 'post');
@@ -72,7 +102,24 @@ export function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipV
72
102
  globalConfig.routes = (onStartConfig.routes || []);
73
103
  globalConfig.errorRoutes = (onStartConfig.errorRoutes || []);
74
104
  }
75
- globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
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));
115
+ if (!hasInfoRoute) {
116
+ filteredRoutes = [LWR_INFO_ROUTE, ...filteredRoutes];
117
+ logger.warn({
118
+ label: 'start hooks',
119
+ message: 'onStart hook attempted to remove /lwr-info route',
120
+ });
121
+ }
122
+ globalConfig.routes = normalizeRoutes(filteredRoutes, globalConfig.routeHandlers);
76
123
  globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes, globalConfig.routeHandlers);
77
124
  if (!skipValidate) {
78
125
  validateLwrAppConfig(globalConfig, 'post');
@@ -81,15 +128,35 @@ export function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipV
81
128
  }
82
129
  export function executeInstrumentationHooks(hooks) {
83
130
  const span = getTracer().startSpan({ name: ConfigSpan.ExecuteInstrHooks });
84
- let retVal = false;
131
+ const instrumentation = [];
85
132
  for (const hook of hooks) {
86
133
  if (!hook.initInstrumentation) {
87
134
  continue;
88
135
  }
89
- retVal = true;
90
- hook.initInstrumentation();
136
+ instrumentation.push(hook.initInstrumentation());
91
137
  }
92
138
  span.end();
93
- return retVal;
139
+ if (!instrumentation.length) {
140
+ return undefined;
141
+ }
142
+ return {
143
+ flush() {
144
+ for (const instance of instrumentation) {
145
+ instance.flush();
146
+ }
147
+ }
148
+ };
149
+ }
150
+ export async function executeContextHooks(hooks, serverContext) {
151
+ if (!hooks.length) {
152
+ return;
153
+ }
154
+ for (const hook of hooks) {
155
+ if (!hook.setupServerContext) {
156
+ continue;
157
+ }
158
+ // eslint-disable-next-line no-await-in-loop
159
+ await hook.setupServerContext(serverContext, hooks);
160
+ }
94
161
  }
95
162
  //# sourceMappingURL=hooks.js.map
@@ -1,6 +1,6 @@
1
1
  export { lwrVersion as LWR_VERSION, lwcVersion as LWC_VERSION, nodeVersion as NODE_VERSION, pwaKitRuntimeVersion as PWA_KIT_RUNTIME_VERSION, } from '@lwrjs/config/package';
2
2
  export { loadConfig, resolveGlobalConfig as normalizeConfig, getLwrConfigFromFile } from './global-config.js';
3
3
  export { getRuntimeEnvironment } from './runtime-config.js';
4
- export { executeConfigHooks, executeStartHooks, executeInstrumentationHooks } from './hooks.js';
4
+ export * from './hooks.js';
5
5
  export { validateLwrAppConfig } from './validation/app-config.js';
6
6
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { lwrVersion as LWR_VERSION, lwcVersion as LWC_VERSION, nodeVersion as NODE_VERSION, pwaKitRuntimeVersion as PWA_KIT_RUNTIME_VERSION, } from '@lwrjs/config/package';
2
2
  export { loadConfig, resolveGlobalConfig as normalizeConfig, getLwrConfigFromFile } from './global-config.js';
3
3
  export { getRuntimeEnvironment } from './runtime-config.js';
4
- export { executeConfigHooks, executeStartHooks, executeInstrumentationHooks } from './hooks.js';
4
+ export * from './hooks.js';
5
5
  export { validateLwrAppConfig } from './validation/app-config.js';
6
6
  //# sourceMappingURL=index.js.map
@@ -77,7 +77,7 @@ export const RUNTIME_CONFIGS = {
77
77
  export function getServerModeConfig(serverMode) {
78
78
  const selectedMode = RUNTIME_CONFIGS[serverMode];
79
79
  if (!selectedMode) {
80
- throw createSingleDiagnosticError({ description: descriptions.SERVER.INVALID_MODE(serverMode) }, LwrServerError);
80
+ throw createSingleDiagnosticError({ description: descriptions.UNRESOLVABLE.INVALID_MODE(serverMode) }, LwrServerError);
81
81
  }
82
82
  return selectedMode;
83
83
  }
@@ -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.cjs CHANGED
@@ -28,15 +28,18 @@ if (globalThis.LWC_VERSION) {
28
28
 
29
29
  // Get the PWA Kit Dev Runtime Version
30
30
  let pwaKitRuntimeVersion;
31
- try {
32
- const packageJsonPath = resolve.sync(`@salesforce/pwa-kit-runtime/package.json`);
33
- const { version: packageVersion } = JSON.parse(fs.readFileSync(packageJsonPath), 'utf-8');
34
- pwaKitRuntimeVersion = packageVersion;
35
- } catch(err) {
36
- console.log(`[config] peer dependency pwa-kit-runtime was not provided`);
37
- pwaKitRuntimeVersion = 'not-provided';
31
+ if (globalThis.PWA_KIT_RUNTIME_VERSION) {
32
+ pwaKitRuntimeVersion = globalThis.PWA_KIT_RUNTIME_VERSION;
33
+ } else {
34
+ try {
35
+ const packageJsonPath = resolve.sync(`@salesforce/pwa-kit-runtime/package.json`);
36
+ const { version: packageVersion } = JSON.parse(fs.readFileSync(packageJsonPath), 'utf-8');
37
+ pwaKitRuntimeVersion = packageVersion;
38
+ } catch(err) {
39
+ console.log(`[config] peer dependency pwa-kit-runtime was not provided`);
40
+ pwaKitRuntimeVersion = 'not-provided';
41
+ }
38
42
  }
39
-
40
43
  const nodeVersion = process.version
41
44
 
42
45
  module.exports = {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.9",
7
+ "version": "0.12.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -42,21 +42,21 @@
42
42
  "test": "jest"
43
43
  },
44
44
  "dependencies": {
45
- "@lwrjs/diagnostics": "0.12.0-alpha.9",
46
- "@lwrjs/instrumentation": "0.12.0-alpha.9",
47
- "@lwrjs/shared-utils": "0.12.0-alpha.9",
48
- "fs-extra": "^11.1.1",
49
- "jsonc-parser": "^3.0.0"
45
+ "@lwrjs/diagnostics": "0.12.0",
46
+ "@lwrjs/instrumentation": "0.12.0",
47
+ "@lwrjs/shared-utils": "0.12.0",
48
+ "fs-extra": "^11.2.0",
49
+ "jsonc-parser": "^3.2.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@lwrjs/types": "0.12.0-alpha.9",
52
+ "@lwrjs/types": "0.12.0",
53
53
  "jest": "^26.6.3",
54
54
  "ts-jest": "^26.5.6"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@lwc/engine-dom": ">= 2.x",
58
58
  "@lwc/synthetic-shadow": ">= 2.x",
59
- "@lwrjs/esbuild": "0.11.x",
59
+ "@lwrjs/esbuild": "0.12.x || >= 0.12.0-alpha",
60
60
  "lwc": ">= 2.x"
61
61
  },
62
62
  "peerDependenciesMeta": {
@@ -70,5 +70,5 @@
70
70
  "volta": {
71
71
  "extends": "../../../package.json"
72
72
  },
73
- "gitHead": "58b28fbc6300b704ac17f8878423120de0e376d7"
73
+ "gitHead": "90f93604b26003e1e1eb85bb0d1f34f4fc9e9ff9"
74
74
  }