'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.unblockAndGetVersionAsync = exports.addToPathAsync = undefined; let addToPathAsync = exports.addToPathAsync = (() => { var _ref = _asyncToGenerator(function* () { if (!isPlatformSupported()) { return; } yield (_Binaries || _load_Binaries()).addToPathAsync('watchman'); }); return function addToPathAsync() { return _ref.apply(this, arguments); }; })(); let unblockAndGetVersionAsync = exports.unblockAndGetVersionAsync = (() => { var _ref2 = _asyncToGenerator(function* (projectRoot) { if (!isPlatformSupported()) { return null; } try { // `watchman version` returns: // { // "version": "4.7.0" // } let result = yield _unblockAndVersionAsync(projectRoot); let watchmanVersion = JSON.parse((_lodash || _load_lodash()).default.trim(result.stdout)).version; return watchmanVersion; } catch (e) { // TODO: Maybe check to make sure this is ENOENT (which means watchman isn't installed) // We might want to report other errors return null; } }); return function unblockAndGetVersionAsync(_x) { return _ref2.apply(this, arguments); }; })(); let _unblockAndVersionAsync = (() => { var _ref3 = _asyncToGenerator(function* (projectRoot) { let cancelObject = { isDoneWithVersionCheck: false }; let result = yield Promise.race([_unblockAsync(projectRoot, cancelObject), _versionAsync(cancelObject)]); if (result.isUnblock) { result = yield Promise.race([_versionAsync(), _asyncToGenerator(function* () { yield (0, (_delayAsync || _load_delayAsync()).default)(WAIT_FOR_WATCHMAN_VERSION_MS); throw new Error(`\`watchman version\` failed even after \`launchctl unload\``); })]); (_Analytics || _load_Analytics()).logEvent('version after launchctl unload'); return result; } else { return result; } }); return function _unblockAndVersionAsync(_x2) { return _ref3.apply(this, arguments); }; })(); let _unblockAsync = (() => { var _ref5 = _asyncToGenerator(function* (projectRoot, cancelObject) { yield (0, (_delayAsync || _load_delayAsync()).default)(WAIT_FOR_WATCHMAN_VERSION_MS); if (!cancelObject.isDoneWithVersionCheck) { (_Analytics || _load_Analytics()).logEvent('launchctl unload'); if (process.env.TMPDIR && process.env.USER) { // XDL's copy of watchman: (_rimraf || _load_rimraf()).default.sync(_path.default.join(process.env.TMPDIR, `${process.env.USER}-state`)); // homebrew's watchman: (_rimraf || _load_rimraf()).default.sync(`/usr/local/var/run/watchman/${process.env.USER}-state`); } if (process.platform === 'darwin') { yield (0, (_spawnAsync || _load_spawnAsync()).default)('launchctl', ['unload', '-F', '~/Library/LaunchAgents/com.github.facebook.watchman.plist']); } if (projectRoot) { yield (0, (_spawnAsync || _load_spawnAsync()).default)('watchman', ['watch-del', projectRoot]); yield (0, (_spawnAsync || _load_spawnAsync()).default)('watchman', ['watch-project', projectRoot]); } } return { isUnblock: true }; }); return function _unblockAsync(_x3, _x4) { return _ref5.apply(this, arguments); }; })(); let _versionAsync = (() => { var _ref6 = _asyncToGenerator(function* (cancelObject) { let result = yield (0, (_spawnAsync || _load_spawnAsync()).default)('watchman', ['version']); if (cancelObject) { cancelObject.isDoneWithVersionCheck = true; } return result; }); return function _versionAsync(_x5) { return _ref6.apply(this, arguments); }; })(); exports.isPlatformSupported = isPlatformSupported; var _lodash; function _load_lodash() { return _lodash = _interopRequireDefault(require('lodash')); } var _spawnAsync; function _load_spawnAsync() { return _spawnAsync = _interopRequireDefault(require('@expo/spawn-async')); } var _delayAsync; function _load_delayAsync() { return _delayAsync = _interopRequireDefault(require('delay-async')); } var _rimraf; function _load_rimraf() { return _rimraf = _interopRequireDefault(require('rimraf')); } var _path = _interopRequireDefault(require('path')); var _Analytics; function _load_Analytics() { return _Analytics = _interopRequireWildcard(require('./Analytics')); } var _Binaries; function _load_Binaries() { return _Binaries = _interopRequireWildcard(require('./Binaries')); } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } const WAIT_FOR_WATCHMAN_VERSION_MS = 3000; function isPlatformSupported() { return process.platform === 'darwin'; } //# sourceMappingURL=__sourcemaps__/Watchman.js.map