@rushstack/lockfile-explorer
Version:
Rush Lockfile Explorer: The UI for solving version conflicts quickly in a large monorepo
44 lines • 2.15 kB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as dependencyPathLockfilePreV9 from '@pnpm/dependency-path-lockfile-pre-v9';
export function convertLockfileV6DepPathToV5DepPath(newDepPath) {
if (!newDepPath.includes('@', 2) || newDepPath.startsWith('file:'))
return newDepPath;
const index = newDepPath.indexOf('@', newDepPath.indexOf('/@') + 2);
if (newDepPath.includes('(') && index > dependencyPathLockfilePreV9.indexOfPeersSuffix(newDepPath))
return newDepPath;
return `${newDepPath.substring(0, index)}/${newDepPath.substring(index + 1)}`;
}
export function parseDependencyPath(shrinkwrapFileMajorVersion, newDepPath) {
let dependencyPath = newDepPath;
if (shrinkwrapFileMajorVersion === 6) {
dependencyPath = convertLockfileV6DepPathToV5DepPath(newDepPath);
}
const packageInfo = dependencyPathLockfilePreV9.parse(dependencyPath);
return {
name: packageInfo.name,
peersSuffix: packageInfo.peersSuffix,
version: packageInfo.version
};
}
export function getShrinkwrapFileMajorVersion(lockfileVersion) {
let shrinkwrapFileMajorVersion;
if (typeof lockfileVersion === 'string') {
const isDotIncluded = lockfileVersion.includes('.');
shrinkwrapFileMajorVersion = parseInt(lockfileVersion.substring(0, isDotIncluded ? lockfileVersion.indexOf('.') : undefined), 10);
}
else if (typeof lockfileVersion === 'number') {
shrinkwrapFileMajorVersion = Math.floor(lockfileVersion);
}
else {
shrinkwrapFileMajorVersion = 0;
}
if (shrinkwrapFileMajorVersion < 5 || shrinkwrapFileMajorVersion > 6) {
throw new Error('The current lockfile version is not supported.');
}
return shrinkwrapFileMajorVersion;
}
export function splicePackageWithVersion(shrinkwrapFileMajorVersion, dependencyPackageName, dependencyPackageVersion) {
return `/${dependencyPackageName}${shrinkwrapFileMajorVersion === 6 ? '@' : '/'}${dependencyPackageVersion}`;
}
//# sourceMappingURL=shrinkwrap.js.map