circular-dependency-plugin
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -69,2 +69,31 @@ var webpack = require('webpack'); | ||
}); | ||
it('can exclude cyclical deps from being output', (done) => { | ||
var s = sandbox.stub(console, 'warn', console.warn); | ||
var fs = new MemoryFS(); | ||
var c = webpack({ | ||
entry: path.join(__dirname, 'deps/d.js'), | ||
output: { path: __dirname }, | ||
plugins: [ | ||
new CircularDependencyPlugin({ | ||
exclude: /f\.js/ | ||
}) | ||
] | ||
}); | ||
c.outputFileSystem = fs; | ||
c.run(function(err, stats){ | ||
if (err) { | ||
assert(false, err); | ||
done(); | ||
} else { | ||
assert(s.getCall(0).args[0].match(/e\.js/)); | ||
assert(s.getCall(0).args[1].match(/cyclical/)); | ||
assert(s.getCall(1).args[0].match(/g\.js/)); | ||
assert(s.getCall(1).args[1].match(/cyclical/)); | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); |
11
index.js
var path = require('path'); | ||
var extend = require('util')._extend; | ||
function CircularDependencyPlugin() {} | ||
function CircularDependencyPlugin(options) { | ||
this.options = extend({ | ||
exclude: new RegExp('$^') | ||
}, options); | ||
} | ||
@@ -30,2 +35,4 @@ function isCyclic(initialModule) { | ||
CircularDependencyPlugin.prototype.apply = function(compiler) { | ||
var plugin = this; | ||
compiler.plugin('done', function(stats){ | ||
@@ -35,3 +42,3 @@ var modules = stats.compilation.modules; | ||
modules.forEach(function(module){ | ||
if (isCyclic(module)) { | ||
if (isCyclic(module) && !plugin.options.exclude.test(module.resource)) { | ||
var relativePathToModule = path.relative(process.cwd(), module.resource); | ||
@@ -38,0 +45,0 @@ console.warn(relativePathToModule, 'contains cyclical dependency'); |
@@ -11,3 +11,3 @@ { | ||
"description": "Detect modules with circular dependencies when bundling with webpack.", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"dependencies": {}, | ||
@@ -14,0 +14,0 @@ "scripts": { |
@@ -11,5 +11,7 @@ ## circular-dependency-plugin | ||
plugins: [ | ||
new CircularDependencyPlugin() | ||
new CircularDependencyPlugin({ | ||
exclude: /a\.js/ | ||
}) | ||
] | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5155
134
17