Socket
Socket
Sign inDemoInstall

circular-dependency-plugin

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

circular-dependency-plugin - npm Package Compare versions

Comparing version 4.2.1 to 4.3.0

67

index.js
let path = require('path')
let extend = require('util')._extend
let cwd = process.cwd()
let BASE_ERROR = 'Circular dependency detected:\r\n'

@@ -11,3 +10,4 @@

failOnError: false,
onDetected: false
onDetected: false,
cwd: process.cwd()
}, options)

@@ -18,2 +18,3 @@ }

let plugin = this
let cwd = this.options.cwd

@@ -24,3 +25,3 @@ compiler.plugin('compilation', (compilation) => {

if (module.resource === undefined) { continue }
let maybeCyclicalPathsList = isCyclic(module, module, {})
let maybeCyclicalPathsList = this.isCyclic(module, module, {})
if (maybeCyclicalPathsList) {

@@ -58,41 +59,43 @@ // allow consumers to override all behavior with onDetected

}
}
function isCyclic(initialModule, currentModule, seenModules) {
// Add the current module to the seen modules cache
seenModules[currentModule.debugId] = true
isCyclic(initialModule, currentModule, seenModules) {
let cwd = this.options.cwd
// If the modules aren't associated to resources
// it's not possible to display how they are cyclical
if (!currentModule.resource || !initialModule.resource) {
return false
}
// Add the current module to the seen modules cache
seenModules[currentModule.debugId] = true
// Iterate over the current modules dependencies
for (let dependency of currentModule.dependencies) {
let depModule = dependency.module
if (!depModule) { continue }
// If the modules aren't associated to resources
// it's not possible to display how they are cyclical
if (!currentModule.resource || !initialModule.resource) {
return false
}
if (depModule.debugId in seenModules) {
if (depModule.debugId === initialModule.debugId) {
// Initial module has a circular dependency
return [
path.relative(cwd, currentModule.resource),
path.relative(cwd, depModule.resource)
]
// Iterate over the current modules dependencies
for (let dependency of currentModule.dependencies) {
let depModule = dependency.module
if (!depModule) { continue }
if (depModule.debugId in seenModules) {
if (depModule.debugId === initialModule.debugId) {
// Initial module has a circular dependency
return [
path.relative(cwd, currentModule.resource),
path.relative(cwd, depModule.resource)
]
}
// Found a cycle, but not for this module
continue
}
// Found a cycle, but not for this module
continue
let maybeCyclicalPathsList = this.isCyclic(initialModule, depModule, seenModules)
if (maybeCyclicalPathsList) {
maybeCyclicalPathsList.unshift(path.relative(cwd, currentModule.resource))
return maybeCyclicalPathsList
}
}
let maybeCyclicalPathsList = isCyclic(initialModule, depModule, seenModules)
if (maybeCyclicalPathsList) {
maybeCyclicalPathsList.unshift(path.relative(cwd, currentModule.resource))
return maybeCyclicalPathsList
}
return false
}
return false
}
module.exports = CircularDependencyPlugin

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

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

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

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

Circular dependencies are often a necessity in complex software, the presence of a circular dependency doesn't always imply a bug, but in the case where the you believe a bug exists, this module may help find it.
Circular dependencies are often a necessity in complex software, the presence of a circular dependency doesn't always imply a bug, but in the case where you believe a bug exists, this module may help find it.

@@ -21,3 +21,5 @@ ### Basic Usage

// add errors to webpack instead of warnings
failOnError: true
failOnError: true,
// set the current working directory for displaying module paths
cwd: process.cwd(),
})

@@ -24,0 +26,0 @@ ]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc