|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 12 | + if (mod && mod.__esModule) return mod; |
| 13 | + var result = {}; |
| 14 | + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; |
| 15 | + result["default"] = mod; |
| 16 | + return result; |
| 17 | +}; |
| 18 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 19 | +const cache = __importStar(require("@actions/tool-cache")); |
| 20 | +const cli = __importStar(require("@actions/exec")); |
| 21 | +const io = __importStar(require("@actions/io")); |
| 22 | +const path = __importStar(require("path")); |
| 23 | +// eslint-disable-next-line @typescript-eslint/no-var-requires |
| 24 | +const registry = require('libnpm'); |
| 25 | +/** |
| 26 | + * Resolve the provided semver to exact version of `expo-cli`. |
| 27 | + * This uses the npm registry and accepts latest, dist-tags or version ranges. |
| 28 | + * It's used to determine the cached version of `expo-cli`. |
| 29 | + */ |
| 30 | +function resolve(version) { |
| 31 | + return __awaiter(this, void 0, void 0, function* () { |
| 32 | + return (yield registry.manifest(`expo-cli@${version}`)).version; |
| 33 | + }); |
| 34 | +} |
| 35 | +exports.resolve = resolve; |
| 36 | +/** |
| 37 | + * Install `expo-cli`, by version, using the packager. |
| 38 | + * Here you can provide any semver range or dist tag used in the registry. |
| 39 | + * It returns the path where Expo is installed. |
| 40 | + */ |
| 41 | +function install(version, packager) { |
| 42 | + return __awaiter(this, void 0, void 0, function* () { |
| 43 | + const exact = yield resolve(version); |
| 44 | + let root = yield fromCache(exact); |
| 45 | + if (!root) { |
| 46 | + root = yield fromPackager(exact, packager); |
| 47 | + root = yield toCache(exact, root); |
| 48 | + } |
| 49 | + return path.join(root, 'node_modules', '.bin'); |
| 50 | + }); |
| 51 | +} |
| 52 | +exports.install = install; |
| 53 | +/** |
| 54 | + * Install `expo-cli`, by version, using npm or yarn. |
| 55 | + * It creates a temporary directory to store all required files. |
| 56 | + */ |
| 57 | +function fromPackager(version, packager) { |
| 58 | + return __awaiter(this, void 0, void 0, function* () { |
| 59 | + const root = process.env['RUNNER_TEMP'] || ''; |
| 60 | + const tool = yield io.which(packager); |
| 61 | + yield io.mkdirP(root); |
| 62 | + yield cli.exec(tool, ['add', `expo-cli@${version}`], { cwd: root }); |
| 63 | + return root; |
| 64 | + }); |
| 65 | +} |
| 66 | +exports.fromPackager = fromPackager; |
| 67 | +/** |
| 68 | + * Get the path to the `expo-cli` from cache, if any. |
| 69 | + * Note, this cache is **NOT** shared between jobs. |
| 70 | + * |
| 71 | + * @see https://github.com/actions/toolkit/issues/47 |
| 72 | + */ |
| 73 | +function fromCache(version) { |
| 74 | + return __awaiter(this, void 0, void 0, function* () { |
| 75 | + return cache.find('expo-cli', version); |
| 76 | + }); |
| 77 | +} |
| 78 | +exports.fromCache = fromCache; |
| 79 | +/** |
| 80 | + * Store the root of `expo-cli` in the cache, for future reuse. |
| 81 | + * Note, this cache is **NOT** shared between jobs. |
| 82 | + * |
| 83 | + * @see https://github.com/actions/toolkit/issues/47 |
| 84 | + */ |
| 85 | +function toCache(version, root) { |
| 86 | + return __awaiter(this, void 0, void 0, function* () { |
| 87 | + return cache.cacheDir(root, 'expo-cli', version); |
| 88 | + }); |
| 89 | +} |
| 90 | +exports.toCache = toCache; |
0 commit comments