react-native-bundle-discovery 1.2.0 → 1.2.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/README.md CHANGED
@@ -18,13 +18,18 @@ With this tool, you can easily explore your app's codebase, identify large or he
18
18
 
19
19
  ### Setup:
20
20
 
21
- #### 1. Install
21
+ There are two ways to install the package:
22
+
23
+ 1. As in independent tool
24
+ 2. Or as a [Rozenite](https://www.rozenite.dev/) plugin (see below).
25
+
26
+ #### 1. Install (independent tool)
22
27
 
23
28
  ```bash
24
29
  yarn add -D react-native-bundle-discovery
25
30
  ```
26
31
 
27
- #### 2. Add to your metro.config.js
32
+ Add to your `metro.config.js`:
28
33
 
29
34
  ```diff
30
35
  // metro.config.js
@@ -48,6 +53,46 @@ const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
48
53
  module.exports = mergeConfig(getDefaultConfig(__dirname), config);
49
54
  ```
50
55
 
56
+ ---
57
+
58
+ #### 2. Install as a Rozenite plugin (OPTIONAL)
59
+
60
+
61
+ ```bash
62
+ yarn dlx rozenite@latest init # init rozenite in your project (from: https://www.rozenite.dev/docs/getting-started)
63
+ yarn add -D react-native-bundle-discovery-rozenite-plugin # add the plugin to your project
64
+ ```
65
+
66
+ Then in the `metro.config.js` file add the following:
67
+
68
+ ```diff
69
+ const { withRozenite } = require('@rozenite/metro');
70
+ +const { withRozeniteBundleDiscoveryPlugin } = require('react-native-bundle-discovery-rozenite-plugin');
71
+ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
72
+
73
+ /**
74
+ * Metro configuration
75
+ * https://reactnative.dev/docs/metro
76
+ *
77
+ * @type {import('@react-native/metro-config').MetroConfig}
78
+ */
79
+ const config = {};
80
+
81
+ module.exports = withRozenite(
82
+ mergeConfig(getDefaultConfig(__dirname), config),
83
+ {
84
+ + enhanceMetroConfig: config => withRozeniteBundleDiscoveryPlugin(config, { /* Your Bundle Discovery Options */ }),
85
+ enabled: true,
86
+ },
87
+ );
88
+ ```
89
+
90
+ Now you can run `yarn start` and open [React Native DevTools](https://reactnative.dev/docs/react-native-devtools)
91
+
92
+
93
+ ---
94
+
95
+
51
96
  #### 3. Build the app
52
97
 
53
98
  As example, for iOS you can run the following command, and it will generate the `metro-stats.json` file in the root of your project:
@@ -61,7 +106,9 @@ npx react-native bundle \
61
106
  --assets-dest ios/assets
62
107
  ```
63
108
 
64
- #### 4. View the report in the browser
109
+ #### 4. CLI
110
+
111
+ ##### 4.1 View the report in the browser
65
112
 
66
113
  Run webserver to view the report:
67
114
 
@@ -69,7 +116,7 @@ Run webserver to view the report:
69
116
  npx react-native-bundle-discovery server metro-stats.json [--port <port>]
70
117
  ```
71
118
 
72
- #### 4. Build the HTML report
119
+ ##### 4.2 Build the HTML report
73
120
 
74
121
  Run the following command to generate an HTML report from the JSON file:
75
122
 
@@ -102,7 +149,7 @@ Become a financial contributor at [OpenCollective](https://opencollective.com/re
102
149
  - https://github.com/callstack/react-native-bundle-visualizer
103
150
  - https://github.com/webpack-contrib/webpack-bundle-analyzer
104
151
  - https://github.com/statoscope/statoscope
105
- - https://github.com/relative-ci/bundle-stats/tree/master/packages/cli
152
+ - [https://github.com/relative-ci/bundle-stats/tree/master/packages/cli](https://github.com/relative-ci/bundle-stats/tree/master/packages/cli#readme)
106
153
 
107
154
  **Built using [Discovery.js](https://github.com/discoveryjs/discovery):**
108
155
 
package/lib/.tmp.js CHANGED
@@ -1,6 +1,6 @@
1
1
  module.exports = {
2
2
  "name": "react-native-bundle-discovery",
3
- "data": () => require("/Users/davyd.narbutovich/open-source/bundle-discovery/tmp/rocket-chat-metro-stats.json"),
3
+ "data": () => require("/Users/davyd.narbutovich/open-source/bundle-discovery/tmp/dtv-metro-stats.json"),
4
4
  "setup": "/Users/davyd.narbutovich/open-source/bundle-discovery/setup.js",
5
5
  "view": {
6
6
  "assets": [
@@ -1,3 +1,4 @@
1
+ const { parse } = require("path");
1
2
  const { writeFileSync, existsSync } = require("fs");
2
3
  const { resolve } = require("path");
3
4
  const { Buffer } = require("buffer");
@@ -5,9 +6,18 @@ const chalk = require("chalk");
5
6
 
6
7
  const NAME = require("../package.json").name;
7
8
 
9
+ function getDefault(module) {
10
+ return module.__esModule ? module.default : module;
11
+ }
12
+
8
13
  function getDefaultSerializer() {
9
- const bundleToString = require("metro/src/lib/bundleToString");
10
- const baseJSBundle = require("metro/src/DeltaBundler/Serializers/baseJSBundle");
14
+ const metroPath = parse(require.resolve("metro/package.json")).dir;
15
+ const bundleToString = getDefault(
16
+ require(`${metroPath}/src/lib/bundleToString.js`),
17
+ );
18
+ const baseJSBundle = getDefault(
19
+ require(`${metroPath}/src/DeltaBundler/Serializers/baseJSBundle.js`),
20
+ );
11
21
 
12
22
  return (entryPoint, preModules, graph, options) =>
13
23
  bundleToString(baseJSBundle(entryPoint, preModules, graph, options)).code;
@@ -94,6 +104,7 @@ function createJsonReport({
94
104
  includeCode,
95
105
  outputJsonPath,
96
106
  rootFolder,
107
+ silent,
97
108
  }) {
98
109
  const dependencies = Array.from(graph.dependencies.values());
99
110
 
@@ -114,9 +125,11 @@ function createJsonReport({
114
125
 
115
126
  writeFileSync(outputJsonPath, JSON.stringify(stats));
116
127
 
117
- console.log(
118
- `${chalk.yellow(`[${NAME}]`)}: Saved stats to ${chalk.green(outputJsonPath)}`,
119
- );
128
+ if (!silent) {
129
+ console.log(
130
+ `${chalk.yellow(`[${NAME}]`)}: Saved stats to ${chalk.green(outputJsonPath)}`,
131
+ );
132
+ }
120
133
  }
121
134
 
122
135
  /**
@@ -137,6 +150,7 @@ function createSerializer({
137
150
  projectRoot,
138
151
  outputJsonPath,
139
152
  includeCode = true,
153
+ silent = false,
140
154
  includeEnvs = [],
141
155
  } = {}) {
142
156
  const mySerializer = serializer || getDefaultSerializer();
@@ -159,6 +173,7 @@ function createSerializer({
159
173
  includeCode,
160
174
  outputJsonPath: myOutputJsonPath,
161
175
  rootFolder: projectRoot,
176
+ silent,
162
177
  });
163
178
 
164
179
  return code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bundle-discovery",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "main": "index.js",
5
5
  "bin": "lib/bin.js",
6
6
  "repository": "git@github.com:retyui/react-native-bundle-discovery.git",