@ms-cloudpack/config 0.27.0 → 0.27.2
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 +1 -1
- package/lib/checkMatch.d.ts.map +1 -1
- package/lib/checkMatch.js +3 -0
- package/lib/checkMatch.js.map +1 -1
- package/lib/constants.d.ts +9 -0
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +10 -0
- package/lib/constants.js.map +1 -1
- package/lib/createPackageSettingsTransform.d.ts.map +1 -1
- package/lib/createPackageSettingsTransform.js +1 -1
- package/lib/createPackageSettingsTransform.js.map +1 -1
- package/lib/ensureGeneratedSettingsForPackage.d.ts.map +1 -1
- package/lib/ensureGeneratedSettingsForPackage.js +0 -3
- package/lib/ensureGeneratedSettingsForPackage.js.map +1 -1
- package/lib/getCachePath.d.ts +9 -0
- package/lib/getCachePath.d.ts.map +1 -0
- package/lib/getCachePath.js +15 -0
- package/lib/getCachePath.js.map +1 -0
- package/lib/getUserPreferencesPath.d.ts +14 -0
- package/lib/getUserPreferencesPath.d.ts.map +1 -0
- package/lib/getUserPreferencesPath.js +24 -0
- package/lib/getUserPreferencesPath.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/readConfig.d.ts.map +1 -1
- package/lib/readConfig.js +17 -17
- package/lib/readConfig.js.map +1 -1
- package/lib/readUserPreferences.d.ts +6 -0
- package/lib/readUserPreferences.d.ts.map +1 -0
- package/lib/readUserPreferences.js +13 -0
- package/lib/readUserPreferences.js.map +1 -0
- package/lib/schemaUrls.d.ts +2 -0
- package/lib/schemaUrls.d.ts.map +1 -1
- package/lib/schemaUrls.js +2 -0
- package/lib/schemaUrls.js.map +1 -1
- package/lib/updateUserPreference.d.ts +15 -0
- package/lib/updateUserPreference.d.ts.map +1 -0
- package/lib/updateUserPreference.js +66 -0
- package/lib/updateUserPreference.js.map +1 -0
- package/package.json +4 -4
package/lib/checkMatch.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare function checkMatch(params: {
|
|
|
7
7
|
name: string;
|
|
8
8
|
/** The version of the package. */
|
|
9
9
|
version: string;
|
|
10
|
-
/** The match to check against. */
|
|
10
|
+
/** The match to check against. For an array, returns true if any entries match. */
|
|
11
11
|
match: PackageSettings['match'];
|
|
12
12
|
/** If true, require an exact match for the name (don't process wildcards). */
|
|
13
13
|
exactMatch?: boolean;
|
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,EAAE,MAAM,4BAA4B,CAAC;AAGlE;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,
|
|
1
|
+
{"version":3,"file":"checkMatch.d.ts","sourceRoot":"","sources":["../src/checkMatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,+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,GAAG,OAAO,CAwBV"}
|
package/lib/checkMatch.js
CHANGED
|
@@ -4,6 +4,9 @@ import { satisfies } from 'semver';
|
|
|
4
4
|
*/
|
|
5
5
|
export function checkMatch(params) {
|
|
6
6
|
const { name, version, match, exactMatch } = params;
|
|
7
|
+
if (Array.isArray(match)) {
|
|
8
|
+
return match.some((m) => checkMatch({ ...params, match: m }));
|
|
9
|
+
}
|
|
7
10
|
let matchName;
|
|
8
11
|
let matchVersion;
|
|
9
12
|
if (typeof match === 'string') {
|
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;AAEnC;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAS1B;IACC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAEpD,IAAI,SAAiB,CAAC;IACtB,IAAI,YAAgC,CAAC;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,SAAS,GAAG,KAAK,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,6FAA6F;QAC7F,YAAY,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IACnE,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 type { PackageSettings } from '@ms-cloudpack/common-types';\nimport { satisfies } from 'semver';\n\n/**\n * Checks 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: string;\n let matchVersion: string | undefined;\n if (typeof match === 'string') {\n matchName = match;\n } else {\n matchName = match.name;\n // If any version is allowed, unset the version to skip the satisfies() check for efficiency.\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"]}
|
|
1
|
+
{"version":3,"file":"checkMatch.js","sourceRoot":"","sources":["../src/checkMatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAS1B;IACC,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,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,SAAiB,CAAC;IACtB,IAAI,YAAgC,CAAC;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,SAAS,GAAG,KAAK,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,6FAA6F;QAC7F,YAAY,GAAG,KAAK,CAAC,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IACnE,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 type { PackageSettings } from '@ms-cloudpack/common-types';\nimport { satisfies } from 'semver';\n\n/**\n * Checks 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. 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}): boolean {\n const { name, version, match, exactMatch } = params;\n\n if (Array.isArray(match)) {\n return match.some((m) => checkMatch({ ...params, match: m }));\n }\n\n let matchName: string;\n let matchVersion: string | undefined;\n if (typeof match === 'string') {\n matchName = match;\n } else {\n matchName = match.name;\n // If any version is allowed, unset the version to skip the satisfies() check for efficiency.\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/lib/constants.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import type { UserPreferences } from '@ms-cloudpack/common-types';
|
|
1
2
|
export declare const appConfigFileName = "cloudpack.config.json";
|
|
2
3
|
export declare const generatedConfigFileName = "cloudpack.generated.json";
|
|
4
|
+
export declare const userPreferencesFileName = ".cloudpack.preferences.json";
|
|
5
|
+
/**
|
|
6
|
+
* Object with all valid keys of the UserPreferences object.
|
|
7
|
+
*
|
|
8
|
+
* (This is a mapping from key to true because TS doesn't have a good way to verify that an array
|
|
9
|
+
* contains all keys of a type.)
|
|
10
|
+
*/
|
|
11
|
+
export declare const allUserPreferences: Readonly<Record<keyof UserPreferences, boolean>>;
|
|
3
12
|
//# sourceMappingURL=constants.d.ts.map
|
package/lib/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AACzD,eAAO,MAAM,uBAAuB,6BAA6B,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,eAAO,MAAM,iBAAiB,0BAA0B,CAAC;AACzD,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAClE,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAErE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,eAAe,EAAE,OAAO,CAAC,CAE/E,CAAC"}
|
package/lib/constants.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
export const appConfigFileName = 'cloudpack.config.json';
|
|
2
2
|
export const generatedConfigFileName = 'cloudpack.generated.json';
|
|
3
|
+
export const userPreferencesFileName = '.cloudpack.preferences.json';
|
|
4
|
+
/**
|
|
5
|
+
* Object with all valid keys of the UserPreferences object.
|
|
6
|
+
*
|
|
7
|
+
* (This is a mapping from key to true because TS doesn't have a good way to verify that an array
|
|
8
|
+
* contains all keys of a type.)
|
|
9
|
+
*/
|
|
10
|
+
export const allUserPreferences = {
|
|
11
|
+
cachePath: true,
|
|
12
|
+
};
|
|
3
13
|
//# sourceMappingURL=constants.js.map
|
package/lib/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,0BAA0B,CAAC;AAClE,MAAM,CAAC,MAAM,uBAAuB,GAAG,6BAA6B,CAAC;AAErE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAqD;IAClF,SAAS,EAAE,IAAI;CAChB,CAAC","sourcesContent":["import type { UserPreferences } from '@ms-cloudpack/common-types';\n\nexport const appConfigFileName = 'cloudpack.config.json';\nexport const generatedConfigFileName = 'cloudpack.generated.json';\nexport const userPreferencesFileName = '.cloudpack.preferences.json';\n\n/**\n * Object with all valid keys of the UserPreferences object.\n *\n * (This is a mapping from key to true because TS doesn't have a good way to verify that an array\n * contains all keys of a type.)\n */\nexport const allUserPreferences: Readonly<Record<keyof UserPreferences, boolean>> = {\n cachePath: true,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPackageSettingsTransform.d.ts","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAO3B,MAAM,4BAA4B,CAAC;AAKpC;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,GAAG,0BAA0B,
|
|
1
|
+
{"version":3,"file":"createPackageSettingsTransform.d.ts","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAO3B,MAAM,4BAA4B,CAAC;AAKpC;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,eAAe,GAAG,0BAA0B,CA6ClG"}
|
|
@@ -7,7 +7,7 @@ import { mergePackageSettings } from './mergePackageSettings.js';
|
|
|
7
7
|
*/
|
|
8
8
|
export function createPackageSettingsTransform(config) {
|
|
9
9
|
return async ({ definition, packagePath, packages }) => {
|
|
10
|
-
const { name
|
|
10
|
+
const { name, version } = definition;
|
|
11
11
|
const { userPackageSettings, generatedPackageSettings } = getPackageSettings({
|
|
12
12
|
name,
|
|
13
13
|
version,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPackageSettingsTransform.js","sourceRoot":"","sources":["../src/createPackageSettingsTransform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,kBAAkB,EAAiC,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,MAAuB;IACpE,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE;QACrD,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,UAAU,CAAC;QAC/C,MAAM,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,GAAG,kBAAkB,CAAC;YAC3E,IAAI;YACJ,OAAO;YACP,mBAAmB,EAAE,MAAM,CAAC,eAAe;YAC3C,wBAAwB,EAAE,MAAM,CAAC,S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,UAAU;yBACjC,EACD,OAAO,CACR,CAAC,IAAI,eAAe,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;QAED,oEAAoE;QACpE,IAAI,eAAe,EAAE,CAAC;YACpB,uFAAuF;YACvF,+BAA+B;YAC/B,OAAO,YAAY,CAAC;QACtB,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,OAAO,CAAC,IAAI,CACV,mBAAmB,EAAE,OAAO;QAC1B,UAAU,CAAC,OAAO;QAClB,CAAC,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAC3E,CAAC;IAEF,0BAA0B;IAC1B,IAAI,wBAAwB,EAAE,OAAO,EAAE,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionTransform,\n PackageDefinitionsCache,\n PackageJson,\n PackageJsonDependencies,\n PackageJsonExports,\n PackageJsonExportsObject,\n RenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport { getPackageSettings, type GetPackageSettingsResult } from './getPackageSettings.js';\nimport { addExportsMapEntry, getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { mergePackageSettings } from './mergePackageSettings.js';\n\n/**\n * Creates a transform to be registered with a PackageDefinitions registry for updating package.json\n * based on package settings from the config.\n */\nexport function createPackageSettingsTransform(config: CloudpackConfig): PackageDefinitionTransform {\n return async ({ definition, packagePath, packages }) => {\n const { name = '', version = '' } = definition;\n const { userPackageSettings, generatedPackageSettings } = getPackageSettings({\n name,\n version,\n userPackageSettings: config.packageSettings,\n generatedPackageSettings: config.generated.packageSettings,\n });\n\n // Exclude all things not important in preserving within the package.json. This limits what we end up hashing\n // when we hash the definition.\n const { exports, includedDependencies, excludedDependencies, ...settings } = mergePackageSettings([\n userPackageSettings || {},\n generatedPackageSettings || {},\n ]);\n\n const newDefinition: PackageJson = {\n name,\n version,\n exports: await computeExports(\n { packagePath, definition, userPackageSettings, generatedPackageSettings },\n { packages, config },\n ),\n dependencies: computeDependencies({ definition, userPackageSettings, generatedPackageSettings }),\n };\n\n if (definition.peerDependencies && !userPackageSettings?.excludedDependencies?.includes('$peerDependencies')) {\n newDefinition.peerDependencies = !excludedDependencies?.length\n ? definition.peerDependencies\n : Object.fromEntries(\n Object.entries(definition.peerDependencies).filter(([dep]) => !excludedDependencies.includes(dep)),\n );\n }\n\n if (config.mode || Object.keys(settings).length > 0) {\n newDefinition.cloudpack = {\n mode: config.mode,\n ...settings,\n };\n }\n\n return newDefinition;\n };\n}\n\nfunction computeDependencies(\n options: GetPackageSettingsResult & {\n definition: PackageJson;\n },\n): PackageJsonDependencies {\n const { definition, userPackageSettings, generatedPackageSettings } = options;\n const { dependencies = {} } = definition;\n const newDependencies = { ...dependencies };\n\n // If we have included dependencies, add them.\n const includedDependencies = [\n ...(userPackageSettings?.includedDependencies || []),\n ...(generatedPackageSettings?.includedDependencies || []),\n ];\n\n // Expand the $devDependencies placeholder to the actual dev dependencies.\n const includeDevDependencies = includedDependencies.indexOf('$devDependencies');\n\n if (includeDevDependencies !== -1) {\n includedDependencies.splice(includeDevDependencies, 1, ...Object.keys(definition.devDependencies || {}));\n }\n\n // Add the dependency from other sources, or use a wildcard.\n for (const dep of includedDependencies) {\n newDependencies[dep] =\n definition.dependencies?.[dep] ||\n definition.devDependencies?.[dep] ||\n definition.peerDependencies?.[dep] ||\n definition.optionalDependencies?.[dep] ||\n '*';\n }\n\n const excludedDependencies = [\n ...(userPackageSettings?.excludedDependencies || []),\n ...(generatedPackageSettings?.excludedDependencies || []),\n ];\n\n // Expand the $peerDependencies placeholder to the actual peer dependencies.\n const excludePeerDependencies = excludedDependencies.indexOf('$peerDependencies');\n\n if (excludePeerDependencies !== -1) {\n // Add peer dependencies to the list of excluded dependencies.\n excludedDependencies.splice(excludePeerDependencies, 1, ...Object.keys(definition.peerDependencies || {}));\n }\n\n for (const dep of excludedDependencies) {\n delete newDependencies[dep];\n }\n\n return newDependencies;\n}\n\nasync function computeExports(\n options: GetPackageSettingsResult & {\n packagePath: string;\n definition: PackageJson;\n },\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\n): Promise<PackageJsonExports | undefined> {\n const { packagePath, definition, userPackageSettings, generatedPackageSettings } = options;\n const { appPath } = context.config;\n // TODO: an array of export objects is not really valid per the spec and most implementations\n const exports: PackageJsonExports[] = [];\n\n // If this is the app package, ensure the routes are part of the exports map.\n if (appPath === packagePath) {\n const { routes = [] } = context.config;\n const routeExports: PackageJsonExportsObject = {};\n let hasRouteExports = false;\n\n for (const route of routes) {\n const { entry } = route as RenderedRoute;\n\n if (entry?.length) {\n for (const entryItem of entry) {\n hasRouteExports =\n (await addExportsMapEntry(\n {\n exports: routeExports,\n packagePath,\n environmentCondition: 'browser',\n filePath: entryItem.sourcePath,\n importPath: entryItem.importPath,\n },\n context,\n )) || hasRouteExports;\n }\n }\n }\n\n // Insert them at the start, so that future exports have precedence.\n if (hasRouteExports) {\n // We short circuit here because we don't want to include any unused exports that might\n // be pulled from package.json.\n return routeExports;\n }\n }\n\n // Push exports from the package.\n exports.push(\n userPackageSettings?.exports ||\n definition.exports ||\n (await getExportsMap({ packagePath, disableTransforms: true }, context)),\n );\n\n // Push generated exports.\n if (generatedPackageSettings?.exports) {\n exports.push(generatedPackageSettings.exports);\n }\n\n if (exports.length === 0) {\n return undefined;\n }\n\n if (exports.length === 1) {\n return exports[0];\n }\n\n return exports;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createPackageSettingsTransform.js","sourceRoot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,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionTransform,\n PackageDefinitionsCache,\n PackageJson,\n PackageJsonDependencies,\n PackageJsonExports,\n PackageJsonExportsObject,\n RenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport { getPackageSettings, type GetPackageSettingsResult } from './getPackageSettings.js';\nimport { addExportsMapEntry, getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { mergePackageSettings } from './mergePackageSettings.js';\n\n/**\n * Creates a transform to be registered with a PackageDefinitions registry for updating package.json\n * based on package settings from the config.\n */\nexport function createPackageSettingsTransform(config: CloudpackConfig): PackageDefinitionTransform {\n return async ({ definition, packagePath, packages }) => {\n const { name, version } = definition;\n\n const { userPackageSettings, generatedPackageSettings } = getPackageSettings({\n name,\n version,\n userPackageSettings: config.packageSettings,\n generatedPackageSettings: config.generated.packageSettings,\n });\n\n // Exclude all things not important in preserving within the package.json. This limits what we end up hashing\n // when we hash the definition.\n const { exports, includedDependencies, excludedDependencies, ...settings } = mergePackageSettings([\n userPackageSettings || {},\n generatedPackageSettings || {},\n ]);\n\n const newDefinition: PackageJson = {\n name,\n version,\n exports: await computeExports(\n { packagePath, definition, userPackageSettings, generatedPackageSettings },\n { packages, config },\n ),\n dependencies: computeDependencies({ definition, userPackageSettings, generatedPackageSettings }),\n };\n\n if (definition.peerDependencies && !userPackageSettings?.excludedDependencies?.includes('$peerDependencies')) {\n newDefinition.peerDependencies = !excludedDependencies?.length\n ? definition.peerDependencies\n : Object.fromEntries(\n Object.entries(definition.peerDependencies).filter(([dep]) => !excludedDependencies.includes(dep)),\n );\n }\n\n if (config.mode || Object.keys(settings).length > 0) {\n newDefinition.cloudpack = {\n mode: config.mode,\n ...settings,\n };\n }\n\n return newDefinition;\n };\n}\n\nfunction computeDependencies(\n options: GetPackageSettingsResult & {\n definition: PackageJson;\n },\n): PackageJsonDependencies {\n const { definition, userPackageSettings, generatedPackageSettings } = options;\n const { dependencies = {} } = definition;\n const newDependencies = { ...dependencies };\n\n // If we have included dependencies, add them.\n const includedDependencies = [\n ...(userPackageSettings?.includedDependencies || []),\n ...(generatedPackageSettings?.includedDependencies || []),\n ];\n\n // Expand the $devDependencies placeholder to the actual dev dependencies.\n const includeDevDependencies = includedDependencies.indexOf('$devDependencies');\n\n if (includeDevDependencies !== -1) {\n includedDependencies.splice(includeDevDependencies, 1, ...Object.keys(definition.devDependencies || {}));\n }\n\n // Add the dependency from other sources, or use a wildcard.\n for (const dep of includedDependencies) {\n newDependencies[dep] =\n definition.dependencies?.[dep] ||\n definition.devDependencies?.[dep] ||\n definition.peerDependencies?.[dep] ||\n definition.optionalDependencies?.[dep] ||\n '*';\n }\n\n const excludedDependencies = [\n ...(userPackageSettings?.excludedDependencies || []),\n ...(generatedPackageSettings?.excludedDependencies || []),\n ];\n\n // Expand the $peerDependencies placeholder to the actual peer dependencies.\n const excludePeerDependencies = excludedDependencies.indexOf('$peerDependencies');\n\n if (excludePeerDependencies !== -1) {\n // Add peer dependencies to the list of excluded dependencies.\n excludedDependencies.splice(excludePeerDependencies, 1, ...Object.keys(definition.peerDependencies || {}));\n }\n\n for (const dep of excludedDependencies) {\n delete newDependencies[dep];\n }\n\n return newDependencies;\n}\n\nasync function computeExports(\n options: GetPackageSettingsResult & {\n packagePath: string;\n definition: PackageJson;\n },\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\n): Promise<PackageJsonExports | undefined> {\n const { packagePath, definition, userPackageSettings, generatedPackageSettings } = options;\n const { appPath } = context.config;\n // TODO: an array of export objects is not really valid per the spec and most implementations\n const exports: PackageJsonExports[] = [];\n\n // If this is the app package, ensure the routes are part of the exports map.\n if (appPath === packagePath) {\n const { routes = [] } = context.config;\n const routeExports: PackageJsonExportsObject = {};\n let hasRouteExports = false;\n\n for (const route of routes) {\n const { entry } = route as RenderedRoute;\n\n if (entry?.length) {\n for (const entryItem of entry) {\n hasRouteExports =\n (await addExportsMapEntry(\n {\n exports: routeExports,\n packagePath,\n environmentCondition: 'browser',\n filePath: entryItem.sourcePath,\n importPath: entryItem.importPath,\n },\n context,\n )) || hasRouteExports;\n }\n }\n }\n\n // Insert them at the start, so that future exports have precedence.\n if (hasRouteExports) {\n // We short circuit here because we don't want to include any unused exports that might\n // be pulled from package.json.\n return routeExports;\n }\n }\n\n // Push exports from the package.\n exports.push(\n userPackageSettings?.exports ||\n definition.exports ||\n (await getExportsMap({ packagePath, disableTransforms: true }, context)),\n );\n\n // Push generated exports.\n if (generatedPackageSettings?.exports) {\n exports.push(generatedPackageSettings.exports);\n }\n\n if (exports.length === 0) {\n return undefined;\n }\n\n if (exports.length === 1) {\n return exports[0];\n }\n\n return exports;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureGeneratedSettingsForPackage.d.ts","sourceRoot":"","sources":["../src/ensureGeneratedSettingsForPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAIpC;;;;;GAKG;AACH,wBAAsB,iCAAiC,CACrD,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,kBAAkB,CAAA;CAAE,EACxE,OAAO,EAAE;IAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IAAC,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GACzF,OAAO,CAAC,wBAAwB,CAAC,
|
|
1
|
+
{"version":3,"file":"ensureGeneratedSettingsForPackage.d.ts","sourceRoot":"","sources":["../src/ensureGeneratedSettingsForPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAIpC;;;;;GAKG;AACH,wBAAsB,iCAAiC,CACrD,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,kBAAkB,CAAA;CAAE,EACxE,OAAO,EAAE;IAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IAAC,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GACzF,OAAO,CAAC,wBAAwB,CAAC,CAwBnC"}
|
|
@@ -10,9 +10,6 @@ export async function ensureGeneratedSettingsForPackage(options, context) {
|
|
|
10
10
|
const { packagePath } = options;
|
|
11
11
|
const { config, packages } = context;
|
|
12
12
|
const definition = await packages.get(packagePath);
|
|
13
|
-
if (!definition || !definition.name || !definition.version) {
|
|
14
|
-
throw new Error(`Valid package definition not found for ${packagePath}`);
|
|
15
|
-
}
|
|
16
13
|
const { name, version } = definition;
|
|
17
14
|
let generatedPackageSettings = getGeneratedPackageSettings({
|
|
18
15
|
generatedPackageSettings: config.generated.packageSettings,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureGeneratedSettingsForPackage.js","sourceRoot":"","sources":["../src/ensureGeneratedSettingsForPackage.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,OAAwE,EACxE,OAA0F;IAE1F,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAErC,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAEnD,
|
|
1
|
+
{"version":3,"file":"ensureGeneratedSettingsForPackage.js","sourceRoot":"","sources":["../src/ensureGeneratedSettingsForPackage.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iCAAiC,CACrD,OAAwE,EACxE,OAA0F;IAE1F,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAErC,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAEnD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IACrC,IAAI,wBAAwB,GAAG,2BAA2B,CAAC;QACzD,wBAAwB,EAAE,MAAM,CAAC,SAAS,CAAC,eAAe;QAC1D,IAAI;QACJ,OAAO;KACR,CAAC,CAAC;IAEH,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC9B,wBAAwB,GAAG;YACzB,KAAK,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI;YAC/E,GAAG,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC;SACzE,CAAC;QAEF,MAAM,CAAC,SAAS,CAAC,eAAe,KAAK,EAAE,CAAC;QACxC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,wBAAwB,CAAC;AAClC,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionsCache,\n GeneratedPackageSettings,\n PackageJsonExports,\n} from '@ms-cloudpack/common-types';\nimport { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\n\n/**\n * Ensures the generated package setting for the package provided exists.\n * Used to consistently write to the generated config.\n * Only call this function when you will create a package setting for the package.\n * Note: Does not write to disk.\n */\nexport async function ensureGeneratedSettingsForPackage(\n options: { packagePath: string; defaultExportsMap?: PackageJsonExports },\n context: { config: Pick<CloudpackConfig, 'generated'>; packages: PackageDefinitionsCache },\n): Promise<GeneratedPackageSettings> {\n const { packagePath } = options;\n const { config, packages } = context;\n\n const definition = await packages.get(packagePath);\n\n const { name, version } = definition;\n let generatedPackageSettings = getGeneratedPackageSettings({\n generatedPackageSettings: config.generated.packageSettings,\n name,\n version,\n });\n\n if (!generatedPackageSettings) {\n generatedPackageSettings = {\n match: isExternalPackage(packagePath) ? { name, version: `^${version}` } : name,\n ...(options.defaultExportsMap && { exports: options.defaultExportsMap }),\n };\n\n config.generated.packageSettings ??= [];\n config.generated.packageSettings.push(generatedPackageSettings);\n }\n\n return generatedPackageSettings;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the path to the cache directory.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getCachePath(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Gets the path to the app's local cache directory.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getLocalCachePath(appPath: string): string;
|
|
9
|
+
//# sourceMappingURL=getCachePath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCachePath.d.ts","sourceRoot":"","sources":["../src/getCachePath.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,YAAY,WAE3B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,UAEhD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Gets the path to the cache directory.
|
|
5
|
+
*/
|
|
6
|
+
export function getCachePath() {
|
|
7
|
+
return path.join(os.homedir(), '.cloudpack');
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Gets the path to the app's local cache directory.
|
|
11
|
+
*/
|
|
12
|
+
export function getLocalCachePath(appPath) {
|
|
13
|
+
return path.join(appPath, 'node_modules', '.cache', 'cloudpack');
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getCachePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCachePath.js","sourceRoot":"","sources":["../src/getCachePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import os from 'os';\nimport path from 'path';\n\n/**\n * Gets the path to the cache directory.\n */\nexport function getCachePath() {\n return path.join(os.homedir(), '.cloudpack');\n}\n\n/**\n * Gets the path to the app's local cache directory.\n */\nexport function getLocalCachePath(appPath: string) {\n return path.join(appPath, 'node_modules', '.cache', 'cloudpack');\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path to the user-level preferences file.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getUserPreferencesPath(): string;
|
|
5
|
+
/**
|
|
6
|
+
* For testing only: use this folder instead of the home directory for the user preferences.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setMockUserPreferencesDir(newPath: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Get the currently set mock user preferences directory.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function _getMockUserPreferencesDir(): string | undefined;
|
|
14
|
+
//# sourceMappingURL=getUserPreferencesPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserPreferencesPath.d.ts","sourceRoot":"","sources":["../src/getUserPreferencesPath.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,sBAAsB,WAErC;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,QAExD;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,uBAEzC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { userPreferencesFileName } from './constants.js';
|
|
4
|
+
let mockUserPreferencesDir;
|
|
5
|
+
/**
|
|
6
|
+
* Path to the user-level preferences file.
|
|
7
|
+
*/
|
|
8
|
+
export function getUserPreferencesPath() {
|
|
9
|
+
return path.join(mockUserPreferencesDir || os.homedir(), userPreferencesFileName);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* For testing only: use this folder instead of the home directory for the user preferences.
|
|
13
|
+
*/
|
|
14
|
+
export function setMockUserPreferencesDir(newPath) {
|
|
15
|
+
mockUserPreferencesDir = newPath;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the currently set mock user preferences directory.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export function _getMockUserPreferencesDir() {
|
|
22
|
+
return mockUserPreferencesDir;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=getUserPreferencesPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserPreferencesPath.js","sourceRoot":"","sources":["../src/getUserPreferencesPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,IAAI,sBAA0C,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,CAAC,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,uBAAuB,CAAC,CAAC;AACpF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACvD,sBAAsB,GAAG,OAAO,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,sBAAsB,CAAC;AAChC,CAAC","sourcesContent":["import os from 'os';\nimport path from 'path';\nimport { userPreferencesFileName } from './constants.js';\n\nlet mockUserPreferencesDir: string | undefined;\n\n/**\n * Path to the user-level preferences file.\n */\nexport function getUserPreferencesPath() {\n return path.join(mockUserPreferencesDir || os.homedir(), userPreferencesFileName);\n}\n\n/**\n * For testing only: use this folder instead of the home directory for the user preferences.\n */\nexport function setMockUserPreferencesDir(newPath: string) {\n mockUserPreferencesDir = newPath;\n}\n\n/**\n * Get the currently set mock user preferences directory.\n * @internal\n */\nexport function _getMockUserPreferencesDir() {\n return mockUserPreferencesDir;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
export { checkMatch } from './checkMatch.js';
|
|
2
2
|
export { configTemplate } from './configTemplate.js';
|
|
3
3
|
export { generatedConfigFileName, appConfigFileName } from './constants.js';
|
|
4
|
+
export { allUserPreferences } from './constants.js';
|
|
4
5
|
export { createPackageDefinitions } from './createPackageDefinitions.js';
|
|
6
|
+
export { getCachePath, getLocalCachePath } from './getCachePath.js';
|
|
5
7
|
export { getConfigPath } from './getConfigPath.js';
|
|
8
|
+
export { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';
|
|
6
9
|
export { getPackageSettings } from './getPackageSettings.js';
|
|
7
10
|
export { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
|
|
8
11
|
export { readConfig } from './readConfig.js';
|
|
9
12
|
export { readGeneratedConfig } from './readGeneratedConfig.js';
|
|
10
13
|
export { readAppConfig } from './readAppConfig.js';
|
|
14
|
+
export { readUserPreferences } from './readUserPreferences.js';
|
|
11
15
|
export { writeGeneratedConfig } from './writeGeneratedConfig.js';
|
|
12
16
|
export { writeAppConfig } from './writeAppConfig.js';
|
|
13
17
|
export { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';
|
|
18
|
+
export { updateUserPreference } from './updateUserPreference.js';
|
|
14
19
|
//# 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,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC"}
|
|
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,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,EAAE,MAAM,iBAAiB,CAAC;AAC7C,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"}
|
package/lib/index.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
export { checkMatch } from './checkMatch.js';
|
|
2
2
|
export { configTemplate } from './configTemplate.js';
|
|
3
3
|
export { generatedConfigFileName, appConfigFileName } from './constants.js';
|
|
4
|
+
export { allUserPreferences } from './constants.js';
|
|
4
5
|
export { createPackageDefinitions } from './createPackageDefinitions.js';
|
|
6
|
+
export { getCachePath, getLocalCachePath } from './getCachePath.js';
|
|
5
7
|
export { getConfigPath } from './getConfigPath.js';
|
|
8
|
+
export { getUserPreferencesPath, setMockUserPreferencesDir } from './getUserPreferencesPath.js';
|
|
6
9
|
export { getPackageSettings } from './getPackageSettings.js';
|
|
7
10
|
export { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
|
|
8
11
|
export { readConfig } from './readConfig.js';
|
|
9
12
|
export { readGeneratedConfig } from './readGeneratedConfig.js';
|
|
10
13
|
export { readAppConfig } from './readAppConfig.js';
|
|
14
|
+
export { readUserPreferences } from './readUserPreferences.js';
|
|
11
15
|
export { writeGeneratedConfig } from './writeGeneratedConfig.js';
|
|
12
16
|
export { writeAppConfig } from './writeAppConfig.js';
|
|
13
17
|
export { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.js';
|
|
18
|
+
export { updateUserPreference } from './updateUserPreference.js';
|
|
14
19
|
//# 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,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["export { checkMatch } from './checkMatch.js';\nexport { configTemplate } from './configTemplate.js';\nexport { generatedConfigFileName, appConfigFileName } from './constants.js';\nexport { createPackageDefinitions } from './createPackageDefinitions.js';\nexport { getConfigPath } from './getConfigPath.js';\nexport { getPackageSettings } from './getPackageSettings.js';\nexport { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';\nexport { readConfig } from './readConfig.js';\nexport { readGeneratedConfig } from './readGeneratedConfig.js';\nexport { readAppConfig } from './readAppConfig.js';\nexport { writeGeneratedConfig } from './writeGeneratedConfig.js';\nexport { writeAppConfig } from './writeAppConfig.js';\nexport { ensureGeneratedSettingsForPackage } from './ensureGeneratedSettingsForPackage.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,EAAE,MAAM,iBAAiB,CAAC;AAC7C,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 } 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"]}
|
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,EACV,UAAU,EACV,eAAe,EAKhB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"readConfig.d.ts","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AAepC;;GAEG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAcxG"}
|
package/lib/readConfig.js
CHANGED
|
@@ -26,24 +26,24 @@ export async function readConfig(appPath, mode = 'library') {
|
|
|
26
26
|
async function expandRouteShorthandEntries(config, appPath) {
|
|
27
27
|
const { routes } = config;
|
|
28
28
|
let definition;
|
|
29
|
-
if (routes?.length) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expandDeprecatedExportEntry(route, definition, appPath);
|
|
29
|
+
if (!routes?.length) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
for (const route of routes) {
|
|
33
|
+
const shorthandRoute = route;
|
|
34
|
+
const renderedRoute = route;
|
|
35
|
+
renderedRoute.entry = ensureArray(shorthandRoute.entry)?.map((filePath) => expandRouteEntry({
|
|
36
|
+
filePath,
|
|
37
|
+
appPath,
|
|
38
|
+
}));
|
|
39
|
+
// eslint-disable-next-line etc/no-deprecated
|
|
40
|
+
if (shorthandRoute.exportEntry) {
|
|
41
|
+
if (!definition) {
|
|
42
|
+
// We can't use PackageDefinitions.get here because we're reading the config, and definitions
|
|
43
|
+
// cache requires config resulting in a cycle.
|
|
44
|
+
definition = (await readJson(path.join(appPath, 'package.json')));
|
|
46
45
|
}
|
|
46
|
+
expandDeprecatedExportEntry(route, definition, appPath);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
package/lib/readConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readConfig.js","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAElG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"readConfig.js","sourceRoot":"","sources":["../src/readConfig.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAElG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAQxD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe,EAAE,OAAmB,SAAS;IAC5E,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/G,MAAM,MAAM,GAAG;QACb,GAAG,SAAS;QACZ,OAAO;QACP,IAAI;QACJ,SAAS,EAAE,eAAe;QAC1B,iBAAiB,EAAE,eA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C,CAAC;IAE9D,OAAO;QACL,mCAAmC;QACnC,UAAU;QACV,gCAAgC;QAChC,UAAU,EAAE,UAAU,IAAI,gBAAgB;QAC1C,kCAAkC;QAClC,WAAW,EAAE,gBAAgB;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type {\n BundleMode,\n CloudpackConfig,\n PackageJson,\n RenderedRoute,\n Route,\n ShorthandRenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport { readAppConfig } from './readAppConfig.js';\nimport { readGeneratedConfig } from './readGeneratedConfig.js';\nimport { intermediateToSourcePath, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport type { ExpandedSourcePath } from '../../common-types/lib/ExpandedSourcePath.js';\nimport { flattenExportsMap } from '@ms-cloudpack/package-utilities';\nimport path from 'path';\nimport { readJson } from '@ms-cloudpack/json-utilities';\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\n/**\n * Reads the config file asynchronously (and merges generated config into the result.)\n */\nexport async function readConfig(appPath: string, mode: BundleMode = 'library'): Promise<CloudpackConfig> {\n const [appConfig, generatedConfig] = await Promise.all([readAppConfig(appPath), readGeneratedConfig(appPath)]);\n const config = {\n ...appConfig,\n appPath,\n mode,\n generated: generatedConfig,\n generatedSnapshot: structuredClone(generatedConfig),\n } as CloudpackConfig;\n\n // Expands all routes which refer to source files into fully transformed route objects.\n await expandRouteShorthandEntries(config, appPath);\n\n return config;\n}\n\n/**\n * Ensure all source entries in route are expanded to fully qualified entry paths.\n */\nasync function expandRouteShorthandEntries(config: CloudpackConfig, appPath: string) {\n const { routes } = config;\n let definition: PartialPackageJson | undefined;\n\n if (!routes?.length) {\n return;\n }\n\n for (const route of routes) {\n const shorthandRoute = route as ShorthandRenderedRoute;\n const renderedRoute = route as RenderedRoute;\n\n renderedRoute.entry = ensureArray(shorthandRoute.entry)?.map((filePath) =>\n expandRouteEntry({\n filePath,\n appPath,\n }),\n );\n\n // eslint-disable-next-line etc/no-deprecated\n if (shorthandRoute.exportEntry) {\n if (!definition) {\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 definition = (await readJson(path.join(appPath, 'package.json'))) as PartialPackageJson;\n }\n\n expandDeprecatedExportEntry(route, definition, appPath);\n }\n }\n}\n\n/**\n * Handle backwards compatibility with moving from exportEntry to entry. When exportEntry is deleted,\n * this function can be removed.\n */\nfunction expandDeprecatedExportEntry(route: Route, definition: PartialPackageJson, appPath: string) {\n const shorthandRoute = route as ShorthandRenderedRoute;\n const renderedRoute = route as RenderedRoute;\n\n // eslint-disable-next-line etc/no-deprecated\n const { exportEntry } = shorthandRoute;\n const flattenedExports = flattenExportsMap(definition.exports || {});\n\n if (exportEntry) {\n renderedRoute.entry = ensureArray(renderedRoute.entry) as unknown as ExpandedSourcePath[];\n\n const filePath = flattenedExports[exportEntry] || definition.module || definition.main;\n\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 // We are converting the exportEntry to an ExpandedSourcePath so that the route\n // can be returned as a RenderedRoute.\n renderedRoute.entry.push(\n expandRouteEntry({\n importPath: exportEntry,\n filePath,\n appPath,\n }),\n );\n\n // eslint-disable-next-line etc/no-deprecated\n delete shorthandRoute.exportEntry;\n }\n}\n\n/** Ensures the value is an array, or is wrapped in one. If a value is blank, will return a blank array. */\nfunction ensureArray<T>(value?: T): T extends unknown[] ? T : T[] {\n if (Array.isArray(value)) {\n return value as T extends unknown[] ? T : T[];\n }\n\n return (value !== undefined ? [value] : []) as T extends unknown[] ? T : T[];\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 const intermediatePath = sourceToIntermediatePath(sourcePath);\n\n return {\n // Used to derive bundle entry path\n sourcePath,\n // Used to derive import map key\n importPath: importPath || intermediatePath,\n // Used to derive import map value\n requestPath: intermediatePath,\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readUserPreferences.d.ts","sourceRoot":"","sources":["../src/readUserPreferences.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE;;GAEG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,eAAe,CAAC,CAQpE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readJson } from '@ms-cloudpack/json-utilities';
|
|
2
|
+
import { getUserPreferencesPath } from './getUserPreferencesPath.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the user preferences file asynchronously.
|
|
5
|
+
*/
|
|
6
|
+
export async function readUserPreferences() {
|
|
7
|
+
const { $schema, ...prefs } = (await readJson(getUserPreferencesPath(), {
|
|
8
|
+
verbose: true,
|
|
9
|
+
mode: 'permissive',
|
|
10
|
+
})) || {};
|
|
11
|
+
return prefs;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=readUserPreferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readUserPreferences.js","sourceRoot":"","sources":["../src/readUserPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,GACzB,CAAC,MAAM,QAAQ,CAAyC,sBAAsB,EAAE,EAAE;QAChF,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,YAAY;KACnB,CAAC,CAAC,IAAI,EAAE,CAAC;IAEZ,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { readJson } from '@ms-cloudpack/json-utilities';\nimport type { UserPreferences } from '@ms-cloudpack/common-types';\nimport { getUserPreferencesPath } from './getUserPreferencesPath.js';\n\n/**\n * Reads the user preferences file asynchronously.\n */\nexport async function readUserPreferences(): Promise<UserPreferences> {\n const { $schema, ...prefs } =\n (await readJson<UserPreferences & { $schema?: string }>(getUserPreferencesPath(), {\n verbose: true,\n mode: 'permissive',\n })) || {};\n\n return prefs;\n}\n"]}
|
package/lib/schemaUrls.d.ts
CHANGED
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
export declare const generatedAppConfigSchemaUrl = "https://unpkg.com/@ms-cloudpack/common-types/schema/GeneratedConfig.json";
|
|
3
3
|
/** unpkg URL for the AppConfig JSON schema */
|
|
4
4
|
export declare const appConfigSchemaUrl = "https://unpkg.com/@ms-cloudpack/common-types/schema/AppConfig.json";
|
|
5
|
+
/** unpkg URL for the UserPreferences JSON schema */
|
|
6
|
+
export declare const userPreferencesSchemaUrl = "https://unpkg.com/@ms-cloudpack/common-types/schema/UserPreferences.json";
|
|
5
7
|
//# sourceMappingURL=schemaUrls.d.ts.map
|
package/lib/schemaUrls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaUrls.d.ts","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,eAAO,MAAM,2BAA2B,6EAAyC,CAAC;AAElF,8CAA8C;AAC9C,eAAO,MAAM,kBAAkB,uEAAmC,CAAC"}
|
|
1
|
+
{"version":3,"file":"schemaUrls.d.ts","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,eAAO,MAAM,2BAA2B,6EAAyC,CAAC;AAElF,8CAA8C;AAC9C,eAAO,MAAM,kBAAkB,uEAAmC,CAAC;AAEnE,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,6EAAyC,CAAC"}
|
package/lib/schemaUrls.js
CHANGED
|
@@ -3,4 +3,6 @@ const schemaPrefix = 'https://unpkg.com/@ms-cloudpack/common-types/schema';
|
|
|
3
3
|
export const generatedAppConfigSchemaUrl = `${schemaPrefix}/GeneratedConfig.json`;
|
|
4
4
|
/** unpkg URL for the AppConfig JSON schema */
|
|
5
5
|
export const appConfigSchemaUrl = `${schemaPrefix}/AppConfig.json`;
|
|
6
|
+
/** unpkg URL for the UserPreferences JSON schema */
|
|
7
|
+
export const userPreferencesSchemaUrl = `${schemaPrefix}/UserPreferences.json`;
|
|
6
8
|
//# sourceMappingURL=schemaUrls.js.map
|
package/lib/schemaUrls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaUrls.js","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,qDAAqD,CAAC;AAE3E,oDAAoD;AACpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,YAAY,uBAAuB,CAAC;AAElF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,YAAY,iBAAiB,CAAC","sourcesContent":["const schemaPrefix = 'https://unpkg.com/@ms-cloudpack/common-types/schema';\n\n/** unpkg URL for the GeneratedConfig JSON schema */\nexport const generatedAppConfigSchemaUrl = `${schemaPrefix}/GeneratedConfig.json`;\n\n/** unpkg URL for the AppConfig JSON schema */\nexport const appConfigSchemaUrl = `${schemaPrefix}/AppConfig.json`;\n"]}
|
|
1
|
+
{"version":3,"file":"schemaUrls.js","sourceRoot":"","sources":["../src/schemaUrls.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,qDAAqD,CAAC;AAE3E,oDAAoD;AACpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,YAAY,uBAAuB,CAAC;AAElF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,YAAY,iBAAiB,CAAC;AAEnE,oDAAoD;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,YAAY,uBAAuB,CAAC","sourcesContent":["const schemaPrefix = 'https://unpkg.com/@ms-cloudpack/common-types/schema';\n\n/** unpkg URL for the GeneratedConfig JSON schema */\nexport const generatedAppConfigSchemaUrl = `${schemaPrefix}/GeneratedConfig.json`;\n\n/** unpkg URL for the AppConfig JSON schema */\nexport const appConfigSchemaUrl = `${schemaPrefix}/AppConfig.json`;\n\n/** unpkg URL for the UserPreferences JSON schema */\nexport const userPreferencesSchemaUrl = `${schemaPrefix}/UserPreferences.json`;\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { UserPreferences } from '@ms-cloudpack/common-types';
|
|
2
|
+
/**
|
|
3
|
+
* Validate and write an update to a user preference item.
|
|
4
|
+
* Creates the file if it doesn't already exist.
|
|
5
|
+
*
|
|
6
|
+
* Throws an error if the key is not a valid user preference name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function updateUserPreference(params: {
|
|
9
|
+
key: keyof UserPreferences;
|
|
10
|
+
/** Update `key` to `newValue` */
|
|
11
|
+
newValue?: string;
|
|
12
|
+
/** Delete `key` */
|
|
13
|
+
deleteValue?: boolean;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
//# sourceMappingURL=updateUserPreference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateUserPreference.d.ts","sourceRoot":"","sources":["../src/updateUserPreference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAQlE;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE;IACjD,GAAG,EAAE,MAAM,eAAe,CAAC;IAC3B,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,iBAiCA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { writeJson } from '@ms-cloudpack/json-utilities';
|
|
2
|
+
import { _getMockUserPreferencesDir, getUserPreferencesPath } from './getUserPreferencesPath.js';
|
|
3
|
+
import { allUserPreferences } from './constants.js';
|
|
4
|
+
import { readUserPreferences } from './readUserPreferences.js';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { isFolderSync } from '@ms-cloudpack/path-utilities';
|
|
7
|
+
import { userPreferencesSchemaUrl } from './schemaUrls.js';
|
|
8
|
+
/**
|
|
9
|
+
* Validate and write an update to a user preference item.
|
|
10
|
+
* Creates the file if it doesn't already exist.
|
|
11
|
+
*
|
|
12
|
+
* Throws an error if the key is not a valid user preference name.
|
|
13
|
+
*/
|
|
14
|
+
export async function updateUserPreference(params) {
|
|
15
|
+
const { key, deleteValue } = params;
|
|
16
|
+
if (process.env.JEST_WORKER_ID && !_getMockUserPreferencesDir()) {
|
|
17
|
+
// Prevent tests from accidentally messing with real global state...
|
|
18
|
+
throw new Error('Tests must call setMockUserPreferencesDir before calling updateUserPreference.');
|
|
19
|
+
}
|
|
20
|
+
// The key is user input which could potentially be invalid, despite the types.
|
|
21
|
+
if (!allUserPreferences[key]) {
|
|
22
|
+
throw new Error(`"${key}" is not a valid user preference name.`);
|
|
23
|
+
}
|
|
24
|
+
let value = params.newValue?.trim();
|
|
25
|
+
if (!deleteValue) {
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
throw new Error('Must specify newValue or deleteValue (this is a bug in Cloudpack)');
|
|
28
|
+
}
|
|
29
|
+
value = validateValue(key, value);
|
|
30
|
+
}
|
|
31
|
+
const newPreferences = {
|
|
32
|
+
...(await readUserPreferences()),
|
|
33
|
+
$schema: userPreferencesSchemaUrl,
|
|
34
|
+
};
|
|
35
|
+
if (deleteValue) {
|
|
36
|
+
delete newPreferences[key];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
newPreferences[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return writeJson(getUserPreferencesPath(), newPreferences, { update: true, mode: 'permissive' });
|
|
42
|
+
}
|
|
43
|
+
function validateValue(key, value) {
|
|
44
|
+
switch (key) {
|
|
45
|
+
case 'cachePath': {
|
|
46
|
+
if (!value) {
|
|
47
|
+
throw new Error('The cache folder cannot be empty.');
|
|
48
|
+
}
|
|
49
|
+
if (!path.isAbsolute(value)) {
|
|
50
|
+
throw new Error('The cache folder must be an absolute path.');
|
|
51
|
+
}
|
|
52
|
+
const parentFolder = path.dirname(value);
|
|
53
|
+
if (!isFolderSync(parentFolder)) {
|
|
54
|
+
throw new Error(`The parent folder "${parentFolder}" of the cache folder does not exist.`);
|
|
55
|
+
}
|
|
56
|
+
// The folder is valid
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
default: {
|
|
60
|
+
// this gives a type error if a new preference is added
|
|
61
|
+
const exhaustiveCheck = key;
|
|
62
|
+
throw new Error(`Unhandled user preference: "${exhaustiveCheck}"`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=updateUserPreference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateUserPreference.js","sourceRoot":"","sources":["../src/updateUserPreference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAM1C;IACC,MA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vD,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAChE,CAAC;YAED,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACzC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,sBAAsB,YAAY,uCAAuC,CAAC,CAAC;YAC7F,CAAC;YAED,sBAAsB;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACR,uDAAuD;YACvD,MAAM,eAAe,GAAU,GAAG,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,+BAA+B,eAAe,GAAG,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { writeJson } from '@ms-cloudpack/json-utilities';\nimport type { UserPreferences } from '@ms-cloudpack/common-types';\nimport { _getMockUserPreferencesDir, getUserPreferencesPath } from './getUserPreferencesPath.js';\nimport { allUserPreferences } from './constants.js';\nimport { readUserPreferences } from './readUserPreferences.js';\nimport path from 'path';\nimport { isFolderSync } from '@ms-cloudpack/path-utilities';\nimport { userPreferencesSchemaUrl } from './schemaUrls.js';\n\n/**\n * Validate and write an update to a user preference item.\n * Creates the file if it doesn't already exist.\n *\n * Throws an error if the key is not a valid user preference name.\n */\nexport async function updateUserPreference(params: {\n key: keyof UserPreferences;\n /** Update `key` to `newValue` */\n newValue?: string;\n /** Delete `key` */\n deleteValue?: boolean;\n}) {\n const { key, deleteValue } = params;\n\n if (process.env.JEST_WORKER_ID && !_getMockUserPreferencesDir()) {\n // Prevent tests from accidentally messing with real global state...\n throw new Error('Tests must call setMockUserPreferencesDir before calling updateUserPreference.');\n }\n\n // The key is user input which could potentially be invalid, despite the types.\n if (!allUserPreferences[key]) {\n throw new Error(`\"${key}\" is not a valid user preference name.`);\n }\n\n let value = params.newValue?.trim();\n\n if (!deleteValue) {\n if (value === undefined) {\n throw new Error('Must specify newValue or deleteValue (this is a bug in Cloudpack)');\n }\n value = validateValue(key, value);\n }\n\n const newPreferences = {\n ...(await readUserPreferences()),\n $schema: userPreferencesSchemaUrl,\n };\n if (deleteValue) {\n delete newPreferences[key];\n } else {\n newPreferences[key] = value;\n }\n\n return writeJson(getUserPreferencesPath(), newPreferences, { update: true, mode: 'permissive' });\n}\n\nfunction validateValue(key: keyof UserPreferences, value: string) {\n switch (key) {\n case 'cachePath': {\n if (!value) {\n throw new Error('The cache folder cannot be empty.');\n }\n\n if (!path.isAbsolute(value)) {\n throw new Error('The cache folder must be an absolute path.');\n }\n\n const parentFolder = path.dirname(value);\n if (!isFolderSync(parentFolder)) {\n throw new Error(`The parent folder \"${parentFolder}\" of the cache folder does not exist.`);\n }\n\n // The folder is valid\n return value;\n }\n\n default: {\n // this gives a type error if a new preference is added\n const exhaustiveCheck: never = key;\n throw new Error(`Unhandled user preference: \"${exhaustiveCheck}\"`);\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/config",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.2",
|
|
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/common-types": "^0.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.19.1",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.1.7",
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^
|
|
20
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^10.0.1",
|
|
20
|
+
"@ms-cloudpack/path-utilities": "^2.7.38",
|
|
21
21
|
"import-meta-resolve": "^4.0.0",
|
|
22
22
|
"semver": "^7.6.0"
|
|
23
23
|
},
|