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.1 to 0.9.2

tests/test6_a.js

18

index.js

@@ -28,6 +28,20 @@ 'use strict';

if ( this.invalidable )
this._exports = null;
if ( !this.invalidable )
return;
if ( '_invalidateCallbacks' in this ) {
this._invalidateCallbacks.forEach(callback => callback(this._exports));
this._invalidateCallbacks.clear();
}
this._exports = null;
}
Module.prototype.onInvalidate = function(callback) {
var invalidateCallbacks = this._invalidateCallbacks || (this._invalidateCallbacks = new Set);
return invalidateCallbacks.add(callback).delete.bind(invalidateCallbacks, callback);
}
function reload(mod) {

@@ -34,0 +48,0 @@

2

package.json
{
"name": "module-invalidate",
"version": "0.9.1",
"version": "0.9.2",
"description": "invalidate required modules",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,3 +11,3 @@ # module-invalidate

`npm install --save FranckFreiburger/module-invalidate`
`npm install --save module-invalidate`

@@ -156,3 +156,3 @@

##### Module.invalidateByExports(exports)
Invalidates the module by giving its exported object. The module should have been flagged as invalidable using `module.invaluable`.
Invalidates the module by giving its exported object. The module should have been flagged as invalidable using `module.invaluable`.

@@ -166,3 +166,38 @@ ###### Example:

`invalidateByExports()` only invalidates one module
module `B.js`
```
module.invalidable = true;
console.log('load B');
module.exports = {
foo: 123
}
```
module `A.js`
```
module.invalidable = true;
console.log('load A');
module.exports = require('./B.js');
```
main module `index.js`
```
require('module-invalidate');
var a = require('./A.js');
console.log('invalidate');
module.constructor.invalidateByExports(a);
var tmp = a.foo;
```
output:
```
load A
load B
invalidate
load A
```
##### Module.invalidate()

@@ -186,3 +221,8 @@ Invalidates all nodejs-non-internal modules. Only process modules that have been flagged as invalidable using `module.invaluable`.

##### module.onInvalidate(callback)
callback: `function(immutable_exports)`
Register a callback that will be called when the module is invalidated. The `immutable_exports` is a permanent reference to the current module.exports .
## How it works

@@ -217,14 +257,42 @@

#### Invalidated modules may survive with new sub-module versions
Any reference to an invalidated module will continue to live with its new version.
#### Invalidated modules will survive with the new child-module version
In a module, `module.exports` will always refers to the latest version of the module.
module `./child.js`
```
TBD example
module.invalidable = true;
module.exports = {};
setInterval(function() {
console.log(module.exports.foo);
}, 1000);
```
main module `index.js`
```
require('module-invalidate');
var child = require('./child.js');
child.foo = 1;
module.constructor.invalidateByExports(child);
child.foo = 2;
```
output:
```
2
2
2
2
2
...
```
## To be done
1. allow module to be aware of their invalidation.
## Credits

@@ -231,0 +299,0 @@

require('../index.js');
var ffi = require('ffi');
var libm = new ffi.Library('msvcrt', {
'ceil': [ 'double', [ 'double' ] ]
module.on('invalidated', function() {
})
console.log(libm.ceil(1.1));
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