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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jobsite

v0.4.0

Published

Tools for working with workspaces as defined by Yarn, Bolt, Lerna, etc.

Downloads

18

Readme

jobsite

Tools for working with workspaces as defined by Yarn, Lerna, Bolt, etc.

npm i jobsite

Usage

Usage: jobsite [options] [command]

Options:
  -c, --concurrency [number]  The number of tasks to run at any given time. If true, then as many threads as possible are used.
  -p, --packages [glob]       Filters or finds workspaces that have a package.json and name that match the specified glob. If true, then it operates on all packages that have a name.
  -w, --workspaces <glob>     Filters or finds workspaces that have a path that match the specified glob.
  -h, --help                  output usage information

Commands:
  get                         Returns the available workspaces.
  run <cmd> [args...]         Runs <cmd> in each workspace and passes in <options>.
  npm <cmd> [args...]         Runs the specified npm commands, if they exist.

get

Returns the available workspaces.

$ jobsite get
$ jobsite get -w "packages/*"

run <cmd> [args...]

Runs <cmd> in each workspace and passes in <options>.

$ jobsite run ls
$ jobsite run -- ls -la
$ jobsite run -p "package*" -- ls -la
$ jobsite run -w "packages/*" -- ls -la

It's recommended you use -- so that you can pass arguments to the command you want to run.

npm <cmd> [args...]

Runs the NPM script specified by <cmd> in all workspaces that have the specified script defined in their package.json.

$ jobsite npm test
$ jobsite npm -p "package*" test
$ jobsite npm -w "packages/*" test

API

You can also use jobsite as a module.

A workspace can be defined as:

type Workspace = {
  path: string;
  package: null | { [s: string]: string };
};

For the following examples, let's assume that we have the following workspaces:

const workspaces = [
  { path: "packages/a", package: { name: "a", scripts: { test: "jest" } } },
  { path: "packages/b", package: { name: "b", scripts: { test: "jest" } } }
];

And that we have a workspace definition in our package.json that looks like:

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

Our directory structure looks like:

  • packages
    • a/package.json
    • b/package.json

async getWorkspacesPatterns()

Returns an array of the defined workspaces or null if none are specified. It supports Bolt, Lerna and Yarn workspace definitions.

const { getWorkspacesPatterns } = require("jobsite");

// ["packages/*"]
getWorkspacesPatterns().then(console.log);

Not only does it support Bolt, Lerna and Yarn definitions, it supports anything that [cosmiconfig])(https://github.com/davidtheclark/cosmiconfig) supports, too. This means that you can define a .workspacesrc file next to several repos if you wanted to, and manage them with jobsite!

async getWorkspaces(glob: string | string[])

Expands the workspace glob into an array of Workspace objects.

If you don't specify glob, it will use getWorkspacePatterns() to try and find workspaces.

const { getWorkspaces } = require("jobsite");

// Would return all packages.
getWorkspaces().then(console.log);
getWorkspacesPatterns("packages/*").then(console.log);

Filters

Filters are functions that return functions, than can be passed into Array.prototype.filter.

filterByPackageName(glob: string)

Returns a function that filters the workspaces by matching the glob to the package name.

const { filterByPackageName, getWorkspaces } = require("jobsite");

// Only returns package "b".
getWorkspaces()
  .then(filterByPackageName("b"))
  .then(console.log);

filterByPackageScript(script: string)

Returns a function that filters the workspaces that only have the specified script defined in their package.json, if one exists.

const { filterByPackageScript, getWorkspaces } = require("jobsite");

// Returns both packages.
getWorkspaces()
  .then(filterByPackageScript("test"))
  .then(console.log);

filterByPath(glob: string)

Returns a function that filters the workspaces by matching their path to the package name.

const { filterByPath, getWorkspaces } = require("jobsite");

// Only returns package "b".
getWorkspaces()
  .then(filterByPath("*/b"))
  .then(console.log);