CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sveltejs--adapter-auto

SvelteKit adapter that automatically detects deployment environment and installs appropriate platform-specific adapter

Overall
score

96%

Overview
Eval results
Files

task.mdevals/scenario-2/

Package Manager Detector

Build a utility that detects which package manager is being used in a Node.js project by scanning for lockfiles in the directory hierarchy.

Requirements

Create a function that traverses up the directory tree from a given starting path to identify which package manager is being used based on the presence of specific lockfiles. The function should check directories from the starting path up to the filesystem root.

Detection Priority

When multiple lockfiles are found at the same directory level, use this priority order:

  1. pnpm-lock.yaml indicates pnpm
  2. yarn.lock indicates yarn
  3. package-lock.json indicates npm
  4. bun.lockb or bun.lock indicates bun
  5. deno.lock indicates deno

If no lockfile is found after traversing to the root, default to npm.

Behavior

  • Start from the provided directory path and check each directory level
  • Continue traversing parent directories until a lockfile is found or root is reached
  • Return the package manager name as a string: 'pnpm', 'yarn', 'npm', 'bun', or 'deno'
  • Handle both absolute and relative paths
  • Gracefully handle invalid or non-existent paths

Test Cases

  • Given a directory containing only pnpm-lock.yaml, the function returns 'pnpm' @test
  • Given a directory containing only yarn.lock, the function returns 'yarn' @test
  • Given a directory containing only package-lock.json, the function returns 'npm' @test
  • Given a nested subdirectory where a parent contains pnpm-lock.yaml, the function returns 'pnpm' @test
  • Given a directory with no lockfiles up to root, the function returns 'npm' @test

Implementation

@generates

API

/**
 * Detects which package manager is being used by scanning for lockfiles
 * in the directory hierarchy.
 *
 * @param {string} startPath - The directory path to start searching from
 * @returns {string} The detected package manager name ('pnpm', 'yarn', 'npm', 'bun', or 'deno')
 */
export function detectPackageManager(startPath) {
  // IMPLEMENTATION HERE
}

Dependencies { .dependencies }

Node.js fs module { .dependency }

Provides file system operations for checking lockfile existence and directory traversal.

Install with Tessl CLI

npx tessl i tessl/npm-sveltejs--adapter-auto

tile.json