UNPKG

eas-cli

Version:
106 lines (105 loc) 4.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.expoCommandAsync = exports.shouldUseVersionedExpoCLIWithExplicitPlatforms = exports.shouldUseVersionedExpoCLI = exports.shouldUseVersionedExpoCLIWithExplicitPlatformsExpensive = exports.shouldUseVersionedExpoCLIExpensive = void 0; const tslib_1 = require("tslib"); const spawn_async_1 = tslib_1.__importDefault(require("@expo/spawn-async")); const chalk_1 = tslib_1.__importDefault(require("chalk")); const getenv_1 = require("getenv"); const resolve_from_1 = tslib_1.__importStar(require("resolve-from")); const semver_1 = tslib_1.__importDefault(require("semver")); const memoize_1 = require("./expodash/memoize"); const log_1 = tslib_1.__importStar(require("../log")); // Aggressively returns `true` (UNVERSIONED, invalid SDK version format) to push users towards the versioned CLI. function gteSdkVersion(fromSdkVersion, sdkVersion) { if (fromSdkVersion === 'UNVERSIONED') { return true; } try { return semver_1.default.gte(fromSdkVersion, sdkVersion); } catch { return true; } } /** * @returns `true` if the project is SDK +46, has `@expo/cli`, and `EXPO_USE_LOCAL_CLI` is not set to a _false_ value. */ function shouldUseVersionedExpoCLIExpensive(projectDir, exp) { // Users can disable local CLI settings EXPO_USE_LOCAL_CLI=false // https://github.com/expo/expo/blob/69eddda7bb1dbfab44258f468cf7f22984c1e44e/packages/expo/bin/cli.js#L10 // Run the environment variable check first as it's the cheapest. const userDefinedVersionedCliEnabled = (0, getenv_1.boolish)('EXPO_USE_LOCAL_CLI', true); if (!userDefinedVersionedCliEnabled) { return false; } try { // NOTE(EvanBacon): The CLI package could be available through a monorepo // we need to ensure the project is specifically using a known supported Expo SDK version. if ( // If the version isn't defined then skip the check. // Users running in a non-standard way should use the latest supported behavior (local CLI). exp.sdkVersion && !gteSdkVersion(exp.sdkVersion, '46.0.0')) { return false; } } catch (error) { log_1.default.debug('Error detecting Expo SDK version for enabling versioned Expo CLI:', error); } // Finally ensure the CLI is available for sanity. return !!resolve_from_1.default.silent(projectDir, '@expo/cli'); } exports.shouldUseVersionedExpoCLIExpensive = shouldUseVersionedExpoCLIExpensive; /** * Determine if we can and should use `expo export` with multiple `--platform` flags. * This is an issue related to `expo export --all` causing issues when users have Metro web configured. * See: https://github.com/expo/expo/pull/23621 */ function shouldUseVersionedExpoCLIWithExplicitPlatformsExpensive(projectDir) { const expoCliPath = resolve_from_1.default.silent(projectDir, '@expo/cli/package.json'); if (!expoCliPath) { return false; } return gteSdkVersion(require(expoCliPath).version, '0.10.11'); } exports.shouldUseVersionedExpoCLIWithExplicitPlatformsExpensive = shouldUseVersionedExpoCLIWithExplicitPlatformsExpensive; exports.shouldUseVersionedExpoCLI = (0, memoize_1.memoize)(shouldUseVersionedExpoCLIExpensive); exports.shouldUseVersionedExpoCLIWithExplicitPlatforms = (0, memoize_1.memoize)(shouldUseVersionedExpoCLIWithExplicitPlatformsExpensive); async function expoCommandAsync(projectDir, args, { silent = false, extraEnv = {}, } = {}) { let expoCliPath; try { expoCliPath = (0, resolve_from_1.silent)(projectDir, 'expo/bin/cli') ?? (0, resolve_from_1.default)(projectDir, 'expo/bin/cli.js'); } catch (e) { if (e.code === 'MODULE_NOT_FOUND') { throw new Error(`The \`expo\` package was not found. Follow the installation directions at ${(0, log_1.link)('https://docs.expo.dev/bare/installing-expo-modules/')}`); } throw e; } const spawnPromise = (0, spawn_async_1.default)(expoCliPath, args, { stdio: ['inherit', 'pipe', 'pipe'], // inherit stdin so user can install a missing expo-cli from inside this command env: { ...process.env, ...extraEnv, }, }); const { child: { stdout, stderr }, } = spawnPromise; if (!(stdout && stderr)) { throw new Error('Failed to spawn expo-cli'); } if (!silent) { stdout.on('data', data => { for (const line of data.toString().trim().split('\n')) { log_1.default.log(`${chalk_1.default.gray('[expo-cli]')} ${line}`); } }); stderr.on('data', data => { for (const line of data.toString().trim().split('\n')) { log_1.default.warn(`${chalk_1.default.gray('[expo-cli]')} ${line}`); } }); } await spawnPromise; } exports.expoCommandAsync = expoCommandAsync;