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-detection.mddocs/

Package Detection

Core functionality for checking if packages exist and resolving their locations in the local environment, with support for different search paths and platform-specific behavior.

Capabilities

Package Existence Check

Check if a package exists in the local environment.

/**
 * Check if a package exists in the local environment
 * @param name - Package name to check
 * @param options - Optional resolution configuration
 * @returns true if package exists, false otherwise
 */
function isPackageExists(name: string, options?: PackageResolvingOptions): boolean;

Usage Examples:

import { isPackageExists } from "local-pkg";

// Check if package exists
console.log(isPackageExists("express")); // true
console.log(isPackageExists("nonexistent-package")); // false

// Check with custom search paths
const exists = isPackageExists("my-package", {
  paths: ["/custom/node_modules"]
});

// Platform-specific resolution
const existsWin32 = isPackageExists("some-package", {
  platform: "win32"
});

Module Resolution

Resolve the file path to a module, similar to require.resolve but works in both CJS and ESM environments.

/**
 * Resolve module path similar to require.resolve
 * @param name - Module name to resolve
 * @param options - Optional resolution configuration
 * @returns Resolved module path or undefined if not found
 */
function resolveModule(name: string, options?: PackageResolvingOptions): string | undefined;

Usage Examples:

import { resolveModule } from "local-pkg";

// Basic module resolution
const expressPath = resolveModule("express");
console.log(expressPath); // "/path/to/node_modules/express/index.js"

// Resolve specific file within package
const middlewarePath = resolveModule("express/lib/middleware/query");

// Custom search paths
const customPath = resolveModule("my-package", {
  paths: ["/custom/node_modules", "/another/path"]
});

// Platform-specific paths
const winPath = resolveModule("some-package", {
  platform: "win32"  // Forces Windows-style path normalization
});

Configuration Options

interface PackageResolvingOptions {
  /** Custom search paths for package resolution */
  paths?: string[];
  /** 
   * Platform for path resolution
   * @default 'auto' - automatically detects platform
   */
  platform?: 'posix' | 'win32' | 'auto';
}

The paths option allows you to specify custom directories to search for packages, useful when working with non-standard package locations or custom mono-repo setups.

The platform option controls path normalization:

  • 'auto' (default): Automatically detects the current platform
  • 'posix': Forces POSIX-style paths (forward slashes)
  • 'win32': Forces Windows-style paths with proper normalization

docs

index.md

module-importing.md

package-detection.md

package-information.md

package-json-management.md

tile.json