Skip to content
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

Add support for Webpack 4 #17

Merged
merged 19 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets you debug the unit tests in vscode, I found it useful

{
"type": "node",
"request": "launch",
"name": "Debug Jest",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"cwd": "${workspaceRoot}",
"args": ["--i"]
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"husky": "^0.14.3",
"jest": "^21.2.1",
"lint-staged": "^5.0.0",
"webpack": "^3.8.1"
"prettier": "^1.11.1",
"webpack": "^4.1.1"
}
}
16 changes: 13 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function DuplicatePackageCheckerPlugin(options) {
}

function cleanPath(path) {
return path.split("/node_modules/").join("/~/");
return path.split(/[\/\\]node_modules[\/\\]/).join("/~/");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes clean path work in windows

}

// Get closest package definition from path
Expand Down Expand Up @@ -54,7 +54,10 @@ DuplicatePackageCheckerPlugin.prototype.apply = function(compiler) {
let exclude = this.options.exclude;
let strict = this.options.strict;

compiler.plugin("emit", function(compilation, callback) {
compiler.hooks.emit.tapAsync("DuplicatePackageCheckerPlugin", function(
compilation,
callback
) {
let context = compilation.compiler.context;
let modules = {};

Expand Down Expand Up @@ -157,7 +160,14 @@ DuplicatePackageCheckerPlugin.prototype.apply = function(compiler) {
let array = emitError ? compilation.errors : compilation.warnings;

let i = 0;
_.each(duplicates, (instances, name) => {

let sortedDuplicateKeys = Object.keys(duplicates).sort();

sortedDuplicateKeys.map(name => {
let instances = duplicates[name].sort(
(a, b) => (a.version < b.version ? -1 : 1)
Copy link
Contributor Author

@christiango christiango Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not perfect since it is just a string sort, but it keeps the snapshot tests from being fragile against the ordering of the duplicates and the duplication instances

);

let error =
name +
"\n" +
Expand Down
1 change: 1 addition & 0 deletions test/non-root-package-json/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var DuplicatePackageCheckerPlugin = require("../../src");

module.exports = {
entry: "./entry.js",
mode: "production",
context: __dirname,
output: {
path: path.resolve(__dirname, "dist"),
Expand Down
1 change: 1 addition & 0 deletions test/npm-2/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var DuplicatePackageCheckerPlugin = require("../../src");

module.exports = {
entry: "./entry.js",
mode: "production",
context: __dirname,
output: {
path: path.resolve(__dirname, "dist"),
Expand Down
1 change: 1 addition & 0 deletions test/simple/make.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var DuplicatePackageCheckerPlugin = require("../../src");
module.exports = function(options) {
return {
entry: "./entry.js",
mode: "production",
context: __dirname,
output: {
path: path.resolve(__dirname, "dist"),
Expand Down
1 change: 1 addition & 0 deletions test/strict/make.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var DuplicatePackageCheckerPlugin = require("../../src");
module.exports = function(options) {
return {
entry: "./entry.js",
mode: "production",
context: __dirname,
output: {
path: path.resolve(__dirname, "dist"),
Expand Down
Loading