@ms-cloudpack/config 0.35.13 → 0.35.15

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.
@@ -1 +1 @@
1
- {"version":3,"file":"addReadAppConfigOptions.d.ts","sourceRoot":"","sources":["../../src/readConfig/addReadAppConfigOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,UAAU,GAAG,QAAQ,CAAC,EAChH,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAqBT"}
1
+ {"version":3,"file":"addReadAppConfigOptions.d.ts","sourceRoot":"","sources":["../../src/readConfig/addReadAppConfigOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,UAAU,GAAG,QAAQ,CAAC,EAChH,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAkDT"}
@@ -1,5 +1,5 @@
1
1
  export function addReadAppConfigOptions(config, options) {
2
- const { extraPackageSettings, extraFeatures, extraDefineFlags } = options;
2
+ const { extraPackageSettings, extraFeatures, extraDefineFlags, enableDefaultFeatures } = options;
3
3
  if (extraPackageSettings) {
4
4
  // Add these last so they take precedence.
5
5
  (config.packageSettings ??= []).push(...extraPackageSettings);
@@ -14,6 +14,31 @@ export function addReadAppConfigOptions(config, options) {
14
14
  ...extraDefineFlags,
15
15
  };
16
16
  }
17
+ if (enableDefaultFeatures) {
18
+ // Enable select features by default.
19
+ if (!config.features) {
20
+ config.features = {};
21
+ }
22
+ const { features } = config;
23
+ const defaultFeatures = [
24
+ // Default to provide a more flexible experience.
25
+ 'autoUpdateEntries',
26
+ // Default to true for better support.
27
+ 'enableModuleWorkers',
28
+ // Default to true for better performance.
29
+ 'enableWatcherInFork',
30
+ // Default to true for a more portable import map.
31
+ 'relativeImportMapPaths',
32
+ // Default to true to also enable worker support.
33
+ 'useSingleWebServer',
34
+ ];
35
+ // Enable any default features that are not already set.
36
+ for (const featureName of defaultFeatures) {
37
+ if (features[featureName] === undefined) {
38
+ features[featureName] = true;
39
+ }
40
+ }
41
+ }
17
42
  return config;
18
43
  }
19
44
  //# sourceMappingURL=addReadAppConfigOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"addReadAppConfigOptions.js","sourceRoot":"","sources":["../../src/readConfig/addReadAppConfigOptions.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,uBAAuB,CACrC,MAAe,EACf,OAA6B;IAE7B,MAAM,EAAE,oBAAoB,EAAE,aAAa,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAE1E,IAAI,oBAAoB,EAAE,CAAC;QACzB,0CAA0C;QAC1C,CAAC,MAAM,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,uBAAuB;QACvB,MAAM,CAAC,QAAQ,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;IAC7D,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,CAAC,MAAM,GAAG;YACd,GAAG,MAAM,CAAC,MAAM;YAChB,GAAG,gBAAgB;SACpB,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { AppConfig } from '@ms-cloudpack/common-types';\nimport type { ReadAppConfigOptions } from './readAppConfig.js';\n\nexport function addReadAppConfigOptions<TConfig extends Pick<AppConfig, 'packageSettings' | 'features' | 'define'>>(\n config: TConfig,\n options: ReadAppConfigOptions,\n): TConfig {\n const { extraPackageSettings, extraFeatures, extraDefineFlags } = options;\n\n if (extraPackageSettings) {\n // Add these last so they take precedence.\n (config.packageSettings ??= []).push(...extraPackageSettings);\n }\n\n if (extraFeatures) {\n // Merge extra features\n config.features = { ...config.features, ...extraFeatures };\n }\n\n if (extraDefineFlags) {\n config.define = {\n ...config.define,\n ...extraDefineFlags,\n };\n }\n\n return config;\n}\n"]}
1
+ {"version":3,"file":"addReadAppConfigOptions.js","sourceRoot":"","sources":["../../src/readConfig/addReadAppConfigOptions.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,uBAAuB,CACrC,MAAe,EACf,OAA6B;IAE7B,MAAM,EAAE,oBAAoB,EAAE,aAAa,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC;IAEjG,IAAI,oBAAoB,EAAE,CAAC;QACzB,0CAA0C;QAC1C,CAAC,MAAM,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,oBAAoB,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,uBAAuB;QACvB,MAAM,CAAC,QAAQ,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;IAC7D,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,CAAC,MAAM,GAAG;YACd,GAAG,MAAM,CAAC,MAAM;YAChB,GAAG,gBAAgB;SACpB,CAAC;IACJ,CAAC;IAED,IAAI,qBAAqB,EAAE,CAAC;QAC1B,qCAAqC;QACrC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrB,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC;QACvB,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QAE5B,MAAM,eAAe,GAAuB;YAC1C,iDAAiD;YACjD,mBAAmB;YACnB,sCAAsC;YACtC,qBAAqB;YACrB,0CAA0C;YAC1C,qBAAqB;YACrB,kDAAkD;YAClD,wBAAwB;YACxB,iDAAiD;YACjD,oBAAoB;SACrB,CAAC;QAEF,wDAAwD;QACxD,KAAK,MAAM,WAAW,IAAI,eAAe,EAAE,CAAC;YAC1C,IAAI,QAAQ,CAAC,WAAW,CAAC,KAAK,SAAS,EAAE,CAAC;gBACxC,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { AppConfig, Features } from '@ms-cloudpack/common-types';\nimport type { ReadAppConfigOptions } from './readAppConfig.js';\n\nexport function addReadAppConfigOptions<TConfig extends Pick<AppConfig, 'packageSettings' | 'features' | 'define'>>(\n config: TConfig,\n options: ReadAppConfigOptions,\n): TConfig {\n const { extraPackageSettings, extraFeatures, extraDefineFlags, enableDefaultFeatures } = options;\n\n if (extraPackageSettings) {\n // Add these last so they take precedence.\n (config.packageSettings ??= []).push(...extraPackageSettings);\n }\n\n if (extraFeatures) {\n // Merge extra features\n config.features = { ...config.features, ...extraFeatures };\n }\n\n if (extraDefineFlags) {\n config.define = {\n ...config.define,\n ...extraDefineFlags,\n };\n }\n\n if (enableDefaultFeatures) {\n // Enable select features by default.\n if (!config.features) {\n config.features = {};\n }\n\n const { features } = config;\n\n const defaultFeatures: (keyof Features)[] = [\n // Default to provide a more flexible experience.\n 'autoUpdateEntries',\n // Default to true for better support.\n 'enableModuleWorkers',\n // Default to true for better performance.\n 'enableWatcherInFork',\n // Default to true for a more portable import map.\n 'relativeImportMapPaths',\n // Default to true to also enable worker support.\n 'useSingleWebServer',\n ];\n\n // Enable any default features that are not already set.\n for (const featureName of defaultFeatures) {\n if (features[featureName] === undefined) {\n features[featureName] = true;\n }\n }\n }\n\n return config;\n}\n"]}
@@ -13,6 +13,10 @@ export interface ReadAppConfigOptions {
13
13
  * Extra define flags to add at the end of user-provided settings (so they take precedence).
14
14
  */
15
15
  extraDefineFlags?: DefineFlags;
16
+ /**
17
+ * Enable default features that are not explicitly set in the config.
18
+ */
19
+ enableDefaultFeatures?: boolean;
16
20
  }
17
21
  /**
18
22
  * Reads the user config file and merges with any parent configs asynchronously.
@@ -1 +1 @@
1
- {"version":3,"file":"readAppConfig.d.ts","sourceRoot":"","sources":["../../src/readConfig/readAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAYvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEtE,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,aAAa,CAAC,EAAE,QAAQ,CAAC;IAEzB;;OAEG;IACH,oBAAoB,CAAC,EAAE,eAAe,EAAE,CAAC;IAEzC;;OAEG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC,CAwCvG"}
1
+ {"version":3,"file":"readAppConfig.d.ts","sourceRoot":"","sources":["../../src/readConfig/readAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAYvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEtE,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,aAAa,CAAC,EAAE,QAAQ,CAAC;IAEzB;;OAEG;IACH,oBAAoB,CAAC,EAAE,eAAe,EAAE,CAAC;IAEzC;;OAEG;IACH,gBAAgB,CAAC,EAAE,WAAW,CAAC;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AC;QAED,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC;QAC1B,OAAO,MAAM,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC9B,OAAO,MAAM,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACtC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;YACtC,OAAO,OAAO,CAAC,WAAW,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,qCAAqC;AACvC,CAAC","sourcesContent":["import type { AppConfig, Features, PackageSettings } from '@ms-cloudpack/common-types';\nimport { allFeatures } from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport fs from 'fs';\nimport { getConfigPath } from '../getConfigPath.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\nimport { resolveParentConfig } from './resolveParentConfig.js';\nimport { resolveModule } from '@ms-cloudpack/path-utilities';\nimport { validateMatch } from '../packageSettings/validateMatch.js';\nimport { expandEnvironmentVariables } from './expandEnvironmentVariables.js';\nimport { addReadAppConfigOptions } from './addReadAppConfigOptions.js';\nimport { pathToFileURL } from 'url'; // Import the pathToFileURL function\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\n\nexport interface ReadAppConfigOptions {\n /**\n * Extra feature settings. There will be a warning if any of these are invalid.\n */\n extraFeatures?: Features;\n\n /**\n * Extra package settings to add at the end of user-provided settings (so they take precedence).\n */\n extraPackageSettings?: PackageSettings[];\n\n /**\n * Extra define flags to add at the end of user-provided settings (so they take precedence).\n */\n extraDefineFlags?: DefineFlags;\n}\n\n/**\n * Reads the user config file and merges with any parent configs asynchronously.\n * Note this is only useful for making modifications to the user config.\n * For a full merged representation of config, use `readConfig` instead.\n *\n * Throws an error if the config file exists but is not valid JSON, there's some error reading it,\n * or any settings are invalid. (As of writing, this doesn't do full schema validation; it only\n * checks certain specific settings.)\n */\nexport async function readAppConfig(appPath: string, options?: ReadAppConfigOptions): Promise<AppConfig> {\n const { appConfigPath, appConfigPathsJS } = getConfigPath(appPath);\n\n // Do a separate existence check for the top-level config, since it's fine if that doesn't exist.\n // (readJs[on]AppConfig throws if the file doesn't exist because it's also used for reading\n // parent configs from \"extends\", which must exist if specified.)\n let config: AppConfig;\n\n // Find the js config that exists amongst the possible options.\n // .js .cjs .mjs\n const JSConfigPaths = appConfigPathsJS.filter((p) => fs.existsSync(p));\n if (JSConfigPaths.length > 1) {\n console.warn(`Multiple JS config files found:\\n ${JSConfigPaths.join('\\n ')}\\n` + `Using: ${JSConfigPaths[0]}`);\n }\n\n const appConfigPathJS = JSConfigPaths.length > 0 ? JSConfigPaths[0] : undefined;\n if (appConfigPathJS && fs.existsSync(appConfigPath)) {\n console.warn(\n `Both JSON: ${appConfigPath} and Javascript: ${appConfigPathJS} configs exist.\\n` +\n `Using Javascript: ${appConfigPathJS}`,\n );\n }\n\n if (appConfigPathJS) {\n // If the JS config exists, use that instead of the JSON file.\n config = await readJsAppConfig(appConfigPathJS);\n expandEnvironmentVariables(config as Record<string, unknown>);\n } else if (fs.existsSync(appConfigPath)) {\n config = await readJsonAppConfig(appConfigPath);\n expandEnvironmentVariables(config as Record<string, unknown>);\n } else {\n // If neither exists, return an empty config object.\n config = {};\n }\n\n if (options) {\n config = addReadAppConfigOptions(config, options);\n }\n\n return config;\n}\n\n/**\n * Resolve import specifiers for bundler capabilities registry.\n * Throws if a specifier can't be resolved.\n */\nfunction resolveBundlerCapabilities(params: { appConfig: AppConfig; configPath: string }): void {\n const {\n appConfig: { bundlerCapabilitiesRegistry },\n configPath,\n } = params;\n if (!bundlerCapabilitiesRegistry) {\n return;\n }\n\n for (const [name, importSpecifier] of Object.entries(bundlerCapabilitiesRegistry)) {\n try {\n const moduleUrl = resolveModule({ parentPath: configPath, importSpecifier });\n bundlerCapabilitiesRegistry[name] = moduleUrl.toString();\n } catch (e) {\n throw new Error(`Error resolving bundler capability \"${importSpecifier}\":\\n${(e as Error).message || e}`);\n }\n }\n}\n\n/**\n * Reads the JSON app config file and calls `processConfig` on it.\n * Throws an error if the config file exists but is not valid JSON, or there's some error reading it.\n * @param configPath - The path to the config file.\n * @returns The parsed AppConfig object.\n */\nasync function readJsonAppConfig(configPath: string): Promise<AppConfig> {\n const appConfig = await readJson<AppConfig>(configPath, { mode: 'permissive', throwOnError: true });\n if (!appConfig) {\n // shouldn't happen, but just in case/to satisfy the types...\n throw new Error(`Could not read config file ${configPath}`);\n }\n return processConfig(configPath, appConfig);\n}\n\n/**\n * Reads the JavaScript app config file and calls `processConfig` on it.\n * Throws an error if the config file exists but is not valid, or there's some error reading it.\n * @param configPath - The path to the config file.\n * @returns The parsed AppConfig object.\n */\nasync function readJsAppConfig(configPath: string): Promise<AppConfig> {\n // Convert configPath to a URL for import.\n try {\n const appConfig = (await (import(pathToFileURL(configPath).toString()) as Promise<{ default: AppConfig }>)).default;\n return processConfig(configPath, appConfig);\n } catch (e) {\n throw new Error(`Error reading config file ${configPath}:\\n${(e as Error).message || e}`);\n }\n}\n\n/**\n * Processes the app config file and merges it with any parent configs.\n * This includes validating the config, checking for deprecated values, and resolving bundler capabilities.\n */\nasync function processConfig(configPath: string, appConfig: AppConfig): Promise<AppConfig> {\n if (!validateConfig(appConfig)) {\n throw new Error(`Config file ${configPath} has invalid settings (see above for details)`);\n }\n\n checkFeatures(appConfig.features, configPath);\n\n resolveBundlerCapabilities({ appConfig, configPath });\n\n processDeprecatedValues(appConfig);\n\n // Read and merge with any parent configs (the same processing is applied to parent configs)\n const { extends: _extends = [] } = appConfig;\n const extendsArray = Array.isArray(_extends) ? _extends : [_extends];\n const parentConfigs = await Promise.all(\n extendsArray.map((importSpecifier) => {\n const parentConfigPath = resolveParentConfig({ configPath, importSpecifier });\n return readJsonAppConfig(parentConfigPath);\n }),\n );\n return mergeParentConfig({ appConfig, parentConfigs });\n}\n\n/**\n * Validate parts of the current config file (before merging with parents) and log any errors.\n * Logging here and then letting the caller throw if needed allows us to show more errors at once.\n * @returns true if valid, false if not\n */\nfunction validateConfig(appConfig: AppConfig): boolean {\n let isValid = true;\n\n // Verify that there are no matches with a negated name and a version\n for (const setting of appConfig.packageSettings || []) {\n const { match } = setting;\n const matches = Array.isArray(match) ? match : [match];\n for (const m of matches) {\n const result = validateMatch(m);\n if (!result.isValid) {\n isValid = false;\n console.error(`Invalid packageSettings match: ${result.error}`);\n }\n }\n }\n\n return isValid;\n}\n\n/**\n * Warn if any feature names are invalid, and remove them.\n */\nfunction checkFeatures(features: Record<string, boolean> | undefined, configPath: string): void {\n if (!features) {\n return;\n }\n\n const invalidFeatures: string[] = [];\n for (const featureName of Object.keys(features)) {\n if (!allFeatures[featureName as keyof Features]) {\n invalidFeatures.push(featureName);\n delete features[featureName];\n }\n }\n\n if (invalidFeatures.length) {\n console.warn(\n `Unknown feature(s) found in ${configPath} (most likely they were graduated or removed in Cloudpack):\\n ` +\n invalidFeatures.join(', '),\n );\n }\n}\n\n/**\n * Delete deprecated values and convert them to the new format. (This mutates the `config` object.)\n */\nfunction processDeprecatedValues(config: AppConfig): void {\n /* eslint-disable etc/no-deprecated */\n const { devServer, server, packageSettings = [] } = config;\n\n if (devServer) {\n if (server) {\n throw new Error('Cannot have both \"devServer\" and \"server\" in the config file. Use \"server\" only.');\n }\n\n config.server = devServer;\n delete config.devServer;\n }\n\n if (server?.routes) {\n config.routes = server.routes;\n delete server.routes;\n }\n\n for (const setting of packageSettings) {\n if (setting.bundlerType) {\n setting.bundler = setting.bundlerType;\n delete setting.bundlerType;\n }\n }\n /* eslint-enable etc/no-deprecated */\n}\n"]}
1
+ {"version":3,"file":"readAppConfig.js","sourceRoot":"","sources":["../../src/readConfig/readAppConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CA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,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;YACtC,OAAO,OAAO,CAAC,WAAW,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,qCAAqC;AACvC,CAAC","sourcesContent":["import type { AppConfig, Features, PackageSettings } from '@ms-cloudpack/common-types';\nimport { allFeatures } from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport fs from 'fs';\nimport { getConfigPath } from '../getConfigPath.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\nimport { resolveParentConfig } from './resolveParentConfig.js';\nimport { resolveModule } from '@ms-cloudpack/path-utilities';\nimport { validateMatch } from '../packageSettings/validateMatch.js';\nimport { expandEnvironmentVariables } from './expandEnvironmentVariables.js';\nimport { addReadAppConfigOptions } from './addReadAppConfigOptions.js';\nimport { pathToFileURL } from 'url'; // Import the pathToFileURL function\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\n\nexport interface ReadAppConfigOptions {\n /**\n * Extra feature settings. There will be a warning if any of these are invalid.\n */\n extraFeatures?: Features;\n\n /**\n * Extra package settings to add at the end of user-provided settings (so they take precedence).\n */\n extraPackageSettings?: PackageSettings[];\n\n /**\n * Extra define flags to add at the end of user-provided settings (so they take precedence).\n */\n extraDefineFlags?: DefineFlags;\n\n /**\n * Enable default features that are not explicitly set in the config.\n */\n enableDefaultFeatures?: boolean;\n}\n\n/**\n * Reads the user config file and merges with any parent configs asynchronously.\n * Note this is only useful for making modifications to the user config.\n * For a full merged representation of config, use `readConfig` instead.\n *\n * Throws an error if the config file exists but is not valid JSON, there's some error reading it,\n * or any settings are invalid. (As of writing, this doesn't do full schema validation; it only\n * checks certain specific settings.)\n */\nexport async function readAppConfig(appPath: string, options?: ReadAppConfigOptions): Promise<AppConfig> {\n const { appConfigPath, appConfigPathsJS } = getConfigPath(appPath);\n\n // Do a separate existence check for the top-level config, since it's fine if that doesn't exist.\n // (readJs[on]AppConfig throws if the file doesn't exist because it's also used for reading\n // parent configs from \"extends\", which must exist if specified.)\n let config: AppConfig;\n\n // Find the js config that exists amongst the possible options.\n // .js .cjs .mjs\n const JSConfigPaths = appConfigPathsJS.filter((p) => fs.existsSync(p));\n if (JSConfigPaths.length > 1) {\n console.warn(`Multiple JS config files found:\\n ${JSConfigPaths.join('\\n ')}\\n` + `Using: ${JSConfigPaths[0]}`);\n }\n\n const appConfigPathJS = JSConfigPaths.length > 0 ? JSConfigPaths[0] : undefined;\n if (appConfigPathJS && fs.existsSync(appConfigPath)) {\n console.warn(\n `Both JSON: ${appConfigPath} and Javascript: ${appConfigPathJS} configs exist.\\n` +\n `Using Javascript: ${appConfigPathJS}`,\n );\n }\n\n if (appConfigPathJS) {\n // If the JS config exists, use that instead of the JSON file.\n config = await readJsAppConfig(appConfigPathJS);\n expandEnvironmentVariables(config as Record<string, unknown>);\n } else if (fs.existsSync(appConfigPath)) {\n config = await readJsonAppConfig(appConfigPath);\n expandEnvironmentVariables(config as Record<string, unknown>);\n } else {\n // If neither exists, return an empty config object.\n config = {};\n }\n\n if (options) {\n config = addReadAppConfigOptions(config, options);\n }\n\n return config;\n}\n\n/**\n * Resolve import specifiers for bundler capabilities registry.\n * Throws if a specifier can't be resolved.\n */\nfunction resolveBundlerCapabilities(params: { appConfig: AppConfig; configPath: string }): void {\n const {\n appConfig: { bundlerCapabilitiesRegistry },\n configPath,\n } = params;\n if (!bundlerCapabilitiesRegistry) {\n return;\n }\n\n for (const [name, importSpecifier] of Object.entries(bundlerCapabilitiesRegistry)) {\n try {\n const moduleUrl = resolveModule({ parentPath: configPath, importSpecifier });\n bundlerCapabilitiesRegistry[name] = moduleUrl.toString();\n } catch (e) {\n throw new Error(`Error resolving bundler capability \"${importSpecifier}\":\\n${(e as Error).message || e}`);\n }\n }\n}\n\n/**\n * Reads the JSON app config file and calls `processConfig` on it.\n * Throws an error if the config file exists but is not valid JSON, or there's some error reading it.\n * @param configPath - The path to the config file.\n * @returns The parsed AppConfig object.\n */\nasync function readJsonAppConfig(configPath: string): Promise<AppConfig> {\n const appConfig = await readJson<AppConfig>(configPath, { mode: 'permissive', throwOnError: true });\n if (!appConfig) {\n // shouldn't happen, but just in case/to satisfy the types...\n throw new Error(`Could not read config file ${configPath}`);\n }\n return processConfig(configPath, appConfig);\n}\n\n/**\n * Reads the JavaScript app config file and calls `processConfig` on it.\n * Throws an error if the config file exists but is not valid, or there's some error reading it.\n * @param configPath - The path to the config file.\n * @returns The parsed AppConfig object.\n */\nasync function readJsAppConfig(configPath: string): Promise<AppConfig> {\n // Convert configPath to a URL for import.\n try {\n const appConfig = (await (import(pathToFileURL(configPath).toString()) as Promise<{ default: AppConfig }>)).default;\n return processConfig(configPath, appConfig);\n } catch (e) {\n throw new Error(`Error reading config file ${configPath}:\\n${(e as Error).message || e}`);\n }\n}\n\n/**\n * Processes the app config file and merges it with any parent configs.\n * This includes validating the config, checking for deprecated values, and resolving bundler capabilities.\n */\nasync function processConfig(configPath: string, appConfig: AppConfig): Promise<AppConfig> {\n if (!validateConfig(appConfig)) {\n throw new Error(`Config file ${configPath} has invalid settings (see above for details)`);\n }\n\n checkFeatures(appConfig.features, configPath);\n\n resolveBundlerCapabilities({ appConfig, configPath });\n\n processDeprecatedValues(appConfig);\n\n // Read and merge with any parent configs (the same processing is applied to parent configs)\n const { extends: _extends = [] } = appConfig;\n const extendsArray = Array.isArray(_extends) ? _extends : [_extends];\n const parentConfigs = await Promise.all(\n extendsArray.map((importSpecifier) => {\n const parentConfigPath = resolveParentConfig({ configPath, importSpecifier });\n return readJsonAppConfig(parentConfigPath);\n }),\n );\n return mergeParentConfig({ appConfig, parentConfigs });\n}\n\n/**\n * Validate parts of the current config file (before merging with parents) and log any errors.\n * Logging here and then letting the caller throw if needed allows us to show more errors at once.\n * @returns true if valid, false if not\n */\nfunction validateConfig(appConfig: AppConfig): boolean {\n let isValid = true;\n\n // Verify that there are no matches with a negated name and a version\n for (const setting of appConfig.packageSettings || []) {\n const { match } = setting;\n const matches = Array.isArray(match) ? match : [match];\n for (const m of matches) {\n const result = validateMatch(m);\n if (!result.isValid) {\n isValid = false;\n console.error(`Invalid packageSettings match: ${result.error}`);\n }\n }\n }\n\n return isValid;\n}\n\n/**\n * Warn if any feature names are invalid, and remove them.\n */\nfunction checkFeatures(features: Record<string, boolean> | undefined, configPath: string): void {\n if (!features) {\n return;\n }\n\n const invalidFeatures: string[] = [];\n for (const featureName of Object.keys(features)) {\n if (!allFeatures[featureName as keyof Features]) {\n invalidFeatures.push(featureName);\n delete features[featureName];\n }\n }\n\n if (invalidFeatures.length) {\n console.warn(\n `Unknown feature(s) found in ${configPath} (most likely they were graduated or removed in Cloudpack):\\n ` +\n invalidFeatures.join(', '),\n );\n }\n}\n\n/**\n * Delete deprecated values and convert them to the new format. (This mutates the `config` object.)\n */\nfunction processDeprecatedValues(config: AppConfig): void {\n /* eslint-disable etc/no-deprecated */\n const { devServer, server, packageSettings = [] } = config;\n\n if (devServer) {\n if (server) {\n throw new Error('Cannot have both \"devServer\" and \"server\" in the config file. Use \"server\" only.');\n }\n\n config.server = devServer;\n delete config.devServer;\n }\n\n if (server?.routes) {\n config.routes = server.routes;\n delete server.routes;\n }\n\n for (const setting of packageSettings) {\n if (setting.bundlerType) {\n setting.bundler = setting.bundlerType;\n delete setting.bundlerType;\n }\n }\n /* eslint-enable etc/no-deprecated */\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/config",
3
- "version": "0.35.13",
3
+ "version": "0.35.15",
4
4
  "description": "Configuration handling for cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,12 +14,12 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.25.2",
17
+ "@ms-cloudpack/common-types": "^0.26.1",
18
18
  "@ms-cloudpack/environment": "^0.1.1",
19
19
  "@ms-cloudpack/json-utilities": "^0.1.10",
20
- "@ms-cloudpack/package-utilities": "^12.3.15",
20
+ "@ms-cloudpack/package-utilities": "^12.3.17",
21
21
  "@ms-cloudpack/path-string-parsing": "^1.2.7",
22
- "@ms-cloudpack/path-utilities": "^3.1.9",
22
+ "@ms-cloudpack/path-utilities": "^3.1.11",
23
23
  "semver": "^7.6.0"
24
24
  },
25
25
  "devDependencies": {