You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.0 KiB

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addToPathAsync = addToPathAsync;
exports.isPlatformSupported = isPlatformSupported;
exports.unblockAndGetVersionAsync = unblockAndGetVersionAsync;
function _spawnAsync() {
const data = _interopRequireDefault(require("@expo/spawn-async"));
_spawnAsync = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = _interopRequireDefault(require("fs-extra"));
_fsExtra = function () {
return data;
};
return data;
}
function _pTimeout() {
const data = _interopRequireDefault(require("p-timeout"));
_pTimeout = function () {
return data;
};
return data;
}
function _path() {
const data = _interopRequireDefault(require("path"));
_path = function () {
return data;
};
return data;
}
function _internal() {
const data = require("./internal");
_internal = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const WAIT_FOR_WATCHMAN_VERSION_MS = 3000;
function isPlatformSupported() {
return process.platform === 'darwin';
}
async function addToPathAsync() {
if (!isPlatformSupported()) {
return;
}
await _internal().Binaries.addToPathAsync('watchman');
}
async function unblockAndGetVersionAsync(projectRoot) {
if (!isPlatformSupported()) {
return null;
}
try {
// `watchman version` returns:
// {
// "version": "4.7.0"
// }
const result = await _unblockAndVersionAsync(projectRoot);
const watchmanVersion = JSON.parse(result.stdout.trim()).version;
return watchmanVersion;
} catch {
// TODO: Maybe check to make sure this is ENOENT (which means watchman isn't installed)
// We might want to report other errors
return null;
}
}
async function _unblockAndVersionAsync(projectRoot) {
try {
return await (0, _pTimeout().default)(_versionAsync(), WAIT_FOR_WATCHMAN_VERSION_MS);
} catch {
await _unblockAsync(projectRoot);
return await (0, _pTimeout().default)(_versionAsync(), WAIT_FOR_WATCHMAN_VERSION_MS, '`watchman version` failed even after `launchctl unload`');
}
}
async function _unblockAsync(projectRoot) {
if (process.env.TMPDIR && process.env.USER) {
// XDL's copy of watchman:
_fsExtra().default.removeSync(_path().default.join(process.env.TMPDIR, `${process.env.USER}-state`));
// homebrew's watchman:
_fsExtra().default.removeSync(`/usr/local/var/run/watchman/${process.env.USER}-state`);
}
if (process.platform === 'darwin') {
await (0, _spawnAsync().default)('launchctl', ['unload', '-F', '~/Library/LaunchAgents/com.github.facebook.watchman.plist']);
}
if (projectRoot) {
await (0, _spawnAsync().default)('watchman', ['watch-del', projectRoot]);
await (0, _spawnAsync().default)('watchman', ['watch-project', projectRoot]);
}
}
async function _versionAsync() {
return await (0, _spawnAsync().default)('watchman', ['version']);
}
//# sourceMappingURL=Watchman.js.map