@ms-cloudpack/config 0.38.6 → 0.38.7
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/readConfig/expandModulePaths.d.ts +10 -0
- package/lib/readConfig/expandModulePaths.d.ts.map +1 -0
- package/lib/readConfig/expandModulePaths.js +44 -0
- package/lib/readConfig/expandModulePaths.js.map +1 -0
- package/lib/readConfig/readAppConfig.d.ts.map +1 -1
- package/lib/readConfig/readAppConfig.js +2 -0
- package/lib/readConfig/readAppConfig.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AppConfig } from '@ms-cloudpack/common-types';
|
|
2
|
+
/**
|
|
3
|
+
* Expand template variables in module resolution paths.
|
|
4
|
+
* Currently supports {configDir} to reference the configuration file's directory.
|
|
5
|
+
*/
|
|
6
|
+
export declare function expandModulePaths(params: {
|
|
7
|
+
appConfig: AppConfig;
|
|
8
|
+
configPath: string;
|
|
9
|
+
}): void;
|
|
10
|
+
//# sourceMappingURL=expandModulePaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expandModulePaths.d.ts","sourceRoot":"","sources":["../../src/readConfig/expandModulePaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAe5D;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAsC5F"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
const configDirTemplate = '{configDir}';
|
|
3
|
+
function countOccurrences(str, substring) {
|
|
4
|
+
let count = 0;
|
|
5
|
+
let index = 0;
|
|
6
|
+
while ((index = str.indexOf(substring, index)) !== -1) {
|
|
7
|
+
count++;
|
|
8
|
+
index += substring.length;
|
|
9
|
+
}
|
|
10
|
+
return count;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Expand template variables in module resolution paths.
|
|
14
|
+
* Currently supports {configDir} to reference the configuration file's directory.
|
|
15
|
+
*/
|
|
16
|
+
export function expandModulePaths(params) {
|
|
17
|
+
const { appConfig: { resolve }, configPath, } = params;
|
|
18
|
+
if (!path.isAbsolute(configPath)) {
|
|
19
|
+
throw new Error(`configPath must be an absolute path, got: "${configPath}"`);
|
|
20
|
+
}
|
|
21
|
+
if (!resolve?.modules) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const configDir = path.dirname(configPath);
|
|
25
|
+
// Process each module path and expand template variables
|
|
26
|
+
resolve.modules = resolve.modules.map((modulePath) => {
|
|
27
|
+
// Count occurrences of the template variable
|
|
28
|
+
const templateCount = countOccurrences(modulePath, configDirTemplate);
|
|
29
|
+
if (templateCount === 0) {
|
|
30
|
+
// Return unchanged paths without template variables
|
|
31
|
+
return modulePath;
|
|
32
|
+
}
|
|
33
|
+
if (templateCount > 1) {
|
|
34
|
+
throw new Error(`Multiple template variables not allowed in the same path: "${modulePath}"`);
|
|
35
|
+
}
|
|
36
|
+
// Single template variable - must be at the beginning
|
|
37
|
+
if (!modulePath.startsWith(configDirTemplate)) {
|
|
38
|
+
throw new Error(`${configDirTemplate} template variable must be at the beginning of the path: "${modulePath}"`);
|
|
39
|
+
}
|
|
40
|
+
// Replace template at start of path with actual directory
|
|
41
|
+
return modulePath.replace(configDirTemplate, configDir);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=expandModulePaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expandModulePaths.js","sourceRoot":"","sources":["../../src/readConfig/expandModulePaths.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC,SAAS,gBAAgB,CAAC,GAAW,EAAE,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AAG,iBAAiB,6DAA6D,UAAU,GAAG,CAAC,CAAC;QAClH,CAAC;QAED,0DAA0D;QAC1D,OAAO,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { AppConfig } from '@ms-cloudpack/common-types';\nimport path from 'path';\n\nconst configDirTemplate = '{configDir}';\n\nfunction countOccurrences(str: string, substring: string): number {\n let count = 0;\n let index = 0;\n while ((index = str.indexOf(substring, index)) !== -1) {\n count++;\n index += substring.length;\n }\n return count;\n}\n\n/**\n * Expand template variables in module resolution paths.\n * Currently supports {configDir} to reference the configuration file's directory.\n */\nexport function expandModulePaths(params: { appConfig: AppConfig; configPath: string }): void {\n const {\n appConfig: { resolve },\n configPath,\n } = params;\n\n if (!path.isAbsolute(configPath)) {\n throw new Error(`configPath must be an absolute path, got: \"${configPath}\"`);\n }\n\n if (!resolve?.modules) {\n return;\n }\n\n const configDir = path.dirname(configPath);\n\n // Process each module path and expand template variables\n resolve.modules = resolve.modules.map((modulePath) => {\n // Count occurrences of the template variable\n const templateCount = countOccurrences(modulePath, configDirTemplate);\n\n if (templateCount === 0) {\n // Return unchanged paths without template variables\n return modulePath;\n }\n\n if (templateCount > 1) {\n throw new Error(`Multiple template variables not allowed in the same path: \"${modulePath}\"`);\n }\n\n // Single template variable - must be at the beginning\n if (!modulePath.startsWith(configDirTemplate)) {\n throw new Error(`${configDirTemplate} template variable must be at the beginning of the path: \"${modulePath}\"`);\n }\n\n // Replace template at start of path with actual directory\n return modulePath.replace(configDirTemplate, configDir);\n });\n}\n"]}
|
|
@@ -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;
|
|
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;AActE,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,MAAM,GAAG,aAAa,CAAC,CAAC;IAE/D;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,SAAS,CAAC;IAErB;;OAEG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA4ChH"}
|
|
@@ -10,6 +10,7 @@ import { expandEnvironmentVariables } from './expandEnvironmentVariables.js';
|
|
|
10
10
|
import { mergeParentConfig } from './mergeParentConfig.js';
|
|
11
11
|
import { resolveParentConfig } from './resolveParentConfig.js';
|
|
12
12
|
import { augmentAppConfig } from './augmentAppConfig.js';
|
|
13
|
+
import { expandModulePaths } from './expandModulePaths.js';
|
|
13
14
|
/**
|
|
14
15
|
* Reads the user config file and merges with any parent configs asynchronously.
|
|
15
16
|
* Note this is only useful for making modifications to the user config.
|
|
@@ -123,6 +124,7 @@ async function processConfig(configPath, appConfig) {
|
|
|
123
124
|
}
|
|
124
125
|
checkFeatures(appConfig.features, configPath);
|
|
125
126
|
resolveBundlerCapabilities({ appConfig, configPath });
|
|
127
|
+
expandModulePaths({ appConfig, configPath });
|
|
126
128
|
processDeprecatedValues(appConfig);
|
|
127
129
|
const configPaths = [];
|
|
128
130
|
// Read and merge with any parent configs (the same processing is applied to parent configs)
|
|
@@ -1 +1 @@
|
|
|
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,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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. 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"]}
|
|
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;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA8C3D;;;;;;;;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,CAAC;QAC7B,MAAM,OAAO,GAAG,yFAAyF,CAAC;QAC1G,MAAM,IAAI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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';\nimport { expandModulePaths } from './expandModulePaths.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 expandModulePaths({ 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/config",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.7",
|
|
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.28.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.28.2",
|
|
18
18
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.11",
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^13.0.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.25",
|
|
23
23
|
"semver": "^7.6.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|