1.0.2 • Published 3 years ago
@blowback/contextify v1.0.2
Blowback
Contextify
Creates a contextualized copy of node require
// ./tasks/module1.js
const getContext = require('my-context-module');
module.exports = () => {
return getContext().myContextValueABC;
};
// index.js
import { Contextify } from 'blowback';
const { prepareRequire } = new Contextify({
contextModuleName: 'my-context-module',
});
const require = prepareRequire({
currentDirname: __dirname + '/tasks',
payload: { myContextValueABC: 'abc321' },
});
const contextified = require('./module1');
console.log(contextified()); // -> abc321