@ms-cloudpack/config 0.17.25 → 0.17.27

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.
@@ -1,6 +1,9 @@
1
1
  import type { UserConfig } from '@ms-cloudpack/config-types';
2
+ /**
3
+ * Merge the configs. Later parent configs override earlier ones.
4
+ */
2
5
  export declare function mergeParentConfig(params: {
3
6
  userConfig: UserConfig;
4
- parentConfig: UserConfig;
7
+ parentConfigs: UserConfig[];
5
8
  }): UserConfig;
6
9
  //# sourceMappingURL=mergeParentConfig.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"mergeParentConfig.d.ts","sourceRoot":"","sources":["../src/mergeParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAG7D;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,UAAU,EAAE,CAAA;CAAE,GAAG,UAAU,CAiB7G"}
@@ -1,14 +1,18 @@
1
1
  import { recursive as recursiveMerge } from 'merge';
2
+ /**
3
+ * Merge the configs. Later parent configs override earlier ones.
4
+ */
2
5
  export function mergeParentConfig(params) {
3
- const { userConfig, parentConfig } = params;
6
+ const configs = [...params.parentConfigs, params.userConfig];
4
7
  // NOTE: This must merge into an empty object to avoid modifying the originals
5
- const result = recursiveMerge({}, parentConfig, userConfig);
8
+ const result = recursiveMerge({}, ...configs);
6
9
  // Remove the extends property from the result
7
10
  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];
11
+ // Concatenate the package settings. User config comes first here since order can matter
12
+ // in some cases (and the user config should override the parent).
13
+ const packageSettings = [...configs].reverse().flatMap((config) => config.packageSettings ?? []);
14
+ if (packageSettings.length) {
15
+ result.packageSettings = packageSettings;
12
16
  }
13
17
  return result;
14
18
  }
@@ -1 +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
+ {"version":3,"file":"mergeParentConfig.js","sourceRoot":"","sources":["../src/mergeParentConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,OAAO,CAAC;AAEpD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA+D;IAC/F,MAAM,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAE7D,8EAA8E;IAC9E,MAAM,MAAM,GAAG,cAAc,CAAC,EAAE,EAAE,GAAG,OAAO,CAAe,CAAC;IAE5D,8CAA8C;IAC9C,OAAO,MAAM,CAAC,OAAO,CAAC;IAEtB,wFAAwF;IACxF,kEAAkE;IAClE,MAAM,eAAe,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC;IACjG,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { UserConfig } from '@ms-cloudpack/config-types';\nimport { recursive as recursiveMerge } from 'merge';\n\n/**\n * Merge the configs. Later parent configs override earlier ones.\n */\nexport function mergeParentConfig(params: { userConfig: UserConfig; parentConfigs: UserConfig[] }): UserConfig {\n const configs = [...params.parentConfigs, params.userConfig];\n\n // NOTE: This must merge into an empty object to avoid modifying the originals\n const result = recursiveMerge({}, ...configs) as UserConfig;\n\n // Remove the extends property from the result\n delete result.extends;\n\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 const packageSettings = [...configs].reverse().flatMap((config) => config.packageSettings ?? []);\n if (packageSettings.length) {\n result.packageSettings = packageSettings;\n }\n\n return result;\n}\n"]}
@@ -1 +1 @@
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
+ {"version":3,"file":"readUserConfig.d.ts","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAoC7D;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAIzE"}
@@ -1,44 +1,32 @@
1
1
  import { readJson } from '@ms-cloudpack/json-utilities';
2
2
  import { getConfigPath } from './getConfigPath.js';
3
3
  import { mergeParentConfig } from './mergeParentConfig.js';
4
- import { safeImportParentConfig } from './safeImportParentConfig.js';
4
+ import { resolveParentConfig } from './resolveParentConfig.js';
5
5
  /**
6
- * Reads the user config file and merges it with any parent configs.
7
- * @param params - The path to the user config file or the import specifier for the parent config file.
6
+ * Reads the user config, with any `extends` parent configs merged in.
8
7
  */
9
- async function readUserConfigInternal(params) {
10
- if ('filePath' in params && 'importSpecifier' in params) {
11
- throw new Error('Only one of filePath or importSpecifier can be specified');
8
+ async function readUserConfigInternal(configPath) {
9
+ const userConfig = await readJson(configPath, { verbose: true, mode: 'permissive' });
10
+ if (!userConfig) {
11
+ return undefined;
12
12
  }
13
- // Read the user config file
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;
13
+ const extendsArray = userConfig.extends
14
+ ? Array.isArray(userConfig.extends)
15
+ ? userConfig.extends
16
+ : [userConfig.extends]
17
+ : [];
18
+ // Recursively read any parent config files
19
+ const parentConfigs = [];
20
+ for (const importSpecifier of extendsArray) {
21
+ const resolvedPath = await resolveParentConfig({ configPath, importSpecifier });
22
+ if (resolvedPath) {
23
+ const parentConfig = await readUserConfigInternal(resolvedPath);
24
+ if (parentConfig) {
25
+ parentConfigs.push(parentConfig);
26
+ }
26
27
  }
27
28
  }
28
- // If there is no userConfig or 'extends' property, return it early
29
- if (!userConfig?.extends || !resolvedConfigPath) {
30
- return userConfig;
31
- }
32
- // Recursively read the parent config file
33
- const parentConfig = await readUserConfigInternal({
34
- fromConfigPath: resolvedConfigPath,
35
- importSpecifier: userConfig.extends,
36
- });
37
- // If unable to read the parent config file, return the userConfig
38
- if (!parentConfig) {
39
- return userConfig;
40
- }
41
- return mergeParentConfig({ userConfig, parentConfig });
29
+ return mergeParentConfig({ userConfig, parentConfigs });
42
30
  }
43
31
  /**
44
32
  * Reads the user config file and merges with any parent configs asynchronously. Note this is only useful for making modifications to the user config.
@@ -46,7 +34,6 @@ async function readUserConfigInternal(params) {
46
34
  */
47
35
  export async function readUserConfig(appPath) {
48
36
  const { userConfigPath } = getConfigPath(appPath);
49
- const userConfig = (await readUserConfigInternal({ filePath: userConfigPath })) || {};
50
- return userConfig;
37
+ return (await readUserConfigInternal(userConfigPath)) || {};
51
38
  }
52
39
  //# sourceMappingURL=readUserConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"readUserConfig.js","sourceRoot":"","sources":["../src/readUserConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,a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E,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
+ {"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,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;GAEG;AACH,KAAK,UAAU,sBAAsB,CAAC,UAAkB;IACtD,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAa,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IACjG,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO;QACrC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YACjC,CAAC,CAAC,UAAU,CAAC,OAAO;YACpB,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC;QACxB,CAAC,CAAC,EAAE,CAAC;IAEP,2CAA2C;IAC3C,MAAM,aAAa,GAAiB,EAAE,CAAC;IACvC,KAAK,MAAM,eAAe,IAAI,YAAY,EAAE,CAAC;QAC3C,MAAM,YAAY,GAAG,MAAM,mBAAmB,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC,CAAC;QAChF,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC,YAAY,CAAC,CAAC;YAChE,IAAI,YAAY,EAAE,CAAC;gBACjB,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,iBAAiB,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAe;IAClD,MAAM,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAElD,OAAO,CAAC,MAAM,sBAAsB,CAAC,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9D,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 { resolveParentConfig } from './resolveParentConfig.js';\n\n/**\n * Reads the user config, with any `extends` parent configs merged in.\n */\nasync function readUserConfigInternal(configPath: string): Promise<UserConfig | undefined> {\n const userConfig = await readJson<UserConfig>(configPath, { verbose: true, mode: 'permissive' });\n if (!userConfig) {\n return undefined;\n }\n\n const extendsArray = userConfig.extends\n ? Array.isArray(userConfig.extends)\n ? userConfig.extends\n : [userConfig.extends]\n : [];\n\n // Recursively read any parent config files\n const parentConfigs: UserConfig[] = [];\n for (const importSpecifier of extendsArray) {\n const resolvedPath = await resolveParentConfig({ configPath, importSpecifier });\n if (resolvedPath) {\n const parentConfig = await readUserConfigInternal(resolvedPath);\n if (parentConfig) {\n parentConfigs.push(parentConfig);\n }\n }\n }\n\n return mergeParentConfig({ userConfig, parentConfigs });\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 return (await readUserConfigInternal(userConfigPath)) || {};\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Resolve an import specifier for a parent config file.
3
+ * Returns undefined if it can't be resolved or doesn't exist.
4
+ */
5
+ export declare function resolveParentConfig(params: {
6
+ /** Path of the config file being processed. */
7
+ configPath: string;
8
+ /** The import specifier for the parent (extends) config file. */
9
+ importSpecifier: string;
10
+ }): Promise<string | undefined>;
11
+ //# sourceMappingURL=resolveParentConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveParentConfig.d.ts","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE;IAChD,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA8B9B"}
@@ -0,0 +1,34 @@
1
+ import { resolve } from '@ms-cloudpack/package-utilities';
2
+ import { parseImportString } from '@ms-cloudpack/path-string-parsing';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ /**
6
+ * Resolve an import specifier for a parent config file.
7
+ * Returns undefined if it can't be resolved or doesn't exist.
8
+ */
9
+ export async function resolveParentConfig(params) {
10
+ const { importSpecifier, configPath } = params;
11
+ let resolvedConfigPath;
12
+ if (importSpecifier.startsWith('.')) {
13
+ resolvedConfigPath = path.resolve(path.dirname(configPath), importSpecifier);
14
+ }
15
+ else {
16
+ const parsedImport = parseImportString(importSpecifier);
17
+ const resolvedPackage = await resolve(parsedImport.packageName, path.dirname(configPath));
18
+ if (resolvedPackage) {
19
+ resolvedConfigPath = path.join(resolvedPackage, parsedImport.importPath);
20
+ }
21
+ }
22
+ if (!resolvedConfigPath) {
23
+ console.warn(`Unable to resolve config "extends": "${importSpecifier}" from ${configPath}`);
24
+ return undefined;
25
+ }
26
+ // Explicitly check if the file exists and log a warning (so the user knows their config is wrong),
27
+ // rather than letting readJson quietly return nothing later.
28
+ if (!fs.existsSync(resolvedConfigPath)) {
29
+ console.warn(`Resolved config "extends": "${importSpecifier}" (from ${configPath}) to ${resolvedConfigPath}, but the file doesn't exist`);
30
+ return undefined;
31
+ }
32
+ return resolvedConfigPath;
33
+ }
34
+ //# sourceMappingURL=resolveParentConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveParentConfig.js","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAAA,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,mBAAmB,CAAC,MAKzC;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,wCAAwC,eAAe,UAAU,UAAU,EAAE,CAAC,CAAC;QAC5F,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,mGAAmG;IACnG,6DAA6D;IAC7D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,CACV,+BAA+B,eAAe,WAAW,UAAU,QAAQ,kBAAkB,8BAA8B,CAC5H,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["import { 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 * Resolve an import specifier for a parent config file.\n * Returns undefined if it can't be resolved or doesn't exist.\n */\nexport async function resolveParentConfig(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<string | 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 config \"extends\": \"${importSpecifier}\" from ${configPath}`);\n return undefined;\n }\n\n // Explicitly check if the file exists and log a warning (so the user knows their config is wrong),\n // rather than letting readJson quietly return nothing later.\n if (!fs.existsSync(resolvedConfigPath)) {\n console.warn(\n `Resolved config \"extends\": \"${importSpecifier}\" (from ${configPath}) to ${resolvedConfigPath}, but the file doesn't exist`,\n );\n return undefined;\n }\n\n return resolvedConfigPath;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/config",
3
- "version": "0.17.25",
3
+ "version": "0.17.27",
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.24.1",
18
- "@ms-cloudpack/config-types": "^0.4.3",
19
- "@ms-cloudpack/json-utilities": "^0.1.3",
20
- "@ms-cloudpack/package-utilities": "^5.10.0",
17
+ "@ms-cloudpack/bundler-types": "^0.24.2",
18
+ "@ms-cloudpack/config-types": "^0.4.4",
19
+ "@ms-cloudpack/json-utilities": "^0.1.4",
20
+ "@ms-cloudpack/package-utilities": "^5.10.2",
21
21
  "@ms-cloudpack/path-string-parsing": "^1.1.3",
22
22
  "merge": "^2.1.1",
23
23
  "semver": "^7.6.0"
@@ -1,15 +0,0 @@
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
- * @returns The UserConfig object. If import specifier can not be resolved, returns undefined.
5
- */
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>;
15
- //# sourceMappingURL=safeImportParentConfig.d.ts.map
@@ -1 +0,0 @@
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,38 +0,0 @@
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';
6
- /**
7
- * Imports the parent config and returns the default export which is the json that represents UserConfig.
8
- * @returns The UserConfig object. If import specifier can not be resolved, returns undefined.
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);
15
- }
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`);
34
- return undefined;
35
- }
36
- return { resolvedConfigPath, config };
37
- }
38
- //# sourceMappingURL=safeImportParentConfig.js.map
@@ -1 +0,0 @@
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,MAA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AI,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"]}