or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Workspace Package Selector

A utility tool that helps developers select and list packages in a pnpm workspace based on various filtering criteria.

Overview

Build a package selector utility that can filter and identify packages in a pnpm workspace monorepo. The tool should support filtering by package name patterns and dependency relationships.

Requirements

Input Processing

The utility should accept a workspace configuration and a set of filter criteria, then return the matching package names.

Filter Types

The selector must support the following filter patterns:

  1. Name-based filtering: Match packages by exact name or glob patterns (e.g., @scope/*)
  2. Dependency inclusion: Include all dependencies of matched packages
  3. Dependent inclusion: Include all packages that depend on matched packages
  4. Exclusion filters: Exclude specific packages from results

Expected Behavior

  • When multiple name filters are provided, packages matching ANY filter should be included (union)
  • Exclusion filters should be applied after inclusion filters
  • The tool should handle non-existent package names gracefully
  • Results should be returned as a sorted array of package names

Test Cases

Basic name filtering

  • Given a workspace with packages app, lib, utils, filtering by name app returns ["app"] @test
  • Given a workspace with packages @scope/pkg-a, @scope/pkg-b, other, filtering by glob pattern @scope/* returns ["@scope/pkg-a", "@scope/pkg-b"] @test

Dependency relationships

  • Given packages where app depends on lib and utils, filtering by app with dependency inclusion returns ["app", "lib", "utils"] @test
  • Given packages where app and service both depend on lib, filtering by lib with dependent inclusion returns ["app", "lib", "service"] @test

Exclusion filters

  • Given a workspace with packages app, lib, utils, filtering by * with exclusion of lib returns ["app", "utils"] @test

Implementation

@generates

API

/**
 * Represents a package in the workspace
 */
export interface WorkspacePackage {
  name: string;
  location: string;
  dependencies: string[];
}

/**
 * Filter criteria for package selection
 */
export interface FilterCriteria {
  /** Package name or glob pattern to include */
  includeNames?: string[];
  /** Include dependencies of matched packages */
  includeDependencies?: boolean;
  /** Include dependents of matched packages */
  includeDependents?: boolean;
  /** Package names to exclude */
  exclude?: string[];
}

/**
 * Selects packages from a workspace based on filter criteria
 *
 * @param workspace - Array of workspace packages
 * @param filter - Filter criteria to apply
 * @returns Sorted array of matching package names
 */
export function selectPackages(
  workspace: WorkspacePackage[],
  filter: FilterCriteria
): string[];

Dependencies { .dependencies }

pnpm { .dependency }

Provides package management capabilities for understanding workspace filtering patterns and behavior.