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

@atom/notify

v1.3.3

Published

Cross-platform file system notifications

Downloads

17

Readme

@atom/notify

This Node.js module recursively-observes directory trees on the file system on macOS, Windows, and Linux. It delegates the heavy lifting to the Rust notify crate, which is wrapped in a simple executable that is spawned as a subprocess.

For more background on the reasons for this module's existence, see this pull request.

API

const Watcher = require("@atom/notify");

// Construct the watcher
const watcher = new Watcher();

// Watch a directory path
const watch = await watcher.watch("/my/huge/directory", (events) => {
  /* handle array of events */
});

// Remove the watch
await watch.dispose();

// Shut down the watcher completely
await watcher.kill();

The callback passed to watch is called with an array of event objects. Each event object takes one of the following forms:

  • {action: 'modified', path: string}
  • {action: 'created', path: string}
  • {action: 'deleted', path: string}
  • {action: 'renamed', oldPath: string, path: string}
  • {action: 'error', path: string, description: string}

Error handling

The watcher crate can emit errors. If these errors are associated with paths, they are forwarded as events to your watch callback. If an error is encountered that's not associated with a path, it is passed to an onError callback that is passed as a parameter to the Watcher constructor.

const watcher = new Watcher({
  onError: (error) => { /* global error handling */ },
});

Polling mode

By default, the an appropriate implementation of the watcher is selected for the current platform. You can also generate events by polling the file system. To do this, pass a pollInterval to the Watcher constructor with your desired duration between polls in milliseconds:

const watcher = new Watcher({pollInterval: 1000});

Bin path transformation

If you have a weird packaging situation (for example, this library being archived in an Electron ASAR archive), you may need to modify the path to the subprocess executable. You can pass a transformBinPath function to the Watcher constructor as a parameter to do so.

const watcher = new Watcher({
  transformBinPath: p => p.replace(/\bapp\.asar\b/, "app.asar.unpacked")
});

Project structure

This library spawns a subprocess that speaks a simple line-oriented JSON protocol over stdin and stdout. The Rust source for the subprocess is located in subprocess.

When this module is installed, a platform-appropriate binary is automatically downloaded from a GitHub release that matches the version field in the package.json. This avoids the need for installers to have a Rust toolchain installed on their system.

To produce the release artifacts, this project is associated with an Azure build pipeline that automatically builds the subprocess binary for all three platforms whenever a release tag of the format vX.Y.Z is pushed to the repository. Each binary is suffixed with the platform name and uploaded to the GitHub release.

To publish a new version, once you have a green build, run npm version to produce a new version tag and push it to the repository. Once Azure builds and uploads the subprocess artifacts to a new release, you can run npm publish. If you run npm publish prior to the artifact upload, users won't be able to download the appropriate binaries on installation for a brief window.