-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(karma-webpack): remove compiler
legacy code (compiler.plugin
)
#342
Merged
+15
−50
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,23 +121,13 @@ function Plugin( | |
const applyPlugins = compiler.compilers || [compiler]; | ||
|
||
applyPlugins.forEach(function(compiler) { | ||
if (compiler.hooks) { | ||
compiler.hooks.thisCompilation.tap(this.plugin, (compilation, params) => { | ||
compilation.dependencyFactories.set( | ||
SingleEntryDependency, | ||
params.normalModuleFactory | ||
); | ||
}); | ||
compiler.hooks.make.tapAsync(this.plugin, this.make.bind(this)); | ||
} else { | ||
compiler.plugin('this-compilation', (compilation, params) => { | ||
compilation.dependencyFactories.set( | ||
SingleEntryDependency, | ||
params.normalModuleFactory | ||
); | ||
}); | ||
compiler.plugin('make', this.make.bind(this)); | ||
} | ||
compiler.hooks.thisCompilation.tap(this.plugin, (compilation, params) => { | ||
compilation.dependencyFactories.set( | ||
SingleEntryDependency, | ||
params.normalModuleFactory | ||
); | ||
}); | ||
compiler.hooks.make.tapAsync(this.plugin, this.make.bind(this)); | ||
}, this); | ||
|
||
function handler(callback) { | ||
|
@@ -148,31 +138,9 @@ function Plugin( | |
} | ||
} | ||
|
||
let hooks = ['invalid', 'watch-run', 'run']; | ||
|
||
if (compiler.hooks) { | ||
hooks = [ | ||
{ method: 'sync', name: 'invalid' }, | ||
{ method: 'async', name: 'watchRun' }, | ||
{ method: 'async', name: 'run' }, | ||
]; | ||
} | ||
|
||
hooks.forEach(function(hook) { | ||
if (compiler.hooks) { | ||
if (hook.method === 'sync') { | ||
compiler.hooks[hook.name].tap(this.plugin, () => handler()); | ||
} else { | ||
compiler.hooks[hook.name].tapAsync(this.plugin, (_, callback) => | ||
handler(callback) | ||
); | ||
} | ||
} else { | ||
compiler.plugin(hook, (_, callback) => { | ||
handler(callback); | ||
}); | ||
} | ||
}, this); | ||
compiler.hooks.invalid.tap(this.plugin, () => handler()); | ||
compiler.hooks.watchRun.tap(this.plugin, () => handler()); | ||
compiler.hooks.run.tapAsync(this.plugin, (_, callback) => handler(callback)); | ||
|
||
function done(stats) { | ||
const applyStats = Array.isArray(stats.stats) ? stats.stats : [stats]; | ||
|
@@ -214,13 +182,8 @@ function Plugin( | |
} | ||
} | ||
|
||
if (compiler.hooks) { | ||
compiler.hooks.done.tap(this.plugin, done.bind(this)); | ||
compiler.hooks.invalid.tap(this.plugin, invalid.bind(this)); | ||
} else { | ||
compiler.plugin('done', done.bind(this)); | ||
compiler.plugin('invalid', invalid.bind(this)); | ||
} | ||
compiler.hooks.done.tap(this.plugin, done.bind(this)); | ||
compiler.hooks.invalid.tap(this.plugin, invalid.bind(this)); | ||
|
||
webpackMiddlewareOptions.publicPath = path.join( | ||
os.tmpdir(), | ||
|
@@ -270,7 +233,9 @@ Plugin.prototype.make = function(compilation, callback) { | |
let entry = file; | ||
|
||
if (this.wrapMocha) { | ||
entry = `${require.resolve('./mocha-env-loader')}?name=${compilation.name}!${entry}`; | ||
entry = `${require.resolve('./mocha-env-loader')}?name=${ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems prettier wanted to change this line on this commit for some reason.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
compilation.name | ||
}!${entry}`; | ||
} | ||
|
||
const dep = new SingleEntryDependency(entry); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you try with using
compilation
instead ofthisCompilation
, the latter is an alias if I remember right and will be removed in a feature version ofwebpack
. But it's not important to do this now, I just saw it, so in case it bugs for whatever reason don't bother :)