Socket
Socket
Sign inDemoInstall

@pnpm/dependency-path

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnpm/dependency-path - npm Package Compare versions

Comparing version 2.1.8 to 3.0.0

36

lib/index.d.ts
import { type Registries } from '@pnpm/types';
export declare function isAbsolute(dependencyPath: string): boolean;
export declare function resolve(registries: Registries, resolutionLocation: string): string;
export declare function indexOfPeersSuffix(depPath: string): number;
export declare function tryGetPackageId(registries: Registries, relDepPath: string): string | null;
export declare function refToAbsolute(reference: string, pkgName: string, registries: Registries): string | null;
export interface ParsedDepPath {
id: string;
peersSuffix: string;
}
export declare function parseDepPath(relDepPath: string): ParsedDepPath;
export declare function removePeersSuffix(relDepPath: string): string;
export declare function tryGetPackageId(relDepPath: string): string;
export declare function getRegistryByPackageName(registries: Registries, packageName: string): string;
export declare function relative(registries: Registries, packageName: string, absoluteResolutionLoc: string): string;
export declare function refToRelative(reference: string, pkgName: string): string | null;
export declare function parse(dependencyPath: string): {
host: string | undefined;
isAbsolute: boolean;
name?: undefined;
peersSuffix?: undefined;
version?: undefined;
} | {
host: string | undefined;
isAbsolute: boolean;
name: string | undefined;
peersSuffix: string | undefined;
version: string;
};
export interface DependencyPath {
name?: string;
peersSuffix?: string;
version?: string;
nonSemverVersion?: string;
}
export declare function parse(dependencyPath: string): DependencyPath;
export declare function depPathToFilename(depPath: string): string;
export declare function createPeersFolderSuffix(peers: Array<{
export type PeerId = {
name: string;
version: string;
}>): string;
} | string;
export declare function createPeersDirSuffix(peerIds: PeerId[]): string;

@@ -6,5 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createPeersFolderSuffix = exports.depPathToFilename = exports.parse = exports.refToRelative = exports.relative = exports.getRegistryByPackageName = exports.refToAbsolute = exports.tryGetPackageId = exports.indexOfPeersSuffix = exports.resolve = exports.isAbsolute = void 0;
exports.createPeersDirSuffix = exports.depPathToFilename = exports.parse = exports.refToRelative = exports.getRegistryByPackageName = exports.tryGetPackageId = exports.removePeersSuffix = exports.parseDepPath = exports.indexOfPeersSuffix = exports.isAbsolute = void 0;
const crypto_base32_hash_1 = require("@pnpm/crypto.base32-hash");
const encode_registry_1 = __importDefault(require("encode-registry"));
const semver_1 = __importDefault(require("semver"));

@@ -15,19 +14,2 @@ function isAbsolute(dependencyPath) {

exports.isAbsolute = isAbsolute;
function resolve(registries, resolutionLocation) {
if (!isAbsolute(resolutionLocation)) {
let registryUrl;
if (resolutionLocation[1] === '@') {
const slashIndex = resolutionLocation.indexOf('/', 1);
const scope = resolutionLocation.slice(1, slashIndex !== -1 ? slashIndex : 0);
registryUrl = registries[scope] || registries.default;
}
else {
registryUrl = registries.default;
}
const registryDirectory = (0, encode_registry_1.default)(registryUrl);
return `${registryDirectory}${resolutionLocation}`;
}
return resolutionLocation;
}
exports.resolve = resolve;
function indexOfPeersSuffix(depPath) {

@@ -51,31 +33,35 @@ if (!depPath.endsWith(')'))

exports.indexOfPeersSuffix = indexOfPeersSuffix;
function tryGetPackageId(registries, relDepPath) {
if (relDepPath[0] !== '/') {
return null;
function parseDepPath(relDepPath) {
const sepIndex = indexOfPeersSuffix(relDepPath);
if (sepIndex !== -1) {
return {
id: relDepPath.substring(0, sepIndex),
peersSuffix: relDepPath.substring(sepIndex),
};
}
return {
id: relDepPath,
peersSuffix: '',
};
}
exports.parseDepPath = parseDepPath;
function removePeersSuffix(relDepPath) {
const sepIndex = indexOfPeersSuffix(relDepPath);
if (sepIndex !== -1) {
return resolve(registries, relDepPath.substring(0, sepIndex));
return relDepPath.substring(0, sepIndex);
}
const underscoreIndex = relDepPath.indexOf('_', relDepPath.lastIndexOf('/'));
if (underscoreIndex !== -1) {
return resolve(registries, relDepPath.slice(0, underscoreIndex));
}
return resolve(registries, relDepPath);
return relDepPath;
}
exports.tryGetPackageId = tryGetPackageId;
function refToAbsolute(reference, pkgName, registries) {
if (reference.startsWith('link:')) {
return null;
exports.removePeersSuffix = removePeersSuffix;
function tryGetPackageId(relDepPath) {
const sepIndex = indexOfPeersSuffix(relDepPath);
if (sepIndex !== -1) {
relDepPath = relDepPath.substring(0, sepIndex);
}
if (!reference.includes('/') || reference.includes('(') && reference.lastIndexOf('/', reference.indexOf('(')) === -1) {
const registryName = (0, encode_registry_1.default)(getRegistryByPackageName(registries, pkgName));
return `${registryName}/${pkgName}/${reference}`;
if (relDepPath.includes(':')) {
relDepPath = relDepPath.substring(relDepPath.indexOf('@', 1) + 1);
}
if (reference[0] !== '/')
return reference;
const registryName = (0, encode_registry_1.default)(getRegistryByPackageName(registries, pkgName));
return `${registryName}${reference}`;
return relDepPath;
}
exports.refToAbsolute = refToAbsolute;
exports.tryGetPackageId = tryGetPackageId;
function getRegistryByPackageName(registries, packageName) {

@@ -88,10 +74,2 @@ if (packageName[0] !== '@')

exports.getRegistryByPackageName = getRegistryByPackageName;
function relative(registries, packageName, absoluteResolutionLoc) {
const registryName = (0, encode_registry_1.default)(getRegistryByPackageName(registries, packageName));
if (absoluteResolutionLoc.startsWith(`${registryName}/`)) {
return absoluteResolutionLoc.slice(absoluteResolutionLoc.indexOf('/'));
}
return absoluteResolutionLoc;
}
exports.relative = relative;
function refToRelative(reference, pkgName) {

@@ -101,9 +79,12 @@ if (reference.startsWith('link:')) {

}
if (reference.startsWith('file:')) {
if (reference.startsWith('@'))
return reference;
}
if (!reference.includes('/') || reference.includes('(') && reference.lastIndexOf('/', reference.indexOf('(')) === -1) {
return `/${pkgName}/${reference}`;
}
return reference;
const atIndex = reference.indexOf('@');
if (atIndex === -1)
return `${pkgName}@${reference}`;
const colonIndex = reference.indexOf(':');
const bracketIndex = reference.indexOf('(');
if ((colonIndex === -1 || atIndex < colonIndex) && (bracketIndex === -1 || atIndex < bracketIndex))
return reference;
return `${pkgName}@${reference}`;
}

@@ -118,16 +99,8 @@ exports.refToRelative = refToRelative;

}
const _isAbsolute = isAbsolute(dependencyPath);
const parts = dependencyPath.split('/');
if (!_isAbsolute)
parts.shift();
const host = _isAbsolute ? parts.shift() : undefined;
if (parts.length === 0)
return {
host,
isAbsolute: _isAbsolute,
};
const name = parts[0][0] === '@'
? `${parts.shift()}/${parts.shift()}`
: parts.shift();
let version = parts.join('/');
const sepIndex = dependencyPath.indexOf('@', 1);
if (sepIndex === -1) {
return {};
}
const name = dependencyPath.substring(0, sepIndex);
let version = dependencyPath.substring(sepIndex + 1);
if (version) {

@@ -143,13 +116,4 @@ let peerSepIndex;

}
else {
peerSepIndex = version.indexOf('_');
if (peerSepIndex !== -1) {
peersSuffix = version.substring(peerSepIndex + 1);
version = version.substring(0, peerSepIndex);
}
}
if (semver_1.default.valid(version)) {
return {
host,
isAbsolute: _isAbsolute,
name,

@@ -160,9 +124,9 @@ peersSuffix,

}
return {
name,
nonSemverVersion: version,
peersSuffix,
};
}
if (!_isAbsolute)
throw new Error(`${dependencyPath} is an invalid relative dependency path`);
return {
host,
isAbsolute: _isAbsolute,
};
return {};
}

@@ -189,15 +153,22 @@ exports.parse = parse;

}
const index = depPath.lastIndexOf('/', depPath.includes('(') ? depPath.indexOf('(') - 1 : depPath.length);
const name = depPath.substring(0, index);
if (!name)
const index = depPath.indexOf('@', 1);
if (index === -1)
return depPath;
return `${name}@${depPath.slice(index + 1)}`;
return `${depPath.substring(0, index)}@${depPath.slice(index + 1)}`;
}
return depPath.replace(':', '+');
}
function createPeersFolderSuffix(peers) {
const folderName = peers.map(({ name, version }) => `${name}@${version}`).sort().join(')(');
return `(${folderName})`;
function createPeersDirSuffix(peerIds) {
const dirName = peerIds.map((peerId) => {
if (typeof peerId !== 'string') {
return `${peerId.name}@${peerId.version}`;
}
if (peerId.startsWith('/')) {
return peerId.substring(1);
}
return peerId;
}).sort().join(')(');
return `(${dirName})`;
}
exports.createPeersFolderSuffix = createPeersFolderSuffix;
exports.createPeersDirSuffix = createPeersDirSuffix;
//# sourceMappingURL=index.js.map
{
"name": "@pnpm/dependency-path",
"version": "2.1.8",
"version": "3.0.0",
"description": "Utilities for working with symlinked node_modules",

@@ -13,3 +13,3 @@ "main": "lib/index.js",

"keywords": [
"pnpm8",
"pnpm9",
"node_modules",

@@ -20,3 +20,3 @@ "pnpm",

"engines": {
"node": ">=16.14"
"node": ">=18.12"
},

@@ -29,10 +29,9 @@ "license": "MIT",

"dependencies": {
"encode-registry": "^3.0.1",
"semver": "^7.5.4",
"@pnpm/types": "9.4.2",
"@pnpm/crypto.base32-hash": "2.0.0"
"semver": "^7.6.0",
"@pnpm/crypto.base32-hash": "3.0.0",
"@pnpm/types": "10.0.0"
},
"devDependencies": {
"@types/semver": "7.5.3",
"@pnpm/dependency-path": "2.1.8"
"@pnpm/dependency-path": "3.0.0"
},

@@ -39,0 +38,0 @@ "funding": "https://opencollective.com/pnpm",

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