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

hardhat-watcher

v2.5.0

Published

Hardhat file watcher plugin

Downloads

178,022

Readme

hardhat-watcher

Automatically run Hardhat actions when files change

Installation

npm install hardhat-watcher

or

yarn add hardhat-watcher

Import the plugin in your hardhat.config.js:

require('hardhat-watcher')

Or if you are using TypeScript, in your hardhat.config.ts:

import 'hardhat-watcher'

Tasks

This plugin adds the watch task to Hardhat:

npx hardhat watch

Configuration

This plugin extends the HardhatUserConfig's object with an optional watcher field. Every property of watcher is optional.

This is the complete type:

module.exports = {
  watcher: {
    [key: string]: { // key is the name for the watcherTask
      tasks?: (string | { command: string, params?: { [key: string] => any } })[]; // Every task of the hardhat runtime is supported (including other plugins!)
      files?: string[]; // Files, directories or glob patterns to watch for changes. (defaults to `[config.paths.sources]`, which itself defaults to the `contracts` dir)
      ignoredFiles?: string[]; // Files, directories or glob patterns that should *not* be watched.
      verbose?: boolean; // Turn on for extra logging
      clearOnStart?: boolean; // Turn on to clear the logs (of older task runs) each time before running the task
      start?: string; // Run any desirable command each time before the task runs
      runOnLaunch?: boolean; // Turn on to run tasks immediately on launch. Be aware, tasks will be run with path parameter "none".
    }
  }
};

Usage

The most basic use case, which is simply compiling your files on change, is accomplished very easily with this config:

module.exports = {
  watcher: {
    compilation: {
      tasks: ['compile'],
    },
  },
}

and subsequently running npx hardhat watch compilation

A bit more involved and showcasing the use of parameters for tasks and defining multiple watcher tasks:

module.exports = {
  watcher: {
    compilation: {
      tasks: ['compile'],
      files: ['./contracts'],
      ignoredFiles: ['**/.vscode'],
      verbose: true,
      clearOnStart: true,
      start: 'echo Running my compilation task now..',
    },
    ci: {
      tasks: [
        'clean',
        { command: 'compile', params: { quiet: true } },
        { command: 'test', params: { noCompile: true, testFiles: ['testfile.ts'] } },
      ],
    },
  },
}

Run npx hardhat watch ci to clean, compile and test on every file change, or run npx hardhat watch compilation to compile.

Positional arguments

Positional arguments are provided in the same way as "normal" arguments (check out the testFiles argument in the example above, it's a positional argument). In order to find the name of a positional argument, simply run yarn hardhat <YOUR_COMMAND> --help. This is an example output for the test command:

Hardhat version 2.0.2

Usage: hardhat [GLOBAL OPTIONS] test [--no-compile] [...testFiles]

OPTIONS:

  --no-compile  Don't compile before running this task

POSITIONAL ARGUMENTS:

  testFiles     An optional list of files to test (default: [])

test: Runs mocha tests

For global options help run: hardhat help

Changed file as argument

The path of the changed file can be inserted into positional arguments using the template parameter {path}. This speeds up iteration in testing, especially if using single test isolation (for example, by using it.only("test") in mocha.)

Example:

module.exports = {
  watcher: {
    test: {
      tasks: [{ command: 'test', params: { testFiles: ['{path}'] } }],
      files: ['./test/**/*'],
      verbose: true,
      clearOnStart: true,
      start: 'echo Running my test task now..',
    }
  }
}