{"name":"@eggjs/watcher","version":"4.0.3","keywords":["egg-watcher","egg","watcher","watch"],"_id":"@eggjs/watcher@4.0.3","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":"3ebdf871f31ed1237d9964dbc0902ae1121d67fb","tarball":"http://registry-npm.ywwl.com/@eggjs/watcher/download/@eggjs/watcher-4.0.3.tgz","fileCount":76,"integrity":"sha512-Krjb4V9dxtzcGLnJ4RNDRH6TLdGYMg/1Bf8KLgN1UwnVpsSNl5uW01X5nmDpYwOW2AGKREfScncGVP5ZlpJNgw==","signatures":[{"sig":"MEUCIQCngyCNm2W4kZMUVSV0RzTttoPdUqFTyGeAtuHyaw+QzAIgYUciUG+J3jmMerDYGf+PrmxmYm8ygW1X3eQLNV8vA0Y=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2fwatcher@4.0.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":75213,"size":17899,"noattachment":false,"key":"/@eggjs/watcher/-/@eggjs/watcher-4.0.3.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":"17b20df26eefe4d8741a8e43d7363f487e00c9d2","scripts":{"ci":"egg-bin cov","lint":"eslint --cache src test --ext .ts","test":"egg-bin test","clean":"rimraf dist","preci":"npm run clean && npm run lint","postci":"npm run prepublishOnly && attw --pack && npm run clean","pretest":"npm run clean && npm run lint -- --fix","prepublishOnly":"tshy && tshy-after"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"eggPlugin":{"name":"watcher","exports":{"import":"./dist/esm","require":"./dist/commonjs","typescript":"./src"}},"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/core":"^6.2.13","@eggjs/utils":"^4.2.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"egg":"beta","tshy":"3","eslint":"8","rimraf":"6","@eggjs/bin":"7","tshy-after":"1","typescript":"5","@eggjs/mock":"6","@types/node":"22","@types/mocha":"10","@eggjs/tsconfig":"1","eslint-config-egg":"14","@arethetypeswrong/cli":"^0.17.1"},"_npmOperationalInternal":{"tmp":"tmp/watcher_4.0.3_1735977149440_0.9707528749769829","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":1735977149614,"_cnpm_publish_time":1735977149614,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}