240 lines
7.5 KiB
JavaScript
240 lines
7.5 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.writePathToUserSettingsAsync = exports.sourceBashLoginScriptsAsync = exports.addToPathAsync = exports.OSX_SOURCE_PATH = undefined;
|
||
|
|
||
|
let addToPathAsync = exports.addToPathAsync = (() => {
|
||
|
var _ref = _asyncToGenerator(function* (name) {
|
||
|
yield sourceBashLoginScriptsAsync();
|
||
|
|
||
|
if (yield _hasbinAsync(name)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Users can set {ignoreBundledBinaries: ["watchman"]} to tell us to never use our version
|
||
|
let ignoreBundledBinaries = yield (_UserSettings || _load_UserSettings()).default.getAsync('ignoreBundledBinaries', []);
|
||
|
if (ignoreBundledBinaries.includes(name)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
let binariesPath = _path.default.join(getBinariesPath(), name);
|
||
|
_prependToPath(binariesPath);
|
||
|
});
|
||
|
|
||
|
return function addToPathAsync(_x) {
|
||
|
return _ref.apply(this, arguments);
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
let sourceBashLoginScriptsAsync = exports.sourceBashLoginScriptsAsync = (() => {
|
||
|
var _ref2 = _asyncToGenerator(function* () {
|
||
|
if (hasSourcedBashLoginScripts || process.platform === 'win32') {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ((_Config || _load_Config()).default.developerTool !== 'xde') {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
hasSourcedBashLoginScripts = true;
|
||
|
|
||
|
let userSettingsPATH = yield (_UserSettings || _load_UserSettings()).default.getAsync('PATH', null);
|
||
|
|
||
|
if (userSettingsPATH) {
|
||
|
_prependToPath(userSettingsPATH);
|
||
|
} else if (_expoRCFileExists()) {
|
||
|
try {
|
||
|
// User has a ~/.expo/bashrc. Run that and grab PATH.
|
||
|
let result = yield (0, (_spawnAsync || _load_spawnAsync()).default)(_path.default.join(getBinariesPath(), `get-path-bash`), {
|
||
|
env: {
|
||
|
PATH: ''
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if (result.stderr) {
|
||
|
(_Logger || _load_Logger()).default.global.warn(`Error sourcing ~/.expo/bashrc script: ${result.stderr}`);
|
||
|
}
|
||
|
|
||
|
if (result.stdout) {
|
||
|
_prependToPath(result.stdout);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
(_Logger || _load_Logger()).default.global.warn(`Error sourcing ~/.expo/bashrc script: ${e.stderr}`);
|
||
|
}
|
||
|
} else {
|
||
|
try {
|
||
|
// No ~/.expo/bashrc file found. Run `env` in process.env.SHELL.
|
||
|
const shellName = process.env.SHELL;
|
||
|
if (!shellName) {
|
||
|
throw new Error('This command requires being run within a shell.');
|
||
|
}
|
||
|
|
||
|
let result;
|
||
|
if (/t?csh$/.test(shellName)) {
|
||
|
// csh
|
||
|
result = yield (0, (_spawnAsync || _load_spawnAsync()).default)(shellName, ['-d', '-c', 'env']);
|
||
|
} else if (/zsh$/.test(shellName)) {
|
||
|
// zsh
|
||
|
result = yield (0, (_spawnAsync || _load_spawnAsync()).default)(shellName, ['-l', '-c', 'env']);
|
||
|
} else {
|
||
|
// bash, fish
|
||
|
result = yield (0, (_spawnAsync || _load_spawnAsync()).default)(shellName, ['-l', '-c', 'env']);
|
||
|
}
|
||
|
|
||
|
if (result.stderr) {
|
||
|
(_Logger || _load_Logger()).default.global.warn(`Error sourcing shell startup scripts: ${result.stderr}.${ERROR_MESSAGE}`);
|
||
|
}
|
||
|
|
||
|
if (result.stdout) {
|
||
|
let regexResult = result.stdout.match(/(^|\n)PATH=(.+)/);
|
||
|
|
||
|
if (regexResult.length >= 3) {
|
||
|
_prependToPath(regexResult[2]);
|
||
|
} else {
|
||
|
(_Logger || _load_Logger()).default.global.warn(`Error parsing shell startup scripts output: ${result.stderr}.${ERROR_MESSAGE}`);
|
||
|
}
|
||
|
}
|
||
|
} catch (e) {
|
||
|
(_Logger || _load_Logger()).default.global.warn(`Error sourcing shell startup scripts: ${e.stderr}.${ERROR_MESSAGE}`);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return function sourceBashLoginScriptsAsync() {
|
||
|
return _ref2.apply(this, arguments);
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
let writePathToUserSettingsAsync = exports.writePathToUserSettingsAsync = (() => {
|
||
|
var _ref3 = _asyncToGenerator(function* () {
|
||
|
yield (_UserSettings || _load_UserSettings()).default.setAsync('PATH', process.env.PATH);
|
||
|
|
||
|
// Used in detach app
|
||
|
let pathFile = _path.default.join((_UserSettings || _load_UserSettings()).default.dotExpoHomeDirectory(), 'PATH');
|
||
|
yield (_fsExtra || _load_fsExtra()).default.writeFile(pathFile, process.env.PATH);
|
||
|
});
|
||
|
|
||
|
return function writePathToUserSettingsAsync() {
|
||
|
return _ref3.apply(this, arguments);
|
||
|
};
|
||
|
})();
|
||
|
|
||
|
exports.getBinariesPath = getBinariesPath;
|
||
|
exports.isXcodeInstalled = isXcodeInstalled;
|
||
|
|
||
|
var _fsExtra;
|
||
|
|
||
|
function _load_fsExtra() {
|
||
|
return _fsExtra = _interopRequireDefault(require('fs-extra'));
|
||
|
}
|
||
|
|
||
|
var _hasbin;
|
||
|
|
||
|
function _load_hasbin() {
|
||
|
return _hasbin = _interopRequireDefault(require('hasbin'));
|
||
|
}
|
||
|
|
||
|
var _spawnAsync;
|
||
|
|
||
|
function _load_spawnAsync() {
|
||
|
return _spawnAsync = _interopRequireDefault(require('@expo/spawn-async'));
|
||
|
}
|
||
|
|
||
|
var _path = _interopRequireDefault(require('path'));
|
||
|
|
||
|
var _Config;
|
||
|
|
||
|
function _load_Config() {
|
||
|
return _Config = _interopRequireDefault(require('./Config'));
|
||
|
}
|
||
|
|
||
|
var _ErrorCode;
|
||
|
|
||
|
function _load_ErrorCode() {
|
||
|
return _ErrorCode = _interopRequireDefault(require('./ErrorCode'));
|
||
|
}
|
||
|
|
||
|
var _Logger;
|
||
|
|
||
|
function _load_Logger() {
|
||
|
return _Logger = _interopRequireDefault(require('./Logger'));
|
||
|
}
|
||
|
|
||
|
var _UserSettings;
|
||
|
|
||
|
function _load_UserSettings() {
|
||
|
return _UserSettings = _interopRequireDefault(require('./UserSettings'));
|
||
|
}
|
||
|
|
||
|
var _XDLError;
|
||
|
|
||
|
function _load_XDLError() {
|
||
|
return _XDLError = _interopRequireDefault(require('./XDLError'));
|
||
|
}
|
||
|
|
||
|
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"); }); }; }
|
||
|
|
||
|
let hasSourcedBashLoginScripts = false;
|
||
|
|
||
|
const OSX_SOURCE_PATH = exports.OSX_SOURCE_PATH = _path.default.join(__dirname, '..', 'binaries', 'osx');
|
||
|
const ERROR_MESSAGE = '\nPlease run `npm install -g exp && exp path`';
|
||
|
|
||
|
function _hasbinAsync(name) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
(0, (_hasbin || _load_hasbin()).default)(name, result => {
|
||
|
resolve(result);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function getBinariesPath() {
|
||
|
if (process.platform === 'darwin') {
|
||
|
return _path.default.join(__dirname, '..', 'binaries', 'osx');
|
||
|
} else if (process.platform === 'win32') {
|
||
|
return _path.default.join(__dirname, '..', 'binaries', 'windows');
|
||
|
} else if (process.platform === 'linux') {
|
||
|
return _path.default.join(__dirname, '..', 'binaries', 'linux');
|
||
|
} else {
|
||
|
throw new (_XDLError || _load_XDLError()).default((_ErrorCode || _load_ErrorCode()).default.PLATFORM_NOT_SUPPORTED, 'Platform not supported.');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _expoRCFileExists() {
|
||
|
try {
|
||
|
return (_fsExtra || _load_fsExtra()).default.statSync(_path.default.join((_UserSettings || _load_UserSettings()).default.dotExpoHomeDirectory(), 'bashrc')).isFile();
|
||
|
} catch (e) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _prependToPath(newPath) {
|
||
|
let currentPath = process.env.PATH ? process.env.PATH : '';
|
||
|
if (currentPath.length > 0) {
|
||
|
let delimiter = process.platform === 'win32' ? ';' : ':';
|
||
|
currentPath = `${delimiter}${currentPath}`;
|
||
|
}
|
||
|
|
||
|
process.env.PATH = `${newPath}${currentPath}`;
|
||
|
}
|
||
|
|
||
|
function _isDirectory(dir) {
|
||
|
try {
|
||
|
if ((_fsExtra || _load_fsExtra()).default.statSync(dir).isDirectory()) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
} catch (e) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function isXcodeInstalled() {
|
||
|
return _isDirectory('/Applications/Xcode.app/');
|
||
|
}
|
||
|
//# sourceMappingURL=__sourcemaps__/Binaries.js.map
|