@ms-cloudpack/config 0.31.6 → 0.32.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.
- package/lib/checkMatch.d.ts +2 -0
- package/lib/checkMatch.d.ts.map +1 -1
- package/lib/checkMatch.js +9 -0
- package/lib/checkMatch.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/mergeParentConfig.d.ts +1 -1
- package/lib/mergeParentConfig.d.ts.map +1 -1
- package/lib/mergeParentConfig.js +7 -10
- package/lib/mergeParentConfig.js.map +1 -1
- package/lib/readAppConfig.d.ts +3 -1
- package/lib/readAppConfig.d.ts.map +1 -1
- package/lib/readAppConfig.js +62 -54
- package/lib/readAppConfig.js.map +1 -1
- package/lib/readConfig.d.ts +4 -1
- package/lib/readConfig.d.ts.map +1 -1
- package/lib/readConfig.js +6 -6
- package/lib/readConfig.js.map +1 -1
- package/lib/resolveParentConfig.d.ts +2 -2
- package/lib/resolveParentConfig.d.ts.map +1 -1
- package/lib/resolveParentConfig.js +7 -5
- package/lib/resolveParentConfig.js.map +1 -1
- package/lib/validateMatch.d.ts +13 -0
- package/lib/validateMatch.d.ts.map +1 -0
- package/lib/validateMatch.js +15 -0
- package/lib/validateMatch.js.map +1 -0
- package/package.json +4 -4
package/lib/checkMatch.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface CheckMatchParams {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Checks if the package is a match for the given package settings.
|
|
14
|
+
*
|
|
15
|
+
* Throws if the match is invalid (shouldn't happen due to previous validation).
|
|
14
16
|
*/
|
|
15
17
|
export declare function checkMatch(params: CheckMatchParams): boolean;
|
|
16
18
|
export {};
|
package/lib/checkMatch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkMatch.d.ts","sourceRoot":"","sources":["../src/checkMatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoD,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"checkMatch.d.ts","sourceRoot":"","sources":["../src/checkMatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoD,MAAM,4BAA4B,CAAC;AAIpH,UAAU,gBAAgB;IACxB,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAChC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAqB5D"}
|
package/lib/checkMatch.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { satisfies } from 'semver';
|
|
2
|
+
import { validateMatch } from './validateMatch.js';
|
|
2
3
|
/**
|
|
3
4
|
* Checks if the package is a match for the given package settings.
|
|
5
|
+
*
|
|
6
|
+
* Throws if the match is invalid (shouldn't happen due to previous validation).
|
|
4
7
|
*/
|
|
5
8
|
export function checkMatch(params) {
|
|
6
9
|
const { name, version, match, exactMatch } = params;
|
|
@@ -21,8 +24,14 @@ export function checkMatch(params) {
|
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* Check a match where `match.name` is negated. (This will handle removing the ! from the name.)
|
|
27
|
+
*
|
|
28
|
+
* Throws if the match has a version (shouldn't happen due to previous validation).
|
|
24
29
|
*/
|
|
25
30
|
function checkNegatedMatch(params) {
|
|
31
|
+
const result = validateMatch(params.match);
|
|
32
|
+
if (!result.isValid) {
|
|
33
|
+
throw new Error(result.error);
|
|
34
|
+
}
|
|
26
35
|
return !checkMatch({ ...params, match: { ...params.match, name: params.match.name.slice(1) } });
|
|
27
36
|
}
|
|
28
37
|
function checkMatchArray(params) {
|
package/lib/checkMatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkMatch.js","sourceRoot":"","sources":["../src/checkMatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"checkMatch.js","sourceRoot":"","sources":["../src/checkMatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAanD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAAwB;IACjD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAEpD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,eAAe,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC;IAE5D,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,iBAAiB,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC3D,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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O,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,GAAG,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QAClB,6FAA6F;QAC7F,OAAO,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAC9D,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import type { PackageSettings, PackageSettingsMatch, PackageSettingsMatchObject } from '@ms-cloudpack/common-types';\nimport { satisfies } from 'semver';\nimport { validateMatch } from './validateMatch.js';\n\ninterface CheckMatchParams {\n /** The name of the package. */\n name: string;\n /** The version of the package. */\n version: string;\n /** The match to check against. For an array, returns true if any entries match. */\n match: PackageSettings['match'];\n /** If true, require an exact match for the name (don't process wildcards). */\n exactMatch?: boolean;\n}\n\n/**\n * Checks if the package is a match for the given package settings.\n *\n * Throws if the match is invalid (shouldn't happen due to previous validation).\n */\nexport function checkMatch(params: CheckMatchParams): boolean {\n const { name, version, match, exactMatch } = params;\n\n if (Array.isArray(match)) {\n return checkMatchArray({ ...params, matches: match });\n }\n\n const matchObj = toMatchObject(match);\n const { name: matchName, version: matchVersion } = matchObj;\n\n if (matchName.startsWith('!')) {\n return checkNegatedMatch({ ...params, match: matchObj });\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\n/**\n * Check a match where `match.name` is negated. (This will handle removing the ! from the name.)\n *\n * Throws if the match has a version (shouldn't happen due to previous validation).\n */\nfunction checkNegatedMatch(params: Omit<CheckMatchParams, 'match'> & { match: PackageSettingsMatchObject }): boolean {\n const result = validateMatch(params.match);\n if (!result.isValid) {\n throw new Error(result.error);\n }\n return !checkMatch({ ...params, match: { ...params.match, name: params.match.name.slice(1) } });\n}\n\nfunction checkMatchArray(params: Omit<CheckMatchParams, 'match'> & { matches: PackageSettingsMatch[] }): boolean {\n let hasMatch = false;\n // Now that we support negations, we have to check every element.\n for (const m of params.matches) {\n const matchObj = toMatchObject(m);\n if (matchObj.name.startsWith('!')) {\n hasMatch &&= checkNegatedMatch({ ...params, match: matchObj });\n } else {\n hasMatch ||= checkMatch({ ...params, match: m });\n }\n }\n return hasMatch;\n}\n\nfunction toMatchObject(match: PackageSettingsMatchObject | string): PackageSettingsMatchObject {\n let name: string;\n let version: string | undefined;\n if (typeof match === 'string') {\n name = match;\n } else {\n name = match.name;\n // If any version is allowed, unset the version to skip the satisfies() check for efficiency.\n version = match.version === '*' ? undefined : match.version;\n }\n return { name, version };\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ export { writeGeneratedConfig } from './writeGeneratedConfig.js';
|
|
|
16
16
|
export { writeAppConfig } from './writeAppConfig.js';
|
|
17
17
|
export { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';
|
|
18
18
|
export { updateUserPreference } from './updateUserPreference.js';
|
|
19
|
+
export { validateMatch } from './validateMatch.js';
|
|
19
20
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,E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AO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -16,4 +16,5 @@ export { writeGeneratedConfig } from './writeGeneratedConfig.js';
|
|
|
16
16
|
export { writeAppConfig } from './writeAppConfig.js';
|
|
17
17
|
export { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';
|
|
18
18
|
export { updateUserPreference } from './updateUserPreference.js';
|
|
19
|
+
export { validateMatch } from './validateMatch.js';
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export { checkMatch } from './checkMatch.js';\nexport { configTemplate } from './configTemplate.js';\nexport { generatedConfigFileName, appConfigFileName } from './constants.js';\nexport { allUserPreferences } from './constants.js';\nexport { createPackageDefinitions } from './createPackageDefinitions.js';\nexport { getCachePath, getLocalCachePath } from './getCachePath.js';\nexport { getConfigPath } from './getConfigPath.js';\nexport { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';\nexport { getPackageSettings } from './getPackageSettings.js';\nexport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\nexport { readConfig, type ReadConfigOptions } from './readConfig.js';\nexport { readGeneratedConfig } from './readGeneratedConfig.js';\nexport { readAppConfig } from './readAppConfig.js';\nexport { readUserPreferences } from './readUserPreferences.js';\nexport { writeGeneratedConfig } from './writeGeneratedConfig.js';\nexport { writeAppConfig } from './writeAppConfig.js';\nexport { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';\nexport { updateUserPreference } from './updateUserPreference.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAA0B,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { checkMatch } from './checkMatch.js';\nexport { configTemplate } from './configTemplate.js';\nexport { generatedConfigFileName, appConfigFileName } from './constants.js';\nexport { allUserPreferences } from './constants.js';\nexport { createPackageDefinitions } from './createPackageDefinitions.js';\nexport { getCachePath, getLocalCachePath } from './getCachePath.js';\nexport { getConfigPath } from './getConfigPath.js';\nexport { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';\nexport { getPackageSettings } from './getPackageSettings.js';\nexport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\nexport { readConfig, type ReadConfigOptions } from './readConfig.js';\nexport { readGeneratedConfig } from './readGeneratedConfig.js';\nexport { readAppConfig } from './readAppConfig.js';\nexport { readUserPreferences } from './readUserPreferences.js';\nexport { writeGeneratedConfig } from './writeGeneratedConfig.js';\nexport { writeAppConfig } from './writeAppConfig.js';\nexport { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';\nexport { updateUserPreference } from './updateUserPreference.js';\nexport { validateMatch } from './validateMatch.js';\n"]}
|
|
@@ -3,7 +3,7 @@ import type { AppConfig } from '@ms-cloudpack/common-types';
|
|
|
3
3
|
* Merge the configs. Later parent configs override earlier ones.
|
|
4
4
|
*/
|
|
5
5
|
export declare function mergeParentConfig(params: {
|
|
6
|
-
|
|
6
|
+
appConfig: AppConfig;
|
|
7
7
|
parentConfigs: AppConfig[];
|
|
8
8
|
}): AppConfig;
|
|
9
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,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAG5D;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,aAAa,EAAE,SAAS,EAAE,CAAA;CAAE,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"mergeParentConfig.d.ts","sourceRoot":"","sources":["../src/mergeParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAG5D;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,aAAa,EAAE,SAAS,EAAE,CAAA;CAAE,GAAG,SAAS,CAazG"}
|
package/lib/mergeParentConfig.js
CHANGED
|
@@ -3,18 +3,15 @@ import { mergeObjects } from '@ms-cloudpack/package-utilities';
|
|
|
3
3
|
* Merge the configs. Later parent configs override earlier ones.
|
|
4
4
|
*/
|
|
5
5
|
export function mergeParentConfig(params) {
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const result = mergeObjects([...params.parentConfigs, params.appConfig], {
|
|
7
|
+
arrayMerge: 'overwrite',
|
|
8
|
+
customMerge: {
|
|
9
|
+
// Concatenate package settings
|
|
10
|
+
packageSettings: (prev, curr) => [...(prev ?? []), ...(curr ?? [])],
|
|
11
|
+
},
|
|
12
|
+
});
|
|
8
13
|
// Remove the extends property from the result
|
|
9
14
|
delete result.extends;
|
|
10
|
-
// Remove the default-merged package settings (fixed below)
|
|
11
|
-
delete result.packageSettings;
|
|
12
|
-
// Concatenate the package settings. User config comes first here since order can matter
|
|
13
|
-
// in some cases (and the user config should override the parent).
|
|
14
|
-
const packageSettings = configs.reverse().flatMap((config) => config.packageSettings ?? []);
|
|
15
|
-
if (packageSettings.length) {
|
|
16
|
-
result.packageSettings = packageSettings;
|
|
17
|
-
}
|
|
18
15
|
return result;
|
|
19
16
|
}
|
|
20
17
|
//# sourceMappingURL=mergeParentConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeParentConfig.js","sourceRoot":"","sources":["../src/mergeParentConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA4D;IAC5F,MAAM,
|
|
1
|
+
{"version":3,"file":"mergeParentConfig.js","sourceRoot":"","sources":["../src/mergeParentConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA4D;IAC5F,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE;QACvE,UAAU,EAAE,WAAW;QACvB,WAAW,EAAE;YACX,+BAA+B;YAC/B,eAAe,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;SACpE;KACF,CAAC,CAAC;IAEH,8CAA8C;IAC9C,OAAO,MAAM,CAAC,OAAO,CAAC;IAEtB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { AppConfig } from '@ms-cloudpack/common-types';\nimport { mergeObjects } from '@ms-cloudpack/package-utilities';\n\n/**\n * Merge the configs. Later parent configs override earlier ones.\n */\nexport function mergeParentConfig(params: { appConfig: AppConfig; parentConfigs: AppConfig[] }): AppConfig {\n const result = mergeObjects([...params.parentConfigs, params.appConfig], {\n arrayMerge: 'overwrite',\n customMerge: {\n // Concatenate package settings\n packageSettings: (prev, curr) => [...(prev ?? []), ...(curr ?? [])],\n },\n });\n\n // Remove the extends property from the result\n delete result.extends;\n\n return result;\n}\n"]}
|
package/lib/readAppConfig.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export interface ReadAppConfigOptions {
|
|
|
10
10
|
* Note this is only useful for making modifications to the user config.
|
|
11
11
|
* For a full merged representation of config, use `readConfig` instead.
|
|
12
12
|
*
|
|
13
|
-
* Throws an error if the config file exists but is not valid JSON
|
|
13
|
+
* Throws an error if the config file exists but is not valid JSON, there's some error reading it,
|
|
14
|
+
* or any settings are invalid. (As of writing, this doesn't do full schema validation; it only
|
|
15
|
+
* checks certain specific settings.)
|
|
14
16
|
*/
|
|
15
17
|
export declare function readAppConfig(appPath: string, options?: ReadAppConfigOptions): Promise<AppConfig>;
|
|
16
18
|
//# sourceMappingURL=readAppConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readAppConfig.d.ts","sourceRoot":"","sources":["../src/readAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"readAppConfig.d.ts","sourceRoot":"","sources":["../src/readAppConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAS7E,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,oBAAoB,CAAC,EAAE,eAAe,EAAE,CAAC;CAC1C;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC,CAqBvG"}
|
package/lib/readAppConfig.js
CHANGED
|
@@ -1,32 +1,55 @@
|
|
|
1
1
|
import { readJson } from '@ms-cloudpack/json-utilities';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import { getConfigPath } from './getConfigPath.js';
|
|
3
4
|
import { mergeParentConfig } from './mergeParentConfig.js';
|
|
4
5
|
import { resolveParentConfig } from './resolveParentConfig.js';
|
|
5
6
|
import { resolveModule } from '@ms-cloudpack/package-utilities';
|
|
7
|
+
import { validateMatch } from './validateMatch.js';
|
|
6
8
|
/**
|
|
7
9
|
* Reads the user config file and merges with any parent configs asynchronously.
|
|
8
10
|
* Note this is only useful for making modifications to the user config.
|
|
9
11
|
* For a full merged representation of config, use `readConfig` instead.
|
|
10
12
|
*
|
|
11
|
-
* Throws an error if the config file exists but is not valid JSON
|
|
13
|
+
* Throws an error if the config file exists but is not valid JSON, there's some error reading it,
|
|
14
|
+
* or any settings are invalid. (As of writing, this doesn't do full schema validation; it only
|
|
15
|
+
* checks certain specific settings.)
|
|
12
16
|
*/
|
|
13
17
|
export async function readAppConfig(appPath, options) {
|
|
14
18
|
const { extraPackageSettings } = options || {};
|
|
15
19
|
const { appConfigPath } = getConfigPath(appPath);
|
|
16
|
-
|
|
20
|
+
// Do a separate existence check for the top-level config, since it's fine if that doesn't exist.
|
|
21
|
+
// (readAppConfigInternal throws if the file doesn't exist because it's also used for reading
|
|
22
|
+
// parent configs from "extends", which must exist if specified.)
|
|
23
|
+
let config;
|
|
24
|
+
if (!fs.existsSync(appConfigPath)) {
|
|
25
|
+
config = {};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
config = (await readAppConfigInternal(appConfigPath)) || {};
|
|
29
|
+
}
|
|
17
30
|
if (extraPackageSettings) {
|
|
18
31
|
// Add these last so they take precedence.
|
|
19
32
|
(config.packageSettings ??= []).push(...extraPackageSettings);
|
|
20
33
|
}
|
|
21
34
|
return config;
|
|
22
35
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Resolve import specifiers for bundler capabilities registry.
|
|
38
|
+
* Throws if a specifier can't be resolved.
|
|
39
|
+
*/
|
|
40
|
+
function resolveBundlerCapabilities(params) {
|
|
41
|
+
const { appConfig: { bundlerCapabilitiesRegistry }, configPath, } = params;
|
|
42
|
+
if (!bundlerCapabilitiesRegistry) {
|
|
43
|
+
return;
|
|
26
44
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
for (const [name, importSpecifier] of Object.entries(bundlerCapabilitiesRegistry)) {
|
|
46
|
+
try {
|
|
47
|
+
const moduleUrl = resolveModule({ parentUrl: configPath, importSpecifier });
|
|
48
|
+
bundlerCapabilitiesRegistry[name] = moduleUrl;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
throw new Error(`Error resolving bundler capability "${importSpecifier}":\n${e.message || e}`);
|
|
52
|
+
}
|
|
30
53
|
}
|
|
31
54
|
}
|
|
32
55
|
/**
|
|
@@ -34,56 +57,42 @@ function tryResolveBundlerCapability(importSpecifier, parentUrl) {
|
|
|
34
57
|
* Throws an error if the config file exists but is not valid JSON, or there's some error reading it.
|
|
35
58
|
*/
|
|
36
59
|
async function readAppConfigInternal(configPath) {
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
|
|
60
|
+
const appConfig = await readJson(configPath, { mode: 'permissive', throwOnError: true });
|
|
61
|
+
if (!appConfig) {
|
|
62
|
+
// shouldn't happen, but just in case/to satisfy the types...
|
|
63
|
+
throw new Error(`Could not read config file ${configPath}`);
|
|
40
64
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
for (const [key, value] of Object.entries(AppConfig.bundlerCapabilitiesRegistry)) {
|
|
44
|
-
const moduleUrl = tryResolveBundlerCapability(value, configPath);
|
|
45
|
-
if (moduleUrl) {
|
|
46
|
-
AppConfig.bundlerCapabilitiesRegistry[key] = moduleUrl;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
65
|
+
if (!validateConfig(appConfig)) {
|
|
66
|
+
throw new Error(`Config file ${configPath} has invalid settings (see above for details)`);
|
|
49
67
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
: [];
|
|
75
|
-
// Recursively read any parent config files
|
|
76
|
-
const parentConfigs = [];
|
|
77
|
-
for (const importSpecifier of extendsArray) {
|
|
78
|
-
const resolvedPath = resolveParentConfig({ configPath, importSpecifier });
|
|
79
|
-
if (resolvedPath) {
|
|
80
|
-
const parentConfig = await readAppConfigInternal(resolvedPath);
|
|
81
|
-
if (parentConfig) {
|
|
82
|
-
parentConfigs.push(parentConfig);
|
|
68
|
+
resolveBundlerCapabilities({ appConfig, configPath });
|
|
69
|
+
processDeprecatedValues(appConfig);
|
|
70
|
+
// Read and merge with any parent configs (the same processing is applied to parent configs)
|
|
71
|
+
const { extends: _extends = [] } = appConfig;
|
|
72
|
+
const extendsArray = Array.isArray(_extends) ? _extends : [_extends];
|
|
73
|
+
const parentConfigs = await Promise.all(extendsArray.map((importSpecifier) => readAppConfigInternal(resolveParentConfig({ configPath, importSpecifier }))));
|
|
74
|
+
return mergeParentConfig({ appConfig, parentConfigs });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Validate parts of the current config file (before merging with parents) and log any errors.
|
|
78
|
+
* Logging here and then letting the caller throw if needed allows us to show more errors at once.
|
|
79
|
+
* @returns true if valid, false if not
|
|
80
|
+
*/
|
|
81
|
+
function validateConfig(appConfig) {
|
|
82
|
+
let isValid = true;
|
|
83
|
+
// Verify that there are no matches with a negated name and a version
|
|
84
|
+
for (const setting of appConfig.packageSettings || []) {
|
|
85
|
+
const { match } = setting;
|
|
86
|
+
const matches = Array.isArray(match) ? match : [match];
|
|
87
|
+
for (const m of matches) {
|
|
88
|
+
const result = validateMatch(m);
|
|
89
|
+
if (!result.isValid) {
|
|
90
|
+
isValid = false;
|
|
91
|
+
console.error(`Invalid packageSettings match: ${result.error}`);
|
|
83
92
|
}
|
|
84
93
|
}
|
|
85
94
|
}
|
|
86
|
-
return
|
|
95
|
+
return isValid;
|
|
87
96
|
}
|
|
88
97
|
/**
|
|
89
98
|
* Delete deprecated values and convert them to the new format. (This mutates the `config` object.)
|
|
@@ -108,7 +117,6 @@ function processDeprecatedValues(config) {
|
|
|
108
117
|
delete setting.bundlerType;
|
|
109
118
|
}
|
|
110
119
|
}
|
|
111
|
-
return config;
|
|
112
120
|
/* eslint-enable etc/no-deprecated */
|
|
113
121
|
}
|
|
114
122
|
//# sourceMappingURL=readAppConfig.js.map
|
package/lib/readAppConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readAppConfig.js","sourceRoot":"","sources":["../src/readAppConfig.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;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"readAppConfig.js","sourceRoot":"","sources":["../src/readAppConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASnD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAe,EAAE,OAA8B;IACjF,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAE/C,MAAM,EAAE,aAAa,EAAE,GAAG,aAAa,CAAC,OAAO,C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C,KAAK,CAAC,CAAC;QACvD,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO,GAAG,KAAK,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,kCAAkC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,MAAiB;IAChD,sCAAsC;IACtC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAE3D,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;QACtG,CAAC;QAED,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC;QAC1B,OAAO,MAAM,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC9B,OAAO,MAAM,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACtC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;YACtC,OAAO,OAAO,CAAC,WAAW,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,qCAAqC;AACvC,CAAC","sourcesContent":["import type { AppConfig, PackageSettings } from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport fs from 'fs';\nimport { getConfigPath } from './getConfigPath.js';\nimport { mergeParentConfig } from './mergeParentConfig.js';\nimport { resolveParentConfig } from './resolveParentConfig.js';\nimport { resolveModule } from '@ms-cloudpack/package-utilities';\nimport { validateMatch } from './validateMatch.js';\n\nexport interface ReadAppConfigOptions {\n /**\n * Extra package settings to add at the end of user-provided settings (so they take precedence).\n */\n extraPackageSettings?: PackageSettings[];\n}\n\n/**\n * Reads the user config file and merges with any parent configs asynchronously.\n * Note this is only useful for making modifications to the user config.\n * For a full merged representation of config, use `readConfig` instead.\n *\n * Throws an error if the config file exists but is not valid JSON, there's some error reading it,\n * or any settings are invalid. (As of writing, this doesn't do full schema validation; it only\n * checks certain specific settings.)\n */\nexport async function readAppConfig(appPath: string, options?: ReadAppConfigOptions): Promise<AppConfig> {\n const { extraPackageSettings } = options || {};\n\n const { appConfigPath } = getConfigPath(appPath);\n\n // Do a separate existence check for the top-level config, since it's fine if that doesn't exist.\n // (readAppConfigInternal throws if the file doesn't exist because it's also used for reading\n // parent configs from \"extends\", which must exist if specified.)\n let config: AppConfig;\n if (!fs.existsSync(appConfigPath)) {\n config = {};\n } else {\n config = (await readAppConfigInternal(appConfigPath)) || {};\n }\n\n if (extraPackageSettings) {\n // Add these last so they take precedence.\n (config.packageSettings ??= []).push(...extraPackageSettings);\n }\n\n return config;\n}\n\n/**\n * Resolve import specifiers for bundler capabilities registry.\n * Throws if a specifier can't be resolved.\n */\nfunction resolveBundlerCapabilities(params: { appConfig: AppConfig; configPath: string }): void {\n const {\n appConfig: { bundlerCapabilitiesRegistry },\n configPath,\n } = params;\n if (!bundlerCapabilitiesRegistry) {\n return;\n }\n\n for (const [name, importSpecifier] of Object.entries(bundlerCapabilitiesRegistry)) {\n try {\n const moduleUrl = resolveModule({ parentUrl: configPath, importSpecifier });\n bundlerCapabilitiesRegistry[name] = moduleUrl;\n } catch (e) {\n throw new Error(`Error resolving bundler capability \"${importSpecifier}\":\\n${(e as Error).message || e}`);\n }\n }\n}\n/**\n * Reads the user config, with any `extends` parent configs merged in.\n * Throws an error if the config file exists but is not valid JSON, or there's some error reading it.\n */\nasync function readAppConfigInternal(configPath: string): Promise<AppConfig> {\n const appConfig = await readJson<AppConfig>(configPath, { mode: 'permissive', throwOnError: true });\n if (!appConfig) {\n // shouldn't happen, but just in case/to satisfy the types...\n throw new Error(`Could not read config file ${configPath}`);\n }\n\n if (!validateConfig(appConfig)) {\n throw new Error(`Config file ${configPath} has invalid settings (see above for details)`);\n }\n\n resolveBundlerCapabilities({ appConfig, configPath });\n\n processDeprecatedValues(appConfig);\n\n // Read and merge with any parent configs (the same processing is applied to parent configs)\n const { extends: _extends = [] } = appConfig;\n const extendsArray = Array.isArray(_extends) ? _extends : [_extends];\n const parentConfigs = await Promise.all(\n extendsArray.map((importSpecifier) => readAppConfigInternal(resolveParentConfig({ configPath, importSpecifier }))),\n );\n return mergeParentConfig({ appConfig, parentConfigs });\n}\n\n/**\n * Validate parts of the current config file (before merging with parents) and log any errors.\n * Logging here and then letting the caller throw if needed allows us to show more errors at once.\n * @returns true if valid, false if not\n */\nfunction validateConfig(appConfig: AppConfig) {\n let isValid = true;\n\n // Verify that there are no matches with a negated name and a version\n for (const setting of appConfig.packageSettings || []) {\n const { match } = setting;\n const matches = Array.isArray(match) ? match : [match];\n for (const m of matches) {\n const result = validateMatch(m);\n if (!result.isValid) {\n isValid = false;\n console.error(`Invalid packageSettings match: ${result.error}`);\n }\n }\n }\n\n return isValid;\n}\n\n/**\n * Delete deprecated values and convert them to the new format. (This mutates the `config` object.)\n */\nfunction processDeprecatedValues(config: AppConfig): void {\n /* eslint-disable etc/no-deprecated */\n const { devServer, server, packageSettings = [] } = config;\n\n if (devServer) {\n if (server) {\n throw new Error('Cannot have both \"devServer\" and \"server\" in the config file. Use \"server\" only.');\n }\n\n config.server = devServer;\n delete config.devServer;\n }\n\n if (server?.routes) {\n config.routes = server.routes;\n delete server.routes;\n }\n\n for (const setting of packageSettings) {\n if (setting.bundlerType) {\n setting.bundler = setting.bundlerType;\n delete setting.bundlerType;\n }\n }\n /* eslint-enable etc/no-deprecated */\n}\n"]}
|
package/lib/readConfig.d.ts
CHANGED
|
@@ -8,7 +8,10 @@ export interface ReadConfigOptions extends ReadAppConfigOptions {
|
|
|
8
8
|
mode?: BundleMode;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Read the app config and generated config if they exist.
|
|
12
|
+
*
|
|
13
|
+
* Throws if there's an error reading a file or certain settings are invalid. (As of writing,
|
|
14
|
+
* this doesn't do full schema validation; it only validates certain specific settings.)
|
|
12
15
|
*/
|
|
13
16
|
export declare function readConfig(appPath: string, options?: ReadConfigOptions): Promise<CloudpackConfig>;
|
|
14
17
|
//# sourceMappingURL=readConfig.d.ts.map
|
package/lib/readConfig.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readConfig.d.ts","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EAOhB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAc9E,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;IAC7D;;;OAGG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED
|
|
1
|
+
{"version":3,"file":"readConfig.d.ts","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,UAAU,EACV,eAAe,EAOhB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAc9E,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;IAC7D;;;OAGG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,CAoBvG"}
|
package/lib/readConfig.js
CHANGED
|
@@ -7,14 +7,15 @@ import path from 'path';
|
|
|
7
7
|
import { readJsonSync } from '@ms-cloudpack/json-utilities';
|
|
8
8
|
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Read the app config and generated config if they exist.
|
|
11
|
+
*
|
|
12
|
+
* Throws if there's an error reading a file or certain settings are invalid. (As of writing,
|
|
13
|
+
* this doesn't do full schema validation; it only validates certain specific settings.)
|
|
11
14
|
*/
|
|
12
15
|
export async function readConfig(appPath, options) {
|
|
13
16
|
const { mode = 'library', extraPackageSettings } = options || {};
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
readGeneratedConfig(appPath),
|
|
17
|
-
]);
|
|
17
|
+
const { routes, ...appConfig } = await readAppConfig(appPath, { extraPackageSettings });
|
|
18
|
+
const generatedConfig = await readGeneratedConfig(appPath);
|
|
18
19
|
const config = {
|
|
19
20
|
...appConfig,
|
|
20
21
|
appPath,
|
|
@@ -23,7 +24,6 @@ export async function readConfig(appPath, options) {
|
|
|
23
24
|
generatedSnapshot: structuredClone(generatedConfig),
|
|
24
25
|
};
|
|
25
26
|
// Expands all routes which refer to source files into fully transformed route objects.
|
|
26
|
-
const routes = appConfig.routes;
|
|
27
27
|
if (routes?.length) {
|
|
28
28
|
config.routes = expandRoutes(routes, appPath);
|
|
29
29
|
}
|
package/lib/readConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readConfig.js","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACjG,OAAO,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;A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AC3F,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,mCAAmC;QACnC,UAAU;QACV,iBAAiB;QACjB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,UAAU,CAAC;KAClG,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BootstrapRoute,\n BundleMode,\n CloudpackConfig,\n ExpandedSourcePath,\n PackageJson,\n RenderedRoute,\n Route,\n ShorthandRenderedRoute,\n ShorthandRoute,\n} from '@ms-cloudpack/common-types';\nimport { isShorthandBootstrapRoute, isShorthandRenderedRoute } from '@ms-cloudpack/common-types';\nimport { readAppConfig, type ReadAppConfigOptions } from './readAppConfig.js';\nimport { readGeneratedConfig } from './readGeneratedConfig.js';\nimport { intermediateToSourcePath, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport { flattenExportsMap } from '@ms-cloudpack/package-utilities';\nimport path from 'path';\nimport { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * package.json with only the keys used in this file, since we're missing some logic from\n * PackageDefinitions which is assumed in the full type.\n */\ntype PartialPackageJson = Pick<PackageJson, 'exports' | 'module' | 'main'>;\n\nexport interface ReadConfigOptions extends ReadAppConfigOptions {\n /**\n * Override bundle mode.\n * @default 'library'\n */\n mode?: BundleMode;\n}\n\n/**\n * Read the app config and generated config if they exist.\n *\n * Throws if there's an error reading a file or certain settings are invalid. (As of writing,\n * this doesn't do full schema validation; it only validates certain specific settings.)\n */\nexport async function readConfig(appPath: string, options?: ReadConfigOptions): Promise<CloudpackConfig> {\n const { mode = 'library', extraPackageSettings } = options || {};\n\n const { routes, ...appConfig } = await readAppConfig(appPath, { extraPackageSettings });\n const generatedConfig = await readGeneratedConfig(appPath);\n\n const config: CloudpackConfig = {\n ...appConfig,\n appPath,\n mode,\n generated: generatedConfig,\n generatedSnapshot: structuredClone(generatedConfig),\n };\n\n // Expands all routes which refer to source files into fully transformed route objects.\n if (routes?.length) {\n config.routes = expandRoutes(routes, appPath);\n }\n\n return config;\n}\n\n/**\n * Ensure all source entries in routes are expanded to fully qualified entry paths.\n */\nfunction expandRoutes(routes: ShorthandRoute[], appPath: string): Route[] {\n // Cached flattened exports for appPath, used to expand entries\n const flattenedExports = getFlattenedExports(appPath);\n\n return routes.map((route) => {\n if (!isShorthandRenderedRoute(route) && !isShorthandBootstrapRoute(route)) {\n // Skip extra processing for other route types.\n return route;\n }\n\n // eslint-disable-next-line etc/no-deprecated\n const { entry, exportEntry, ...rest } = route;\n const renderedRoute: RenderedRoute | BootstrapRoute = rest;\n\n if (entry?.length) {\n // Expand the entry to full info about the file path.\n renderedRoute.entry = expandEntry({ entry, appPath, flattenedExports });\n }\n\n if (exportEntry) {\n // Handle backwards compatibility with moving from exportEntry to entry.\n const filePath = flattenedExports[exportEntry];\n if (!filePath) {\n throw new Error(\n `A route referenced exportEntry \"${exportEntry}\" but this couldn't be resolved from the package.json.`,\n );\n }\n\n const expanded = expandRouteEntry({ importPath: exportEntry, filePath, appPath });\n console.warn(\n 'The route property \"exportEntry\" is deprecated. Update your route as follows:',\n JSON.stringify({ ...renderedRoute, entry: expanded.sourcePath }, null, 2),\n );\n (renderedRoute.entry ??= []).push(expanded);\n }\n\n return renderedRoute;\n });\n}\n\nfunction expandEntry(params: {\n entry: ShorthandRenderedRoute['entry'];\n appPath: string;\n flattenedExports: Record<string, string | undefined>;\n}): ExpandedSourcePath[] {\n const { entry, appPath, flattenedExports } = params;\n const entryArray = Array.isArray(entry) ? entry : entry !== undefined ? [entry] : [];\n\n return entryArray.map((entryPath) =>\n expandRouteEntry({\n // Usually entryPath will be a source path, but also handle if it's an exports map key.\n importPath: flattenedExports[entryPath] ? entryPath : undefined,\n filePath: flattenedExports[entryPath] || entryPath,\n appPath,\n }),\n );\n}\n\n/**\n * Get flattened exports from package.json at `appPath`.\n * If there's no export for `.`, it will be filled in from `module || main`.\n */\nfunction getFlattenedExports(appPath: string): Record<string, string | undefined> {\n // We can't use PackageDefinitions.get here because we're reading the config, and definitions\n // cache requires config resulting in a cycle.\n const definition = readJsonSync<PartialPackageJson>(path.join(appPath, 'package.json')) || {};\n const flatExports: Record<string, string | undefined> = flattenExportsMap(definition.exports || {});\n flatExports['.'] ??= definition.module || definition.main;\n return flatExports;\n}\n\n/** Expands shorthand route entries into fully qualified ones. */\nfunction expandRouteEntry(options: { importPath?: string; filePath: string; appPath: string }): ExpandedSourcePath {\n const { filePath, appPath, importPath } = options;\n const sourcePath = intermediateToSourcePath(filePath, appPath);\n\n if (!sourcePath) {\n throw new Error(`Could not resolve source path for entry: ${filePath}`);\n }\n\n return {\n // Used to derive bundle entry path\n sourcePath,\n // Import map key\n importPath: importPath ? normalizeRelativePath(importPath) : sourceToIntermediatePath(sourcePath),\n };\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolve an import specifier for a parent config file.
|
|
3
|
-
*
|
|
3
|
+
* Throws if it can't be resolved or doesn't exist.
|
|
4
4
|
*/
|
|
5
5
|
export declare function resolveParentConfig(params: {
|
|
6
6
|
/** Path of the config file being processed. */
|
|
7
7
|
configPath: string;
|
|
8
8
|
/** The import specifier for the parent (extends) config file. */
|
|
9
9
|
importSpecifier: string;
|
|
10
|
-
}): string
|
|
10
|
+
}): string;
|
|
11
11
|
//# sourceMappingURL=resolveParentConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveParentConfig.d.ts","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"resolveParentConfig.d.ts","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,MAAM,CAWT"}
|
|
@@ -2,16 +2,18 @@ import { fileURLToPath } from 'url';
|
|
|
2
2
|
import { resolveModule } from '@ms-cloudpack/package-utilities';
|
|
3
3
|
/**
|
|
4
4
|
* Resolve an import specifier for a parent config file.
|
|
5
|
-
*
|
|
5
|
+
* Throws if it can't be resolved or doesn't exist.
|
|
6
6
|
*/
|
|
7
7
|
export function resolveParentConfig(params) {
|
|
8
|
-
const { importSpecifier } = params;
|
|
8
|
+
const { importSpecifier, configPath } = params;
|
|
9
9
|
try {
|
|
10
|
-
return fileURLToPath(resolveModule({ importSpecifier, parentUrl:
|
|
10
|
+
return fileURLToPath(resolveModule({ importSpecifier, parentUrl: configPath }));
|
|
11
11
|
}
|
|
12
12
|
catch (err) {
|
|
13
|
-
|
|
13
|
+
// The error message often includes the config path, so don't show it twice.
|
|
14
|
+
const errorMessage = String(err.message || err);
|
|
15
|
+
const fromPathPart = errorMessage.includes(configPath) ? '' : ` from ${configPath}`;
|
|
16
|
+
throw new Error(`Could not resolve "extends": "${importSpecifier}"${fromPathPart}:\n${errorMessage}`);
|
|
14
17
|
}
|
|
15
|
-
return undefined;
|
|
16
18
|
}
|
|
17
19
|
//# sourceMappingURL=resolveParentConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveParentConfig.js","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAKnC;IACC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveParentConfig.js","sourceRoot":"","sources":["../src/resolveParentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAKnC;IACC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE/C,IAAI,CAAC;QACH,OAAO,aAAa,CAAC,aAAa,CAAC,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IAClF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,4EAA4E;QAC5E,MAAM,YAAY,GAAG,MAAM,CAAE,GAAa,CAAC,OAAO,IAAI,GAAG,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC;QACpF,MAAM,IAAI,KAAK,CAAC,iCAAiC,eAAe,IAAI,YAAY,MAAM,YAAY,EAAE,CAAC,CAAC;IACxG,CAAC;AACH,CAAC","sourcesContent":["import { fileURLToPath } from 'url';\nimport { resolveModule } from '@ms-cloudpack/package-utilities';\n\n/**\n * Resolve an import specifier for a parent config file.\n * Throws if it can't be resolved or doesn't exist.\n */\nexport 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}): string {\n const { importSpecifier, configPath } = params;\n\n try {\n return fileURLToPath(resolveModule({ importSpecifier, parentUrl: configPath }));\n } catch (err) {\n // The error message often includes the config path, so don't show it twice.\n const errorMessage = String((err as Error).message || err);\n const fromPathPart = errorMessage.includes(configPath) ? '' : ` from ${configPath}`;\n throw new Error(`Could not resolve \"extends\": \"${importSpecifier}\"${fromPathPart}:\\n${errorMessage}`);\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PackageSettingsMatch } from '@ms-cloudpack/common-types';
|
|
2
|
+
/**
|
|
3
|
+
* Validate a package settings match object.
|
|
4
|
+
* (As of writing, this just checks that negated matches don't have a version.)
|
|
5
|
+
* @returns object with validation info (so the caller can log and/or throw as needed)
|
|
6
|
+
*/
|
|
7
|
+
export declare function validateMatch(match: PackageSettingsMatch): {
|
|
8
|
+
isValid: false;
|
|
9
|
+
error: string;
|
|
10
|
+
} | {
|
|
11
|
+
isValid: true;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=validateMatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateMatch.d.ts","sourceRoot":"","sources":["../src/validateMatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEvE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAQhH"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a package settings match object.
|
|
3
|
+
* (As of writing, this just checks that negated matches don't have a version.)
|
|
4
|
+
* @returns object with validation info (so the caller can log and/or throw as needed)
|
|
5
|
+
*/
|
|
6
|
+
export function validateMatch(match) {
|
|
7
|
+
if (typeof match === 'object' && match.name.startsWith('!') && match.version && match.version !== '*') {
|
|
8
|
+
return {
|
|
9
|
+
isValid: false,
|
|
10
|
+
error: `Negated match name "${match.name}" cannot have a version ("${match.version}")`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return { isValid: true };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=validateMatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateMatch.js","sourceRoot":"","sources":["../src/validateMatch.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAA2B;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC;QACtG,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,uBAAuB,KAAK,CAAC,IAAI,6BAA6B,KAAK,CAAC,OAAO,IAAI;SACvF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import type { PackageSettingsMatch } from '@ms-cloudpack/common-types';\n\n/**\n * Validate a package settings match object.\n * (As of writing, this just checks that negated matches don't have a version.)\n * @returns object with validation info (so the caller can log and/or throw as needed)\n */\nexport function validateMatch(match: PackageSettingsMatch): { isValid: false; error: string } | { isValid: true } {\n if (typeof match === 'object' && match.name.startsWith('!') && match.version && match.version !== '*') {\n return {\n isValid: false,\n error: `Negated match name \"${match.name}\" cannot have a version (\"${match.version}\")`,\n };\n }\n return { isValid: true };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Configuration handling for cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.23.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.23.3",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.1.8",
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^10.2.
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^10.2.8",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.2.4",
|
|
21
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
21
|
+
"@ms-cloudpack/path-utilities": "^2.7.52",
|
|
22
22
|
"semver": "^7.6.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|