Skip to content

Commit

Permalink
Merge pull request #33 from gpoitch/gpoitch/webpack4
Browse files Browse the repository at this point in the history
Webpack 4 support
  • Loading branch information
aackerman committed Mar 20, 2018
2 parents 3d65622 + f5d656e commit d0e9d75
Show file tree
Hide file tree
Showing 4 changed files with 6,132 additions and 4,635 deletions.
9 changes: 9 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('circular dependency', () => {
it('detects circular dependencies from a -> b -> c -> b', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/a.js'),
output: { path: __dirname },
plugins: [ new CircularDependencyPlugin() ]
Expand All @@ -34,6 +35,7 @@ describe('circular dependency', () => {
it('detects circular dependencies from d -> e -> f -> g -> e', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/d.js'),
output: { path: __dirname },
plugins: [ new CircularDependencyPlugin() ]
Expand All @@ -53,6 +55,7 @@ describe('circular dependency', () => {
it('uses errors instead of warnings with failOnError', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/d.js'),
output: { path: __dirname },
plugins: [ new CircularDependencyPlugin({
Expand All @@ -74,6 +77,7 @@ describe('circular dependency', () => {
it('can exclude cyclical deps from being output', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/d.js'),
output: { path: __dirname },
plugins: [
Expand All @@ -95,6 +99,7 @@ describe('circular dependency', () => {
it(`can handle context modules that have an undefined resource h -> i -> a -> i`, async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/h.js'),
output: { path: __dirname },
plugins: [
Expand All @@ -110,6 +115,7 @@ describe('circular dependency', () => {
it('allows hooking into detection cycle', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/nocycle.js'),
output: { path: __dirname },
plugins: [
Expand Down Expand Up @@ -137,6 +143,7 @@ describe('circular dependency', () => {
let cyclesPaths
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/d.js'),
output: { path: __dirname },
plugins: [
Expand All @@ -162,6 +169,7 @@ describe('circular dependency', () => {
it('detects circular dependencies from d -> e -> f -> g -> e', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/d.js'),
output: { path: __dirname },
plugins: [
Expand All @@ -186,6 +194,7 @@ describe('circular dependency', () => {
it('can detect circular dependencies when the ModuleConcatenationPlugin is used', async () => {
let fs = new MemoryFS()
let compiler = webpack({
mode: 'development',
entry: path.join(__dirname, 'deps/module-concat-plugin-compat/index.js'),
output: { path: __dirname },
plugins: [
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let path = require('path')
let extend = require('util')._extend
let BASE_ERROR = 'Circular dependency detected:\r\n'
let PluginTitle = 'CircularDependencyPlugin'

class CircularDependencyPlugin {
constructor(options) {
Expand All @@ -16,8 +17,8 @@ class CircularDependencyPlugin {
let plugin = this
let cwd = this.options.cwd

compiler.plugin('compilation', (compilation) => {
compilation.plugin('optimize-modules', (modules) => {
compiler.hooks.compilation.tap(PluginTitle, (compilation) => {
compilation.hooks.optimizeModules.tap(PluginTitle, (modules) => {
if (plugin.options.onStart) {
plugin.options.onStart({ compilation });
}
Expand Down
Loading

0 comments on commit d0e9d75

Please sign in to comment.