{"name":"@eggjs/watcher","version":"5.0.2-rc.0","keywords":["egg","egg-watcher","watch","watcher"],"license":"MIT","_id":"@eggjs/watcher@5.0.2-rc.0","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":"644171127@qq.com"},{"name":"elrrrrrrr","email":"elrrrrrrr@gmail.com"},{"name":"niania","email":"ljracm@gmail.com"}],"homepage":"https://github.com/eggjs/egg/tree/next/plugins/watcher","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"bb811f5bac23702ca52fbbf6114cdbba0d6ac1a9","tarball":"http://registry-npm.ywwl.com/@eggjs/watcher/download/@eggjs/watcher-5.0.2-rc.0.tgz","fileCount":31,"integrity":"sha512-YdE5w5/aQParY2zKMB3NfJAg/1LfqYgCUIc2M0K0PxmJKLnIFIC2olbJ6A0btyRkRmonpaQS0Zr5po96j44Dkw==","signatures":[{"sig":"MEQCIGTUnu+SaK+88B3/VlwXOidBRncLfjwORI78w8l95fNoAiBpVh++SOiX3ivqbrGGg6UYVZ2+nIRMoS7X4bHmc14/hg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEQCIBssydr3Ap0ZdyU/6IUQSYCZvcrFVInaXIMaiMDXsAuhAiAX8wNMnMGBsa+27JE1rgNVJfR4MkTxHp/SdZ4bpHMnrw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fwatcher@5.0.2-rc.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":19349,"size":6257,"noattachment":false,"key":"/@eggjs/watcher/-/@eggjs/watcher-5.0.2-rc.0.tgz"},"main":"./dist/index.js","type":"module","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"},"gitHead":"c92333429c2dfbdc5ddd06c7f3e238b4b07cbf41","scripts":{"typecheck":"tsgo --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:d9b9980f-ed6d-445c-90c8-4bdd19ca7768"}},"repository":{"url":"git+https://github.com/eggjs/egg.git","type":"git","directory":"plugins/watcher"},"_npmVersion":"11.19.0","description":"file watcher plugin for egg","directories":{},"_nodeVersion":"24.21.0","dependencies":{"sdk-base":"^5.0.1","camelcase":"^9.0.0","@eggjs/utils":"5.0.2-rc.0"},"publishConfig":{"access":"public","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"}},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"egg":"4.1.2-rc.0","typescript":"^5.9.3","@eggjs/mock":"7.0.2-rc.0","@eggjs/utils":"5.0.2-rc.0"},"peerDependencies":{"egg":"4.1.2-rc.0"},"_npmOperationalInternal":{"tmp":"tmp/watcher_5.0.2-rc.0_1790176707068_0.1444513268640606","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":1790176707166,"_cnpm_publish_time":1790176707166,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}