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