@lwrjs/config 0.12.0-alpha.11 → 0.12.0-alpha.13

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
  });
@@ -125,6 +126,11 @@ function getDefaultBundleConfig(mode) {
125
126
  external: format === "esm" ? DEFAULT_ESM_BUNDLE_EXTERNALS : loaderLegacy ? DEFAULT_AMD_LEGACY_BUNDLE_EXTERNALS : DEFAULT_AMD_BUNDLE_EXTERNALS
126
127
  };
127
128
  }
129
+ var LWR_INFO_ROUTE = {
130
+ id: "lwrInfo",
131
+ path: "/lwr-info",
132
+ routeHandler: `@lwrjs/core/info/route-handler`
133
+ };
128
134
  var DEFAULT_LWR_CONFIG = {
129
135
  port: PORT,
130
136
  ignoreLwrConfigFile: false,
@@ -152,11 +158,7 @@ var DEFAULT_LWR_CONFIG = {
152
158
  environment: {},
153
159
  lwc: {modules: []},
154
160
  routes: [
155
- {
156
- id: "lwrInfo",
157
- path: "/lwr-info",
158
- routeHandler: `@lwrjs/core/info/route-handler`
159
- }
161
+ LWR_INFO_ROUTE
160
162
  ],
161
163
  errorRoutes: [],
162
164
  routeHandlers: {},
@@ -32,6 +32,7 @@ __export(exports, {
32
32
  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
+ var import_defaults = __toModule(require("./defaults.cjs"));
35
36
  async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globalData, skipValidate = false) {
36
37
  const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteConfigHooks});
37
38
  if (!hooks.length) {
@@ -44,6 +45,10 @@ async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globa
44
45
  }
45
46
  await hook.initConfigs(globalConfig, globalData, runtimeEnvironment);
46
47
  }
48
+ const hasInfoRoute = globalConfig.routes.some((route) => route.id === import_defaults.LWR_INFO_ROUTE.id);
49
+ if (!hasInfoRoute) {
50
+ globalConfig.routes = [...globalConfig.routes, import_defaults.LWR_INFO_ROUTE];
51
+ }
47
52
  globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
48
53
  globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes, globalConfig.routeHandlers);
49
54
  if (!skipValidate) {
@@ -73,6 +78,10 @@ function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipValidate
73
78
  globalConfig.routes = onStartConfig.routes || [];
74
79
  globalConfig.errorRoutes = onStartConfig.errorRoutes || [];
75
80
  }
81
+ const hasInfoRoute = globalConfig.routes.some((route) => route.id === import_defaults.LWR_INFO_ROUTE.id);
82
+ if (!hasInfoRoute) {
83
+ globalConfig.routes = [...globalConfig.routes, import_defaults.LWR_INFO_ROUTE];
84
+ }
76
85
  globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
77
86
  globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes, globalConfig.routeHandlers);
78
87
  if (!skipValidate) {
@@ -82,16 +91,24 @@ function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipValidate
82
91
  }
83
92
  function executeInstrumentationHooks(hooks) {
84
93
  const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteInstrHooks});
85
- let retVal = false;
94
+ const instrumentation = [];
86
95
  for (const hook of hooks) {
87
96
  if (!hook.initInstrumentation) {
88
97
  continue;
89
98
  }
90
- retVal = true;
91
- hook.initInstrumentation();
99
+ instrumentation.push(hook.initInstrumentation());
92
100
  }
93
101
  span.end();
94
- return retVal;
102
+ if (!instrumentation.length) {
103
+ return void 0;
104
+ }
105
+ return {
106
+ flush() {
107
+ for (const instance of instrumentation) {
108
+ instance.flush();
109
+ }
110
+ }
111
+ };
95
112
  }
96
113
  async function executeContextHooks(hooks, serverContext) {
97
114
  if (!hooks.length) {
@@ -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
  }
@@ -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
@@ -91,6 +91,11 @@ export function getDefaultBundleConfig(mode) {
91
91
  : DEFAULT_AMD_BUNDLE_EXTERNALS,
92
92
  };
93
93
  }
94
+ export const LWR_INFO_ROUTE = {
95
+ id: 'lwrInfo',
96
+ path: '/lwr-info',
97
+ routeHandler: `@lwrjs/core/info/route-handler`
98
+ };
94
99
  export const DEFAULT_LWR_CONFIG = {
95
100
  port: PORT,
96
101
  ignoreLwrConfigFile: false,
@@ -118,11 +123,7 @@ export const DEFAULT_LWR_CONFIG = {
118
123
  environment: {},
119
124
  lwc: { modules: [] },
120
125
  routes: [
121
- {
122
- id: 'lwrInfo',
123
- path: '/lwr-info',
124
- routeHandler: `@lwrjs/core/info/route-handler`,
125
- },
126
+ LWR_INFO_ROUTE,
126
127
  ],
127
128
  errorRoutes: [],
128
129
  routeHandlers: {},
@@ -1,4 +1,4 @@
1
- import type { GlobalData, HooksPlugin, NormalizedLwrGlobalConfig, RuntimeEnvironment, ServerContext } from '@lwrjs/types';
1
+ import type { GlobalData, HooksPlugin, Instrumentation, NormalizedLwrGlobalConfig, RuntimeEnvironment, ServerContext } from '@lwrjs/types';
2
2
  /**
3
3
  * Run `initConfigs` hooks
4
4
  *
@@ -29,6 +29,6 @@ export declare function executeConfigHooks(hooks: HooksPlugin[], globalConfig: N
29
29
  * @param globalConfig - global configuration
30
30
  */
31
31
  export declare function executeStartHooks(hooks: HooksPlugin[], globalConfig: NormalizedLwrGlobalConfig, runtimeEnvironment: RuntimeEnvironment, skipValidate?: boolean): void;
32
- export declare function executeInstrumentationHooks(hooks: HooksPlugin[]): boolean;
32
+ export declare function executeInstrumentationHooks(hooks: HooksPlugin[]): Instrumentation | undefined;
33
33
  export declare function executeContextHooks(hooks: HooksPlugin[], serverContext: ServerContext): Promise<void>;
34
34
  //# sourceMappingURL=hooks.d.ts.map
package/build/es/hooks.js CHANGED
@@ -1,6 +1,7 @@
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
+ import { LWR_INFO_ROUTE } from './defaults.js';
4
5
  /**
5
6
  * Run `initConfigs` hooks
6
7
  *
@@ -28,6 +29,10 @@ export async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment
28
29
  // eslint-disable-next-line no-await-in-loop
29
30
  await hook.initConfigs(globalConfig, globalData, runtimeEnvironment);
30
31
  }
32
+ const hasInfoRoute = globalConfig.routes.some(route => route.id === LWR_INFO_ROUTE.id);
33
+ if (!hasInfoRoute) {
34
+ globalConfig.routes = [...globalConfig.routes, LWR_INFO_ROUTE];
35
+ }
31
36
  globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
32
37
  globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes, globalConfig.routeHandlers);
33
38
  if (!skipValidate) {
@@ -72,6 +77,11 @@ export function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipV
72
77
  globalConfig.routes = (onStartConfig.routes || []);
73
78
  globalConfig.errorRoutes = (onStartConfig.errorRoutes || []);
74
79
  }
80
+ // Check if Info Route was removed
81
+ const hasInfoRoute = globalConfig.routes.some(route => route.id === LWR_INFO_ROUTE.id);
82
+ if (!hasInfoRoute) {
83
+ globalConfig.routes = [...globalConfig.routes, LWR_INFO_ROUTE];
84
+ }
75
85
  globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
76
86
  globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes, globalConfig.routeHandlers);
77
87
  if (!skipValidate) {
@@ -81,16 +91,24 @@ export function executeStartHooks(hooks, globalConfig, runtimeEnvironment, skipV
81
91
  }
82
92
  export function executeInstrumentationHooks(hooks) {
83
93
  const span = getTracer().startSpan({ name: ConfigSpan.ExecuteInstrHooks });
84
- let retVal = false;
94
+ const instrumentation = [];
85
95
  for (const hook of hooks) {
86
96
  if (!hook.initInstrumentation) {
87
97
  continue;
88
98
  }
89
- retVal = true;
90
- hook.initInstrumentation();
99
+ instrumentation.push(hook.initInstrumentation());
91
100
  }
92
101
  span.end();
93
- return retVal;
102
+ if (!instrumentation.length) {
103
+ return undefined;
104
+ }
105
+ return {
106
+ flush() {
107
+ for (const instance of instrumentation) {
108
+ instance.flush();
109
+ }
110
+ }
111
+ };
94
112
  }
95
113
  export async function executeContextHooks(hooks, serverContext) {
96
114
  if (!hooks.length) {
@@ -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
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.11",
7
+ "version": "0.12.0-alpha.13",
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.11",
46
- "@lwrjs/instrumentation": "0.12.0-alpha.11",
47
- "@lwrjs/shared-utils": "0.12.0-alpha.11",
45
+ "@lwrjs/diagnostics": "0.12.0-alpha.13",
46
+ "@lwrjs/instrumentation": "0.12.0-alpha.13",
47
+ "@lwrjs/shared-utils": "0.12.0-alpha.13",
48
48
  "fs-extra": "^11.1.1",
49
49
  "jsonc-parser": "^3.0.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@lwrjs/types": "0.12.0-alpha.11",
52
+ "@lwrjs/types": "0.12.0-alpha.13",
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": "781951a5ef92ce735cbffce7c7a2a32c60bd3c16"
73
+ "gitHead": "7a63e416f9e5f27b44331311a371f68e20ce685c"
74
74
  }