Resolves optimal pnpm store path locations based on filesystem capabilities and project structure
npx @tessl/cli install tessl/npm-pnpm--store-path@1000.0.0@pnpm/store-path provides intelligent store path resolution for pnpm package manager installations. It determines the optimal location for the pnpm store directory based on filesystem capabilities, project location, and system permissions, ensuring maximum performance through hard linking when possible.
npm install @pnpm/store-pathimport { getStorePath } from "@pnpm/store-path";For CommonJS:
const { getStorePath } = require("@pnpm/store-path");import { getStorePath } from "@pnpm/store-path";
// Resolve store path with explicit location
const storePath = getStorePath({
pkgRoot: "/home/user/my-project",
storePath: "/custom/pnpm-store",
pnpmHomeDir: "/home/user/.local/share/pnpm"
});
// Returns: "/custom/pnpm-store/v10"
// Resolve optimal store path based on filesystem capabilities
const optimalPath = await getStorePath({
pkgRoot: "/home/user/my-project",
pnpmHomeDir: "/home/user/.local/share/pnpm"
});
// Returns: Promise<string> - optimal location based on hard linking supportThe store path resolution follows a three-tier strategy:
storePath is provided, use it directly (appending store version if needed)~/, resolve relative to user home directory.pnpm-store prefix if linking only works locallyIntelligently resolves the optimal pnpm store path location based on filesystem capabilities and configuration options.
/**
* Resolves the optimal pnpm store path based on filesystem capabilities
* @param options - Configuration options for store path resolution
* @returns Store path string (sync) or Promise<string> (async when optimization needed)
* @throws PnpmError with code 'NO_PNPM_HOME_DIR' when pnpmHomeDir is undefined and storePath not provided
*/
function getStorePath(options: GetStorePathOptions): string | Promise<string>;
interface GetStorePathOptions {
/** Root directory of the package/project */
pkgRoot: string;
/**
* Optional explicit store path - can be absolute or home-relative (~/path)
* When provided, skips filesystem optimization and uses this path directly
*/
storePath?: string;
/**
* Pnpm home directory for fallback store location
* Required when storePath is not provided
*/
pnpmHomeDir: string;
}Usage Examples:
import { getStorePath } from "@pnpm/store-path";
// Explicit absolute store path
const explicitPath = getStorePath({
pkgRoot: "/home/user/project",
storePath: "/var/cache/pnpm",
pnpmHomeDir: "/home/user/.local/share/pnpm"
});
// Returns: "/var/cache/pnpm/v10" (synchronous)
// Home-relative store path
const homePath = getStorePath({
pkgRoot: "/home/user/project",
storePath: "~/custom-store",
pnpmHomeDir: "/home/user/.local/share/pnpm"
});
// Returns: "/home/user/custom-store/v10" (synchronous)
// Optimized store path (filesystem linking detection)
const optimizedPath = await getStorePath({
pkgRoot: "/mnt/external/project",
pnpmHomeDir: "/home/user/.local/share/pnpm"
});
// Returns: Promise<string> - optimal location after testing hard linking capabilities
// Error handling
try {
getStorePath({
pkgRoot: "/some/project",
pnpmHomeDir: undefined // This will throw an error
});
} catch (error) {
console.log(error.code); // 'NO_PNPM_HOME_DIR'
}The package throws PnpmError instances from the @pnpm/error package:
// Error thrown when pnpmHomeDir is not provided and storePath is undefined
interface PnpmError extends Error {
code: 'NO_PNPM_HOME_DIR';
message: 'The pnpm home directory is unknown. Cannot calculate the store directory location.';
}The package uses the STORE_VERSION constant from @pnpm/constants, which is currently "v10". This version is automatically appended to store paths to maintain compatibility across pnpm versions.
~/) and Windows (~\\) home directory notation