Socket
Socket
Sign inDemoInstall

@ms-cloudpack/config

Package Overview
Dependencies
Maintainers
0
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/config - npm Package Compare versions

Comparing version 0.26.3 to 0.27.0

lib/getGeneratedPackageSettings.d.ts

7

lib/checkMatch.js

@@ -7,5 +7,2 @@ import { satisfies } from 'semver';

const { name, version, match, exactMatch } = params;
if (!match) {
return true;
}
let matchName;

@@ -17,5 +14,5 @@ let matchVersion;

else {
matchName = match?.name;
matchName = match.name;
// If any version is allowed, unset the version to skip the satisfies() check for efficiency.
matchVersion = match?.version === '*' ? undefined : match?.version;
matchVersion = match.version === '*' ? undefined : match.version;
}

@@ -22,0 +19,0 @@ // For exact or non-wildcard matches, check the full name and possibly the version.

@@ -1,3 +0,6 @@

import type { PackageSettings } from '@ms-cloudpack/common-types';
export declare function compareSettings(a: PackageSettings, b: PackageSettings): number;
import type { GeneratedPackageSettings } from '@ms-cloudpack/common-types';
/**
* Compare generated package settings for array sorting.
*/
export declare function compareSettings(a: GeneratedPackageSettings, b: GeneratedPackageSettings): number;
//# sourceMappingURL=compareSettings.d.ts.map

@@ -0,1 +1,4 @@

/**
* Compare generated package settings for array sorting.
*/
export function compareSettings(a, b) {

@@ -6,32 +9,10 @@ // TypeScript's type narrowing doesn't work well with object properties,

const bMatch = b.match;
// Check if the match is a string.
// Place string matches at the beginning of the list.
const isAString = typeof aMatch === 'string';
const isBString = typeof bMatch === 'string';
// Handle empty matches.
if (!aMatch) {
if (!bMatch) {
return 0;
}
return -1;
if (isAString || isBString) {
return isAString ? (isBString ? aMatch.localeCompare(bMatch) : -1) : 1;
}
if (!bMatch) {
return 1;
}
// Place string matches at the beginning of the list.
if (isAString && isBString) {
return aMatch.localeCompare(bMatch);
}
else if (isAString) {
return -1;
}
else if (isBString) {
return 1;
}
const { name: aName = '', version: aVersion = '*' } = aMatch;
const { name: bName = '', version: bVersion = '*' } = bMatch;
if (aName === bName) {
return aVersion.localeCompare(bVersion);
}
return aName.localeCompare(bName);
return aMatch.name.localeCompare(bMatch.name) || aMatch.version.localeCompare(bMatch.version);
}
//# sourceMappingURL=compareSettings.js.map

@@ -1,2 +0,2 @@

import { type CloudpackConfig, type PackageDefinitionTransform } from '@ms-cloudpack/common-types';
import type { CloudpackConfig, PackageDefinitionTransform } from '@ms-cloudpack/common-types';
/**

@@ -3,0 +3,0 @@ * Creates a transform to be registered with a PackageDefinitions registry for updating package.json

@@ -84,2 +84,3 @@ import { getPackageSettings } from './getPackageSettings.js';

const { appPath } = context.config;
// TODO: an array of export objects is not really valid per the spec and most implementations
const exports = [];

@@ -86,0 +87,0 @@ // If this is the app package, ensure the routes are part of the exports map.

@@ -1,2 +0,2 @@

import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports, PackageSettings } from '@ms-cloudpack/common-types';
import type { CloudpackConfig, PackageDefinitionsCache, GeneratedPackageSettings, PackageJsonExports } from '@ms-cloudpack/common-types';
/**

@@ -14,3 +14,3 @@ * Ensures the generated package setting for the package provided exists.

packages: PackageDefinitionsCache;
}): Promise<PackageSettings>;
}): Promise<GeneratedPackageSettings>;
//# sourceMappingURL=ensureGeneratedSettingsForPackage.d.ts.map

@@ -1,3 +0,3 @@

import { getPackageSettings } from './getPackageSettings.js';
import { isExternalPackage } from '@ms-cloudpack/package-utilities';
import { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
/**

@@ -17,9 +17,6 @@ * Ensures the generated package setting for the package provided exists.

const { name, version } = definition;
const packageSettings = (config.generated.packageSettings ??= []);
let { generatedPackageSettings } = getPackageSettings({
userPackageSettings: undefined,
let generatedPackageSettings = getGeneratedPackageSettings({
generatedPackageSettings: config.generated.packageSettings,
name,
version,
firstMatch: true,
});

@@ -29,7 +26,6 @@ if (!generatedPackageSettings) {

match: isExternalPackage(packagePath) ? { name, version: `^${version}` } : name,
...(options.defaultExportsMap && { exports: options.defaultExportsMap }),
};
if (options.defaultExportsMap) {
generatedPackageSettings.exports = options.defaultExportsMap;
}
packageSettings.push(generatedPackageSettings);
config.generated.packageSettings ??= [];
config.generated.packageSettings.push(generatedPackageSettings);
}

@@ -36,0 +32,0 @@ return generatedPackageSettings;

@@ -1,4 +0,15 @@

import type { PackageSettings } from '@ms-cloudpack/common-types';
import type { PackageSettings, GeneratedPackageSettings } from '@ms-cloudpack/common-types';
/** Result of calling `getPackageSettings`. */
export interface GetPackageSettingsResult {
/** Merged user package settings, with `match` removed. */
userPackageSettings: Omit<PackageSettings, 'match'> | undefined;
/** Merged generated package settings, with `match` removed. */
generatedPackageSettings: Omit<GeneratedPackageSettings, 'match'> | undefined;
}
/**
* Gets the single set of package settings for a given package using the given config.
* Gets the user and generated package settings which apply to this package name and version,
* with the settings from each source merged together.
*
* NOTE: If you're calling from init-related code and would like to modify the result to update
* the generated config, use `getGeneratedPackageSettings` instead.
*/

@@ -8,13 +19,7 @@ export declare function getPackageSettings(params: {

version: string;
/** User package settings from the config */
userPackageSettings: PackageSettings[] | undefined;
generatedPackageSettings: PackageSettings[] | undefined;
/**
* If true, only the first matching package settings will be returned, rather than the merge of all viable settings.
* This is useful in the `init` case, where we want to attach new settings to the first matching entry.
*/
firstMatch?: boolean;
}): {
userPackageSettings: PackageSettings | undefined;
generatedPackageSettings: PackageSettings | undefined;
};
/** Generated package settings from the config */
generatedPackageSettings: GeneratedPackageSettings[] | undefined;
}): GetPackageSettingsResult;
//# sourceMappingURL=getPackageSettings.d.ts.map
import { mergePackageSettings } from './mergePackageSettings.js';
import { checkMatch } from './checkMatch.js';
/**
* Gets the single set of package settings for a given package using the given config.
* Gets the user and generated package settings which apply to this package name and version,
* with the settings from each source merged together.
*
* NOTE: If you're calling from init-related code and would like to modify the result to update
* the generated config, use `getGeneratedPackageSettings` instead.
*/
export function getPackageSettings(params) {
const { userPackageSettings, generatedPackageSettings } = params;
const { name, version, userPackageSettings, generatedPackageSettings } = params;
const matchingUserSettings = userPackageSettings?.filter(({ match }) => checkMatch({ name, version, match }));
// For generated settings, restrict to exact matches since the name won't have wildcards
const matchingGeneratedSettings = generatedPackageSettings?.filter(({ match }) => checkMatch({ name, version, match, exactMatch: true }));
return {
userPackageSettings: filterSettings({ ...params, packageSettings: userPackageSettings }),
generatedPackageSettings: filterSettings({
...params,
packageSettings: generatedPackageSettings,
}),
userPackageSettings: matchingUserSettings?.length ? mergePackageSettings(matchingUserSettings) : undefined,
generatedPackageSettings: matchingGeneratedSettings?.length
? mergePackageSettings(matchingGeneratedSettings)
: undefined,
};
}
/**
* Get the package settings for a given package name and version.
*/
function filterSettings(params) {
const { name, version, packageSettings, firstMatch } = params;
if (firstMatch) {
return packageSettings?.find(({ match }) => checkMatch({ name, version, match, exactMatch: firstMatch }));
}
const filteredSettings = packageSettings?.filter(({ match }) => checkMatch({ name, version, match }));
return filteredSettings?.length ? mergePackageSettings(filteredSettings) : undefined;
}
//# sourceMappingURL=getPackageSettings.js.map

@@ -7,2 +7,3 @@ export { checkMatch } from './checkMatch.js';

export { getPackageSettings } from './getPackageSettings.js';
export { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
export { readConfig } from './readConfig.js';

@@ -9,0 +10,0 @@ export { readGeneratedConfig } from './readGeneratedConfig.js';

@@ -7,2 +7,3 @@ export { checkMatch } from './checkMatch.js';

export { getPackageSettings } from './getPackageSettings.js';
export { getGeneratedPackageSettings } from './getGeneratedPackageSettings.js';
export { readConfig } from './readConfig.js';

@@ -9,0 +10,0 @@ export { readGeneratedConfig } from './readGeneratedConfig.js';

@@ -1,2 +0,2 @@

import type { PackageSettings } from '@ms-cloudpack/common-types';
import type { GeneratedPackageSettings, PackageSettings } from '@ms-cloudpack/common-types';
/**

@@ -10,3 +10,3 @@ * Merges package settings together.

*/
export declare function mergePackageSettings(settings: PackageSettings[]): PackageSettings;
export declare function mergePackageSettings<TSettings extends Partial<PackageSettings | GeneratedPackageSettings>>(settings: TSettings[]): Omit<TSettings, 'match'>;
//# sourceMappingURL=mergePackageSettings.d.ts.map

@@ -12,2 +12,4 @@ import { mergeObjects, mergeArrayDefaults } from '@ms-cloudpack/package-utilities';

export function mergePackageSettings(settings) {
// Use PackageSettings as the type while merging so that the key-based typings work
// (if the key is not present in generated settings, it does nothing)
const result = mergeObjects(settings, {

@@ -14,0 +16,0 @@ // match is deleted after merging, so it is best to overwrite it to avoid merging conflicts.

@@ -5,2 +5,3 @@ import { readJson } from '@ms-cloudpack/json-utilities';

import { resolveParentConfig } from './resolveParentConfig.js';
import { resolveModule } from './resolveModule.js';
/**

@@ -17,2 +18,11 @@ * Reads the user config file and merges with any parent configs asynchronously.

}
function tryResolveBundlerCapability(importSpecifier, parentUrl) {
try {
return resolveModule({ parentUrl, importSpecifier });
}
catch (e) {
console.warn(`Error resolving bundler capability "${importSpecifier}", Error:`, e);
return undefined;
}
}
/**

@@ -27,2 +37,31 @@ * Reads the user config, with any `extends` parent configs merged in.

}
// Resolve import specifiers for bundler capabilities registry
if (AppConfig.bundlerCapabilitiesRegistry) {
for (const [key, value] of Object.entries(AppConfig.bundlerCapabilitiesRegistry)) {
const moduleUrl = tryResolveBundlerCapability(value, configPath);
if (moduleUrl) {
AppConfig.bundlerCapabilitiesRegistry[key] = moduleUrl;
}
}
}
// PackageSettings's bundlerCapabilities may contain short-hand keys that need to be resolved to full import specifiers before bundler capabilities can be processed
// This is done by looking up the short-hand keys in the bundlerCapabilitiesRegistry
// If the short-hand key is not found in the registry, it is assumed to be a full import specifier
if (AppConfig.packageSettings && AppConfig.bundlerCapabilitiesRegistry) {
for (const setting of AppConfig.packageSettings) {
if (setting.bundlerCapabilities) {
const newBundlerCapabilities = {};
for (const key in setting.bundlerCapabilities) {
if (key in AppConfig.bundlerCapabilitiesRegistry) {
const newKey = AppConfig.bundlerCapabilitiesRegistry[key];
newBundlerCapabilities[newKey] = setting.bundlerCapabilities[key];
}
else {
newBundlerCapabilities[key] = setting.bundlerCapabilities[key];
}
}
setting.bundlerCapabilities = newBundlerCapabilities;
}
}
}
const extendsArray = AppConfig.extends

@@ -29,0 +68,0 @@ ? Array.isArray(AppConfig.extends)

import type { GeneratedConfig } from '@ms-cloudpack/common-types';
/**
* Reads the generated config file asynchronously. This is only useful for the `init` verb generating or updated
* the generated overrides. For a full merged representation of config, use `readConfig` instead.
* the generated settings. For a full merged representation of config, use `readConfig` instead.
*

@@ -6,0 +6,0 @@ * Throws an error if the config file exists but is not valid JSON (or there's some error reading it).

@@ -5,3 +5,3 @@ import { readJson } from '@ms-cloudpack/json-utilities';

* Reads the generated config file asynchronously. This is only useful for the `init` verb generating or updated
* the generated overrides. For a full merged representation of config, use `readConfig` instead.
* the generated settings. For a full merged representation of config, use `readConfig` instead.
*

@@ -8,0 +8,0 @@ * Throws an error if the config file exists but is not valid JSON (or there's some error reading it).

@@ -1,6 +0,2 @@

import { moduleResolve } from 'import-meta-resolve';
import { fileURLToPath, pathToFileURL } from 'url';
// Conditions used for resolution if the package has an exports map.
// More could be added later if desired ("default" is implicitly included).
const conditions = new Set(['import', 'require', 'node']);
import { resolveModule } from './resolveModule.js';
/**

@@ -11,7 +7,5 @@ * Resolve an import specifier for a parent config file.

export function resolveParentConfig(params) {
const { importSpecifier, configPath } = params;
let resolvedConfigPath;
const { importSpecifier } = params;
try {
const resolvedUrl = moduleResolve(importSpecifier, pathToFileURL(configPath), conditions);
resolvedConfigPath = fileURLToPath(resolvedUrl);
return resolveModule({ importSpecifier, parentUrl: params.configPath });
}

@@ -21,4 +15,4 @@ catch (err) {

}
return resolvedConfigPath;
return undefined;
}
//# sourceMappingURL=resolveParentConfig.js.map

@@ -12,3 +12,3 @@ import { sortObjectKeys } from './sortObjectKeys.js';

}
// Ensure package overrides are sorted based on package name and version requirement.
// Ensure package settings are sorted based on package name and version requirement.
packageSettings.sort(compareSettings);

@@ -15,0 +15,0 @@ for (let i = 0; i < packageSettings.length; i++) {

@@ -19,2 +19,8 @@ import type { GeneratedConfig } from '@ms-cloudpack/common-types';

export declare function writeGeneratedConfig(config: GeneratedConfig, appPath: string): Promise<'written' | 'deleted' | 'no-op'>;
/**
* Due to optimization, some package settings may end up with a "match" key but nothing else.
* These would add useless bloat, so filter them out before writing the generated config.
* This function removes those settings by mutating the input generated config.
*/
export declare function cleanGeneratedConfig(config: GeneratedConfig): void;
//# sourceMappingURL=writeGeneratedConfig.d.ts.map
import { writeJson } from '@ms-cloudpack/json-utilities';
import fs from 'fs';
import { cleanGeneratedConfig } from './cleanGeneratedConfig.js';
import { getConfigPath } from './getConfigPath.js';

@@ -40,2 +39,10 @@ import { generatedAppConfigSchemaUrl } from './schemaUrls.js';

}
/**
* Due to optimization, some package settings may end up with a "match" key but nothing else.
* These would add useless bloat, so filter them out before writing the generated config.
* This function removes those settings by mutating the input generated config.
*/
export function cleanGeneratedConfig(config) {
config.packageSettings = config.packageSettings?.filter((s) => Object.keys(s).length > 1);
}
//# sourceMappingURL=writeGeneratedConfig.js.map
{
"name": "@ms-cloudpack/config",
"version": "0.26.3",
"version": "0.27.0",
"description": "Configuration handling for cloudpack.",

@@ -17,6 +17,6 @@ "license": "MIT",

"dependencies": {
"@ms-cloudpack/common-types": "^0.17.0",
"@ms-cloudpack/common-types": "^0.18.0",
"@ms-cloudpack/json-utilities": "^0.1.7",
"@ms-cloudpack/package-utilities": "^9.0.4",
"@ms-cloudpack/path-utilities": "^2.7.35",
"@ms-cloudpack/package-utilities": "^9.0.5",
"@ms-cloudpack/path-utilities": "^2.7.36",
"import-meta-resolve": "^4.0.0",

@@ -23,0 +23,0 @@ "semver": "^7.6.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc