Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

module-invalidate

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

module-invalidate - npm Package Compare versions

Comparing version 0.9.6 to 0.9.7

1

index.js

@@ -33,2 +33,3 @@ 'use strict';

Object.setPrototypeOf(bound, fct); // see test "exports property on function"
delete bound.name; // preserves the bound function name
return bound;

@@ -35,0 +36,0 @@ }

39

package.json
{
"name": "module-invalidate",
"version": "0.9.6",
"version": "0.9.7",
"description": "invalidate required modules",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"keywords": [
"module",
"require",
"invalidate",
"reload",
"unload"
],
"author": "Franck Freiburger",
"license": "MIT",
"devDependencies": {
"benchmark": "^2.1.3",
"ffi": "^2.2.0",
"mocha": "^3.2.0"
},
"homepage": "https://github.com/FranckFreiburger/module-invalidate#readme",
"repository": {

@@ -20,6 +26,17 @@ "type": "git",

},
"bugs": {
"url": "https://github.com/FranckFreiburger/module-invalidate/issues"
},
"homepage": "https://github.com/FranckFreiburger/module-invalidate#readme"
"main": "index.js",
"scripts": {
"test": "mocha"
},
"devDependencies": {
"benchmark": "^2.1.3",
"ffi": "^2.2.0",
"mocha": "^3.2.0"
}
}

@@ -70,23 +70,2 @@ # module-invalidate

var foo = require('foo');
console.log(foo.bar); // a value
// -- 'foo' module has changed --
myFooBarSystem.on('reloadModules', function() {
module.constructor.invalidateByExports(foo);
console.log(foo.bar); // a new value
})
```
##### Example:
```JavaScript
require('module-invalidate');
var tmp_modulePath = require('path').join(__dirname, 'tmp_module.js');

@@ -99,7 +78,8 @@

var tmp_module = require('./tmp_module.js');
console.log(tmp_module.a); // 1
require('fs').writeFileSync(tmp_modulePath, `

@@ -110,7 +90,7 @@ module.invalidable = true;

module.constructor.invalidateByExports(tmp_module);
module.invalidateByPath('./tmp_module.js'); // or module.constructor.invalidateByExports(tmp_module)
console.log(tmp_module.a); // 2
require('fs').unlinkSync(tmp_modulePath);

@@ -117,0 +97,0 @@

@@ -14,3 +14,8 @@ var assert = require('assert');

`);
assert.equal(typeof mod.module.exports, 'object');
mod.module.invalidate();
assert.equal(typeof mod.module.exports, 'object');
});

@@ -25,3 +30,8 @@

`);
assert.equal(typeof mod.module.exports, 'function');
mod.module.invalidate();
assert.equal(typeof mod.module.exports, 'function');
});

@@ -39,2 +49,6 @@

assert.equal(mod.module.exports.foo, 'bar');
mod.module.invalidate();
assert.equal(mod.module.exports.foo, 'bar');
});

@@ -49,5 +63,11 @@

`);
assert.equal(mod.module.exports(), 'foo');
mod.module.invalidate();
assert.equal(mod.module.exports(), 'foo');
});
it('exports type constructor', function() {

@@ -69,3 +89,5 @@

assert.equal(new mod.module.exports().getValue(), 123);
module.constructor.invalidateByExports(mod.module.exports);
assert.equal(new mod.module.exports().getValue(), 123);

@@ -100,5 +122,12 @@ });

`);
assert.equal(mod.module.exports[1], 2);
assert.equal(mod.module.exports.length, 3);
assert.equal(typeof mod.module.exports.map, 'function');
module.constructor.invalidateByExports(mod.module.exports);
assert.equal(mod.module.exports[1], 2);
assert.equal(mod.module.exports.length, 3);
assert.equal(typeof mod.module.exports.map, 'function');
});

@@ -115,3 +144,4 @@

assert.equal(mod.module.exports, 'foo');
//assert.throws(function() { mod.module.exports.length }, /TypeError/);
module.constructor.invalidateByExports(mod.module.exports);
assert.equal(mod.module.exports, 'foo');
});

@@ -132,3 +162,5 @@

mod.set();
mod.module.invalidate();
assert.equal(mod.module.exports, 456);

@@ -179,2 +211,4 @@ });

assert.equal(Object.keys(mod.module.exports).join(), 'a,b');
mod.module.invalidate();
assert.equal(Object.keys(mod.module.exports).join(), 'a,b');
});

@@ -194,2 +228,9 @@

assert.equal(res, 'a1b2');
mod.module.invalidate();
for ( var prop in mod.module.exports )
res += prop + mod.module.exports[prop];
assert.equal(res, 'a1b2a1b2');
});

@@ -210,2 +251,9 @@

assert.equal(val, 6);
mod.module.invalidate();
for ( var v of mod.module.exports )
val += v;
assert.equal(val, 12);
});

@@ -231,7 +279,55 @@

//assert.equal(mod.module.exports.constructor.name, 'ctor');
assert.equal(mod.module.exports.constructor.name, 'ctor');
assert.equal(mod.module.exports.foo(), 123);
mod.module.invalidate();
assert.equal(mod.module.exports.constructor.name, 'ctor');
assert.equal(mod.module.exports.foo(), 123);
});
it('exports keep method name', function() {
var mod = new utils.TmpModule(`
module.invalidable = true;
function ctor() {
this.foo = function foo() {
}
this.bar = function() {
}
}
module.exports = new ctor;
`);
assert.equal(mod.module.exports.constructor.name, 'ctor');
assert.equal(mod.module.exports.foo.name, 'foo');
assert.equal(mod.module.exports.bar.name, '');
mod.module.invalidate();
assert.equal(mod.module.exports.constructor.name, 'ctor');
assert.equal(mod.module.exports.foo.name, 'foo');
assert.equal(mod.module.exports.bar.name, '');
});
it('exports keep function name', function() {
var mod = new utils.TmpModule(`
module.invalidable = true;
function myFct() {
}
module.exports = myFct;
`);
assert.equal(mod.module.exports.name, 'myFct');
mod.module.invalidate();
assert.equal(mod.module.exports.name, 'myFct');
});
it('property on function', function() {

@@ -250,2 +346,8 @@

assert.equal(mod.module.exports.foo.bar, 456);
mod.module.invalidate();
assert.equal(typeof mod.module.exports.foo, 'function');
assert.equal(mod.module.exports.foo(), 123);
assert.equal(mod.module.exports.foo.bar, 456);
});

@@ -265,2 +367,8 @@

assert.equal(mod.module.exports.foo.bar, 456);
mod.module.invalidate();
assert.equal(typeof mod.module.exports.foo, 'function');
assert.equal(mod.module.exports.foo(), 123);
assert.equal(mod.module.exports.foo.bar, 456);
});

@@ -278,3 +386,8 @@

assert.equal(typeof mod.module.exports.foo, 'function');
assert.equal(mod.module.exports.foo.bar, 456);
assert.equal(mod.module.exports.foo(), 123);
mod.module.invalidate();
assert.equal(typeof mod.module.exports.foo, 'function');
assert.equal(mod.module.exports.foo.bar, 456);

@@ -281,0 +394,0 @@ assert.equal(mod.module.exports.foo(), 123);

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