@ms-cloudpack/config 0.38.0 → 0.38.2
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/lib/builtInSettings/builtInSettings.d.ts +159 -156
- package/lib/builtInSettings/builtInSettings.d.ts.map +1 -1
- package/lib/readConfig/augmentAppConfig.d.ts +2 -1
- package/lib/readConfig/augmentAppConfig.d.ts.map +1 -1
- package/lib/readConfig/augmentAppConfig.js +5 -1
- package/lib/readConfig/augmentAppConfig.js.map +1 -1
- package/lib/readConfig/readAppConfig.d.ts +5 -1
- package/lib/readConfig/readAppConfig.d.ts.map +1 -1
- package/lib/readConfig/readAppConfig.js.map +1 -1
- package/lib/writeConfig/writeAppConfig.d.ts +2 -1
- package/lib/writeConfig/writeAppConfig.d.ts.map +1 -1
- package/lib/writeConfig/writeAppConfig.js +3 -2
- package/lib/writeConfig/writeAppConfig.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtInSettings.d.ts","sourceRoot":"","sources":["../../src/builtInSettings/builtInSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG/E,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,eAAe,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;IAC7D;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC,CAAC;CACnE;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"builtInSettings.d.ts","sourceRoot":"","sources":["../../src/builtInSettings/builtInSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG/E,MAAM,WAAW,eAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqL1B,CAAC"}
|
|
@@ -3,6 +3,7 @@ import type { ReadAppConfigOptions } from './readAppConfig.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Update the app config read from disk with extra settings that were passed in from CLI options.
|
|
5
5
|
* This is called after any extended configs have been merged.
|
|
6
|
+
* @returns The original `config` object for convenience (modifications are done in-place)
|
|
6
7
|
*/
|
|
7
|
-
export declare function augmentAppConfig<TConfig extends Pick<AppConfig, 'packageSettings' | 'features' | 'define'>>(config: TConfig, options: ReadAppConfigOptions): TConfig;
|
|
8
|
+
export declare function augmentAppConfig<TConfig extends Pick<AppConfig, 'packageSettings' | 'features' | 'define' | 'server'>>(config: TConfig, options: ReadAppConfigOptions): TConfig;
|
|
8
9
|
//# sourceMappingURL=augmentAppConfig.d.ts.map
|
|
@@ -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
|
|
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,CA4BT"}
|
|
@@ -2,9 +2,10 @@ import { defaultFeatures } from '@ms-cloudpack/common-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Update the app config read from disk with extra settings that were passed in from CLI options.
|
|
4
4
|
* This is called after any extended configs have been merged.
|
|
5
|
+
* @returns The original `config` object for convenience (modifications are done in-place)
|
|
5
6
|
*/
|
|
6
7
|
export function augmentAppConfig(config, options) {
|
|
7
|
-
const { extraPackageSettings, extraFeatures, extraDefineFlags, enableDefaultFeatures } = options;
|
|
8
|
+
const { extraPackageSettings, extraFeatures, extraDefineFlags, enableDefaultFeatures, extraServerConfig } = options;
|
|
8
9
|
if (extraPackageSettings) {
|
|
9
10
|
// Add these last so they take precedence.
|
|
10
11
|
(config.packageSettings ??= []).push(...extraPackageSettings);
|
|
@@ -21,6 +22,9 @@ export function augmentAppConfig(config, options) {
|
|
|
21
22
|
// User-provided features should override the defaults.
|
|
22
23
|
config.features = { ...defaultFeatures, ...config.features };
|
|
23
24
|
}
|
|
25
|
+
if (extraServerConfig) {
|
|
26
|
+
config.server = { ...config.server, ...extraServerConfig };
|
|
27
|
+
}
|
|
24
28
|
return config;
|
|
25
29
|
}
|
|
26
30
|
//# sourceMappingURL=augmentAppConfig.js.map
|
|
@@ -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
|
|
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,uDAAuD;QACvD,MAAM,CAAC,QAAQ,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC;IAED,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,CAAC,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAAC;IAC7D,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 config.server = { ...config.server, ...extraServerConfig };\n }\n\n return config;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AppConfig, Features, PackageSettings } from '@ms-cloudpack/common-types';
|
|
1
|
+
import type { AppConfig, Features, PackageSettings, ServerConfig } from '@ms-cloudpack/common-types';
|
|
2
2
|
import type { DefineFlags } from '@ms-cloudpack/common-types-browser';
|
|
3
3
|
export interface ReadAppConfigOptions {
|
|
4
4
|
/**
|
|
@@ -17,6 +17,10 @@ export interface ReadAppConfigOptions {
|
|
|
17
17
|
* Enable default features that are not explicitly set in the config.
|
|
18
18
|
*/
|
|
19
19
|
enableDefaultFeatures?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Overrides for the server config.
|
|
22
|
+
*/
|
|
23
|
+
extraServerConfig?: Pick<ServerConfig, 'showOverlay'>;
|
|
20
24
|
/**
|
|
21
25
|
* Custom config file name to use instead of cloudpack.config.json
|
|
22
26
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readAppConfig.d.ts","sourceRoot":"","sources":["../../src/readConfig/readAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,
|
|
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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,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CACV,+BAA+B,UAAU,iEAAiE;YACxG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7B,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,MAAiB;IAChD,sCAAsC;IACtC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAE3D,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;QACtG,CAAC;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 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 * Custom config file name to use instead of cloudpack.config.json\n */\n configFileName?: 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<AppConfig> {\n const { appConfigPaths } = getConfigPath(appPath, options?.configFileName);\n\n let config: AppConfig;\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 = {};\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 as Record<string, unknown>);\n\n // Merge extra settings (usually from CLI options) into the final config.\n if (options) {\n config = augmentAppConfig(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(`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<AppConfig> {\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<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 path.extname(parentConfigPath).toLowerCase() === '.json'\n ? readJsonAppConfig(parentConfigPath)\n : readJsAppConfig(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,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;AAkCzD;;;;;;;;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,MAAiB,CAAC;IAEtB,sCAAsC;IACtC,MAAM,aAAa,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uBAAuB,CAAC,MAAiB;IAChD,sCAAsC;IACtC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAE3D,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;QACtG,CAAC;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, 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 * 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 { appConfigPaths } = getConfigPath(appPath, options?.configFileName);\n\n let config: AppConfig;\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 = {};\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 as Record<string, unknown>);\n\n // Merge extra settings (usually from CLI options) into the final config.\n if (options) {\n config = augmentAppConfig(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(`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<AppConfig> {\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<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 path.extname(parentConfigPath).toLowerCase() === '.json'\n ? readJsonAppConfig(parentConfigPath)\n : readJsAppConfig(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 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"]}
|
|
@@ -2,6 +2,7 @@ import type { AppConfig } from '@ms-cloudpack/common-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Writes updates to the user config JSON.
|
|
4
4
|
* This is ONLY used when creating a default app config or by tests.
|
|
5
|
+
* @param customConfigFileName - optional custom config file name to use instead of defaults
|
|
5
6
|
*/
|
|
6
|
-
export declare function writeAppConfig(config: AppConfig, appPath: string): Promise<void>;
|
|
7
|
+
export declare function writeAppConfig(config: AppConfig, appPath: string, customConfigFileName?: string): Promise<void>;
|
|
7
8
|
//# sourceMappingURL=writeAppConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeAppConfig.d.ts","sourceRoot":"","sources":["../../src/writeConfig/writeAppConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAI5D
|
|
1
|
+
{"version":3,"file":"writeAppConfig.d.ts","sourceRoot":"","sources":["../../src/writeConfig/writeAppConfig.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAI5D;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAWrH"}
|
|
@@ -4,9 +4,10 @@ import { appConfigSchemaUrl } from '../constants.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Writes updates to the user config JSON.
|
|
6
6
|
* This is ONLY used when creating a default app config or by tests.
|
|
7
|
+
* @param customConfigFileName - optional custom config file name to use instead of defaults
|
|
7
8
|
*/
|
|
8
|
-
export async function writeAppConfig(config, appPath) {
|
|
9
|
-
const { defaultAppConfigPath } = getConfigPath(appPath);
|
|
9
|
+
export async function writeAppConfig(config, appPath, customConfigFileName) {
|
|
10
|
+
const { defaultAppConfigPath } = getConfigPath(appPath, customConfigFileName);
|
|
10
11
|
return writeJson(defaultAppConfigPath, {
|
|
11
12
|
$schema: appConfigSchemaUrl,
|
|
12
13
|
...config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeAppConfig.js","sourceRoot":"","sources":["../../src/writeConfig/writeAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD
|
|
1
|
+
{"version":3,"file":"writeAppConfig.js","sourceRoot":"","sources":["../../src/writeConfig/writeAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAiB,EAAE,OAAe,EAAE,oBAA6B;IACpG,MAAM,EAAE,oBAAoB,EAAE,GAAG,aAAa,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;IAE9E,OAAO,SAAS,CACd,oBAAoB,EACpB;QACE,OAAO,EAAE,kBAAkB;QAC3B,GAAG,MAAM;KACV,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CACrC,CAAC;AACJ,CAAC","sourcesContent":["import { writeJson } from '@ms-cloudpack/json-utilities';\nimport type { AppConfig } from '@ms-cloudpack/common-types';\nimport { getConfigPath } from '../getConfigPath.js';\nimport { appConfigSchemaUrl } from '../constants.js';\n\n/**\n * Writes updates to the user config JSON.\n * This is ONLY used when creating a default app config or by tests.\n * @param customConfigFileName - optional custom config file name to use instead of defaults\n */\nexport async function writeAppConfig(config: AppConfig, appPath: string, customConfigFileName?: string): Promise<void> {\n const { defaultAppConfigPath } = getConfigPath(appPath, customConfigFileName);\n\n return writeJson(\n defaultAppConfigPath,\n {\n $schema: appConfigSchemaUrl,\n ...config,\n },\n { update: true, mode: 'permissive' },\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/config",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.2",
|
|
4
4
|
"description": "Configuration handling for cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.27.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.27.5",
|
|
18
18
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.10",
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^12.
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^12.4.0",
|
|
21
21
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
22
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
22
|
+
"@ms-cloudpack/path-utilities": "^3.1.20",
|
|
23
23
|
"semver": "^7.6.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@ms-cloudpack/common-types-browser": "^0.6.
|
|
26
|
+
"@ms-cloudpack/common-types-browser": "^0.6.3",
|
|
27
27
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
28
28
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
29
29
|
"@ms-cloudpack/test-utilities": "^0.5.0"
|