Socket
Socket
Sign inDemoInstall

circular-dependency-plugin

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.3.0 to 4.4.0

6

index.js

@@ -21,2 +21,5 @@ let path = require('path')

compilation.plugin('optimize-modules', (modules) => {
if (plugin.options.onStart) {
plugin.options.onStart({ compilation });
}
for (let module of modules) {

@@ -54,2 +57,5 @@ if (module.resource === undefined) { continue }

}
if (plugin.options.onEnd) {
plugin.options.onEnd({ compilation });
}
})

@@ -56,0 +62,0 @@ })

2

package.json

@@ -10,3 +10,3 @@ {

"description": "Detect modules with circular dependencies when bundling with webpack.",
"version": "4.3.0",
"version": "4.4.0",
"engines": {

@@ -13,0 +13,0 @@ "node": ">=6.0.0"

@@ -11,3 +11,3 @@ ## Circular Dependency Plugin

// webpack.config.js
let CircularDependencyPlugin = require('circular-dependency-plugin')
const CircularDependencyPlugin = require('circular-dependency-plugin')

@@ -33,3 +33,3 @@ module.exports = {

// webpack.config.js
let CircularDependencyPlugin = require('circular-dependency-plugin')
const CircularDependencyPlugin = require('circular-dependency-plugin')

@@ -40,2 +40,6 @@ module.exports = {

new CircularDependencyPlugin({
// `onStart` is called before the cycle detection starts
onStart({ compilation }) {
console.log('start detecting webpack modules cycles');
},
// `onDetected` is called for each module that is cyclical

@@ -46,3 +50,7 @@ onDetected({ module: webpackModuleRecord, paths, compilation }) {

compilation.errors.push(new Error(paths.join(' -> ')))
}
},
// `onEnd` is called before the cycle detection ends
onEnd({ compilation }) {
console.log('end detecting webpack modules cycles');
},
})

@@ -52,1 +60,37 @@ ]

```
If you have some number of cycles and want to fail if any new ones are
introduced, you can use the life cycle methods to count and fail when the
count is exceeded. (Note if you care about detecting a cycle being replaced by
another, this won't catch that.)
```js
// webpack.config.js
const CircularDependencyPlugin = require('circular-dependency-plugin')
const MAX_CYCLES = 5;
let numCyclesDetected = 0;
module.exports = {
entry: "./src/index",
plugins: [
new CircularDependencyPlugin({
onStart({ compilation }) {
numCyclesDetected = 0;
},
onDetected({ module: webpackModuleRecord, paths, compilation }) {
numCyclesDetected++;
compilation.warnings.push(new Error(paths.join(' -> ')))
},
onEnd({ compilation }) {
if (numCyclesDetected > MAX_CYCLES) {
compilation.errors.push(new Error(
`Detected ${numCyclesDetected} cycles which exceeds configured limit of ${MAX_CYCLES}`
));
}
},
})
]
}
```
```
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