New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gu

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gu - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

test/handlers.test.js

11

gu.js
var log = require('logule').init(module);
var join = require('path').join;
var path = require('path');
var hotReload = require('hot-reload');

@@ -10,2 +10,3 @@ var Duplex = require('stream').Duplex;

}
scriptPath = path.resolve(scriptPath);
Duplex.call(this, {objectMode: true});

@@ -16,3 +17,3 @@ opts = opts || {};

for (var i = 0; i < (files || []).length; i += 1) {
var f = join(scriptPath, files[i]);
var f = path.join(scriptPath, files[i]);
this.files.push(f);

@@ -24,3 +25,3 @@ }

hotReload.create(require)
.loggingEnabled(false) // TODO: option
.loggingEnabled(!!opts.hotLogging)
.watch(scriptPath)

@@ -48,5 +49,5 @@ .uncache(scriptPath, true)

}
fn(this/*, this._state[f]*/);
fn(this);
if (!first) {
log.info('Loaded handlers from', f);
log.info('Reloaded handlers from', f);
}

@@ -53,0 +54,0 @@ }

@@ -5,3 +5,3 @@ {

"author": "Eirik Albrigtsen <analsandblaster@gmail.com>",
"version": "0.2.1",
"version": "0.2.2",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -9,3 +9,3 @@ # gu [![Build Status](https://secure.travis-ci.org/clux/gu.png)](http://travis-ci.org/clux/gu) [![Dependency Status](https://david-dm.org/clux/gu.png)](https://david-dm.org/clux/gu)

- hot code reloading of specified files (without the bot having to leave the server)
- streaming input and output allows for easy control, extensibility and transport-less testing
- streaming input and output allows for easy control, extensibility and transport-less testing of handlers

@@ -19,3 +19,3 @@ ## Usage

var gu = require('gu')(scriptPath, files);
var ircStream = require('ircStream')(name, server, {chan: chan});
var ircStream = require('ircStream')(name, server, {chan: [chan]});

@@ -75,2 +75,3 @@ ircStream.pipe(gu).pipe(ircStream);

## Caveats
### What files are reloaded
The script path you specify to `gu` should only contain the handler functions. If you point the path at your `lib` dir, then it may reload all the files in that directory when you change one of your handlers.

@@ -80,2 +81,17 @@

### When things can still go wrong
If you save one of the reload-watched files, and there's a syntax error, we will catch this error for you. An exception and a stack trace will be logged and all the handlers from the file with the error will be inactive.
However, it is possible to save a file that looks valid but will have a runtime error, for instance referencing an undefined variable. This we will not guard on (otherwise we'd have to try-catch _everything_), and your bot will crash. Thus, you should lint on save to prevent this from happening.
## Options
A few options can be passed along to the `gu` instance as the third parameter, these are:
```js
{
noReload: Boolean, // disable the hot-reload module (a must for handler tests)
hotLogging: Boolean // enable logging from the hot-reload module
}
```
## Installation

@@ -82,0 +98,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc