react-native-bundle-discovery 1.0.1 → 1.1.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/.discoveryrc.js CHANGED
@@ -2,7 +2,7 @@ const path = require("path");
2
2
 
3
3
  module.exports = {
4
4
  name: "react-native-bundle-discovery",
5
- data: () => require("./tmp/before_metro-stats.json"),
5
+ data: () => require("./tmp/rainbow-metro-stats.json"),
6
6
  setup: path.resolve(__dirname, "setup.js"),
7
7
  view: {
8
8
  assets: [
package/README.md CHANGED
@@ -1,13 +1,21 @@
1
1
  # react-native-bundle-discovery
2
2
 
3
- > [!WARNING]
4
- > Currently, everything is in a very early stage. The project is not yet ready for use.
5
-
6
3
  A simple package that helps developers visualize and analyze the bundle size of React Native apps.
7
4
  With this tool, you can easily explore your app's codebase, identify large or heavy packages, and inspect the structure of modules and code within your project.
8
5
 
9
6
  <img width="800" alt="" src="./assets/img.png" />
10
7
 
8
+
9
+ ### What you should consider when analyzing your bundle
10
+
11
+ 1. if you use **React 19** then it's time to remove a `prop-types` package from your bundle.
12
+ 2. Search for `development|debug|dev` modules in your production JS bundle (it's a dead code that should not be there).
13
+ 3. Also check polyfills duplicates (search example: `url|fetch|crypto|buffer|base-?64`).
14
+ 4. Verify that you don't have any similar packages in your bundle (search example: `object|just-|debounce|ramda|lodash|underscore`). I often see that devs use both `lodash/debounce`, `lodash.debounce` and `debounce` in their projects. Or mix `ramda`, `underscore` and `lodash`._
15
+ 5. Try to find `package.json$` files in your bundle. They are often used to get only the package `version/name` but all other fields are not needed in the bundle.
16
+ 6. Please provide your ideas soo other devs can benefit from them :)
17
+
18
+
11
19
  ### Setup:
12
20
 
13
21
  #### 1. Install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bundle-discovery",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "bin": "lib/bin.js",
6
6
  "repository": "git@github.com:retyui/react-native-bundle-discovery.git",
package/pages/_common.js CHANGED
@@ -234,10 +234,11 @@ const metadata = {
234
234
 
235
235
  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>`;
236
236
 
237
- function getCopyToClipboardButton({ textToCopy, className }) {
237
+ function getCopyToClipboardButton({ textToCopy, className, text }) {
238
238
  return {
239
239
  view: "button",
240
240
  className: `${className ?? ""} copy-to-clipboard`,
241
+ text,
241
242
  data: `{ textToCopy: ${textToCopy} }`,
242
243
  onClick(elm, data) {
243
244
  clearTimeout(elm.__timer);
package/pages/default.js CHANGED
@@ -3,6 +3,7 @@ const {
3
3
  getModulesTree,
4
4
  getPackage,
5
5
  getPackageList,
6
+ getCopyToClipboardButton,
6
7
  } = require("./_common");
7
8
 
8
9
  const topMetaData = [
@@ -141,9 +142,25 @@ discovery.page.define("default", [
141
142
  {
142
143
  when: `#.id="${TABS.PACKAGES}"`,
143
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
+ },
144
159
  {
145
160
  view: "content-filter",
161
+ //
146
162
  data: `${getPackage(`modules.filter(=> path has "node_modules")`)}.sort(pkgInstances desc, size desc)`,
163
+ className: "packages-content",
147
164
  name: "filterByPathStr",
148
165
  content: getPackageList({
149
166
  showCopiesBadge: true,
package/queryHelpers.js CHANGED
@@ -19,6 +19,17 @@ const helpers = {
19
19
  return formatted;
20
20
  });
21
21
  },
22
+ askChatGPTAboutPackages() {
23
+ const prompt = `I have a list of JavaScript packages from my React Native bundle (see below). I want to optimize bundle size by identifying similar or redundant packages — such as multiple versions of similar libraries (e.g., lodash, lodash-es, underscore, etc.), duplicate utilities, or overlapping functionality (e.g., date libraries like moment, dayjs, date-fns).
24
+
25
+ Please do the following:
26
+
27
+ 1. Group similar or overlapping packages together.
28
+ 2. For each group, suggest which one to keep and which ones to consider removing.
29
+ 3. For each group, provide a regex string that can be used to filter those packages from the list (e.g., in grep, find, or search tools).
30
+ 4. Keep the output concise and copy-paste friendly.`;
31
+ return `https://chat.openai.com/?prompt=${encodeURIComponent(prompt)}`;
32
+ },
22
33
  plural(count, [singular, plural]) {
23
34
  return count === 1 ? singular : plural;
24
35
  },
package/views/global.css CHANGED
@@ -131,3 +131,34 @@ hr{
131
131
  margin-top: -26px;
132
132
  z-index: 1;
133
133
  }
134
+ .ask-chatgpt{
135
+ color: var(--discovery-view-button-color, #000);
136
+ text-decoration: none;
137
+ vertical-align: middle;
138
+ position: absolute;
139
+ z-index: 9;
140
+ margin-top: 12px;
141
+ margin-left: 105px !important;
142
+ height: 35px;
143
+ }
144
+ .ask-chatgpt::before {
145
+ content: '”';
146
+ font-size: 2em;
147
+ vertical-align: middle;
148
+ font-family: math;
149
+ margin-right: 0.2em;
150
+ display: inline-block;
151
+ height: 15px;
152
+ }
153
+ .packages-content>.view-input{
154
+ padding-left: 265px;
155
+ }
156
+ .copy-before-ask-chatgpt{
157
+ width: 95px;
158
+ background-position: left center;
159
+ padding-left: 25px;
160
+ position: absolute;
161
+ z-index: 9;
162
+ margin-top: 12px;
163
+ height: 35px;
164
+ }