react-native-bundle-discovery-ui 2.6.0 → 2.7.0-rc.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/README.md +168 -117
- package/assets/global.css +171 -0
- package/dist/bin.js +202 -0
- package/dist/client/_virtual/_rolldown/runtime.js +23 -0
- package/dist/client/pages/_common.js +282 -0
- package/dist/client/pages/default.js +184 -0
- package/dist/client/pages/module.js +260 -0
- package/dist/client/pages/package.js +187 -0
- package/dist/client/prepare.js +52 -0
- package/dist/client/queryHelpers.js +282 -0
- package/dist/client/setup.js +9 -0
- package/dist/client/views/_theme.js +16 -0
- package/dist/client/views/foamtree.js +88 -0
- package/dist/client/views/highcharts.js +23 -0
- package/dist/client/views/prettify.js +9 -0
- package/dist/discoveryrc.js +21 -0
- package/dist/rolldown-runtime-VH7oDXx4.js +28 -0
- package/dist/rsdoctor.js +75 -0
- package/dist/src-BSLX-He2.js +30 -0
- package/package.json +26 -27
- package/.discoveryrc.js +0 -22
- package/lib/bin.js +0 -94
- package/lib/build.js +0 -123
- package/lib/isRsdoctorReport.js +0 -33
- package/lib/rsdoctor.js +0 -149
- package/lib/server.js +0 -90
- package/pages/_common.js +0 -324
- package/pages/default.js +0 -211
- package/pages/module.js +0 -324
- package/pages/package.js +0 -255
- package/prepare.js +0 -102
- package/queryHelpers.js +0 -375
- package/setup.js +0 -12
- package/views/_theme.js +0 -35
- package/views/foamtree.js +0 -136
- package/views/global.css +0 -169
- package/views/highcharts.js +0 -43
- package/views/prettify.js +0 -17
- /package/{views → assets}/highcharts.css +0 -0
package/.discoveryrc.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
name: "react-native-bundle-discovery",
|
|
5
|
-
data: () => require("./tmp/metro-stats.json"),
|
|
6
|
-
setup: path.resolve(__dirname, "setup.js"),
|
|
7
|
-
view: {
|
|
8
|
-
assets: [
|
|
9
|
-
// Global styles
|
|
10
|
-
path.resolve(__dirname, "views/global.css"),
|
|
11
|
-
// Pages
|
|
12
|
-
path.resolve(__dirname, "pages/default.js"),
|
|
13
|
-
path.resolve(__dirname, "pages/module.js"),
|
|
14
|
-
path.resolve(__dirname, "pages/package.js"),
|
|
15
|
-
// Custom views
|
|
16
|
-
path.resolve(__dirname, "views/highcharts.css"),
|
|
17
|
-
path.resolve(__dirname, "views/prettify.js"),
|
|
18
|
-
path.resolve(__dirname, "views/highcharts.js"),
|
|
19
|
-
path.resolve(__dirname, "views/foamtree.js"),
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
};
|
package/lib/bin.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const minimist = require("minimist");
|
|
3
|
-
|
|
4
|
-
function printHelp() {
|
|
5
|
-
console.log(`react-native-bundle-discovery-ui
|
|
6
|
-
|
|
7
|
-
Usage:
|
|
8
|
-
react-native-bundle-discovery-ui <file> [port] [--verbose] # <- server can be omitted
|
|
9
|
-
react-native-bundle-discovery-ui server <file> [port] [--verbose]
|
|
10
|
-
|
|
11
|
-
react-native-bundle-discovery-ui build <file> [--output <path>] [--clean] [--single-file] [--verbose]
|
|
12
|
-
|
|
13
|
-
Commands:
|
|
14
|
-
server <file> [port] Run a web server to show a Metro bundler stat report
|
|
15
|
-
build <file> Build a HTML report from the Metro bundler stat file
|
|
16
|
-
|
|
17
|
-
Options:
|
|
18
|
-
-v, --verbose Run with verbose logging
|
|
19
|
-
-o, --output <path> Path for a build result (default: .bundle-discovery)
|
|
20
|
-
-c, --clean Clean output directory before writing build files (default: true)
|
|
21
|
-
-s, --single-file Output report build as a single HTML file (default: true)
|
|
22
|
-
-p, --port <port> Port for server command (same as [port], default: 8079)
|
|
23
|
-
-h, --help Show help
|
|
24
|
-
`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function fail(message) {
|
|
28
|
-
console.error(message);
|
|
29
|
-
console.error("Use --help to see usage.");
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const argv = minimist(process.argv.slice(2), {
|
|
34
|
-
alias: {
|
|
35
|
-
v: "verbose",
|
|
36
|
-
h: "help",
|
|
37
|
-
o: "output",
|
|
38
|
-
c: "clean",
|
|
39
|
-
s: "single-file",
|
|
40
|
-
p: "port",
|
|
41
|
-
},
|
|
42
|
-
boolean: ["verbose", "help", "clean", "single-file"],
|
|
43
|
-
string: ["output"],
|
|
44
|
-
default: {
|
|
45
|
-
clean: true,
|
|
46
|
-
"single-file": true,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const command = argv._[0];
|
|
51
|
-
const isServerCommand = command === "server";
|
|
52
|
-
const isBuildCommand = command === "build";
|
|
53
|
-
const isImplicitServerCommand =
|
|
54
|
-
Boolean(command) && !isServerCommand && !isBuildCommand;
|
|
55
|
-
|
|
56
|
-
if (argv.help || !command) {
|
|
57
|
-
printHelp();
|
|
58
|
-
process.exit(0);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (isServerCommand || isImplicitServerCommand) {
|
|
62
|
-
const file = isImplicitServerCommand ? argv._[0] : argv._[1];
|
|
63
|
-
if (!file) {
|
|
64
|
-
fail("Missing required argument: <file>");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const rawPort =
|
|
68
|
-
argv.port ?? (isImplicitServerCommand ? argv._[1] : argv._[2]) ?? 8079;
|
|
69
|
-
const port = Number(rawPort);
|
|
70
|
-
if (!Number.isFinite(port)) {
|
|
71
|
-
fail(`Invalid port: ${rawPort}`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const { serve } = require("./server.js");
|
|
75
|
-
return serve(file, port, Boolean(argv.verbose));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (isBuildCommand) {
|
|
79
|
-
const file = argv._[1];
|
|
80
|
-
if (!file) {
|
|
81
|
-
fail("Missing required argument: <file>");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const { buildHtmlPage } = require("./build.js");
|
|
85
|
-
return buildHtmlPage(
|
|
86
|
-
file,
|
|
87
|
-
argv.output,
|
|
88
|
-
argv.clean,
|
|
89
|
-
argv["single-file"],
|
|
90
|
-
Boolean(argv.verbose),
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
fail(`Unknown command: ${command}`);
|
package/lib/build.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const { build } = require("@discoveryjs/cli");
|
|
5
|
-
const config = require("../.discoveryrc.js");
|
|
6
|
-
const { isRsdoctorReportPath } = require("./isRsdoctorReport.js");
|
|
7
|
-
|
|
8
|
-
function buildHtmlPage(filePath, output, clean, singleFile, verbose) {
|
|
9
|
-
if (verbose) {
|
|
10
|
-
console.info(
|
|
11
|
-
`Building HTML page from file: ${chalk.green(filePath)} options: ${JSON.stringify(
|
|
12
|
-
{ output, clean, singleFile },
|
|
13
|
-
null,
|
|
14
|
-
2,
|
|
15
|
-
)}`,
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!filePath) {
|
|
20
|
-
console.error(
|
|
21
|
-
`Usage: '${chalk.green("npx react-native-bundle-discovery build <path-to-file>")}', Please provide a path to a JSON file.`,
|
|
22
|
-
);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const jsonFilePath = path.resolve(process.cwd(), filePath);
|
|
27
|
-
if (verbose) {
|
|
28
|
-
console.info(
|
|
29
|
-
`Loading JSON file from: ${chalk.green(jsonFilePath)}, base directory: ${chalk.green(process.cwd())}`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let fullJsonPath;
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
fullJsonPath = require.resolve(jsonFilePath);
|
|
37
|
-
} catch (err) {
|
|
38
|
-
console.error(`❌Error loading file: ${chalk.red(jsonFilePath)}\n\n`);
|
|
39
|
-
console.error(err.message);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const configFile = path.resolve(__dirname, "./.tmp.js");
|
|
44
|
-
|
|
45
|
-
if (verbose) {
|
|
46
|
-
console.info(
|
|
47
|
-
`Creating temporary config file at: ${chalk.green(configFile)}, for discovery.js`,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
const transformRcdoctor = require.resolve("./rsdoctor.js");
|
|
51
|
-
fs.writeFileSync(
|
|
52
|
-
configFile,
|
|
53
|
-
`const {transformRSDoctorData} = require("${transformRcdoctor}");
|
|
54
|
-
module.exports = ${JSON.stringify(
|
|
55
|
-
{ ...config, data: "<tmp>" },
|
|
56
|
-
null,
|
|
57
|
-
1,
|
|
58
|
-
).replace(
|
|
59
|
-
`"<tmp>"`,
|
|
60
|
-
isRsdoctorReportPath(fullJsonPath)
|
|
61
|
-
? `() => transformRSDoctorData(require("${fullJsonPath}"))`
|
|
62
|
-
: `() => require("${fullJsonPath}")`,
|
|
63
|
-
)};`,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
if (verbose) {
|
|
67
|
-
console.info(`Building HTML page with options:`, {
|
|
68
|
-
output,
|
|
69
|
-
clean,
|
|
70
|
-
singleFile,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const _config = {
|
|
75
|
-
name: "Bundle Discovery",
|
|
76
|
-
mode: "single",
|
|
77
|
-
// models: [ [Object] ],
|
|
78
|
-
colorScheme: "auto",
|
|
79
|
-
download: true,
|
|
80
|
-
upload: false,
|
|
81
|
-
embed: false,
|
|
82
|
-
encodings: false,
|
|
83
|
-
};
|
|
84
|
-
const _options = {
|
|
85
|
-
singleFile,
|
|
86
|
-
clean,
|
|
87
|
-
output,
|
|
88
|
-
//
|
|
89
|
-
cache: true,
|
|
90
|
-
cachedir: path.resolve(__dirname, "./.discoveryjs-cache"),
|
|
91
|
-
checkCacheTtl: false,
|
|
92
|
-
minify: true,
|
|
93
|
-
dataCompression: true,
|
|
94
|
-
sourcemap: false,
|
|
95
|
-
embed: "by-config",
|
|
96
|
-
experimentalJsonxl: false,
|
|
97
|
-
scriptFormat: "esm",
|
|
98
|
-
scriptExternal: [],
|
|
99
|
-
data: true,
|
|
100
|
-
excludeModelOnDataFail: false,
|
|
101
|
-
prettyData: false,
|
|
102
|
-
modelDownload: false,
|
|
103
|
-
modelDataUpload: true,
|
|
104
|
-
modelResetCache: false,
|
|
105
|
-
serveOnlyAssets: true,
|
|
106
|
-
dev: true,
|
|
107
|
-
config: configFile,
|
|
108
|
-
configFile: configFile,
|
|
109
|
-
};
|
|
110
|
-
return build(_options, _config, configFile).then((result) => {
|
|
111
|
-
console.log(`========================================`);
|
|
112
|
-
console.log(
|
|
113
|
-
`✅ HTML page built successfully at: ${chalk.green(
|
|
114
|
-
path.resolve(output, "index.html").replace(process.cwd() + "/", ""),
|
|
115
|
-
)}`,
|
|
116
|
-
);
|
|
117
|
-
console.log(`========================================`);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
module.exports = {
|
|
122
|
-
buildHtmlPage,
|
|
123
|
-
};
|
package/lib/isRsdoctorReport.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const chalk = require("chalk");
|
|
2
|
-
|
|
3
|
-
const isRsdoctorReportPath = (reportPath) => {
|
|
4
|
-
try {
|
|
5
|
-
const reportJson = require(reportPath);
|
|
6
|
-
return isRsdoctorReport(reportJson, reportPath);
|
|
7
|
-
} catch {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const isRsdoctorReport = (reportJson, reportPath, noLogs) => {
|
|
13
|
-
try {
|
|
14
|
-
if (
|
|
15
|
-
Array.isArray(reportJson?.data?.moduleGraph?.modules) ||
|
|
16
|
-
Array.isArray(reportJson?.data?.packageGraph?.packages)
|
|
17
|
-
) {
|
|
18
|
-
!noLogs &&
|
|
19
|
-
console.info(
|
|
20
|
-
`Detected ${chalk.red("rsdoctor")} format in the input file: ${chalk.green(reportPath)}`,
|
|
21
|
-
);
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
return false;
|
|
25
|
-
} catch {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
module.exports = {
|
|
31
|
-
isRsdoctorReport,
|
|
32
|
-
isRsdoctorReportPath,
|
|
33
|
-
};
|
package/lib/rsdoctor.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
const { resolve } = require("path");
|
|
2
|
-
|
|
3
|
-
const possibleEntryFiles = [
|
|
4
|
-
"index.js",
|
|
5
|
-
"index.jsx",
|
|
6
|
-
"index.ts",
|
|
7
|
-
"index.tsx",
|
|
8
|
-
"index.mjs",
|
|
9
|
-
"index.cjs",
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
const doStructureCheck = (rsdoctorData) => {
|
|
13
|
-
if (!(
|
|
14
|
-
Array.isArray(rsdoctorData?.data?.configs) &&
|
|
15
|
-
rsdoctorData.data.configs.length === 1
|
|
16
|
-
)) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
`Unexpected number of "data.configs[]" in rsdoctor-data.json. Work only with single config. Found: ${rsdoctorData?.data?.configs?.length}`,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!Array.isArray(rsdoctorData?.data?.packageGraph?.packages)) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
`Unexpected "data.packageGraph.packages[]" in rsdoctor-data.json. Expected array. Found: ${typeof rsdoctorData?.data?.packageGraph?.packages}`,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const firstConfig = rsdoctorData.data.configs[0];
|
|
29
|
-
|
|
30
|
-
if (!(firstConfig.name === "rspack" || firstConfig.name === "webpack")) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`Unsupported bundler: ${firstConfig.name}@${firstConfig.version}. Only 'rspack' and 'webpack' are supported.`,
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const getDependenciesMap = (rsdoctorData) => {
|
|
38
|
-
const depsMap = new Map(
|
|
39
|
-
rsdoctorData.data.moduleGraph.dependencies.map((dep) => [dep.id, dep]),
|
|
40
|
-
);
|
|
41
|
-
return depsMap;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const getEntryFile = (rsdoctorData) => {
|
|
45
|
-
const firstConfig = rsdoctorData?.data?.configs?.[0];
|
|
46
|
-
const entry = firstConfig?.config?.entry;
|
|
47
|
-
const entryFile =
|
|
48
|
-
typeof entry?.main === "string"
|
|
49
|
-
? entry.main
|
|
50
|
-
: typeof entry?.main?.import === "string"
|
|
51
|
-
? entry.main.import
|
|
52
|
-
: entry?.main.import[0];
|
|
53
|
-
|
|
54
|
-
if (entryFile) {
|
|
55
|
-
return resolve(firstConfig.root, entryFile);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const pathsToCheck = possibleEntryFiles.map((f) =>
|
|
59
|
-
resolve(firstConfig.root, f),
|
|
60
|
-
);
|
|
61
|
-
const indexFile = rsdoctorData.data.moduleGraph.modules.find((mdl) =>
|
|
62
|
-
pathsToCheck.some((entry) => mdl.path === entry),
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (indexFile && indexFile.imported?.length === 0) {
|
|
66
|
-
return indexFile.path;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return `${firstConfig.root}/index.js`;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const transformRSDoctorData = (rsdoctorData) => {
|
|
73
|
-
doStructureCheck(rsdoctorData);
|
|
74
|
-
const tmpDependenciesMap = getDependenciesMap(rsdoctorData);
|
|
75
|
-
const firstConfig = rsdoctorData.data.configs[0];
|
|
76
|
-
return {
|
|
77
|
-
date: Date.now(), // no info in rspack report
|
|
78
|
-
entryPoint: getEntryFile(rsdoctorData),
|
|
79
|
-
rootFolder: firstConfig.root,
|
|
80
|
-
// envs: {},
|
|
81
|
-
transformOptions: {
|
|
82
|
-
// customTransformOptions: {},
|
|
83
|
-
dev: firstConfig.config.mode !== "production",
|
|
84
|
-
minify: firstConfig.config.optimization?.minimize ?? false,
|
|
85
|
-
platform: firstConfig.config.name ?? "ios",
|
|
86
|
-
// type: "module",
|
|
87
|
-
// unstable_transformProfile: "default",
|
|
88
|
-
},
|
|
89
|
-
// Example of package:
|
|
90
|
-
// {
|
|
91
|
-
// name: "@react-native/js-polyfills",
|
|
92
|
-
// absolutePath:
|
|
93
|
-
// "/Users/xd/tmp/RN84/node_modules/@react-native/js-polyfills",
|
|
94
|
-
// version: "0.84.1",
|
|
95
|
-
// }
|
|
96
|
-
packages: rsdoctorData.data.packageGraph.packages.map((pkg) => ({
|
|
97
|
-
name: pkg.name,
|
|
98
|
-
absolutePath: pkg.root,
|
|
99
|
-
version: pkg.version,
|
|
100
|
-
source: { sizeInBytes: pkg.size?.sourceSize ?? 1 },
|
|
101
|
-
output: { sizeInBytes: pkg.size?.parsedSize ?? 1 },
|
|
102
|
-
})),
|
|
103
|
-
// Example of module:
|
|
104
|
-
// {
|
|
105
|
-
// "path": "/Users/xd/tmp/RN84/node_modules/react-native/Libraries/BatchedBridge/BatchedBridge.js",
|
|
106
|
-
// "source": {
|
|
107
|
-
// "code": "",
|
|
108
|
-
// "lineCount": 32,
|
|
109
|
-
// "sizeInBytes": 954
|
|
110
|
-
// },
|
|
111
|
-
// "output": {
|
|
112
|
-
// "code": "",
|
|
113
|
-
// "lineCount": 1,
|
|
114
|
-
// "sizeInBytes": 219
|
|
115
|
-
// },
|
|
116
|
-
// "dependencies": [
|
|
117
|
-
// {
|
|
118
|
-
// "absolutePath": "/Users/xd/tmp/RN84/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js",
|
|
119
|
-
// "name": "./MessageQueue"
|
|
120
|
-
// }
|
|
121
|
-
// ]
|
|
122
|
-
// },
|
|
123
|
-
modules: rsdoctorData.data.moduleGraph.modules.map((mdl) => ({
|
|
124
|
-
path: mdl.path,
|
|
125
|
-
source: {
|
|
126
|
-
code: "", // no code in rspack report
|
|
127
|
-
lineCount: 0, // no code to count lines in rspack report
|
|
128
|
-
sizeInBytes: mdl.size?.sourceSize ?? 0,
|
|
129
|
-
},
|
|
130
|
-
output: {
|
|
131
|
-
code: "",
|
|
132
|
-
lineCount: 0,
|
|
133
|
-
sizeInBytes: mdl.size?.parsedSize ?? 0,
|
|
134
|
-
},
|
|
135
|
-
dependencies: mdl.dependencies
|
|
136
|
-
.map((depNumId) => {
|
|
137
|
-
const dep = tmpDependenciesMap.get(depNumId);
|
|
138
|
-
return dep
|
|
139
|
-
? { absolutePath: dep.resolvedRequest, name: dep.request }
|
|
140
|
-
: null;
|
|
141
|
-
})
|
|
142
|
-
.filter((e) => e !== null),
|
|
143
|
-
})),
|
|
144
|
-
};
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
module.exports = {
|
|
148
|
-
transformRSDoctorData,
|
|
149
|
-
};
|
package/lib/server.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const { createServer } = require("@discoveryjs/cli");
|
|
5
|
-
const { silent } = require("@discoveryjs/cli/lib/shared/utils.js");
|
|
6
|
-
const config = require("../.discoveryrc.js");
|
|
7
|
-
const { isRsdoctorReportPath } = require("./isRsdoctorReport.js");
|
|
8
|
-
|
|
9
|
-
function serve(filePath, port, verbose) {
|
|
10
|
-
const PORT = process.env.PORT || port;
|
|
11
|
-
|
|
12
|
-
if (verbose) {
|
|
13
|
-
console.info(
|
|
14
|
-
`start server with file: ${filePath} on port: ${port} ${process.env.PORT ? `(${chalk.yellow("PORT")} env)` : ""}`,
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!filePath) {
|
|
19
|
-
console.error(
|
|
20
|
-
`Usage: '${chalk.green("npx react-native-bundle-discovery server <path-to-file>")}', Please provide a path to a JSON file.`,
|
|
21
|
-
);
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const jsonFilePath = path.resolve(process.cwd(), filePath);
|
|
26
|
-
if (verbose) {
|
|
27
|
-
console.info(
|
|
28
|
-
`Loading JSON file from: ${chalk.green(jsonFilePath)}, base directory: ${chalk.green(process.cwd())}`,
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let fullJsonPath;
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
fullJsonPath = require.resolve(jsonFilePath);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error(`❌Error loading file: ${chalk.red(jsonFilePath)}\n\n`);
|
|
38
|
-
console.error(err.message);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const configFile = path.resolve(__dirname, "./.tmp.js");
|
|
43
|
-
|
|
44
|
-
if (verbose) {
|
|
45
|
-
console.info(
|
|
46
|
-
`Creating temporary config file at: ${chalk.green(configFile)}, for discovery.js`,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
const transformRcdoctor = require.resolve("./rsdoctor.js");
|
|
50
|
-
fs.writeFileSync(
|
|
51
|
-
configFile,
|
|
52
|
-
`const {transformRSDoctorData} = require("${transformRcdoctor}");
|
|
53
|
-
module.exports = ${JSON.stringify(
|
|
54
|
-
{ ...config, data: "<tmp>" },
|
|
55
|
-
null,
|
|
56
|
-
1,
|
|
57
|
-
).replace(
|
|
58
|
-
`"<tmp>"`,
|
|
59
|
-
isRsdoctorReportPath(fullJsonPath)
|
|
60
|
-
? `() => transformRSDoctorData(require("${fullJsonPath}"))`
|
|
61
|
-
: `() => require("${fullJsonPath}")`,
|
|
62
|
-
)};`,
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (verbose) {
|
|
66
|
-
console.info(`Running server with config: ${chalk.green(configFile)}`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return silent(() =>
|
|
70
|
-
createServer({
|
|
71
|
-
cache: false,
|
|
72
|
-
minify: true,
|
|
73
|
-
dev: false,
|
|
74
|
-
config: configFile,
|
|
75
|
-
configFile,
|
|
76
|
-
}).then((server) =>
|
|
77
|
-
server.listen(PORT, () => {
|
|
78
|
-
console.log(
|
|
79
|
-
`[react-native-bundle-discovery]: 🚀 Server listen on ${chalk.green.underline(
|
|
80
|
-
chalk.green(`http://localhost:${PORT}`),
|
|
81
|
-
)}`,
|
|
82
|
-
);
|
|
83
|
-
}),
|
|
84
|
-
),
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = {
|
|
89
|
-
serve,
|
|
90
|
-
};
|