CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-local-pkg

Get information on local packages, providing utilities for package detection, metadata retrieval, module resolution, and cross-environment imports.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

package-information.mddocs/

Package Information

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.

Capabilities

Get Package Information (Async)

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"]
});

Get Package Information (Sync)

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);
}

Package Information Structure

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:

  • name: The package name exactly as specified in its package.json
  • rootPath: The file system path to the package's root directory
  • packageJsonPath: Full path to the package.json file itself
  • version: Current version string of the installed package
  • packageJson: The complete, parsed package.json object containing all metadata including dependencies, scripts, configuration, etc.

Error Handling

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}`);
}

docs

index.md

module-importing.md

package-detection.md

package-information.md

package-json-management.md

tile.json