UNPKG

eas-cli

Version:
101 lines (100 loc) 4.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findProjectDirAndVerifyProjectSetupAsync = exports.findProjectRootAsync = void 0; const tslib_1 = require("tslib"); const eas_json_1 = require("@expo/eas-json"); const PackageManagerUtils = tslib_1.__importStar(require("@expo/package-manager")); const chalk_1 = tslib_1.__importDefault(require("chalk")); const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); const path_1 = tslib_1.__importDefault(require("path")); const pkg_dir_1 = tslib_1.__importDefault(require("pkg-dir")); const semver_1 = tslib_1.__importDefault(require("semver")); const log_1 = require("../../../log"); const easCli_1 = require("../../../utils/easCli"); const vcs_1 = require("../../../vcs"); async function applyCliConfigAsync(projectDir) { const easJsonAccessor = eas_json_1.EasJsonAccessor.fromProjectPath(projectDir); const config = await eas_json_1.EasJsonUtils.getCliConfigAsync(easJsonAccessor); if (config?.version && !semver_1.default.satisfies(easCli_1.easCliVersion, config.version)) { throw new Error(`You are on eas-cli@${easCli_1.easCliVersion} which does not satisfy the CLI version constraint defined in eas.json (${config.version}).\n\nThis error probably means that you need update your eas-cli to a newer version.\nRun ${chalk_1.default.bold('npm install -g eas-cli')} to update the eas-cli to the latest version.`); } } async function ensureEasCliIsNotInDependenciesAsync(projectDir) { let printCliVersionWarning = false; const consoleWarn = (msg) => { if (msg) { // eslint-disable-next-line no-console console.warn(chalk_1.default.yellow(msg)); } else { // eslint-disable-next-line no-console console.warn(); } }; if (await isEasCliInDependenciesAsync(projectDir)) { printCliVersionWarning = true; consoleWarn(`Found ${chalk_1.default.bold('eas-cli')} in your project dependencies.`); } const maybeRepoRoot = PackageManagerUtils.resolveWorkspaceRoot(projectDir) ?? projectDir; if (maybeRepoRoot !== projectDir && (await isEasCliInDependenciesAsync(maybeRepoRoot))) { printCliVersionWarning = true; consoleWarn(`Found ${chalk_1.default.bold('eas-cli')} in your monorepo dependencies.`); } if (printCliVersionWarning) { consoleWarn(`It's recommended to use the ${chalk_1.default.bold('"cli.version"')} field in eas.json to enforce the ${chalk_1.default.bold('eas-cli')} version for your project.`); consoleWarn((0, log_1.learnMore)('https://github.com/expo/eas-cli#enforcing-eas-cli-version-for-your-project')); consoleWarn(); } } async function isEasCliInDependenciesAsync(dir) { const packageJsonPath = path_1.default.join(dir, 'package.json'); const packageJson = JSON.parse(await fs_extra_1.default.readFile(packageJsonPath, 'utf8')); return (packageJson?.dependencies?.['eas-cli'] !== undefined || packageJson?.devDependencies?.['eas-cli'] !== undefined); } /** * @returns the project root directory. * * @deprecated Should not be used outside of context functions. */ async function findProjectRootAsync({ cwd, defaultToProcessCwd = false, } = {}) { const projectRootDir = await (0, pkg_dir_1.default)(cwd); if (!projectRootDir) { if (!defaultToProcessCwd) { throw new Error('Run this command inside a project directory.'); } else { return process.cwd(); } } else { let vcsRoot; try { vcsRoot = path_1.default.normalize(await (0, vcs_1.resolveVcsClient)().getRootPathAsync()); } catch { } if (vcsRoot && vcsRoot.startsWith(projectRootDir) && vcsRoot !== projectRootDir) { throw new Error(`package.json is outside of the current git repository (project root: ${projectRootDir}, git root: ${vcsRoot}.`); } return projectRootDir; } } exports.findProjectRootAsync = findProjectRootAsync; let ranEnsureEasCliIsNotInDependencies = false; /** * Determine the project root directory and ensure some constraints about the project setup * like CLI version and dependencies. * @returns the project root directory * * @deprecated Should not be used outside of context functions. */ async function findProjectDirAndVerifyProjectSetupAsync() { const projectDir = await findProjectRootAsync(); await applyCliConfigAsync(projectDir); if (!ranEnsureEasCliIsNotInDependencies) { ranEnsureEasCliIsNotInDependencies = true; await ensureEasCliIsNotInDependenciesAsync(projectDir); } return projectDir; } exports.findProjectDirAndVerifyProjectSetupAsync = findProjectDirAndVerifyProjectSetupAsync;