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.0 to 1.0.1

lib/bundlers/webpack/getLoaderTestRegExp.js

5

CHANGELOG.md
##Changelog
###v1.0.1
- Fixed crash when a global module has been used in the browser
###v1.0.0
- Removed caching functionality. Now rewire doesn't modify `require.cache` at all.
- Removed caching functionality. Now rewire doesn't modify `require.cache` at all
- Added support for [webpack](https://github.com/webpack/webpack)-bundler
- Moved browserify-middleware from `rewire.browserify` to `rewire.bundlers.browserify`
- Reached stable state :)

40

lib/bundlers/webpack/webpackPostLoader.js

@@ -9,4 +9,6 @@ "use strict"; // run code in ES5 strict mode

rewireLib = path.join("rewire", "lib"),
webpackBuildin = path.join("webpack", "buildin", "__webpack"),
rewireLib = path.resolve(__dirname, "../../"),
projectBasePath = path.resolve(__dirname, "../../../../../"),
nodeModulesPath = path.join(projectBasePath, "node_modules"),
webpackPath = path.join("node_modules", "webpack"),
settersAndGettersSrc;

@@ -24,12 +26,7 @@

*/
function webpackLoader(src) {
function webpackPostLoader(src) {
var filename = this.request.split("!").pop(),
rewireRegExp = getRewireRegExp();
// We don't want to inject this code at the beginning of a rewire/lib-module. Otherwise
// it would cause a black hole that devours our universe.
// We're also omitting webpack's buildin because it doesn't makes sense to rewire these modules. There's also
// a bug if the special code is injecting into these modules.
if (filename.indexOf(rewireLib) === -1 && filename.indexOf(webpackBuildin) === -1) {
if (isRewireableModule(filename)) {
// replaces rewire("some/path") into rewire("some/path", require("some/path"))

@@ -45,6 +42,25 @@ src = src.replace(rewireRegExp, '$1rewire("$2", require("$2"))');

webpackLoader.loader = __filename;
webpackLoader.test = /\.js$/;
webpackPostLoader.loader = __filename;
webpackPostLoader.test = /\.js$/;
/**
* Returns true if the module is rewireable. Rewireable are all modules of the project.
*
* Example:
* Imagine rewire lies under "~/myProject/node_modules/rewire". All files in "~/myProject" are rewireable except
* the "~/myProject/node_modules"-path.
*
* @param {!String} path
* @return {Boolean}
*/
function isRewireableModule(path) {
return path.indexOf(projectBasePath) !== -1 &&
path.indexOf(nodeModulesPath) === -1 &&
// "rewire/lib" and "node_modules/webpack" are explicitly excluded to make the tests work
path.indexOf(rewireLib) === -1 &&
path.indexOf(webpackPath) === -1;
}
/**
* This string gets injected at the beginning of every module. Its purpose is to

@@ -67,2 +83,2 @@ * - register the setters and getters according to the module's filename

module.exports = webpackLoader;
module.exports = webpackPostLoader;
{
"name" : "rewire",
"version" : "1.0.0",
"version" : "1.0.1",
"description" : "Dependency injection for node.js applications",

@@ -20,5 +20,5 @@ "keywords" : [

"main" : "lib/index.js",
"homepage": "http://jhnns.github.com/rewire",
"homepage": "https://github.com/jhnns/rewire",
"bugs" : {
"url" : "http://github.com/jhnns/rewire/issues",
"url" : "https://github.com/jhnns/rewire/issues",
"email" : "mail@johannesewald.de"

@@ -25,0 +25,0 @@ },

@@ -116,7 +116,17 @@ rewire

**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 ... :)
###browserify
```javascript
var b = browserify();
var b = browserify(),
bundleSrc;
// Add rewire as browserify middleware
// @see https://github.com/substack/node-browserify/blob/master/doc/methods.markdown#busefn
b.use(require("rewire").bundlers.browserify);
b.addEntry("entry.js");
bundleSrc = b.bundle();
```

@@ -127,5 +137,12 @@

```javascript
var options = {};
var webpackOptions = {
output: "bundle.js"
};
require("rewire").bundlers.webpack(options);
// This function modifies the webpack options object.
// It adds a postLoader and postProcessor to the bundling process.
// @see https://github.com/webpack/webpack#programmatically-usage
require("rewire").bundlers.webpack(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