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

@lekoarts/filespy

v1.0.0

Published

Spy on files, powered by @parcel/watcher

Downloads

2

Readme

filespy

This is a fork of alloc/filespy to keep dependencies up-to-date and do the occasional fix. This package is ESM only.

Spy on files

Features

  • Emits files only
  • Crawls asynchronously before watching
  • Powered by @parcel/watcher for native performance, event throttling, and Watchman support
  • Tolerates permission errors
  • Has powerful pattern syntax
  • Handles renamed directories properly
  • Exposes the paths being watched
  • Exposes the paths that were skipped
  • Ensures file paths use forward slashes
  • Protects against reentrancy by using setImmediate before emitting
  • Splits up long-running listeners with setImmediate
  • Crashes if you don't handle error events
  • Waits for root directory to exist

Usage

import { filespy } from '@lekoarts/filespy'

const spy = filespy(process.cwd(), {
  only: ['*.[jt]sx?'],
  skip: ['node_modules'],
}).on('all', (event, file, stats, cwd) => {
  // "file" argument is relative to "cwd"
  // "stats" is from lstat call

  if (event === 'create') {
    // File created.
  }
  else if (event === 'update') {
    // File changed.
  }
  else {
    // File deleted.
  }
}).on('error', (error) => {
  // Permission error or watcher failed.
  console.error(error)
}).on('ready', () => {
  // Initial crawl completed. Watcher initialized.
})

spy.dirs // Set of watched directories.
spy.files // Sorted list of watched paths (even directories).
spy.skipped // Sorted list of existing paths that were skipped.

// List all watched paths within a watched directory.
// Returned paths are relative to cwd.
spy.list('foo/bar')

// Stop watching.
spy.close()

Events

interface Events {
  all(
    event: 'create' | 'update' | 'delete',
    /** Path relative to cwd */
    file: string,
    /** Equals null for "delete" events */
    stats: fs.Stats | null, // https://nodejs.org/api/fs.html#fs_class_fs_stats
    /** The root directory */
    cwd: string
  ): void

  /** Permission error or watcher failure */
  error(error: Error): void

  /** Directory was crawled */
  crawl(dir: string, cwd: string): void

  /** Watcher is ready */
  ready(): void

  /** File created */
  create(file: string, stats: fs.Stats, cwd: string): void

  /** File changed */
  update(file: string, stats: fs.Stats, cwd: string): void

  /** File deleted */
  delete(file: string, cwd: string): void
}

Pattern syntax

Filespy mixes globbing with regular expressions, a concept borrowed from Recrawl.

  1. When a path has no separators (/), only the basename is matched.
'*.js' // matches 'a.js' and 'a/b.js'
  1. Recursivity is implicit.
'a/b' // identical to '**/a/b'
  1. Use a leading separator to match against the root.
'/*.js' // matches 'a.js' not 'a/b.js'
  1. Use a trailing separator to match all descendants.
'foo/' // matches 'foo/bar' and 'foo/bar/baz' etc
  1. Regular expression syntax is supported. (except dot-all)
'*.jsx?' // matches 'a.js' and 'b.jsx'
'*.(js|ts)' // matches 'a.js' and 'b.ts'
  1. Recursive globbing is supported.
'foo/**/bar' // matches 'foo/bar' and 'foo/a/b/c/bar' etc