react-native-bundle-discovery-ui 2.1.0-rc.2 → 2.2.0-rc.1
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/README.md +14 -28
- package/lib/bin.js +5 -15
- package/lib/build.js +3 -2
- package/lib/server.js +3 -3
- package/lib/utils.js +23 -0
- package/package.json +6 -2
- package/queryHelpers.js +3 -0
package/README.md
CHANGED
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/react-native-bundle-discovery)
|
|
4
4
|
[](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.
|
|
@@ -17,13 +15,20 @@ With this tool, you can easily explore your app's codebase, identify large or he
|
|
|
17
15
|
- `react-native-bundle-discovery-cli` - CLI to analyze the bundle report.
|
|
18
16
|
- `react-native-bundle-discovery-rozenite-plugin` - Rozenite plugin to integrate UI tool to [React Native DevTools](https://reactnative.dev/docs/react-native-devtools).
|
|
19
17
|
|
|
18
|
+
---
|
|
19
|
+
|
|
20
20
|
### Setup:
|
|
21
21
|
|
|
22
22
|
There are two ways to install the package:
|
|
23
23
|
|
|
24
|
-
1. As in independent tool (UI + CLI)
|
|
24
|
+
1. As in independent tool (UI + CLI)
|
|
25
25
|
2. Or as a [Rozenite](_rozenite/README.md) plugin (see: [_rozenite/README.md](_rozenite/README.md))
|
|
26
26
|
|
|
27
|
+
|
|
28
|
+
> 🚀 If you've migrated to [Re.Pack](https://re-pack.dev/), you can still use this package to analyze 📊 JS bundles 📦 generated by Re.Pack.
|
|
29
|
+
>
|
|
30
|
+
> 💡 Learn more: 📖 [Re.Pack.md](./Re.Pack.md)
|
|
31
|
+
|
|
27
32
|
#### 1. Install (independent tool)
|
|
28
33
|
|
|
29
34
|
```bash
|
|
@@ -62,7 +67,7 @@ See: [_rozenite/README.md](_rozenite/README.md)
|
|
|
62
67
|
|
|
63
68
|
### 3. Build the app
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
For example, for iOS you can run the following command, and it will generate the `metro-stats.json` file in the root of your project:
|
|
66
71
|
|
|
67
72
|
```bash
|
|
68
73
|
npx react-native bundle \
|
|
@@ -99,20 +104,6 @@ npx react-native-bundle-discovery-ui metro-stats.json [--port <port>]
|
|
|
99
104
|
npx react-native-bundle-discovery-ui build metro-stats.json
|
|
100
105
|
```
|
|
101
106
|
|
|
102
|
-
---
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
### Re.Pack Support
|
|
106
|
-
|
|
107
|
-
If you've migrated to [Re.Pack](https://re-pack.dev/docs/guides/bundle-analysis), you can still use this package to analyze bundles generated by Re.Pack.
|
|
108
|
-
|
|
109
|
-
Learn more: [Rsdoctor.md](./Rsdoctor.md)
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
npx react-native-bundle-discovery-ui rsdoctor-data.json --format rsdoctor
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
|
|
116
107
|
---
|
|
117
108
|
|
|
118
109
|
### `react-native-bundle-discovery` JS API
|
|
@@ -126,8 +117,6 @@ npx react-native-bundle-discovery-ui rsdoctor-data.json --format rsdoctor
|
|
|
126
117
|
| outputJsonPath: string | `<root>/metro-stats.json` | The path where the JSON report will be saved. Defaults to `metro-stats.json` in project root. |
|
|
127
118
|
| includeCode: boolean | `true` | Whether to include the source and output code in the JSON report. |
|
|
128
119
|
|
|
129
|
-
|
|
130
|
-
|
|
131
120
|
**⚠️ Be cautious sharing reports with `includeCode` enabled**
|
|
132
121
|
|
|
133
122
|
Enabling this option significantly increases report size and **embeds the source code** of your assets.
|
|
@@ -138,22 +127,19 @@ If your code is proprietary 🔒, share these reports responsibly 🤝!
|
|
|
138
127
|
|
|
139
128
|
### `createResolveRequest(options: ResolveRequestOptions)`
|
|
140
129
|
|
|
141
|
-
| Prop
|
|
142
|
-
|
|
|
143
|
-
| removePromisePolyfill: boolean | `false`
|
|
144
|
-
|
|
|
145
|
-
| removeNewRenderer: boolean | `false` | Whether to remove the new renderer. Set to `true` when New Arch is disabled |
|
|
146
|
-
| removeUTFSequence: boolean | `false` | Remove useless undocumented RN module. |
|
|
130
|
+
| Prop | Default value | Description |
|
|
131
|
+
| ------------------------------ | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
132
|
+
| removePromisePolyfill: boolean | `false` | Remove the Promise polyfill as Hermes provide own impl. (issue: [#57702](https://github.com/react/react-native/issues/57702)) |
|
|
133
|
+
| removeUTFSequence: boolean | `false` | Remove useless undocumented RN module. |
|
|
147
134
|
|
|
148
135
|
Helper that creates a custom resolve request function to filter out unnecessary modules from the bundle.
|
|
149
136
|
You can get recommendations during the analysis of the bundle report using the CLI tool.
|
|
150
137
|
|
|
151
138
|
```js
|
|
152
139
|
// metro.config.js
|
|
153
|
-
const {createResolveRequest} = require(
|
|
140
|
+
const { createResolveRequest } = require("react-native-bundle-discovery");
|
|
154
141
|
const resolveRequest = createResolveRequest({
|
|
155
142
|
removePromisePolyfill: true,
|
|
156
|
-
removeOldRenderer: true,
|
|
157
143
|
removeUTFSequence: true,
|
|
158
144
|
});
|
|
159
145
|
const config = {
|
package/lib/bin.js
CHANGED
|
@@ -5,10 +5,10 @@ function printHelp() {
|
|
|
5
5
|
console.log(`react-native-bundle-discovery-ui
|
|
6
6
|
|
|
7
7
|
Usage:
|
|
8
|
-
react-native-bundle-discovery-ui <file> [port] [--
|
|
9
|
-
react-native-bundle-discovery-ui server <file> [port] [--
|
|
8
|
+
react-native-bundle-discovery-ui <file> [port] [--verbose] # <- server can be omitted
|
|
9
|
+
react-native-bundle-discovery-ui server <file> [port] [--verbose]
|
|
10
10
|
|
|
11
|
-
react-native-bundle-discovery-ui build <file> [--output <path>] [--clean] [--single-file] [--
|
|
11
|
+
react-native-bundle-discovery-ui build <file> [--output <path>] [--clean] [--single-file] [--verbose]
|
|
12
12
|
|
|
13
13
|
Commands:
|
|
14
14
|
server <file> [port] Run a web server to show a Metro bundler stat report
|
|
@@ -19,7 +19,6 @@ Options:
|
|
|
19
19
|
-o, --output <path> Path for a build result (default: .bundle-discovery)
|
|
20
20
|
-c, --clean Clean output directory before writing build files (default: true)
|
|
21
21
|
-s, --single-file Output report build as a single HTML file (default: true)
|
|
22
|
-
-f, --format <name> Report format: rsdoctor | metro (default: metro)
|
|
23
22
|
-p, --port <port> Port for server command (same as [port], default: 8079)
|
|
24
23
|
-h, --help Show help
|
|
25
24
|
`);
|
|
@@ -38,24 +37,16 @@ const argv = minimist(process.argv.slice(2), {
|
|
|
38
37
|
o: "output",
|
|
39
38
|
c: "clean",
|
|
40
39
|
s: "single-file",
|
|
41
|
-
f: "format",
|
|
42
40
|
p: "port",
|
|
43
41
|
},
|
|
44
42
|
boolean: ["verbose", "help", "clean", "single-file"],
|
|
45
|
-
string: ["output"
|
|
43
|
+
string: ["output"],
|
|
46
44
|
default: {
|
|
47
45
|
clean: true,
|
|
48
46
|
"single-file": true,
|
|
49
|
-
format: "metro",
|
|
50
47
|
},
|
|
51
48
|
});
|
|
52
49
|
|
|
53
|
-
const SUPPORTED_FORMATS = new Set(["rsdoctor", "metro"]);
|
|
54
|
-
const format = argv.format;
|
|
55
|
-
if (!SUPPORTED_FORMATS.has(format)) {
|
|
56
|
-
fail(`Invalid format: ${format}. Supported formats: rsdoctor | metro`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
50
|
const command = argv._[0];
|
|
60
51
|
const isServerCommand = command === "server";
|
|
61
52
|
const isBuildCommand = command === "build";
|
|
@@ -81,7 +72,7 @@ if (isServerCommand || isImplicitServerCommand) {
|
|
|
81
72
|
}
|
|
82
73
|
|
|
83
74
|
const { serve } = require("./server.js");
|
|
84
|
-
return serve(file, port,
|
|
75
|
+
return serve(file, port, Boolean(argv.verbose));
|
|
85
76
|
}
|
|
86
77
|
|
|
87
78
|
if (isBuildCommand) {
|
|
@@ -96,7 +87,6 @@ if (isBuildCommand) {
|
|
|
96
87
|
argv.output,
|
|
97
88
|
argv.clean,
|
|
98
89
|
argv["single-file"],
|
|
99
|
-
format,
|
|
100
90
|
Boolean(argv.verbose),
|
|
101
91
|
);
|
|
102
92
|
}
|
package/lib/build.js
CHANGED
|
@@ -3,8 +3,9 @@ const path = require("path");
|
|
|
3
3
|
const chalk = require("chalk");
|
|
4
4
|
const { build } = require("@discoveryjs/cli");
|
|
5
5
|
const config = require("../.discoveryrc.js");
|
|
6
|
+
const { isRsdoctorReport } = require("./utils.js");
|
|
6
7
|
|
|
7
|
-
function buildHtmlPage(filePath, output, clean, singleFile,
|
|
8
|
+
function buildHtmlPage(filePath, output, clean, singleFile, verbose) {
|
|
8
9
|
if (verbose) {
|
|
9
10
|
console.info(
|
|
10
11
|
`Building HTML page from file: ${chalk.green(filePath)} options: ${JSON.stringify(
|
|
@@ -56,7 +57,7 @@ module.exports = ${JSON.stringify(
|
|
|
56
57
|
1,
|
|
57
58
|
).replace(
|
|
58
59
|
`"<tmp>"`,
|
|
59
|
-
|
|
60
|
+
isRsdoctorReport(fullJsonPath)
|
|
60
61
|
? `() => transformRSDoctorData(require("${fullJsonPath}"))`
|
|
61
62
|
: `() => require("${fullJsonPath}")`,
|
|
62
63
|
)};`,
|
package/lib/server.js
CHANGED
|
@@ -4,8 +4,9 @@ const chalk = require("chalk");
|
|
|
4
4
|
const { createServer } = require("@discoveryjs/cli");
|
|
5
5
|
const { silent } = require("@discoveryjs/cli/lib/shared/utils.js");
|
|
6
6
|
const config = require("../.discoveryrc.js");
|
|
7
|
+
const { isRsdoctorReport } = require("./utils.js");
|
|
7
8
|
|
|
8
|
-
function serve(filePath, port,
|
|
9
|
+
function serve(filePath, port, verbose) {
|
|
9
10
|
const PORT = process.env.PORT || port;
|
|
10
11
|
|
|
11
12
|
if (verbose) {
|
|
@@ -55,8 +56,7 @@ module.exports = ${JSON.stringify(
|
|
|
55
56
|
1,
|
|
56
57
|
).replace(
|
|
57
58
|
`"<tmp>"`,
|
|
58
|
-
|
|
59
|
-
format === "rsdoctor"
|
|
59
|
+
isRsdoctorReport(fullJsonPath)
|
|
60
60
|
? `() => transformRSDoctorData(require("${fullJsonPath}"))`
|
|
61
61
|
: `() => require("${fullJsonPath}")`,
|
|
62
62
|
)};`,
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
|
|
3
|
+
const isRsdoctorReport = (fullJsonPath) => {
|
|
4
|
+
try {
|
|
5
|
+
const json = require(fullJsonPath);
|
|
6
|
+
if (
|
|
7
|
+
Array.isArray(json?.data?.moduleGraph?.modules) ||
|
|
8
|
+
Array.isArray(json?.data?.packageGraph?.packages)
|
|
9
|
+
) {
|
|
10
|
+
console.info(
|
|
11
|
+
`Detected ${chalk.red("rsdoctor")} format in the input file: ${chalk.green(fullJsonPath)}`,
|
|
12
|
+
);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
isRsdoctorReport,
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-bundle-discovery-ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-rc.1",
|
|
4
4
|
"main": "lib/bin.js",
|
|
5
5
|
"bin": "lib/bin.js",
|
|
6
6
|
"repository": "git@github.com:retyui/react-native-bundle-discovery.git",
|
|
@@ -38,5 +38,9 @@
|
|
|
38
38
|
"queryHelpers.js",
|
|
39
39
|
".discoveryrc.js"
|
|
40
40
|
],
|
|
41
|
-
"packageManager": "yarn@4.18.0"
|
|
41
|
+
"packageManager": "yarn@4.18.0",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"acorn": "^8.18.0",
|
|
44
|
+
"acorn-walk": "^8.3.5"
|
|
45
|
+
}
|
|
42
46
|
}
|