@ms-cloudpack/config 0.17.20 → 0.17.22

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.
@@ -0,0 +1,6 @@
1
+ import type { UserConfig } from '@ms-cloudpack/config-types';
2
+ export declare function mergeParentConfig(params: {
3
+ userConfig: UserConfig;
4
+ parentConfig: UserConfig;
5
+ }): UserConfig;
6
+ //# sourceMappingURL=mergeParentConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeParentConfig.d.ts","sourceRoot":"","sources":["../src/mergeParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAG7D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,YAAY,EAAE,UAAU,CAAA;CAAE,GAAG,UAAU,CAgB1G"}
@@ -0,0 +1,15 @@
1
+ import { recursive as recursiveMerge } from 'merge';
2
+ export function mergeParentConfig(params) {
3
+ const { userConfig, parentConfig } = params;
4
+ // NOTE: This must merge into an empty object to avoid modifying the originals
5
+ const result = recursiveMerge({}, parentConfig, userConfig);
6
+ // Remove the extends property from the result
7
+ delete result.extends;
8
+ if (userConfig.packageSettings && parentConfig.packageSettings) {
9
+ // Concatenate the package settings. User config comes first here since order can matter
10
+ // in some cases (and the user config should override the parent).
11
+ result.packageSettings = [...userConfig.packageSettings, ...parentConfig.packageSettings];
12
+ }
13
+ return result;
14
+ }
15
+ //# sourceMappingURL=mergeParentConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeParentConfig.js","sourceRoot":"","sources":["../src/mergeParentConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,OAAO,CAAC;AAEpD,MAAM,UAAU,iBAAiB,CAAC,MAA4D;IAC5F,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAE5C,8EAA8E;IAC9E,MAAM,MAAM,GAAG,cAAc,CAAC,EAAE,EAAE,YAAY,EAAE,UAAU,CAAe,CAAC;IAE1E,8CAA8C;IAC9C,OAAO,MAAM,CAAC,OAAO,CAAC;IAEtB,IAAI,UAAU,CAAC,eAAe,IAAI,YAAY,CAAC,eAAe,EAAE,CAAC;QAC/D,wFAAwF;QACxF,kEAAkE;QAClE,MAAM,CAAC,eAAe,GAAG,CAAC,GAAG,UAAU,CAAC,eAAe,EAAE,GAAG,YAAY,CAAC,eAAe,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { UserConfig } from '@ms-cloudpack/config-types';\nimport { recursive as recursiveMerge } from 'merge';\n\nexport function mergeParentConfig(params: { userConfig: UserConfig; parentConfig: UserConfig }): UserConfig {\n const { userConfig, parentConfig } = params;\n\n // NOTE: This must merge into an empty object to avoid modifying the originals\n const result = recursiveMerge({}, parentConfig, userConfig) as UserConfig;\n\n // Remove the extends property from the result\n delete result.extends;\n\n if (userConfig.packageSettings && parentConfig.packageSettings) {\n // Concatenate the package settings. User config comes first here since order can matter\n // in some cases (and the user config should override the parent).\n result.packageSettings = [...userConfig.packageSettings, ...parentConfig.packageSettings];\n }\n\n return result;\n}\n"]}
@@ -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;AAgD7D;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMzE"}
1
+ {"version":3,"file":"readUserConfig.d.ts","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAyD7D;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAMzE"}
@@ -1,5 +1,6 @@
1
1
  import { readJson } from '@ms-cloudpack/json-utilities';
2
2
  import { getConfigPath } from './getConfigPath.js';
3
+ import { mergeParentConfig } from './mergeParentConfig.js';
3
4
  import { safeImportParentConfig } from './safeImportParentConfig.js';
4
5
  /**
5
6
  * Reads the user config file and merges it with any parent configs.
@@ -10,30 +11,34 @@ async function readUserConfigInternal(params) {
10
11
  throw new Error('Only one of filePath or importSpecifier can be specified');
11
12
  }
12
13
  // 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' });
14
+ let userConfig;
15
+ let resolvedConfigPath;
16
+ if ('filePath' in params) {
17
+ userConfig = await readJson(params.filePath, { verbose: true, mode: 'permissive' });
18
+ resolvedConfigPath = params.filePath;
19
+ }
20
+ else {
21
+ const { importSpecifier, fromConfigPath } = params;
22
+ const result = await safeImportParentConfig({ importSpecifier, configPath: fromConfigPath });
23
+ if (result) {
24
+ resolvedConfigPath = result.resolvedConfigPath;
25
+ userConfig = result.config;
26
+ }
27
+ }
16
28
  // If there is no userConfig or 'extends' property, return it early
17
- if (!userConfig?.extends) {
29
+ if (!userConfig?.extends || !resolvedConfigPath) {
18
30
  return userConfig;
19
31
  }
20
32
  // Recursively read the parent config file
21
- const parentConfig = await readUserConfigInternal({ importSpecifier: userConfig.extends });
33
+ const parentConfig = await readUserConfigInternal({
34
+ fromConfigPath: resolvedConfigPath,
35
+ importSpecifier: userConfig.extends,
36
+ });
22
37
  // If unable to read the parent config file, return the userConfig
23
38
  if (!parentConfig) {
24
39
  return userConfig;
25
40
  }
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;
41
+ return mergeParentConfig({ userConfig, parentConfig });
37
42
  }
38
43
  /**
39
44
  * Reads the user config file and merges with any parent configs asynchronously. Note this is only useful for making modifications to the user config.
@@ -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,MAA0D;IAE1D,IAAI,UAAU,IAAI,MAAM,IAAI,iBAAiB,IAAI,MAAM,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;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,CAAC;QACzB,OAAO,UAAU,CAAC;IACpB,CAAC;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,CAAC;QAClB,OAAO,UAAU,CAAC;IACpB,CAAC;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"]}
1
+ {"version":3,"file":"readUserConfig.js","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,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,UAAkC,CAAC;IACvC,IAAI,kBAAsC,CAAC;IAE3C,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;QACzB,UAAU,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACpF,kBAAkB,GAAG,MAAM,CAAC,QAAQ,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;QACnD,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC,CAAC;QAC7F,IAAI,MAAM,EAAE,CAAC;YACX,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;YAC/C,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,mEAAmE;IACnE,IAAI,CAAC,UAAU,EAAE,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAChD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,0CAA0C;IAC1C,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC;QAChD,cAAc,EAAE,kBAAkB;QAClC,eAAe,EAAE,UAAU,CAAC,OAAO;KACpC,CAAC,CAAC;IAEH,kEAAkE;IAClE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,iBAAiB,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;AACzD,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 type { UserConfig } from '@ms-cloudpack/config-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { getConfigPath } from './getConfigPath.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\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 return mergeParentConfig({ userConfig, parentConfig });\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(userConfigImportSpecifier: string): Promise<UserConfig | undefined>;
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;AAE7D;;;;GAIG;AACH,wBAAsB,sBAAsB,CAAC,yBAAyB,EAAE,MAAM,mCAW7E"}
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(userConfigImportSpecifier) {
7
- try {
8
- const module = await import(userConfigImportSpecifier, { assert: { type: 'json' } });
9
- return module.default;
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
- 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}`);
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":"AAEA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,yBAAiC;IAC5E,IAAI,CAAC;QACH,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;IACxB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,4EAA4E;QAC5E,OAAO,CAAC,IAAI,CAAC,kCAAkC,yBAAyB,EAAE,CAAC,CAAC;QAC5E,OAAO,SAAS,CAAC;IACnB,CAAC;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"]}
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.20",
3
+ "version": "0.17.22",
4
4
  "description": "Configuration handling for cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,6 +18,8 @@
18
18
  "@ms-cloudpack/config-types": "^0.4.3",
19
19
  "@ms-cloudpack/json-utilities": "^0.1.3",
20
20
  "@ms-cloudpack/package-utilities": "^5.8.2",
21
+ "@ms-cloudpack/path-string-parsing": "^1.1.3",
22
+ "merge": "^2.1.1",
21
23
  "semver": "^7.6.0"
22
24
  },
23
25
  "devDependencies": {