@expo/xdl
Version:
The Expo Development Library
132 lines (99 loc) • 4.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isPlatformSupported = isPlatformSupported;
exports.addToPathAsync = addToPathAsync;
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 Binaries() {
const data = _interopRequireWildcard(require("./Binaries"));
Binaries = function () {
return data;
};
return data;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
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 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 (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;
}
}
async function _unblockAndVersionAsync(projectRoot) {
try {
return await (0, _pTimeout().default)(_versionAsync(), WAIT_FOR_WATCHMAN_VERSION_MS);
} catch (error) {
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=__sourcemaps__/Watchman.js.map