react-native-bundle-discovery-ui 2.5.0 → 2.7.0-rc.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/pages/_common.js DELETED
@@ -1,324 +0,0 @@
1
- const platformColor = `transformOptions.platform = 'android' ? 'rgba(194, 239, 116, .4)' : 'rgba(119, 31, 218, .4)'`;
2
-
3
- function getPackage(entry) {
4
- return `
5
- $packages: $.packages;
6
- $totalSize: $.modules.sum(=>output.sizeInBytes);
7
- $toModule: => {
8
- ext: $.path.getFileExtension(),
9
- name: $.path,
10
- size: $.output.sizeInBytes.formatBytes(),
11
- percent: ($.output.sizeInBytes / $totalSize).percent(3),
12
- };
13
-
14
- ${entry}.group(=> path.getModulesName())
15
- .map(=> ({
16
- $pkgName: $.key;
17
- pkgName: $pkgName, // example: lodash
18
- size: $.value.sum(=>output.sizeInBytes),
19
- pkgInstances: $.value
20
- .group(=> path.split('node_modules/' + $pkgName).pick(0) + 'node_modules/' + $pkgName)
21
- .map(=> {
22
- $pkgNameWithPath: $.key;
23
- $pkgInfo: $packages.[path = $pkgNameWithPath][0];
24
- pkgName: $pkgNameWithPath, // example: node_modules/lodash
25
- version: $pkgInfo.version,
26
- metadata: $pkgInfo.metadata,
27
- size: $.value.sum(=> output.sizeInBytes),
28
- modules: $.value.map(=> $.$toModule()),
29
- }),
30
- }))`;
31
- }
32
-
33
- const metadataTooltip = {
34
- view: "text",
35
- when: "metadata.createdAt",
36
- data: "'Published ' + metadata.createdAt.formatDate() + ' (' + metadata.createdAt.timeAgo() + ')'",
37
- };
38
- const outdatedColor = "rgba(255, 165, 0, 0.35)";
39
-
40
- // Compact npm metadata badges (`metadata` from the report)
41
- function getMetadataBadges({
42
- deprecated,
43
- outdated,
44
- latestVersion,
45
- renderLatestVersion,
46
- }) {
47
- return [
48
- {
49
- view: "pill-badge",
50
- when: deprecated,
51
- data: `{ text: '⚠️ deprecated', message: ${deprecated} }`,
52
- color: "#cf222e",
53
- textColor: "white",
54
- darkColor: "#f85149",
55
- darkTextColor: "white",
56
- tooltip: "text: message",
57
- },
58
- renderLatestVersion
59
- ? {
60
- view: "pill-badge",
61
- when: outdated,
62
- data: `{ text: '↑ v' + ${latestVersion} }`,
63
- color: outdatedColor,
64
- tooltip: "text: 'Latest version on npm'",
65
- }
66
- : null,
67
- ].filter(Boolean);
68
- }
69
-
70
- function getPackageList({
71
- data,
72
- itemPkgName,
73
- showCopiesBadge,
74
- expanded,
75
- limit,
76
- subLimit,
77
- }) {
78
- return {
79
- view: "list",
80
- data,
81
- emptyText: "⚠️ No packages found",
82
- limit,
83
- item: {
84
- view: "tree",
85
- expanded,
86
- itemConfig: {
87
- content: [
88
- itemPkgName,
89
- "text: ' '",
90
- "pill-badge:{ text: size.formatBytes(), color: 'rgba(120, 177, 9, 0.35)' }",
91
- // Summary of all instances (visible when the tree is collapsed)
92
- ...getMetadataBadges({
93
- deprecated: "pkgInstances.metadata.deprecated[0]",
94
- outdated: "pkgInstances.[metadata and not metadata.isLatest]",
95
- latestVersion: "pkgInstances.metadata.latestVersion[0]",
96
- renderLatestVersion: false,
97
- }),
98
- showCopiesBadge
99
- ? {
100
- view: "pill-badge",
101
- when: "pkgInstances.size() > 1",
102
- data: "(pkgInstances.size() - 1).pluralBadge(['copy','copies'], '+')",
103
- color: "rgba(255, 0, 0, 0.35)",
104
- }
105
- : null,
106
- {
107
- view: "pill-badge",
108
- data: "pkgInstances.modules.size().pluralBadge(['file','files'])",
109
- },
110
- ].filter(Boolean),
111
- children: `$.pkgInstances`,
112
- itemConfig: {
113
- view: "tree-leaf",
114
- limit: subLimit,
115
- content: [
116
- //
117
- "text:pkgName",
118
- "text:' '",
119
- {
120
- view: "pill-badge",
121
- data: "{ text: 'v' + version, metadata }",
122
- color: "#0af",
123
- tooltip: metadataTooltip,
124
- },
125
- "pill-badge:{ text: size.formatBytes(), color: 'rgba(120, 177, 9, 0.35)' }",
126
- {
127
- view: "pill-badge",
128
- data: "modules.size().pluralBadge(['file','files'])",
129
- },
130
- ...getMetadataBadges({
131
- deprecated: "metadata.deprecated",
132
- outdated: "metadata and not metadata.isLatest",
133
- latestVersion: "metadata.latestVersion",
134
- renderLatestVersion: true,
135
- }),
136
- ],
137
- children: `$.modules`,
138
- itemConfig: {
139
- view: "tree-leaf",
140
- content: getTreeModule({ hasPercent: true }),
141
- },
142
- },
143
- },
144
- },
145
- };
146
- }
147
-
148
- function getTreeModule({ hasTextMatch = false, hasPercent = false } = {}) {
149
- return [
150
- "pill-badge:{ text: ext, color: ext.getExtColor() }",
151
- hasTextMatch
152
- ? {
153
- view: "link",
154
- content: hasTextMatch ? "text-match" : "text",
155
- data: `{
156
- href: name.pageLink("module", {}),
157
- text: name,
158
- match: #.filterByPathStr
159
- }`,
160
- }
161
- : {
162
- view: "link",
163
- data: `{ href: $.name.pageLink("module", {}), text: $.name }`,
164
- },
165
- "text:' '",
166
- {
167
- view: "badge",
168
- when: "isEntry",
169
- text: "Entrypoint",
170
- color: "gold",
171
- textColor: "black",
172
- },
173
- "pill-badge:{ text: size, color: 'rgba(120, 177, 9, 0.35)' }",
174
- hasPercent
175
- ? "pill-badge:{ text: percent, color: 'rgba(120, 177, 9, 0.35)' }"
176
- : null,
177
- ].filter(Boolean);
178
- }
179
- function getModulesTree({ data, limit }) {
180
- if (!data) {
181
- throw new Error("[getModulesTree]: data is required");
182
- }
183
- return {
184
- view: "content-filter",
185
- data,
186
- name: "filterByPathStr",
187
- content: {
188
- view: "list",
189
- limit,
190
- data: ".[name ~= #.filterByPathStr]",
191
- emptyText: "⚠️ No modules found",
192
- item: {
193
- view: "tree",
194
- expanded: false,
195
- itemConfig: {
196
- content: getTreeModule({ hasTextMatch: true }),
197
- children: `
198
- [
199
- {
200
- title:'Imported by modules',
201
- data: $.reasons,
202
- type: 'reasons',
203
- },
204
- {
205
- title:'Similar copies',
206
- data: $.duplicates,
207
- type: 'duplicates',
208
- }
209
- ].filter(=> $.data.size() > 0)
210
- `,
211
- itemConfig: {
212
- view: "switch",
213
- content: [
214
- {
215
- when: 'type="reasons"',
216
- content: {
217
- view: "tree-leaf",
218
- content: [
219
- "text:title",
220
- "text:' '",
221
- "badge:{ text: $.data.size() }",
222
- ],
223
- children: `$.data`,
224
- itemConfig: {
225
- view: "tree-leaf",
226
- content: getTreeModule(),
227
- },
228
- },
229
- },
230
- {
231
- when: 'type="duplicates"',
232
- content: {
233
- view: "tree-leaf",
234
- content: [
235
- "text:title",
236
- "text:' '",
237
- "badge:{ text: $.data.size() }",
238
- ],
239
- children: `$.data`,
240
- itemConfig: {
241
- view: "tree-leaf",
242
- content: getTreeModule(),
243
- },
244
- },
245
- },
246
- ],
247
- },
248
- },
249
- },
250
- },
251
- };
252
- }
253
-
254
- const metadata = {
255
- platform: {
256
- when: "transformOptions.platform",
257
- view: "badge",
258
- data: `{ prefix: 'Platform: ', text: transformOptions.platform, color: ${platformColor} }`,
259
- },
260
- size: {
261
- when: "modules.filter(=> $.path has 'node_modules').size()",
262
- view: "badge",
263
- data: `{ prefix: 'Size: ', text: modules.sum(=>output.sizeInBytes).formatBytes(), color: ${platformColor} }`,
264
- },
265
- node_modules_size: {
266
- when: "modules.filter(=> $.path has 'node_modules').size()",
267
- view: "badge",
268
- data: "{ prefix: 'node_modules: ', text: modules.filter(=> $.path has 'node_modules').sum(=>output.sizeInBytes).formatBytes(), color: 'rgba(255, 0, 0, 0.35)' }",
269
- },
270
- source_code_size: {
271
- when: "modules.filter(=> $.path has 'node_modules').size()",
272
- view: "badge",
273
- data: `
274
- // vars
275
- $totalSize: modules.sum(=>output.sizeInBytes);
276
- $thirdPartySize: modules.filter(=> $.path has 'node_modules').sum(=>output.sizeInBytes);
277
- // return data
278
- { prefix: 'Source code: ', text: ($totalSize - $thirdPartySize).formatBytes(), color: 'rgba(148, 111, 234, 0.5)' }`,
279
- },
280
- is_dev: {
281
- when: "transformOptions.dev != null",
282
- view: "badge",
283
- data: "{ prefix: '__DEV__: ', text: transformOptions.dev }",
284
- },
285
- is_minified: {
286
- when: "transformOptions.minify != null",
287
- view: "badge",
288
- data: "{ prefix: 'Minify: ', text: transformOptions.minify }",
289
- },
290
- };
291
-
292
- const externalLinkHtml = `<svg class="my-icon my-icon-link" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" ><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3"></path></svg>`;
293
-
294
- function getCopyToClipboardButton({ textToCopy, className, text }) {
295
- return {
296
- view: "button",
297
- className: `${className ?? ""} copy-to-clipboard`,
298
- text,
299
- data: `{ textToCopy: ${textToCopy} }`,
300
- onClick(elm, data) {
301
- clearTimeout(elm.__timer);
302
- navigator.clipboard
303
- .writeText(data.textToCopy)
304
- .then(() => {
305
- elm.classList.add("done");
306
- elm.__timer = setTimeout(() => elm.classList.remove("done"), 2000);
307
- })
308
- .catch(() => {
309
- elm.classList.add("err");
310
- elm.__timer = setTimeout(() => elm.classList.remove("err"), 2000);
311
- });
312
- },
313
- };
314
- }
315
-
316
- module.exports = {
317
- getCopyToClipboardButton,
318
- getPackage,
319
- getPackageList,
320
- externalLinkHtml,
321
- getTreeModule,
322
- getModulesTree,
323
- metadata,
324
- };
package/pages/default.js DELETED
@@ -1,211 +0,0 @@
1
- const {
2
- metadata,
3
- getModulesTree,
4
- getPackage,
5
- getPackageList,
6
- getCopyToClipboardButton,
7
- } = require("./_common");
8
-
9
- const topMetaData = [
10
- metadata.platform,
11
- metadata.size,
12
- metadata.source_code_size,
13
- metadata.node_modules_size,
14
- metadata.is_dev,
15
- metadata.is_minified,
16
- ];
17
-
18
- const TABS = {
19
- TREEMAP_FOAMTREE: "treemap-foamtree",
20
- MODULES: "modules",
21
- PACKAGES: "packages",
22
- DUPLICATES: "duplicates",
23
- };
24
-
25
- function parseHashRef(url = window.location.href) {
26
- return new URL(url).hash.split(":")?.[1];
27
- }
28
-
29
- discovery.page.define("default", [
30
- ...topMetaData,
31
-
32
- {
33
- view: "tabs",
34
- name: "mainTabs",
35
- className: "main-tabs",
36
- value: parseHashRef() ?? TABS.TREEMAP_FOAMTREE,
37
- tabs: [
38
- {
39
- value: TABS.TREEMAP_FOAMTREE,
40
- text: "Treemap chart",
41
- className: `main-tabs-${TABS.TREEMAP_FOAMTREE}`,
42
- },
43
- {
44
- value: TABS.PACKAGES,
45
- className: `main-tabs-${TABS.PACKAGES}`,
46
- content: [
47
- "text:'Packages '",
48
- `pill-badge: modules.filter(=> path has "node_modules").group(=> path.getModulesName(), => 0).size()`,
49
- ],
50
- },
51
- {
52
- value: TABS.MODULES,
53
- className: `main-tabs-${TABS.MODULES}`,
54
- content: ["text:'Modules '", "pill-badge: modules.size()"],
55
- },
56
- {
57
- value: TABS.DUPLICATES,
58
- className: `main-tabs-${TABS.DUPLICATES}`,
59
- content: [
60
- "text:'Duplicate modules '",
61
- "pill-badge: modules.filter(=> duplicates).size()",
62
- ],
63
- },
64
- ],
65
- content: {
66
- view: "switch",
67
- context(data, context) {
68
- // FIXME - common nobody handle navigation in such way :(
69
- const isHashChangeEvent = new Error("").stack.includes("Promise.all");
70
- discovery.overridePageHashStateWithAnchor({
71
- id: "default",
72
- ref: isHashChangeEvent ? discovery.pageRef : context.mainTabs,
73
- });
74
- discovery.cancelScheduledRender();
75
-
76
- const id = discovery.pageRef ?? TABS.TREEMAP_FOAMTREE;
77
-
78
- setTimeout(() => {
79
- discovery.dom.root
80
- .querySelectorAll(".main-tabs>div>.onclick")
81
- .forEach((e) => e.classList.remove("active"));
82
- discovery.dom.root
83
- .querySelectorAll(`.main-tabs .main-tabs-${id}`)
84
- .forEach((e) => e.classList.add("active"));
85
- }, 50);
86
-
87
- return {
88
- ...context,
89
- id,
90
- };
91
- },
92
- content: [
93
- {
94
- when: `#.id="${TABS.TREEMAP_FOAMTREE}"`,
95
- content: {
96
- view: "content-filter",
97
- name: "filterByPathStr",
98
- debounce: 300,
99
- className: "foamtree-filter",
100
- content: {
101
- view: "foamtree",
102
- data: `
103
- $root: $.rootFolder;
104
- $applyFilter: => #.filterByPathStr ? $.modules.filter(=> $.path ~= #.filterByPathStr) : $.modules;
105
- $dataObject: $.$applyFilter()
106
- .map(=> {path, size: $.output.sizeInBytes})
107
- .transformFilesList($root, "foamtree");
108
-
109
- {
110
- options: {
111
- dataObject: $dataObject,
112
- descriptionGroupSize: 0.05,
113
- descriptionGroupMinHeight: 30,
114
- }
115
- }
116
- `,
117
- },
118
- },
119
- },
120
- {
121
- when: `#.id="${TABS.MODULES}"`,
122
- content: getModulesTree({
123
- limit: 200,
124
- data: `
125
- $entryPoint: $.entryPointPath;
126
- $totalSize: modules.sum(=>output.sizeInBytes);
127
- $toModule: => {
128
- ext: $.path.getFileExtension(),
129
- name: $.path,
130
- size: $.output.sizeInBytes.formatBytes(),
131
- percent: ($.output.sizeInBytes / $totalSize).percent(3),
132
- };
133
- modules.map(=> {
134
- ...$.$toModule(),
135
- isEntry: $.isEntry,
136
- reasons: $.dependents.map(=> $.$toModule()),
137
- duplicates: $.duplicates.map(=> $.$toModule()),
138
- })
139
- `,
140
- }),
141
- },
142
- {
143
- when: `#.id="${TABS.PACKAGES}"`,
144
- content: [
145
- getCopyToClipboardButton({
146
- text: "Copy list",
147
- className: "copy-before-ask-chatgpt",
148
- textToCopy: `"- " + modules.filter(=> path has "node_modules").group(=> path.getModulesName()).map(=> $.key).join("\\n- ")`,
149
- }),
150
- {
151
- view: "link",
152
- className: "ask-chatgpt view-button",
153
- text: "and Ask ChatGPT",
154
- external: true,
155
- data: `{
156
- href: $.askChatGPTAboutPackages()
157
- }`,
158
- },
159
- {
160
- view: "content-filter",
161
- //
162
- data: `${getPackage(`modules.filter(=> path has "node_modules")`)}.sort(pkgInstances desc, size desc)`,
163
- className: "packages-content",
164
- name: "filterByPathStr",
165
- content: getPackageList({
166
- showCopiesBadge: true,
167
- expanded: false,
168
- limit: 200,
169
- subLimit: 50,
170
- data: ".[pkgName ~= #.filterByPathStr]",
171
- itemPkgName: {
172
- view: "link",
173
- content: "text-match",
174
- data: `{
175
- href: pkgName.pageLink("package", {}),
176
- text: pkgName,
177
- match: #.filterByPathStr
178
- }`,
179
- },
180
- }),
181
- },
182
- ],
183
- },
184
- {
185
- when: `#.id="${TABS.DUPLICATES}"`,
186
- content: getModulesTree({
187
- data: `
188
- // values
189
- $duplicatesOnly: modules.filter(=> duplicates);
190
- $totalSize: $duplicatesOnly.sum(=>output.sizeInBytes);
191
- $toModule: => {
192
- ext: $.path.getFileExtension(),
193
- name: $.path,
194
- size: $.output.sizeInBytes.formatBytes(),
195
- percent: ($.output.sizeInBytes / $totalSize).percent(3),
196
- };
197
- // return
198
- $duplicatesOnly.map(=> {
199
- ...$.$toModule(),
200
- reasons: $.dependents.map(=> $.$toModule()),
201
- duplicates: $.duplicates.map(=> $.$toModule()),
202
- })
203
- `,
204
- }),
205
- },
206
- ],
207
- },
208
- },
209
-
210
- // END
211
- ]);