{"name":"@eggjs/watcher","version":"4.0.1","keywords":["egg-watcher","egg","watcher","watch"],"_id":"@eggjs/watcher@4.0.1","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":"dead_horse","email":"dead_horse@qq.com"},{"name":"wanghx","email":"whxaxes@gmail.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"mansonchor.zzw","email":"mansonchor1987@gmail.com"},{"name":"hubcarl","email":"hubcarl@126.com"},{"name":"gemwuu","email":"gemwuu@gmail.com"},{"name":"akitasummer","email":"644171127@qq.com"}],"homepage":"https://github.com/eggjs/watcher","bugs":{"url":"https://github.com/eggjs/watcher/issues"},"dist":{"shasum":"7350c82d0d4462c1345c4e2ec23b0e3346125c1c","tarball":"http://registry-npm.ywwl.com/@eggjs/watcher/download/@eggjs/watcher-4.0.1.tgz","fileCount":76,"integrity":"sha512-Y3sAWcU9OhFPEtYN8tSL4tNUlnkn8CH2q2CnOHE+jwiMpxHdL7SGiBOStIeP5p8u1HwhGwqCRzyXsLumw7Uz1g==","signatures":[{"sig":"MEYCIQDWPI5QAnZbrktir5G08mkas0Ll6RRkBdmbhdKIZ38BUgIhALnl1ovdgkTUzpWhZtZcN0zJH2G3OFsqFw0vrY47kEbf","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fwatcher@4.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":74319,"size":17571,"noattachment":false,"key":"/@eggjs/watcher/-/@eggjs/watcher-4.0.1.tgz"},"main":"./dist/commonjs/index.js","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":">= 18.19.0"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"097f79d7db28ed6e44866297ce88f61df1536c3d","scripts":{"ci":"egg-bin cov","lint":"eslint --cache src test --ext .ts","test":"egg-bin test","preci":"npm run lint && npm run prepublishOnly && attw --pack","pretest":"npm run lint -- --fix && npm run prepublishOnly","prepublishOnly":"tshy && tshy-after"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"eggPlugin":{"name":"watcher","exports":{"import":"./dist/esm","require":"./dist/commonjs"}},"repository":{"url":"git+ssh://git@github.com/eggjs/watcher.git","type":"git"},"_npmVersion":"10.8.2","description":"file watcher plugin for egg","directories":{},"_nodeVersion":"20.18.1","dependencies":{"sdk-base":"^5.0.0","camelcase":"^5.0.0","@eggjs/utils":"^4.0.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"egg":"beta","tshy":"3","eslint":"8","egg-bin":"beta","egg-mock":"beta","tshy-after":"1","typescript":"5","@types/node":"22","@types/mocha":"10","@eggjs/tsconfig":"1","eslint-config-egg":"14","@arethetypeswrong/cli":"^0.17.1"},"_npmOperationalInternal":{"tmp":"tmp/watcher_4.0.1_1734660203832_0.6788466092144823","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":1734660204031,"_cnpm_publish_time":1734660204031,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}