Socket
Socket
Sign inDemoInstall

rewire

Package Overview
Dependencies
102
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0 to 6.0.0

.github/workflows/test.yml

6

CHANGELOG.md
Changelog
---------
### 6.0.0
- **Breaking**: Remove Node v8 support. We had to do this because one of our dependencies had security issues and the version with the fix dropped Node v8 as well.
- Update dependencies [#193](https://github.com/jhnns/rewire/issues/193)
- Fix Modifying globals within module leaks to global with Node >=10 [#167](https://github.com/jhnns/rewire/issues/167)
- Fixed import errors on modules with shebang declarations [#179](https://github.com/jhnns/rewire/pull/179)
### 5.0.0

@@ -5,0 +11,0 @@ - **Breaking**: Remove Node v6 support. We had to do this because one of our dependencies had security issues and the version with the fix dropped Node v6 as well.

0

lib/__get__.js

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ var multiLineComment = /^\s*\/\*.*?\*\//;

28

lib/getImportGlobalsSrc.js

@@ -12,3 +12,2 @@ /**

var key,
value,
src = "",

@@ -18,14 +17,25 @@ globalObj = typeof global === "undefined"? window: global;

ignore = ignore || [];
// global itself can't be overridden because it's the only reference to our real global objects
ignore.push("global");
// ignore 'module', 'exports' and 'require' on the global scope, because otherwise our code would
// shadow the module-internal variables
// @see https://github.com/jhnns/rewire-webpack/pull/6
ignore.push("module", "exports", "require");
ignore.push(
// global itself can't be overridden because it's the only reference to our real global objects
"global",
// ignore 'module', 'exports' and 'require' on the global scope, because otherwise our code would
// shadow the module-internal variables
// @see https://github.com/jhnns/rewire-webpack/pull/6
"module", "exports", "require",
// strict mode doesn't allow to (re)define 'undefined', 'eval' & 'arguments'
"undefined", "eval", "arguments",
// 'GLOBAL' and 'root' are deprecated in Node
// (assigning them causes a DeprecationWarning)
"GLOBAL", "root",
// 'NaN' and 'Infinity' are immutable
// (doesn't throw an error if you set 'var NaN = ...', but doesn't work either)
"NaN", "Infinity",
);
for (key in globalObj) { /* jshint forin: false */
const globals = Object.getOwnPropertyNames(globalObj);
for (key of globals) {
if (ignore.indexOf(key) !== -1) {
continue;
}
value = globalObj[key];

@@ -32,0 +42,0 @@ // key may be an invalid variable name (e.g. 'a-b')

@@ -46,2 +46,4 @@ "use strict";

matchConst = /(^|\s|\}|;)const(\/\*|\s|{)/gm,
// Required for importing modules with shebang declarations, since NodeJS 12.16.0
shebang = /^#!.+/,
nodeRequire,

@@ -127,3 +129,5 @@ currentModule;

module,
content.replace(matchConst, "$1let $2"), // replace const with let, while maintaining the column width
content
.replace(shebang, '') // Remove shebang declarations
.replace(matchConst, "$1let $2"), // replace const with let, while maintaining the column width
filename

@@ -130,0 +134,0 @@ );

{
"name": "rewire",
"version": "5.0.0",
"version": "6.0.0",
"description": "Easy dependency injection for node.js unit testing",

@@ -35,3 +35,4 @@ "keywords": [

"expect.js": "^0.3.1",
"mocha": "^7.1.0",
"mocha": "^9.1.2",
"nyc": "^15.1.0",
"rewire": "file://."

@@ -41,8 +42,7 @@ },

"scripts": {
"test": "mocha -R spec",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha"
"test": "nyc --reporter=html --reporter=lcov mocha -R spec"
},
"dependencies": {
"eslint": "^6.8.0"
"eslint": "^7.32.0"
}
}

@@ -180,7 +180,3 @@ // Don't run code in ES5 strict mode.

// This test fails on modern Node versions since they started to configure some
// global variables to be non-enumerable. This means that rewire() does in fact
// modify the global console object in newer Node versions.
// There is a work in progress fix at https://github.com/jhnns/rewire/tree/fix-globals
it.skip("should provide the ability to mock global objects just within the module", function () {
it("should provide the ability to mock global objects just within the module", function () {
var rewiredModuleA = rewire("./moduleA.js"),

@@ -288,3 +284,14 @@ rewiredModuleB = rewire("./moduleB.js"),

} catch (err) {
expect(err.stack.split("\n")[1]).to.match(/:6:26/);
// Firefox implements a different error-stack format,
// but does offer line and column numbers on errors: we use
// those instead.
if (err.lineNumber !== undefined && err.columnNumber !== undefined) {
expect(err.lineNumber).to.equal(6)
expect(err.columnNumber).to.equal(26)
}
// This is for the V8 stack trace format (Node, Chrome)
else {
expect(err.stack.split("\n")[1]).to.match(/:6:26/);
}
}

@@ -413,2 +420,9 @@ });

it("should be possible to rewire shebang modules", function () {
var shebangModule = rewire("./shebangModule");
var shebangs = shebangModule.__get__("shebangs");
expect(typeof shebangs).to.be("function");
expect(shebangModule.shebangs()).to.be(true);
});
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc