UNPKG

1.33 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _fetch = require("./fetch");
8/**
9 * Copyright (c) Facebook, Inc. and its affiliates.
10 *
11 * This source code is licensed under the MIT license found in the
12 * LICENSE file in the root directory of this source tree.
13 *
14 */
15
16/**
17 * Indicates whether or not the packager is running. It returns a promise that
18 * returns one of these possible values:
19 * - `running`: the packager is running
20 * - `not_running`: the packager nor any process is running on the expected port.
21 * - `unrecognized`: one other process is running on the port we expect the packager to be running.
22 */
23async function isPackagerRunning(packagerPort = process.env.RCT_METRO_PORT || '8081') {
24 try {
25 const {
26 data,
27 headers
28 } = await (0, _fetch.fetch)(`http://localhost:${packagerPort}/status`);
29 try {
30 if (data === 'packager-status:running') {
31 return {
32 status: 'running',
33 root: headers.get('X-React-Native-Project-Root') ?? ''
34 };
35 }
36 } catch (_error) {
37 return 'unrecognized';
38 }
39 return 'unrecognized';
40 } catch (_error) {
41 return 'not_running';
42 }
43}
44var _default = isPackagerRunning;
45exports.default = _default;
46
47//# sourceMappingURL=isPackagerRunning.ts.map
\No newline at end of file