UNPKG

xdl

Version:
82 lines (80 loc) 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execFile = exports.exec = void 0; exports.onBeforeExit = onBeforeExit; exports.once = once; exports.wait = void 0; function cp() { const data = _interopRequireWildcard(require("child_process")); cp = function () { return data; }; return data; } function _debug() { const data = _interopRequireDefault(require("debug")); _debug = function () { return data; }; return data; } function util() { const data = _interopRequireWildcard(require("util")); util = function () { return data; }; return data; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /** * Copyright (c) 2021 Expo, Inc. * Copyright (c) 2018 Drifty Co. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ const debug = (0, _debug().default)('expo:xdl:utils:process'); function once(fn) { let called = false; let r; const wrapper = (...args) => { if (!called) { called = true; r = fn(...args); } return r; }; return wrapper; } const exec = util().promisify(cp().exec); exports.exec = exec; const execFile = util().promisify(cp().execFile); exports.execFile = execFile; const wait = util().promisify(setTimeout); exports.wait = wait; const exitQueue = []; function onBeforeExit(fn) { exitQueue.push(fn); } const BEFORE_EXIT_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGBREAK']; const beforeExitHandlerWrapper = signal => once(async () => { debug('onBeforeExit handler: %s received', signal); debug('onBeforeExit handler: running %s queued functions', exitQueue.length); for (const [i, fn] of exitQueue.entries()) { try { await fn(); } catch (e) { debug('Error from function %d in exit queue: %O', i, e); } } debug('onBeforeExit handler: exiting (exit code %s)', process.exitCode ? process.exitCode : 0); process.exit(); }); for (const signal of BEFORE_EXIT_SIGNALS) { process.on(signal, beforeExitHandlerWrapper(signal)); } //# sourceMappingURL=process.js.map