From c2fbc16150f3985a022e89b4a6376568795da12c Mon Sep 17 00:00:00 2001 From: Max Hung Date: Wed, 8 May 2019 09:55:37 +1200 Subject: [PATCH 1/4] Add custom port --- package-lock.json | 2 +- src/index.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index c33da90..5e93781 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "visualize-bundle", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/index.ts b/src/index.ts index 1b1539d..4f8d250 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ commander .option('-d, --dev', 'Analyse developement bundle') .option('-j, --json', 'Output JSON') .option('-o, --output [dir]', 'Specify output dir', defaultDir) + .option('-p, --port [port]', 'Specify js package port') .parse(process.argv); const sourceMapExplorer = require('source-map-explorer'); @@ -45,7 +46,7 @@ const start = async () => { isExpoRunning(), isRnRunning() ]); - let port = expoRunning ? 19001 : 8081; + let port = commander.port || (expoRunning ? 19001 : 8081); if (expoRunning && !rnRunning) { console.log('Found Expo app.'); @@ -89,8 +90,8 @@ const start = async () => { port === 19001 ? [`http://localhost:19001/node_modules/expo/AppEntry.bundle?${query}`] : [ - `http://localhost:8081/index.bundle?${query}`, - `http://localhost:8081/index.${platform}.bundle?${query}` + `http://localhost:${port}/index.bundle?${query}`, + `http://localhost:${port}/index.${platform}.bundle?${query}` ] ); spinner.text = `Getting map from port ${port}...`; @@ -99,8 +100,8 @@ const start = async () => { port === 19001 ? [`http://localhost:19001/node_modules/expo/AppEntry.map?${query}`] : [ - `http://localhost:8081/index.map?${query}`, - `http://localhost:8081/index.${platform}.map?${query}` + `http://localhost:${port}/index.map?${query}`, + `http://localhost:${port}/index.${platform}.map?${query}` ] ); const outputDir = path.resolve(commander.output); From 51321e5ca85d5661ca29d4589360c2a61a6cbba3 Mon Sep 17 00:00:00 2001 From: Jonny Burger Date: Wed, 8 May 2019 12:39:40 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4695b5f..bc65dc4 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ The following options are available: -a, --android analyse Android bundle -d, --dev analyse developement bundle -o, --output [dir] output directory +-p, --port [port] use custom port -j, --json save output as JSON file instead of HTML -v, --version print the version number -h, --help print usage information From f11b45ef197e48f4d39f769edb4528a58961ca02 Mon Sep 17 00:00:00 2001 From: Jonny Burger Date: Wed, 8 May 2019 12:46:38 +0200 Subject: [PATCH 3/4] Tweaks to the flow --- src/index.ts | 12 ++++++------ src/is-rn-running.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4f8d250..3bf6534 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,7 @@ const start = async () => { process.stdout.write('Searching for running React Native app... '); const [expoRunning, rnRunning] = await Promise.all([ isExpoRunning(), - isRnRunning() + isRnRunning(commander.port || 8081) ]); let port = commander.port || (expoRunning ? 19001 : 8081); @@ -57,7 +57,7 @@ const start = async () => { console.log(''); } - if (expoRunning && rnRunning) { + if (expoRunning && rnRunning && !commander.port) { console.log('Multiple found.'); const prompt = inquirer.createPromptModule(); const {project} = await prompt([ @@ -90,8 +90,8 @@ const start = async () => { port === 19001 ? [`http://localhost:19001/node_modules/expo/AppEntry.bundle?${query}`] : [ - `http://localhost:${port}/index.bundle?${query}`, - `http://localhost:${port}/index.${platform}.bundle?${query}` + `http://localhost:${port}/index.bundle?${query}`, + `http://localhost:${port}/index.${platform}.bundle?${query}` ] ); spinner.text = `Getting map from port ${port}...`; @@ -100,8 +100,8 @@ const start = async () => { port === 19001 ? [`http://localhost:19001/node_modules/expo/AppEntry.map?${query}`] : [ - `http://localhost:${port}/index.map?${query}`, - `http://localhost:${port}/index.${platform}.map?${query}` + `http://localhost:${port}/index.map?${query}`, + `http://localhost:${port}/index.${platform}.map?${query}` ] ); const outputDir = path.resolve(commander.output); diff --git a/src/is-rn-running.ts b/src/is-rn-running.ts index bb7bfc7..1322c5f 100644 --- a/src/is-rn-running.ts +++ b/src/is-rn-running.ts @@ -1,8 +1,8 @@ import getResource from './request-resource'; -export default async (): Promise => { +export default async (port: number): Promise => { try { - await getResource('http://localhost:8081'); + await getResource(`http://localhost:${port}`); return true; } catch (err) { return false; From a8108710d8a311a6e8647a22d205760cca353729 Mon Sep 17 00:00:00 2001 From: Jonny Burger Date: Wed, 8 May 2019 12:47:32 +0200 Subject: [PATCH 4/4] bump version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5e93781..cc4f19e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "visualize-bundle", - "version": "1.1.1", + "version": "1.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 642db65..60f2308 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "visualize-bundle", - "version": "1.1.1", + "version": "1.1.2", "description": "Visualize React Native bundle", "main": "dist/index.js", "bin": "dist/index.js",