react-native-bundle-discovery 1.0.0 → 1.0.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/.discoveryrc.js CHANGED
@@ -14,6 +14,7 @@ module.exports = {
14
14
  path.resolve(__dirname, "pages/package.js"),
15
15
  // Custom views
16
16
  path.resolve(__dirname, "views/highcharts.css"),
17
+ path.resolve(__dirname, "views/prettify.js"),
17
18
  path.resolve(__dirname, "views/highcharts.js"),
18
19
  path.resolve(__dirname, "views/foamtree.js"),
19
20
  ],
package/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  > [!WARNING]
4
4
  > Currently, everything is in a very early stage. The project is not yet ready for use.
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
 
@@ -12,6 +11,7 @@ With this tool, you can easily explore your app's codebase, identify large or he
12
11
  ### Setup:
13
12
 
14
13
  #### 1. Install
14
+
15
15
  ```bash
16
16
  yarn add -D react-native-bundle-discovery
17
17
  ```
@@ -23,9 +23,9 @@ yarn add -D react-native-bundle-discovery
23
23
  const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
24
24
  +const {createSerializer} = require('react-native-bundle-discovery');
25
25
 
26
- +const mySerializer = createSerializer({
26
+ +const mySerializer = createSerializer({
27
27
  + includeCode: true, // Useful if you want to compare source/bundle code (but a report file will be larger)
28
- + projectRoot: __dirname,
28
+ + projectRoot: __dirname,
29
29
  + //^^^ ⚠️ WARNING: In a monorepo setup, this should point to the monorepo root,
30
30
  + // not the individual package directory.
31
31
  +});
@@ -63,6 +63,21 @@ npx react-native-bundle-discovery metro-stats.json
63
63
 
64
64
  ---
65
65
 
66
+ ### `createSerializer(optiosn: Options)`
67
+
68
+ | Prop | Default value | Description |
69
+ | ---------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
70
+ | serializer: Function | Default serializer | A custom serializer function. If not provided, a default serializer is used. |
71
+ | projectRoot: string | Required | The root directory of the project. ⚠️ In a monorepo setup, this should point to the monorepo root, not the individual package directory. |
72
+ | outputJsonPath: string | `<root>/metro-stats.json` | The path where the JSON report will be saved. Defaults to `metro-stats.json` in project root. |
73
+ | includeCode: boolean | `true` | Whether to include the source and output code in the JSON report. |
74
+
75
+ ### Financial Contributors
76
+
77
+ Become a financial contributor at [OpenCollective](https://opencollective.com/react-native-bundle-discovery) or [GitHub Sponsors](https://github.com/sponsors/retyui)
78
+
79
+ ### Other
80
+
66
81
  **Similar projects:**
67
82
 
68
83
  - https://github.com/expo/atlas
@@ -72,8 +87,7 @@ npx react-native-bundle-discovery metro-stats.json
72
87
  - https://github.com/statoscope/statoscope
73
88
  - https://github.com/relative-ci/bundle-stats/tree/master/packages/cli
74
89
 
75
- ---
90
+ **Built using [Discovery.js](https://github.com/discoveryjs/discovery):**
76
91
 
77
- **Built using Discovery.js:**
78
92
  - Build blocks for pages: https://discoveryjs.github.io/discovery/#views-showcase
79
93
  - Jora syntax: https://discoveryjs.github.io/jora/#article:jora-syntax-operators
@@ -106,7 +106,7 @@ function createJsonReport({
106
106
  return acc;
107
107
  }, {}),
108
108
  rootFolder,
109
- packages: toPackages(dependencies),
109
+ packages: toPackages(preModules).concat(toPackages(dependencies)),
110
110
  modules: preModules
111
111
  .map((m) => toModuleStruct(m, includeCode))
112
112
  .concat(dependencies.map((m) => toModuleStruct(m, includeCode))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bundle-discovery",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "index.js",
5
5
  "bin": "lib/bin.js",
6
6
  "repository": "git@github.com:retyui/react-native-bundle-discovery.git",
@@ -12,10 +12,12 @@
12
12
  "build": "npx discovery-build --config .discoveryrc.js --output build --serve-only-assets --single-file"
13
13
  },
14
14
  "dependencies": {
15
+ "@babel/parser": "^7.0.0",
15
16
  "@discoveryjs/cli": "2.14.2",
16
17
  "@discoveryjs/discovery": "1.0.0-beta.93",
17
18
  "chalk": "^4.1.2",
18
- "highcharts": "12.2.0"
19
+ "highcharts": "12.2.0",
20
+ "prettier": "^3.5.3"
19
21
  },
20
22
  "peerDependencies": {
21
23
  "metro": "*"
@@ -35,8 +37,5 @@
35
37
  "prepare.js",
36
38
  "queryHelpers.js",
37
39
  ".discoveryrc.js"
38
- ],
39
- "devDependencies": {
40
- "prettier": "3.5.3"
41
- }
40
+ ]
42
41
  }
package/pages/module.js CHANGED
@@ -119,11 +119,29 @@ discovery.page.define("module", {
119
119
  view: "block",
120
120
  className: "width-50p",
121
121
  content: [
122
- "h5: 'Output'",
123
122
  {
124
- view: "source",
125
- syntax: "ts",
126
- source: "=$.currentModule.output.code",
123
+ view: "h5",
124
+ content: 'text:"Output"',
125
+ },
126
+ {
127
+ view: "context",
128
+ modifiers: [
129
+ {
130
+ view: "checkbox",
131
+ name: "prettify",
132
+ checked: true,
133
+ className: "prettify-checkbox",
134
+ content: 'text:"Prettify"',
135
+ },
136
+ ],
137
+ content: [
138
+ {
139
+ view: "source-prettify",
140
+ syntax: "ts",
141
+ source:
142
+ "=(#.prettify ? $.currentModule.output.code.prettifyJS() : $.currentModule.output.code)",
143
+ },
144
+ ],
127
145
  },
128
146
  ],
129
147
  },
package/prepare.js CHANGED
@@ -66,9 +66,6 @@ function prepare(data) {
66
66
  m.source.code = m.source.code
67
67
  .replaceAll(";", ";\n\n")
68
68
  .replaceAll(",", ",\n ");
69
- m.output.code = m.output.code
70
- .replaceAll(";", ";\n\n")
71
- .replaceAll(",", ",\n ");
72
69
  }
73
70
  });
74
71
 
package/queryHelpers.js CHANGED
@@ -1,4 +1,24 @@
1
1
  const helpers = {
2
+ prettifyMap: new Map(),
3
+ prettifyJS(sourceStr) {
4
+ if (helpers.prettifyMap.has(sourceStr)) {
5
+ return helpers.prettifyMap.get(sourceStr);
6
+ }
7
+
8
+ const prettier = require("prettier/standalone");
9
+ const prettierPluginBabel = require("prettier/plugins/babel");
10
+ const prettierPluginEstree = require("prettier/plugins/estree");
11
+
12
+ return prettier
13
+ .format(sourceStr, {
14
+ parser: "babel",
15
+ plugins: [prettierPluginBabel, prettierPluginEstree],
16
+ })
17
+ .then((formatted) => {
18
+ helpers.prettifyMap.set(sourceStr, formatted);
19
+ return formatted;
20
+ });
21
+ },
2
22
  plural(count, [singular, plural]) {
3
23
  return count === 1 ? singular : plural;
4
24
  },
package/views/global.css CHANGED
@@ -125,3 +125,9 @@ hr{
125
125
  background: red;
126
126
  opacity: 1;
127
127
  }
128
+ .prettify-checkbox{
129
+ position: absolute;
130
+ right: 31px;
131
+ margin-top: -26px;
132
+ z-index: 1;
133
+ }
@@ -0,0 +1,17 @@
1
+ discovery.view.define(
2
+ "source-prettify",
3
+ async function renderPrettify(el, config, data, context) {
4
+ await this.render(
5
+ el,
6
+ this.composeConfig([
7
+ {
8
+ ...config,
9
+ source: await config.source,
10
+ view: "source",
11
+ },
12
+ ]),
13
+ data,
14
+ context,
15
+ );
16
+ },
17
+ );