forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisPackagerRunning.js
36 lines (32 loc) · 1.03 KB
/
isPackagerRunning.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const fetch = require('node-fetch');
/**
* Indicates whether or not the packager is running. It returns a promise that
* when fulfilled can returns one out 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.
*/
function isPackagerRunning(packagerPort = process.env.RCT_METRO_PORT || 8081) {
return fetch(`http://localhost:${packagerPort}/status`).then(
res =>
res
.text()
.then(
body =>
body === 'packager-status:running' ? 'running' : 'unrecognized',
),
() => 'not_running',
);
}
module.exports = isPackagerRunning;