Skip to content

Commit

Permalink
Merge pull request #45 from sfrieson/master
Browse files Browse the repository at this point in the history
Add includes option
  • Loading branch information
aackerman committed Aug 9, 2019
2 parents 57a2867 + 96ab455 commit 94ecd90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module.exports = {
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /a\.js|node_modules/,
// include specific files based on a RegExp
include: /dir/,
// add errors to webpack instead of warnings
failOnError: true,
// allow import cycles that include an asyncronous import,
Expand Down
22 changes: 22 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ describe('circular dependency', () => {
expect(stats.warnings[1]).toMatch(/g\.js/)
})

it('can include only specific cyclical deps in the output', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/d.js'),
output: { path: __dirname },
plugins: [
new CircularDependencyPlugin({
include: /f\.js/
})
]
})
compiler.outputFileSystem = fs

let runAsync = wrapRun(compiler.run.bind(compiler))
let stats = await runAsync()
stats.warnings.forEach(warning => {
const firstFile = warning.match(/\w+\.js/)[0]
expect(firstFile).toMatch(/f\.js/)
})
})

it(`can handle context modules that have an undefined resource h -> i -> a -> i`, async () => {
let fs = new MemoryFS()
let compiler = webpack({
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CircularDependencyPlugin {
constructor(options) {
this.options = extend({
exclude: new RegExp('$^'),
include: new RegExp('.*'),
failOnError: false,
allowAsyncCycles: false,
onDetected: false,
Expand All @@ -26,7 +27,8 @@ class CircularDependencyPlugin {
for (let module of modules) {
const shouldSkip = (
module.resource == null ||
plugin.options.exclude.test(module.resource)
plugin.options.exclude.test(module.resource) ||
!plugin.options.include.test(module.resource)
)
// skip the module if it matches the exclude pattern
if (shouldSkip) {
Expand Down

0 comments on commit 94ecd90

Please sign in to comment.