@ms-cloudpack/config 0.17.10 → 0.17.12
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/readUserConfig.d.ts +1 -1
- package/lib/readUserConfig.d.ts.map +1 -1
- package/lib/readUserConfig.js +38 -2
- package/lib/readUserConfig.js.map +1 -1
- package/lib/safeImportParentConfig.d.ts +8 -0
- package/lib/safeImportParentConfig.d.ts.map +1 -0
- package/lib/safeImportParentConfig.js +17 -0
- package/lib/safeImportParentConfig.js.map +1 -0
- package/package.json +4 -4
package/lib/readUserConfig.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UserConfig } from '@ms-cloudpack/config-types';
|
|
2
2
|
/**
|
|
3
|
-
* Reads the user config file asynchronously. Note this is only useful for making modifications to the user config.
|
|
3
|
+
* Reads the user config file and merges with any parent configs asynchronously. Note this is only useful for making modifications to the user config.
|
|
4
4
|
* For a full merged representation of config, use `readConfig` instead.
|
|
5
5
|
*/
|
|
6
6
|
export declare function readUserConfig(appPath: string): Promise<UserConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readUserConfig.d.ts","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"readUserConfig.d.ts","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAgD7D;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMzE"}
|
package/lib/readUserConfig.js
CHANGED
|
@@ -1,11 +1,47 @@
|
|
|
1
1
|
import { readJson } from '@ms-cloudpack/json-utilities';
|
|
2
2
|
import { getConfigPath } from './getConfigPath.js';
|
|
3
|
+
import { safeImportParentConfig } from './safeImportParentConfig.js';
|
|
3
4
|
/**
|
|
4
|
-
* Reads the user config file
|
|
5
|
+
* Reads the user config file and merges it with any parent configs.
|
|
6
|
+
* @param params - The path to the user config file or the import specifier for the parent config file.
|
|
7
|
+
*/
|
|
8
|
+
async function readUserConfigInternal(params) {
|
|
9
|
+
if ('filePath' in params && 'importSpecifier' in params) {
|
|
10
|
+
throw new Error('Only one of filePath or importSpecifier can be specified');
|
|
11
|
+
}
|
|
12
|
+
// Read the user config file
|
|
13
|
+
const userConfig = 'importSpecifier' in params
|
|
14
|
+
? await safeImportParentConfig(params.importSpecifier)
|
|
15
|
+
: await readJson(params.filePath, { verbose: true, mode: 'permissive' });
|
|
16
|
+
// If there is no userConfig or 'extends' property, return it early
|
|
17
|
+
if (!userConfig?.extends) {
|
|
18
|
+
return userConfig;
|
|
19
|
+
}
|
|
20
|
+
// Recursively read the parent config file
|
|
21
|
+
const parentConfig = await readUserConfigInternal({ importSpecifier: userConfig.extends });
|
|
22
|
+
// If unable to read the parent config file, return the userConfig
|
|
23
|
+
if (!parentConfig) {
|
|
24
|
+
return userConfig;
|
|
25
|
+
}
|
|
26
|
+
// Merge the parent config with the user config and return the result
|
|
27
|
+
const result = {
|
|
28
|
+
...parentConfig,
|
|
29
|
+
...userConfig,
|
|
30
|
+
features: {
|
|
31
|
+
...(parentConfig.features || {}),
|
|
32
|
+
...(userConfig.features || {}),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
delete result.extends; // Remove the extends property from the result
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reads the user config file and merges with any parent configs asynchronously. Note this is only useful for making modifications to the user config.
|
|
5
40
|
* For a full merged representation of config, use `readConfig` instead.
|
|
6
41
|
*/
|
|
7
42
|
export async function readUserConfig(appPath) {
|
|
8
43
|
const { userConfigPath } = getConfigPath(appPath);
|
|
9
|
-
|
|
44
|
+
const userConfig = (await readUserConfigInternal({ filePath: userConfigPath })) || {};
|
|
45
|
+
return userConfig;
|
|
10
46
|
}
|
|
11
47
|
//# sourceMappingURL=readUserConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readUserConfig.js","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"readUserConfig.js","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;GAGG;AACH,KAAK,UAAU,sBAAsB,CACnC,MAA0D;IAE1D,IAAI,UAAU,IAAI,MAAM,IAAI,iBAAiB,IAAI,MAAM,EAAE;QACvD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC7E;IAED,4BAA4B;IAC5B,MAAM,UAAU,GACd,iBAAiB,IAAI,MAAM;QACzB,CAAC,CAAC,MAAM,sBAAsB,CAAC,MAAM,CAAC,eAAe,CAAC;QACtD,CAAC,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IAE7E,mEAAmE;IACnE,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE;QACxB,OAAO,UAAU,CAAC;KACnB;IAED,0CAA0C;IAC1C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,EAAE,eAAe,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAE3F,kEAAkE;IAClE,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO,UAAU,CAAC;KACnB;IAED,qEAAqE;IACrE,MAAM,MAAM,GAAe;QACzB,GAAG,YAAY;QACf,GAAG,UAAU;QACb,QAAQ,EAAE;YACR,GAAG,CAAC,YAAY,CAAC,QAAQ,IAAI,EAAE,CAAC;YAChC,GAAG,CAAC,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC;SAC/B;KACF,CAAC;IAEF,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,8CAA8C;IAErE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAe;IAClD,MAAM,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAElD,MAAM,UAAU,GAAG,CAAC,MAAM,sBAAsB,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAEtF,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { readJson } from '@ms-cloudpack/json-utilities';\nimport { getConfigPath } from './getConfigPath.js';\nimport type { UserConfig } from '@ms-cloudpack/config-types';\nimport { safeImportParentConfig } from './safeImportParentConfig.js';\n\n/**\n * Reads the user config file and merges it with any parent configs.\n * @param params - The path to the user config file or the import specifier for the parent config file.\n */\nasync function readUserConfigInternal(\n params: { filePath: string } | { importSpecifier: string },\n): Promise<UserConfig | undefined> {\n if ('filePath' in params && 'importSpecifier' in params) {\n throw new Error('Only one of filePath or importSpecifier can be specified');\n }\n\n // Read the user config file\n const userConfig: UserConfig | undefined =\n 'importSpecifier' in params\n ? await safeImportParentConfig(params.importSpecifier)\n : await readJson(params.filePath, { verbose: true, mode: 'permissive' });\n\n // If there is no userConfig or 'extends' property, return it early\n if (!userConfig?.extends) {\n return userConfig;\n }\n\n // Recursively read the parent config file\n const parentConfig = await readUserConfigInternal({ importSpecifier: userConfig.extends });\n\n // If unable to read the parent config file, return the userConfig\n if (!parentConfig) {\n return userConfig;\n }\n\n // Merge the parent config with the user config and return the result\n const result: UserConfig = {\n ...parentConfig,\n ...userConfig,\n features: {\n ...(parentConfig.features || {}),\n ...(userConfig.features || {}),\n },\n };\n\n delete result.extends; // Remove the extends property from the result\n\n return result;\n}\n\n/**\n * Reads the user config file and merges with any parent configs asynchronously. Note this is only useful for making modifications to the user config.\n * For a full merged representation of config, use `readConfig` instead.\n */\nexport async function readUserConfig(appPath: string): Promise<UserConfig> {\n const { userConfigPath } = getConfigPath(appPath);\n\n const userConfig = (await readUserConfigInternal({ filePath: userConfigPath })) || {};\n\n return userConfig;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UserConfig } from '@ms-cloudpack/config-types';
|
|
2
|
+
/**
|
|
3
|
+
* Imports the parent config and returns the default export which is the json that represents UserConfig.
|
|
4
|
+
* @param userConfigImportSpecifier - The import specifier for the parent config file.
|
|
5
|
+
* @returns The UserConfig object. If import specifier can not be resolved, returns undefined.
|
|
6
|
+
*/
|
|
7
|
+
export declare function safeImportParentConfig(userConfigImportSpecifier: string): Promise<UserConfig | undefined>;
|
|
8
|
+
//# sourceMappingURL=safeImportParentConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeImportParentConfig.d.ts","sourceRoot":"","sources":["../src/safeImportParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,yBAAyB,EAAE,MAAM,mCAW7E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Imports the parent config and returns the default export which is the json that represents UserConfig.
|
|
3
|
+
* @param userConfigImportSpecifier - The import specifier for the parent config file.
|
|
4
|
+
* @returns The UserConfig object. If import specifier can not be resolved, returns undefined.
|
|
5
|
+
*/
|
|
6
|
+
export async function safeImportParentConfig(userConfigImportSpecifier) {
|
|
7
|
+
try {
|
|
8
|
+
const module = await import(userConfigImportSpecifier, { assert: { type: 'json' } });
|
|
9
|
+
return module.default;
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
// If unable to import the parent config, log a warning and return undefined
|
|
13
|
+
console.warn(`Unable to import parent config ${userConfigImportSpecifier}`);
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=safeImportParentConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeImportParentConfig.js","sourceRoot":"","sources":["../src/safeImportParentConfig.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,yBAAiC;IAC5E,IAAI;QACF,MAAM,MAAM,GAAG,MAAO,MAAM,CAAC,yBAAyB,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAEjF,CAAC;QACJ,OAAO,MAAM,CAAC,OAAO,CAAC;KACvB;IAAC,OAAO,CAAC,EAAE;QACV,4EAA4E;QAC5E,OAAO,CAAC,IAAI,CAAC,kCAAkC,yBAAyB,EAAE,CAAC,CAAC;QAC5E,OAAO,SAAS,CAAC;KAClB;AACH,CAAC","sourcesContent":["import type { UserConfig } from '@ms-cloudpack/config-types';\n\n/**\n * Imports the parent config and returns the default export which is the json that represents UserConfig.\n * @param userConfigImportSpecifier - The import specifier for the parent config file.\n * @returns The UserConfig object. If import specifier can not be resolved, returns undefined.\n */\nexport async function safeImportParentConfig(userConfigImportSpecifier: string) {\n try {\n const module = await (import(userConfigImportSpecifier, { assert: { type: 'json' } }) as Promise<{\n default: UserConfig;\n }>);\n return module.default;\n } catch (e) {\n // If unable to import the parent config, log a warning and return undefined\n console.warn(`Unable to import parent config ${userConfigImportSpecifier}`);\n return undefined;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/config",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.12",
|
|
4
4
|
"description": "Configuration handling for cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/bundler-types": "^0.23.
|
|
18
|
-
"@ms-cloudpack/config-types": "^0.3.
|
|
17
|
+
"@ms-cloudpack/bundler-types": "^0.23.8",
|
|
18
|
+
"@ms-cloudpack/config-types": "^0.3.3",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.3",
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^5.7.
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^5.7.6",
|
|
21
21
|
"semver": "^7.3.7"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|