isPackagerRunning.js 1.1 KB

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