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

@yarn-tool/ws-changed

v3.0.14

Published

Detect changed packages in monorepo workspaces using both Lerna and Git

Readme

@yarn-tool/ws-changed

Detect changed packages in monorepo workspaces using both Lerna and Git.

同時使用 Lerna 與 Git 檢測 monorepo 工作區 (Workspaces) 中已變更的套件。

Features | 功能特色

  • Dual Detection: Combines Lerna and Git to detect changed packages
  • Lerna Integration: Uses lerna changed to detect packages changed since last release
  • Git Staged: Detects packages with staged changes in Git
  • Workspace Aware: Automatically detects workspace root and configuration
  • Dependency Tracking: Helps identify affected packages for selective builds

Installation | 安裝

# Using yarn
yarn add @yarn-tool/ws-changed

# Using yarn-tool
yarn-tool add @yarn-tool/ws-changed

# Using yt (alias)
yt add @yarn-tool/ws-changed

Usage | 使用方式

Get Changed Packages

import wsChanged from '@yarn-tool/ws-changed';

const result = wsChanged(process.cwd());

console.log(result.cwd);       // Workspace root path
console.log(result.changed);   // Packages changed according to Lerna
console.log(result.staged);    // Packages with Git staged changes

Lerna Only

import { lernaChanged } from '@yarn-tool/ws-changed';

const result = lernaChanged(process.cwd());
console.log(result.list);  // Array of changed package info

Git Staged Only

import { wsGitChanged } from '@yarn-tool/ws-changed';

const result = wsGitChanged(process.cwd());
console.log(result.list);  // Array of staged package info

API Documentation | API 文件

Return Type | 回傳型別

interface IChangedResult {
  cwd: string;           // Workspace root directory
  changed: IListableRowExtra[];  // Lerna detected changes
  staged: IListableRowExtra[];   // Git staged changes
}

interface IListableRowExtra {
  name: string;          // Package name
  version: string;       // Current version
  private: boolean;      // Is private package
  location: string;      // Absolute path
  prefix: string;        // Relative path from workspace root
}

Example Output | 範例輸出

{
  cwd: '/path/to/workspace',
  changed: [
    {
      name: 'package-a',
      version: '1.0.0',
      private: false,
      location: '/path/to/workspace/packages/package-a',
      prefix: 'packages/package-a'
    }
  ],
  staged: [
    {
      name: 'package-b',
      version: '2.0.0',
      private: false,
      location: '/path/to/workspace/packages/package-b',
      prefix: 'packages/package-b'
    }
  ]
}

Advanced Usage

Build Only Changed Packages

import wsChanged from '@yarn-tool/ws-changed';
import { findUpDepsAllDeep } from '@yarn-tool/find-deps';

const result = wsChanged();
const allChanged = result.changed.concat(result.staged);
const packageNames = allChanged.map(row => row.name);

console.log('Packages to build:', packageNames);

Run Scripts on Changed Packages

import wsChanged from '@yarn-tool/ws-changed';
import crossSpawn from 'cross-spawn-extra';

const result = wsChanged();
const packages = result.changed.map(row => row.name);

if (packages.length > 0) {
  await crossSpawn.async('lerna', [
    'run',
    '--scope', packages[0],
    'build'
  ], { stdio: 'inherit' });
}

Configuration | 設定

| Option | Type | Description | |--------|------|-------------| | cwd | string | Working directory (default: process.cwd()) / 工作目錄(預設:process.cwd()) | | gitBin | string | Path to Git binary / Git 執行檔路徑 | | lernaBin | string | Path to Lerna binary / Lerna 執行檔路徑 |

How It Works | 運作原理

  1. Lerna Changed: Executes lerna changed --json to get packages changed since last release
  2. Git Staged: Analyzes git diff --staged to find packages with staged changes
  3. Workspace Mapping: Matches changed paths to workspace packages using workspaces config
  4. Deduplication: Removes duplicate packages from the combined list

Related

License

ISC