@ms-cloudpack/config 0.18.1 → 0.19.0

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.
@@ -17,16 +17,16 @@ export declare function getPackageSettings(params: {
17
17
  };
18
18
  /**
19
19
  * Checks if the package is a match for the given package settings.
20
- * @param name The name of the package.
21
- * @param version The version of the package.
22
- * @param match The match to check against.
23
- * @param firstMatch If true, only the first matching package settings will be returned, rather than the merge of all viable settings.
24
20
  * @returns True if the package is a match for the given package settings.
25
21
  */
26
22
  export declare function checkMatch(params: {
23
+ /** The name of the package. */
27
24
  name: string;
25
+ /** The version of the package. */
28
26
  version: string;
27
+ /** The match to check against. */
29
28
  match: PackageSettings['match'];
30
- firstMatch?: boolean;
29
+ /** If true, require an exact match for the name (don't process wildcards). */
30
+ exactMatch?: boolean;
31
31
  }): boolean;
32
32
  //# sourceMappingURL=getPackageSettings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageSettings.d.ts","sourceRoot":"","sources":["../src/getPackageSettings.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEnF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG;IACF,mBAAmB,EAAE,eAAe,GAAG,SAAS,CAAC;IACjD,wBAAwB,EAAE,eAAe,GAAG,SAAS,CAAC;CACvD,CAUA;AAmBD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAgBV"}
1
+ {"version":3,"file":"getPackageSettings.d.ts","sourceRoot":"","sources":["../src/getPackageSettings.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEnF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,eAAe,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG;IACF,mBAAmB,EAAE,eAAe,GAAG,SAAS,CAAC;IACjD,wBAAwB,EAAE,eAAe,GAAG,SAAS,CAAC;CACvD,CAUA;AAmBD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAChC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,OAAO,CAkBV"}
@@ -19,32 +19,30 @@ export function getPackageSettings(params) {
19
19
  function filterSettings(params) {
20
20
  const { name, version, packageSettings, firstMatch } = params;
21
21
  if (firstMatch) {
22
- return packageSettings?.find(({ match }) => checkMatch({ name, version, match, firstMatch }));
22
+ return packageSettings?.find(({ match }) => checkMatch({ name, version, match, exactMatch: firstMatch }));
23
23
  }
24
24
  const filteredSettings = packageSettings?.filter(({ match }) => checkMatch({ name, version, match }));
25
25
  return filteredSettings?.length ? mergePackageSettings(filteredSettings) : undefined;
26
26
  }
27
27
  /**
28
28
  * Checks if the package is a match for the given package settings.
29
- * @param name The name of the package.
30
- * @param version The version of the package.
31
- * @param match The match to check against.
32
- * @param firstMatch If true, only the first matching package settings will be returned, rather than the merge of all viable settings.
33
29
  * @returns True if the package is a match for the given package settings.
34
30
  */
35
31
  export function checkMatch(params) {
36
- const { name, version, match, firstMatch } = params;
32
+ const { name, version, match, exactMatch } = params;
37
33
  let matchName, matchVersion;
38
34
  if (typeof match === 'string') {
39
35
  matchName = match;
40
36
  }
41
37
  else {
42
38
  matchName = match?.name;
43
- matchVersion = match?.version;
39
+ matchVersion = match?.version === '*' ? undefined : match?.version;
44
40
  }
45
- if (firstMatch || !matchName.endsWith('*')) {
41
+ // For exact or non-wildcard matches, check the full name and possibly the version.
42
+ if (exactMatch || !matchName.endsWith('*')) {
46
43
  return matchName === name && (!matchVersion || satisfies(version, matchVersion));
47
44
  }
45
+ // Remove the trailing wildcard and check for a prefix match and possibly the version.
48
46
  return name.startsWith(matchName.slice(0, -1)) && (!matchVersion || satisfies(version, matchVersion));
49
47
  }
50
48
  //# sourceMappingURL=getPackageSettings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageSettings.js","sourceRoot":"","sources":["../src/getPackageSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MASlC;IAIC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAE1B,OAAO;QACL,mBAAmB,EAAE,cAAc,CAAC,EAAE,GAAG,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;QAC3F,wBAAwB,EAAE,cAAc,CAAC;YACvC,GAAG,MAAM;YACT,eAAe,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe;SACnD,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CACrB,MAEC;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE9D,IAA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,CAAC","sourcesContent":["import { satisfies } from 'semver';\nimport { mergePackageSettings } from './mergePackageSettings.js';\nimport type { PackageSettings, CloudpackConfig } from '@ms-cloudpack/common-types';\n\n/**\n * Gets the single set of package settings for a given package using the given config.\n */\nexport function getPackageSettings(params: {\n name: string;\n version: string;\n config: CloudpackConfig;\n /**\n * If true, only the first matching package settings will be returned, rather than the merge of all viable settings.\n * This is useful in the `init` case, where we want to attach new settings to the first matching entry.\n */\n firstMatch?: boolean;\n}): {\n userPackageSettings: PackageSettings | undefined;\n generatedPackageSettings: PackageSettings | undefined;\n} {\n const { config } = params;\n\n return {\n userPackageSettings: filterSettings({ ...params, packageSettings: config.packageSettings }),\n generatedPackageSettings: filterSettings({\n ...params,\n packageSettings: config.generated?.packageSettings,\n }),\n };\n}\n\n/**\n * Get the package settings for a given package name and version.\n */\nfunction filterSettings(\n params: Omit<Parameters<typeof getPackageSettings>[0], 'config'> & {\n packageSettings: PackageSettings[] | undefined;\n },\n): PackageSettings | undefined {\n const { name, version, packageSettings, firstMatch } = params;\n\n if (firstMatch) {\n return packageSettings?.find(({ match }) => checkMatch({ name, version, match, firstMatch }));\n }\n const filteredSettings = packageSettings?.filter(({ match }) => checkMatch({ name, version, match }));\n return filteredSettings?.length ? mergePackageSettings(filteredSettings) : undefined;\n}\n\n/**\n * Checks if the package is a match for the given package settings.\n * @param name The name of the package.\n * @param version The version of the package.\n * @param match The match to check against.\n * @param firstMatch If true, only the first matching package settings will be returned, rather than the merge of all viable settings.\n * @returns True if the package is a match for the given package settings.\n */\nexport function checkMatch(params: {\n name: string;\n version: string;\n match: PackageSettings['match'];\n firstMatch?: boolean;\n}): boolean {\n const { name, version, match, firstMatch } = params;\n\n let matchName, matchVersion;\n if (typeof match === 'string') {\n matchName = match;\n } else {\n matchName = match?.name;\n matchVersion = match?.version;\n }\n\n if (firstMatch || !matchName.endsWith('*')) {\n return matchName === name && (!matchVersion || satisfies(version, matchVersion));\n }\n\n return name.startsWith(matchName.slice(0, -1)) && (!matchVersion || satisfies(version, matchVersion));\n}\n"]}
1
+ {"version":3,"file":"getPackageSettings.js","sourceRoot":"","sources":["../src/getPackageSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MASlC;IAIC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAE1B,OAAO;QACL,mBAAmB,EAAE,cAAc,CAAC,EAAE,GAAG,MAAM,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;QAC3F,wBAAwB,EAAE,cAAc,CAAC;YACvC,GAAG,MAAM;YACT,eAAe,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe;SACnD,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CACrB,MAEC;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE9D,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,eAAe,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IAC5G,CAAC;IACD,MAAM,gBAAgB,GAAG,eAAe,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACtG,OAAO,gBAAgB,EAAE,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACvF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAS1B;IACC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAEpD,IAAI,SAAS,EAAE,YAAY,CAAC;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,SAAS,GAAG,KAAK,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,KAAK,EAAE,IAAI,CAAC;QACxB,YAAY,GAAG,KAAK,EAAE,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC;IACrE,CAAC;IAED,mFAAmF;IACnF,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,OAAO,SAAS,KAAK,IAAI,IAAI,CAAC,CAAC,YAAY,IAAI,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,sFAAsF;IACtF,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,IAAI,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;AACxG,CAAC","sourcesContent":["import { satisfies } from 'semver';\nimport { mergePackageSettings } from './mergePackageSettings.js';\nimport type { PackageSettings, CloudpackConfig } from '@ms-cloudpack/common-types';\n\n/**\n * Gets the single set of package settings for a given package using the given config.\n */\nexport function getPackageSettings(params: {\n name: string;\n version: string;\n config: CloudpackConfig;\n /**\n * If true, only the first matching package settings will be returned, rather than the merge of all viable settings.\n * This is useful in the `init` case, where we want to attach new settings to the first matching entry.\n */\n firstMatch?: boolean;\n}): {\n userPackageSettings: PackageSettings | undefined;\n generatedPackageSettings: PackageSettings | undefined;\n} {\n const { config } = params;\n\n return {\n userPackageSettings: filterSettings({ ...params, packageSettings: config.packageSettings }),\n generatedPackageSettings: filterSettings({\n ...params,\n packageSettings: config.generated?.packageSettings,\n }),\n };\n}\n\n/**\n * Get the package settings for a given package name and version.\n */\nfunction filterSettings(\n params: Omit<Parameters<typeof getPackageSettings>[0], 'config'> & {\n packageSettings: PackageSettings[] | undefined;\n },\n): PackageSettings | undefined {\n const { name, version, packageSettings, firstMatch } = params;\n\n if (firstMatch) {\n return packageSettings?.find(({ match }) => checkMatch({ name, version, match, exactMatch: firstMatch }));\n }\n const filteredSettings = packageSettings?.filter(({ match }) => checkMatch({ name, version, match }));\n return filteredSettings?.length ? mergePackageSettings(filteredSettings) : undefined;\n}\n\n/**\n * Checks if the package is a match for the given package settings.\n * @returns True if the package is a match for the given package settings.\n */\nexport function checkMatch(params: {\n /** The name of the package. */\n name: string;\n /** The version of the package. */\n version: string;\n /** The match to check against. */\n match: PackageSettings['match'];\n /** If true, require an exact match for the name (don't process wildcards). */\n exactMatch?: boolean;\n}): boolean {\n const { name, version, match, exactMatch } = params;\n\n let matchName, matchVersion;\n if (typeof match === 'string') {\n matchName = match;\n } else {\n matchName = match?.name;\n matchVersion = match?.version === '*' ? undefined : match?.version;\n }\n\n // For exact or non-wildcard matches, check the full name and possibly the version.\n if (exactMatch || !matchName.endsWith('*')) {\n return matchName === name && (!matchVersion || satisfies(version, matchVersion));\n }\n\n // Remove the trailing wildcard and check for a prefix match and possibly the version.\n return name.startsWith(matchName.slice(0, -1)) && (!matchVersion || satisfies(version, matchVersion));\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/config",
3
- "version": "0.18.1",
3
+ "version": "0.19.0",
4
4
  "description": "Configuration handling for cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,9 +14,9 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.2.0",
17
+ "@ms-cloudpack/common-types": "^0.2.1",
18
18
  "@ms-cloudpack/json-utilities": "^0.1.4",
19
- "@ms-cloudpack/package-utilities": "^7.1.1",
19
+ "@ms-cloudpack/package-utilities": "^7.1.2",
20
20
  "import-meta-resolve": "^4.0.0",
21
21
  "merge": "^2.1.1",
22
22
  "semver": "^7.6.0"