npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bernierllc/workspace-manager

v0.3.0

Published

Pure workspace management utilities for monorepo package discovery and configuration

Readme

@bernierllc/workspace-manager

Pure workspace management utilities for monorepo package discovery and configuration.

Features

  • Workspace Detection: Automatically detect npm, yarn, pnpm, and lerna workspaces
  • Package Discovery: Find all packages in a workspace with proper path resolution
  • Package Categorization: Organize packages by type (core, service, suite, ui, util, legacy)
  • Workspace Validation: Validate workspace structure and configuration
  • Changeset Integration: Resolve package paths correctly for changeset CLI

Installation

npm install @bernierllc/workspace-manager

Usage

Basic Workspace Detection

import { detectWorkspaceType, getWorkspaceConfig } from '@bernierllc/workspace-manager';

// Detect workspace type
const detection = detectWorkspaceType();
console.log(detection.type); // 'npm', 'yarn', 'pnpm', 'lerna', or 'unknown'

// Get full workspace configuration
const config = getWorkspaceConfig();
console.log(config.isValid); // true/false
console.log(config.packages); // Array of package paths

Package Discovery

import { getWorkspacePackages, getCategorizedPackages } from '@bernierllc/workspace-manager';

// Get all packages with detailed information
const packages = getWorkspacePackages();
packages.forEach(pkg => {
  console.log(`${pkg.name}: ${pkg.relativePath}`);
  console.log(`  Has package.json: ${pkg.hasPackageJson}`);
  console.log(`  Is directory: ${pkg.isDirectory}`);
});

// Get packages organized by category
const categorized = getCategorizedPackages();
categorized.forEach(pkg => {
  console.log(`${pkg.name} (${pkg.category}): ${pkg.relativePath}`);
});

Workspace Validation

import { validateWorkspaceStructure } from '@bernierllc/workspace-manager';

// Validate workspace structure
const result = validateWorkspaceStructure();

if (result.isValid) {
  console.log('✅ Workspace is valid');
} else {
  console.log('❌ Workspace has issues:');
  result.errors.forEach(error => console.log(`  - ${error}`));
}

// Validate with strict options
const strictResult = validateWorkspaceStructure('.', {
  requirePackageJson: true,
  allowedCategories: ['core', 'service', 'suite']
});

Changeset Integration

import { resolvePackagePaths } from '@bernierllc/workspace-manager';

// Get package paths for changeset CLI
try {
  const paths = resolvePackagePaths();
  console.log('Package paths for changeset:', paths);
} catch (error) {
  console.error('Invalid workspace configuration:', error.message);
}

API Reference

detectWorkspaceType(rootPath?: string): WorkspaceDetectionResult

Detect the type of workspace in the given directory.

Parameters:

  • rootPath (optional): Path to workspace root (defaults to process.cwd())

Returns:

  • WorkspaceDetectionResult with type, confidence, and detection reason

getWorkspaceConfig(rootPath?: string): WorkspaceConfig

Get complete workspace configuration.

Parameters:

  • rootPath (optional): Path to workspace root (defaults to process.cwd())

Returns:

  • WorkspaceConfig with type, packages, validation status, and errors

getWorkspacePackages(rootPath?: string): PackageInfo[]

Get detailed information about all packages in the workspace.

Parameters:

  • rootPath (optional): Path to workspace root (defaults to process.cwd())

Returns:

  • Array of PackageInfo objects with package details

getPackageCategories(rootPath?: string): Record<PackageCategory, string[]>

Get packages organized by category.

Parameters:

  • rootPath (optional): Path to workspace root (defaults to process.cwd())

Returns:

  • Object mapping categories to arrays of package paths

getCategorizedPackages(rootPath?: string): CategorizedPackage[]

Get packages with category information.

Parameters:

  • rootPath (optional): Path to workspace root (defaults to process.cwd())

Returns:

  • Array of CategorizedPackage objects

validateWorkspaceStructure(rootPath?: string, options?: WorkspaceValidationOptions): WorkspaceValidationResult

Validate workspace structure and configuration.

Parameters:

  • rootPath (optional): Path to workspace root (defaults to process.cwd())
  • options (optional): Validation options

Returns:

  • WorkspaceValidationResult with validation status, errors, and warnings

resolvePackagePaths(rootPath?: string): string[]

Resolve package paths for changeset CLI integration.

Parameters:

  • rootPath (optional): Path to workspace root (defaults to process.cwd())

Returns:

  • Array of package paths relative to workspace root

Throws:

  • Error if workspace configuration is invalid

Types

WorkspaceType

type WorkspaceType = 'npm' | 'yarn' | 'pnpm' | 'lerna' | 'unknown';

PackageCategory

type PackageCategory = 'core' | 'service' | 'suite' | 'ui' | 'util' | 'legacy' | 'unknown';

WorkspaceConfig

interface WorkspaceConfig {
  type: WorkspaceType;
  packages: string[];
  rootPath: string;
  configPath?: string;
  isValid: boolean;
  errors: string[];
}

PackageInfo

interface PackageInfo {
  name: string;
  path: string;
  relativePath: string;
  packageJsonPath: string;
  hasPackageJson: boolean;
  isDirectory: boolean;
}

Supported Workspace Types

npm Workspaces

Detected by package.json with workspaces field:

{
  "workspaces": ["packages/*"]
}

Yarn Workspaces

Detected by presence of yarn.lock and package.json with workspaces field.

pnpm Workspaces

Detected by presence of pnpm-workspace.yaml:

packages:
  - 'packages/*'

Lerna Workspaces

Detected by presence of lerna.json:

{
  "packages": ["packages/*"]
}

Package Categories

Packages are automatically categorized based on their directory structure:

  • core: packages/core/* - Atomic utilities and pure functions
  • service: packages/service/* - Business logic and orchestration
  • suite: packages/suite/* - Complete end-to-end solutions
  • ui: packages/ui/* - React components and UI utilities
  • util: packages/util/* - Utility packages
  • legacy: Other packages or legacy structure
  • unknown: Unable to determine category

Error Handling

The package provides comprehensive error handling:

try {
  const config = getWorkspaceConfig();
  if (!config.isValid) {
    console.error('Workspace configuration errors:', config.errors);
    return;
  }
  
  const packages = getWorkspacePackages();
  console.log(`Found ${packages.length} packages`);
} catch (error) {
  console.error('Failed to analyze workspace:', error.message);
}

Testing

npm test

Contributing

This package is part of the Bernier LLC tools ecosystem. Please follow the project's contribution guidelines.

License

UNLICENSED - Bernier LLC proprietary software