Skip to content

Commit

Permalink
Merge pull request #5096 from dklymenk/4819-improve-check-port-script
Browse files Browse the repository at this point in the history
#4819 improve the check port script
  • Loading branch information
marcaaron authored Sep 9, 2021
2 parents a74ebd0 + da90f41 commit 3676eb3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 44 deletions.
18 changes: 18 additions & 0 deletions config/checkMetroBundlerPort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const {isPackagerRunning} = require('@react-native-community/cli-tools');

/**
* Function isPackagerRunning indicates whether or not the packager is running. It returns a promise that
* returns one of these possible values:
* - `running`: the packager is running
* - `not_running`: the packager nor any process is running on the expected port.
* - `unrecognized`: one other process is running on the port we expect the packager to be running.
*/
isPackagerRunning().then((result) => {
if (result === 'unrecognized') {
console.error(
'The port 8081 is currently in use.',
'You can run `lsof -i :8081` to see which program is using it.\n',
);
process.exit(1);
}
});
39 changes: 0 additions & 39 deletions config/checkPort.js

This file was deleted.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"license": "MIT",
"private": true,
"scripts": {
"android": "npm run check-port -- 8081 && react-native run-android",
"ios": "npm run check-port -- 8081 && react-native run-ios",
"ipad": "npm run check-port -- 8081 && react-native run-ios --simulator=\"iPad Pro (12.9-inch) (4th generation)\"",
"ipad-sm": "npm run check-port -- 8081 && react-native run-ios --simulator=\"iPad Pro (9.7-inch)\"",
"android": "npm run check-metro-bundler-port && react-native run-android",
"ios": "npm run check-metro-bundler-port && react-native run-ios",
"ipad": "npm run check-metro-bundler-port && react-native run-ios --simulator=\"iPad Pro (12.9-inch) (4th generation)\"",
"ipad-sm": "npm run check-metro-bundler-port && react-native run-ios --simulator=\"iPad Pro (9.7-inch)\"",
"desktop": "node desktop/start.js",
"start": "react-native start",
"web": "node web/proxy.js & webpack-dev-server --open --config config/webpack/webpack.dev.js",
Expand All @@ -30,7 +30,7 @@
"gh-actions-build": "./.github/scripts/buildActions.sh",
"gh-actions-validate": "./.github/scripts/validateActionsAndWorkflows.sh",
"analyze-packages": "ANALYZE_BUNDLE=true webpack --config config/webpack/webpack.prod.js",
"check-port": "node config/checkPort.js"
"check-metro-bundler-port": "node config/checkMetroBundlerPort.js"
},
"dependencies": {
"@formatjs/intl-getcanonicallocales": "^1.5.8",
Expand Down

0 comments on commit 3676eb3

Please sign in to comment.