Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

watchpack

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watchpack

Wrapper library for directory and file watching.

  • 2.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27M
increased by2.85%
Maintainers
2
Weekly downloads
 
Created

What is watchpack?

The watchpack npm package is a wrapper around the file-watching functionality of Node.js and chokidar. It provides a higher-level API for watching file changes in a specified directory or set of directories. It is often used in build tools and development servers to watch for file changes and trigger rebuilds or reloads.

What are watchpack's main functionalities?

Watching Files and Directories

This feature allows you to watch for changes in specific files and directories. You can listen for 'change' events on individual files and 'aggregated' events for batch changes.

const Watchpack = require('watchpack');

const wp = new Watchpack({
  // options
});

wp.watch({
  files: ['file1.js', 'file2.js'],
  directories: ['dir1', 'dir2'],
  missing: ['file3.js', 'file4.js']
});

wp.on('change', (filePath, mtime, explanation) => {
  console.log(`${filePath} changed`, mtime, explanation);
});

wp.on('aggregated', (changes, removals) => {
  console.log('Changes:', changes);
  console.log('Removals:', removals);
});

Pausing and Resuming Watch

This feature allows you to temporarily pause the watching process and resume it later. This can be useful when performing batch operations that should not trigger watch events.

const wp = new Watchpack({});

// Start watching
wp.watch({ files: ['file1.js'] });

// Pause watching
wp.pause();

// After some time, resume watching
wp.watch({ files: ['file1.js'] });

Getting Watched Items

This feature allows you to retrieve a list of all files that are currently being watched. This can be useful for debugging or logging purposes.

const wp = new Watchpack({});

wp.watch({ files: ['file1.js'] });

const watchedFiles = wp.getWatchedFiles();
console.log(watchedFiles); // Outputs: ['file1.js']

Other packages similar to watchpack

FAQs

Package last updated on 13 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc