Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 806e4bb

Browse files
committed
- Improved client-side rewire() with webpack
- Fixed webpack-version in "devDependencies"
1 parent 7b21f0f commit 806e4bb

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
##Changelog
22

3+
###v1.0.4
4+
- Improved client-side rewire() with webpack
5+
36
###v1.0.3
47
- Fixed error with client-side bundlers when a module was ending with a comment
58

lib/bundlers/webpack/webpackRewire.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,13 @@ var requireInDisguise;
77

88
eval("requireInDisguise = require");
99

10-
function getId(module) {
11-
var index = registry.modules.indexOf(module);
12-
13-
return registry.id[index] || null;
14-
}
15-
16-
function getIdFromCache(module) {
10+
function getModuleId(exports) {
1711
var cache = require.cache,
1812
id;
1913

2014
for (id in cache) {
2115
if (cache.hasOwnProperty(id)) {
22-
if (cache[id] === module) {
23-
return Number(id);
24-
}
25-
}
26-
}
27-
28-
return null;
29-
}
30-
31-
function getIdByExportsObj(moduleExports) {
32-
var id,
33-
entry;
34-
35-
for (id in registry) {
36-
if (registry.hasOwnProperty(id)) {
37-
entry = registry[id];
38-
if (entry.module.exports === moduleExports) {
16+
if (cache[id].exports === exports) {
3917
return Number(id);
4018
}
4119
}
@@ -45,7 +23,7 @@ function getIdByExportsObj(moduleExports) {
4523
}
4624

4725
function webpackRewire(path, moduleExports) {
48-
var id = getIdByExportsObj(moduleExports),
26+
var id = getModuleId(moduleExports),
4927
previousRegistryEntry,
5028
cachedModule,
5129
rewiredModule,
@@ -75,7 +53,7 @@ function webpackRewire(path, moduleExports) {
7553
}
7654

7755
webpackRewire.register = function (module, setter, getter) {
78-
var id = getIdFromCache(module);
56+
var id = module.id;
7957

8058
registry[id] = {
8159
module: module,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "rewire",
3-
"version" : "1.0.3",
3+
"version" : "1.0.4",
44
"description" : "Dependency injection for node.js applications",
55
"keywords" : [
66
"dependency",
@@ -33,7 +33,7 @@
3333
"mocha": "1.x",
3434
"expect.js": "0.x",
3535
"browserify": "1.x",
36-
"webpack": "0.x"
36+
"webpack": "0.8.x"
3737
},
3838
"scripts" : {
3939
"test" : "node node_modules/mocha/bin/mocha -R spec"

0 commit comments

Comments
 (0)