@lwrjs/config 0.9.0-alpha.8 → 0.9.0-alpha.9

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.
@@ -36,13 +36,16 @@ var import_services = __toModule(require("./utils/services.cjs"));
36
36
  var import_routes = __toModule(require("./utils/routes.cjs"));
37
37
  var import_merge = __toModule(require("./utils/merge.cjs"));
38
38
  var import_lwc = __toModule(require("./utils/lwc.cjs"));
39
+ var import_jsonc_parser = __toModule(require("jsonc-parser"));
39
40
  function getLwrConfigFromFile(rootDir, lwrConfigPath = import_defaults.DEFAULT_LWR_CONFIG_JSON) {
40
41
  const resolvedLwrConfigPath = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(lwrConfigPath, rootDir));
41
42
  if (!import_fs.default.existsSync(resolvedLwrConfigPath)) {
42
43
  import_shared_utils.logger.warn(`LWR Config not found on "${resolvedLwrConfigPath}"`);
43
44
  return void 0;
44
45
  }
45
- return (0, import_app_config.validateLwrAppConfig)((0, import_shared_utils.readFile)(resolvedLwrConfigPath), "file");
46
+ const configSource = (0, import_shared_utils.readFile)(resolvedLwrConfigPath);
47
+ (0, import_app_config.validateLwrAppConfig)(configSource, "file");
48
+ return (0, import_jsonc_parser.parse)(configSource);
46
49
  }
47
50
  function createCacheFolder(cache, rootDir) {
48
51
  const cacheDir = (0, import_shared_utils.normalizeDirectory)(cache, rootDir);
@@ -53,7 +56,7 @@ function createCacheFolder(cache, rootDir) {
53
56
  function loadConfig(configArg) {
54
57
  if (configArg) {
55
58
  configArg = (0, import_merge.trimLwrConfig)(configArg);
56
- (0, import_app_config.validateLwrAppConfig)(JSON.stringify(configArg), "pre");
59
+ (0, import_app_config.validateLwrAppConfig)(configArg, "pre");
57
60
  }
58
61
  const rootDir = import_path.default.resolve(configArg?.rootDir || import_defaults.DEFAULT_ROOT_DIR);
59
62
  const configFile = !configArg?.ignoreLwrConfigFile ? getLwrConfigFromFile(rootDir, configArg?.lwrConfigFile) : void 0;
@@ -170,8 +170,9 @@ function validateRoot(node, validationContext, preMerge) {
170
170
  validationContext.assertIsEnvironment((0, import_jsonc_parser.findNodeAtLocation)(node, ["environment"]), "environment");
171
171
  validationContext.assertIsBasePath((0, import_jsonc_parser.findNodeAtLocation)(node, ["basePath"]), "basePath");
172
172
  }
173
- function validateLwrAppConfig(jsonSourceText, phase) {
173
+ function validateLwrAppConfig(config, phase) {
174
174
  try {
175
+ const jsonSourceText = typeof config === "string" ? config : JSON.stringify(config);
175
176
  const errors = [];
176
177
  const preMerge = phase !== "post";
177
178
  const rootNode = (0, import_jsonc_parser.parseTree)(jsonSourceText, errors);
@@ -189,12 +190,12 @@ function validateLwrAppConfig(jsonSourceText, phase) {
189
190
  if (validationContext.diagnostics.length) {
190
191
  throw new import_diagnostics.LwrConfigValidationError(`Configuration validation errors in ${SOURCE_BY_PHASE[phase]}`, validationContext.diagnostics);
191
192
  }
192
- return (0, import_jsonc_parser.parse)(jsonSourceText);
193
+ return;
193
194
  } catch (err) {
194
195
  if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
195
196
  console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
196
197
  console.dir(err, {depth: null});
197
- return (0, import_jsonc_parser.parse)(jsonSourceText);
198
+ return;
198
199
  } else {
199
200
  throw err;
200
201
  }
@@ -8,6 +8,7 @@ import { normalizeServicePaths, normalizeServices } from './utils/services.js';
8
8
  import { normalizeRoutePaths, normalizeRoutes } from './utils/routes.js';
9
9
  import { mergeBundleConfig, mergeLockerConfig, mergeLwcConfig, mergeStaticGenerationConfig, trimLwrConfig, } from './utils/merge.js';
10
10
  import { normalizeLwcConfig, normalizeModulePaths } from './utils/lwc.js';
11
+ import { parse } from 'jsonc-parser';
11
12
  /**
12
13
  * Load and validate the global config file.
13
14
  *
@@ -28,7 +29,9 @@ function getLwrConfigFromFile(rootDir, lwrConfigPath = DEFAULT_LWR_CONFIG_JSON)
28
29
  logger.warn(`LWR Config not found on "${resolvedLwrConfigPath}"`);
29
30
  return undefined;
30
31
  }
31
- return validateLwrAppConfig(readFile(resolvedLwrConfigPath), 'file');
32
+ const configSource = readFile(resolvedLwrConfigPath);
33
+ validateLwrAppConfig(configSource, 'file');
34
+ return parse(configSource);
32
35
  }
33
36
  /**
34
37
  * Normalize the cache directory path and create the directory
@@ -62,7 +65,7 @@ function loadConfig(configArg) {
62
65
  // the programmatic config is trimmed to prevent overriding properties with an undefined value
63
66
  configArg = trimLwrConfig(configArg);
64
67
  // validation errors will not be caught unless `UNSAFE_IGNORE_CONFIG_VALIDATION` is set
65
- validateLwrAppConfig(JSON.stringify(configArg), 'pre');
68
+ validateLwrAppConfig(configArg, 'pre');
66
69
  }
67
70
  // resolve the current root dir
68
71
  const rootDir = path.resolve(configArg?.rootDir || DEFAULT_ROOT_DIR);
@@ -1,10 +1,10 @@
1
- import { LwrGlobalConfig } from '@lwrjs/types';
1
+ import type { LwrGlobalConfig } from '@lwrjs/types';
2
2
  export declare const SOURCE_BY_PHASE: {
3
3
  file: string;
4
4
  pre: string;
5
5
  post: string;
6
6
  };
7
7
  declare type ConfigPhase = 'file' | 'pre' | 'post';
8
- export declare function validateLwrAppConfig(jsonSourceText: string, phase: ConfigPhase): LwrGlobalConfig;
8
+ export declare function validateLwrAppConfig(config: string | LwrGlobalConfig, phase: ConfigPhase): void | never;
9
9
  export {};
10
10
  //# sourceMappingURL=app-config.d.ts.map
@@ -1,4 +1,4 @@
1
- import { parse, parseTree, printParseErrorCode, findNodeAtLocation as findNode, } from 'jsonc-parser';
1
+ import { parseTree, printParseErrorCode, findNodeAtLocation as findNode, } from 'jsonc-parser';
2
2
  import { createSingleDiagnosticError, descriptions, LwrConfigValidationError } from '@lwrjs/diagnostics';
3
3
  import { ASSET_DIR_ATTRIBUTE_KEYS, ASSET_FILE_ATTRIBUTE_KEYS, BOOTSTRAP_ATTRIBUTE_KEYS, ERROR_ROUTE_ATTRIBUTE_KEYS, LOCKER_ATTRIBUTE_KEYS, ROOT_ATTRIBUTE_KEYS, ROUTE_ATTRIBUTE_KEYS, ValidationContext, } from './app-config-context.js';
4
4
  import { calculatePositionFromSource } from './helpers.js';
@@ -219,8 +219,9 @@ function validateRoot(node, validationContext, preMerge) {
219
219
  validationContext.assertIsEnvironment(findNode(node, ['environment']), 'environment');
220
220
  validationContext.assertIsBasePath(findNode(node, ['basePath']), 'basePath');
221
221
  }
222
- export function validateLwrAppConfig(jsonSourceText, phase) {
222
+ export function validateLwrAppConfig(config, phase) {
223
223
  try {
224
+ const jsonSourceText = typeof config === 'string' ? config : JSON.stringify(config);
224
225
  const errors = [];
225
226
  const preMerge = phase !== 'post'; // meaning the config has not yet been merged and normalized
226
227
  const rootNode = parseTree(jsonSourceText, errors);
@@ -241,13 +242,13 @@ export function validateLwrAppConfig(jsonSourceText, phase) {
241
242
  if (validationContext.diagnostics.length) {
242
243
  throw new LwrConfigValidationError(`Configuration validation errors in ${SOURCE_BY_PHASE[phase]}`, validationContext.diagnostics);
243
244
  }
244
- return parse(jsonSourceText);
245
+ return;
245
246
  }
246
247
  catch (err) {
247
248
  if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
248
249
  console.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
249
250
  console.dir(err, { depth: null });
250
- return parse(jsonSourceText);
251
+ return;
251
252
  }
252
253
  else {
253
254
  throw err;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.8",
7
+ "version": "0.9.0-alpha.9",
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.8",
36
- "@lwrjs/shared-utils": "0.9.0-alpha.8",
35
+ "@lwrjs/diagnostics": "0.9.0-alpha.9",
36
+ "@lwrjs/shared-utils": "0.9.0-alpha.9",
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.8"
41
+ "@lwrjs/types": "0.9.0-alpha.9"
42
42
  },
43
43
  "engines": {
44
44
  "node": ">=14.15.4 <19"
45
45
  },
46
- "gitHead": "013fcee240ff2e1c23ef304e70fc39d6ef13fb8b"
46
+ "gitHead": "93522592d25375bb20da156f864d153ffcd3ec88"
47
47
  }