@bundle-stats/ui 4.13.4 → 4.14.0-beta.1
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/lib/components/asset-info/asset-info.js +1 -1
- package/lib/components/asset-info/asset-info.js.map +1 -1
- package/lib/components/bundle-modules/bundle-modules.js +16 -9
- package/lib/components/bundle-modules/bundle-modules.js.map +1 -1
- package/lib/components/bundle-modules/bundle-modules.utils.js +18 -4
- package/lib/components/bundle-modules/bundle-modules.utils.js.map +1 -1
- package/lib/components/bundle-modules/index.js +9 -6
- package/lib/components/bundle-modules/index.js.map +1 -1
- package/lib/components/entry-info/entry-info.js +16 -9
- package/lib/components/entry-info/entry-info.js.map +1 -1
- package/lib/components/entry-info/entry-info.module.css +34 -8
- package/lib/components/module-info/module-info.js +80 -16
- package/lib/components/module-info/module-info.js.map +1 -1
- package/lib/components/module-info/module-info.module.css +38 -0
- package/lib/components/package-info/package-info.js +1 -1
- package/lib/components/package-info/package-info.js.map +1 -1
- package/lib/components/run-info/run-info.module.css +1 -1
- package/lib/constants.js +21 -1
- package/lib/constants.js.map +1 -1
- package/lib/hooks/rows-sort.js.map +1 -1
- package/lib-esm/components/asset-info/asset-info.js +1 -1
- package/lib-esm/components/asset-info/asset-info.js.map +1 -1
- package/lib-esm/components/bundle-modules/bundle-modules.js +17 -10
- package/lib-esm/components/bundle-modules/bundle-modules.js.map +1 -1
- package/lib-esm/components/bundle-modules/bundle-modules.utils.js +19 -4
- package/lib-esm/components/bundle-modules/bundle-modules.utils.js.map +1 -1
- package/lib-esm/components/bundle-modules/index.js +9 -6
- package/lib-esm/components/bundle-modules/index.js.map +1 -1
- package/lib-esm/components/entry-info/entry-info.js +16 -9
- package/lib-esm/components/entry-info/entry-info.js.map +1 -1
- package/lib-esm/components/entry-info/entry-info.module.css +34 -8
- package/lib-esm/components/module-info/module-info.js +84 -19
- package/lib-esm/components/module-info/module-info.js.map +1 -1
- package/lib-esm/components/module-info/module-info.module.css +38 -0
- package/lib-esm/components/package-info/package-info.js +1 -1
- package/lib-esm/components/package-info/package-info.js.map +1 -1
- package/lib-esm/components/run-info/run-info.module.css +1 -1
- package/lib-esm/constants.js +20 -0
- package/lib-esm/constants.js.map +1 -1
- package/lib-esm/hooks/rows-sort.js.map +1 -1
- package/package.json +9 -9
- package/src/components/asset-info/asset-info.tsx +5 -2
- package/src/components/bundle-modules/bundle-modules.tsx +40 -19
- package/src/components/bundle-modules/bundle-modules.utils.ts +37 -14
- package/src/components/bundle-modules/index.tsx +19 -15
- package/src/components/entry-info/entry-info.module.css +34 -8
- package/src/components/entry-info/entry-info.tsx +47 -32
- package/src/components/module-info/module-info.module.css +38 -0
- package/src/components/module-info/module-info.stories.tsx +57 -3
- package/src/components/module-info/module-info.tsx +221 -40
- package/src/components/package-info/package-info.tsx +2 -3
- package/src/components/run-info/run-info.module.css +1 -1
- package/src/constants.ts +22 -1
- package/src/hooks/rows-sort.ts +17 -10
- package/src/types.d.ts +13 -0
- package/types/components/bundle-modules/bundle-modules.d.ts +4 -5
- package/types/components/bundle-modules/bundle-modules.utils.d.ts +3 -5
- package/types/components/entry-info/entry-info.d.ts +8 -10
- package/types/components/module-info/module-info.d.ts +4 -10
- package/types/constants.d.ts +21 -2
- package/types/hooks/rows-sort.d.ts +9 -14
- package/lib/components/bundle-modules/bundle-modules.constants.js +0 -9
- package/lib/components/bundle-modules/bundle-modules.constants.js.map +0 -1
- package/lib-esm/components/bundle-modules/bundle-modules.constants.js +0 -6
- package/lib-esm/components/bundle-modules/bundle-modules.constants.js.map +0 -1
- package/src/components/bundle-modules/bundle-modules.constants.ts +0 -4
- package/src/components/bundle-modules/bundle-modules.types.d.ts +0 -9
- package/types/components/bundle-modules/bundle-modules.constants.d.ts +0 -4
|
@@ -1,36 +1,210 @@
|
|
|
1
|
+
import type { ElementType } from 'react';
|
|
1
2
|
import React, { useMemo } from 'react';
|
|
2
3
|
import cx from 'classnames';
|
|
3
|
-
import
|
|
4
|
+
import orderBy from 'lodash/orderBy';
|
|
4
5
|
import noop from 'lodash/noop';
|
|
6
|
+
import type { MetricRunInfo, MetricTypeConfig, ReportMetricRow } from '@bundle-stats/utils';
|
|
5
7
|
import {
|
|
8
|
+
METRIC_TYPE_CONFIGS,
|
|
6
9
|
BUNDLE_MODULES_DUPLICATE,
|
|
7
10
|
FILE_TYPE_LABELS,
|
|
8
11
|
MODULE_SOURCE_TYPE_LABELS,
|
|
9
|
-
|
|
12
|
+
formatNumber,
|
|
10
13
|
getBundleModulesByChunk,
|
|
11
14
|
getBundleModulesByFileTpe,
|
|
12
15
|
getBundleModulesBySource,
|
|
16
|
+
getMetricRunInfo,
|
|
13
17
|
} from '@bundle-stats/utils';
|
|
14
|
-
import { Module, MetaChunk } from '@bundle-stats/utils/types/webpack';
|
|
18
|
+
import type { Module, MetaChunk } from '@bundle-stats/utils/types/webpack';
|
|
15
19
|
|
|
20
|
+
import type { ReportMetricModuleRow } from '../../types';
|
|
16
21
|
import { Stack } from '../../layout/stack';
|
|
17
22
|
import { Tag } from '../../ui/tag';
|
|
18
23
|
import { ComponentLink } from '../component-link';
|
|
24
|
+
import { RunInfo } from '../run-info';
|
|
19
25
|
import { EntryInfo, EntryInfoMetaLink } from '../entry-info';
|
|
20
26
|
import css from './module-info.module.css';
|
|
27
|
+
import { FlexStack } from '../../layout';
|
|
28
|
+
import { ModuleSizeMetric, ModuleSizeMetrics } from '../../constants';
|
|
29
|
+
|
|
30
|
+
interface DuplicateInstancesProps {
|
|
31
|
+
current: number;
|
|
32
|
+
baseline: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const DuplicateInstances = ({ current, baseline }: DuplicateInstancesProps) => {
|
|
36
|
+
const runInfo = getMetricRunInfo(
|
|
37
|
+
{ biggerIsBetter: false, formatter: formatNumber },
|
|
38
|
+
current,
|
|
39
|
+
baseline,
|
|
40
|
+
) as MetricRunInfo;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<RunInfo
|
|
44
|
+
current={runInfo.displayValue}
|
|
45
|
+
delta={runInfo.displayDeltaPercentage}
|
|
46
|
+
deltaPercentage={runInfo.displayDelta}
|
|
47
|
+
deltaType={runInfo.deltaType}
|
|
48
|
+
size="small"
|
|
49
|
+
className={css.duplicateInstances}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
enum ChunkDataState {
|
|
55
|
+
ADDED = 2,
|
|
56
|
+
REMOVED = 1,
|
|
57
|
+
NOT_CHANGED = 0,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const ChunkDataStateKind = {
|
|
61
|
+
[ChunkDataState.ADDED]: 'info',
|
|
62
|
+
[ChunkDataState.REMOVED]: 'danger',
|
|
63
|
+
[ChunkDataState.NOT_CHANGED]: 'default',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
interface ChunkData {
|
|
67
|
+
id: string;
|
|
68
|
+
state: ChunkDataState;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function compareChunksData(
|
|
72
|
+
currentChunkIds: Array<string>,
|
|
73
|
+
baselineChunkIds: Array<string>,
|
|
74
|
+
): Array<ChunkData> {
|
|
75
|
+
const result: Array<ChunkData> = [];
|
|
76
|
+
|
|
77
|
+
currentChunkIds.forEach((chunkId) => {
|
|
78
|
+
if (!baselineChunkIds.includes(chunkId)) {
|
|
79
|
+
result.push({ id: chunkId, state: ChunkDataState.ADDED });
|
|
80
|
+
} else {
|
|
81
|
+
result.push({ id: chunkId, state: ChunkDataState.NOT_CHANGED });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
baselineChunkIds.forEach((chunk) => {
|
|
86
|
+
if (!currentChunkIds.includes(chunk)) {
|
|
87
|
+
result.push({ id: chunk, state: ChunkDataState.REMOVED });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return orderBy(result, 'state', 'desc');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface ChunksDeltaProps {
|
|
95
|
+
customComponentLink: ElementType;
|
|
96
|
+
runs: Array<Module & MetricRunInfo>;
|
|
97
|
+
chunks: Array<MetaChunk>;
|
|
98
|
+
chunkIds: Array<string>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const ChunksDelta = (props: ChunksDeltaProps) => {
|
|
102
|
+
const { customComponentLink: CustomComponentLink, runs, chunks, chunkIds } = props;
|
|
103
|
+
|
|
104
|
+
const currentChunkIds = runs[0]?.chunkIds || [];
|
|
105
|
+
const baselineChunkIds = runs[runs.length - 1]?.chunkIds || [];
|
|
106
|
+
|
|
107
|
+
const chunksData = compareChunksData(currentChunkIds, baselineChunkIds);
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Stack space="xxxsmall">
|
|
111
|
+
<div>
|
|
112
|
+
{chunksData.map((chunkData) => {
|
|
113
|
+
const chunk = chunks?.find(({ id }) => id === chunkData.id);
|
|
114
|
+
|
|
115
|
+
if (!chunk) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<EntryInfoMetaLink
|
|
121
|
+
as={CustomComponentLink}
|
|
122
|
+
{...getBundleModulesByChunk(chunkIds, chunkData.id)}
|
|
123
|
+
className={cx(
|
|
124
|
+
css.chunksItem,
|
|
125
|
+
css[`chunksItem-${ChunkDataStateKind[chunkData.state]}`],
|
|
126
|
+
)}
|
|
127
|
+
>
|
|
128
|
+
{chunk.name}
|
|
129
|
+
</EntryInfoMetaLink>
|
|
130
|
+
);
|
|
131
|
+
})}
|
|
132
|
+
</div>
|
|
133
|
+
</Stack>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
interface ModuleSizeRunInfoProps {
|
|
138
|
+
metric: MetricTypeConfig;
|
|
139
|
+
title: string;
|
|
140
|
+
titleTooltip?: string;
|
|
141
|
+
current?: number;
|
|
142
|
+
baseline?: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const ModuleSizeRunInfo = (props: ModuleSizeRunInfoProps) => {
|
|
146
|
+
const { metric, title, titleTooltip, current, baseline } = props;
|
|
147
|
+
|
|
148
|
+
const runInfo = getMetricRunInfo(metric, current || 0, baseline || 0) as MetricRunInfo;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<RunInfo
|
|
152
|
+
title={title}
|
|
153
|
+
titleTooltip={titleTooltip}
|
|
154
|
+
current={runInfo.displayValue}
|
|
155
|
+
delta={runInfo.displayDeltaPercentage}
|
|
156
|
+
deltaPercentage={runInfo.displayDelta}
|
|
157
|
+
deltaType={runInfo.deltaType}
|
|
158
|
+
baseline={metric.formatter(baseline || 0)}
|
|
159
|
+
/>
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const renderRunInfo = (item: ReportMetricRow) => {
|
|
164
|
+
const itemModule = item as ReportMetricModuleRow;
|
|
165
|
+
|
|
166
|
+
const currentRun = itemModule.runs[0];
|
|
167
|
+
const baselineRun =
|
|
168
|
+
itemModule.runs.length > 1 ? itemModule.runs[itemModule.runs.length - 1] : null;
|
|
169
|
+
const metric = METRIC_TYPE_CONFIGS.METRIC_TYPE_FILE_SIZE;
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<FlexStack space="small" className={css.moduleSizes}>
|
|
173
|
+
{itemModule.duplicated && (
|
|
174
|
+
<>
|
|
175
|
+
<ModuleSizeRunInfo
|
|
176
|
+
metric={metric}
|
|
177
|
+
title={ModuleSizeMetrics[ModuleSizeMetric.TOTAL_SIZE].label}
|
|
178
|
+
titleTooltip={ModuleSizeMetrics[ModuleSizeMetric.TOTAL_SIZE].tooltip}
|
|
179
|
+
current={currentRun.sizeTotal}
|
|
180
|
+
baseline={baselineRun.sizeTotal}
|
|
181
|
+
/>
|
|
182
|
+
<ModuleSizeRunInfo
|
|
183
|
+
metric={metric}
|
|
184
|
+
title={ModuleSizeMetrics[ModuleSizeMetric.DUPLICATE_SIZE].label}
|
|
185
|
+
titleTooltip={ModuleSizeMetrics[ModuleSizeMetric.DUPLICATE_SIZE].tooltip}
|
|
186
|
+
current={currentRun.sizeDuplicate}
|
|
187
|
+
baseline={baselineRun.sizeDuplicate}
|
|
188
|
+
/>
|
|
189
|
+
</>
|
|
190
|
+
)}
|
|
191
|
+
<ModuleSizeRunInfo
|
|
192
|
+
metric={metric}
|
|
193
|
+
title={ModuleSizeMetrics[ModuleSizeMetric.SIZE].label}
|
|
194
|
+
titleTooltip={ModuleSizeMetrics[ModuleSizeMetric.SIZE].tooltip}
|
|
195
|
+
current={currentRun.size}
|
|
196
|
+
baseline={baselineRun.size}
|
|
197
|
+
/>
|
|
198
|
+
</FlexStack>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
21
201
|
|
|
22
202
|
interface ModuleInfoProps {
|
|
23
|
-
item:
|
|
24
|
-
label: string;
|
|
25
|
-
changed?: boolean;
|
|
26
|
-
duplicated?: boolean;
|
|
27
|
-
thirdParty?: boolean;
|
|
28
|
-
fileType?: string;
|
|
29
|
-
runs: Array<Module & MetricRunInfo>;
|
|
30
|
-
};
|
|
203
|
+
item: ReportMetricModuleRow;
|
|
31
204
|
chunks?: Array<MetaChunk>;
|
|
32
205
|
chunkIds?: Array<string>;
|
|
33
206
|
labels: Array<string>;
|
|
207
|
+
metricLabel?: string;
|
|
34
208
|
customComponentLink?: React.ElementType;
|
|
35
209
|
onClose: () => void;
|
|
36
210
|
}
|
|
@@ -42,6 +216,7 @@ export const ModuleInfo = (props: ModuleInfoProps & React.ComponentProps<'div'>)
|
|
|
42
216
|
labels,
|
|
43
217
|
chunks = [],
|
|
44
218
|
chunkIds = [],
|
|
219
|
+
metricLabel = '',
|
|
45
220
|
customComponentLink: CustomComponentLink = ComponentLink,
|
|
46
221
|
onClick = noop,
|
|
47
222
|
onClose,
|
|
@@ -69,37 +244,25 @@ export const ModuleInfo = (props: ModuleInfoProps & React.ComponentProps<'div'>)
|
|
|
69
244
|
? MODULE_SOURCE_TYPE_LABELS.THIRD_PARTY
|
|
70
245
|
: MODULE_SOURCE_TYPE_LABELS.FIRST_PARTY;
|
|
71
246
|
|
|
247
|
+
const currentChunkCount = (item.runs[0]?.chunkIds || []).length;
|
|
248
|
+
const baselineChunkCount = (item.runs[item.runs.length - 1]?.chunkIds || []).length;
|
|
249
|
+
const currentDuplicateInstances = currentChunkCount > 0 ? currentChunkCount - 1 : 0;
|
|
250
|
+
const baselineDuplicateInstances = baselineChunkCount > 0 ? baselineChunkCount - 1 : 0;
|
|
251
|
+
const hasDuplicates = currentDuplicateInstances !== 0 || baselineDuplicateInstances !== 0;
|
|
252
|
+
|
|
72
253
|
return (
|
|
73
|
-
<EntryInfo
|
|
254
|
+
<EntryInfo
|
|
255
|
+
item={item as ReportMetricRow}
|
|
256
|
+
labels={labels}
|
|
257
|
+
tags={tags}
|
|
258
|
+
onClose={onClose}
|
|
259
|
+
renderRunInfo={renderRunInfo}
|
|
260
|
+
runSizeLabel={metricLabel}
|
|
261
|
+
className={rootClassName}
|
|
262
|
+
>
|
|
74
263
|
<Stack space="xxxsmall">
|
|
75
|
-
{item.runs?.map(
|
|
76
|
-
(currentRun, index) =>
|
|
77
|
-
!isEmpty(currentRun?.chunkIds) && (
|
|
78
|
-
<EntryInfo.Meta label="Chunks" className={css.chunks}>
|
|
79
|
-
{labels[index]}:
|
|
80
|
-
{currentRun.chunkIds.map((chunkId) => {
|
|
81
|
-
const chunk = chunks?.find(({ id }) => id === chunkId);
|
|
82
|
-
|
|
83
|
-
if (!chunk) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<EntryInfoMetaLink
|
|
89
|
-
as={CustomComponentLink}
|
|
90
|
-
{...getBundleModulesByChunk(chunkIds, chunkId)}
|
|
91
|
-
className={css.chunksItem}
|
|
92
|
-
>
|
|
93
|
-
{chunk.name}
|
|
94
|
-
</EntryInfoMetaLink>
|
|
95
|
-
);
|
|
96
|
-
})}
|
|
97
|
-
</EntryInfo.Meta>
|
|
98
|
-
),
|
|
99
|
-
)}
|
|
100
|
-
|
|
101
264
|
{item?.fileType && (
|
|
102
|
-
<EntryInfo.Meta label="File type">
|
|
265
|
+
<EntryInfo.Meta label="File type" tooltip="Module file type: JS, CSS">
|
|
103
266
|
<EntryInfoMetaLink
|
|
104
267
|
as={CustomComponentLink}
|
|
105
268
|
{...getBundleModulesByFileTpe(item.fileType, fileTypeLabel)}
|
|
@@ -109,7 +272,7 @@ export const ModuleInfo = (props: ModuleInfoProps & React.ComponentProps<'div'>)
|
|
|
109
272
|
</EntryInfo.Meta>
|
|
110
273
|
)}
|
|
111
274
|
|
|
112
|
-
<EntryInfo.Meta label="Source">
|
|
275
|
+
<EntryInfo.Meta label="Source" tooltip="Module source type: first party, third party">
|
|
113
276
|
<EntryInfoMetaLink
|
|
114
277
|
as={CustomComponentLink}
|
|
115
278
|
{...getBundleModulesBySource(item.thirdParty || false, sourceTypeLabel)}
|
|
@@ -118,6 +281,24 @@ export const ModuleInfo = (props: ModuleInfoProps & React.ComponentProps<'div'>)
|
|
|
118
281
|
{sourceTypeLabel}
|
|
119
282
|
</EntryInfoMetaLink>
|
|
120
283
|
</EntryInfo.Meta>
|
|
284
|
+
|
|
285
|
+
{hasDuplicates && (
|
|
286
|
+
<EntryInfo.Meta label="Duplicates" tooltip="Module duplicate instances">
|
|
287
|
+
<DuplicateInstances
|
|
288
|
+
current={currentDuplicateInstances}
|
|
289
|
+
baseline={baselineDuplicateInstances}
|
|
290
|
+
/>
|
|
291
|
+
</EntryInfo.Meta>
|
|
292
|
+
)}
|
|
293
|
+
|
|
294
|
+
<EntryInfo.Meta label="Chunks" tooltip="Chunks that contain the module">
|
|
295
|
+
<ChunksDelta
|
|
296
|
+
runs={item.runs}
|
|
297
|
+
chunks={chunks}
|
|
298
|
+
chunkIds={chunkIds}
|
|
299
|
+
customComponentLink={CustomComponentLink}
|
|
300
|
+
/>
|
|
301
|
+
</EntryInfo.Meta>
|
|
121
302
|
</Stack>
|
|
122
303
|
</EntryInfo>
|
|
123
304
|
);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
-
import noop from 'lodash/noop';
|
|
3
2
|
import {
|
|
4
3
|
BUNDLE_PACKAGES_DUPLICATE,
|
|
5
4
|
PACKAGES_SEPARATOR,
|
|
@@ -79,14 +78,14 @@ export const PackageInfo = (props: PackageInfoProps & React.ComponentProps<'div'
|
|
|
79
78
|
return (
|
|
80
79
|
<EntryInfo
|
|
81
80
|
itemTitle={packageTitle}
|
|
82
|
-
item={item}
|
|
81
|
+
item={item as any}
|
|
83
82
|
labels={labels}
|
|
84
83
|
tags={tags}
|
|
85
84
|
runNameSelector="path"
|
|
86
85
|
onClose={onClose}
|
|
87
86
|
className={className}
|
|
88
87
|
>
|
|
89
|
-
<EntryInfo.Meta label="Path">
|
|
88
|
+
<EntryInfo.Meta label="Path" tooltip="Package path">
|
|
90
89
|
<FileName name={normalizedPackagePath} className={css.fileName} />
|
|
91
90
|
</EntryInfo.Meta>
|
|
92
91
|
|
package/src/constants.ts
CHANGED
|
@@ -39,9 +39,30 @@ export const METRICS_WEBPACK_PACKAGES = ['webpack.packageCount', 'webpack.duplic
|
|
|
39
39
|
export const SORT = {
|
|
40
40
|
ASC: 'asc',
|
|
41
41
|
DESC: 'desc',
|
|
42
|
-
};
|
|
42
|
+
} as const;
|
|
43
43
|
|
|
44
44
|
export enum MetricsDisplayType {
|
|
45
45
|
TABLE = 'table',
|
|
46
46
|
TREEMAP = 'treemap',
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
export enum ModuleSizeMetric {
|
|
50
|
+
SIZE = 'value',
|
|
51
|
+
DUPLICATE_SIZE = 'duplicateSize',
|
|
52
|
+
TOTAL_SIZE = 'totalSize',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const ModuleSizeMetrics = {
|
|
56
|
+
[ModuleSizeMetric.SIZE]: {
|
|
57
|
+
label: 'Size',
|
|
58
|
+
tooltip: 'Module size (excluding duplicate modules)',
|
|
59
|
+
},
|
|
60
|
+
[ModuleSizeMetric.TOTAL_SIZE]: {
|
|
61
|
+
label: 'Total size',
|
|
62
|
+
tooltip: 'Module total size (including duplicate modules)',
|
|
63
|
+
},
|
|
64
|
+
[ModuleSizeMetric.DUPLICATE_SIZE]: {
|
|
65
|
+
label: 'Duplicate size',
|
|
66
|
+
tooltip: 'Module duplicate size',
|
|
67
|
+
},
|
|
68
|
+
};
|
package/src/hooks/rows-sort.ts
CHANGED
|
@@ -5,15 +5,9 @@ import orderBy from 'lodash/orderBy';
|
|
|
5
5
|
import type { SortAction } from '../types';
|
|
6
6
|
import { SORT } from '../constants';
|
|
7
7
|
|
|
8
|
-
interface UseRowsSortParams {
|
|
9
|
-
rows: Array<unknown>;
|
|
10
|
-
initialField?: string;
|
|
11
|
-
initialDirection?: SortAction['direction'];
|
|
12
|
-
getCustomSort: (item: any) => Array<string | number | boolean>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
8
|
export const getSortFn =
|
|
16
|
-
(fieldPath: string, getCustomSort: UseRowsSortParams['getCustomSort']) =>
|
|
9
|
+
<TRow>(fieldPath: string, getCustomSort: UseRowsSortParams<TRow>['getCustomSort']) =>
|
|
10
|
+
(item: TRow) => {
|
|
17
11
|
if (!fieldPath) {
|
|
18
12
|
return getCustomSort(item);
|
|
19
13
|
}
|
|
@@ -21,12 +15,25 @@ export const getSortFn =
|
|
|
21
15
|
return get(item, fieldPath) || 0;
|
|
22
16
|
};
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
interface UseRowsSortParams<TRow> {
|
|
19
|
+
rows: Array<TRow>;
|
|
20
|
+
initialField?: string;
|
|
21
|
+
initialDirection?: SortAction['direction'];
|
|
22
|
+
getCustomSort: (item: any) => Array<string | number | boolean>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface UseRowsSort<TRow> {
|
|
26
|
+
items: Array<TRow>;
|
|
27
|
+
sort: SortAction;
|
|
28
|
+
updateSort: (params: SortAction) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const useRowsSort = <TRow>({
|
|
25
32
|
rows,
|
|
26
33
|
initialField = 'runs[0].delta',
|
|
27
34
|
initialDirection = 'desc',
|
|
28
35
|
getCustomSort,
|
|
29
|
-
}: UseRowsSortParams) => {
|
|
36
|
+
}: UseRowsSortParams<TRow>): UseRowsSort<TRow> => {
|
|
30
37
|
const [sort, updateSort] = useState({ field: initialField, direction: initialDirection });
|
|
31
38
|
|
|
32
39
|
const orderedRows = useMemo(
|
package/src/types.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { ReportMetricRow } from '@bundle-stats/utils';
|
|
2
|
+
import type { Module } from '@bundle-stats/utils/types/webpack/types';
|
|
3
|
+
|
|
1
4
|
export interface SortAction {
|
|
2
5
|
field: string;
|
|
3
6
|
direction: 'asc' | 'desc' | '';
|
|
@@ -15,3 +18,13 @@ type FilterGroupFieldData = {
|
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
type FilterFieldsData = Record<string, FilterFieldData | FilterGroupFieldData>;
|
|
21
|
+
|
|
22
|
+
export type ReportMetricModuleRow = {
|
|
23
|
+
thirdParty: boolean;
|
|
24
|
+
duplicated: boolean;
|
|
25
|
+
fileType: string;
|
|
26
|
+
} & Omit<ReportMetricRow, 'runs'> & {
|
|
27
|
+
runs: Array<
|
|
28
|
+
(Module & ReportMetricRun & { size: number; sizeDuplicate: number; sizeTotal: number }) | null
|
|
29
|
+
>;
|
|
30
|
+
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type Job } from '@bundle-stats/utils';
|
|
3
3
|
import { WebpackChunk } from '@bundle-stats/utils';
|
|
4
|
-
import { SortAction } from '../../types';
|
|
5
|
-
import {
|
|
6
|
-
import type { ReportMetricModuleRow } from './bundle-modules.types';
|
|
4
|
+
import type { ReportMetricModuleRow, SortAction } from '../../types';
|
|
5
|
+
import { ModuleSizeMetric } from '../../constants';
|
|
7
6
|
interface BundleModulesProps extends React.ComponentProps<'div'> {
|
|
8
7
|
jobs?: Array<Job>;
|
|
9
8
|
items?: Array<ReportMetricModuleRow>;
|
|
@@ -21,8 +20,8 @@ interface BundleModulesProps extends React.ComponentProps<'div'> {
|
|
|
21
20
|
entryId?: string;
|
|
22
21
|
hideEntryInfo: () => void;
|
|
23
22
|
showEntryInfo: (entryId: string) => void;
|
|
24
|
-
moduleMetric:
|
|
25
|
-
setModuleMetric: (newValue:
|
|
23
|
+
moduleMetric: ModuleSizeMetric;
|
|
24
|
+
setModuleMetric: (newValue: ModuleSizeMetric) => void;
|
|
26
25
|
customComponentLink: React.ElementType;
|
|
27
26
|
}
|
|
28
27
|
export declare const BundleModules: (props: BundleModulesProps) => React.JSX.Element;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import type { ReportMetricModuleRow } from './bundle-modules.types';
|
|
5
|
-
export declare const addRowFlags: (row: Module & ReportMetricRow) => ReportMetricModuleRow;
|
|
1
|
+
import type { WebpackChunk, ReportMetricRow } from '@bundle-stats/utils';
|
|
2
|
+
import type { FilterFieldsData, ReportMetricModuleRow } from '../../types';
|
|
3
|
+
export declare const addRowFlags: (row: ReportMetricRow) => ReportMetricModuleRow;
|
|
6
4
|
export declare const getCustomSort: (item: ReportMetricRow) => (string | boolean)[];
|
|
7
5
|
export declare const generateGetRowFilter: ({ chunkIds }: {
|
|
8
6
|
chunkIds: Array<string>;
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
+
import type { ElementType, ReactNode } from 'react';
|
|
1
2
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
+
import type { ReportMetricRow } from '@bundle-stats/utils';
|
|
3
4
|
interface EntryInfoMetaLinkProps {
|
|
4
|
-
as?:
|
|
5
|
+
as?: ElementType;
|
|
5
6
|
}
|
|
6
7
|
export declare const EntryInfoMetaLink: (props: EntryInfoMetaLinkProps & React.ComponentProps<"a">) => React.JSX.Element;
|
|
7
8
|
interface EntryInfoMetaProps {
|
|
8
9
|
label: string;
|
|
9
|
-
|
|
10
|
-
interface EntryRun {
|
|
11
|
-
name: string;
|
|
10
|
+
tooltip?: ReactNode;
|
|
12
11
|
}
|
|
13
12
|
interface EntryInfoProps {
|
|
14
13
|
itemTitle?: React.ReactNode;
|
|
15
|
-
item:
|
|
16
|
-
label: string;
|
|
17
|
-
runs: Array<EntryRun & MetricRunInfo>;
|
|
18
|
-
};
|
|
14
|
+
item: ReportMetricRow;
|
|
19
15
|
labels: Array<string>;
|
|
20
16
|
runNameSelector?: string;
|
|
21
17
|
runNameLabel?: string;
|
|
18
|
+
runSizeLabel?: string;
|
|
22
19
|
tags?: React.ReactNode;
|
|
23
20
|
onClose: () => void;
|
|
21
|
+
renderRunInfo?: (item: ReportMetricRow) => React.ReactNode;
|
|
24
22
|
}
|
|
25
23
|
export declare const EntryInfo: {
|
|
26
24
|
(props: EntryInfoProps & React.ComponentProps<"div">): React.JSX.Element;
|
|
27
|
-
Meta: ({ className, label, children, }: EntryInfoMetaProps & React.ComponentProps<"p">) => React.JSX.Element;
|
|
25
|
+
Meta: ({ className, label, tooltip, children, }: EntryInfoMetaProps & React.ComponentProps<"p">) => React.JSX.Element;
|
|
28
26
|
};
|
|
29
27
|
export {};
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { MetaChunk } from '@bundle-stats/utils/types/webpack';
|
|
3
|
+
import type { ReportMetricModuleRow } from '../../types';
|
|
4
4
|
interface ModuleInfoProps {
|
|
5
|
-
item:
|
|
6
|
-
label: string;
|
|
7
|
-
changed?: boolean;
|
|
8
|
-
duplicated?: boolean;
|
|
9
|
-
thirdParty?: boolean;
|
|
10
|
-
fileType?: string;
|
|
11
|
-
runs: Array<Module & MetricRunInfo>;
|
|
12
|
-
};
|
|
5
|
+
item: ReportMetricModuleRow;
|
|
13
6
|
chunks?: Array<MetaChunk>;
|
|
14
7
|
chunkIds?: Array<string>;
|
|
15
8
|
labels: Array<string>;
|
|
9
|
+
metricLabel?: string;
|
|
16
10
|
customComponentLink?: React.ElementType;
|
|
17
11
|
onClose: () => void;
|
|
18
12
|
}
|
package/types/constants.d.ts
CHANGED
|
@@ -13,10 +13,29 @@ export declare const METRICS_WEBPACK_ASSETS: string[];
|
|
|
13
13
|
export declare const METRICS_WEBPACK_MODULES: string[];
|
|
14
14
|
export declare const METRICS_WEBPACK_PACKAGES: string[];
|
|
15
15
|
export declare const SORT: {
|
|
16
|
-
ASC:
|
|
17
|
-
DESC:
|
|
16
|
+
readonly ASC: "asc";
|
|
17
|
+
readonly DESC: "desc";
|
|
18
18
|
};
|
|
19
19
|
export declare enum MetricsDisplayType {
|
|
20
20
|
TABLE = "table",
|
|
21
21
|
TREEMAP = "treemap"
|
|
22
22
|
}
|
|
23
|
+
export declare enum ModuleSizeMetric {
|
|
24
|
+
SIZE = "value",
|
|
25
|
+
DUPLICATE_SIZE = "duplicateSize",
|
|
26
|
+
TOTAL_SIZE = "totalSize"
|
|
27
|
+
}
|
|
28
|
+
export declare const ModuleSizeMetrics: {
|
|
29
|
+
value: {
|
|
30
|
+
label: string;
|
|
31
|
+
tooltip: string;
|
|
32
|
+
};
|
|
33
|
+
totalSize: {
|
|
34
|
+
label: string;
|
|
35
|
+
tooltip: string;
|
|
36
|
+
};
|
|
37
|
+
duplicateSize: {
|
|
38
|
+
label: string;
|
|
39
|
+
tooltip: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import type { SortAction } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export declare const getSortFn: <TRow>(fieldPath: string, getCustomSort: UseRowsSortParams<TRow>["getCustomSort"]) => (item: TRow) => any;
|
|
3
|
+
interface UseRowsSortParams<TRow> {
|
|
4
|
+
rows: Array<TRow>;
|
|
4
5
|
initialField?: string;
|
|
5
6
|
initialDirection?: SortAction['direction'];
|
|
6
7
|
getCustomSort: (item: any) => Array<string | number | boolean>;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
sort:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
updateSort: import("react").Dispatch<import("react").SetStateAction<{
|
|
15
|
-
field: string;
|
|
16
|
-
direction: "" | "asc" | "desc";
|
|
17
|
-
}>>;
|
|
18
|
-
items: unknown[];
|
|
19
|
-
};
|
|
9
|
+
interface UseRowsSort<TRow> {
|
|
10
|
+
items: Array<TRow>;
|
|
11
|
+
sort: SortAction;
|
|
12
|
+
updateSort: (params: SortAction) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const useRowsSort: <TRow>({ rows, initialField, initialDirection, getCustomSort, }: UseRowsSortParams<TRow>) => UseRowsSort<TRow>;
|
|
20
15
|
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModuleMetric = void 0;
|
|
4
|
-
var ModuleMetric;
|
|
5
|
-
(function (ModuleMetric) {
|
|
6
|
-
ModuleMetric["SIZE"] = "value";
|
|
7
|
-
ModuleMetric["TOTAL_SIZE"] = "totalSize";
|
|
8
|
-
})(ModuleMetric || (exports.ModuleMetric = ModuleMetric = {}));
|
|
9
|
-
//# sourceMappingURL=bundle-modules.constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-modules.constants.js","sourceRoot":"","sources":["../../../src/components/bundle-modules/bundle-modules.constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,8BAAc,CAAA;IACd,wCAAwB,CAAA;AAC1B,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle-modules.constants.js","sourceRoot":"","sources":["../../../src/components/bundle-modules/bundle-modules.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,8BAAc,CAAA;IACd,wCAAwB,CAAA;AAC1B,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Module } from '@bundle-stats/utils/lib-esm/webpack/types';
|
|
2
|
-
import type { ReportMetricRun } from '@bundle-stats/utils/types/report/types';
|
|
3
|
-
|
|
4
|
-
export type ReportMetricModuleRow = {
|
|
5
|
-
thirdParty: boolean;
|
|
6
|
-
duplicated: boolean;
|
|
7
|
-
fileType: string;
|
|
8
|
-
} & ReportMetricRun &
|
|
9
|
-
Module;
|