Socket
Socket
Sign inDemoInstall

@ms-cloudpack/package-utilities

Package Overview
Dependencies
Maintainers
0
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/package-utilities - npm Package Compare versions

Comparing version 7.6.0 to 7.6.1

2

lib/createResolveMap/createResolveMap.js

@@ -27,3 +27,3 @@ import { findProjectRoot } from '../findProjectRoot.js';

for (const linkedPath of linkedPaths) {
await linkPath({ linkedPath, appMap, repoDefinition }, context);
await linkPath({ rootPath, linkedPath, appMap, repoDefinition }, context);
}

@@ -30,0 +30,0 @@ // Finally we condense into a resolve map.

import type { PackageMap } from '../types/PackageMap.js';
import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
/**

@@ -6,6 +7,9 @@ * Deduplicates linked packages by removing all but the highest version,

*/
export declare function dedupeLinkedPackages({ appMap, allDuplicates }: {
export declare function dedupeLinkedPackages(options: {
appMap: PackageMap;
allDuplicates: Set<string>;
}): void;
rootPath?: string;
}, context: {
packages: PackageDefinitionsCache;
}): Promise<void>;
//# sourceMappingURL=dedupeLinkedPackages.d.ts.map
import { satisfies, compare as semverCompare } from 'semver';
import { parseRequiredBy } from './parseRequiredBy.js';
import { detachEntry } from './detachEntry.js';
import { slash } from '@ms-cloudpack/path-string-parsing';
/**

@@ -8,3 +9,5 @@ * Deduplicates linked packages by removing all but the highest version,

*/
export function dedupeLinkedPackages({ appMap, allDuplicates }) {
export async function dedupeLinkedPackages(options, context) {
const { rootPath, appMap, allDuplicates } = options;
const { packages } = context;
console.debug(`The following packages were duplicated by linking:\n ${Array.from(allDuplicates).join(', ')}`);

@@ -18,2 +21,9 @@ for (const duplicate of allDuplicates) {

}
let dedupeStrategy = 'allow-duplication';
for (const entry of Object.values(entries)) {
const packageJson = await packages.get(entry.path);
if (packageJson?.cloudpack?.link?.duplicatedDependencyBehavior) {
dedupeStrategy = packageJson.cloudpack.link.duplicatedDependencyBehavior;
}
}
const availableVersions = Object.keys(entries);

@@ -35,12 +45,34 @@ const versionRequirements = new Set();

.sort(semverCompare);
if (satisfiedVersions.length === 0) {
let satisfiedVersion;
if (dedupeStrategy === 'force-host-version') {
if (!rootPath) {
console.error('Root path for project not found and is required when using the "force-host-version" dedupe strategy.');
continue;
}
// Use the app host's version of the package.
// Find the version of the package that belongs to the host.
// We assume that the host has a single version of the package.
const hostVersion = availableVersions.find((v) => slash(entries[v].path).startsWith(slash(rootPath)));
if (!hostVersion) {
console.error(`Could not find a version of "${packageName}" that is belongs to the host.`);
continue;
}
satisfiedVersion = hostVersion;
}
else if (dedupeStrategy === 'allow-duplication' && satisfiedVersions.length > 0) {
// Select the highest version that satisfies the semver requirements of all the requiredBy entries.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
satisfiedVersion = satisfiedVersions.pop();
console.debug(`Version "${satisfiedVersion}" of "${packageName}" satisfies the semver requirements of all the requiredBy entries.`);
}
else {
// If the deduplication strategy allows duplicates and
// no version satisfies the semver requirements for all dependents,
// then deduplication of this package is not possible.
console.debug(`Could not find a version of "${packageName}" that satisfies the semver requirements of all the requiredBy entries.`);
continue;
}
// Select the highest version that satisfies the semver requirements of all the requiredBy entries.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const highestSatisfiedVersion = satisfiedVersions.pop();
entries[highestSatisfiedVersion].requiredBy = requiredBy;
entries[satisfiedVersion].requiredBy = requiredBy;
for (const version of availableVersions) {
if (version == highestSatisfiedVersion) {
if (version == satisfiedVersion) {
continue;

@@ -53,7 +85,7 @@ }

const { name: requiredByName, version: requiredByVersion } = parseRequiredBy(requiredById);
appMap[requiredByName][requiredByVersion].dependencies[packageName] = highestSatisfiedVersion;
appMap[requiredByName][requiredByVersion].dependencies[packageName] = satisfiedVersion;
}
console.debug(`Removed versions of "${packageName}" except for "${highestSatisfiedVersion}".`);
console.debug(`Removed versions of "${packageName}" except for "${satisfiedVersion}".`);
}
}
//# sourceMappingURL=dedupeLinkedPackages.js.map

@@ -10,2 +10,3 @@ import type { LinkedPath } from '../types/LinkedPath.js';

appMap: PackageMap;
rootPath?: string;
repoDefinition?: PackageJson;

@@ -12,0 +13,0 @@ }, context: {

@@ -11,3 +11,3 @@ import { addLinkedEntryDependencies } from './addLinkedEntryDependencies.js';

export async function linkPath(options, context) {
const { linkedPath, appMap, repoDefinition } = options;
const { linkedPath, appMap, rootPath, repoDefinition } = options;
const linkMap = await findPackagesFromPath({

@@ -86,3 +86,3 @@ searchPaths: [linkedPath.path],

if (linkedPath.resolveStrategy !== 'duplicate') {
dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates) });
await dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates), rootPath }, context);
}

@@ -89,0 +89,0 @@ }

{
"name": "@ms-cloudpack/package-utilities",
"version": "7.6.0",
"version": "7.6.1",
"description": "Utilities for resolving/parsing packages and their imports.",

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

"dependencies": {
"@ms-cloudpack/common-types": "^0.8.0",
"@ms-cloudpack/common-types": "^0.8.1",
"@ms-cloudpack/json-utilities": "^0.1.4",
"@ms-cloudpack/package-overrides": "^0.9.3",
"@ms-cloudpack/package-overrides": "^0.9.4",
"@ms-cloudpack/path-string-parsing": "^1.2.3",
"@ms-cloudpack/path-utilities": "^2.7.18",
"@ms-cloudpack/path-utilities": "^2.7.19",
"@ms-cloudpack/task-reporter": "^0.14.1",

@@ -24,0 +24,0 @@ "acorn": "^8.11.2",

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