Skip to content

Commit 7a1b1e1

Browse files
authored
Merge pull request webpack#5777 from RoboBurned/5769_file_size_in_kibibytes
Display file size in kibibytes Fixes 5769
2 parents c02ca77 + dbc02de commit 7a1b1e1

46 files changed

Lines changed: 228 additions & 187 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎lib/SizeFormatHelpers.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ SizeFormatHelpers.formatSize = size => {
1111
return "0 bytes";
1212
}
1313

14-
const abbreviations = ["bytes", "kB", "MB", "GB"];
15-
const index = Math.floor(Math.log(size) / Math.log(1000));
14+
const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
15+
const index = Math.floor(Math.log(size) / Math.log(1024));
1616

17-
return `${+(size / Math.pow(1000, index)).toPrecision(3)} ${abbreviations[index]}`;
17+
return `${+(size / Math.pow(1024, index)).toPrecision(3)} ${abbreviations[index]}`;
1818
};

‎test/SizeFormatHelpers.unittest.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* globals describe, it, beforeEach */
2+
"use strict";
3+
4+
const should = require("should");
5+
const SizeFormatHelpers = require("../lib/SizeFormatHelpers");
6+
7+
describe("SizeFormatHelpers", () => {
8+
describe("formatSize", () => {
9+
it("should handle zero size", () => {
10+
should(SizeFormatHelpers.formatSize(0)).be.eql("0 bytes");
11+
});
12+
13+
it("should handle bytes", () => {
14+
should(SizeFormatHelpers.formatSize(1000)).be.eql("1000 bytes");
15+
});
16+
17+
it("should handle integer kibibytes", () => {
18+
should(SizeFormatHelpers.formatSize(2048)).be.eql("2 KiB");
19+
});
20+
21+
it("should handle float kibibytes", () => {
22+
should(SizeFormatHelpers.formatSize(2560)).be.eql("2.5 KiB");
23+
});
24+
25+
it("should handle integer mebibytes", () => {
26+
should(SizeFormatHelpers.formatSize(10 * 1024 * 1024)).be.eql("10 MiB");
27+
});
28+
29+
it("should handle float mebibytes", () => {
30+
should(SizeFormatHelpers.formatSize(12.5 * 1024 * 1024)).be.eql("12.5 MiB");
31+
});
32+
33+
it("should handle integer gibibytes", () => {
34+
should(SizeFormatHelpers.formatSize(3 * 1024 * 1024 * 1024)).be.eql("3 GiB");
35+
});
36+
37+
it("should handle float gibibytes", () => {
38+
should(SizeFormatHelpers.formatSize(1.2 * 1024 * 1024 * 1024)).be.eql("1.2 GiB");
39+
});
40+
});
41+
});

‎test/statsCases/aggressive-splitting-entry/expected.txt‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ Hash: 0c4822f4b0f344d71ebc0c4822f4b0f344d71ebc
22
Child fitting:
33
Hash: 0c4822f4b0f344d71ebc
44
Time: Xms
5-
Asset Size Chunks Chunk Names
6-
3b0abf784cffee9cdb84.js 2.29 kB 0 [emitted]
7-
fd43aeccca69e5179cb6.js 1.98 kB 4 [emitted]
8-
0fb4d7363ffcca01b706.js 5.94 kB 5 [emitted]
9-
e1f8db72211be4caf41d.js 1.03 kB 6 [emitted]
5+
Asset Size Chunks Chunk Names
6+
3b0abf784cffee9cdb84.js 2.23 KiB 0 [emitted]
7+
fd43aeccca69e5179cb6.js 1.93 KiB 4 [emitted]
8+
0fb4d7363ffcca01b706.js 5.8 KiB 5 [emitted]
9+
e1f8db72211be4caf41d.js 1 KiB 6 [emitted]
1010
Entrypoint main = 0fb4d7363ffcca01b706.js e1f8db72211be4caf41d.js fd43aeccca69e5179cb6.js 3b0abf784cffee9cdb84.js
11-
chunk {0} 3b0abf784cffee9cdb84.js 1.91 kB [initial] [rendered]
11+
chunk {0} 3b0abf784cffee9cdb84.js 1.87 KiB [initial] [rendered]
1212
> aggressive-splitted main [4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js
1313
[4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js 112 bytes {0} [built]
1414
[6] (webpack)/test/statsCases/aggressive-splitting-entry/f.js 899 bytes {0} [built]
1515
[7] (webpack)/test/statsCases/aggressive-splitting-entry/g.js 899 bytes {0} [built]
16-
chunk {4} fd43aeccca69e5179cb6.js 1.8 kB [initial] [rendered] [recorded]
16+
chunk {4} fd43aeccca69e5179cb6.js 1.76 KiB [initial] [rendered] [recorded]
1717
> aggressive-splitted main [4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js
1818
[0] (webpack)/test/statsCases/aggressive-splitting-entry/b.js 899 bytes {4} [built]
1919
[1] (webpack)/test/statsCases/aggressive-splitting-entry/c.js 899 bytes {4} [built]
20-
chunk {5} 0fb4d7363ffcca01b706.js 1.8 kB [entry] [rendered] [recorded]
20+
chunk {5} 0fb4d7363ffcca01b706.js 1.76 KiB [entry] [rendered] [recorded]
2121
> aggressive-splitted main [4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js
2222
[2] (webpack)/test/statsCases/aggressive-splitting-entry/d.js 899 bytes {5} [built]
2323
[5] (webpack)/test/statsCases/aggressive-splitting-entry/a.js 899 bytes {5} [built]
@@ -27,22 +27,22 @@ Child fitting:
2727
Child content-change:
2828
Hash: 0c4822f4b0f344d71ebc
2929
Time: Xms
30-
Asset Size Chunks Chunk Names
31-
3b0abf784cffee9cdb84.js 2.29 kB 0 [emitted]
32-
fd43aeccca69e5179cb6.js 1.98 kB 4 [emitted]
33-
0fb4d7363ffcca01b706.js 5.94 kB 5 [emitted]
34-
e1f8db72211be4caf41d.js 1.03 kB 6 [emitted]
30+
Asset Size Chunks Chunk Names
31+
3b0abf784cffee9cdb84.js 2.23 KiB 0 [emitted]
32+
fd43aeccca69e5179cb6.js 1.93 KiB 4 [emitted]
33+
0fb4d7363ffcca01b706.js 5.8 KiB 5 [emitted]
34+
e1f8db72211be4caf41d.js 1 KiB 6 [emitted]
3535
Entrypoint main = 0fb4d7363ffcca01b706.js e1f8db72211be4caf41d.js fd43aeccca69e5179cb6.js 3b0abf784cffee9cdb84.js
36-
chunk {0} 3b0abf784cffee9cdb84.js 1.91 kB [initial] [rendered]
36+
chunk {0} 3b0abf784cffee9cdb84.js 1.87 KiB [initial] [rendered]
3737
> aggressive-splitted main [4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js
3838
[4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js 112 bytes {0} [built]
3939
[6] (webpack)/test/statsCases/aggressive-splitting-entry/f.js 899 bytes {0} [built]
4040
[7] (webpack)/test/statsCases/aggressive-splitting-entry/g.js 899 bytes {0} [built]
41-
chunk {4} fd43aeccca69e5179cb6.js 1.8 kB [initial] [rendered] [recorded]
41+
chunk {4} fd43aeccca69e5179cb6.js 1.76 KiB [initial] [rendered] [recorded]
4242
> aggressive-splitted main [4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js
4343
[0] (webpack)/test/statsCases/aggressive-splitting-entry/b.js 899 bytes {4} [built]
4444
[1] (webpack)/test/statsCases/aggressive-splitting-entry/c.js 899 bytes {4} [built]
45-
chunk {5} 0fb4d7363ffcca01b706.js 1.8 kB [entry] [rendered] [recorded]
45+
chunk {5} 0fb4d7363ffcca01b706.js 1.76 KiB [entry] [rendered] [recorded]
4646
> aggressive-splitted main [4] (webpack)/test/statsCases/aggressive-splitting-entry/index.js
4747
[2] (webpack)/test/statsCases/aggressive-splitting-entry/d.js 899 bytes {5} [built]
4848
[5] (webpack)/test/statsCases/aggressive-splitting-entry/a.js 899 bytes {5} [built]

‎test/statsCases/aggressive-splitting-on-demand/expected.txt‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
Hash: 643982be9b8a84182a8b
22
Time: Xms
3-
Asset Size Chunks Chunk Names
4-
1744d4ad4296f5fa250c.js 2.01 kB 0 [emitted]
5-
fcea9401f4f21cf79d39.js 1.99 kB 1 [emitted]
6-
522bb8ca666406617ab6.js 1.03 kB 2 [emitted]
7-
20b6ca975e28ea5b7a3d.js 1.99 kB 3 [emitted]
8-
c1e3d74e221cc503e2e1.js 1.99 kB 4 [emitted]
9-
3d41758100f56aac517e.js 1.03 kB 5 [emitted]
10-
c64eeda8f0bfba682f9d.js 1.03 kB 6 [emitted]
11-
520c994eaddf273485ec.js 8.5 kB 7 [emitted] main
3+
Asset Size Chunks Chunk Names
4+
1744d4ad4296f5fa250c.js 1.96 KiB 0 [emitted]
5+
fcea9401f4f21cf79d39.js 1.94 KiB 1 [emitted]
6+
522bb8ca666406617ab6.js 1 KiB 2 [emitted]
7+
20b6ca975e28ea5b7a3d.js 1.94 KiB 3 [emitted]
8+
c1e3d74e221cc503e2e1.js 1.94 KiB 4 [emitted]
9+
3d41758100f56aac517e.js 1 KiB 5 [emitted]
10+
c64eeda8f0bfba682f9d.js 1.01 KiB 6 [emitted]
11+
520c994eaddf273485ec.js 8.3 KiB 7 [emitted] main
1212
Entrypoint main = 520c994eaddf273485ec.js
13-
chunk {0} 1744d4ad4296f5fa250c.js 1.8 kB {7} [recorded]
13+
chunk {0} 1744d4ad4296f5fa250c.js 1.76 KiB {7} [recorded]
1414
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 4:0-51
1515
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 5:0-44
1616
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 6:0-72
1717
[3] (webpack)/test/statsCases/aggressive-splitting-on-demand/f.js 899 bytes {0} [built]
1818
[4] (webpack)/test/statsCases/aggressive-splitting-on-demand/g.js 901 bytes {0} [built]
19-
chunk {1} fcea9401f4f21cf79d39.js 1.8 kB {7} [recorded]
19+
chunk {1} fcea9401f4f21cf79d39.js 1.76 KiB {7} [recorded]
2020
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 3:0-30
2121
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 5:0-44
2222
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 6:0-72
@@ -26,12 +26,12 @@ chunk {2} 522bb8ca666406617ab6.js 899 bytes {7}
2626
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 2:0-23
2727
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 3:0-30
2828
[5] (webpack)/test/statsCases/aggressive-splitting-on-demand/c.js 899 bytes {2} [built]
29-
chunk {3} 20b6ca975e28ea5b7a3d.js 1.8 kB {7} [recorded]
29+
chunk {3} 20b6ca975e28ea5b7a3d.js 1.76 KiB {7} [recorded]
3030
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 4:0-51
3131
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 6:0-72
3232
[8] (webpack)/test/statsCases/aggressive-splitting-on-demand/j.js 901 bytes {3} [built]
3333
[9] (webpack)/test/statsCases/aggressive-splitting-on-demand/k.js 899 bytes {3} [built]
34-
chunk {4} c1e3d74e221cc503e2e1.js 1.8 kB {7} [recorded]
34+
chunk {4} c1e3d74e221cc503e2e1.js 1.76 KiB {7} [recorded]
3535
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 4:0-51
3636
> aggressive-splitted duplicate [11] (webpack)/test/statsCases/aggressive-splitting-on-demand/index.js 6:0-72
3737
[6] (webpack)/test/statsCases/aggressive-splitting-on-demand/h.js 899 bytes {4} [built]

‎test/statsCases/chunks/expected.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Time: Xms
44
0.bundle.js 288 bytes 0 [emitted]
55
1.bundle.js 152 bytes 1 [emitted]
66
2.bundle.js 232 bytes 2 [emitted]
7-
bundle.js 7.14 kB 3 [emitted] main
7+
bundle.js 6.97 KiB 3 [emitted] main
88
chunk {0} 0.bundle.js 54 bytes {3} [rendered]
99
> [0] (webpack)/test/statsCases/chunks/index.js 3:0-16
1010
[3] (webpack)/test/statsCases/chunks/c.js 54 bytes {0} [built]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hash: 9b62d877d26dd61e1fb9
22
Time: Xms
3-
Asset Size Chunks Chunk Names
4-
main.js 2.69 kB 0 [emitted] main
3+
Asset Size Chunks Chunk Names
4+
main.js 2.63 KiB 0 [emitted] main
55
[0] (webpack)/test/statsCases/color-disabled/index.js 0 bytes {0} [built]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hash: <CLR=BOLD>9b62d877d26dd61e1fb9</CLR>
22
Time: <CLR=BOLD>X</CLR>ms
3-
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
4-
<CLR=32>main.js</CLR> 2.69 kB <CLR=BOLD>0</CLR> <CLR=32>[emitted]</CLR> main
3+
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
4+
<CLR=32>main.js</CLR> 2.63 KiB <CLR=BOLD>0</CLR> <CLR=32>[emitted]</CLR> main
55
[0] <CLR=BOLD>(webpack)/test/statsCases/color-enabled-custom/index.js</CLR> 0 bytes {<CLR=33>0</CLR>}<CLR=32> [built]</CLR>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hash: <CLR=BOLD>9b62d877d26dd61e1fb9</CLR>
22
Time: <CLR=BOLD>X</CLR>ms
3-
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
4-
<CLR=32,BOLD>main.js</CLR> 2.69 kB <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR> main
3+
<CLR=BOLD>Asset</CLR> <CLR=BOLD>Size</CLR> <CLR=BOLD>Chunks</CLR> <CLR=39,BOLD><CLR=22> <CLR=39,BOLD><CLR=22><CLR=BOLD>Chunk Names</CLR>
4+
<CLR=32,BOLD>main.js</CLR> 2.63 KiB <CLR=BOLD>0</CLR> <CLR=32,BOLD>[emitted]</CLR> main
55
[0] <CLR=BOLD>(webpack)/test/statsCases/color-enabled/index.js</CLR> 0 bytes {<CLR=33,BOLD>0</CLR>}<CLR=32,BOLD> [built]</CLR>

‎test/statsCases/commons-chunk-min-size-0/expected.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Hash: 6e3e301d55085d22e738
22
Time: Xms
33
Asset Size Chunks Chunk Names
44
entry-1.js 81 bytes 0 [emitted] entry-1
5-
vendor-1.js 8.21 kB 1 [emitted] vendor-1
5+
vendor-1.js 8.02 KiB 1 [emitted] vendor-1
66
[0] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/a.js 22 bytes {1} [built]
77
[1] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/b.js 22 bytes {1} [built]
88
[2] (webpack)/test/statsCases/commons-chunk-min-size-0/modules/c.js 22 bytes {1} [built]

‎test/statsCases/commons-chunk-min-size-Infinity/expected.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Hash: 6b34e4a15d90c981775e
22
Time: Xms
3-
Asset Size Chunks Chunk Names
4-
entry-1.js 3.32 kB 0 [emitted] entry-1
5-
vendor-1.js 3.07 kB 1 [emitted] vendor-1
3+
Asset Size Chunks Chunk Names
4+
entry-1.js 3.24 KiB 0 [emitted] entry-1
5+
vendor-1.js 3 KiB 1 [emitted] vendor-1
66
[0] (webpack)/test/statsCases/commons-chunk-min-size-Infinity/modules/a.js 22 bytes {0} {1} [built]
77
[1] (webpack)/test/statsCases/commons-chunk-min-size-Infinity/modules/b.js 22 bytes {0} {1} [built]
88
[2] (webpack)/test/statsCases/commons-chunk-min-size-Infinity/modules/c.js 22 bytes {0} {1} [built]

0 commit comments

Comments
 (0)