Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cjs and esm both by tshy #14

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .autod.conf.js

This file was deleted.

5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "eslint-config-egg"
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '18.19.0, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release

on:
push:
branches: [ master ]

jobs:
release:
name: Node.js
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ coverage/
.DS_Store
run/
.vscode
package-lock.json
.tshy*
.eslintcache
dist
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

File renamed without changes.
64 changes: 38 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
# egg-watcher
File watcher plugin for egg
# @eggjs/watcher

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Node.js CI](https://github.com/eggjs/egg-watcher/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-watcher/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/schedule.svg?style=flat)](https://nodejs.org/en/download/)

fengmk2 marked this conversation as resolved.
Show resolved Hide resolved
[npm-image]: https://img.shields.io/npm/v/egg-watcher.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-watcher
[travis-image]: https://img.shields.io/travis/eggjs/egg-watcher.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-watcher
[codecov-image]: https://codecov.io/github/eggjs/egg-watcher/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/egg-watcher?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-watcher.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-watcher
[snyk-image]: https://snyk.io/test/npm/egg-watcher/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-watcher
[download-image]: https://img.shields.io/npm/dm/egg-watcher.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-watcher

File watcher plugin for egg

## Usage
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved

In worker process:

### app.watcher.watch(path, listener)

Start watching file(s).

- path(String|Array): file path(s)
- listener(Function): file change callback

### app.watcher.unwatch(path[, listener])

Stop watching file(s).

- path(String|Array): file path(s)
Expand All @@ -40,12 +39,14 @@ Stop watching file(s).
In agent process:

### agent.watcher.watch(path, listener)

Start watching file(s).

- path(String|Array): file path(s)
- listener(Function): file change callback

### agent.watcher.unwatch(path[, listener])

Stop watching file(s).

- path(String|Array): file path(s)
Expand All @@ -55,19 +56,19 @@ Stop watching file(s).

### `development` Mode

There's a built-in [development mode](https://github.com/eggjs/egg-watcher/blob/master/lib/event-sources/development.js) which works in local(env is `local`). Once files on disk is modified it will emit a `change` event immediately.
There's a built-in [development mode](https://github.com/eggjs/egg-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.

### Customize Watching Mode

Say we want to build a custom event source plugin (package name: `egg-watcher-custom`, eggPlugin.name: `watcherCustom`).

Firstly define our custom event source like this:

```js
```ts
// {plugin_root}/lib/custom_event_source.js
const Base = require('sdk-base');
import { Base } from 'sdk-base';

class CustomEventSource extends Base {
export default class CustomEventSource extends Base {
// `opts` comes from app.config[${eventSourceName}]
// `eventSourceName` will be registered later in
// `config.watcher.eventSources` as the key shown below
Expand All @@ -93,34 +94,39 @@ class CustomEventSource extends Base {
}
}
}

module.exports = CustomEventSource;
```

Event 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.

Then add your custom event source to config:

```js
// config.default.js
exports.watcher = {
eventSources: {
custom: require('../lib/custom_event_source'),
// config/config.default.js
import CustomEventSource from '../lib/custom_event_source';

export default {
watcher: {
eventSources: {
custom: CustomEventSource,
},
},
};
```

Choose to use your custom watching mode in your desired env.

```js
// config.${env}.js
exports.watcher = {
type: 'custom',
};
// config/config.${env}.js

export default {
watcher: {
type: 'custom',
},

// this will pass to your CustomEventSource constructor as opts
exports.watcherCustom = {
// foo: 'bar',
// this will pass to your CustomEventSource constructor as opts
watcherCustom: {
// foo: 'bar',
},
};
```

Expand All @@ -132,4 +138,10 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](https://github.com/eggjs/egg-watcher/blob/master/LICENSE)
[MIT](LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-watcher)](https://github.com/eggjs/egg-watcher/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
3 changes: 0 additions & 3 deletions agent.js

This file was deleted.

3 changes: 0 additions & 3 deletions app.js

This file was deleted.

15 changes: 0 additions & 15 deletions appveyor.yml

This file was deleted.

16 changes: 0 additions & 16 deletions config/config.default.js

This file was deleted.

5 changes: 0 additions & 5 deletions config/config.local.js

This file was deleted.

5 changes: 0 additions & 5 deletions config/config.unittest.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/event-sources/default.js

This file was deleted.

Loading
Loading