cousin-harris
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

cousin-harris

build status Known Vulnerabilities Renovate

Usage

import cousinHarris from 'cousin-harris'
import delay from 'delay'

const roots = ['dir1', 'dir2']
const watcher = cousinHarris(
  roots,
  ({ root, path, removal, isDirectory }) => {
    console.log(
      '%s %s at root %s was %s',
      isDirectory ? 'directory' : 'file',
      path,
      root,
      removal ? 'removed' : 'changed',
    )
  },
  { watchProject: true },
)

// wait for all watches to be initialised
await watcher.waitForWatches

// add more watches after a second
await delay(1000)
await watcher.addRoot('dir3')
await watcher.waitForWatches

// stop watching one second after setting up watch for 'dir3'
await delay(1000)
await watcher.stop()

Without { watchProject: true } watchman's watch command is used instead of watch-project.

The root passed to the update function will be an absolute path, if it's important to receive the same root as was passed then the result of fs.realPath or equivalent should be passed to cousinHarris.

Readme

Keywords

Package Sidebar

Install

npm i cousin-harris

Weekly Downloads

149

Version

3.0.1

License

ISC

Unpacked Size

28.6 kB

Total Files

16

Last publish

Collaborators

  • jpike