react-native-bundle-discovery 1.3.1 → 2.0.0-rc.2

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/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
- ]);
package/pages/module.js DELETED
@@ -1,314 +0,0 @@
1
- const {
2
- getModulesTree,
3
- getTreeModule,
4
- getCopyToClipboardButton,
5
- } = require("./_common");
6
-
7
- function getMetroWarn({ when, href, linkText, content }) {
8
- return {
9
- view: "alert-warning",
10
- when,
11
- className: "m-v-8",
12
- content: [
13
- ...content,
14
- {
15
- view: "link",
16
- data: {
17
- external: true,
18
- href,
19
- text: linkText,
20
- },
21
- },
22
- ],
23
- };
24
- }
25
-
26
- discovery.page.define("module", {
27
- view: "context",
28
- data: `{
29
- $currentModule: $.modules.[path = #.id].pick(0);
30
- ...$,
31
- currentModule: $currentModule,
32
- isEntry: $currentModule.isEntry,
33
- isInjectedByMetro: $currentModule.path = '__prelude__' or $currentModule.path has '@react-native/js-polyfills',
34
- }`,
35
- content: [
36
- {
37
- view: "h2",
38
- content: [
39
- //
40
- 'text: "Module: "',
41
- "text: $.currentModule.path",
42
- getCopyToClipboardButton({
43
- textToCopy: `$.currentModule.path`,
44
- className: "m-l-0_5em",
45
- }),
46
- ],
47
- },
48
-
49
- {
50
- view: "tabs",
51
- name: "tabs",
52
- // value: "networkGraph", //FIXME
53
- tabs: [
54
- {
55
- value: "mcontent",
56
- text: "Module content",
57
- },
58
- {
59
- value: "networkGraph",
60
- when: "not isInjectedByMetro and not isEntry",
61
- text: "Imported by modules",
62
- },
63
- {
64
- value: "mduplicates",
65
- when: "not isInjectedByMetro and not isEntry and currentModule.duplicates",
66
- text: "Duplicates",
67
- },
68
- ],
69
- content: {
70
- view: "switch",
71
- content: [
72
- {
73
- when: '#.tabs="mcontent"',
74
- content: [
75
- getMetroWarn({
76
- when: "$.currentModule.path = '__prelude__'",
77
- content: [
78
- "html: '<b>__prelude__</b>'",
79
- "text: ' is a special runtime code that was generated by the Metro bundler, see: '",
80
- ],
81
- href: "https://github.com/facebook/metro/blob/f595e9e1c9021ad372b489be8958cc298eb1e0d9/packages/metro/src/lib/getPreludeCode.js#L25-L33",
82
- linkText: "getPreludeCode.js",
83
- }),
84
- getMetroWarn({
85
- when: "$.currentModule.path has '@react-native/js-polyfills'",
86
- content: [
87
- "html: '<b>@react-native/js-polyfills/*</b>'",
88
- "text: ' is a special package that was injected by the Metro bundler, see: '",
89
- ],
90
- href: "https://github.com/facebook/react-native/blob/198c6fc81cda67a46fff457cc39eb2a297eddc01/packages/metro-config/src/index.flow.js#L61",
91
- linkText: "rn/metro-config/index.js",
92
- }),
93
- getMetroWarn({
94
- when: "$.currentModule.path has 'metro-runtime'",
95
- content: [
96
- "html: '<b>metro-runtime/*</b>'",
97
- "text: ' is a special package that was injected by the Metro bundler, see: '",
98
- ],
99
- href: "https://github.com/facebook/metro/blob/f595e9e1c9021ad372b489be8958cc298eb1e0d9/packages/metro-config/src/defaults/defaults.js#L61-L63",
100
- linkText: "metro-config/index.js",
101
- }),
102
- {
103
- view: "hstack",
104
- className: "flex-no-wrap",
105
- content: [
106
- {
107
- view: "block",
108
- className: "width-50p",
109
- content: [
110
- "h5: 'Source'",
111
- {
112
- view: "source",
113
- syntax: "ts",
114
- source: "=$.currentModule.source.code",
115
- },
116
- ],
117
- },
118
- {
119
- view: "block",
120
- className: "width-50p",
121
- content: [
122
- {
123
- view: "h5",
124
- content: 'text:"Output"',
125
- },
126
- {
127
- view: "context",
128
- modifiers: [
129
- {
130
- view: "checkbox",
131
- name: "prettify",
132
- checked: true,
133
- className: "prettify-checkbox",
134
- content: 'text:"Prettify"',
135
- },
136
- ],
137
- content: [
138
- {
139
- view: "source-prettify",
140
- syntax: "ts",
141
- source:
142
- "=(#.prettify ? $.currentModule.output.code.prettifyJS() : $.currentModule.output.code)",
143
- },
144
- ],
145
- },
146
- ],
147
- },
148
- ],
149
- },
150
- ],
151
- },
152
- {
153
- when: '#.tabs="networkGraph"',
154
- content: {
155
- view: "context",
156
- context: `{ ...#, maxParentDepth: $.currentModule.getBestNetworkGraphSize() }`,
157
- modifiers: [
158
- "html: '<br/>'",
159
- "text:'Max parent depth: '",
160
- {
161
- view: "input",
162
- name: "maxParentDepth",
163
- className: "inline-block",
164
- htmlType: "number",
165
- htmlMin: 1,
166
- htmlMax: 10,
167
- },
168
- ],
169
- content: [
170
- {
171
- view: "context",
172
- data: `{
173
- // Vars
174
- $tmp: $.currentModule.getNetworkGraph({ maxParentDepth: #.maxParentDepth });
175
- $limit: 150;
176
- // Return data
177
- currentModule: $.currentModule,
178
- entryPointPath: $tmp.entryPointPath,
179
- limit: $limit,
180
- data: $tmp.data,
181
- isGraphTooBig: $tmp.data.size() > $limit,
182
- }`,
183
- content: [
184
- // TODO use for debugging
185
- // {
186
- // view: "struct",
187
- // expanded: 2,
188
- // },
189
- {
190
- when: "isGraphTooBig",
191
- view: "block",
192
- className: "m-v-8",
193
- content: [
194
- {
195
- view: "alert-warning",
196
- data: '"Amount of dependencies "+$.data.size()+" (limit: "+$.limit+") are too big to display as a graph :("',
197
- },
198
- ],
199
- },
200
- {
201
- view: "hstack",
202
- className: "flex-no-wrap two-column",
203
- content: [
204
- {
205
- when: "not isGraphTooBig",
206
- view: "highcharts",
207
- data: `{
208
- options: {
209
- chart: {
210
- type: "networkgraph",
211
- height: "500px",
212
- },
213
- title: {
214
- text: "Import Dependency Graph",
215
- align: "left",
216
- },
217
- subtitle: {
218
- text: "It shows which modules import this file (Red - current module, Gold - entry point)",
219
- align: "left",
220
- },
221
- plotOptions: {
222
- networkgraph: {
223
- keys: ["from", "to"],
224
- layoutAlgorithm: {
225
- enableSimulation: true,
226
- friction: -0.9,
227
- gravitationalConstant: 0.06,
228
- },
229
- },
230
- },
231
- series: [
232
- {
233
- accessibility: {
234
- enabled: false,
235
- },
236
- dataLabels: {
237
- enabled: true,
238
- linkFormat: "",
239
- style: {
240
- fontSize: "0.8em",
241
- fontWeight: "normal",
242
- },
243
- },
244
- id: "lang-tree",
245
- data: $.data,
246
- nodes:[
247
- { id: $.currentModule.path, marker: { radius: 15, fillColor: 'red' }, },
248
- { id: $.entryPointPath, marker: { radius: 15, fillColor: 'gold' } }
249
- ].filter(=> id),
250
- },
251
- ],
252
- },
253
- }`,
254
- },
255
-
256
- {
257
- view: "block",
258
- content: [
259
- "h4: 'Modules that import this file: ' + $.currentModule.path",
260
- {
261
- view: "list",
262
- data: `
263
- $totalSize: modules.sum(=>output.sizeInBytes);
264
- $toModule: => {
265
- $deepIdx: $$ + 1;
266
- ext: $.path.getFileExtension(),
267
- name: $.path,
268
- size: $.output.sizeInBytes.formatBytes(),
269
- percent: ($.output.sizeInBytes / $totalSize).percent(3),
270
- children: $deepIdx < 2 ? $.dependents.map(=> $.$toModule()) : null,
271
- };
272
- $.currentModule.dependents.map(=> $.$toModule(0))
273
- `,
274
- emptyText: "⚠️ No importing modules found",
275
- item: {
276
- view: "tree",
277
- expanded: false,
278
- itemConfig: {
279
- content: getTreeModule({
280
- hasTextMatch: true,
281
- }),
282
- children: `$.children`,
283
- },
284
- },
285
- },
286
- ],
287
- },
288
- ],
289
- },
290
- ],
291
- },
292
- ],
293
- },
294
- },
295
- {
296
- when: '#.tabs="mduplicates"',
297
- content: getModulesTree({
298
- data: `
299
- $totalSize: modules.sum(=>output.sizeInBytes);
300
- $toModule: => {
301
- ext: $.path.getFileExtension(),
302
- name: $.path,
303
- size: $.output.sizeInBytes.formatBytes(),
304
- percent: ($.output.sizeInBytes / $totalSize).percent(3),
305
- };
306
- currentModule.duplicates.map(=> $.$toModule())
307
- `,
308
- }),
309
- },
310
- ],
311
- },
312
- },
313
- ],
314
- });
package/pages/package.js DELETED
@@ -1,161 +0,0 @@
1
- const { externalLinkHtml } = require("./_common.js");
2
- const {
3
- getTreeModule,
4
- getPackage,
5
- getPackageList,
6
- getCopyToClipboardButton,
7
- } = require("./_common");
8
-
9
- discovery.page.define("package", {
10
- view: "context",
11
- data: `
12
- // Tmp variables
13
- $currentPkgName: #.id;
14
- ${getPackage(`$pkg: modules.filter(=> path has "node_modules" and path has $currentPkgName)`)}[0];
15
- $copies: $pkg.pkgInstances.size() - 1;
16
- $ver: $pkg.pkgInstances[0].version;
17
-
18
- // Return value
19
- {
20
- ...$,
21
- currentPkgHasCopies: $copies > 0,
22
- currentPkgCopiesCount: $copies,
23
- currentPkgVersion: $ver,
24
- currentPkgWithUniqVer: $pkg.pkgName + ($copies = 0 ? '@' + $ver : ''),
25
- currentPkgWithUniqVerNpm: $pkg.pkgName + ($copies = 0 ? '/v/' + $ver : ''),
26
- currentPkg: $pkg,
27
- }
28
- `,
29
- content: [
30
- // TODO uncomment for debugging
31
- // {
32
- // view: "struct",
33
- // data: "$.currentPkg",
34
- // },
35
-
36
- {
37
- view: "block",
38
- content: [
39
- {
40
- view: "h1",
41
- className: "inline-block no-margin",
42
- content: `badge: {
43
- text: $.currentPkgWithUniqVer,
44
- color: "#fffb5a",
45
- }`,
46
- },
47
- {
48
- when: "$.currentPkgCopiesCount > 0",
49
- view: "h2",
50
- className: "inline-block no-margin",
51
- content: [
52
- `badge: {
53
- text: '+' + $.currentPkgCopiesCount,
54
- postfix: $.currentPkgCopiesCount = 1 ? 'copy' : 'copies',
55
- color: "rgba(255, 0, 0, 0.35)"
56
- }`,
57
- ],
58
- },
59
- getCopyToClipboardButton({
60
- textToCopy: `$.currentPkg.pkgName`,
61
- className: "m-l-0_5em",
62
- }),
63
- ],
64
- },
65
-
66
- "html: '<br>'",
67
-
68
- {
69
- view: "block",
70
- content: [
71
- "text: 'Links: '",
72
- {
73
- view: "link",
74
- external: true,
75
- data: `{ href: "https://www.npmjs.com/package/" + currentPkgWithUniqVerNpm }`,
76
- content: [
77
- "text: 'npmjs.com'",
78
- `html: '<span class="my-icon-inline my-icon-12">${externalLinkHtml}</span>'`,
79
- ],
80
- },
81
- "text: ' '",
82
- {
83
- view: "link",
84
- external: true,
85
- data: `{ href: "https://bundlephobia.com/package/" + currentPkgWithUniqVer }`,
86
- content: [
87
- "text: 'bundlephobia.com'",
88
- `html: '<span class="my-icon-inline my-icon-12">${externalLinkHtml}</span>'`,
89
- ],
90
- },
91
- "text: ' '",
92
- {
93
- view: "link",
94
- external: true,
95
- data: `{ href: "https://packagephobia.com/result?p=" + currentPkgWithUniqVer }`,
96
- content: [
97
- "text: 'packagephobia.com'",
98
- `html: '<span class="my-icon-inline my-icon-12">${externalLinkHtml}</span>'`,
99
- ],
100
- },
101
- {
102
- view: "link",
103
- external: true,
104
- data: `{ href: "https://bundlejs.com/?q=" + currentPkgWithUniqVer, q: currentPkgWithUniqVer }`,
105
- content: [
106
- {
107
- view: "html",
108
- data: `'<img class="bundlejs-badge-img" src="https://deno.bundlejs.com/?q=' + q + '&badge=detailed" />'`,
109
- },
110
- ],
111
- },
112
- ],
113
- },
114
-
115
- "html: '<hr>'",
116
-
117
- {
118
- view: "block",
119
- content: getPackageList({
120
- data: "$.currentPkg",
121
- itemPkgName: "text: pkgName",
122
- showCopiesBadge: false,
123
- expanded: true,
124
- }),
125
-
126
- /*[
127
- {
128
- view: "list",
129
- data: "$.currentPkg",
130
- item: {
131
- view: "tree",
132
- expanded: true,
133
- itemConfig: {
134
- content: [
135
- "text: pkgName",
136
- "text: ' '",
137
- "pill-badge:{ text: size.formatBytes(), color: 'rgba(120, 177, 9, 0.35)' }",
138
- ],
139
- children: `$.pkgInstances`,
140
- itemConfig: {
141
- view: "tree-leaf",
142
- content: [
143
- //
144
- "text:pkgName",
145
- "text:' '",
146
- "pill-badge:{ text: 'v' + version, color: '#0af' }",
147
- "pill-badge:{ text: size.formatBytes(), color: 'rgba(120, 177, 9, 0.35)' }",
148
- ],
149
- children: `$.modules`,
150
- itemConfig: {
151
- view: "tree-leaf",
152
- content: getTreeModule({ hasPercent: false }),
153
- },
154
- },
155
- },
156
- },
157
- },
158
- ]*/
159
- },
160
- ],
161
- });