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

mrdr

v0.1.3

Published

`mrdr` (pronounced: /mordor/) is a Swiss-army knife for running tasks in a monorepo.

Downloads

17

Readme

mrdr - Mono repo dev runner

mrdr (pronounced: /mordor/) is a Swiss-army knife for running tasks in a monorepo.

Usage

This app requires a bit of setup, which you probably already have, but let's re-iterate what's needed.

NPM workspace configuration

In your monorepo there's a parent package.json that needs to have your workspaces listed. Given that your project contains 3 packages, a, b and c here's the necessary configuration:

/package.json

{
  "workspaces": [
    "packages/a",
    "packages/b",
    "packages/c"
  ]
}

Individual project configuration

Each project can either be a shared library or an application.

Shared libraries

In the case of a shared library you need to tell it what artifacts are exposed from it. This is standard npm package configuration, but for the sake of completeness here's an example, where package c from the above workspaces definition is a shared library:

/packages/c

{
  "name": "c",
  "exports": {
    ".": {
      "default": "./dist/c.js",
      "require": "./dist/c.umd.cjs",
      "types": "./dist/index.d.ts"
    }
  }
}

Dependencies

Let's assume package a is an application that would like to use package c as a library. The standard way of expressing that dependency is to put it in the list of dependencies:

{
  "name": "a",
  "dependencies": {
    "c": "*"
  }
}

It can also be a devDependency - doesn't matter as long as one of those sections contain the dependency to c.

Scripts

Now to the good part - running builds.

Once you have all your exports and dependencies defined it's time to define scripts that will build your project for both development and final build.

In this example I am going to assume you're going to use vite because if you're still using webpack you should rethink your life, maybe change jobs or just upgrade. It is worth every effort (unless you can't for some technical reason...)

In your common library (c) you define the scripts as follows:

/packages/c/package.json

{
  "scripts": {
    "dev": "vite build -w",
    "build": "vite build"
  }
}

In your application (a) you define them as follows:

/packages/a/package.json

{
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  }
}

This is pretty standard configuration that all examples on the Internet and all the templates will follow - because it is obvious and simple.

Top-level scripts

In the strictest sense you don't need them but it is surely a nice to have thing:

/package.json

{
  "scripts": {
    "dev": "mrdr",
    "build": "mrdr build"
  }
}

Command-line options

mrdr is a very young utility so the options are few at the moment:

Usage: mrdr [options] [command]

Options:
  -V, --version           output the version number
  -h, --help              display help for command

Commands:
  run [options] [script]  Run a task recursively within the monorepo
  ls [options]            List dependencies between projects
  help [command]          display help for command

The run command is for running tasks

Usage: mrdr run [options] [script]

Arguments:
  script                       Script to execute (default: "dev")

Options:
  -q, --quiet                  Be quiet
  -v, --verbose                Be verbose
  -P, --prefix <path>          Workspaces root (default: ".")
  -d, --delay <ms>             Additional miliseconds to wait after the resource is created (default: 200)
  -t, --timeout <s>            Max time in seconds to wait for resources to be generated (default: 30)
  -w, --workspace <workspace>  Run only the given workspace and its dependencies (default: "")
  -C, --clean [task]           Call the "clean" task before building a project; defaults to "clean" task
  --no-wait                    Do not wait for resources to be created (useful for running the "clean" task alone)
  --vite-reload-hack           Install a hack that kicks dependent projects when a dependency is rebuilt
  -h, --help                   display help for command

The ls task is for listing dependencies between projects:

Usage: mrdr ls [options]

List dependencies between projects

Options:
  -w, --workspace <workspace>  Run only the given workspace and its dependencies (default: "")
  -P, --prefix <path>          Workspaces root (default: ".")
  -h, --help                   display help for command

Listing dependencies

It is possible to have the dependencies between projects listed, possibly for debugging

npx mrdr ls

Running tasks

Being in your top-level folder, if you want to run everything in dev mode all you need to do is:

npx mrdr

It will take the dev script from your packages and run it in order from least-dependent to most-dependent.

WARNING! No circular dependency check is done. If you have a case like that, don't use mrdr before you cut them!

You also might want to build your project in the proper sequence:

npx mrdr build

Vite.js hack for reloading projects

At present there is a bug either in vite.js or in vue.js or the hot-reloader for vue.js. The bug manifests in such a way that you need to manually reload the page if a package is used that is located behind a symlink.

Since npm workspaces automatically link packages in the top-level node_modules folder they are always behind a symlink. The hack does a touch on vite.config.js (if it exists) to poke vite to restart the application. It may not be what you need, hence this is an option. Use it if it helps, forget it ever existed if it hurts your feelings

Have fun using mrdr!