rollup-plugin-stats 1.1.2 → 1.2.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extract.cjs +85 -0
- package/dist/extract.cjs.map +1 -0
- package/dist/extract.mjs +83 -0
- package/dist/extract.mjs.map +1 -0
- package/dist/index.cjs +7 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +6 -74
- package/dist/index.mjs.map +1 -1
- package/dist/utils/omit.d.ts +5 -0
- package/dist/utils/round.d.ts +1 -0
- package/package.json +10 -5
package/dist/extract.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function omit(data, keys) {
|
|
4
|
+
const result = {};
|
|
5
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
6
|
+
if (!keys.includes(key)) {
|
|
7
|
+
result[key] = value;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Check if filepath should be excluded based on patterns
|
|
15
|
+
*/
|
|
16
|
+
function checkExcludeFilepath(filepath, patterns) {
|
|
17
|
+
if (!patterns) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(patterns)) {
|
|
21
|
+
let res = false;
|
|
22
|
+
for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
|
|
23
|
+
res = checkExcludeFilepath(filepath, patterns[i]);
|
|
24
|
+
}
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
if (typeof patterns === 'function') {
|
|
28
|
+
return patterns(filepath);
|
|
29
|
+
}
|
|
30
|
+
if (typeof patterns === 'string') {
|
|
31
|
+
return Boolean(filepath.match(patterns));
|
|
32
|
+
}
|
|
33
|
+
if ('test' in patterns) {
|
|
34
|
+
return patterns.test(filepath);
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function extractRollupStats(bundle, options = {}) {
|
|
40
|
+
const { source = false, excludeAssets, excludeModules } = options;
|
|
41
|
+
const output = {};
|
|
42
|
+
Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
|
|
43
|
+
// Skip extraction if the entry filepath matches the exclude assets pattern
|
|
44
|
+
if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (bundleEntryStats.type === "asset") {
|
|
48
|
+
let assetStats = structuredClone(bundleEntryStats);
|
|
49
|
+
// Skip asset source if options source is false
|
|
50
|
+
if (!source) {
|
|
51
|
+
assetStats = omit(assetStats, 'source');
|
|
52
|
+
}
|
|
53
|
+
output[bundleEntryFilepath] = assetStats;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (bundleEntryStats.type === "chunk") {
|
|
57
|
+
let chunkStats = structuredClone(bundleEntryStats);
|
|
58
|
+
// Skip chunk source if options source is false
|
|
59
|
+
if (!source) {
|
|
60
|
+
chunkStats = omit(chunkStats, 'code');
|
|
61
|
+
}
|
|
62
|
+
// Extract chunk modules stats
|
|
63
|
+
const chunkModulesStats = {};
|
|
64
|
+
Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
|
|
65
|
+
// Skip module extraction if the filepath matches the exclude modules pattern
|
|
66
|
+
if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let moduleStats = structuredClone(bundleModuleStats);
|
|
70
|
+
// Skip module source if options source is false
|
|
71
|
+
if (!source) {
|
|
72
|
+
moduleStats = omit(moduleStats, 'code');
|
|
73
|
+
}
|
|
74
|
+
chunkModulesStats[bundleModuleFilepath] = moduleStats;
|
|
75
|
+
});
|
|
76
|
+
chunkStats.modules = chunkModulesStats;
|
|
77
|
+
output[bundleEntryFilepath] = chunkStats;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return output;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = extractRollupStats;
|
|
85
|
+
//# sourceMappingURL=extract.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.cjs","sources":["../src/utils/omit.ts","../src/utils/check-exclude-filepath.ts","../src/extract.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":";;AAAgB,SAAA,IAAI,CAClB,IAAgC,EAChC,IAAmB,EAAA;IAEnB,MAAM,MAAM,GAAG,EAAE;AAEjB,IAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;QAC5C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AACvB,YAAA,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;;AAEvB,KAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;ACTA;;AAEG;AACa,SAAA,oBAAoB,CAClC,QAAgB,EAChB,QAAkC,EAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,KAAK;;AAGd,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,IAAI,GAAG,GAAG,KAAK;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9D,GAAG,GAAG,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;;AAGnD,QAAA,OAAO,GAAG;;AAGZ,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAClC,QAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC;;AAG3B,IAAA,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAA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AAC,oBAAoB,EAAE,cAAc,CAAC,EAAE;oBAC9D;;AAGF,gBAAA,IAAI,WAAW,GAAG,eAAe,CAAC,iBAAiB,CAAgB;;gBAGnE,IAAI,CAAC,MAAM,EAAE;AACX,oBAAA,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;;AAGzC,gBAAA,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,WAAW;AACvD,aAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;;AAEJ,KAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"}
|
package/dist/extract.mjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
function omit(data, keys) {
|
|
2
|
+
const result = {};
|
|
3
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
4
|
+
if (!keys.includes(key)) {
|
|
5
|
+
result[key] = value;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Check if filepath should be excluded based on patterns
|
|
13
|
+
*/
|
|
14
|
+
function checkExcludeFilepath(filepath, patterns) {
|
|
15
|
+
if (!patterns) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(patterns)) {
|
|
19
|
+
let res = false;
|
|
20
|
+
for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
|
|
21
|
+
res = checkExcludeFilepath(filepath, patterns[i]);
|
|
22
|
+
}
|
|
23
|
+
return res;
|
|
24
|
+
}
|
|
25
|
+
if (typeof patterns === 'function') {
|
|
26
|
+
return patterns(filepath);
|
|
27
|
+
}
|
|
28
|
+
if (typeof patterns === 'string') {
|
|
29
|
+
return Boolean(filepath.match(patterns));
|
|
30
|
+
}
|
|
31
|
+
if ('test' in patterns) {
|
|
32
|
+
return patterns.test(filepath);
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function extractRollupStats(bundle, options = {}) {
|
|
38
|
+
const { source = false, excludeAssets, excludeModules } = options;
|
|
39
|
+
const output = {};
|
|
40
|
+
Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
|
|
41
|
+
// Skip extraction if the entry filepath matches the exclude assets pattern
|
|
42
|
+
if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (bundleEntryStats.type === "asset") {
|
|
46
|
+
let assetStats = structuredClone(bundleEntryStats);
|
|
47
|
+
// Skip asset source if options source is false
|
|
48
|
+
if (!source) {
|
|
49
|
+
assetStats = omit(assetStats, 'source');
|
|
50
|
+
}
|
|
51
|
+
output[bundleEntryFilepath] = assetStats;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (bundleEntryStats.type === "chunk") {
|
|
55
|
+
let chunkStats = structuredClone(bundleEntryStats);
|
|
56
|
+
// Skip chunk source if options source is false
|
|
57
|
+
if (!source) {
|
|
58
|
+
chunkStats = omit(chunkStats, 'code');
|
|
59
|
+
}
|
|
60
|
+
// Extract chunk modules stats
|
|
61
|
+
const chunkModulesStats = {};
|
|
62
|
+
Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
|
|
63
|
+
// Skip module extraction if the filepath matches the exclude modules pattern
|
|
64
|
+
if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let moduleStats = structuredClone(bundleModuleStats);
|
|
68
|
+
// Skip module source if options source is false
|
|
69
|
+
if (!source) {
|
|
70
|
+
moduleStats = omit(moduleStats, 'code');
|
|
71
|
+
}
|
|
72
|
+
chunkModulesStats[bundleModuleFilepath] = moduleStats;
|
|
73
|
+
});
|
|
74
|
+
chunkStats.modules = chunkModulesStats;
|
|
75
|
+
output[bundleEntryFilepath] = chunkStats;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return output;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { extractRollupStats as default };
|
|
83
|
+
//# sourceMappingURL=extract.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.mjs","sources":["../src/utils/omit.ts","../src/utils/check-exclude-filepath.ts","../src/extract.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":"AAAgB,SAAA,IAAI,CAClB,IAAgC,EAChC,IAAmB,EAAA;IAEnB,MAAM,MAAM,GAAG,EAAE;AAEjB,IAAA,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;QAC5C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AACvB,YAAA,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK;;AAEvB,KAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;ACTA;;AAEG;AACa,SAAA,oBAAoB,CAClC,QAAgB,EAChB,QAAkC,EAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,KAAK;;AAGd,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,IAAI,GAAG,GAAG,KAAK;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9D,GAAG,GAAG,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;;AAGnD,QAAA,OAAO,GAAG;;AAGZ,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAClC,QAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC;;AAG3B,IAA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,KAAI;;AAEvF,gBAAA,IAAI,oBAAoB,CAAC,oBAAoB,EAAE,cAAc,CAAC,EAAE;oBAC9D;;AAGF,gBAAA,IAAI,WAAW,GAAG,eAAe,CAAC,iBAAiB,CAAgB;;gBAGnE,IAAI,CAAC,MAAM,EAAE;AACX,oBAAA,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;;AAGzC,gBAAA,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,WAAW;AACvD,aAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;;AAEJ,KAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -2,81 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var path = require('node:path');
|
|
4
4
|
var process = require('node:process');
|
|
5
|
-
var
|
|
6
|
-
var entries = require('lodash/entries.js');
|
|
5
|
+
var extract = require('./extract.cjs');
|
|
7
6
|
var fs = require('node:fs/promises');
|
|
8
|
-
var round = require('lodash/round.js');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Check if filepath should be excluded based on patterns
|
|
12
|
-
*/
|
|
13
|
-
function checkExcludeFilepath(filepath, patterns) {
|
|
14
|
-
if (!patterns) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
if (Array.isArray(patterns)) {
|
|
18
|
-
let res = false;
|
|
19
|
-
for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
|
|
20
|
-
res = checkExcludeFilepath(filepath, patterns[i]);
|
|
21
|
-
}
|
|
22
|
-
return res;
|
|
23
|
-
}
|
|
24
|
-
if (typeof patterns === 'function') {
|
|
25
|
-
return patterns(filepath);
|
|
26
|
-
}
|
|
27
|
-
if (typeof patterns === 'string') {
|
|
28
|
-
return Boolean(filepath.match(patterns));
|
|
29
|
-
}
|
|
30
|
-
if ('test' in patterns) {
|
|
31
|
-
return patterns.test(filepath);
|
|
32
|
-
}
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function extractRollupStats(bundle, options = {}) {
|
|
37
|
-
const { source = false, excludeAssets, excludeModules } = options;
|
|
38
|
-
const output = {};
|
|
39
|
-
entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
|
|
40
|
-
// Skip extraction if the entry filepath matches the exclude assets pattern
|
|
41
|
-
if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (bundleEntryStats.type === "asset") {
|
|
45
|
-
let assetStats = structuredClone(bundleEntryStats);
|
|
46
|
-
// Skip asset source if options source is false
|
|
47
|
-
if (!source) {
|
|
48
|
-
assetStats = omit(assetStats, 'source');
|
|
49
|
-
}
|
|
50
|
-
output[bundleEntryFilepath] = assetStats;
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (bundleEntryStats.type === "chunk") {
|
|
54
|
-
let chunkStats = structuredClone(bundleEntryStats);
|
|
55
|
-
// Skip chunk source if options source is false
|
|
56
|
-
if (!source) {
|
|
57
|
-
chunkStats = omit(chunkStats, 'code');
|
|
58
|
-
}
|
|
59
|
-
// Extract chunk modules stats
|
|
60
|
-
const chunkModulesStats = {};
|
|
61
|
-
entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
|
|
62
|
-
// Skip module extraction if the filepath matches the exclude modules pattern
|
|
63
|
-
if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
let moduleStats = structuredClone(bundleModuleStats);
|
|
67
|
-
// Skip module source if options source is false
|
|
68
|
-
if (!source) {
|
|
69
|
-
moduleStats = omit(moduleStats, 'code');
|
|
70
|
-
}
|
|
71
|
-
chunkModulesStats[bundleModuleFilepath] = moduleStats;
|
|
72
|
-
});
|
|
73
|
-
chunkStats.modules = chunkModulesStats;
|
|
74
|
-
output[bundleEntryFilepath] = chunkStats;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return output;
|
|
79
|
-
}
|
|
80
7
|
|
|
81
8
|
async function rollupStatsWrite(filepath, stats) {
|
|
82
9
|
const content = JSON.stringify(stats, null, 2);
|
|
@@ -89,6 +16,11 @@ async function rollupStatsWrite(filepath, stats) {
|
|
|
89
16
|
};
|
|
90
17
|
}
|
|
91
18
|
|
|
19
|
+
function round(value, precision = 2) {
|
|
20
|
+
const multiplier = 10 ^ precision;
|
|
21
|
+
return Math.round(value * multiplier) / multiplier;
|
|
22
|
+
}
|
|
23
|
+
|
|
92
24
|
const FILE_SIZE = {
|
|
93
25
|
BYTE: {
|
|
94
26
|
symbol: 'B',
|
|
@@ -131,7 +63,7 @@ function rollupStats(options = {}) {
|
|
|
131
63
|
const filepath = path.isAbsolute(resolvedFileName)
|
|
132
64
|
? resolvedFileName
|
|
133
65
|
: path.join(context.dir || process.cwd(), resolvedFileName);
|
|
134
|
-
const stats =
|
|
66
|
+
const stats = extract(bundle, statsOptions);
|
|
135
67
|
try {
|
|
136
68
|
const res = await write(filepath, stats);
|
|
137
69
|
const outputSize = Buffer.byteLength(res.content, 'utf-8');
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/write.ts","../src/utils/round.ts","../src/utils/format-file-size.ts","../src/index.ts"],"sourcesContent":[null,null,null,null],"names":["extractRollupStats"],"mappings":";;;;;;;AAaO,eAAe,gBAAgB,CAEpC,QAAgB,EAAE,KAAQ,EAAA;AAC1B,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAG9C,IAAA,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC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AAM,EAAE;AAC7D;;ACzBA,MAAM,WAAW,GAAG,aAAa;AACjC,MAAM,iBAAiB,GAAG,YAAY;AAmBtC,SAAS,WAAW,CAAC,OAAA,GAA8B,EAAE,EAAA;AACnD,IAAA,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,GAAG,gBAAgB,EAAE,GAAG,OAAO;IAE3E,OAAO;AACL,QAAA,IAAI,EAAE,WAAW;AACjB,QAAA,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,EAAA;AAClC,YAAA,MAAM,gBAAgB,GAAG,QAAQ,IAAI,iBAAiB;AACtD,YAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB;AAC/C,kBAAE;AACF,kBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC;YAE7D,MAAM,KAAK,GAAGA,OAAkB,CAAC,MAAM,EAAE,YAAY,CAAC;AAEtD,YAAA,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC;AACxC,gBAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;AAE1D,gBAAA,IAAI,CAAC,IAAI,CAAC,CAAA,eAAA,EAAkB,GAAG,CAAC,QAAQ,CAAK,EAAA,EAAA,cAAc,CAAC,UAAU,CAAC,CAAA,CAAA,CAAG,CAAC;;AAC3E,YAAA,OAAO,KAAU,EAAE;;AAEnB,gBAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;;SAEnB;KACe;AACpB;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,80 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import process from 'node:process';
|
|
3
|
-
import
|
|
4
|
-
import entries from 'lodash/entries.js';
|
|
3
|
+
import extractRollupStats from './extract.mjs';
|
|
5
4
|
import fs from 'node:fs/promises';
|
|
6
|
-
import round from 'lodash/round.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Check if filepath should be excluded based on patterns
|
|
10
|
-
*/
|
|
11
|
-
function checkExcludeFilepath(filepath, patterns) {
|
|
12
|
-
if (!patterns) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (Array.isArray(patterns)) {
|
|
16
|
-
let res = false;
|
|
17
|
-
for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
|
|
18
|
-
res = checkExcludeFilepath(filepath, patterns[i]);
|
|
19
|
-
}
|
|
20
|
-
return res;
|
|
21
|
-
}
|
|
22
|
-
if (typeof patterns === 'function') {
|
|
23
|
-
return patterns(filepath);
|
|
24
|
-
}
|
|
25
|
-
if (typeof patterns === 'string') {
|
|
26
|
-
return Boolean(filepath.match(patterns));
|
|
27
|
-
}
|
|
28
|
-
if ('test' in patterns) {
|
|
29
|
-
return patterns.test(filepath);
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function extractRollupStats(bundle, options = {}) {
|
|
35
|
-
const { source = false, excludeAssets, excludeModules } = options;
|
|
36
|
-
const output = {};
|
|
37
|
-
entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
|
|
38
|
-
// Skip extraction if the entry filepath matches the exclude assets pattern
|
|
39
|
-
if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (bundleEntryStats.type === "asset") {
|
|
43
|
-
let assetStats = structuredClone(bundleEntryStats);
|
|
44
|
-
// Skip asset source if options source is false
|
|
45
|
-
if (!source) {
|
|
46
|
-
assetStats = omit(assetStats, 'source');
|
|
47
|
-
}
|
|
48
|
-
output[bundleEntryFilepath] = assetStats;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (bundleEntryStats.type === "chunk") {
|
|
52
|
-
let chunkStats = structuredClone(bundleEntryStats);
|
|
53
|
-
// Skip chunk source if options source is false
|
|
54
|
-
if (!source) {
|
|
55
|
-
chunkStats = omit(chunkStats, 'code');
|
|
56
|
-
}
|
|
57
|
-
// Extract chunk modules stats
|
|
58
|
-
const chunkModulesStats = {};
|
|
59
|
-
entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
|
|
60
|
-
// Skip module extraction if the filepath matches the exclude modules pattern
|
|
61
|
-
if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
let moduleStats = structuredClone(bundleModuleStats);
|
|
65
|
-
// Skip module source if options source is false
|
|
66
|
-
if (!source) {
|
|
67
|
-
moduleStats = omit(moduleStats, 'code');
|
|
68
|
-
}
|
|
69
|
-
chunkModulesStats[bundleModuleFilepath] = moduleStats;
|
|
70
|
-
});
|
|
71
|
-
chunkStats.modules = chunkModulesStats;
|
|
72
|
-
output[bundleEntryFilepath] = chunkStats;
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
return output;
|
|
77
|
-
}
|
|
78
5
|
|
|
79
6
|
async function rollupStatsWrite(filepath, stats) {
|
|
80
7
|
const content = JSON.stringify(stats, null, 2);
|
|
@@ -87,6 +14,11 @@ async function rollupStatsWrite(filepath, stats) {
|
|
|
87
14
|
};
|
|
88
15
|
}
|
|
89
16
|
|
|
17
|
+
function round(value, precision = 2) {
|
|
18
|
+
const multiplier = 10 ^ precision;
|
|
19
|
+
return Math.round(value * multiplier) / multiplier;
|
|
20
|
+
}
|
|
21
|
+
|
|
90
22
|
const FILE_SIZE = {
|
|
91
23
|
BYTE: {
|
|
92
24
|
symbol: 'B',
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/write.ts","../src/utils/round.ts","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;;AAC3E,YAAA,OAAO,KAAU,EAAE;;AAEnB,gBAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;;SAEnB;KACe;AACpB;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function round(value: number, precision?: number): number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-stats",
|
|
3
3
|
"description": "Output Rollup stats",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.2.1-beta.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
"import": "./dist/index.mjs",
|
|
33
33
|
"require": "./dist/index.cjs",
|
|
34
34
|
"types": "./dist/index.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./extract": {
|
|
37
|
+
"import": "./dist/extract.mjs",
|
|
38
|
+
"require": "./dist/extract.cjs",
|
|
39
|
+
"types": "./dist/extract.d.ts"
|
|
35
40
|
}
|
|
36
41
|
},
|
|
37
42
|
"engines": {
|
|
@@ -53,7 +58,7 @@
|
|
|
53
58
|
},
|
|
54
59
|
"devDependencies": {
|
|
55
60
|
"@eslint/js": "^9.17.0",
|
|
56
|
-
"@release-it/conventional-changelog": "
|
|
61
|
+
"@release-it/conventional-changelog": "10.0.0",
|
|
57
62
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
58
63
|
"@tsconfig/node18": "^18.2.4",
|
|
59
64
|
"@types/lodash": "^4.17.13",
|
|
@@ -64,13 +69,13 @@
|
|
|
64
69
|
"husky": "^8.0.3",
|
|
65
70
|
"memfs": "^4.15.1",
|
|
66
71
|
"prettier": "^3.4.2",
|
|
67
|
-
"release-it": "
|
|
72
|
+
"release-it": "18.0.0",
|
|
68
73
|
"rollup": "^4.29.1",
|
|
69
74
|
"typescript": "^5.7.2",
|
|
70
75
|
"typescript-eslint": "^8.18.2",
|
|
71
76
|
"vitest": "^2.1.8"
|
|
72
77
|
},
|
|
73
|
-
"
|
|
74
|
-
"
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"rollup": "^3.0.0 || ^4.0.0"
|
|
75
80
|
}
|
|
76
81
|
}
|