@ms-cloudpack/config 0.17.19 → 0.17.21
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.map +1 -1
- package/lib/readUserConfig.js +19 -5
- package/lib/readUserConfig.js.map +1 -1
- package/lib/safeImportParentConfig.d.ts +9 -2
- package/lib/safeImportParentConfig.d.ts.map +1 -1
- package/lib/safeImportParentConfig.js +29 -8
- package/lib/safeImportParentConfig.js.map +1 -1
- package/package.json +4 -3
|
@@ -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;AAkE7D;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMzE"}
|
package/lib/readUserConfig.js
CHANGED
|
@@ -10,15 +10,29 @@ async function readUserConfigInternal(params) {
|
|
|
10
10
|
throw new Error('Only one of filePath or importSpecifier can be specified');
|
|
11
11
|
}
|
|
12
12
|
// Read the user config file
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
let userConfig;
|
|
14
|
+
let resolvedConfigPath;
|
|
15
|
+
if ('filePath' in params) {
|
|
16
|
+
userConfig = await readJson(params.filePath, { verbose: true, mode: 'permissive' });
|
|
17
|
+
resolvedConfigPath = params.filePath;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const { importSpecifier, fromConfigPath } = params;
|
|
21
|
+
const result = await safeImportParentConfig({ importSpecifier, configPath: fromConfigPath });
|
|
22
|
+
if (result) {
|
|
23
|
+
resolvedConfigPath = result.resolvedConfigPath;
|
|
24
|
+
userConfig = result.config;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
16
27
|
// If there is no userConfig or 'extends' property, return it early
|
|
17
|
-
if (!userConfig?.extends) {
|
|
28
|
+
if (!userConfig?.extends || !resolvedConfigPath) {
|
|
18
29
|
return userConfig;
|
|
19
30
|
}
|
|
20
31
|
// Recursively read the parent config file
|
|
21
|
-
const parentConfig = await readUserConfigInternal({
|
|
32
|
+
const parentConfig = await readUserConfigInternal({
|
|
33
|
+
fromConfigPath: resolvedConfigPath,
|
|
34
|
+
importSpecifier: userConfig.extends,
|
|
35
|
+
});
|
|
22
36
|
// If unable to read the parent config file, return the userConfig
|
|
23
37
|
if (!parentConfig) {
|
|
24
38
|
return userConfig;
|
|
@@ -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;AAEnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;GAGG;AACH,KAAK,UAAU,sBAAsB,CACnC,
|
|
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,MAKK;IAEL,IAAI,UAAU,IAAI,MAAM,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,4BAA4B;IAC5B,IAAI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;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:\n | { filePath: string }\n | {\n fromConfigPath: string;\n importSpecifier: string;\n },\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 let userConfig: UserConfig | undefined;\n let resolvedConfigPath: string | undefined;\n\n if ('filePath' in params) {\n userConfig = await readJson(params.filePath, { verbose: true, mode: 'permissive' });\n resolvedConfigPath = params.filePath;\n } else {\n const { importSpecifier, fromConfigPath } = params;\n const result = await safeImportParentConfig({ importSpecifier, configPath: fromConfigPath });\n if (result) {\n resolvedConfigPath = result.resolvedConfigPath;\n userConfig = result.config;\n }\n }\n\n // If there is no userConfig or 'extends' property, return it early\n if (!userConfig?.extends || !resolvedConfigPath) {\n return userConfig;\n }\n\n // Recursively read the parent config file\n const parentConfig = await readUserConfigInternal({\n fromConfigPath: resolvedConfigPath,\n importSpecifier: userConfig.extends,\n });\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"]}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { UserConfig } from '@ms-cloudpack/config-types';
|
|
2
2
|
/**
|
|
3
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
4
|
* @returns The UserConfig object. If import specifier can not be resolved, returns undefined.
|
|
6
5
|
*/
|
|
7
|
-
export declare function safeImportParentConfig(
|
|
6
|
+
export declare function safeImportParentConfig(params: {
|
|
7
|
+
/** Path of the config file being processed. */
|
|
8
|
+
configPath: string;
|
|
9
|
+
/** The import specifier for the parent (extends) config file. */
|
|
10
|
+
importSpecifier: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
resolvedConfigPath: string;
|
|
13
|
+
config: UserConfig;
|
|
14
|
+
} | undefined>;
|
|
8
15
|
//# sourceMappingURL=safeImportParentConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safeImportParentConfig.d.ts","sourceRoot":"","sources":["../src/safeImportParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"safeImportParentConfig.d.ts","sourceRoot":"","sources":["../src/safeImportParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAO7D;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE;IACnD,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC;IAAE,kBAAkB,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GAAG,SAAS,CAAC,CAiC1E"}
|
|
@@ -1,17 +1,38 @@
|
|
|
1
|
+
import { readJson } from '@ms-cloudpack/json-utilities';
|
|
2
|
+
import { resolve } from '@ms-cloudpack/package-utilities';
|
|
3
|
+
import { parseImportString } from '@ms-cloudpack/path-string-parsing';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
1
6
|
/**
|
|
2
7
|
* 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
8
|
* @returns The UserConfig object. If import specifier can not be resolved, returns undefined.
|
|
5
9
|
*/
|
|
6
|
-
export async function safeImportParentConfig(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export async function safeImportParentConfig(params) {
|
|
11
|
+
const { importSpecifier, configPath } = params;
|
|
12
|
+
let resolvedConfigPath;
|
|
13
|
+
if (importSpecifier.startsWith('.')) {
|
|
14
|
+
resolvedConfigPath = path.resolve(path.dirname(configPath), importSpecifier);
|
|
10
15
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
else {
|
|
17
|
+
const parsedImport = parseImportString(importSpecifier);
|
|
18
|
+
const resolvedPackage = await resolve(parsedImport.packageName, path.dirname(configPath));
|
|
19
|
+
if (resolvedPackage) {
|
|
20
|
+
resolvedConfigPath = path.join(resolvedPackage, parsedImport.importPath);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!resolvedConfigPath) {
|
|
24
|
+
console.warn(`Unable to resolve "${importSpecifier}" relative to ${configPath}`);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (!fs.existsSync(resolvedConfigPath)) {
|
|
28
|
+
console.warn(`Unable to find config file at ${resolvedConfigPath} (resolving "${importSpecifier}" relative to ${configPath}`);
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const config = await readJson(resolvedConfigPath, { verbose: true, mode: 'permissive' });
|
|
32
|
+
if (!config) {
|
|
33
|
+
console.warn(`Config file at ${resolvedConfigPath} was not valid JSON`);
|
|
14
34
|
return undefined;
|
|
15
35
|
}
|
|
36
|
+
return { resolvedConfigPath, config };
|
|
16
37
|
}
|
|
17
38
|
//# sourceMappingURL=safeImportParentConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safeImportParentConfig.js","sourceRoot":"","sources":["../src/safeImportParentConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"safeImportParentConfig.js","sourceRoot":"","sources":["../src/safeImportParentConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAK5C;IACC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE/C,IAAI,kBAAsC,CAAC;IAE3C,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,eAAe,CAAC,CAAC;IAC/E,CAAC;SAAM,CAAC;QACN,MAAM,YAAY,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC;QACxD,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;QAC1F,IAAI,eAAe,EAAE,CAAC;YACpB,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,sBAAsB,eAAe,iBAAiB,UAAU,EAAE,CAAC,CAAC;QACjF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,CACV,iCAAiC,kBAAkB,gBAAgB,eAAe,iBAAiB,UAAU,EAAE,CAChH,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAa,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IACrG,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,IAAI,CAAC,kBAAkB,kBAAkB,qBAAqB,CAAC,CAAC;QACxE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC","sourcesContent":["import type { UserConfig } from '@ms-cloudpack/config-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { resolve } from '@ms-cloudpack/package-utilities';\nimport { parseImportString } from '@ms-cloudpack/path-string-parsing';\nimport fs from 'fs';\nimport path from 'path';\n\n/**\n * Imports the parent config and returns the default export which is the json that represents UserConfig.\n * @returns The UserConfig object. If import specifier can not be resolved, returns undefined.\n */\nexport async function safeImportParentConfig(params: {\n /** Path of the config file being processed. */\n configPath: string;\n /** The import specifier for the parent (extends) config file. */\n importSpecifier: string;\n}): Promise<{ resolvedConfigPath: string; config: UserConfig } | undefined> {\n const { importSpecifier, configPath } = params;\n\n let resolvedConfigPath: string | undefined;\n\n if (importSpecifier.startsWith('.')) {\n resolvedConfigPath = path.resolve(path.dirname(configPath), importSpecifier);\n } else {\n const parsedImport = parseImportString(importSpecifier);\n const resolvedPackage = await resolve(parsedImport.packageName, path.dirname(configPath));\n if (resolvedPackage) {\n resolvedConfigPath = path.join(resolvedPackage, parsedImport.importPath);\n }\n }\n\n if (!resolvedConfigPath) {\n console.warn(`Unable to resolve \"${importSpecifier}\" relative to ${configPath}`);\n return undefined;\n }\n\n if (!fs.existsSync(resolvedConfigPath)) {\n console.warn(\n `Unable to find config file at ${resolvedConfigPath} (resolving \"${importSpecifier}\" relative to ${configPath}`,\n );\n return undefined;\n }\n\n const config = await readJson<UserConfig>(resolvedConfigPath, { verbose: true, mode: 'permissive' });\n if (!config) {\n console.warn(`Config file at ${resolvedConfigPath} was not valid JSON`);\n return undefined;\n }\n return { resolvedConfigPath, config };\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.21",
|
|
4
4
|
"description": "Configuration handling for cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/bundler-types": "^0.
|
|
17
|
+
"@ms-cloudpack/bundler-types": "^0.24.0",
|
|
18
18
|
"@ms-cloudpack/config-types": "^0.4.3",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.3",
|
|
20
|
-
"@ms-cloudpack/package-utilities": "^5.8.
|
|
20
|
+
"@ms-cloudpack/package-utilities": "^5.8.2",
|
|
21
|
+
"@ms-cloudpack/path-string-parsing": "^1.1.3",
|
|
21
22
|
"semver": "^7.6.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|