diff --git a/CHANGELOG.md b/CHANGELOG.md old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/lib/RewirePlugin.js b/lib/RewirePlugin.js old mode 100644 new mode 100755 index 1fcc0db..8c4fa02 --- a/lib/RewirePlugin.js +++ b/lib/RewirePlugin.js @@ -10,44 +10,67 @@ function RewirePlugin() {} RewirePlugin.prototype.apply = function (compiler) { // wire our RewiredDependency to our RewiredNormalModuleFactory // by decorating the original factory - compiler.plugin("compilation", function(compilation, params) { - var normalModuleFactory = params.normalModuleFactory, - rewiredNormalModuleFactory = new RewiredNormalModuleFactory(normalModuleFactory); + compiler.plugin("compilation", function(compilation, data) { + var normalModuleFactory = data.normalModuleFactory + var rewiredNormalModuleFactory = new RewiredNormalModuleFactory(normalModuleFactory); compilation.dependencyFactories.set(RewiredDependency, rewiredNormalModuleFactory); compilation.dependencyTemplates.set(RewiredDependency, new RewiredDependency.Template()); }); - // accept "var rewire", elsewise it would not be parsed (as overwritten) - compiler.parser.plugin("var rewire", function () { - return true; - }); + compiler.plugin("compilation", function(compilation, data) { + data.normalModuleFactory.plugin("parser", function(parser, options) { + // accept "var rewire", elsewise it would not be parsed (as overwritten) + parser.plugin("var rewire", function() { + console.log('var rewire body') + return true; + }); - // find rewire(request: String) calls and bind our RewiredDependency - compiler.parser.plugin("call rewire", function (expr) { - var param, - dep; + // find rewire(request: String) calls and bind our RewiredDependency + parser.plugin("call rewire", function (expr) { + console.log('call rewire body') + var param, + dep; - if (expr.arguments.length !== 1) { - return false; - } + if (expr.arguments.length !== 1) { + return false; + } + console.log('call rewire body 1') - param = this.evaluateExpression(expr.arguments[0]); - if (!param.isString()) { - return false; - } + param = this.evaluateExpression(expr.arguments[0]); + if (!param.isString()) { + return false; + } - dep = new RewiredDependency(param.string, param.range); - dep.loc = expr.loc; - this.state.current.addDependency(dep); + console.log('call rewire body 2') - return true; - }); + dep = new RewiredDependency(param.string, param.range); + dep.loc = expr.loc; + console.log('call rewire body 3') + this.state.current.addDependency(dep); + console.log('call rewire body 4') + + return true; + }); + }); + }) // alias the require("rewire") to a webpack rewire - compiler.resolvers.normal.apply(new ModuleAliasPlugin({ - rewire: path.join(__dirname, "rewire.web.js") - })); + //compiler.resolvers.normal.apply(new ModuleAliasPlugin({ + // rewire: path.join(__dirname, "rewire.web.js") + //})); + if (!compiler.options) { + compiler.options = {}; + } + if (!compiler.options.resolve) { + compiler.options.resolve = {}; + } + if (!compiler.options.resolve.alias) { + compiler.options.resolve.alias = {}; + } + if (!compiler.options.resolve.alias.rewire) { + compiler.options.resolve.alias.rewire = path.join(__dirname, "rewire.web.js"); + } }; module.exports = RewirePlugin; \ No newline at end of file diff --git a/lib/RewiredDependency.js b/lib/RewiredDependency.js index 0b40a8d..b00e51d 100644 --- a/lib/RewiredDependency.js +++ b/lib/RewiredDependency.js @@ -3,7 +3,7 @@ var Dependency = require("webpack/lib/Dependency.js"); function RewiredDependency(request, range) { - Dependency.call(this); + this.module = null; this.request = request; this.userRequest = request; this.Class = RewiredDependency; diff --git a/lib/RewiredNormalModuleFactory.js b/lib/RewiredNormalModuleFactory.js old mode 100644 new mode 100755 index f2fa64d..f23a9ae --- a/lib/RewiredNormalModuleFactory.js +++ b/lib/RewiredNormalModuleFactory.js @@ -15,6 +15,8 @@ RewiredNormalModuleFactory.prototype.create = function (context, dependency, cal module.request += " rewired"; module.userRequest += " (rewired)"; module.loaders.unshift(path.join(__dirname, "rewire.loader.js")); + console.log('module.loaders is now') + console.log(module.loaders) return callback(null, module); }); diff --git a/lib/rewire.loader.js b/lib/rewire.loader.js old mode 100644 new mode 100755 index f516a69..455a75c --- a/lib/rewire.loader.js +++ b/lib/rewire.loader.js @@ -32,6 +32,9 @@ function rewireLoader(src) { // append at least a newline, the source may end with a line comment "\n" + getDefinePropertySrc() + " })();"; + console.log('in rewireLoader. src is:') + console.log(src) + return src; } diff --git a/lib/rewire.web.js b/lib/rewire.web.js old mode 100644 new mode 100755 index aed0808..69784a8 --- a/lib/rewire.web.js +++ b/lib/rewire.web.js @@ -2,13 +2,23 @@ function rewire(module) { var rewiredModule = { - id: module, - loaded: false, + i: module, + l: false, exports: {} }; + //console.log('in rewire.web.js') + //console.log(__webpack_modules__[module]) + //console.log(__webpack_modules__) + //console.log(__webpack_require__.m) + //console.log(__webpack_require__.m[module]) + //console.log('module is') + //console.log(module) + //console.log(__webpack_require__.m) __webpack_modules__[module].call(rewiredModule.exports, rewiredModule, rewiredModule.exports, __webpack_require__); - rewiredModule.loaded = true; + rewiredModule.l = true; + console.log(rewiredModule) + console.log(rewiredModule.__get__) return rewiredModule.exports; } diff --git a/package.json b/package.json index 2ca3ed9..5d6598d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "license": "Unlicense", "dependencies": { "enhanced-resolve": "^0.9.1", - "webpack": "^1.12.6" + "webpack": "^2.2.0" }, "devDependencies": { "expect.js": "^0.3.1",