@lwrjs/config 0.9.0-alpha.11 → 0.9.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.
@@ -48,6 +48,7 @@ var DEFAULT_LWR_CONFIG_JSON = "$rootDir/lwr.config.json";
48
48
  var DEFAULT_GENERATOR_CONFIG = {
49
49
  outputDir: "__generated_site__",
50
50
  locales: ["en-US"],
51
+ skipCleanOutputDir: false,
51
52
  skipBaseDocumentGeneration: false,
52
53
  _additionalRoutePaths: []
53
54
  };
@@ -59,7 +60,6 @@ var DEFAULT_LAYOUTS_DIR = "$rootDir/src/layouts";
59
60
  var DEFAULT_DATA_DIR = "$rootDir/src/data";
60
61
  var DEFAULT_MODULE_PROVIDERS = [
61
62
  "@lwrjs/app-service/moduleProvider",
62
- "@lwrjs/lwc-ssr/moduleProvider",
63
63
  "@lwrjs/router/module-provider",
64
64
  "@lwrjs/lwc-module-provider",
65
65
  "@lwrjs/npm-module-provider"
@@ -71,7 +71,7 @@ var DEFAULT_VIEW_PROVIDERS = [
71
71
  "@lwrjs/markdown-view-provider",
72
72
  "@lwrjs/base-view-provider"
73
73
  ];
74
- var DEFAULT_VIEW_TRANSFORM_PLUGINS = ["@lwrjs/base-view-transformer", "@lwrjs/lwc-ssr/viewTransformer"];
74
+ var DEFAULT_VIEW_TRANSFORM_PLUGINS = ["@lwrjs/base-view-transformer"];
75
75
  var DEFAULT_ASSET_PROVIDERS = ["@lwrjs/fs-asset-provider"];
76
76
  var DEFAULT_ASSET_TRANSFORM_PLUGINS = ["@lwrjs/asset-transformer"];
77
77
  var DEFAULT_AMD_LOADER = "lwr/loader";
@@ -21,13 +21,17 @@ var __toModule = (module2) => {
21
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
22
  };
23
23
 
24
- // packages/@lwrjs/config/src/env-config.ts
24
+ // packages/@lwrjs/config/src/global-config.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
- resolveConfig: () => resolveConfig
27
+ loadConfig: () => loadConfig,
28
+ loadRoutes: () => loadRoutes,
29
+ loadServices: () => loadServices,
30
+ resolveGlobalConfig: () => resolveGlobalConfig
28
31
  });
29
32
  var import_fs = __toModule(require("fs"));
30
33
  var import_path = __toModule(require("path"));
34
+ var import_jsonc_parser = __toModule(require("jsonc-parser"));
31
35
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
36
  var import_defaults = __toModule(require("./defaults.cjs"));
33
37
  var import_app_config = __toModule(require("./validation/app-config.cjs"));
@@ -36,7 +40,8 @@ var import_services = __toModule(require("./utils/services.cjs"));
36
40
  var import_routes = __toModule(require("./utils/routes.cjs"));
37
41
  var import_merge = __toModule(require("./utils/merge.cjs"));
38
42
  var import_lwc = __toModule(require("./utils/lwc.cjs"));
39
- var import_jsonc_parser = __toModule(require("jsonc-parser"));
43
+ var import_runtime_config = __toModule(require("./runtime-config.cjs"));
44
+ var import_global_data = __toModule(require("./utils/global-data.cjs"));
40
45
  function getLwrConfigFromFile(rootDir, lwrConfigPath = import_defaults.DEFAULT_LWR_CONFIG_JSON) {
41
46
  const resolvedLwrConfigPath = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(lwrConfigPath, rootDir));
42
47
  if (!import_fs.default.existsSync(resolvedLwrConfigPath)) {
@@ -53,7 +58,7 @@ function createCacheFolder(cache, rootDir) {
53
58
  import_fs.default.mkdirSync(import_path.default.join(absPath, import_shared_utils.ASSETS_CACHE_DIR), {recursive: true});
54
59
  return absPath;
55
60
  }
56
- function loadConfig(configArg) {
61
+ function mergeConfig(configArg) {
57
62
  if (configArg) {
58
63
  configArg = (0, import_merge.trimLwrConfig)(configArg);
59
64
  (0, import_app_config.validateLwrAppConfig)(configArg, "pre");
@@ -120,10 +125,19 @@ function normalizeConfigPaths(config) {
120
125
  errorRoutes: (0, import_routes.normalizeRoutePaths)(config.errorRoutes, resourcePaths)
121
126
  };
122
127
  }
123
- function resolveConfig(configArg, options) {
128
+ async function applyConfigHooks(globalConfig, runtimeEnvironment, globalData) {
129
+ const hooks = await (0, import_services.loadServiceEntries)(globalConfig.hooks, globalConfig.rootDir, globalConfig.cacheDir);
130
+ for (const [hook, hookConfig = {}] of hooks) {
131
+ await new hook(hookConfig).initConfigs(globalConfig, globalData, runtimeEnvironment);
132
+ }
133
+ globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes);
134
+ globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes);
135
+ (0, import_app_config.validateLwrAppConfig)(JSON.stringify(globalConfig), "post");
136
+ }
137
+ function resolveGlobalConfig(configArg, options) {
124
138
  const skipDirNormalization = options?.skipDirNormalization;
125
139
  const skipCacheDirCreation = options?.skipDirNormalization;
126
- const mergedConfig = loadConfig(configArg);
140
+ const mergedConfig = mergeConfig(configArg);
127
141
  const normalizedConfig = normalizeConfig(mergedConfig);
128
142
  if (!skipCacheDirCreation) {
129
143
  createCacheFolder(normalizedConfig.cacheDir, normalizedConfig.rootDir);
@@ -133,3 +147,38 @@ function resolveConfig(configArg, options) {
133
147
  }
134
148
  return normalizeConfigPaths(normalizedConfig);
135
149
  }
150
+ async function loadConfig(config, options) {
151
+ const globalConfig = await resolveGlobalConfig(config, options);
152
+ const runtimeEnvironment = (0, import_runtime_config.getRuntimeEnvironment)(globalConfig);
153
+ const globalData = await (0, import_global_data.getGlobalData)(globalConfig.globalDataDir, globalConfig.globalData);
154
+ await applyConfigHooks(globalConfig, runtimeEnvironment, globalData);
155
+ return {
156
+ appConfig: globalConfig,
157
+ runtimeEnvironment,
158
+ globalData
159
+ };
160
+ }
161
+ async function loadServices(config) {
162
+ const moduleProviders = await (0, import_services.loadServiceEntries)(config.moduleProviders, config.rootDir, config.cacheDir);
163
+ const assetProviders = await (0, import_services.loadServiceEntries)(config.assetProviders, config.rootDir, config.cacheDir);
164
+ const assetTransformers = await (0, import_services.loadServiceEntries)(config.assetTransformers, config.rootDir, config.cacheDir);
165
+ const resourceProviders = await (0, import_services.loadServiceEntries)(config.resourceProviders, config.rootDir, config.cacheDir);
166
+ const viewProviders = await (0, import_services.loadServiceEntries)(config.viewProviders, config.rootDir, config.cacheDir);
167
+ const viewTransformers = await (0, import_services.loadServiceEntries)(config.viewTransformers, config.rootDir, config.cacheDir);
168
+ return {
169
+ moduleProviders,
170
+ assetProviders,
171
+ assetTransformers,
172
+ resourceProviders,
173
+ viewProviders,
174
+ viewTransformers
175
+ };
176
+ }
177
+ async function loadRoutes(config) {
178
+ const routes = await (0, import_routes.loadRouteHandlers)(config.routes, config.rootDir, config.cacheDir);
179
+ const errorRoutes = await (0, import_routes.loadRouteHandlers)(config.errorRoutes, config.rootDir, config.cacheDir);
180
+ return {
181
+ routes,
182
+ errorRoutes
183
+ };
184
+ }
@@ -24,10 +24,13 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/config/src/index.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
- explodeMode: () => import_runtime_config.getServerModeConfig,
28
- normalizeConfig: () => import_env_config.resolveConfig,
29
- validateLwrAppConfig: () => import_app_config.validateLwrAppConfig
27
+ LWR_VERSION: () => import_package.version,
28
+ getRuntimeEnvironment: () => import_runtime_config.getRuntimeEnvironment,
29
+ loadConfig: () => import_global_config.loadConfig,
30
+ loadRoutes: () => import_global_config.loadRoutes,
31
+ loadServices: () => import_global_config.loadServices,
32
+ normalizeConfig: () => import_global_config.resolveGlobalConfig
30
33
  });
31
- var import_env_config = __toModule(require("./env-config.cjs"));
34
+ var import_global_config = __toModule(require("./global-config.cjs"));
32
35
  var import_runtime_config = __toModule(require("./runtime-config.cjs"));
33
- var import_app_config = __toModule(require("./validation/app-config.cjs"));
36
+ var import_package = __toModule(require("@lwrjs/config/package"));
@@ -25,15 +25,18 @@ var __toModule = (module2) => {
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
27
  RUNTIME_CONFIGS: () => RUNTIME_CONFIGS,
28
+ getRuntimeEnvironment: () => getRuntimeEnvironment,
28
29
  getServerModeConfig: () => getServerModeConfig
29
30
  });
30
31
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
32
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
33
  var RUNTIME_CONFIGS = {
32
34
  dev: {
33
35
  bundle: false,
34
36
  minify: false,
35
37
  format: "esm",
36
38
  compat: "0",
39
+ debug: false,
37
40
  watchFiles: true,
38
41
  defaultLocale: "en_US",
39
42
  hmrEnabled: true,
@@ -47,6 +50,7 @@ var RUNTIME_CONFIGS = {
47
50
  minify: true,
48
51
  format: "esm",
49
52
  compat: "0",
53
+ debug: false,
50
54
  watchFiles: false,
51
55
  defaultLocale: "en_US",
52
56
  hmrEnabled: false,
@@ -60,6 +64,7 @@ var RUNTIME_CONFIGS = {
60
64
  minify: false,
61
65
  format: "amd",
62
66
  compat: "1",
67
+ debug: false,
63
68
  watchFiles: true,
64
69
  defaultLocale: "en_US",
65
70
  hmrEnabled: false,
@@ -73,6 +78,7 @@ var RUNTIME_CONFIGS = {
73
78
  minify: true,
74
79
  format: "amd",
75
80
  compat: "1",
81
+ debug: false,
76
82
  watchFiles: false,
77
83
  defaultLocale: "en_US",
78
84
  hmrEnabled: false,
@@ -82,10 +88,21 @@ var RUNTIME_CONFIGS = {
82
88
  }
83
89
  }
84
90
  };
85
- function getServerModeConfig(mode) {
86
- const selectedMode = RUNTIME_CONFIGS[mode];
91
+ function getServerModeConfig(serverMode) {
92
+ const selectedMode = RUNTIME_CONFIGS[serverMode];
87
93
  if (!selectedMode) {
88
- throw (0, import_diagnostics.createSingleDiagnosticError)({description: import_diagnostics.descriptions.SERVER.INVALID_MODE(mode)}, import_diagnostics.LwrServerError);
94
+ throw (0, import_diagnostics.createSingleDiagnosticError)({description: import_diagnostics.descriptions.SERVER.INVALID_MODE(serverMode)}, import_diagnostics.LwrServerError);
89
95
  }
90
96
  return selectedMode;
91
97
  }
98
+ function getRuntimeEnvironment(config) {
99
+ const {serverMode, lwrVersion, apiVersion, basePath} = config;
100
+ return {
101
+ ...getServerModeConfig(config.serverMode),
102
+ featureFlags: (0, import_shared_utils.getFeatureFlags)(),
103
+ serverMode,
104
+ lwrVersion,
105
+ apiVersion,
106
+ basePath
107
+ };
108
+ }
@@ -0,0 +1,54 @@
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/config/src/utils/global-data.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ getGlobalData: () => getGlobalData
28
+ });
29
+ var import_fs = __toModule(require("fs"));
30
+ var import_path = __toModule(require("path"));
31
+ function recursiveJsonCollector(resources, currentPath, collector) {
32
+ for (const resource of resources) {
33
+ const resourcePath = import_path.default.join(currentPath, resource);
34
+ if (resource.endsWith(".json")) {
35
+ const resourceName = import_path.default.basename(resource, ".json");
36
+ const jsonSource = JSON.parse(import_fs.default.readFileSync(resourcePath, "utf-8"));
37
+ collector[resourceName] = jsonSource;
38
+ } else if (import_fs.default.statSync(resourcePath).isDirectory()) {
39
+ const dirContentList = import_fs.default.readdirSync(resourcePath);
40
+ collector[resource] = recursiveJsonCollector(dirContentList, resourcePath, {});
41
+ }
42
+ }
43
+ return collector;
44
+ }
45
+ function getGlobalData(globalDataDir, defaultData = {}) {
46
+ if (!import_fs.default.existsSync(globalDataDir) || !import_fs.default.statSync(globalDataDir).isDirectory()) {
47
+ return defaultData;
48
+ }
49
+ const dirContentList = import_fs.default.readdirSync(globalDataDir);
50
+ return {
51
+ ...recursiveJsonCollector(dirContentList, globalDataDir, {}),
52
+ ...defaultData
53
+ };
54
+ }
@@ -32,6 +32,9 @@ __export(exports, {
32
32
  });
33
33
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
34
  var import_defaults = __toModule(require("../defaults.cjs"));
35
+ function isNormalizedLwrGlobalConfig(config) {
36
+ return config?.lwrVersion !== void 0;
37
+ }
35
38
  function trimLwrConfig(config) {
36
39
  Object.keys(config).forEach((k) => {
37
40
  if (config[k] === void 0)
@@ -40,6 +43,7 @@ function trimLwrConfig(config) {
40
43
  return config;
41
44
  }
42
45
  function mergeLwcConfig(config1, config2) {
46
+ const defaultModules = !isNormalizedLwrGlobalConfig(config1) && !isNormalizedLwrGlobalConfig(config2) ? import_defaults.DEFAULT_LWR_MODULES : [];
43
47
  const modules1 = config1?.lwc?.modules || [];
44
48
  const modules2 = config2?.lwc?.modules || [];
45
49
  const interchangeable1 = config1?.lwc?.interchangeable || [];
@@ -49,17 +53,17 @@ function mergeLwcConfig(config1, config2) {
49
53
  const interchangeableModules2 = config2?.lwc?.interchangeableModules || [];
50
54
  const mergedInterchangeableModules = [...interchangeableModules1, ...interchangeableModules2];
51
55
  return {
52
- modules: [...import_defaults.DEFAULT_LWR_MODULES, ...modules1, ...modules2],
56
+ modules: [...defaultModules, ...modules1, ...modules2],
53
57
  interchangeable: mergedInterchangeable.length ? mergedInterchangeable : void 0,
54
58
  interchangeableModules: mergedInterchangeableModules.length ? mergedInterchangeableModules : void 0
55
59
  };
56
60
  }
57
- function mergeBundleConfig(jsonConfig, config) {
58
- const defaultExclusions = config?.bundleConfig?.UNSAFE_lwrDefaultExclude || jsonConfig?.bundleConfig?.UNSAFE_lwrDefaultExclude || import_defaults.DEFAULT_BUNDLE_EXCLUSIONS;
59
- const configExclusions = config?.bundleConfig?.exclude || jsonConfig?.bundleConfig?.exclude || [];
61
+ function mergeBundleConfig(config1, config2) {
62
+ const defaultExclusions = config2?.bundleConfig?.UNSAFE_lwrDefaultExclude || config1?.bundleConfig?.UNSAFE_lwrDefaultExclude || import_defaults.DEFAULT_BUNDLE_EXCLUSIONS;
63
+ const configExclusions = config2?.bundleConfig?.exclude || config1?.bundleConfig?.exclude || [];
60
64
  return {
61
- ...jsonConfig?.bundleConfig,
62
- ...config?.bundleConfig,
65
+ ...config1?.bundleConfig,
66
+ ...config2?.bundleConfig,
63
67
  exclude: [...new Set([...defaultExclusions, ...configExclusions])]
64
68
  };
65
69
  }
@@ -0,0 +1,45 @@
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/config/src/utils/module-loader.ts
25
+ __markAsModule(exports);
26
+ __export(exports, {
27
+ loadModule: () => loadModule
28
+ });
29
+ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
+ async function loadModule(filepath, rootDir, cacheDir) {
31
+ let resolvedFilePath = (0, import_shared_utils.normalizeDirectory)(filepath, rootDir);
32
+ const resolvedCacheDir = (0, import_shared_utils.normalizeDirectory)(cacheDir, rootDir);
33
+ try {
34
+ if (resolvedFilePath.endsWith(".ts")) {
35
+ const fullPath = (0, import_shared_utils.resolveFileExtension)(resolvedFilePath);
36
+ resolvedFilePath = await (0, import_shared_utils.transpileTs)(fullPath, {rootDir, cacheDir: resolvedCacheDir});
37
+ }
38
+ const moduleEntry = await Promise.resolve().then(() => __toModule(require(resolvedFilePath)));
39
+ const output = moduleEntry.default || moduleEntry;
40
+ return output;
41
+ } catch (err) {
42
+ console.log(err);
43
+ throw new Error(`Unable to load configurable module: ${filepath}`);
44
+ }
45
+ }
@@ -24,11 +24,13 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/config/src/utils/routes.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
+ loadRouteHandlers: () => loadRouteHandlers,
27
28
  normalizeRoutePaths: () => normalizeRoutePaths,
28
29
  normalizeRoutes: () => normalizeRoutes
29
30
  });
30
31
  var import_path = __toModule(require("path"));
31
32
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
33
+ var import_module_loader = __toModule(require("./module-loader.cjs"));
32
34
  function normalizeRoutes(routes = []) {
33
35
  return routes.map((route) => ({
34
36
  ...route,
@@ -48,3 +50,23 @@ function normalizeRoutePaths(routes = [], resourcePaths) {
48
50
  return route;
49
51
  });
50
52
  }
53
+ async function loadRouteHandlers(routes, rootDir, cacheDir) {
54
+ const cache = {};
55
+ return Promise.all(routes.map(async (route) => {
56
+ if (!route.routeHandler) {
57
+ return route;
58
+ }
59
+ if (cache[route.routeHandler]) {
60
+ return {
61
+ ...route,
62
+ routeHandler: cache[route.routeHandler]
63
+ };
64
+ }
65
+ const routeHandler = await (0, import_module_loader.loadModule)(route.routeHandler, rootDir, import_path.default.join(cacheDir, "routeHandlers"));
66
+ cache[route.routeHandler] = routeHandler;
67
+ return {
68
+ ...route,
69
+ routeHandler
70
+ };
71
+ }));
72
+ }
@@ -24,12 +24,14 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/config/src/utils/services.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
+ loadServiceEntries: () => loadServiceEntries,
27
28
  normalizeServicePaths: () => normalizeServicePaths,
28
29
  normalizeServices: () => normalizeServices
29
30
  });
30
31
  var import_path = __toModule(require("path"));
31
32
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
33
  var import_defaults = __toModule(require("../defaults.cjs"));
34
+ var import_module_loader = __toModule(require("./module-loader.cjs"));
33
35
  function normalizeServices(services = []) {
34
36
  return services.map((service) => Array.isArray(service) ? service : [service, void 0]);
35
37
  }
@@ -43,3 +45,9 @@ function normalizeServicePaths(services, rootDir) {
43
45
  return [serviceName, serviceConfig];
44
46
  });
45
47
  }
48
+ async function loadServiceEntries(entries, rootDir, cacheDir) {
49
+ return Promise.all(entries.map(async ([entry, config]) => {
50
+ const ctor = await (0, import_module_loader.loadModule)(entry, rootDir, import_path.default.join(cacheDir, "services"));
51
+ return [ctor, config];
52
+ }));
53
+ }
@@ -68,9 +68,11 @@ function validateRouteCommon(node, validationContext, propPrefix) {
68
68
  validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["routeHandler"]), `${propPrefix}.routeHandler`);
69
69
  validateBootstrap((0, import_jsonc_parser.findNodeAtLocation)(node, ["bootstrap"]), validationContext, `${propPrefix}.bootstrap`);
70
70
  }
71
- function validateRoutes(node, validationContext) {
71
+ function validateRoutes(node, validationContext, preMerge) {
72
72
  if (node) {
73
- validationContext.assertNotEmptyArray(node, "routes");
73
+ if (!preMerge) {
74
+ validationContext.assertNotEmptyArray(node, "routes");
75
+ }
74
76
  if (node.children) {
75
77
  node.children.forEach((n, index) => {
76
78
  const propPrefix = `routes[${index}]`;
@@ -143,7 +145,7 @@ function validateRoot(node, validationContext, preMerge) {
143
145
  const routes = (0, import_jsonc_parser.findNodeAtLocation)(node, ["routes"]);
144
146
  const errorRoutes = (0, import_jsonc_parser.findNodeAtLocation)(node, ["errorRoutes"]);
145
147
  validationContext.assertUniqueIds([...routes?.children || [], ...errorRoutes?.children || []], "routes");
146
- validateRoutes(routes, validationContext);
148
+ validateRoutes(routes, validationContext, preMerge);
147
149
  validateErrorRoutes(errorRoutes, validationContext);
148
150
  validateAssets((0, import_jsonc_parser.findNodeAtLocation)(node, ["assets"]), validationContext, preMerge);
149
151
  validateLocker((0, import_jsonc_parser.findNodeAtLocation)(node, ["locker"]), validationContext);
@@ -4,6 +4,7 @@ export declare const DEFAULT_LWR_CONFIG_JSON = "$rootDir/lwr.config.json";
4
4
  export declare const DEFAULT_GENERATOR_CONFIG: {
5
5
  outputDir: string;
6
6
  locales: string[];
7
+ skipCleanOutputDir: boolean;
7
8
  skipBaseDocumentGeneration: boolean;
8
9
  _additionalRoutePaths: never[];
9
10
  };
@@ -10,6 +10,7 @@ export const DEFAULT_LWR_CONFIG_JSON = '$rootDir/lwr.config.json';
10
10
  export const DEFAULT_GENERATOR_CONFIG = {
11
11
  outputDir: '__generated_site__',
12
12
  locales: ['en-US'],
13
+ skipCleanOutputDir: false,
13
14
  skipBaseDocumentGeneration: false,
14
15
  _additionalRoutePaths: [],
15
16
  };
@@ -23,7 +24,6 @@ const DEFAULT_DATA_DIR = '$rootDir/src/data';
23
24
  // Providers
24
25
  const DEFAULT_MODULE_PROVIDERS = [
25
26
  '@lwrjs/app-service/moduleProvider',
26
- '@lwrjs/lwc-ssr/moduleProvider',
27
27
  '@lwrjs/router/module-provider',
28
28
  '@lwrjs/lwc-module-provider',
29
29
  '@lwrjs/npm-module-provider',
@@ -35,7 +35,7 @@ const DEFAULT_VIEW_PROVIDERS = [
35
35
  '@lwrjs/markdown-view-provider',
36
36
  '@lwrjs/base-view-provider',
37
37
  ];
38
- const DEFAULT_VIEW_TRANSFORM_PLUGINS = ['@lwrjs/base-view-transformer', '@lwrjs/lwc-ssr/viewTransformer'];
38
+ const DEFAULT_VIEW_TRANSFORM_PLUGINS = ['@lwrjs/base-view-transformer'];
39
39
  const DEFAULT_ASSET_PROVIDERS = ['@lwrjs/fs-asset-provider'];
40
40
  const DEFAULT_ASSET_TRANSFORM_PLUGINS = ['@lwrjs/asset-transformer'];
41
41
  export const DEFAULT_AMD_LOADER = 'lwr/loader';
@@ -0,0 +1,53 @@
1
+ import type { GlobalData, LwrGlobalConfig, NormalizedLwrGlobalConfig, RuntimeEnvironment, NormalizedLwrRoute, NormalizedLwrErrorRoute, Services, Route } from '@lwrjs/types';
2
+ export interface ResolveConfigOptions {
3
+ skipDirNormalization?: boolean;
4
+ skipCacheDirCreation?: boolean;
5
+ }
6
+ export interface Configurations {
7
+ appConfig: NormalizedLwrGlobalConfig;
8
+ runtimeEnvironment: RuntimeEnvironment;
9
+ globalData: GlobalData;
10
+ }
11
+ export interface Routes {
12
+ routes: Route<NormalizedLwrRoute>[];
13
+ errorRoutes: Route<NormalizedLwrErrorRoute>[];
14
+ }
15
+ /**
16
+ * Load, merge, and normalize all of the config sources.
17
+ *
18
+ * @remarks
19
+ * Config hooks are not loaded or applied during config resolution.
20
+ *
21
+ * @privateRemarks
22
+ * The `skipDirNormalization` and `skipCacheDirCreation` options are useful for generating
23
+ * a portable global config. The directories can be normalized and the cache directory can
24
+ * be created at runtime.
25
+ *
26
+ * @param {LwrGlobalConfig} configArg - programmatic global config
27
+ * @param {ResolveConfigOptions} options - config resolution mutations
28
+ * @returns {NormalizedLwrGlobalConfig} a normalized global config relative to the provided options
29
+ */
30
+ export declare function resolveGlobalConfig(configArg?: LwrGlobalConfig, options?: ResolveConfigOptions): NormalizedLwrGlobalConfig;
31
+ /**
32
+ * Resolve all application configurations by loading and merging global data, applying config hooks, and
33
+ * importing configurable paths to javascript(ie. services and route handlers).
34
+ *
35
+ * @param {LwrGlobalConfig} config - programmatic global config
36
+ * @returns {Configurations} all of the fully resolved configurations
37
+ */
38
+ export declare function loadConfig(config?: LwrGlobalConfig, options?: ResolveConfigOptions): Promise<Configurations>;
39
+ /**
40
+ * Load service modules from the filepaths configured in the global config
41
+ *
42
+ * @param config - global config
43
+ * @returns {Services} all of the imported service constructors
44
+ */
45
+ export declare function loadServices(config: NormalizedLwrGlobalConfig): Promise<Services>;
46
+ /**
47
+ * Load all route handlers from the filepaths configured in the global config
48
+ *
49
+ * @param config - global config
50
+ * @returns {Routes} all routes with resolved route handlers
51
+ */
52
+ export declare function loadRoutes(config: NormalizedLwrGlobalConfig): Promise<Routes>;
53
+ //# sourceMappingURL=global-config.d.ts.map
@@ -1,14 +1,16 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { parse } from 'jsonc-parser';
3
4
  import { readFile, normalizeDirectory, getFeatureFlags, logger, ASSETS_CACHE_DIR } from '@lwrjs/shared-utils';
4
5
  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';
5
6
  import { validateLwrAppConfig } from './validation/app-config.js';
6
7
  import { normalizeAssetPaths, normalizeAssets } from './utils/assets.js';
7
- import { normalizeServicePaths, normalizeServices } from './utils/services.js';
8
- import { normalizeRoutePaths, normalizeRoutes } from './utils/routes.js';
8
+ import { loadServiceEntries, normalizeServicePaths, normalizeServices } from './utils/services.js';
9
+ import { loadRouteHandlers, normalizeRoutePaths, normalizeRoutes } from './utils/routes.js';
9
10
  import { mergeBundleConfig, mergeLockerConfig, mergeLwcConfig, mergeStaticGenerationConfig, trimLwrConfig, } from './utils/merge.js';
10
11
  import { normalizeLwcConfig, normalizeModulePaths } from './utils/lwc.js';
11
- import { parse } from 'jsonc-parser';
12
+ import { getRuntimeEnvironment } from './runtime-config.js';
13
+ import { getGlobalData } from './utils/global-data.js';
12
14
  /**
13
15
  * Load and validate the global config file.
14
16
  *
@@ -59,7 +61,7 @@ function createCacheFolder(cache, rootDir) {
59
61
  * @param {LwrGlobalConfig} configArg - programmatic global config
60
62
  * @returns {Required<LwrGlobalConfig>} a complete(but not normalized) global config
61
63
  */
62
- function loadConfig(configArg) {
64
+ function mergeConfig(configArg) {
63
65
  // process programmatic config
64
66
  if (configArg) {
65
67
  // the programmatic config is trimmed to prevent overriding properties with an undefined value
@@ -162,6 +164,16 @@ function normalizeConfigPaths(config) {
162
164
  errorRoutes: normalizeRoutePaths(config.errorRoutes, resourcePaths),
163
165
  };
164
166
  }
167
+ async function applyConfigHooks(globalConfig, runtimeEnvironment, globalData) {
168
+ const hooks = await loadServiceEntries(globalConfig.hooks, globalConfig.rootDir, globalConfig.cacheDir);
169
+ for (const [hook, hookConfig = {}] of hooks) {
170
+ // eslint-disable-next-line no-await-in-loop
171
+ await new hook(hookConfig).initConfigs(globalConfig, globalData, runtimeEnvironment);
172
+ }
173
+ globalConfig.routes = normalizeRoutes(globalConfig.routes);
174
+ globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes);
175
+ validateLwrAppConfig(JSON.stringify(globalConfig), 'post');
176
+ }
165
177
  /**
166
178
  * Load, merge, and normalize all of the config sources.
167
179
  *
@@ -177,10 +189,10 @@ function normalizeConfigPaths(config) {
177
189
  * @param {ResolveConfigOptions} options - config resolution mutations
178
190
  * @returns {NormalizedLwrGlobalConfig} a normalized global config relative to the provided options
179
191
  */
180
- export function resolveConfig(configArg, options) {
192
+ export function resolveGlobalConfig(configArg, options) {
181
193
  const skipDirNormalization = options?.skipDirNormalization;
182
194
  const skipCacheDirCreation = options?.skipDirNormalization;
183
- const mergedConfig = loadConfig(configArg);
195
+ const mergedConfig = mergeConfig(configArg);
184
196
  const normalizedConfig = normalizeConfig(mergedConfig);
185
197
  // skip cache dir creation when the option is set
186
198
  if (!skipCacheDirCreation) {
@@ -192,4 +204,58 @@ export function resolveConfig(configArg, options) {
192
204
  }
193
205
  return normalizeConfigPaths(normalizedConfig);
194
206
  }
195
- //# sourceMappingURL=env-config.js.map
207
+ /**
208
+ * Resolve all application configurations by loading and merging global data, applying config hooks, and
209
+ * importing configurable paths to javascript(ie. services and route handlers).
210
+ *
211
+ * @param {LwrGlobalConfig} config - programmatic global config
212
+ * @returns {Configurations} all of the fully resolved configurations
213
+ */
214
+ export async function loadConfig(config, options) {
215
+ const globalConfig = await resolveGlobalConfig(config, options);
216
+ const runtimeEnvironment = getRuntimeEnvironment(globalConfig);
217
+ const globalData = await getGlobalData(globalConfig.globalDataDir, globalConfig.globalData);
218
+ await applyConfigHooks(globalConfig, runtimeEnvironment, globalData);
219
+ return {
220
+ appConfig: globalConfig,
221
+ runtimeEnvironment: runtimeEnvironment,
222
+ globalData: globalData,
223
+ };
224
+ }
225
+ /**
226
+ * Load service modules from the filepaths configured in the global config
227
+ *
228
+ * @param config - global config
229
+ * @returns {Services} all of the imported service constructors
230
+ */
231
+ export async function loadServices(config) {
232
+ const moduleProviders = await loadServiceEntries(config.moduleProviders, config.rootDir, config.cacheDir);
233
+ const assetProviders = await loadServiceEntries(config.assetProviders, config.rootDir, config.cacheDir);
234
+ const assetTransformers = await loadServiceEntries(config.assetTransformers, config.rootDir, config.cacheDir);
235
+ const resourceProviders = await loadServiceEntries(config.resourceProviders, config.rootDir, config.cacheDir);
236
+ const viewProviders = await loadServiceEntries(config.viewProviders, config.rootDir, config.cacheDir);
237
+ const viewTransformers = await loadServiceEntries(config.viewTransformers, config.rootDir, config.cacheDir);
238
+ return {
239
+ moduleProviders,
240
+ assetProviders,
241
+ assetTransformers,
242
+ resourceProviders,
243
+ viewProviders,
244
+ viewTransformers,
245
+ };
246
+ }
247
+ /**
248
+ * Load all route handlers from the filepaths configured in the global config
249
+ *
250
+ * @param config - global config
251
+ * @returns {Routes} all routes with resolved route handlers
252
+ */
253
+ export async function loadRoutes(config) {
254
+ const routes = await loadRouteHandlers(config.routes, config.rootDir, config.cacheDir);
255
+ const errorRoutes = await loadRouteHandlers(config.errorRoutes, config.rootDir, config.cacheDir);
256
+ return {
257
+ routes,
258
+ errorRoutes,
259
+ };
260
+ }
261
+ //# sourceMappingURL=global-config.js.map
@@ -1,5 +1,5 @@
1
- import { resolveConfig as normalizeConfig } from './env-config.js';
2
- import { getServerModeConfig as explodeMode } from './runtime-config.js';
3
- import { validateLwrAppConfig } from './validation/app-config.js';
4
- export { normalizeConfig, explodeMode, validateLwrAppConfig };
1
+ import { resolveGlobalConfig as normalizeConfig, loadConfig, loadRoutes, loadServices } from './global-config.js';
2
+ import { getRuntimeEnvironment } from './runtime-config.js';
3
+ export { version as LWR_VERSION } from '@lwrjs/config/package';
4
+ export { normalizeConfig, loadConfig, loadRoutes, loadServices, getRuntimeEnvironment };
5
5
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { resolveConfig as normalizeConfig } from './env-config.js';
2
- import { getServerModeConfig as explodeMode } from './runtime-config.js';
3
- import { validateLwrAppConfig } from './validation/app-config.js';
1
+ import { resolveGlobalConfig as normalizeConfig, loadConfig, loadRoutes, loadServices, } from './global-config.js';
2
+ import { getRuntimeEnvironment } from './runtime-config.js';
3
+ export { version as LWR_VERSION } from '@lwrjs/config/package';
4
4
  // Only export the functions we utilize internally
5
- export { normalizeConfig, explodeMode, validateLwrAppConfig };
5
+ export { normalizeConfig, loadConfig, loadRoutes, loadServices, getRuntimeEnvironment };
6
6
  //# sourceMappingURL=index.js.map
@@ -1,12 +1,19 @@
1
- import { ServerModeConfig } from '@lwrjs/types';
1
+ import type { ServerModeConfig, NormalizedLwrGlobalConfig, RuntimeEnvironment } from '@lwrjs/types';
2
2
  export declare const RUNTIME_CONFIGS: Record<string, ServerModeConfig>;
3
3
  /**
4
- * Get the runtime environment config for the mode.
4
+ * Get server mode config by name
5
5
  *
6
6
  * @throws {LwrServerError} Mode must be supported by LWR.
7
7
  *
8
- * @param {string} mode - the name of the server mode
9
- * @returns {ServerModeConfig} the runtime environment config for the mode
8
+ * @param {string} serverMode - the name of the server mode
9
+ * @returns {ServerModeConfig} the server mode config
10
10
  */
11
- export declare function getServerModeConfig(mode: string): ServerModeConfig;
11
+ export declare function getServerModeConfig(serverMode: string): ServerModeConfig;
12
+ /**
13
+ * Get runtime environment
14
+ *
15
+ * @param {NormalizedLwrGlobalConfig} config - the normalized global config object
16
+ * @returns {RuntimeEnvironment} the complete runtime environment
17
+ */
18
+ export declare function getRuntimeEnvironment(config: NormalizedLwrGlobalConfig): RuntimeEnvironment;
12
19
  //# sourceMappingURL=runtime-config.d.ts.map
@@ -1,10 +1,12 @@
1
1
  import { createSingleDiagnosticError, descriptions, LwrServerError } from '@lwrjs/diagnostics';
2
+ import { getFeatureFlags } from '@lwrjs/shared-utils';
2
3
  export const RUNTIME_CONFIGS = {
3
4
  dev: {
4
5
  bundle: false,
5
6
  minify: false,
6
7
  format: 'esm',
7
8
  compat: '0',
9
+ debug: false,
8
10
  watchFiles: true,
9
11
  defaultLocale: 'en_US',
10
12
  hmrEnabled: true,
@@ -18,6 +20,7 @@ export const RUNTIME_CONFIGS = {
18
20
  minify: true,
19
21
  format: 'esm',
20
22
  compat: '0',
23
+ debug: false,
21
24
  watchFiles: false,
22
25
  defaultLocale: 'en_US',
23
26
  hmrEnabled: false,
@@ -31,6 +34,7 @@ export const RUNTIME_CONFIGS = {
31
34
  minify: false,
32
35
  format: 'amd',
33
36
  compat: '1',
37
+ debug: false,
34
38
  watchFiles: true,
35
39
  defaultLocale: 'en_US',
36
40
  hmrEnabled: false,
@@ -44,6 +48,7 @@ export const RUNTIME_CONFIGS = {
44
48
  minify: true,
45
49
  format: 'amd',
46
50
  compat: '1',
51
+ debug: false,
47
52
  watchFiles: false,
48
53
  defaultLocale: 'en_US',
49
54
  hmrEnabled: false,
@@ -54,18 +59,35 @@ export const RUNTIME_CONFIGS = {
54
59
  },
55
60
  };
56
61
  /**
57
- * Get the runtime environment config for the mode.
62
+ * Get server mode config by name
58
63
  *
59
64
  * @throws {LwrServerError} Mode must be supported by LWR.
60
65
  *
61
- * @param {string} mode - the name of the server mode
62
- * @returns {ServerModeConfig} the runtime environment config for the mode
66
+ * @param {string} serverMode - the name of the server mode
67
+ * @returns {ServerModeConfig} the server mode config
63
68
  */
64
- export function getServerModeConfig(mode) {
65
- const selectedMode = RUNTIME_CONFIGS[mode];
69
+ export function getServerModeConfig(serverMode) {
70
+ const selectedMode = RUNTIME_CONFIGS[serverMode];
66
71
  if (!selectedMode) {
67
- throw createSingleDiagnosticError({ description: descriptions.SERVER.INVALID_MODE(mode) }, LwrServerError);
72
+ throw createSingleDiagnosticError({ description: descriptions.SERVER.INVALID_MODE(serverMode) }, LwrServerError);
68
73
  }
69
74
  return selectedMode;
70
75
  }
76
+ /**
77
+ * Get runtime environment
78
+ *
79
+ * @param {NormalizedLwrGlobalConfig} config - the normalized global config object
80
+ * @returns {RuntimeEnvironment} the complete runtime environment
81
+ */
82
+ export function getRuntimeEnvironment(config) {
83
+ const { serverMode, lwrVersion, apiVersion, basePath } = config;
84
+ return {
85
+ ...getServerModeConfig(config.serverMode),
86
+ featureFlags: getFeatureFlags(),
87
+ serverMode,
88
+ lwrVersion,
89
+ apiVersion,
90
+ basePath,
91
+ };
92
+ }
71
93
  //# sourceMappingURL=runtime-config.js.map
@@ -0,0 +1,3 @@
1
+ import { GlobalData } from '@lwrjs/types';
2
+ export declare function getGlobalData(globalDataDir: string, defaultData?: GlobalData): GlobalData;
3
+ //# sourceMappingURL=global-data.d.ts.map
@@ -0,0 +1,29 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ function recursiveJsonCollector(resources, currentPath, collector) {
5
+ for (const resource of resources) {
6
+ const resourcePath = path.join(currentPath, resource);
7
+ if (resource.endsWith('.json')) {
8
+ const resourceName = path.basename(resource, '.json');
9
+ const jsonSource = JSON.parse(fs.readFileSync(resourcePath, 'utf-8'));
10
+ collector[resourceName] = jsonSource;
11
+ }
12
+ else if (fs.statSync(resourcePath).isDirectory()) {
13
+ const dirContentList = fs.readdirSync(resourcePath);
14
+ collector[resource] = recursiveJsonCollector(dirContentList, resourcePath, {});
15
+ }
16
+ }
17
+ return collector;
18
+ }
19
+ export function getGlobalData(globalDataDir, defaultData = {}) {
20
+ if (!fs.existsSync(globalDataDir) || !fs.statSync(globalDataDir).isDirectory()) {
21
+ return defaultData;
22
+ }
23
+ const dirContentList = fs.readdirSync(globalDataDir);
24
+ return {
25
+ ...recursiveJsonCollector(dirContentList, globalDataDir, {}),
26
+ ...defaultData,
27
+ };
28
+ }
29
+ //# sourceMappingURL=global-data.js.map
@@ -1,7 +1,7 @@
1
1
  import type { BundleConfig, LwcConfig, LwrGlobalConfig, LwrLockerConfig, StaticSiteGenerator } from '@lwrjs/types';
2
2
  export declare function trimLwrConfig(config: LwrGlobalConfig): LwrGlobalConfig;
3
3
  export declare function mergeLwcConfig(config1: LwrGlobalConfig | undefined, config2: LwrGlobalConfig | undefined): LwcConfig;
4
- export declare function mergeBundleConfig(jsonConfig: LwrGlobalConfig | undefined, config: LwrGlobalConfig | undefined): BundleConfig;
4
+ export declare function mergeBundleConfig(config1: LwrGlobalConfig | undefined, config2: LwrGlobalConfig | undefined): BundleConfig;
5
5
  export declare function mergeLockerConfig(jsonConfig: LwrGlobalConfig | undefined, config: LwrGlobalConfig | undefined): LwrLockerConfig;
6
6
  export declare function mergeStaticGenerationConfig(configFile?: LwrGlobalConfig, configArg?: LwrGlobalConfig): StaticSiteGenerator;
7
7
  //# sourceMappingURL=merge.d.ts.map
@@ -1,5 +1,8 @@
1
1
  import { DEFAULT_LOCKER_TRUSTED_CMP, DEFAULT_LWR_LOCKER_CONFIG } from '@lwrjs/shared-utils';
2
2
  import { DEFAULT_BUNDLE_EXCLUSIONS, DEFAULT_GENERATOR_CONFIG, DEFAULT_LWR_MODULES } from '../defaults.js';
3
+ function isNormalizedLwrGlobalConfig(config) {
4
+ return config?.lwrVersion !== undefined;
5
+ }
3
6
  export function trimLwrConfig(config) {
4
7
  Object.keys(config).forEach((k) => {
5
8
  if (config[k] === undefined)
@@ -9,6 +12,10 @@ export function trimLwrConfig(config) {
9
12
  }
10
13
  // deep merge LWC configs
11
14
  export function mergeLwcConfig(config1, config2) {
15
+ // normalized config already contains the defaults
16
+ const defaultModules = !isNormalizedLwrGlobalConfig(config1) && !isNormalizedLwrGlobalConfig(config2)
17
+ ? DEFAULT_LWR_MODULES
18
+ : [];
12
19
  const modules1 = config1?.lwc?.modules || [];
13
20
  const modules2 = config2?.lwc?.modules || [];
14
21
  const interchangeable1 = config1?.lwc?.interchangeable || [];
@@ -18,7 +25,7 @@ export function mergeLwcConfig(config1, config2) {
18
25
  const interchangeableModules2 = config2?.lwc?.interchangeableModules || [];
19
26
  const mergedInterchangeableModules = [...interchangeableModules1, ...interchangeableModules2];
20
27
  return {
21
- modules: [...DEFAULT_LWR_MODULES, ...modules1, ...modules2],
28
+ modules: [...defaultModules, ...modules1, ...modules2],
22
29
  interchangeable: mergedInterchangeable.length ? mergedInterchangeable : undefined,
23
30
  interchangeableModules: mergedInterchangeableModules.length
24
31
  ? mergedInterchangeableModules
@@ -26,14 +33,14 @@ export function mergeLwcConfig(config1, config2) {
26
33
  };
27
34
  }
28
35
  // merge default bundle exclusions with any bundle exclusions specified in config
29
- export function mergeBundleConfig(jsonConfig, config) {
30
- const defaultExclusions = config?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
31
- jsonConfig?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
36
+ export function mergeBundleConfig(config1, config2) {
37
+ const defaultExclusions = config2?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
38
+ config1?.bundleConfig?.UNSAFE_lwrDefaultExclude ||
32
39
  DEFAULT_BUNDLE_EXCLUSIONS;
33
- const configExclusions = config?.bundleConfig?.exclude || jsonConfig?.bundleConfig?.exclude || [];
40
+ const configExclusions = config2?.bundleConfig?.exclude || config1?.bundleConfig?.exclude || [];
34
41
  return {
35
- ...jsonConfig?.bundleConfig,
36
- ...config?.bundleConfig,
42
+ ...config1?.bundleConfig,
43
+ ...config2?.bundleConfig,
37
44
  exclude: [...new Set([...defaultExclusions, ...configExclusions])],
38
45
  };
39
46
  }
@@ -0,0 +1,2 @@
1
+ export declare function loadModule<T>(filepath: string, rootDir: string, cacheDir: string): Promise<T>;
2
+ //# sourceMappingURL=module-loader.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { normalizeDirectory, resolveFileExtension, transpileTs } from '@lwrjs/shared-utils';
2
+ export async function loadModule(filepath, rootDir, cacheDir) {
3
+ // ensure paths are fully resolved before loading source
4
+ let resolvedFilePath = normalizeDirectory(filepath, rootDir);
5
+ const resolvedCacheDir = normalizeDirectory(cacheDir, rootDir);
6
+ try {
7
+ if (resolvedFilePath.endsWith('.ts')) {
8
+ const fullPath = resolveFileExtension(resolvedFilePath);
9
+ resolvedFilePath = await transpileTs(fullPath, { rootDir, cacheDir: resolvedCacheDir });
10
+ }
11
+ const moduleEntry = await import(resolvedFilePath);
12
+ const output = moduleEntry.default || moduleEntry;
13
+ return output;
14
+ }
15
+ catch (err) {
16
+ console.log(err);
17
+ throw new Error(`Unable to load configurable module: ${filepath}`);
18
+ }
19
+ }
20
+ //# sourceMappingURL=module-loader.js.map
@@ -1,7 +1,8 @@
1
- import type { LwrErrorRoute, LwrRoute, NormalizedLwrErrorRoute, NormalizedLwrRoute, ResourcePaths } from '@lwrjs/types';
1
+ import type { LwrErrorRoute, LwrRoute, NormalizedLwrErrorRoute, NormalizedLwrRoute, ResourcePaths, Route } from '@lwrjs/types';
2
2
  declare type ViewOrErrorRoute = LwrRoute | LwrErrorRoute;
3
3
  declare type NormalizedRoute<T extends ViewOrErrorRoute> = T extends LwrRoute ? NormalizedLwrRoute : NormalizedLwrErrorRoute;
4
4
  export declare function normalizeRoutes<T extends ViewOrErrorRoute>(routes?: T[]): NormalizedRoute<T>[];
5
5
  export declare function normalizeRoutePaths<T extends ViewOrErrorRoute>(routes: T[] | undefined, resourcePaths: ResourcePaths): NormalizedRoute<T>[];
6
+ export declare function loadRouteHandlers<T extends ViewOrErrorRoute>(routes: T[], rootDir: string, cacheDir: string): Promise<Route<T>[]>;
6
7
  export {};
7
8
  //# sourceMappingURL=routes.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import path from 'path';
2
2
  import { DEFAULT_LWR_BOOTSTRAP_CONFIG, normalizeDirectory, normalizeResourcePath } from '@lwrjs/shared-utils';
3
+ import { loadModule } from './module-loader.js';
3
4
  export function normalizeRoutes(routes = []) {
4
5
  return routes.map((route) => ({
5
6
  ...route,
@@ -22,4 +23,24 @@ export function normalizeRoutePaths(routes = [], resourcePaths) {
22
23
  return route;
23
24
  });
24
25
  }
26
+ export async function loadRouteHandlers(routes, rootDir, cacheDir) {
27
+ const cache = {};
28
+ return Promise.all(routes.map(async (route) => {
29
+ if (!route.routeHandler) {
30
+ return route;
31
+ }
32
+ if (cache[route.routeHandler]) {
33
+ return {
34
+ ...route,
35
+ routeHandler: cache[route.routeHandler],
36
+ };
37
+ }
38
+ const routeHandler = await loadModule(route.routeHandler, rootDir, path.join(cacheDir, 'routeHandlers'));
39
+ cache[route.routeHandler] = routeHandler;
40
+ return {
41
+ ...route,
42
+ routeHandler,
43
+ };
44
+ }));
45
+ }
25
46
  //# sourceMappingURL=routes.js.map
@@ -1,4 +1,5 @@
1
- import type { ServiceConfig, ServiceEntry } from '@lwrjs/types';
1
+ import type { LwrService, ServiceConfig, ServiceEntry, ResolvedServiceEntry } from '@lwrjs/types';
2
2
  export declare function normalizeServices(services?: ServiceConfig[]): ServiceEntry[];
3
3
  export declare function normalizeServicePaths(services: ServiceConfig[], rootDir: string): ServiceEntry[];
4
+ export declare function loadServiceEntries<T extends LwrService>(entries: ServiceEntry[], rootDir: string, cacheDir: string): Promise<ResolvedServiceEntry<T>[]>;
4
5
  //# sourceMappingURL=services.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import path from 'path';
2
2
  import { normalizeDirectory } from '@lwrjs/shared-utils';
3
3
  import { DEFAULT_SERVICE_PACKAGE_NAME } from '../defaults.js';
4
+ import { loadModule } from './module-loader.js';
4
5
  export function normalizeServices(services = []) {
5
6
  return services.map((service) => (Array.isArray(service) ? service : [service, undefined]));
6
7
  }
@@ -16,4 +17,10 @@ export function normalizeServicePaths(services, rootDir) {
16
17
  return [serviceName, serviceConfig];
17
18
  });
18
19
  }
20
+ export async function loadServiceEntries(entries, rootDir, cacheDir) {
21
+ return Promise.all(entries.map(async ([entry, config]) => {
22
+ const ctor = await loadModule(entry, rootDir, path.join(cacheDir, 'services'));
23
+ return [ctor, config];
24
+ }));
25
+ }
19
26
  //# sourceMappingURL=services.js.map
@@ -68,9 +68,12 @@ function validateRouteCommon(node, validationContext, propPrefix) {
68
68
  * - path: required path segment string
69
69
  * - method: optional 'get' | 'post'
70
70
  */
71
- function validateRoutes(node, validationContext) {
71
+ function validateRoutes(node, validationContext, preMerge) {
72
72
  if (node) {
73
- validationContext.assertNotEmptyArray(node, 'routes');
73
+ // routes may not be defined until after config hooks are applied
74
+ if (!preMerge) {
75
+ validationContext.assertNotEmptyArray(node, 'routes');
76
+ }
74
77
  if (node.children) {
75
78
  node.children.forEach((n, index) => {
76
79
  const propPrefix = `routes[${index}]`;
@@ -191,7 +194,7 @@ function validateRoot(node, validationContext, preMerge) {
191
194
  const routes = findNode(node, ['routes']);
192
195
  const errorRoutes = findNode(node, ['errorRoutes']);
193
196
  validationContext.assertUniqueIds([...(routes?.children || []), ...(errorRoutes?.children || [])], 'routes');
194
- validateRoutes(routes, validationContext);
197
+ validateRoutes(routes, validationContext, preMerge);
195
198
  validateErrorRoutes(errorRoutes, validationContext);
196
199
  validateAssets(findNode(node, ['assets']), validationContext, preMerge);
197
200
  validateLocker(findNode(node, ['locker']), validationContext);
package/package.cjs CHANGED
@@ -1,7 +1,13 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const rootPath = path.join(__dirname, './');
4
- const version = JSON.parse(fs.readFileSync(path.join(rootPath, 'package.json'), 'utf-8')).version;
4
+
5
+ let version;
6
+ if (globalThis.LWR_VERSION) {
7
+ version = globalThis.LWR_VERSION;
8
+ } else {
9
+ version = JSON.parse(fs.readFileSync(path.join(rootPath, 'package.json'), 'utf-8')).version;
10
+ }
5
11
 
6
12
  module.exports = {
7
13
  rootPath,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.11",
7
+ "version": "0.9.0-alpha.13",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -32,16 +32,16 @@
32
32
  "package.cjs"
33
33
  ],
34
34
  "dependencies": {
35
- "@lwrjs/diagnostics": "0.9.0-alpha.11",
36
- "@lwrjs/shared-utils": "0.9.0-alpha.11",
35
+ "@lwrjs/diagnostics": "0.9.0-alpha.13",
36
+ "@lwrjs/shared-utils": "0.9.0-alpha.13",
37
37
  "fs-extra": "^10.1.0",
38
38
  "jsonc-parser": "^3.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@lwrjs/types": "0.9.0-alpha.11"
41
+ "@lwrjs/types": "0.9.0-alpha.13"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=14.15.4 <19"
45
45
  },
46
- "gitHead": "3cb1275b364ae7373c1868c79e6082a122dbef9c"
46
+ "gitHead": "fa30915a685f6e8c5c2895d0c053d59145780123"
47
47
  }
@@ -1,22 +0,0 @@
1
- import type { LwrGlobalConfig, NormalizedLwrGlobalConfig } from '@lwrjs/types';
2
- export interface ResolveConfigOptions {
3
- skipDirNormalization?: boolean;
4
- skipCacheDirCreation?: boolean;
5
- }
6
- /**
7
- * Load, merge, and normalize all of the config sources.
8
- *
9
- * @remarks
10
- * Config hooks are not loaded or applied during config resolution.
11
- *
12
- * @privateRemarks
13
- * The `skipDirNormalization` and `skipCacheDirCreation` options are useful for generating
14
- * a portable global config. The directories can be normalized and the cache directory can
15
- * be created at runtime.
16
- *
17
- * @param {LwrGlobalConfig} configArg - programmatic global config
18
- * @param {ResolveConfigOptions} options - config resolution mutations
19
- * @returns {NormalizedLwrGlobalConfig} a normalized global config relative to the provided options
20
- */
21
- export declare function resolveConfig(configArg?: LwrGlobalConfig, options?: ResolveConfigOptions): NormalizedLwrGlobalConfig;
22
- //# sourceMappingURL=env-config.d.ts.map