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.3 to 0.9.4

test.js

36

index.js

@@ -53,4 +53,6 @@ 'use strict';

const boundCached = Symbol();
function createProxy(mod) {
return new Proxy(function() {}, {

@@ -85,2 +87,5 @@

mod._exports === null && reload(mod);
if ( prop === 'prototype' && typeof(mod._exports) !== 'function' ) // see ownKeys
return {};
return Reflect.getOwnPropertyDescriptor(mod._exports, prop);

@@ -106,6 +111,21 @@ },

// see http://stackoverflow.com/questions/42496414/illegal-invocation-error-using-es6-proxy-and-node-js
// see https://github.com/nodejs/node/issues/11629
//var val = Reflect.get(mod._exports, property, receiver);
//return typeof(val) === 'function' ? val.bind(mod._exports) : val;
return Reflect.get(mod._exports, property, receiver);
// see https://github.com/nodejs/node/issues/11629 (Illegal invocation error using ES6 Proxy and node.js)
// see http://stackoverflow.com/questions/42594682/how-to-determine-that-a-javascript-function-is-native-without-testing-native
//return Reflect.get(mod._exports, property, receiver); // fails with native functions
var val = Reflect.get(mod._exports, property);
if ( typeof(val) === 'function' ) { // TBD: bind native functions only
// needed for native function, like Promise.resolve().then, ...
if ( boundCached in val )
return val[boundCached];
var bound = val.bind(mod._exports);
Object.setPrototypeOf(bound, val); // see test "exports property on function"
val[boundCached] = bound;
return bound;
}
return val;
},

@@ -116,3 +136,3 @@

mod._exports === null && reload(mod);
return Reflect.set(mod._exports, property, value, receiver);
return Reflect.set(mod._exports, property, value);
},

@@ -130,4 +150,4 @@

// see https://tc39.github.io/ecma262/#sec-invariants-of-the-essential-internal-methods
throw new TypeError('ownKeys not implemented');
//return [...Reflect.ownKeys(target), ...Reflect.ownKeys(mod._exports)];
//throw new TypeError('ownKeys not implemented');
return Reflect.ownKeys(target).concat(Reflect.ownKeys(mod._exports));
//return Reflect.ownKeys(mod._exports);

@@ -134,0 +154,0 @@ },

{
"name": "module-invalidate",
"version": "0.9.3",
"version": "0.9.4",
"description": "invalidate required modules",
"main": "index.js",
"scripts": {},
"scripts": {
"test": "mocha"
},
"author": "Franck Freiburger",
"license": "MIT",
"devDependencies": {
"ffi": "^2.2.0"
"ffi": "^2.2.0",
"mocha": "^3.2.0"
},
"repository" : {
"type" : "git",
"url" : "git@github.com:FranckFreiburger/module-invalidate.git"
"repository": {
"type": "git",
"url": "git@github.com:FranckFreiburger/module-invalidate.git"
},

@@ -20,3 +23,2 @@ "bugs": {

"homepage": "https://github.com/FranckFreiburger/module-invalidate#readme"
}

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

## Description
`module-invalidate` allows you to invalidate a given module (or all modules) and make it automatically reloaded on further access.
`module-invalidate` allows you to invalidate a given module (or all modules) and make it automatically reloaded on further access, no need to call `require()` again.

@@ -18,5 +18,5 @@

### example: simple case
##### Example: simple case
module `./myModule.js`
###### module `./myModule.js`
```JavaScript

@@ -32,3 +32,3 @@ module.invalidable = true;

main module `./index.js`
###### main module `./index.js`
```JavaScript

@@ -49,3 +49,3 @@ require('module-invalidate');

### example: invalidate module on modification
##### Example: invalidate module on modification

@@ -69,3 +69,3 @@ ```JavaScript

### example:
##### Example:

@@ -90,3 +90,3 @@ ```JavaScript

### example:
##### Example:

@@ -132,3 +132,3 @@ ```JavaScript

#### require('module-invalidate')
#### `require('module-invalidate')`
Enable the module-invalidate mechanism.

@@ -138,7 +138,7 @@ Any nodejs-non-internal module loaded after this call can be handled by this library.

#### module.invalidable
This property controls whether the module can be invalidated. By default, modules are not invalidable. This property must be set before exporting.
#### `module.invalidable`
This property controls whether the module can be invalidated. By default, modules are not invalidable.
###### Example:
module `./myModule.js`
##### Example:
###### module `./myModule.js`
```JavaScript

@@ -151,6 +151,6 @@ module.invalidable = true;

#### module.invalidateByPath(path)
#### `module.invalidateByPath(path)`
Invalidates the specified module by its path (same syntax and context than `require()`). The module should have been flagged as invalidable using `module.invaluable`.
###### Example:
##### Example:
```JavaScript

@@ -163,6 +163,6 @@ require('module-invalidate');

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

@@ -174,4 +174,4 @@ require('module-invalidate');

`invalidateByExports()` only invalidates one module
module `B.js`
`invalidateByExports()` only invalidates one module.
###### module `B.js`
```

@@ -185,3 +185,3 @@ module.invalidable = true;

module `A.js`
###### module `A.js`
```

@@ -194,3 +194,3 @@ module.invalidable = true;

main module `index.js`
###### main module `index.js`
```

@@ -213,6 +213,6 @@ require('module-invalidate');

#### Module.invalidate()
#### `Module.invalidate()`
Invalidates all nodejs-non-internal modules. Only process modules that have been flagged as invalidable using `module.invaluable`.
###### Example:
##### Example:
```JavaScript

@@ -224,6 +224,6 @@ require('module-invalidate');

#### module.invalidate()
#### `module.invalidate()`
Invalidates the module `module`. The module should have been flagged as invalidable using `module.invaluable`.
###### Example:
##### Example:
```JavaScript

@@ -233,15 +233,15 @@ module.invalidate();

#### module.unload()
#### `module.unload()`
Definitely unloads the module `module`.
#### module.unloadByPath(path)
#### `module.unloadByPath(path)`
Definitely unloads the module by its path (same syntax and context than `require()`).
#### Module.unloadByExports(exports)
#### `Module.unloadByExports(exports)`
Definitely unloads the module by giving its exported object.
#### module.onInvalidate(callback)
#### `module.onInvalidate(callback)`
callback: `function(immutable_exports)`

@@ -263,15 +263,11 @@

#### `typeof module.exports` is always 'function'
#### ownKeys is not supported
Because the library is unable to know in advance what type of value will be assigned to `module.export`, it choose the most generic one as ES6 Proxy target.
However, `(function(){}) instanceof Object === true`
Reflect.ownKeys(), Object.keys(), for-in loop, console.log(), ... are not available on the module exports (only).
eg.
```
Object.keys(require('foo.js'));
```
will throw a `TypeError: ownKeys not implemented` exception.
However for-of loop works properly.
#### Only direct variable access is handled
#### Only direct variable access is handled
##### Example:
```

@@ -287,4 +283,5 @@ var foo = require('foo.js');

##### Example:
module `./child.js`
###### module `./child.js`
```

@@ -300,3 +297,3 @@ module.invalidable = true;

main module `index.js`
###### main module `index.js`
```

@@ -311,3 +308,3 @@ require('module-invalidate');

output:
###### output
```

@@ -324,5 +321,2 @@ 2

## To be done
## Credits

@@ -329,0 +323,0 @@

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