react-native-bundle-discovery 2.1.0 → 2.2.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.
Files changed (3) hide show
  1. package/README.md +20 -18
  2. package/index.js +0 -34
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3,13 +3,11 @@
3
3
  [![react-native-bundle-discovery on npm](https://badgen.net/npm/v/react-native-bundle-discovery)](https://www.npmjs.com/package/react-native-bundle-discovery)
4
4
  [![react-native-bundle-discovery downloads](https://badgen.net/npm/dm/react-native-bundle-discovery)](https://www.npmtrends.com/react-native-bundle-discovery)
5
5
 
6
-
7
6
  A simple package that helps developers visualize and analyze the bundle size of React Native apps.
8
7
  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.
9
8
 
10
9
  <img width="800" alt="" src="./assets/img.png" />
11
10
 
12
-
13
11
  ### Packages:
14
12
 
15
13
  - `react-native-bundle-discovery` - simple JS library to generate a JSON report of the bundle.
@@ -21,7 +19,7 @@ With this tool, you can easily explore your app's codebase, identify large or he
21
19
 
22
20
  There are two ways to install the package:
23
21
 
24
- 1. As in independent tool (UI + CLI)
22
+ 1. As in independent tool (UI + CLI)
25
23
  2. Or as a [Rozenite](_rozenite/README.md) plugin (see: [_rozenite/README.md](_rozenite/README.md))
26
24
 
27
25
  #### 1. Install (independent tool)
@@ -112,30 +110,34 @@ npx react-native-bundle-discovery-ui build metro-stats.json
112
110
  | outputJsonPath: string | `<root>/metro-stats.json` | The path where the JSON report will be saved. Defaults to `metro-stats.json` in project root. |
113
111
  | includeCode: boolean | `true` | Whether to include the source and output code in the JSON report. |
114
112
 
115
- ### `createProcessModuleFilter(options: ProcessModuleFilterOptions)`
113
+ **⚠️ Be cautious sharing reports with `includeCode` enabled**
114
+
115
+ Enabling this option significantly increases report size and **embeds the source code** of your assets.
116
116
 
117
+ If your code is proprietary 🔒, share these reports responsibly 🤝!
118
+
119
+ ---
117
120
 
118
- | Prop | Default value | Description |
119
- | ---------------------- | ------------------------- | ----------------------------- |
120
- | removePromisePolyfill: boolean | `false` | Remove the Promise polyfill as Hermes provide own impl. (issue: [#57702](https://github.com/react/react-native/issues/57702)) |
121
- | removeOldRenderer: boolean | `false` | Whether to remove the old renderer. Set to `true` when New Arch is enabled |
122
- | removeNewRenderer: boolean | `false` | Whether to remove the new renderer. Set to `true` when New Arch is disabled |
123
- | removeUTFSequence: boolean | `false` | Remove useless undocumented RN module. |
121
+ ### `createResolveRequest(options: ResolveRequestOptions)`
124
122
 
123
+ | Prop | Default value | Description |
124
+ | ------------------------------ | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
125
+ | removePromisePolyfill: boolean | `false` | Remove the Promise polyfill as Hermes provide own impl. (issue: [#57702](https://github.com/react/react-native/issues/57702)) |
126
+ | removeUTFSequence: boolean | `false` | Remove useless undocumented RN module. |
125
127
 
126
- Simple helper that devs can use to filter out unnecessary modules from the bundle report.
128
+ Helper that creates a custom resolve request function to filter out unnecessary modules from the bundle.
127
129
  You can get recommendations during the analysis of the bundle report using the CLI tool.
128
130
 
129
131
  ```js
130
132
  // metro.config.js
131
- const {createProcessModuleFilter} = require('react-native-bundle-discovery');
133
+ const { createResolveRequest } = require("react-native-bundle-discovery");
134
+ const resolveRequest = createResolveRequest({
135
+ removePromisePolyfill: true,
136
+ removeUTFSequence: true,
137
+ });
132
138
  const config = {
133
- serializer: {
134
- processModuleFilter: createProcessModuleFilter({
135
- removePromisePolyfill: true,
136
- removeOldRenderer: true,
137
- removeUTFSequence: true,
138
- }),
139
+ resolver: {
140
+ resolveRequest,
139
141
  },
140
142
  };
141
143
  ```
package/index.js CHANGED
@@ -215,8 +215,6 @@ function createSerializer({
215
215
  */
216
216
  const empty = { type: "empty" };
217
217
  const createResolveRequest = ({
218
- removePromisePolyfill = false, // Remove useless polyfill (Hermes already has Promise)
219
- removeOldRenderer = false, // Should be true when new ARCH is enabled
220
218
  removeNewRenderer = false, // Should be true when new ARCH is disabled
221
219
  removeUTFSequence = false, // Remove useless code
222
220
  } = {}) => {
@@ -231,20 +229,6 @@ const createResolveRequest = ({
231
229
  ) {
232
230
  return empty;
233
231
  }
234
- if (
235
- removePromisePolyfill &&
236
- result?.filePath?.endsWith("/react-native/Libraries/Promise.js")
237
- ) {
238
- return empty;
239
- }
240
- if (
241
- removeOldRenderer &&
242
- result?.filePath?.endsWith(
243
- "/react-native/Libraries/Renderer/shims/ReactNative.js",
244
- )
245
- ) {
246
- return empty;
247
- }
248
232
  if (
249
233
  removeNewRenderer &&
250
234
  result?.filePath?.endsWith(
@@ -264,8 +248,6 @@ const createResolveRequest = ({
264
248
  const createProcessModuleFilter =
265
249
  ({
266
250
  removePromisePolyfill = false, // Remove useless polyfill (Hermes already has Promise)
267
- removeOldRenderer = false, // Should be true when new ARCH is enabled
268
- removeNewRenderer = false, // Should be true when new ARCH is disabled
269
251
  removeUTFSequence = false, // Remove useless code
270
252
  } = {}) =>
271
253
  (module) => {
@@ -275,22 +257,6 @@ const createProcessModuleFilter =
275
257
  ) {
276
258
  return false;
277
259
  }
278
- if (
279
- removeOldRenderer &&
280
- module.path.endsWith(
281
- "/react-native/Libraries/Renderer/shims/ReactNative.js",
282
- )
283
- ) {
284
- return false;
285
- }
286
- if (
287
- removeNewRenderer &&
288
- module.path.endsWith(
289
- "/react-native/Libraries/Renderer/shims/ReactFabric.js",
290
- )
291
- ) {
292
- return false;
293
- }
294
260
  if (
295
261
  removeUTFSequence &&
296
262
  module.path.endsWith("/react-native/Libraries/UTFSequence.js")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bundle-discovery",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:retyui/react-native-bundle-discovery.git",
6
6
  "author": "David <4661784+retyui@users.noreply.github.com>",