Get information on local packages, providing utilities for package detection, metadata retrieval, module resolution, and cross-environment imports.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Retrieve comprehensive metadata and information about installed packages, including version details, file system paths, and complete package.json contents. Available in both asynchronous and synchronous variants.
Retrieve detailed information about a package asynchronously.
/**
* Get comprehensive information about a package (async)
* @param name - Package name to get information for
* @param options - Optional resolution configuration
* @returns Promise resolving to PackageInfo or undefined if package not found
*/
function getPackageInfo(name: string, options?: PackageResolvingOptions): Promise<PackageInfo | undefined>;Usage Examples:
import { getPackageInfo } from "local-pkg";
// Get basic package information
const info = await getPackageInfo("express");
if (info) {
console.log(info.name); // "express"
console.log(info.version); // "4.18.2"
console.log(info.rootPath); // "/path/to/node_modules/express"
console.log(info.packageJsonPath); // "/path/to/node_modules/express/package.json"
console.log(info.packageJson); // Full package.json object
}
// Handle non-existent packages
const missing = await getPackageInfo("nonexistent-package");
console.log(missing); // undefined
// Use custom search paths
const customInfo = await getPackageInfo("my-package", {
paths: ["/custom/node_modules"]
});Retrieve detailed information about a package synchronously.
/**
* Get comprehensive information about a package (sync)
* @param name - Package name to get information for
* @param options - Optional resolution configuration
* @returns PackageInfo or undefined if package not found
*/
function getPackageInfoSync(name: string, options?: PackageResolvingOptions): PackageInfo | undefined;Usage Examples:
import { getPackageInfoSync } from "local-pkg";
// Synchronous package information retrieval
const info = getPackageInfoSync("lodash");
if (info) {
console.log(`${info.name}@${info.version}`);
// Access full package.json data
console.log(info.packageJson.description);
console.log(info.packageJson.dependencies);
console.log(info.packageJson.main);
}interface PackageInfo {
/** Package name as specified in package.json */
name: string;
/** Root directory path of the package */
rootPath: string;
/** Full path to the package.json file */
packageJsonPath: string;
/** Package version string */
version: string;
/** Complete parsed package.json object */
packageJson: PackageJson;
}The PackageInfo interface provides comprehensive access to package metadata:
Both functions return undefined when a package cannot be found or accessed, rather than throwing errors. This allows for graceful handling of missing packages:
import { getPackageInfo } from "local-pkg";
const info = await getPackageInfo("might-not-exist");
if (!info) {
console.log("Package not found or not accessible");
} else {
console.log(`Found ${info.name}@${info.version}`);
}