@ms-cloudpack/config 0.38.4 → 0.38.6
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.
- package/README.md +0 -2
- package/lib/readConfig/augmentAppConfig.d.ts.map +1 -1
- package/lib/readConfig/augmentAppConfig.js +8 -1
- package/lib/readConfig/augmentAppConfig.js.map +1 -1
- package/lib/readConfig/readAppConfig.d.ts +2 -2
- package/lib/readConfig/readAppConfig.d.ts.map +1 -1
- package/lib/readConfig/readAppConfig.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"augmentAppConfig.d.ts","sourceRoot":"","sources":["../../src/readConfig/augmentAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC,EACpH,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,oBAAoB,GAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"augmentAppConfig.d.ts","sourceRoot":"","sources":["../../src/readConfig/augmentAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC,EACpH,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAmCT"}
|
|
@@ -23,7 +23,14 @@ export function augmentAppConfig(config, options) {
|
|
|
23
23
|
config.features = { ...defaultFeatures, ...config.features };
|
|
24
24
|
}
|
|
25
25
|
if (extraServerConfig) {
|
|
26
|
-
|
|
26
|
+
// Only set values that aren't undefined, to avoid overwriting values from the config
|
|
27
|
+
// in case a key was included in extraServerConfig by default without a value
|
|
28
|
+
for (const [key, value] of Object.entries(extraServerConfig)) {
|
|
29
|
+
if (value !== undefined) {
|
|
30
|
+
config.server ??= {};
|
|
31
|
+
config.server[key] = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
27
34
|
}
|
|
28
35
|
return config;
|
|
29
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"augmentAppConfig.js","sourceRoot":"","sources":["../../src/readConfig/augmentAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,4BAA4B,CAAC;AAG7E;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAe,EACf,OAA6B;IAE7B,MAAM,EAAE,oBAAoB,EAAE,aAAa,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;IAEpH,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,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAC5D,CAAC;IAED,IAAI,qBAAqB,EAAE,CAAC;QAC1B,qCAAqC;QACrC,uDAA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iBAAiB,CAAC,EAAE,CAAC;YAC7D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC;gBACpB,MAAM,CAAC,MAAkC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YAC1D,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { defaultFeatures, type AppConfig } from '@ms-cloudpack/common-types';\nimport type { ReadAppConfigOptions } from './readAppConfig.js';\n\n/**\n * Update the app config read from disk with extra settings that were passed in from CLI options.\n * This is called after any extended configs have been merged.\n * @returns The original `config` object for convenience (modifications are done in-place)\n */\nexport function augmentAppConfig<TConfig extends Pick<AppConfig, 'packageSettings' | 'features' | 'define' | 'server'>>(\n config: TConfig,\n options: ReadAppConfigOptions,\n): TConfig {\n const { extraPackageSettings, extraFeatures, extraDefineFlags, enableDefaultFeatures, extraServerConfig } = 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 = { ...config.define, ...extraDefineFlags };\n }\n\n if (enableDefaultFeatures) {\n // Enable select features by default.\n // User-provided features should override the defaults.\n config.features = { ...defaultFeatures, ...config.features };\n }\n\n if (extraServerConfig) {\n // Only set values that aren't undefined, to avoid overwriting values from the config\n // in case a key was included in extraServerConfig by default without a value\n for (const [key, value] of Object.entries(extraServerConfig)) {\n if (value !== undefined) {\n config.server ??= {};\n (config.server as Record<string, unknown>)[key] = value;\n }\n }\n }\n\n return config;\n}\n"]}
|
|
@@ -18,9 +18,9 @@ export interface ReadAppConfigOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
enableDefaultFeatures?: boolean;
|
|
20
20
|
/**
|
|
21
|
-
* Overrides for the server config.
|
|
21
|
+
* Overrides for the server config. Undefined keys will be ignored.
|
|
22
22
|
*/
|
|
23
|
-
extraServerConfig?: Pick<ServerConfig, 'showOverlay'>;
|
|
23
|
+
extraServerConfig?: Pick<ServerConfig, 'open' | 'showOverlay'>;
|
|
24
24
|
/**
|
|
25
25
|
* Custom config file name to use instead of cloudpack.config.json
|
|
26
26
|
*/
|
|
@@ -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,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAElH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAatE,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;IAE/B;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,iBAAiB,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;
|
|
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,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAElH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAatE,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;IAE/B;;OAEG;IACH,qBAAqB,CAAC,E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AC;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, FeatureName, Features, PackageSettings, ServerConfig } from '@ms-cloudpack/common-types';\nimport { allFeatures } from '@ms-cloudpack/common-types';\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { resolveModule } from '@ms-cloudpack/path-utilities';\nimport fs from 'fs';\nimport path from 'path';\nimport { pathToFileURL } from 'url';\nimport { getConfigPath } from '../getConfigPath.js';\nimport { validateMatch } from '../packageSettings/validateMatch.js';\nimport { expandEnvironmentVariables } from './expandEnvironmentVariables.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\nimport { resolveParentConfig } from './resolveParentConfig.js';\nimport { augmentAppConfig } from './augmentAppConfig.js';\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 * Overrides for the server config.\n */\n extraServerConfig?: Pick<ServerConfig, 'showOverlay'>;\n\n /**\n * Custom config file name to use instead of cloudpack.config.json\n */\n configFileName?: string;\n}\n\n/**\n * Application configuration combined with the file paths that were used to load it.\n */\nexport interface AppConfigWithPaths {\n appConfig: AppConfig;\n\n /**\n * The paths to the config files that were read, in order of precedence.\n */\n appConfigPaths: string[];\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<AppConfigWithPaths> {\n const { appConfigPaths } = getConfigPath(appPath, options?.configFileName);\n\n let config: AppConfigWithPaths;\n\n // Check for JS and JSON config files.\n const existingPaths = appConfigPaths.filter((p) => fs.existsSync(p));\n if (existingPaths.length > 1) {\n const message = 'Multiple Cloudpack config files found. Determine the correct one and delete the others:';\n throw new Error([message, ...existingPaths].join('\\n '));\n }\n\n const appConfigPath = existingPaths[0];\n if (!appConfigPath) {\n // If a custom config was specified, it must exist\n if (options?.configFileName) {\n throw new Error(`Config file not found: ${options.configFileName}`);\n }\n // This is fine, use an empty config\n config = { appConfig: {}, appConfigPaths: [] };\n } else if (path.extname(appConfigPath) === '.json') {\n // Check for an existing JSON app config first\n config = await readJsonAppConfig(appConfigPath);\n } else {\n // Otherwise, read as a JS file\n config = await readJsAppConfig(appConfigPath);\n }\n\n expandEnvironmentVariables(config.appConfig as Record<string, unknown>);\n\n // Merge extra settings (usually from CLI options) into the final config.\n if (options) {\n config.appConfig = augmentAppConfig(config.appConfig, options);\n }\n\n if (appConfigPath) {\n if (config.appConfigPaths) {\n config.appConfigPaths?.unshift(appConfigPath); // Add the config path to the beginning of the list\n } else {\n config.appConfigPaths = [appConfigPath]; // If no paths were set, just use the current one\n }\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<AppConfigWithPaths> {\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(`Cloudpack config not found at ${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<AppConfigWithPaths> {\n // Convert configPath to a URL for import.\n try {\n const appConfig = (await (import(pathToFileURL(configPath).toString()) as Promise<{ default?: AppConfig }>))\n .default;\n if (!appConfig) {\n throw new Error(`Missing default export from Cloudpack config at ${configPath}`);\n }\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<AppConfigWithPaths> {\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 const configPaths: string[] = [];\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 parentResults = await Promise.all(\n extendsArray.map(async (importSpecifier) => {\n const parentConfigPath = resolveParentConfig({ configPath, importSpecifier });\n\n const result =\n path.extname(parentConfigPath).toLowerCase() === '.json'\n ? await readJsonAppConfig(parentConfigPath)\n : await readJsAppConfig(parentConfigPath);\n\n // Collect paths from parent configs\n configPaths.push(...result.appConfigPaths);\n return result.appConfig;\n }),\n );\n\n const mergedConfig = mergeParentConfig({ appConfig, parentConfigs: parentResults });\n return { appConfig: mergedConfig, appConfigPaths: configPaths };\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 FeatureName]) {\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,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AA8CzD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAe,EAAE,OAA8B;IACjF,MAAM,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IAE3E,IAAI,MAA0B,CAAC;IAE/B,sCAAsC;IACtC,MAAM,aAAa,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CA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cloudpack/common-types';\nimport { allFeatures } from '@ms-cloudpack/common-types';\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { resolveModule } from '@ms-cloudpack/path-utilities';\nimport fs from 'fs';\nimport path from 'path';\nimport { pathToFileURL } from 'url';\nimport { getConfigPath } from '../getConfigPath.js';\nimport { validateMatch } from '../packageSettings/validateMatch.js';\nimport { expandEnvironmentVariables } from './expandEnvironmentVariables.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\nimport { resolveParentConfig } from './resolveParentConfig.js';\nimport { augmentAppConfig } from './augmentAppConfig.js';\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 * Overrides for the server config. Undefined keys will be ignored.\n */\n extraServerConfig?: Pick<ServerConfig, 'open' | 'showOverlay'>;\n\n /**\n * Custom config file name to use instead of cloudpack.config.json\n */\n configFileName?: string;\n}\n\n/**\n * Application configuration combined with the file paths that were used to load it.\n */\nexport interface AppConfigWithPaths {\n appConfig: AppConfig;\n\n /**\n * The paths to the config files that were read, in order of precedence.\n */\n appConfigPaths: string[];\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<AppConfigWithPaths> {\n const { appConfigPaths } = getConfigPath(appPath, options?.configFileName);\n\n let config: AppConfigWithPaths;\n\n // Check for JS and JSON config files.\n const existingPaths = appConfigPaths.filter((p) => fs.existsSync(p));\n if (existingPaths.length > 1) {\n const message = 'Multiple Cloudpack config files found. Determine the correct one and delete the others:';\n throw new Error([message, ...existingPaths].join('\\n '));\n }\n\n const appConfigPath = existingPaths[0];\n if (!appConfigPath) {\n // If a custom config was specified, it must exist\n if (options?.configFileName) {\n throw new Error(`Config file not found: ${options.configFileName}`);\n }\n // This is fine, use an empty config\n config = { appConfig: {}, appConfigPaths: [] };\n } else if (path.extname(appConfigPath) === '.json') {\n // Check for an existing JSON app config first\n config = await readJsonAppConfig(appConfigPath);\n } else {\n // Otherwise, read as a JS file\n config = await readJsAppConfig(appConfigPath);\n }\n\n expandEnvironmentVariables(config.appConfig as Record<string, unknown>);\n\n // Merge extra settings (usually from CLI options) into the final config.\n if (options) {\n config.appConfig = augmentAppConfig(config.appConfig, options);\n }\n\n if (appConfigPath) {\n if (config.appConfigPaths) {\n config.appConfigPaths?.unshift(appConfigPath); // Add the config path to the beginning of the list\n } else {\n config.appConfigPaths = [appConfigPath]; // If no paths were set, just use the current one\n }\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<AppConfigWithPaths> {\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(`Cloudpack config not found at ${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<AppConfigWithPaths> {\n // Convert configPath to a URL for import.\n try {\n const appConfig = (await (import(pathToFileURL(configPath).toString()) as Promise<{ default?: AppConfig }>))\n .default;\n if (!appConfig) {\n throw new Error(`Missing default export from Cloudpack config at ${configPath}`);\n }\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<AppConfigWithPaths> {\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 const configPaths: string[] = [];\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 parentResults = await Promise.all(\n extendsArray.map(async (importSpecifier) => {\n const parentConfigPath = resolveParentConfig({ configPath, importSpecifier });\n\n const result =\n path.extname(parentConfigPath).toLowerCase() === '.json'\n ? await readJsonAppConfig(parentConfigPath)\n : await readJsAppConfig(parentConfigPath);\n\n // Collect paths from parent configs\n configPaths.push(...result.appConfigPaths);\n return result.appConfig;\n }),\n );\n\n const mergedConfig = mergeParentConfig({ appConfig, parentConfigs: parentResults });\n return { appConfig: mergedConfig, appConfigPaths: configPaths };\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 FeatureName]) {\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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/config",
|
|
3
|
-
"version": "0.38.
|
|
4
|
-
"description": "Configuration handling for
|
|
3
|
+
"version": "0.38.6",
|
|
4
|
+
"description": "Configuration handling for Cloudpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.28.1",
|
|
18
18
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.11",
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^12.5.
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^12.5.3",
|
|
21
21
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
22
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
22
|
+
"@ms-cloudpack/path-utilities": "^3.1.24",
|
|
23
23
|
"semver": "^7.6.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|