What is @pnpm/dependency-path?
@pnpm/dependency-path is a utility package designed to handle and manipulate dependency paths in a consistent manner. It is particularly useful for package managers and tools that need to resolve and manage dependencies efficiently.
What are @pnpm/dependency-path's main functionalities?
Create Dependency Path
This feature allows you to create a dependency path given a root directory, package name, and version. It helps in standardizing the way dependency paths are generated.
const { createDependencyPath } = require('@pnpm/dependency-path');
const depPath = createDependencyPath('/root/project', 'lodash', '4.17.21');
console.log(depPath);
Parse Dependency Path
This feature parses a given dependency path and extracts useful information such as the package name and version. It is useful for analyzing and understanding the structure of dependency paths.
const { parseDependencyPath } = require('@pnpm/dependency-path');
const parsed = parseDependencyPath('/root/project/node_modules/lodash@4.17.21');
console.log(parsed);
Get Package Name from Path
This feature extracts the package name from a given dependency path. It simplifies the process of identifying packages from their paths.
const { getPackageNameFromPath } = require('@pnpm/dependency-path');
const packageName = getPackageNameFromPath('/root/project/node_modules/lodash@4.17.21');
console.log(packageName);
Other packages similar to @pnpm/dependency-path
resolve
The 'resolve' package is used to resolve module paths in Node.js. It provides similar functionality in terms of resolving paths but is more focused on module resolution rather than dependency path manipulation.
dependency-tree
The 'dependency-tree' package generates a dependency tree for a given module. While it provides insights into dependencies, it is more focused on visualizing and analyzing dependency trees rather than manipulating dependency paths.
read-pkg-up
The 'read-pkg-up' package reads the closest package.json file. It is useful for retrieving package information but does not offer the same level of path manipulation capabilities as @pnpm/dependency-path.
dependency-path
Utilities for working with symlinked node_modules
Like path
but for packages in a symlinked node_modules
. Symlinked node_modules
is a unique dependencies layout that
pnpm creates.
Installation
pnpm add dependency-path
Usage
const dependencyPath = require('dependency-path')
const registry = 'https://registry.npmjs.org/'
console.log(dependencyPath.isAbsolute('/foo/1.0.0'))
console.log(dependencyPath.resolve(registry, '/foo/1.0.0'))
console.log(dependencyPath.relative(registry, 'registry.npmjs.org/foo/1.0.0'))
console.log(dependencyPath.refToAbsolute('1.0.1', 'foo', registry))
console.log(dependencyPath.refToAbsolute('github.com/foo/bar/twe0jger043t0ew', 'foo', registry))
console.log(dependencyPath.refToRelative('1.0.1', 'foo', registry))
console.log(dependencyPath.parse('/foo/2.0.0'))
License
MIT