Socket
Socket
Sign inDemoInstall

rewire

Package Overview
Dependencies
0
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

.idea/libraries/sass_stdlib.xml

3

CHANGELOG.md
##Changelog
###v1.0.4
- Improved client-side rewire() with webpack
###v1.0.3

@@ -4,0 +7,0 @@ - Fixed error with client-side bundlers when a module was ending with a comment

30

lib/bundlers/webpack/webpackRewire.js

@@ -10,9 +10,3 @@ "use strict"; // run code in ES5 strict mode

function getId(module) {
var index = registry.modules.indexOf(module);
return registry.id[index] || null;
}
function getIdFromCache(module) {
function getModuleId(exports) {
var cache = require.cache,

@@ -23,3 +17,3 @@ id;

if (cache.hasOwnProperty(id)) {
if (cache[id] === module) {
if (cache[id].exports === exports) {
return Number(id);

@@ -33,20 +27,4 @@ }

function getIdByExportsObj(moduleExports) {
var id,
entry;
for (id in registry) {
if (registry.hasOwnProperty(id)) {
entry = registry[id];
if (entry.module.exports === moduleExports) {
return Number(id);
}
}
}
return null;
}
function webpackRewire(path, moduleExports) {
var id = getIdByExportsObj(moduleExports),
var id = getModuleId(moduleExports),
previousRegistryEntry,

@@ -81,3 +59,3 @@ cachedModule,

webpackRewire.register = function (module, setter, getter) {
var id = getIdFromCache(module);
var id = module.id;

@@ -84,0 +62,0 @@ registry[id] = {

{
"name" : "rewire",
"version" : "1.0.3",
"version" : "1.0.4",
"description" : "Dependency injection for node.js applications",

@@ -36,3 +36,3 @@ "keywords" : [

"browserify": "1.x",
"webpack": "0.x"
"webpack": "0.8.x"
},

@@ -39,0 +39,0 @@ "scripts" : {

@@ -16,2 +16,4 @@ rewire

[![Build Status](https://secure.travis-ci.org/jhnns/rewire.png?branch=master)](http://travis-ci.org/jhnns/rewire)
[![Dependency Status](http://david-dm.org/jhnns/rewire/status.png)](http://david-dm.org/jhnns/rewire)
Dependency tracking by [David](http://david-dm.org/)

@@ -30,10 +32,34 @@ <br />

Imagine you want to test this module:
```javascript
// lib/myModule.js
// With rewire you can change all these variables
var fs = require("fs"),
http = require("http"),
someOtherVar = "hi",
myPrivateVar = 1;
function readSomethingFromFileSystem(cb) {
// But no scoped variables
var path = "/somewhere/on/the/disk";
console.log("Reading from file system ...");
fs.readFile(path, "utf8", cb);
}
exports.readSomethingFromFileSystem = readSomethingFromFileSystem;
```
Now within your test module:
```javascript
// test/myModule.test.js
var rewire = require("rewire");
// rewire acts exactly like require.
var myModule = rewire("../lib/myModule.js");
// Just with one difference:

@@ -44,3 +70,2 @@ // Your module will now export a special setter and getter for private variables.

// This allows you to mock almost everything within the module e.g. the fs-module.

@@ -57,3 +82,2 @@ // Just pass the variable name as first parameter and your mock as second.

// You can set different variables with one call.

@@ -66,3 +90,2 @@ myModule.__set__({

// You may also override globals. These changes are only within the module, so

@@ -79,3 +102,2 @@ // you don't have to be concerned that other modules are influenced by your mock.

// But be careful, if you do something like this you'll change your global

@@ -120,6 +142,6 @@ // console instance.

- [browserify](https://github.com/substack/node-browserify)
- [webpack](https://github.com/webpack/webpack)
- [webpack](https://github.com/webpack/webpack) < 0.9.x
**Please note:** Unfortunately the line numbers in stack traces have an offset of +2 (browserify) / +1 (webpack).
This is caused by generated code that is added during the bundling process. I'm working on that ... :)
This is caused by generated code that is added during the bundling process.

@@ -142,2 +164,4 @@ ###browserify

rewire doesn't run with webpack 0.9 because of various breaking api changes. I'm working on that.
```javascript

@@ -154,2 +178,2 @@ var webpackOptions = {

webpack("entry.js", webpackOptions, function () {});
```
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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