0.0.5 • Published 8 years ago

require-patch v0.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

require-patch

Patch the global nodejs require hook

Installation

npm install require-patch

Usage

Let's say you want to setup a function that copies files when they're required, you might want to use it like this

usage.js

var copied = require.copy('./myjsonfile.json');

Here's how you'd set that up in your main app file

main.js

extend = require('extend');
var patcher = require('require-patch');

patcher.patch(function(globalRequire) {
  globalRequire.copy = function(filepath) {
    return extend(true, {}, globalRequire(filepath));
  }
});

usage = require('./usage');

Note: Only works in native node environments that don't do static preprocessing of require()'s (Mocha, webpack, etc. don't work)

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago