# hardhat-watcher

> Hardhat file watcher plugin

Latest version **2.5.0** (published 2022-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install hardhat-watcher
pnpm add hardhat-watcher
yarn add hardhat-watcher
bun add hardhat-watcher
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.0 |
| Published | 2022-08-19 |
| First published | 2020-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Xander Deseyn |
| Maintainers | xanderd |
| Keywords | ethereum, hardhat, hardhat-plugin, file, watcher |

## Links

- npm: https://www.npmjs.com/package/hardhat-watcher
- Repository: https://github.com/N1ghtly/hardhat-watcher
- npm.io page: https://npm.io/package/hardhat-watcher

## Dependencies (1)

- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.5.0 (latest) — 2022-08-19
- 2.4.0 — 2022-08-19
- 2.3.0 — 2022-05-08
- 2.2.0 — 2022-05-06
- 2.1.1 — 2021-01-30
- 2.0.0 — 2020-11-05
- 1.0.14 — 2020-11-04
- 1.0.13 — 2020-10-31
- 1.0.12 — 2020-10-31
- 1.0.11 — 2020-10-31
- 1.0.10 — 2020-10-30
- 1.0.9 — 2020-10-30
- 1.0.8 — 2020-10-30
- 1.0.7 — 2020-10-30
- 1.0.6 — 2020-10-30
- … 5 more at https://npm.io/package/hardhat-watcher/versions

## README

# hardhat-watcher

_Automatically run Hardhat actions when files change_

## Installation

```bash
npm install hardhat-watcher
```

or

```bash
yarn add hardhat-watcher
```

Import the plugin in your `hardhat.config.js`:

```js
require('hardhat-watcher')
```

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

```ts
import 'hardhat-watcher'
```

## Tasks

This plugin adds the _watch_ task to Hardhat:

```bash
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:

```js
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:

```js
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:

```js
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..',
    }
  }
}
```

---
_Source: https://npm.io/package/hardhat-watcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
