Skip to content

Commit

Permalink
fix: Fixes printing of a reason when it doesn't have clearName
Browse files Browse the repository at this point in the history
Closes: #7
  • Loading branch information
d4rkr00t committed Mar 13, 2018
1 parent 7998897 commit a2aa178
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 23 deletions.
54 changes: 54 additions & 0 deletions fixtures/with-external.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"chunks": [
{
"modules": [
{
"id": "S33B",
"identifier":
"delegated 164 from dll-reference reactVendors_489ff309e47766c80b1e",
"name":
"delegated ./node_modules/react-tap-event-plugin/src/injectTapEventPlugin.js from dll-reference reactVendors_489ff309e47766c80b1e",
"index": 382,
"index2": 380,
"size": 42,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [1],
"assets": [],
"issuer":
"/Users/ssysoev/Development/temp/guillaumecisco/node_modules/happypack/loader.js?id=babel!/Users/ssysoev/Development/temp/guillaumecisco/src/client/index.js",
"issuerId": "EAxn",
"issuerName": "./src/client/index.js",
"profile": {
"factory": 12,
"building": 0,
"dependencies": 0
},
"failed": false,
"errors": 0,
"warnings": 0,
"reasons": [
{
"moduleId": "EAxn",
"moduleIdentifier":
"/Users/ssysoev/Development/temp/guillaumecisco/node_modules/happypack/loader.js?id=babel!/Users/ssysoev/Development/temp/guillaumecisco/src/client/index.js",
"module": "./src/client/index.js",
"moduleName": "./src/client/index.js",
"type": "cjs require",
"userRequest": "react-tap-event-plugin",
"loc": "17:27-60"
}
],
"usedExports": true,
"providedExports": null,
"optimizationBailout": [
"ModuleConcatenation bailout: Module is not an ECMAScript module"
],
"depth": 2
}
]
}
]
}
28 changes: 28 additions & 0 deletions lib/__tests__/__snapshots__/print.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Snapshot report for `lib/__tests__/print.js`

The actual snapshot is saved in `print.js.snap`.

Generated by [AVA](https://ava.li).

## should properly print reasons without clearName

> Snapshot 1
[
'',
` MODULE react-tap-event-plugin␊
├─ imported: 1 time␊
├─ type: [direct]␊
├─ locations: ␊
│ └─ delegated ./node_modules/react-tap-event-plugin/␊
│ ␊
├─ files: ␊
│ └─ delegated ./node_modules/react-tap-event-plugin/src/injectTapEventPlugin.js from dll-reference reactVendors_489ff309e47766c80b1e␊
│ ␊
└─ reasons:␊
└─ ./src/client/index.js 17:27-60 [cjs require]␊
`,
'--------------------',
'',
'',
]
Binary file added lib/__tests__/__snapshots__/print.js.snap
Binary file not shown.
22 changes: 22 additions & 0 deletions lib/__tests__/print.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const stripAnsi = require("strip-ansi");
const test = require("ava");
const fixtures = require("fixturez");
const f = fixtures(__dirname);
const getStats = require("../get-stats");
const analyze = require("../analyze");
const print = require("../print");

const createPrint = () => {
const messages = [];
return msg => {
messages.push(stripAnsi(msg) || "");
return messages;
};
};

test("should properly print reasons without clearName", t => {
const stats = analyze(getStats(f.find("with-external.json")));
const logger = createPrint();
print(stats, {}, 0, logger);
t.snapshot(logger());
});
23 changes: 13 additions & 10 deletions lib/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ const printReasons = (
] = null;
}

acc[`${printReasonNameModule(reason.clearName, by)}`] = subReasons;
acc[
`${printReasonNameModule(reason.clearName || reason.moduleName, by)}`
] = subReasons;
}

return acc;
Expand Down Expand Up @@ -180,22 +182,23 @@ const printModule = (module /*: Module */, limit, by) => {
module.exports = function print(
report /*: Array<Module> */,
flags /*: { by?: string } */,
limit /*: number */
limit /*: number */,
logger /*: (msg?: string) => void*/ = console.log
) {
report
.sort((a, b) => b.imported - a.imported)
.filter(module => module.imported > 0)
.forEach(module => {
if (module.type === "file") {
console.log();
console.log(printFile(module, limit, flags.by).join("\n"));
console.log(chalk.dim("--------------------"));
console.log();
logger();
logger(printFile(module, limit, flags.by).join("\n"));
logger(chalk.dim("--------------------"));
logger();
} else if (module.type === "module") {
console.log();
console.log(printModule(module, limit, flags.by).join("\n"));
console.log(chalk.dim("--------------------"));
console.log();
logger();
logger(printModule(module, limit, flags.by).join("\n"));
logger(chalk.dim("--------------------"));
logger();
}
});
};
97 changes: 85 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"nyc": "^11.4.1",
"pmm": "^1.3.1",
"pre-commit": "^1.2.2",
"prettier": "^1.10.2"
"prettier": "^1.10.2",
"strip-ansi": "^4.0.0"
}
}

0 comments on commit a2aa178

Please sign in to comment.