{"id":19904379,"url":"https://github.com/alloc/filespy","last_synced_at":"2025-05-03T00:31:37.493Z","repository":{"id":57235885,"uuid":"348125822","full_name":"alloc/filespy","owner":"alloc","description":"Spy on files 🔍","archived":true,"fork":false,"pushed_at":"2021-03-22T16:25:25.000Z","size":322,"stargazers_count":38,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T21:02:30.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alloc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-15T21:20:25.000Z","updated_at":"2024-11-11T17:03:38.000Z","dependencies_parsed_at":"2022-09-04T21:40:15.882Z","dependency_job_id":null,"html_url":"https://github.com/alloc/filespy","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Ffilespy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Ffilespy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Ffilespy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alloc%2Ffilespy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alloc","download_url":"https://codeload.github.com/alloc/filespy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252126559,"owners_count":21698964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T20:28:08.603Z","updated_at":"2025-05-03T00:31:36.757Z","avatar_url":"https://github.com/alloc.png","language":"TypeScript","funding_links":["https://paypal.me/alecdotbiz"],"categories":[],"sub_categories":[],"readme":"# filespy\n\n[![npm](https://img.shields.io/npm/v/filespy.svg)](https://www.npmjs.com/package/filespy)\n[![ci](https://github.com/alloc/filespy/actions/workflows/release.yml/badge.svg)](https://github.com/alloc/filespy/actions/workflows/release.yml)\n[![codecov](https://codecov.io/gh/alloc/filespy/branch/master/graph/badge.svg)](https://codecov.io/gh/alloc/filespy)\n[![Bundle size](https://badgen.net/bundlephobia/min/filespy)](https://bundlephobia.com/result?p=filespy)\n[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/alecdotbiz)\n\n\u003e Spy on files\n\n\u0026nbsp;\n\n### Features\n\n- Emits files only\n- Crawls **asynchronously** before watching\n- Powered by `@parcel/watcher` for native performance, event throttling, and [Watchman](https://facebook.github.io/watchman/) support\n- Tolerates permission errors\n- Has powerful [pattern syntax](#pattern-syntax)\n- Handles renamed directories properly\n- Exposes the paths being watched\n- Exposes the paths that were skipped\n- Ensures file paths use forward slashes\n- Protects against reentrancy by using `setImmediate` before emitting\n- Splits up long-running listeners with `setImmediate`\n- Crashes if you don't handle `error` events\n- Waits for root directory to exist\n\n\u0026nbsp;\n\n## Usage\n\n```ts\nimport filespy from 'filespy'\n\nconst spy = filespy(process.cwd(), {\n  only: ['*.[jt]sx?'],\n  skip: ['node_modules'],\n}).on('all', (event, file, stats, cwd) =\u003e {\n  // \"file\" argument is relative to \"cwd\"\n  // \"stats\" is from lstat call\n\n  if (event == 'create') {\n    // File created.\n  } else if (event == 'update') {\n    // File changed.\n  } else {\n    // File deleted.\n  }\n}).on('error', error =\u003e {\n  // Permission error or watcher failed.\n}).on('ready', () =\u003e {\n  // Initial crawl completed. Watcher initialized.\n})\n\nspy.dirs // Set of watched directories.\nspy.files // Sorted list of watched paths (even directories).\nspy.skipped // Sorted list of existing paths that were skipped.\n\n// List all watched paths within a watched directory.\n// Returned paths are relative to cwd.\nspy.list('foo/bar')\n\n// Stop watching.\nspy.close()\n```\n\n\u0026nbsp;\n\n## Events\n\n```ts\ninterface {\n  all(\n    event: 'create' | 'update' | 'delete',\n    /** Path relative to cwd */\n    file: string,\n    /** Equals null for \"delete\" events */\n    stats: fs.Stats | null, // https://nodejs.org/api/fs.html#fs_class_fs_stats\n    /** The root directory */\n    cwd: string\n  ): void\n\n  /** Permission error or watcher failure */\n  error(error: Error): void\n\n  /** Directory was crawled */\n  crawl(dir: string, cwd: string): void\n\n  /** Watcher is ready */\n  ready(): void\n\n  /** File created */\n  create(file: string, stats: fs.Stats, cwd: string): void\n\n  /** File changed */\n  update(file: string, stats: fs.Stats, cwd: string): void\n\n  /** File deleted */\n  delete(file: string, cwd: string): void\n}\n```\n\n\u0026nbsp;\n\n## Pattern syntax\n\nFilespy mixes globbing with regular expressions, a concept borrowed from [Recrawl](https://github.com/aleclarson/recrawl).\n\n1. When a path has no separators (`/`), only the basename is matched.\n\n```js\n'*.js' // matches 'a.js' and 'a/b.js'\n```\n\n2. Recursivity is implicit.\n\n```js\n'a/b' // identical to '**/a/b'\n```\n\n3. Use a leading separator to match against the root.\n\n```js\n'/*.js' // matches 'a.js' not 'a/b.js'\n```\n\n4. Use a trailing separator to match all descendants.\n\n```js\n'foo/' // matches 'foo/bar' and 'foo/bar/baz' etc\n```\n\n5. Regular expression syntax is supported. (except dot-all)\n\n```js\n'*.jsx?' // matches 'a.js' and 'b.jsx'\n'*.(js|ts)' // matches 'a.js' and 'b.ts'\n```\n\n6. Recursive globbing is supported.\n\n```js\n'foo/**/bar' // matches 'foo/bar' and 'foo/a/b/c/bar' etc\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falloc%2Ffilespy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falloc%2Ffilespy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falloc%2Ffilespy/lists"}