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

Watcher plugin API #54

Open
ide opened this issue Aug 12, 2015 · 6 comments
Open

Watcher plugin API #54

ide opened this issue Aug 12, 2015 · 6 comments

Comments

@ide
Copy link

ide commented Aug 12, 2015

Branching off the discussion about the chokidar watcher in #53, I've been thinking that a plugin API could be useful to let users of sane (e.g. me) use custom watchers without bloating the sane package or adding too much maintenance cost.

My end goal is to be able to use a custom watcher with the RN packager where the pieces are layered like this:

(The packager would also expose a flag to set the watcher implementation.)

At a high level is this something you'd be open to?

@amasad
Copy link
Owner

amasad commented Aug 21, 2015

yes!

@amasad
Copy link
Owner

amasad commented Aug 26, 2015

It's worth looking into the NodeWatcher again with iojs. It might be good enough now without any native extensions. I remember seeing a few patches on libuv for better watching (and less fsevents bugs)

@ide
Copy link
Author

ide commented Aug 26, 2015

Nice to hear that. Will be able to test it on a moderately sized project once react-native's dependencies have been updated to support io.js 3.x.

@ide
Copy link
Author

ide commented Sep 1, 2015

Didn't investigate deeply but did run into "too many open files" after uninstalling watchman:

Error: EMFILE: too many open files, open '/Users/ide/.babel.json'
    at Error (native)
    at Object.fs.openSync (evalmachine.<anonymous>:549:18)
    at Object.fs.writeFileSync (evalmachine.<anonymous>:1155:15)
    at process.save (/Users/ide/.nvm/versions/io.js/v3.2.0/lib/node_modules/exp/node_modules/react-native/node_modules/babel-core/lib/api/register/cache.js:35:19)
    at emitOne (events.js:77:13)
    at process.emit (events.js:169:7)
    at process.exit (node.js:737:17)
    at process.<anonymous> (/Users/ide/.nvm/versions/io.js/v3.2.0/lib/node_modules/exp/node_modules/react-native/packager/packager.js:156:11)
    at emitOne (events.js:77:13)
    at process.emit (events.js:169:7)

The packager works fine with watchman or chokidar though.

@ccheever
Copy link
Contributor

ccheever commented Sep 2, 2015

As a start for a proposal:

  • watcher plugins would be published as a separate npm package, typically prefixed with sane-
    • For example, I would publish the chokidar watcher as sane-chokidar or sane-chokidar
    • Plugins would list sane as a peer depency. sane itself would not list any plugins.
    • To use a custom watcher via a plugin, the function sane(dir, opts) would be updated to allow an optin called watcher which you would pass an instance of a class that implements the same interface that PollWatcher and watchman_watcher use.

For a concrete example, this is how you would use the ChokidarWatcher.

    ...
    let cw = new require('sane-chokidar');
    let w = sane('.', {watcher: cw});
    ...

@amasad
Copy link
Owner

amasad commented Sep 8, 2015

As mentioned on the PR. This is fine by me, but I'm missing the point of this if sane would just return the argument passed. If you gave me an example of how this would be used in the wild maybe I'll have a better understanding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants