{"name":"@eggjs/watcher","version":"5.0.0-beta.29","keywords":["egg-watcher","egg","watcher","watch"],"_id":"@eggjs/watcher@5.0.0-beta.29","maintainers":[{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"akitasummer","email":"akitasummer@outlook.com"}],"homepage":"https://github.com/eggjs/egg/tree/next/plugins/watcher","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"3eedd02698e5a6a45e632ccd3eae395c6058c323","tarball":"http://registry-npm.ywwl.com/@eggjs/watcher/download/@eggjs/watcher-5.0.0-beta.29.tgz","fileCount":31,"integrity":"sha512-UtGLmDvob9+hNQTO4vjEgZMVGoT3GRIEhhTN9/aWEp7LYY+7wmep6ziuNnz0MkcI7Q9T6xwGTIodVn36zWizAg==","signatures":[{"sig":"MEUCIGh9upUB9Ld9ohV0BY/jl4F+NOkORu5yiURviIt6Kyb8AiEA/eF38+eHeH+FUPEKR+wG5zLHeIhGWtRvmTdwAoe8eNQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fwatcher@5.0.0-beta.29","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":33555,"size":10586,"noattachment":false,"key":"/@eggjs/watcher/-/@eggjs/watcher-5.0.0-beta.29.tgz"},"main":"./dist/index.js","type":"module","_from":"file:eggjs-watcher-5.0.0-beta.29.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=22.18.0"},"exports":{".":"./dist/index.js","./app":"./dist/app.js","./agent":"./dist/agent.js","./types":"./dist/types.js","./lib/boot":"./dist/lib/boot.js","./lib/utils":"./dist/lib/utils.js","./lib/watcher":"./dist/lib/watcher.js","./package.json":"./package.json","./lib/event-sources":"./dist/lib/event-sources/index.js","./config/config.local":"./dist/config/config.local.js","./config/config.default":"./dist/config/config.default.js","./config/config.unittest":"./dist/config/config.unittest.js","./lib/event-sources/base":"./dist/lib/event-sources/base.js","./lib/event-sources/default":"./dist/lib/event-sources/default.js","./lib/event-sources/development":"./dist/lib/event-sources/development.js"},"scripts":{"lint":"oxlint --type-aware","test":"vitest run","build":"tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:d9b9980f-ed6d-445c-90c8-4bdd19ca7768"}},"_resolved":"/tmp/813f26c9e15b03ead5c68004853a4226/eggjs-watcher-5.0.0-beta.29.tgz","eggPlugin":{"name":"watcher"},"_integrity":"sha512-UtGLmDvob9+hNQTO4vjEgZMVGoT3GRIEhhTN9/aWEp7LYY+7wmep6ziuNnz0MkcI7Q9T6xwGTIodVn36zWizAg==","repository":{"url":"git://github.com/eggjs/egg.git","type":"git","directory":"plugins/watcher"},"_npmVersion":"11.6.2","description":"file watcher plugin for egg","directories":{},"_nodeVersion":"22.20.0","dependencies":{"sdk-base":"^5.0.1","camelcase":"^8.0.0","@eggjs/utils":"5.0.0-beta.29"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"egg":"4.1.0-beta.29","tsdown":"0.15.6","vitest":"4.0.0-beta.18","typescript":"^5.9.3","@eggjs/mock":"7.0.0-beta.29","@eggjs/utils":"5.0.0-beta.29","@eggjs/tsconfig":"3.1.0-beta.29"},"peerDependencies":{"egg":"4.1.0-beta.29"},"_npmOperationalInternal":{"tmp":"tmp/watcher_5.0.0-beta.29_1760799348633_0.8957443530486382","host":"s3://npm-registry-packages-npm-production"},"readme":"# @eggjs/watcher\n\n[![NPM version][npm-image]][npm-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/@eggjs/watcher.svg?style=flat)](https://nodejs.org/en/download/)\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/watcher.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/watcher\n[snyk-image]: https://snyk.io/test/npm/@eggjs/watcher/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/@eggjs/watcher\n[download-image]: https://img.shields.io/npm/dm/@eggjs/watcher.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@eggjs/watcher\n\nFile watcher plugin for egg\n\n## Usage\n\nIn worker process:\n\n### app.watcher.watch(path, listener)\n\nStart watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\n### app.watcher.unwatch(path[, listener])\n\nStop watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\nIn agent process:\n\n### agent.watcher.watch(path, listener)\n\nStart watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\n### agent.watcher.unwatch(path[, listener])\n\nStop watching file(s).\n\n- path(String|Array): file path(s)\n- listener(Function): file change callback\n\n## Watching mode\n\n### `development` Mode\n\nThere's a built-in [development mode](https://github.com/eggjs/watcher/blob/master/src/lib/event-sources/development.ts) which works in local(env is `local`). Once files on disk is modified it will emit a `change` event immediately.\n\n### Customize Watching Mode\n\nSay we want to build a custom event source plugin (package name: `egg-watcher-custom`, eggPlugin.name: `watcherCustom`).\n\nFirstly define our custom event source like this:\n\n```ts\n// {plugin_root}/lib/custom_event_source.js\nimport { Base } from 'sdk-base';\n\nexport default class CustomEventSource extends Base {\n  // `opts` comes from app.config[${eventSourceName}]\n  // `eventSourceName` will be registered later in\n  // `config.watcher.eventSources` as the key shown below\n  constructor(opts) {\n    super(opts);\n    this.ready(true);\n  }\n\n  watch(path) {\n    // replace this with your desired way of watching,\n    // when aware of any change, emit a `change` event\n    // with an info object containing `path` property\n    // specifying the changed directory or file.\n    this._h = setInterval(() => {\n      this.emit('change', { path });\n    }, 1000);\n  }\n\n  unwatch() {\n    // replace this with your implementation\n    if (this._h) {\n      clearInterval(this._h);\n    }\n  }\n}\n```\n\nEvent source implementations varies according to your running environment. When working with vagrant, docker, samba or such other non-standard way of development, you should use a different watch API specific to what you are working with.\n\nThen add your custom event source to config:\n\n```js\n// config/config.default.js\nimport CustomEventSource from '../lib/custom_event_source';\n\nexport default {\n  watcher: {\n    eventSources: {\n      custom: CustomEventSource,\n    },\n  },\n};\n```\n\nChoose to use your custom watching mode in your desired env.\n\n```js\n// config/config.${env}.js\n\nexport default {\n  watcher: {\n    type: 'custom',\n  },\n\n  // this will pass to your CustomEventSource constructor as opts\n  watcherCustom: {\n    // foo: 'bar',\n  },\n};\n```\n\nIf possible, plugins named like `egg-watcher-${customName}`(`egg-watcher-vagrant` eg.) are recommended.\n\n## Questions & Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1760799348815,"_cnpm_publish_time":1760799348815,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}