Skip to content

Commit 217bccc

Browse files
committed
Merge branch 'master' of github.com:aackerman/circular-dependency-plugin
2 parents c30e70e + 94ecd90 commit 217bccc

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module.exports = {
2020
new CircularDependencyPlugin({
2121
// exclude detection of files based on a RegExp
2222
exclude: /a\.js|node_modules/,
23+
// include specific files based on a RegExp
24+
include: /dir/,
2325
// add errors to webpack instead of warnings
2426
failOnError: true,
2527
// allow import cycles that include an asyncronous import,

__tests__/index.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ describe('circular dependency', () => {
9696
expect(stats.warnings[1]).toMatch(/g\.js/)
9797
})
9898

99+
it('can include only specific cyclical deps in the output', async () => {
100+
let fs = new MemoryFS()
101+
let compiler = webpack({
102+
mode: 'development',
103+
entry: path.join(__dirname, 'deps/d.js'),
104+
output: { path: __dirname },
105+
plugins: [
106+
new CircularDependencyPlugin({
107+
include: /f\.js/
108+
})
109+
]
110+
})
111+
compiler.outputFileSystem = fs
112+
113+
let runAsync = wrapRun(compiler.run.bind(compiler))
114+
let stats = await runAsync()
115+
stats.warnings.forEach(warning => {
116+
const firstFile = warning.match(/\w+\.js/)[0]
117+
expect(firstFile).toMatch(/f\.js/)
118+
})
119+
})
120+
99121
it(`can handle context modules that have an undefined resource h -> i -> a -> i`, async () => {
100122
let fs = new MemoryFS()
101123
let compiler = webpack({

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CircularDependencyPlugin {
77
constructor(options) {
88
this.options = extend({
99
exclude: new RegExp('$^'),
10+
include: new RegExp('.*'),
1011
failOnError: false,
1112
allowAsyncCycles: false,
1213
onDetected: false,
@@ -26,7 +27,8 @@ class CircularDependencyPlugin {
2627
for (let module of modules) {
2728
const shouldSkip = (
2829
module.resource == null ||
29-
plugin.options.exclude.test(module.resource)
30+
plugin.options.exclude.test(module.resource) ||
31+
!plugin.options.include.test(module.resource)
3032
)
3133
// skip the module if it matches the exclude pattern
3234
if (shouldSkip) {

0 commit comments

Comments
 (0)