-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #6
- Loading branch information
Showing
11 changed files
with
130 additions
and
4 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"chunks": [ | ||
{ | ||
"modules": [ | ||
{ | ||
"id": "module1", | ||
"name": "module-name", | ||
"size": 500 | ||
} | ||
] | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"chunks": [ | ||
{ | ||
"modules": [ | ||
{ | ||
"id": "module1", | ||
"name": "module-name", | ||
"size": 500, | ||
"reasons": [] | ||
} | ||
] | ||
} | ||
] | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const test = require("ava"); | ||
const fixtures = require("fixturez"); | ||
const f = fixtures(__dirname); | ||
const validate = require("../validate"); | ||
const getStats = require("../get-stats"); | ||
|
||
test(`should return false for an invalid stats file that doesn't have "reasons" for modules`, t => { | ||
const stats = getStats(f.find("invalid-no-reasons.json")); | ||
t.falsy(validate(stats)); | ||
}); | ||
|
||
test(`should return false for an invalid stats file that doesn't have niether chunks nor modules`, t => { | ||
const stats = getStats(f.find("empty-stats.json")); | ||
t.falsy(validate(stats)); | ||
}); | ||
|
||
test("should return true for a valid stats file", t => { | ||
const stats = getStats(f.find("valid.json")); | ||
t.truthy(validate(stats)); | ||
}); |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* @flow */ | ||
|
||
const chalk = require("chalk"); | ||
|
||
function log(msg /*: Array<string> */) { | ||
console.log(msg.join("\n")); | ||
} | ||
|
||
function redBadge(label /*: string*/) { | ||
return chalk.bgRed.black(` ${label} `); | ||
} | ||
|
||
function errorBadge() { | ||
return redBadge("ERROR"); | ||
} | ||
|
||
function invalidStatsJson(file /*: string */) { | ||
return [ | ||
chalk.red( | ||
`${errorBadge()} Stats file ${chalk.bold( | ||
`"${file}"` | ||
)} doesn't contain "reasons" why modules are included...` | ||
), | ||
`${chalk.yellow("Whybundled")} needs "reasons" to function properly.`, | ||
"", | ||
`To add reason check webpack documentation about stats configuration: ${chalk.blue( | ||
"https://webpack.js.org/configuration/stats/#stats" | ||
)}` | ||
]; | ||
} | ||
|
||
module.exports = { log, invalidStatsJson }; |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* @flow */ | ||
|
||
/*:: | ||
import type { WebpackStats } from "./analyze"; | ||
*/ | ||
|
||
function has(obj) { | ||
return function(prop) { | ||
return obj.hasOwnProperty(prop); | ||
}; | ||
} | ||
|
||
function isValidModule(sample) { | ||
const isProp = has(sample); | ||
if (!isProp("reasons")) return false; | ||
return true; | ||
} | ||
|
||
module.exports = function vlidateStatsJson(stats /*: WebpackStats */) { | ||
if ( | ||
!stats || | ||
((!stats.chunks || !stats.chunks[0].modules) && !stats.modules) | ||
) { | ||
return false; | ||
} | ||
const samples = (stats.modules || stats.chunks[0].modules).slice(0, 10); | ||
return samples.some(isValidModule); | ||
}; |