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

warm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

warm - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

.editorconfig

50

index.js

@@ -0,5 +1,7 @@

'use strict';
var _ = require('lodash');
var Promise = require('bluebird');
config = {
var config = {
expect: 'promise',

@@ -12,3 +14,3 @@ path: '',

function Warm() {
var cfg = this.cfg = config;
var cfg = this.cfg = _.clone(config);
this.payloads = _.chain(arguments)

@@ -20,2 +22,5 @@ .values()

_.extend(cfg, item);
if(item.path && item.path[item.path.length-1] !== '/') {
cfg.path += '/';
}
return false;

@@ -27,2 +32,3 @@ }

.value();
}

@@ -33,37 +39,33 @@

var cfg = this.cfg, path = cfg.path,
_module = null, _warmPayload = null;
var cfg = this.cfg, _module = null;
if(path && path[path.length-1] !== '/') {
path += '/';
function wrap(err) {
return function () {
return err ? Promise.reject(err) : Promise.resolve();
};
}
if(typeof item === 'string') {
_module = require(path + item);
_module = require(this.cfg.path + item);
} else {
_module = item;
}
warmPayload = _module && _module[cfg.init];
var warmPayload = _module && _module[cfg.init];
if (warmPayload instanceof Function) {
if(cfg.expect === 'promise') {
return warmPayload;
} else {
return function() {
return new Promise(function(resolve, reject) {
warmPayload(function (err, res) {
return err ? reject(err) : resolve(res);
});
});
};
}
} else if(warmPayload instanceof Promise || warmPayload) {
throw new Error('.'+cfg.init+'() should be function (with callback or promise)');
} else {
if(cfg.strict) {
throw new Error('.'+cfg.init+'() not found in one of modules');
}
return function() {
Promise.resolve();
return new Promise(function(resolve, reject) {
warmPayload(function (err, res) {
return err ? reject(err) : resolve(res);
});
});
};
}
if(cfg.strict) {
return wrap(new Error('.'+cfg.init+'() should be function (containing callback or promise)'));
}
return wrap();
};

@@ -82,3 +84,3 @@

} else {
Promise.reject(err);
throw err;
}

@@ -85,0 +87,0 @@ });

{
"name": "warm",
"version": "0.0.0",
"version": "1.0.0",
"description": "warm up node modules before using",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"coverage": "istanbul cover _mocha --",
"pretest": "jshint index.js",
"test": "istanbul cover _mocha --"
},

@@ -27,6 +29,15 @@ "repository": {

"dependencies": {
"async": "^1.4.2",
"bluebird": "^2.10.2",
"lodash": "^3.10.1"
}
},
"devDependencies": {
"chai": "^3.3.0",
"istanbul": "^0.3.22",
"jshint": "^2.8.0",
"mocha": "^2.3.3",
"pre-git": "^0.6.2"
},
"pre-push": [
"npm test"
]
}
# warm
Warm up node modules before using
[![Build Status via Travis CI](https://travis-ci.org/vkfont/warm.svg?branch=master)](https://travis-ci.org/vkfont/warm)
[![NPM version](http://img.shields.io/npm/v/warm.svg)](https://www.npmjs.org/package/warm)
[![Coverage Status](https://coveralls.io/repos/vkfont/warm/badge.svg?branch=master&service=github)](https://coveralls.io/github/vkfont/warm?branch=master)
This node.js module is useful if you want to load other modules and be sure all warming code is executed before you continue.
### Quick usage
Install module into own project
```
# npm install --save warm
```
Create new class and call `.parallel` method
```javascript
Warm = requre('warm');
new Warm('./database', './redis').parallel(function (err) {
if(err) { throw err; }
console.log('Initial code was executed in all described modules');
});
```
Modules `database` and `redis` should return special method (`.init` by default), which resolve promise or call callback on finish. See *Modules*
### Options
You can pass additional options like plain object: `new Warm({ ... }, 'module1', ...)`:
| Name | Default | Description |
| ------------- |:----------:| -----|
| `.expect` | `promise` | will init method inform about finish with promise (reject/resolve it), or will fire callback with error (`expect: 'callback'`)
| `.path` | `''` | prefix for requiring modules
| `.strict` | `true` | should return error if init method not found in module
| `.init` | `init` | init method name
### Samples
```javascript
Warm = requre('warm');
// load modules in array or additional parameters with options
options1 = {
expect: 'callback'
}
options2 = {
strict: true
}
new Warm(options1, ['./module1', './module2'], './module3', options2).parallel(console.log);
// execute already loaded module
new Warm(require('./module3')).parallel(console.log);
// handle promise
new Warm('./module1').parallel().then(function () {
console.log('loaded');
}).catch(function (err) {
console.log('error:', err);
})
```
### Modules
Module should contain method `.init` (or other, described in options) which will return promise or file callback. Example:
```javascript
module.exports = function () {
return 'i will not fire';
};
module.exports.init = function (callback) {
setTimeout(function () {
console.log('>>> i will fire durning warming');
callback();
}, 100);
};
```
Additional samples can be found in [test folder](./tetst/fixtures/)
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