Skip to content

Watcher that deletes require cache on files update πŸ•

Notifications You must be signed in to change notification settings

leireNN/pit-require-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

exprexo

pit-require-cache πŸ•

What is pit-require-cache? πŸ€·β€

pit-require-cache is a zero-configuration watcher that deletes require's cache for any updated file.

Use case πŸ–Œ

Lets say that you are importing trought require a specific file and then serving that file trought a express server, then you update that file and as require cache the files already imported you need to stop the server and start it again. With pit-require-cache is not needed anymore, just instantiate the watcher once and then it will delete the cache for you making the changes appear all straight.

Installation 🧱

npm install pit-require-cache

Usage 🐢

const { watcher } = require('pit-require-cache')

watcher()

Available Options πŸ§ͺ

const options = {
  persistent: true,
 
  ignored: '*.txt',
  ignoreInitial: false,
  followSymlinks: true,
  cwd: '.',
  disableGlobbing: false,
 
  usePolling: true,
  interval: 100,
  binaryInterval: 300,
  alwaysStat: false,
  depth: 99,
  awaitWriteFinish: {
    stabilityThreshold: 2000,
    pollInterval: 100
  },
  ignorePermissionErrors: false,
  atomic: true
}

watcher({directory: 'myFolderName', ...options})

Main options:

{
  directory        Directory to be watched           [default: ".", string or array of strings]

  options: {       Options object                    [default: {}, object]

    persistent       Show version number               [default: true, boolean]

    ignored          Ignored files                     [default: '', string, example: '*.txt']

    ignoreInitial    Add/addDir events are also        [default: false, boolean]
                    emitted while instantiating

    followSymlinks   Watch followinf symbolic links    [default: true, boolean]

    cwd              Base directory                    [default: '.', string]

    usePolling       Whether to use fs.watchFile or    [default: false, boolean]
                    fs.watchtrue

    interval         Interval for polling              [default: 100, number]

    binaryInterval   Interval polling for binary files.[default: 300, number]

    depth            Limits how many levels of 
                    subdirectories will be traversed. [default: undefined, number]

    awaitWriteFinish Wait until the size of the file   [default: undefined, example: {
                    stays constant.                      stabilityThreshold: 2000,
                                                          pollInterval: 100
                                                        }, object]
    ignorePermissionErrors Silence the access errors   [default: false, boolean]
  }
}

As we are using chokidar module for the watcher implementation, there are a couple more options that can be checked on chokidar's module docs https://www.npmjs.com/package/chokidar/v/2.0.4

Credits ❀️

Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

About

Watcher that deletes require cache on files update πŸ•

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published