Use @actions/tool-cache (#196)

51905b8 · Eric Meadows-Jönsson · 2023-05-08 10:40

13 files +2811 -246

Files changed

modified dist/index.js
+2673 −37
@@ -3042,6 +3042,2590 @@ function copyFile(srcFile, destFile, force) {
3042 3042 }
3043 3043 //# sourceMappingURL=io.js.map
3044 3044
3045 +/***/ }),
3046 +
3047 +/***/ 2473:
3048 +/***/ (function(module, exports, __nccwpck_require__) {
3049 +
3050 +"use strict";
3051 +
3052 +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3053 + if (k2 === undefined) k2 = k;
3054 + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3055 +}) : (function(o, m, k, k2) {
3056 + if (k2 === undefined) k2 = k;
3057 + o[k2] = m[k];
3058 +}));
3059 +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
3060 + Object.defineProperty(o, "default", { enumerable: true, value: v });
3061 +}) : function(o, v) {
3062 + o["default"] = v;
3063 +});
3064 +var __importStar = (this && this.__importStar) || function (mod) {
3065 + if (mod && mod.__esModule) return mod;
3066 + var result = {};
3067 + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
3068 + __setModuleDefault(result, mod);
3069 + return result;
3070 +};
3071 +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3072 + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3073 + return new (P || (P = Promise))(function (resolve, reject) {
3074 + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3075 + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3076 + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3077 + step((generator = generator.apply(thisArg, _arguments || [])).next());
3078 + });
3079 +};
3080 +Object.defineProperty(exports, "__esModule", ({ value: true }));
3081 +exports._readLinuxVersionFile = exports._getOsVersion = exports._findMatch = void 0;
3082 +const semver = __importStar(__nccwpck_require__(562));
3083 +const core_1 = __nccwpck_require__(2186);
3084 +// needs to be require for core node modules to be mocked
3085 +/* eslint @typescript-eslint/no-require-imports: 0 */
3086 +const os = __nccwpck_require__(2037);
3087 +const cp = __nccwpck_require__(2081);
3088 +const fs = __nccwpck_require__(7147);
3089 +function _findMatch(versionSpec, stable, candidates, archFilter) {
3090 + return __awaiter(this, void 0, void 0, function* () {
3091 + const platFilter = os.platform();
3092 + let result;
3093 + let match;
3094 + let file;
3095 + for (const candidate of candidates) {
3096 + const version = candidate.version;
3097 + core_1.debug(`check ${version} satisfies ${versionSpec}`);
3098 + if (semver.satisfies(version, versionSpec) &&
3099 + (!stable || candidate.stable === stable)) {
3100 + file = candidate.files.find(item => {
3101 + core_1.debug(`${item.arch}===${archFilter} && ${item.platform}===${platFilter}`);
3102 + let chk = item.arch === archFilter && item.platform === platFilter;
3103 + if (chk && item.platform_version) {
3104 + const osVersion = module.exports._getOsVersion();
3105 + if (osVersion === item.platform_version) {
3106 + chk = true;
3107 + }
3108 + else {
3109 + chk = semver.satisfies(osVersion, item.platform_version);
3110 + }
3111 + }
3112 + return chk;
3113 + });
3114 + if (file) {
3115 + core_1.debug(`matched ${candidate.version}`);
3116 + match = candidate;
3117 + break;
3118 + }
3119 + }
3120 + }
3121 + if (match && file) {
3122 + // clone since we're mutating the file list to be only the file that matches
3123 + result = Object.assign({}, match);
3124 + result.files = [file];
3125 + }
3126 + return result;
3127 + });
3128 +}
3129 +exports._findMatch = _findMatch;
3130 +function _getOsVersion() {
3131 + // TODO: add windows and other linux, arm variants
3132 + // right now filtering on version is only an ubuntu and macos scenario for tools we build for hosted (python)
3133 + const plat = os.platform();
3134 + let version = '';
3135 + if (plat === 'darwin') {
3136 + version = cp.execSync('sw_vers -productVersion').toString();
3137 + }
3138 + else if (plat === 'linux') {
3139 + // lsb_release process not in some containers, readfile
3140 + // Run cat /etc/lsb-release
3141 + // DISTRIB_ID=Ubuntu
3142 + // DISTRIB_RELEASE=18.04
3143 + // DISTRIB_CODENAME=bionic
3144 + // DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
3145 + const lsbContents = module.exports._readLinuxVersionFile();
3146 + if (lsbContents) {
3147 + const lines = lsbContents.split('\n');
3148 + for (const line of lines) {
3149 + const parts = line.split('=');
3150 + if (parts.length === 2 &&
3151 + (parts[0].trim() === 'VERSION_ID' ||
3152 + parts[0].trim() === 'DISTRIB_RELEASE')) {
3153 + version = parts[1]
3154 + .trim()
3155 + .replace(/^"/, '')
3156 + .replace(/"$/, '');
3157 + break;
3158 + }
3159 + }
3160 + }
3161 + }
3162 + return version;
3163 +}
3164 +exports._getOsVersion = _getOsVersion;
3165 +function _readLinuxVersionFile() {
3166 + const lsbReleaseFile = '/etc/lsb-release';
3167 + const osReleaseFile = '/etc/os-release';
3168 + let contents = '';
3169 + if (fs.existsSync(lsbReleaseFile)) {
3170 + contents = fs.readFileSync(lsbReleaseFile).toString();
3171 + }
3172 + else if (fs.existsSync(osReleaseFile)) {
3173 + contents = fs.readFileSync(osReleaseFile).toString();
3174 + }
3175 + return contents;
3176 +}
3177 +exports._readLinuxVersionFile = _readLinuxVersionFile;
3178 +//# sourceMappingURL=manifest.js.map
3179 +
3180 +/***/ }),
3181 +
3182 +/***/ 8279:
3183 +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
3184 +
3185 +"use strict";
3186 +
3187 +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3188 + if (k2 === undefined) k2 = k;
3189 + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3190 +}) : (function(o, m, k, k2) {
3191 + if (k2 === undefined) k2 = k;
3192 + o[k2] = m[k];
3193 +}));
3194 +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
3195 + Object.defineProperty(o, "default", { enumerable: true, value: v });
3196 +}) : function(o, v) {
3197 + o["default"] = v;
3198 +});
3199 +var __importStar = (this && this.__importStar) || function (mod) {
3200 + if (mod && mod.__esModule) return mod;
3201 + var result = {};
3202 + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
3203 + __setModuleDefault(result, mod);
3204 + return result;
3205 +};
3206 +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3207 + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3208 + return new (P || (P = Promise))(function (resolve, reject) {
3209 + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3210 + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3211 + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3212 + step((generator = generator.apply(thisArg, _arguments || [])).next());
3213 + });
3214 +};
3215 +Object.defineProperty(exports, "__esModule", ({ value: true }));
3216 +exports.RetryHelper = void 0;
3217 +const core = __importStar(__nccwpck_require__(2186));
3218 +/**
3219 + * Internal class for retries
3220 + */
3221 +class RetryHelper {
3222 + constructor(maxAttempts, minSeconds, maxSeconds) {
3223 + if (maxAttempts < 1) {
3224 + throw new Error('max attempts should be greater than or equal to 1');
3225 + }
3226 + this.maxAttempts = maxAttempts;
3227 + this.minSeconds = Math.floor(minSeconds);
3228 + this.maxSeconds = Math.floor(maxSeconds);
3229 + if (this.minSeconds > this.maxSeconds) {
3230 + throw new Error('min seconds should be less than or equal to max seconds');
3231 + }
3232 + }
3233 + execute(action, isRetryable) {
3234 + return __awaiter(this, void 0, void 0, function* () {
3235 + let attempt = 1;
3236 + while (attempt < this.maxAttempts) {
3237 + // Try
3238 + try {
3239 + return yield action();
3240 + }
3241 + catch (err) {
3242 + if (isRetryable && !isRetryable(err)) {
3243 + throw err;
3244 + }
3245 + core.info(err.message);
3246 + }
3247 + // Sleep
3248 + const seconds = this.getSleepAmount();
3249 + core.info(`Waiting ${seconds} seconds before trying again`);
3250 + yield this.sleep(seconds);
3251 + attempt++;
3252 + }
3253 + // Last attempt
3254 + return yield action();
3255 + });
3256 + }
3257 + getSleepAmount() {
3258 + return (Math.floor(Math.random() * (this.maxSeconds - this.minSeconds + 1)) +
3259 + this.minSeconds);
3260 + }
3261 + sleep(seconds) {
3262 + return __awaiter(this, void 0, void 0, function* () {
3263 + return new Promise(resolve => setTimeout(resolve, seconds * 1000));
3264 + });
3265 + }
3266 +}
3267 +exports.RetryHelper = RetryHelper;
3268 +//# sourceMappingURL=retry-helper.js.map
3269 +
3270 +/***/ }),
3271 +
3272 +/***/ 7784:
3273 +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
3274 +
3275 +"use strict";
3276 +
3277 +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3278 + if (k2 === undefined) k2 = k;
3279 + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
3280 +}) : (function(o, m, k, k2) {
3281 + if (k2 === undefined) k2 = k;
3282 + o[k2] = m[k];
3283 +}));
3284 +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
3285 + Object.defineProperty(o, "default", { enumerable: true, value: v });
3286 +}) : function(o, v) {
3287 + o["default"] = v;
3288 +});
3289 +var __importStar = (this && this.__importStar) || function (mod) {
3290 + if (mod && mod.__esModule) return mod;
3291 + var result = {};
3292 + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
3293 + __setModuleDefault(result, mod);
3294 + return result;
3295 +};
3296 +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3297 + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3298 + return new (P || (P = Promise))(function (resolve, reject) {
3299 + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3300 + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3301 + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3302 + step((generator = generator.apply(thisArg, _arguments || [])).next());
3303 + });
3304 +};
3305 +var __importDefault = (this && this.__importDefault) || function (mod) {
3306 + return (mod && mod.__esModule) ? mod : { "default": mod };
3307 +};
3308 +Object.defineProperty(exports, "__esModule", ({ value: true }));
3309 +exports.evaluateVersions = exports.isExplicitVersion = exports.findFromManifest = exports.getManifestFromRepo = exports.findAllVersions = exports.find = exports.cacheFile = exports.cacheDir = exports.extractZip = exports.extractXar = exports.extractTar = exports.extract7z = exports.downloadTool = exports.HTTPError = void 0;
3310 +const core = __importStar(__nccwpck_require__(2186));
3311 +const io = __importStar(__nccwpck_require__(7436));
3312 +const fs = __importStar(__nccwpck_require__(7147));
3313 +const mm = __importStar(__nccwpck_require__(2473));
3314 +const os = __importStar(__nccwpck_require__(2037));
3315 +const path = __importStar(__nccwpck_require__(1017));
3316 +const httpm = __importStar(__nccwpck_require__(6255));
3317 +const semver = __importStar(__nccwpck_require__(562));
3318 +const stream = __importStar(__nccwpck_require__(2781));
3319 +const util = __importStar(__nccwpck_require__(3837));
3320 +const assert_1 = __nccwpck_require__(9491);
3321 +const v4_1 = __importDefault(__nccwpck_require__(7468));
3322 +const exec_1 = __nccwpck_require__(1514);
3323 +const retry_helper_1 = __nccwpck_require__(8279);
3324 +class HTTPError extends Error {
3325 + constructor(httpStatusCode) {
3326 + super(`Unexpected HTTP response: ${httpStatusCode}`);
3327 + this.httpStatusCode = httpStatusCode;
3328 + Object.setPrototypeOf(this, new.target.prototype);
3329 + }
3330 +}
3331 +exports.HTTPError = HTTPError;
3332 +const IS_WINDOWS = process.platform === 'win32';
3333 +const IS_MAC = process.platform === 'darwin';
3334 +const userAgent = 'actions/tool-cache';
3335 +/**
3336 + * Download a tool from an url and stream it into a file
3337 + *
3338 + * @param url url of tool to download
3339 + * @param dest path to download tool
3340 + * @param auth authorization header
3341 + * @param headers other headers
3342 + * @returns path to downloaded tool
3343 + */
3344 +function downloadTool(url, dest, auth, headers) {
3345 + return __awaiter(this, void 0, void 0, function* () {
3346 + dest = dest || path.join(_getTempDirectory(), v4_1.default());
3347 + yield io.mkdirP(path.dirname(dest));
3348 + core.debug(`Downloading ${url}`);
3349 + core.debug(`Destination ${dest}`);
3350 + const maxAttempts = 3;
3351 + const minSeconds = _getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS', 10);
3352 + const maxSeconds = _getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS', 20);
3353 + const retryHelper = new retry_helper_1.RetryHelper(maxAttempts, minSeconds, maxSeconds);
3354 + return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
3355 + return yield downloadToolAttempt(url, dest || '', auth, headers);
3356 + }), (err) => {
3357 + if (err instanceof HTTPError && err.httpStatusCode) {
3358 + // Don't retry anything less than 500, except 408 Request Timeout and 429 Too Many Requests
3359 + if (err.httpStatusCode < 500 &&
3360 + err.httpStatusCode !== 408 &&
3361 + err.httpStatusCode !== 429) {
3362 + return false;
3363 + }
3364 + }
3365 + // Otherwise retry
3366 + return true;
3367 + });
3368 + });
3369 +}
3370 +exports.downloadTool = downloadTool;
3371 +function downloadToolAttempt(url, dest, auth, headers) {
3372 + return __awaiter(this, void 0, void 0, function* () {
3373 + if (fs.existsSync(dest)) {
3374 + throw new Error(`Destination file path ${dest} already exists`);
3375 + }
3376 + // Get the response headers
3377 + const http = new httpm.HttpClient(userAgent, [], {
3378 + allowRetries: false
3379 + });
3380 + if (auth) {
3381 + core.debug('set auth');
3382 + if (headers === undefined) {
3383 + headers = {};
3384 + }
3385 + headers.authorization = auth;
3386 + }
3387 + const response = yield http.get(url, headers);
3388 + if (response.message.statusCode !== 200) {
3389 + const err = new HTTPError(response.message.statusCode);
3390 + core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
3391 + throw err;
3392 + }
3393 + // Download the response body
3394 + const pipeline = util.promisify(stream.pipeline);
3395 + const responseMessageFactory = _getGlobal('TEST_DOWNLOAD_TOOL_RESPONSE_MESSAGE_FACTORY', () => response.message);
3396 + const readStream = responseMessageFactory();
3397 + let succeeded = false;
3398 + try {
3399 + yield pipeline(readStream, fs.createWriteStream(dest));
3400 + core.debug('download complete');
3401 + succeeded = true;
3402 + return dest;
3403 + }
3404 + finally {
3405 + // Error, delete dest before retry
3406 + if (!succeeded) {
3407 + core.debug('download failed');
3408 + try {
3409 + yield io.rmRF(dest);
3410 + }
3411 + catch (err) {
3412 + core.debug(`Failed to delete '${dest}'. ${err.message}`);
3413 + }
3414 + }
3415 + }
3416 + });
3417 +}
3418 +/**
3419 + * Extract a .7z file
3420 + *
3421 + * @param file path to the .7z file
3422 + * @param dest destination directory. Optional.
3423 + * @param _7zPath path to 7zr.exe. Optional, for long path support. Most .7z archives do not have this
3424 + * problem. If your .7z archive contains very long paths, you can pass the path to 7zr.exe which will
3425 + * gracefully handle long paths. By default 7zdec.exe is used because it is a very small program and is
3426 + * bundled with the tool lib. However it does not support long paths. 7zr.exe is the reduced command line
3427 + * interface, it is smaller than the full command line interface, and it does support long paths. At the
3428 + * time of this writing, it is freely available from the LZMA SDK that is available on the 7zip website.
3429 + * Be sure to check the current license agreement. If 7zr.exe is bundled with your action, then the path
3430 + * to 7zr.exe can be pass to this function.
3431 + * @returns path to the destination directory
3432 + */
3433 +function extract7z(file, dest, _7zPath) {
3434 + return __awaiter(this, void 0, void 0, function* () {
3435 + assert_1.ok(IS_WINDOWS, 'extract7z() not supported on current OS');
3436 + assert_1.ok(file, 'parameter "file" is required');
3437 + dest = yield _createExtractFolder(dest);
3438 + const originalCwd = process.cwd();
3439 + process.chdir(dest);
3440 + if (_7zPath) {
3441 + try {
3442 + const logLevel = core.isDebug() ? '-bb1' : '-bb0';
3443 + const args = [
3444 + 'x',
3445 + logLevel,
3446 + '-bd',
3447 + '-sccUTF-8',
3448 + file
3449 + ];
3450 + const options = {
3451 + silent: true
3452 + };
3453 + yield exec_1.exec(`"${_7zPath}"`, args, options);
3454 + }
3455 + finally {
3456 + process.chdir(originalCwd);
3457 + }
3458 + }
3459 + else {
3460 + const escapedScript = path
3461 + .join(__dirname, '..', 'scripts', 'Invoke-7zdec.ps1')
3462 + .replace(/'/g, "''")
3463 + .replace(/"|\n|\r/g, ''); // double-up single quotes, remove double quotes and newlines
3464 + const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, '');
3465 + const escapedTarget = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '');
3466 + const command = `& '${escapedScript}' -Source '${escapedFile}' -Target '${escapedTarget}'`;
3467 + const args = [
3468 + '-NoLogo',
3469 + '-Sta',
3470 + '-NoProfile',
3471 + '-NonInteractive',
3472 + '-ExecutionPolicy',
3473 + 'Unrestricted',
3474 + '-Command',
3475 + command
3476 + ];
3477 + const options = {
3478 + silent: true
3479 + };
3480 + try {
3481 + const powershellPath = yield io.which('powershell', true);
3482 + yield exec_1.exec(`"${powershellPath}"`, args, options);
3483 + }
3484 + finally {
3485 + process.chdir(originalCwd);
3486 + }
3487 + }
3488 + return dest;
3489 + });
3490 +}
3491 +exports.extract7z = extract7z;
3492 +/**
3493 + * Extract a compressed tar archive
3494 + *
3495 + * @param file path to the tar
3496 + * @param dest destination directory. Optional.
3497 + * @param flags flags for the tar command to use for extraction. Defaults to 'xz' (extracting gzipped tars). Optional.
3498 + * @returns path to the destination directory
3499 + */
3500 +function extractTar(file, dest, flags = 'xz') {
3501 + return __awaiter(this, void 0, void 0, function* () {
3502 + if (!file) {
3503 + throw new Error("parameter 'file' is required");
3504 + }
3505 + // Create dest
3506 + dest = yield _createExtractFolder(dest);
3507 + // Determine whether GNU tar
3508 + core.debug('Checking tar --version');
3509 + let versionOutput = '';
3510 + yield exec_1.exec('tar --version', [], {
3511 + ignoreReturnCode: true,
3512 + silent: true,
3513 + listeners: {
3514 + stdout: (data) => (versionOutput += data.toString()),
3515 + stderr: (data) => (versionOutput += data.toString())
3516 + }
3517 + });
3518 + core.debug(versionOutput.trim());
3519 + const isGnuTar = versionOutput.toUpperCase().includes('GNU TAR');
3520 + // Initialize args
3521 + let args;
3522 + if (flags instanceof Array) {
3523 + args = flags;
3524 + }
3525 + else {
3526 + args = [flags];
3527 + }
3528 + if (core.isDebug() && !flags.includes('v')) {
3529 + args.push('-v');
3530 + }
3531 + let destArg = dest;
3532 + let fileArg = file;
3533 + if (IS_WINDOWS && isGnuTar) {
3534 + args.push('--force-local');
3535 + destArg = dest.replace(/\\/g, '/');
3536 + // Technically only the dest needs to have `/` but for aesthetic consistency
3537 + // convert slashes in the file arg too.
3538 + fileArg = file.replace(/\\/g, '/');
3539 + }
3540 + if (isGnuTar) {
3541 + // Suppress warnings when using GNU tar to extract archives created by BSD tar
3542 + args.push('--warning=no-unknown-keyword');
3543 + args.push('--overwrite');
3544 + }
3545 + args.push('-C', destArg, '-f', fileArg);
3546 + yield exec_1.exec(`tar`, args);
3547 + return dest;
3548 + });
3549 +}
3550 +exports.extractTar = extractTar;
3551 +/**
3552 + * Extract a xar compatible archive
3553 + *
3554 + * @param file path to the archive
3555 + * @param dest destination directory. Optional.
3556 + * @param flags flags for the xar. Optional.
3557 + * @returns path to the destination directory
3558 + */
3559 +function extractXar(file, dest, flags = []) {
3560 + return __awaiter(this, void 0, void 0, function* () {
3561 + assert_1.ok(IS_MAC, 'extractXar() not supported on current OS');
3562 + assert_1.ok(file, 'parameter "file" is required');
3563 + dest = yield _createExtractFolder(dest);
3564 + let args;
3565 + if (flags instanceof Array) {
3566 + args = flags;
3567 + }
3568 + else {
3569 + args = [flags];
3570 + }
3571 + args.push('-x', '-C', dest, '-f', file);
3572 + if (core.isDebug()) {
3573 + args.push('-v');
3574 + }
3575 + const xarPath = yield io.which('xar', true);
3576 + yield exec_1.exec(`"${xarPath}"`, _unique(args));
3577 + return dest;
3578 + });
3579 +}
3580 +exports.extractXar = extractXar;
3581 +/**
3582 + * Extract a zip
3583 + *
3584 + * @param file path to the zip
3585 + * @param dest destination directory. Optional.
3586 + * @returns path to the destination directory
3587 + */
3588 +function extractZip(file, dest) {
3589 + return __awaiter(this, void 0, void 0, function* () {
3590 + if (!file) {
3591 + throw new Error("parameter 'file' is required");
3592 + }
3593 + dest = yield _createExtractFolder(dest);
3594 + if (IS_WINDOWS) {
3595 + yield extractZipWin(file, dest);
3596 + }
3597 + else {
3598 + yield extractZipNix(file, dest);
3599 + }
3600 + return dest;
3601 + });
3602 +}
3603 +exports.extractZip = extractZip;
3604 +function extractZipWin(file, dest) {
3605 + return __awaiter(this, void 0, void 0, function* () {
3606 + // build the powershell command
3607 + const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, ''); // double-up single quotes, remove double quotes and newlines
3608 + const escapedDest = dest.replace(/'/g, "''").replace(/"|\n|\r/g, '');
3609 + const pwshPath = yield io.which('pwsh', false);
3610 + //To match the file overwrite behavior on nix systems, we use the overwrite = true flag for ExtractToDirectory
3611 + //and the -Force flag for Expand-Archive as a fallback
3612 + if (pwshPath) {
3613 + //attempt to use pwsh with ExtractToDirectory, if this fails attempt Expand-Archive
3614 + const pwshCommand = [
3615 + `$ErrorActionPreference = 'Stop' ;`,
3616 + `try { Add-Type -AssemblyName System.IO.Compression.ZipFile } catch { } ;`,
3617 + `try { [System.IO.Compression.ZipFile]::ExtractToDirectory('${escapedFile}', '${escapedDest}', $true) }`,
3618 + `catch { if (($_.Exception.GetType().FullName -eq 'System.Management.Automation.MethodException') -or ($_.Exception.GetType().FullName -eq 'System.Management.Automation.RuntimeException') ){ Expand-Archive -LiteralPath '${escapedFile}' -DestinationPath '${escapedDest}' -Force } else { throw $_ } } ;`
3619 + ].join(' ');
3620 + const args = [
3621 + '-NoLogo',
3622 + '-NoProfile',
3623 + '-NonInteractive',
3624 + '-ExecutionPolicy',
3625 + 'Unrestricted',
3626 + '-Command',
3627 + pwshCommand
3628 + ];
3629 + core.debug(`Using pwsh at path: ${pwshPath}`);
3630 + yield exec_1.exec(`"${pwshPath}"`, args);
3631 + }
3632 + else {
3633 + const powershellCommand = [
3634 + `$ErrorActionPreference = 'Stop' ;`,
3635 + `try { Add-Type -AssemblyName System.IO.Compression.FileSystem } catch { } ;`,
3636 + `if ((Get-Command -Name Expand-Archive -Module Microsoft.PowerShell.Archive -ErrorAction Ignore)) { Expand-Archive -LiteralPath '${escapedFile}' -DestinationPath '${escapedDest}' -Force }`,
3637 + `else {[System.IO.Compression.ZipFile]::ExtractToDirectory('${escapedFile}', '${escapedDest}', $true) }`
3638 + ].join(' ');
3639 + const args = [
3640 + '-NoLogo',
3641 + '-Sta',
3642 + '-NoProfile',
3643 + '-NonInteractive',
3644 + '-ExecutionPolicy',
3645 + 'Unrestricted',
3646 + '-Command',
3647 + powershellCommand
3648 + ];
3649 + const powershellPath = yield io.which('powershell', true);
3650 + core.debug(`Using powershell at path: ${powershellPath}`);
3651 + yield exec_1.exec(`"${powershellPath}"`, args);
3652 + }
3653 + });
3654 +}
3655 +function extractZipNix(file, dest) {
3656 + return __awaiter(this, void 0, void 0, function* () {
3657 + const unzipPath = yield io.which('unzip', true);
3658 + const args = [file];
3659 + if (!core.isDebug()) {
3660 + args.unshift('-q');
3661 + }
3662 + args.unshift('-o'); //overwrite with -o, otherwise a prompt is shown which freezes the run
3663 + yield exec_1.exec(`"${unzipPath}"`, args, { cwd: dest });
3664 + });
3665 +}
3666 +/**
3667 + * Caches a directory and installs it into the tool cacheDir
3668 + *
3669 + * @param sourceDir the directory to cache into tools
3670 + * @param tool tool name
3671 + * @param version version of the tool. semver format
3672 + * @param arch architecture of the tool. Optional. Defaults to machine architecture
3673 + */
3674 +function cacheDir(sourceDir, tool, version, arch) {
3675 + return __awaiter(this, void 0, void 0, function* () {
3676 + version = semver.clean(version) || version;
3677 + arch = arch || os.arch();
3678 + core.debug(`Caching tool ${tool} ${version} ${arch}`);
3679 + core.debug(`source dir: ${sourceDir}`);
3680 + if (!fs.statSync(sourceDir).isDirectory()) {
3681 + throw new Error('sourceDir is not a directory');
3682 + }
3683 + // Create the tool dir
3684 + const destPath = yield _createToolPath(tool, version, arch);
3685 + // copy each child item. do not move. move can fail on Windows
3686 + // due to anti-virus software having an open handle on a file.
3687 + for (const itemName of fs.readdirSync(sourceDir)) {
3688 + const s = path.join(sourceDir, itemName);
3689 + yield io.cp(s, destPath, { recursive: true });
3690 + }
3691 + // write .complete
3692 + _completeToolPath(tool, version, arch);
3693 + return destPath;
3694 + });
3695 +}
3696 +exports.cacheDir = cacheDir;
3697 +/**
3698 + * Caches a downloaded file (GUID) and installs it
3699 + * into the tool cache with a given targetName
3700 + *
3701 + * @param sourceFile the file to cache into tools. Typically a result of downloadTool which is a guid.
3702 + * @param targetFile the name of the file name in the tools directory
3703 + * @param tool tool name
3704 + * @param version version of the tool. semver format
3705 + * @param arch architecture of the tool. Optional. Defaults to machine architecture
3706 + */
3707 +function cacheFile(sourceFile, targetFile, tool, version, arch) {
3708 + return __awaiter(this, void 0, void 0, function* () {
3709 + version = semver.clean(version) || version;
3710 + arch = arch || os.arch();
3711 + core.debug(`Caching tool ${tool} ${version} ${arch}`);
3712 + core.debug(`source file: ${sourceFile}`);
3713 + if (!fs.statSync(sourceFile).isFile()) {
3714 + throw new Error('sourceFile is not a file');
3715 + }
3716 + // create the tool dir
3717 + const destFolder = yield _createToolPath(tool, version, arch);
3718 + // copy instead of move. move can fail on Windows due to
3719 + // anti-virus software having an open handle on a file.
3720 + const destPath = path.join(destFolder, targetFile);
3721 + core.debug(`destination file ${destPath}`);
3722 + yield io.cp(sourceFile, destPath);
3723 + // write .complete
3724 + _completeToolPath(tool, version, arch);
3725 + return destFolder;
3726 + });
3727 +}
3728 +exports.cacheFile = cacheFile;
3729 +/**
3730 + * Finds the path to a tool version in the local installed tool cache
3731 + *
3732 + * @param toolName name of the tool
3733 + * @param versionSpec version of the tool
3734 + * @param arch optional arch. defaults to arch of computer
3735 + */
3736 +function find(toolName, versionSpec, arch) {
3737 + if (!toolName) {
3738 + throw new Error('toolName parameter is required');
3739 + }
3740 + if (!versionSpec) {
3741 + throw new Error('versionSpec parameter is required');
3742 + }
3743 + arch = arch || os.arch();
3744 + // attempt to resolve an explicit version
3745 + if (!isExplicitVersion(versionSpec)) {
3746 + const localVersions = findAllVersions(toolName, arch);
3747 + const match = evaluateVersions(localVersions, versionSpec);
3748 + versionSpec = match;
3749 + }
3750 + // check for the explicit version in the cache
3751 + let toolPath = '';
3752 + if (versionSpec) {
3753 + versionSpec = semver.clean(versionSpec) || '';
3754 + const cachePath = path.join(_getCacheDirectory(), toolName, versionSpec, arch);
3755 + core.debug(`checking cache: ${cachePath}`);
3756 + if (fs.existsSync(cachePath) && fs.existsSync(`${cachePath}.complete`)) {
3757 + core.debug(`Found tool in cache ${toolName} ${versionSpec} ${arch}`);
3758 + toolPath = cachePath;
3759 + }
3760 + else {
3761 + core.debug('not found');
3762 + }
3763 + }
3764 + return toolPath;
3765 +}
3766 +exports.find = find;
3767 +/**
3768 + * Finds the paths to all versions of a tool that are installed in the local tool cache
3769 + *
3770 + * @param toolName name of the tool
3771 + * @param arch optional arch. defaults to arch of computer
3772 + */
3773 +function findAllVersions(toolName, arch) {
3774 + const versions = [];
3775 + arch = arch || os.arch();
3776 + const toolPath = path.join(_getCacheDirectory(), toolName);
3777 + if (fs.existsSync(toolPath)) {
3778 + const children = fs.readdirSync(toolPath);
3779 + for (const child of children) {
3780 + if (isExplicitVersion(child)) {
3781 + const fullPath = path.join(toolPath, child, arch || '');
3782 + if (fs.existsSync(fullPath) && fs.existsSync(`${fullPath}.complete`)) {
3783 + versions.push(child);
3784 + }
3785 + }
3786 + }
3787 + }
3788 + return versions;
3789 +}
3790 +exports.findAllVersions = findAllVersions;
3791 +function getManifestFromRepo(owner, repo, auth, branch = 'master') {
3792 + return __awaiter(this, void 0, void 0, function* () {
3793 + let releases = [];
3794 + const treeUrl = `https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}`;
3795 + const http = new httpm.HttpClient('tool-cache');
3796 + const headers = {};
3797 + if (auth) {
3798 + core.debug('set auth');
3799 + headers.authorization = auth;
3800 + }
3801 + const response = yield http.getJson(treeUrl, headers);
3802 + if (!response.result) {
3803 + return releases;
3804 + }
3805 + let manifestUrl = '';
3806 + for (const item of response.result.tree) {
3807 + if (item.path === 'versions-manifest.json') {
3808 + manifestUrl = item.url;
3809 + break;
3810 + }
3811 + }
3812 + headers['accept'] = 'application/vnd.github.VERSION.raw';
3813 + let versionsRaw = yield (yield http.get(manifestUrl, headers)).readBody();
3814 + if (versionsRaw) {
3815 + // shouldn't be needed but protects against invalid json saved with BOM
3816 + versionsRaw = versionsRaw.replace(/^\uFEFF/, '');
3817 + try {
3818 + releases = JSON.parse(versionsRaw);
3819 + }
3820 + catch (_a) {
3821 + core.debug('Invalid json');
3822 + }
3823 + }
3824 + return releases;
3825 + });
3826 +}
3827 +exports.getManifestFromRepo = getManifestFromRepo;
3828 +function findFromManifest(versionSpec, stable, manifest, archFilter = os.arch()) {
3829 + return __awaiter(this, void 0, void 0, function* () {
3830 + // wrap the internal impl
3831 + const match = yield mm._findMatch(versionSpec, stable, manifest, archFilter);
3832 + return match;
3833 + });
3834 +}
3835 +exports.findFromManifest = findFromManifest;
3836 +function _createExtractFolder(dest) {
3837 + return __awaiter(this, void 0, void 0, function* () {
3838 + if (!dest) {
3839 + // create a temp dir
3840 + dest = path.join(_getTempDirectory(), v4_1.default());
3841 + }
3842 + yield io.mkdirP(dest);
3843 + return dest;
3844 + });
3845 +}
3846 +function _createToolPath(tool, version, arch) {
3847 + return __awaiter(this, void 0, void 0, function* () {
3848 + const folderPath = path.join(_getCacheDirectory(), tool, semver.clean(version) || version, arch || '');
3849 + core.debug(`destination ${folderPath}`);
3850 + const markerPath = `${folderPath}.complete`;
3851 + yield io.rmRF(folderPath);
3852 + yield io.rmRF(markerPath);
3853 + yield io.mkdirP(folderPath);
3854 + return folderPath;
3855 + });
3856 +}
3857 +function _completeToolPath(tool, version, arch) {
3858 + const folderPath = path.join(_getCacheDirectory(), tool, semver.clean(version) || version, arch || '');
3859 + const markerPath = `${folderPath}.complete`;
3860 + fs.writeFileSync(markerPath, '');
3861 + core.debug('finished caching tool');
3862 +}
3863 +/**
3864 + * Check if version string is explicit
3865 + *
3866 + * @param versionSpec version string to check
3867 + */
3868 +function isExplicitVersion(versionSpec) {
3869 + const c = semver.clean(versionSpec) || '';
3870 + core.debug(`isExplicit: ${c}`);
3871 + const valid = semver.valid(c) != null;
3872 + core.debug(`explicit? ${valid}`);
3873 + return valid;
3874 +}
3875 +exports.isExplicitVersion = isExplicitVersion;
3876 +/**
3877 + * Get the highest satisfiying semantic version in `versions` which satisfies `versionSpec`
3878 + *
3879 + * @param versions array of versions to evaluate
3880 + * @param versionSpec semantic version spec to satisfy
3881 + */
3882 +function evaluateVersions(versions, versionSpec) {
3883 + let version = '';
3884 + core.debug(`evaluating ${versions.length} versions`);
3885 + versions = versions.sort((a, b) => {
3886 + if (semver.gt(a, b)) {
3887 + return 1;
3888 + }
3889 + return -1;
3890 + });
3891 + for (let i = versions.length - 1; i >= 0; i--) {
3892 + const potential = versions[i];
3893 + const satisfied = semver.satisfies(potential, versionSpec);
3894 + if (satisfied) {
3895 + version = potential;
3896 + break;
3897 + }
3898 + }
3899 + if (version) {
3900 + core.debug(`matched: ${version}`);
3901 + }
3902 + else {
3903 + core.debug('match not found');
3904 + }
3905 + return version;
3906 +}
3907 +exports.evaluateVersions = evaluateVersions;
3908 +/**
3909 + * Gets RUNNER_TOOL_CACHE
3910 + */
3911 +function _getCacheDirectory() {
3912 + const cacheDirectory = process.env['RUNNER_TOOL_CACHE'] || '';
3913 + assert_1.ok(cacheDirectory, 'Expected RUNNER_TOOL_CACHE to be defined');
3914 + return cacheDirectory;
3915 +}
3916 +/**
3917 + * Gets RUNNER_TEMP
3918 + */
3919 +function _getTempDirectory() {
3920 + const tempDirectory = process.env['RUNNER_TEMP'] || '';
3921 + assert_1.ok(tempDirectory, 'Expected RUNNER_TEMP to be defined');
3922 + return tempDirectory;
3923 +}
3924 +/**
3925 + * Gets a global variable
3926 + */
3927 +function _getGlobal(key, defaultValue) {
3928 + /* eslint-disable @typescript-eslint/no-explicit-any */
3929 + const value = global[key];
3930 + /* eslint-enable @typescript-eslint/no-explicit-any */
3931 + return value !== undefined ? value : defaultValue;
3932 +}
3933 +/**
3934 + * Returns an array of unique values.
3935 + * @param values Values to make unique.
3936 + */
3937 +function _unique(values) {
3938 + return Array.from(new Set(values));
3939 +}
3940 +//# sourceMappingURL=tool-cache.js.map
3941 +
3942 +/***/ }),
3943 +
3944 +/***/ 562:
3945 +/***/ ((module, exports) => {
3946 +
3947 +exports = module.exports = SemVer
3948 +
3949 +var debug
3950 +/* istanbul ignore next */
3951 +if (typeof process === 'object' &&
3952 + process.env &&
3953 + process.env.NODE_DEBUG &&
3954 + /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
3955 + debug = function () {
3956 + var args = Array.prototype.slice.call(arguments, 0)
3957 + args.unshift('SEMVER')
3958 + console.log.apply(console, args)
3959 + }
3960 +} else {
3961 + debug = function () {}
3962 +}
3963 +
3964 +// Note: this is the semver.org version of the spec that it implements
3965 +// Not necessarily the package version of this code.
3966 +exports.SEMVER_SPEC_VERSION = '2.0.0'
3967 +
3968 +var MAX_LENGTH = 256
3969 +var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
3970 + /* istanbul ignore next */ 9007199254740991
3971 +
3972 +// Max safe segment length for coercion.
3973 +var MAX_SAFE_COMPONENT_LENGTH = 16
3974 +
3975 +// The actual regexps go on exports.re
3976 +var re = exports.re = []
3977 +var src = exports.src = []
3978 +var t = exports.tokens = {}
3979 +var R = 0
3980 +
3981 +function tok (n) {
3982 + t[n] = R++
3983 +}
3984 +
3985 +// The following Regular Expressions can be used for tokenizing,
3986 +// validating, and parsing SemVer version strings.
3987 +
3988 +// ## Numeric Identifier
3989 +// A single `0`, or a non-zero digit followed by zero or more digits.
3990 +
3991 +tok('NUMERICIDENTIFIER')
3992 +src[t.NUMERICIDENTIFIER] = '0|[1-9]\\d*'
3993 +tok('NUMERICIDENTIFIERLOOSE')
3994 +src[t.NUMERICIDENTIFIERLOOSE] = '[0-9]+'
3995 +
3996 +// ## Non-numeric Identifier
3997 +// Zero or more digits, followed by a letter or hyphen, and then zero or
3998 +// more letters, digits, or hyphens.
3999 +
4000 +tok('NONNUMERICIDENTIFIER')
4001 +src[t.NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'
4002 +
4003 +// ## Main Version
4004 +// Three dot-separated numeric identifiers.
4005 +
4006 +tok('MAINVERSION')
4007 +src[t.MAINVERSION] = '(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
4008 + '(' + src[t.NUMERICIDENTIFIER] + ')\\.' +
4009 + '(' + src[t.NUMERICIDENTIFIER] + ')'
4010 +
4011 +tok('MAINVERSIONLOOSE')
4012 +src[t.MAINVERSIONLOOSE] = '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
4013 + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')\\.' +
4014 + '(' + src[t.NUMERICIDENTIFIERLOOSE] + ')'
4015 +
4016 +// ## Pre-release Version Identifier
4017 +// A numeric identifier, or a non-numeric identifier.
4018 +
4019 +tok('PRERELEASEIDENTIFIER')
4020 +src[t.PRERELEASEIDENTIFIER] = '(?:' + src[t.NUMERICIDENTIFIER] +
4021 + '|' + src[t.NONNUMERICIDENTIFIER] + ')'
4022 +
4023 +tok('PRERELEASEIDENTIFIERLOOSE')
4024 +src[t.PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[t.NUMERICIDENTIFIERLOOSE] +
4025 + '|' + src[t.NONNUMERICIDENTIFIER] + ')'
4026 +
4027 +// ## Pre-release Version
4028 +// Hyphen, followed by one or more dot-separated pre-release version
4029 +// identifiers.
4030 +
4031 +tok('PRERELEASE')
4032 +src[t.PRERELEASE] = '(?:-(' + src[t.PRERELEASEIDENTIFIER] +
4033 + '(?:\\.' + src[t.PRERELEASEIDENTIFIER] + ')*))'
4034 +
4035 +tok('PRERELEASELOOSE')
4036 +src[t.PRERELEASELOOSE] = '(?:-?(' + src[t.PRERELEASEIDENTIFIERLOOSE] +
4037 + '(?:\\.' + src[t.PRERELEASEIDENTIFIERLOOSE] + ')*))'
4038 +
4039 +// ## Build Metadata Identifier
4040 +// Any combination of digits, letters, or hyphens.
4041 +
4042 +tok('BUILDIDENTIFIER')
4043 +src[t.BUILDIDENTIFIER] = '[0-9A-Za-z-]+'
4044 +
4045 +// ## Build Metadata
4046 +// Plus sign, followed by one or more period-separated build metadata
4047 +// identifiers.
4048 +
4049 +tok('BUILD')
4050 +src[t.BUILD] = '(?:\\+(' + src[t.BUILDIDENTIFIER] +
4051 + '(?:\\.' + src[t.BUILDIDENTIFIER] + ')*))'
4052 +
4053 +// ## Full Version String
4054 +// A main version, followed optionally by a pre-release version and
4055 +// build metadata.
4056 +
4057 +// Note that the only major, minor, patch, and pre-release sections of
4058 +// the version string are capturing groups. The build metadata is not a
4059 +// capturing group, because it should not ever be used in version
4060 +// comparison.
4061 +
4062 +tok('FULL')
4063 +tok('FULLPLAIN')
4064 +src[t.FULLPLAIN] = 'v?' + src[t.MAINVERSION] +
4065 + src[t.PRERELEASE] + '?' +
4066 + src[t.BUILD] + '?'
4067 +
4068 +src[t.FULL] = '^' + src[t.FULLPLAIN] + '$'
4069 +
4070 +// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
4071 +// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
4072 +// common in the npm registry.
4073 +tok('LOOSEPLAIN')
4074 +src[t.LOOSEPLAIN] = '[v=\\s]*' + src[t.MAINVERSIONLOOSE] +
4075 + src[t.PRERELEASELOOSE] + '?' +
4076 + src[t.BUILD] + '?'
4077 +
4078 +tok('LOOSE')
4079 +src[t.LOOSE] = '^' + src[t.LOOSEPLAIN] + '$'
4080 +
4081 +tok('GTLT')
4082 +src[t.GTLT] = '((?:<|>)?=?)'
4083 +
4084 +// Something like "2.*" or "1.2.x".
4085 +// Note that "x.x" is a valid xRange identifer, meaning "any version"
4086 +// Only the first item is strictly required.
4087 +tok('XRANGEIDENTIFIERLOOSE')
4088 +src[t.XRANGEIDENTIFIERLOOSE] = src[t.NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'
4089 +tok('XRANGEIDENTIFIER')
4090 +src[t.XRANGEIDENTIFIER] = src[t.NUMERICIDENTIFIER] + '|x|X|\\*'
4091 +
4092 +tok('XRANGEPLAIN')
4093 +src[t.XRANGEPLAIN] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIER] + ')' +
4094 + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
4095 + '(?:\\.(' + src[t.XRANGEIDENTIFIER] + ')' +
4096 + '(?:' + src[t.PRERELEASE] + ')?' +
4097 + src[t.BUILD] + '?' +
4098 + ')?)?'
4099 +
4100 +tok('XRANGEPLAINLOOSE')
4101 +src[t.XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
4102 + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
4103 + '(?:\\.(' + src[t.XRANGEIDENTIFIERLOOSE] + ')' +
4104 + '(?:' + src[t.PRERELEASELOOSE] + ')?' +
4105 + src[t.BUILD] + '?' +
4106 + ')?)?'
4107 +
4108 +tok('XRANGE')
4109 +src[t.XRANGE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAIN] + '$'
4110 +tok('XRANGELOOSE')
4111 +src[t.XRANGELOOSE] = '^' + src[t.GTLT] + '\\s*' + src[t.XRANGEPLAINLOOSE] + '$'
4112 +
4113 +// Coercion.
4114 +// Extract anything that could conceivably be a part of a valid semver
4115 +tok('COERCE')
4116 +src[t.COERCE] = '(^|[^\\d])' +
4117 + '(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '})' +
4118 + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
4119 + '(?:\\.(\\d{1,' + MAX_SAFE_COMPONENT_LENGTH + '}))?' +
4120 + '(?:$|[^\\d])'
4121 +tok('COERCERTL')
4122 +re[t.COERCERTL] = new RegExp(src[t.COERCE], 'g')
4123 +
4124 +// Tilde ranges.
4125 +// Meaning is "reasonably at or greater than"
4126 +tok('LONETILDE')
4127 +src[t.LONETILDE] = '(?:~>?)'
4128 +
4129 +tok('TILDETRIM')
4130 +src[t.TILDETRIM] = '(\\s*)' + src[t.LONETILDE] + '\\s+'
4131 +re[t.TILDETRIM] = new RegExp(src[t.TILDETRIM], 'g')
4132 +var tildeTrimReplace = '$1~'
4133 +
4134 +tok('TILDE')
4135 +src[t.TILDE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAIN] + '$'
4136 +tok('TILDELOOSE')
4137 +src[t.TILDELOOSE] = '^' + src[t.LONETILDE] + src[t.XRANGEPLAINLOOSE] + '$'
4138 +
4139 +// Caret ranges.
4140 +// Meaning is "at least and backwards compatible with"
4141 +tok('LONECARET')
4142 +src[t.LONECARET] = '(?:\\^)'
4143 +
4144 +tok('CARETTRIM')
4145 +src[t.CARETTRIM] = '(\\s*)' + src[t.LONECARET] + '\\s+'
4146 +re[t.CARETTRIM] = new RegExp(src[t.CARETTRIM], 'g')
4147 +var caretTrimReplace = '$1^'
4148 +
4149 +tok('CARET')
4150 +src[t.CARET] = '^' + src[t.LONECARET] + src[t.XRANGEPLAIN] + '$'
4151 +tok('CARETLOOSE')
4152 +src[t.CARETLOOSE] = '^' + src[t.LONECARET] + src[t.XRANGEPLAINLOOSE] + '$'
4153 +
4154 +// A simple gt/lt/eq thing, or just "" to indicate "any version"
4155 +tok('COMPARATORLOOSE')
4156 +src[t.COMPARATORLOOSE] = '^' + src[t.GTLT] + '\\s*(' + src[t.LOOSEPLAIN] + ')$|^$'
4157 +tok('COMPARATOR')
4158 +src[t.COMPARATOR] = '^' + src[t.GTLT] + '\\s*(' + src[t.FULLPLAIN] + ')$|^$'
4159 +
4160 +// An expression to strip any whitespace between the gtlt and the thing
4161 +// it modifies, so that `> 1.2.3` ==> `>1.2.3`
4162 +tok('COMPARATORTRIM')
4163 +src[t.COMPARATORTRIM] = '(\\s*)' + src[t.GTLT] +
4164 + '\\s*(' + src[t.LOOSEPLAIN] + '|' + src[t.XRANGEPLAIN] + ')'
4165 +
4166 +// this one has to use the /g flag
4167 +re[t.COMPARATORTRIM] = new RegExp(src[t.COMPARATORTRIM], 'g')
4168 +var comparatorTrimReplace = '$1$2$3'
4169 +
4170 +// Something like `1.2.3 - 1.2.4`
4171 +// Note that these all use the loose form, because they'll be
4172 +// checked against either the strict or loose comparator form
4173 +// later.
4174 +tok('HYPHENRANGE')
4175 +src[t.HYPHENRANGE] = '^\\s*(' + src[t.XRANGEPLAIN] + ')' +
4176 + '\\s+-\\s+' +
4177 + '(' + src[t.XRANGEPLAIN] + ')' +
4178 + '\\s*$'
4179 +
4180 +tok('HYPHENRANGELOOSE')
4181 +src[t.HYPHENRANGELOOSE] = '^\\s*(' + src[t.XRANGEPLAINLOOSE] + ')' +
4182 + '\\s+-\\s+' +
4183 + '(' + src[t.XRANGEPLAINLOOSE] + ')' +
4184 + '\\s*$'
4185 +
4186 +// Star ranges basically just allow anything at all.
4187 +tok('STAR')
4188 +src[t.STAR] = '(<|>)?=?\\s*\\*'
4189 +
4190 +// Compile to actual regexp objects.
4191 +// All are flag-free, unless they were created above with a flag.
4192 +for (var i = 0; i < R; i++) {
4193 + debug(i, src[i])
4194 + if (!re[i]) {
4195 + re[i] = new RegExp(src[i])
4196 + }
4197 +}
4198 +
4199 +exports.parse = parse
4200 +function parse (version, options) {
4201 + if (!options || typeof options !== 'object') {
4202 + options = {
4203 + loose: !!options,
4204 + includePrerelease: false
4205 + }
4206 + }
4207 +
4208 + if (version instanceof SemVer) {
4209 + return version
4210 + }
4211 +
4212 + if (typeof version !== 'string') {
4213 + return null
4214 + }
4215 +
4216 + if (version.length > MAX_LENGTH) {
4217 + return null
4218 + }
4219 +
4220 + var r = options.loose ? re[t.LOOSE] : re[t.FULL]
4221 + if (!r.test(version)) {
4222 + return null
4223 + }
4224 +
4225 + try {
4226 + return new SemVer(version, options)
4227 + } catch (er) {
4228 + return null
4229 + }
4230 +}
4231 +
4232 +exports.valid = valid
4233 +function valid (version, options) {
4234 + var v = parse(version, options)
4235 + return v ? v.version : null
4236 +}
4237 +
4238 +exports.clean = clean
4239 +function clean (version, options) {
4240 + var s = parse(version.trim().replace(/^[=v]+/, ''), options)
4241 + return s ? s.version : null
4242 +}
4243 +
4244 +exports.SemVer = SemVer
4245 +
4246 +function SemVer (version, options) {
4247 + if (!options || typeof options !== 'object') {
4248 + options = {
4249 + loose: !!options,
4250 + includePrerelease: false
4251 + }
4252 + }
4253 + if (version instanceof SemVer) {
4254 + if (version.loose === options.loose) {
4255 + return version
4256 + } else {
4257 + version = version.version
4258 + }
4259 + } else if (typeof version !== 'string') {
4260 + throw new TypeError('Invalid Version: ' + version)
4261 + }
4262 +
4263 + if (version.length > MAX_LENGTH) {
4264 + throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters')
4265 + }
4266 +
4267 + if (!(this instanceof SemVer)) {
4268 + return new SemVer(version, options)
4269 + }
4270 +
4271 + debug('SemVer', version, options)
4272 + this.options = options
4273 + this.loose = !!options.loose
4274 +
4275 + var m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL])
4276 +
4277 + if (!m) {
4278 + throw new TypeError('Invalid Version: ' + version)
4279 + }
4280 +
4281 + this.raw = version
4282 +
4283 + // these are actually numbers
4284 + this.major = +m[1]
4285 + this.minor = +m[2]
4286 + this.patch = +m[3]
4287 +
4288 + if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
4289 + throw new TypeError('Invalid major version')
4290 + }
4291 +
4292 + if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
4293 + throw new TypeError('Invalid minor version')
4294 + }
4295 +
4296 + if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
4297 + throw new TypeError('Invalid patch version')
4298 + }
4299 +
4300 + // numberify any prerelease numeric ids
4301 + if (!m[4]) {
4302 + this.prerelease = []
4303 + } else {
4304 + this.prerelease = m[4].split('.').map(function (id) {
4305 + if (/^[0-9]+$/.test(id)) {
4306 + var num = +id
4307 + if (num >= 0 && num < MAX_SAFE_INTEGER) {
4308 + return num
4309 + }
4310 + }
4311 + return id
4312 + })
4313 + }
4314 +
4315 + this.build = m[5] ? m[5].split('.') : []
4316 + this.format()
4317 +}
4318 +
4319 +SemVer.prototype.format = function () {
4320 + this.version = this.major + '.' + this.minor + '.' + this.patch
4321 + if (this.prerelease.length) {
4322 + this.version += '-' + this.prerelease.join('.')
4323 + }
4324 + return this.version
4325 +}
4326 +
4327 +SemVer.prototype.toString = function () {
4328 + return this.version
4329 +}
4330 +
4331 +SemVer.prototype.compare = function (other) {
4332 + debug('SemVer.compare', this.version, this.options, other)
4333 + if (!(other instanceof SemVer)) {
4334 + other = new SemVer(other, this.options)
4335 + }
4336 +
4337 + return this.compareMain(other) || this.comparePre(other)
4338 +}
4339 +
4340 +SemVer.prototype.compareMain = function (other) {
4341 + if (!(other instanceof SemVer)) {
4342 + other = new SemVer(other, this.options)
4343 + }
4344 +
4345 + return compareIdentifiers(this.major, other.major) ||
4346 + compareIdentifiers(this.minor, other.minor) ||
4347 + compareIdentifiers(this.patch, other.patch)
4348 +}
4349 +
4350 +SemVer.prototype.comparePre = function (other) {
4351 + if (!(other instanceof SemVer)) {
4352 + other = new SemVer(other, this.options)
4353 + }
4354 +
4355 + // NOT having a prerelease is > having one
4356 + if (this.prerelease.length && !other.prerelease.length) {
4357 + return -1
4358 + } else if (!this.prerelease.length && other.prerelease.length) {
4359 + return 1
4360 + } else if (!this.prerelease.length && !other.prerelease.length) {
4361 + return 0
4362 + }
4363 +
4364 + var i = 0
4365 + do {
4366 + var a = this.prerelease[i]
4367 + var b = other.prerelease[i]
4368 + debug('prerelease compare', i, a, b)
4369 + if (a === undefined && b === undefined) {
4370 + return 0
4371 + } else if (b === undefined) {
4372 + return 1
4373 + } else if (a === undefined) {
4374 + return -1
4375 + } else if (a === b) {
4376 + continue
4377 + } else {
4378 + return compareIdentifiers(a, b)
4379 + }
4380 + } while (++i)
4381 +}
4382 +
4383 +SemVer.prototype.compareBuild = function (other) {
4384 + if (!(other instanceof SemVer)) {
4385 + other = new SemVer(other, this.options)
4386 + }
4387 +
4388 + var i = 0
4389 + do {
4390 + var a = this.build[i]
4391 + var b = other.build[i]
4392 + debug('prerelease compare', i, a, b)
4393 + if (a === undefined && b === undefined) {
4394 + return 0
4395 + } else if (b === undefined) {
4396 + return 1
4397 + } else if (a === undefined) {
4398 + return -1
4399 + } else if (a === b) {
4400 + continue
4401 + } else {
4402 + return compareIdentifiers(a, b)
4403 + }
4404 + } while (++i)
4405 +}
4406 +
4407 +// preminor will bump the version up to the next minor release, and immediately
4408 +// down to pre-release. premajor and prepatch work the same way.
4409 +SemVer.prototype.inc = function (release, identifier) {
4410 + switch (release) {
4411 + case 'premajor':
4412 + this.prerelease.length = 0
4413 + this.patch = 0
4414 + this.minor = 0
4415 + this.major++
4416 + this.inc('pre', identifier)
4417 + break
4418 + case 'preminor':
4419 + this.prerelease.length = 0
4420 + this.patch = 0
4421 + this.minor++
4422 + this.inc('pre', identifier)
4423 + break
4424 + case 'prepatch':
4425 + // If this is already a prerelease, it will bump to the next version
4426 + // drop any prereleases that might already exist, since they are not
4427 + // relevant at this point.
4428 + this.prerelease.length = 0
4429 + this.inc('patch', identifier)
4430 + this.inc('pre', identifier)
4431 + break
4432 + // If the input is a non-prerelease version, this acts the same as
4433 + // prepatch.
4434 + case 'prerelease':
4435 + if (this.prerelease.length === 0) {
4436 + this.inc('patch', identifier)
4437 + }
4438 + this.inc('pre', identifier)
4439 + break
4440 +
4441 + case 'major':
4442 + // If this is a pre-major version, bump up to the same major version.
4443 + // Otherwise increment major.
4444 + // 1.0.0-5 bumps to 1.0.0
4445 + // 1.1.0 bumps to 2.0.0
4446 + if (this.minor !== 0 ||
4447 + this.patch !== 0 ||
4448 + this.prerelease.length === 0) {
4449 + this.major++
4450 + }
4451 + this.minor = 0
4452 + this.patch = 0
4453 + this.prerelease = []
4454 + break
4455 + case 'minor':
4456 + // If this is a pre-minor version, bump up to the same minor version.
4457 + // Otherwise increment minor.
4458 + // 1.2.0-5 bumps to 1.2.0
4459 + // 1.2.1 bumps to 1.3.0
4460 + if (this.patch !== 0 || this.prerelease.length === 0) {
4461 + this.minor++
4462 + }
4463 + this.patch = 0
4464 + this.prerelease = []
4465 + break
4466 + case 'patch':
4467 + // If this is not a pre-release version, it will increment the patch.
4468 + // If it is a pre-release it will bump up to the same patch version.
4469 + // 1.2.0-5 patches to 1.2.0
4470 + // 1.2.0 patches to 1.2.1
4471 + if (this.prerelease.length === 0) {
4472 + this.patch++
4473 + }
4474 + this.prerelease = []
4475 + break
4476 + // This probably shouldn't be used publicly.
4477 + // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
4478 + case 'pre':
4479 + if (this.prerelease.length === 0) {
4480 + this.prerelease = [0]
4481 + } else {
4482 + var i = this.prerelease.length
4483 + while (--i >= 0) {
4484 + if (typeof this.prerelease[i] === 'number') {
4485 + this.prerelease[i]++
4486 + i = -2
4487 + }
4488 + }
4489 + if (i === -1) {
4490 + // didn't increment anything
4491 + this.prerelease.push(0)
4492 + }
4493 + }
4494 + if (identifier) {
4495 + // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
4496 + // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
4497 + if (this.prerelease[0] === identifier) {
4498 + if (isNaN(this.prerelease[1])) {
4499 + this.prerelease = [identifier, 0]
4500 + }
4501 + } else {
4502 + this.prerelease = [identifier, 0]
4503 + }
4504 + }
4505 + break
4506 +
4507 + default:
4508 + throw new Error('invalid increment argument: ' + release)
4509 + }
4510 + this.format()
4511 + this.raw = this.version
4512 + return this
4513 +}
4514 +
4515 +exports.inc = inc
4516 +function inc (version, release, loose, identifier) {
4517 + if (typeof (loose) === 'string') {
4518 + identifier = loose
4519 + loose = undefined
4520 + }
4521 +
4522 + try {
4523 + return new SemVer(version, loose).inc(release, identifier).version
4524 + } catch (er) {
4525 + return null
4526 + }
4527 +}
4528 +
4529 +exports.diff = diff
4530 +function diff (version1, version2) {
4531 + if (eq(version1, version2)) {
4532 + return null
4533 + } else {
4534 + var v1 = parse(version1)
4535 + var v2 = parse(version2)
4536 + var prefix = ''
4537 + if (v1.prerelease.length || v2.prerelease.length) {
4538 + prefix = 'pre'
4539 + var defaultResult = 'prerelease'
4540 + }
4541 + for (var key in v1) {
4542 + if (key === 'major' || key === 'minor' || key === 'patch') {
4543 + if (v1[key] !== v2[key]) {
4544 + return prefix + key
4545 + }
4546 + }
4547 + }
4548 + return defaultResult // may be undefined
4549 + }
4550 +}
4551 +
4552 +exports.compareIdentifiers = compareIdentifiers
4553 +
4554 +var numeric = /^[0-9]+$/
4555 +function compareIdentifiers (a, b) {
4556 + var anum = numeric.test(a)
4557 + var bnum = numeric.test(b)
4558 +
4559 + if (anum && bnum) {
4560 + a = +a
4561 + b = +b
4562 + }
4563 +
4564 + return a === b ? 0
4565 + : (anum && !bnum) ? -1
4566 + : (bnum && !anum) ? 1
4567 + : a < b ? -1
4568 + : 1
4569 +}
4570 +
4571 +exports.rcompareIdentifiers = rcompareIdentifiers
4572 +function rcompareIdentifiers (a, b) {
4573 + return compareIdentifiers(b, a)
4574 +}
4575 +
4576 +exports.major = major
4577 +function major (a, loose) {
4578 + return new SemVer(a, loose).major
4579 +}
4580 +
4581 +exports.minor = minor
4582 +function minor (a, loose) {
4583 + return new SemVer(a, loose).minor
4584 +}
4585 +
4586 +exports.patch = patch
4587 +function patch (a, loose) {
4588 + return new SemVer(a, loose).patch
4589 +}
4590 +
4591 +exports.compare = compare
4592 +function compare (a, b, loose) {
4593 + return new SemVer(a, loose).compare(new SemVer(b, loose))
4594 +}
4595 +
4596 +exports.compareLoose = compareLoose
4597 +function compareLoose (a, b) {
4598 + return compare(a, b, true)
4599 +}
4600 +
4601 +exports.compareBuild = compareBuild
4602 +function compareBuild (a, b, loose) {
4603 + var versionA = new SemVer(a, loose)
4604 + var versionB = new SemVer(b, loose)
4605 + return versionA.compare(versionB) || versionA.compareBuild(versionB)
4606 +}
4607 +
4608 +exports.rcompare = rcompare
4609 +function rcompare (a, b, loose) {
4610 + return compare(b, a, loose)
4611 +}
4612 +
4613 +exports.sort = sort
4614 +function sort (list, loose) {
4615 + return list.sort(function (a, b) {
4616 + return exports.compareBuild(a, b, loose)
4617 + })
4618 +}
4619 +
4620 +exports.rsort = rsort
4621 +function rsort (list, loose) {
4622 + return list.sort(function (a, b) {
4623 + return exports.compareBuild(b, a, loose)
4624 + })
4625 +}
4626 +
4627 +exports.gt = gt
4628 +function gt (a, b, loose) {
4629 + return compare(a, b, loose) > 0
4630 +}
4631 +
4632 +exports.lt = lt
4633 +function lt (a, b, loose) {
4634 + return compare(a, b, loose) < 0
4635 +}
4636 +
4637 +exports.eq = eq
4638 +function eq (a, b, loose) {
4639 + return compare(a, b, loose) === 0
4640 +}
4641 +
4642 +exports.neq = neq
4643 +function neq (a, b, loose) {
4644 + return compare(a, b, loose) !== 0
4645 +}
4646 +
4647 +exports.gte = gte
4648 +function gte (a, b, loose) {
4649 + return compare(a, b, loose) >= 0
4650 +}
4651 +
4652 +exports.lte = lte
4653 +function lte (a, b, loose) {
4654 + return compare(a, b, loose) <= 0
4655 +}
4656 +
4657 +exports.cmp = cmp
4658 +function cmp (a, op, b, loose) {
4659 + switch (op) {
4660 + case '===':
4661 + if (typeof a === 'object')
4662 + a = a.version
4663 + if (typeof b === 'object')
4664 + b = b.version
4665 + return a === b
4666 +
4667 + case '!==':
4668 + if (typeof a === 'object')
4669 + a = a.version
4670 + if (typeof b === 'object')
4671 + b = b.version
4672 + return a !== b
4673 +
4674 + case '':
4675 + case '=':
4676 + case '==':
4677 + return eq(a, b, loose)
4678 +
4679 + case '!=':
4680 + return neq(a, b, loose)
4681 +
4682 + case '>':
4683 + return gt(a, b, loose)
4684 +
4685 + case '>=':
4686 + return gte(a, b, loose)
4687 +
4688 + case '<':
4689 + return lt(a, b, loose)
4690 +
4691 + case '<=':
4692 + return lte(a, b, loose)
4693 +
4694 + default:
4695 + throw new TypeError('Invalid operator: ' + op)
4696 + }
4697 +}
4698 +
4699 +exports.Comparator = Comparator
4700 +function Comparator (comp, options) {
4701 + if (!options || typeof options !== 'object') {
4702 + options = {
4703 + loose: !!options,
4704 + includePrerelease: false
4705 + }
4706 + }
4707 +
4708 + if (comp instanceof Comparator) {
4709 + if (comp.loose === !!options.loose) {
4710 + return comp
4711 + } else {
4712 + comp = comp.value
4713 + }
4714 + }
4715 +
4716 + if (!(this instanceof Comparator)) {
4717 + return new Comparator(comp, options)
4718 + }
4719 +
4720 + debug('comparator', comp, options)
4721 + this.options = options
4722 + this.loose = !!options.loose
4723 + this.parse(comp)
4724 +
4725 + if (this.semver === ANY) {
4726 + this.value = ''
4727 + } else {
4728 + this.value = this.operator + this.semver.version
4729 + }
4730 +
4731 + debug('comp', this)
4732 +}
4733 +
4734 +var ANY = {}
4735 +Comparator.prototype.parse = function (comp) {
4736 + var r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
4737 + var m = comp.match(r)
4738 +
4739 + if (!m) {
4740 + throw new TypeError('Invalid comparator: ' + comp)
4741 + }
4742 +
4743 + this.operator = m[1] !== undefined ? m[1] : ''
4744 + if (this.operator === '=') {
4745 + this.operator = ''
4746 + }
4747 +
4748 + // if it literally is just '>' or '' then allow anything.
4749 + if (!m[2]) {
4750 + this.semver = ANY
4751 + } else {
4752 + this.semver = new SemVer(m[2], this.options.loose)
4753 + }
4754 +}
4755 +
4756 +Comparator.prototype.toString = function () {
4757 + return this.value
4758 +}
4759 +
4760 +Comparator.prototype.test = function (version) {
4761 + debug('Comparator.test', version, this.options.loose)
4762 +
4763 + if (this.semver === ANY || version === ANY) {
4764 + return true
4765 + }
4766 +
4767 + if (typeof version === 'string') {
4768 + try {
4769 + version = new SemVer(version, this.options)
4770 + } catch (er) {
4771 + return false
4772 + }
4773 + }
4774 +
4775 + return cmp(version, this.operator, this.semver, this.options)
4776 +}
4777 +
4778 +Comparator.prototype.intersects = function (comp, options) {
4779 + if (!(comp instanceof Comparator)) {
4780 + throw new TypeError('a Comparator is required')
4781 + }
4782 +
4783 + if (!options || typeof options !== 'object') {
4784 + options = {
4785 + loose: !!options,
4786 + includePrerelease: false
4787 + }
4788 + }
4789 +
4790 + var rangeTmp
4791 +
4792 + if (this.operator === '') {
4793 + if (this.value === '') {
4794 + return true
4795 + }
4796 + rangeTmp = new Range(comp.value, options)
4797 + return satisfies(this.value, rangeTmp, options)
4798 + } else if (comp.operator === '') {
4799 + if (comp.value === '') {
4800 + return true
4801 + }
4802 + rangeTmp = new Range(this.value, options)
4803 + return satisfies(comp.semver, rangeTmp, options)
4804 + }
4805 +
4806 + var sameDirectionIncreasing =
4807 + (this.operator === '>=' || this.operator === '>') &&
4808 + (comp.operator === '>=' || comp.operator === '>')
4809 + var sameDirectionDecreasing =
4810 + (this.operator === '<=' || this.operator === '<') &&
4811 + (comp.operator === '<=' || comp.operator === '<')
4812 + var sameSemVer = this.semver.version === comp.semver.version
4813 + var differentDirectionsInclusive =
4814 + (this.operator === '>=' || this.operator === '<=') &&
4815 + (comp.operator === '>=' || comp.operator === '<=')
4816 + var oppositeDirectionsLessThan =
4817 + cmp(this.semver, '<', comp.semver, options) &&
4818 + ((this.operator === '>=' || this.operator === '>') &&
4819 + (comp.operator === '<=' || comp.operator === '<'))
4820 + var oppositeDirectionsGreaterThan =
4821 + cmp(this.semver, '>', comp.semver, options) &&
4822 + ((this.operator === '<=' || this.operator === '<') &&
4823 + (comp.operator === '>=' || comp.operator === '>'))
4824 +
4825 + return sameDirectionIncreasing || sameDirectionDecreasing ||
4826 + (sameSemVer && differentDirectionsInclusive) ||
4827 + oppositeDirectionsLessThan || oppositeDirectionsGreaterThan
4828 +}
4829 +
4830 +exports.Range = Range
4831 +function Range (range, options) {
4832 + if (!options || typeof options !== 'object') {
4833 + options = {
4834 + loose: !!options,
4835 + includePrerelease: false
4836 + }
4837 + }
4838 +
4839 + if (range instanceof Range) {
4840 + if (range.loose === !!options.loose &&
4841 + range.includePrerelease === !!options.includePrerelease) {
4842 + return range
4843 + } else {
4844 + return new Range(range.raw, options)
4845 + }
4846 + }
4847 +
4848 + if (range instanceof Comparator) {
4849 + return new Range(range.value, options)
4850 + }
4851 +
4852 + if (!(this instanceof Range)) {
4853 + return new Range(range, options)
4854 + }
4855 +
4856 + this.options = options
4857 + this.loose = !!options.loose
4858 + this.includePrerelease = !!options.includePrerelease
4859 +
4860 + // First, split based on boolean or ||
4861 + this.raw = range
4862 + this.set = range.split(/\s*\|\|\s*/).map(function (range) {
4863 + return this.parseRange(range.trim())
4864 + }, this).filter(function (c) {
4865 + // throw out any that are not relevant for whatever reason
4866 + return c.length
4867 + })
4868 +
4869 + if (!this.set.length) {
4870 + throw new TypeError('Invalid SemVer Range: ' + range)
4871 + }
4872 +
4873 + this.format()
4874 +}
4875 +
4876 +Range.prototype.format = function () {
4877 + this.range = this.set.map(function (comps) {
4878 + return comps.join(' ').trim()
4879 + }).join('||').trim()
4880 + return this.range
4881 +}
4882 +
4883 +Range.prototype.toString = function () {
4884 + return this.range
4885 +}
4886 +
4887 +Range.prototype.parseRange = function (range) {
4888 + var loose = this.options.loose
4889 + range = range.trim()
4890 + // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
4891 + var hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
4892 + range = range.replace(hr, hyphenReplace)
4893 + debug('hyphen replace', range)
4894 + // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
4895 + range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
4896 + debug('comparator trim', range, re[t.COMPARATORTRIM])
4897 +
4898 + // `~ 1.2.3` => `~1.2.3`
4899 + range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
4900 +
4901 + // `^ 1.2.3` => `^1.2.3`
4902 + range = range.replace(re[t.CARETTRIM], caretTrimReplace)
4903 +
4904 + // normalize spaces
4905 + range = range.split(/\s+/).join(' ')
4906 +
4907 + // At this point, the range is completely trimmed and
4908 + // ready to be split into comparators.
4909 +
4910 + var compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
4911 + var set = range.split(' ').map(function (comp) {
4912 + return parseComparator(comp, this.options)
4913 + }, this).join(' ').split(/\s+/)
4914 + if (this.options.loose) {
4915 + // in loose mode, throw out any that are not valid comparators
4916 + set = set.filter(function (comp) {
4917 + return !!comp.match(compRe)
4918 + })
4919 + }
4920 + set = set.map(function (comp) {
4921 + return new Comparator(comp, this.options)
4922 + }, this)
4923 +
4924 + return set
4925 +}
4926 +
4927 +Range.prototype.intersects = function (range, options) {
4928 + if (!(range instanceof Range)) {
4929 + throw new TypeError('a Range is required')
4930 + }
4931 +
4932 + return this.set.some(function (thisComparators) {
4933 + return (
4934 + isSatisfiable(thisComparators, options) &&
4935 + range.set.some(function (rangeComparators) {
4936 + return (
4937 + isSatisfiable(rangeComparators, options) &&
4938 + thisComparators.every(function (thisComparator) {
4939 + return rangeComparators.every(function (rangeComparator) {
4940 + return thisComparator.intersects(rangeComparator, options)
4941 + })
4942 + })
4943 + )
4944 + })
4945 + )
4946 + })
4947 +}
4948 +
4949 +// take a set of comparators and determine whether there
4950 +// exists a version which can satisfy it
4951 +function isSatisfiable (comparators, options) {
4952 + var result = true
4953 + var remainingComparators = comparators.slice()
4954 + var testComparator = remainingComparators.pop()
4955 +
4956 + while (result && remainingComparators.length) {
4957 + result = remainingComparators.every(function (otherComparator) {
4958 + return testComparator.intersects(otherComparator, options)
4959 + })
4960 +
4961 + testComparator = remainingComparators.pop()
4962 + }
4963 +
4964 + return result
4965 +}
4966 +
4967 +// Mostly just for testing and legacy API reasons
4968 +exports.toComparators = toComparators
4969 +function toComparators (range, options) {
4970 + return new Range(range, options).set.map(function (comp) {
4971 + return comp.map(function (c) {
4972 + return c.value
4973 + }).join(' ').trim().split(' ')
4974 + })
4975 +}
4976 +
4977 +// comprised of xranges, tildes, stars, and gtlt's at this point.
4978 +// already replaced the hyphen ranges
4979 +// turn into a set of JUST comparators.
4980 +function parseComparator (comp, options) {
4981 + debug('comp', comp, options)
4982 + comp = replaceCarets(comp, options)
4983 + debug('caret', comp)
4984 + comp = replaceTildes(comp, options)
4985 + debug('tildes', comp)
4986 + comp = replaceXRanges(comp, options)
4987 + debug('xrange', comp)
4988 + comp = replaceStars(comp, options)
4989 + debug('stars', comp)
4990 + return comp
4991 +}
4992 +
4993 +function isX (id) {
4994 + return !id || id.toLowerCase() === 'x' || id === '*'
4995 +}
4996 +
4997 +// ~, ~> --> * (any, kinda silly)
4998 +// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
4999 +// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
5000 +// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
5001 +// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
5002 +// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
5003 +function replaceTildes (comp, options) {
5004 + return comp.trim().split(/\s+/).map(function (comp) {
5005 + return replaceTilde(comp, options)
5006 + }).join(' ')
5007 +}
5008 +
5009 +function replaceTilde (comp, options) {
5010 + var r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE]
5011 + return comp.replace(r, function (_, M, m, p, pr) {
5012 + debug('tilde', comp, _, M, m, p, pr)
5013 + var ret
5014 +
5015 + if (isX(M)) {
5016 + ret = ''
5017 + } else if (isX(m)) {
5018 + ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
5019 + } else if (isX(p)) {
5020 + // ~1.2 == >=1.2.0 <1.3.0
5021 + ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
5022 + } else if (pr) {
5023 + debug('replaceTilde pr', pr)
5024 + ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
5025 + ' <' + M + '.' + (+m + 1) + '.0'
5026 + } else {
5027 + // ~1.2.3 == >=1.2.3 <1.3.0
5028 + ret = '>=' + M + '.' + m + '.' + p +
5029 + ' <' + M + '.' + (+m + 1) + '.0'
5030 + }
5031 +
5032 + debug('tilde return', ret)
5033 + return ret
5034 + })
5035 +}
5036 +
5037 +// ^ --> * (any, kinda silly)
5038 +// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
5039 +// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
5040 +// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
5041 +// ^1.2.3 --> >=1.2.3 <2.0.0
5042 +// ^1.2.0 --> >=1.2.0 <2.0.0
5043 +function replaceCarets (comp, options) {
5044 + return comp.trim().split(/\s+/).map(function (comp) {
5045 + return replaceCaret(comp, options)
5046 + }).join(' ')
5047 +}
5048 +
5049 +function replaceCaret (comp, options) {
5050 + debug('caret', comp, options)
5051 + var r = options.loose ? re[t.CARETLOOSE] : re[t.CARET]
5052 + return comp.replace(r, function (_, M, m, p, pr) {
5053 + debug('caret', comp, _, M, m, p, pr)
5054 + var ret
5055 +
5056 + if (isX(M)) {
5057 + ret = ''
5058 + } else if (isX(m)) {
5059 + ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
5060 + } else if (isX(p)) {
5061 + if (M === '0') {
5062 + ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
5063 + } else {
5064 + ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.0.0'
5065 + }
5066 + } else if (pr) {
5067 + debug('replaceCaret pr', pr)
5068 + if (M === '0') {
5069 + if (m === '0') {
5070 + ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
5071 + ' <' + M + '.' + m + '.' + (+p + 1)
5072 + } else {
5073 + ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
5074 + ' <' + M + '.' + (+m + 1) + '.0'
5075 + }
5076 + } else {
5077 + ret = '>=' + M + '.' + m + '.' + p + '-' + pr +
5078 + ' <' + (+M + 1) + '.0.0'
5079 + }
5080 + } else {
5081 + debug('no pr')
5082 + if (M === '0') {
5083 + if (m === '0') {
5084 + ret = '>=' + M + '.' + m + '.' + p +
5085 + ' <' + M + '.' + m + '.' + (+p + 1)
5086 + } else {
5087 + ret = '>=' + M + '.' + m + '.' + p +
5088 + ' <' + M + '.' + (+m + 1) + '.0'
5089 + }
5090 + } else {
5091 + ret = '>=' + M + '.' + m + '.' + p +
5092 + ' <' + (+M + 1) + '.0.0'
5093 + }
5094 + }
5095 +
5096 + debug('caret return', ret)
5097 + return ret
5098 + })
5099 +}
5100 +
5101 +function replaceXRanges (comp, options) {
5102 + debug('replaceXRanges', comp, options)
5103 + return comp.split(/\s+/).map(function (comp) {
5104 + return replaceXRange(comp, options)
5105 + }).join(' ')
5106 +}
5107 +
5108 +function replaceXRange (comp, options) {
5109 + comp = comp.trim()
5110 + var r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE]
5111 + return comp.replace(r, function (ret, gtlt, M, m, p, pr) {
5112 + debug('xRange', comp, ret, gtlt, M, m, p, pr)
5113 + var xM = isX(M)
5114 + var xm = xM || isX(m)
5115 + var xp = xm || isX(p)
5116 + var anyX = xp
5117 +
5118 + if (gtlt === '=' && anyX) {
5119 + gtlt = ''
5120 + }
5121 +
5122 + // if we're including prereleases in the match, then we need
5123 + // to fix this to -0, the lowest possible prerelease value
5124 + pr = options.includePrerelease ? '-0' : ''
5125 +
5126 + if (xM) {
5127 + if (gtlt === '>' || gtlt === '<') {
5128 + // nothing is allowed
5129 + ret = '<0.0.0-0'
5130 + } else {
5131 + // nothing is forbidden
5132 + ret = '*'
5133 + }
5134 + } else if (gtlt && anyX) {
5135 + // we know patch is an x, because we have any x at all.
5136 + // replace X with 0
5137 + if (xm) {
5138 + m = 0
5139 + }
5140 + p = 0
5141 +
5142 + if (gtlt === '>') {
5143 + // >1 => >=2.0.0
5144 + // >1.2 => >=1.3.0
5145 + // >1.2.3 => >= 1.2.4
5146 + gtlt = '>='
5147 + if (xm) {
5148 + M = +M + 1
5149 + m = 0
5150 + p = 0
5151 + } else {
5152 + m = +m + 1
5153 + p = 0
5154 + }
5155 + } else if (gtlt === '<=') {
5156 + // <=0.7.x is actually <0.8.0, since any 0.7.x should
5157 + // pass. Similarly, <=7.x is actually <8.0.0, etc.
5158 + gtlt = '<'
5159 + if (xm) {
5160 + M = +M + 1
5161 + } else {
5162 + m = +m + 1
5163 + }
5164 + }
5165 +
5166 + ret = gtlt + M + '.' + m + '.' + p + pr
5167 + } else if (xm) {
5168 + ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr
5169 + } else if (xp) {
5170 + ret = '>=' + M + '.' + m + '.0' + pr +
5171 + ' <' + M + '.' + (+m + 1) + '.0' + pr
5172 + }
5173 +
5174 + debug('xRange return', ret)
5175 +
5176 + return ret
5177 + })
5178 +}
5179 +
5180 +// Because * is AND-ed with everything else in the comparator,
5181 +// and '' means "any version", just remove the *s entirely.
5182 +function replaceStars (comp, options) {
5183 + debug('replaceStars', comp, options)
5184 + // Looseness is ignored here. star is always as loose as it gets!
5185 + return comp.trim().replace(re[t.STAR], '')
5186 +}
5187 +
5188 +// This function is passed to string.replace(re[t.HYPHENRANGE])
5189 +// M, m, patch, prerelease, build
5190 +// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
5191 +// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
5192 +// 1.2 - 3.4 => >=1.2.0 <3.5.0
5193 +function hyphenReplace ($0,
5194 + from, fM, fm, fp, fpr, fb,
5195 + to, tM, tm, tp, tpr, tb) {
5196 + if (isX(fM)) {
5197 + from = ''
5198 + } else if (isX(fm)) {
5199 + from = '>=' + fM + '.0.0'
5200 + } else if (isX(fp)) {
5201 + from = '>=' + fM + '.' + fm + '.0'
5202 + } else {
5203 + from = '>=' + from
5204 + }
5205 +
5206 + if (isX(tM)) {
5207 + to = ''
5208 + } else if (isX(tm)) {
5209 + to = '<' + (+tM + 1) + '.0.0'
5210 + } else if (isX(tp)) {
5211 + to = '<' + tM + '.' + (+tm + 1) + '.0'
5212 + } else if (tpr) {
5213 + to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr
5214 + } else {
5215 + to = '<=' + to
5216 + }
5217 +
5218 + return (from + ' ' + to).trim()
5219 +}
5220 +
5221 +// if ANY of the sets match ALL of its comparators, then pass
5222 +Range.prototype.test = function (version) {
5223 + if (!version) {
5224 + return false
5225 + }
5226 +
5227 + if (typeof version === 'string') {
5228 + try {
5229 + version = new SemVer(version, this.options)
5230 + } catch (er) {
5231 + return false
5232 + }
5233 + }
5234 +
5235 + for (var i = 0; i < this.set.length; i++) {
5236 + if (testSet(this.set[i], version, this.options)) {
5237 + return true
5238 + }
5239 + }
5240 + return false
5241 +}
5242 +
5243 +function testSet (set, version, options) {
5244 + for (var i = 0; i < set.length; i++) {
5245 + if (!set[i].test(version)) {
5246 + return false
5247 + }
5248 + }
5249 +
5250 + if (version.prerelease.length && !options.includePrerelease) {
5251 + // Find the set of versions that are allowed to have prereleases
5252 + // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
5253 + // That should allow `1.2.3-pr.2` to pass.
5254 + // However, `1.2.4-alpha.notready` should NOT be allowed,
5255 + // even though it's within the range set by the comparators.
5256 + for (i = 0; i < set.length; i++) {
5257 + debug(set[i].semver)
5258 + if (set[i].semver === ANY) {
5259 + continue
5260 + }
5261 +
5262 + if (set[i].semver.prerelease.length > 0) {
5263 + var allowed = set[i].semver
5264 + if (allowed.major === version.major &&
5265 + allowed.minor === version.minor &&
5266 + allowed.patch === version.patch) {
5267 + return true
5268 + }
5269 + }
5270 + }
5271 +
5272 + // Version has a -pre, but it's not one of the ones we like.
5273 + return false
5274 + }
5275 +
5276 + return true
5277 +}
5278 +
5279 +exports.satisfies = satisfies
5280 +function satisfies (version, range, options) {
5281 + try {
5282 + range = new Range(range, options)
5283 + } catch (er) {
5284 + return false
5285 + }
5286 + return range.test(version)
5287 +}
5288 +
5289 +exports.maxSatisfying = maxSatisfying
5290 +function maxSatisfying (versions, range, options) {
5291 + var max = null
5292 + var maxSV = null
5293 + try {
5294 + var rangeObj = new Range(range, options)
5295 + } catch (er) {
5296 + return null
5297 + }
5298 + versions.forEach(function (v) {
5299 + if (rangeObj.test(v)) {
5300 + // satisfies(v, range, options)
5301 + if (!max || maxSV.compare(v) === -1) {
5302 + // compare(max, v, true)
5303 + max = v
5304 + maxSV = new SemVer(max, options)
5305 + }
5306 + }
5307 + })
5308 + return max
5309 +}
5310 +
5311 +exports.minSatisfying = minSatisfying
5312 +function minSatisfying (versions, range, options) {
5313 + var min = null
5314 + var minSV = null
5315 + try {
5316 + var rangeObj = new Range(range, options)
5317 + } catch (er) {
5318 + return null
5319 + }
5320 + versions.forEach(function (v) {
5321 + if (rangeObj.test(v)) {
5322 + // satisfies(v, range, options)
5323 + if (!min || minSV.compare(v) === 1) {
5324 + // compare(min, v, true)
5325 + min = v
5326 + minSV = new SemVer(min, options)
5327 + }
5328 + }
5329 + })
5330 + return min
5331 +}
5332 +
5333 +exports.minVersion = minVersion
5334 +function minVersion (range, loose) {
5335 + range = new Range(range, loose)
5336 +
5337 + var minver = new SemVer('0.0.0')
5338 + if (range.test(minver)) {
5339 + return minver
5340 + }
5341 +
5342 + minver = new SemVer('0.0.0-0')
5343 + if (range.test(minver)) {
5344 + return minver
5345 + }
5346 +
5347 + minver = null
5348 + for (var i = 0; i < range.set.length; ++i) {
5349 + var comparators = range.set[i]
5350 +
5351 + comparators.forEach(function (comparator) {
5352 + // Clone to avoid manipulating the comparator's semver object.
5353 + var compver = new SemVer(comparator.semver.version)
5354 + switch (comparator.operator) {
5355 + case '>':
5356 + if (compver.prerelease.length === 0) {
5357 + compver.patch++
5358 + } else {
5359 + compver.prerelease.push(0)
5360 + }
5361 + compver.raw = compver.format()
5362 + /* fallthrough */
5363 + case '':
5364 + case '>=':
5365 + if (!minver || gt(minver, compver)) {
5366 + minver = compver
5367 + }
5368 + break
5369 + case '<':
5370 + case '<=':
5371 + /* Ignore maximum versions */
5372 + break
5373 + /* istanbul ignore next */
5374 + default:
5375 + throw new Error('Unexpected operation: ' + comparator.operator)
5376 + }
5377 + })
5378 + }
5379 +
5380 + if (minver && range.test(minver)) {
5381 + return minver
5382 + }
5383 +
5384 + return null
5385 +}
5386 +
5387 +exports.validRange = validRange
5388 +function validRange (range, options) {
5389 + try {
5390 + // Return '*' instead of '' so that truthiness works.
5391 + // This will throw if it's invalid anyway
5392 + return new Range(range, options).range || '*'
5393 + } catch (er) {
5394 + return null
5395 + }
5396 +}
5397 +
5398 +// Determine if version is less than all the versions possible in the range
5399 +exports.ltr = ltr
5400 +function ltr (version, range, options) {
5401 + return outside(version, range, '<', options)
5402 +}
5403 +
5404 +// Determine if version is greater than all the versions possible in the range.
5405 +exports.gtr = gtr
5406 +function gtr (version, range, options) {
5407 + return outside(version, range, '>', options)
5408 +}
5409 +
5410 +exports.outside = outside
5411 +function outside (version, range, hilo, options) {
5412 + version = new SemVer(version, options)
5413 + range = new Range(range, options)
5414 +
5415 + var gtfn, ltefn, ltfn, comp, ecomp
5416 + switch (hilo) {
5417 + case '>':
5418 + gtfn = gt
5419 + ltefn = lte
5420 + ltfn = lt
5421 + comp = '>'
5422 + ecomp = '>='
5423 + break
5424 + case '<':
5425 + gtfn = lt
5426 + ltefn = gte
5427 + ltfn = gt
5428 + comp = '<'
5429 + ecomp = '<='
5430 + break
5431 + default:
5432 + throw new TypeError('Must provide a hilo val of "<" or ">"')
5433 + }
5434 +
5435 + // If it satisifes the range it is not outside
5436 + if (satisfies(version, range, options)) {
5437 + return false
5438 + }
5439 +
5440 + // From now on, variable terms are as if we're in "gtr" mode.
5441 + // but note that everything is flipped for the "ltr" function.
5442 +
5443 + for (var i = 0; i < range.set.length; ++i) {
5444 + var comparators = range.set[i]
5445 +
5446 + var high = null
5447 + var low = null
5448 +
5449 + comparators.forEach(function (comparator) {
5450 + if (comparator.semver === ANY) {
5451 + comparator = new Comparator('>=0.0.0')
5452 + }
5453 + high = high || comparator
5454 + low = low || comparator
5455 + if (gtfn(comparator.semver, high.semver, options)) {
5456 + high = comparator
5457 + } else if (ltfn(comparator.semver, low.semver, options)) {
5458 + low = comparator
5459 + }
5460 + })
5461 +
5462 + // If the edge version comparator has a operator then our version
5463 + // isn't outside it
5464 + if (high.operator === comp || high.operator === ecomp) {
5465 + return false
5466 + }
5467 +
5468 + // If the lowest version comparator has an operator and our version
5469 + // is less than it then it isn't higher than the range
5470 + if ((!low.operator || low.operator === comp) &&
5471 + ltefn(version, low.semver)) {
5472 + return false
5473 + } else if (low.operator === ecomp && ltfn(version, low.semver)) {
5474 + return false
5475 + }
5476 + }
5477 + return true
5478 +}
5479 +
5480 +exports.prerelease = prerelease
5481 +function prerelease (version, options) {
5482 + var parsed = parse(version, options)
5483 + return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
5484 +}
5485 +
5486 +exports.intersects = intersects
5487 +function intersects (r1, r2, options) {
5488 + r1 = new Range(r1, options)
5489 + r2 = new Range(r2, options)
5490 + return r1.intersects(r2)
5491 +}
5492 +
5493 +exports.coerce = coerce
5494 +function coerce (version, options) {
5495 + if (version instanceof SemVer) {
5496 + return version
5497 + }
5498 +
5499 + if (typeof version === 'number') {
5500 + version = String(version)
5501 + }
5502 +
5503 + if (typeof version !== 'string') {
5504 + return null
5505 + }
5506 +
5507 + options = options || {}
5508 +
5509 + var match = null
5510 + if (!options.rtl) {
5511 + match = version.match(re[t.COERCE])
5512 + } else {
5513 + // Find the right-most coercible string that does not share
5514 + // a terminus with a more left-ward coercible string.
5515 + // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
5516 + //
5517 + // Walk through the string checking with a /g regexp
5518 + // Manually set the index so as to pick up overlapping matches.
5519 + // Stop when we get a match that ends at the string end, since no
5520 + // coercible string can be more right-ward without the same terminus.
5521 + var next
5522 + while ((next = re[t.COERCERTL].exec(version)) &&
5523 + (!match || match.index + match[0].length !== version.length)
5524 + ) {
5525 + if (!match ||
5526 + next.index + next[0].length !== match.index + match[0].length) {
5527 + match = next
5528 + }
5529 + re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length
5530 + }
5531 + // leave it in a clean state
5532 + re[t.COERCERTL].lastIndex = -1
5533 + }
5534 +
5535 + if (match === null) {
5536 + return null
5537 + }
5538 +
5539 + return parse(match[2] +
5540 + '.' + (match[3] || '0') +
5541 + '.' + (match[4] || '0'), options)
5542 +}
5543 +
5544 +
5545 +/***/ }),
5546 +
5547 +/***/ 7701:
5548 +/***/ ((module) => {
5549 +
5550 +/**
5551 + * Convert array of 16 byte values to UUID string format of the form:
5552 + * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
5553 + */
5554 +var byteToHex = [];
5555 +for (var i = 0; i < 256; ++i) {
5556 + byteToHex[i] = (i + 0x100).toString(16).substr(1);
5557 +}
5558 +
5559 +function bytesToUuid(buf, offset) {
5560 + var i = offset || 0;
5561 + var bth = byteToHex;
5562 + // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
5563 + return ([
5564 + bth[buf[i++]], bth[buf[i++]],
5565 + bth[buf[i++]], bth[buf[i++]], '-',
5566 + bth[buf[i++]], bth[buf[i++]], '-',
5567 + bth[buf[i++]], bth[buf[i++]], '-',
5568 + bth[buf[i++]], bth[buf[i++]], '-',
5569 + bth[buf[i++]], bth[buf[i++]],
5570 + bth[buf[i++]], bth[buf[i++]],
5571 + bth[buf[i++]], bth[buf[i++]]
5572 + ]).join('');
5573 +}
5574 +
5575 +module.exports = bytesToUuid;
5576 +
5577 +
5578 +/***/ }),
5579 +
5580 +/***/ 7269:
5581 +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
5582 +
5583 +// Unique ID creation requires a high quality random # generator. In node.js
5584 +// this is pretty straight-forward - we use the crypto API.
5585 +
5586 +var crypto = __nccwpck_require__(6113);
5587 +
5588 +module.exports = function nodeRNG() {
5589 + return crypto.randomBytes(16);
5590 +};
5591 +
5592 +
5593 +/***/ }),
5594 +
5595 +/***/ 7468:
5596 +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
5597 +
5598 +var rng = __nccwpck_require__(7269);
5599 +var bytesToUuid = __nccwpck_require__(7701);
5600 +
5601 +function v4(options, buf, offset) {
5602 + var i = buf && offset || 0;
5603 +
5604 + if (typeof(options) == 'string') {
5605 + buf = options === 'binary' ? new Array(16) : null;
5606 + options = null;
5607 + }
5608 + options = options || {};
5609 +
5610 + var rnds = options.random || (options.rng || rng)();
5611 +
5612 + // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
5613 + rnds[6] = (rnds[6] & 0x0f) | 0x40;
5614 + rnds[8] = (rnds[8] & 0x3f) | 0x80;
5615 +
5616 + // Copy bytes to buffer, if provided
5617 + if (buf) {
5618 + for (var ii = 0; ii < 16; ++ii) {
5619 + buf[i + ii] = rnds[ii];
5620 + }
5621 + }
5622 +
5623 + return buf || bytesToUuid(rnds);
5624 +}
5625 +
5626 +module.exports = v4;
5627 +
5628 +
3045 5629 /***/ }),
3046 5630
3047 5631 /***/ 7129:
@@ -7122,7 +9706,10 @@ try {
7122 9706
7123 9707 const core = __nccwpck_require__(2186)
7124 9708 const { exec } = __nccwpck_require__(1514)
9709 +const tc = __nccwpck_require__(7784)
7125 9710 const path = __nccwpck_require__(1017)
9711 +const fs = __nccwpck_require__(7147)
9712 +const os = __nccwpck_require__(2037)
7126 9713
7127 9714 /**
7128 9715 * Install Erlang/OTP.
@@ -7132,28 +9719,64 @@ const path = __nccwpck_require__(1017)
7132 9719 * @param {string[]} hexMirrors
7133 9720 */
7134 9721 async function installOTP(osVersion, otpVersion, hexMirrors) {
9722 + if (hexMirrors.length === 0) {
9723 + throw new Error(
9724 + `Could not install Erlang/OTP ${otpVersion} from any hex.pm mirror`,
9725 + )
9726 + }
9727 +
9728 + const [hexMirror, ...hexMirrorsT] = hexMirrors
9729 + const fullVersion = `${osVersion}/${otpVersion}`
9730 + let cachedPath = tc.find('otp', fullVersion)
7135 9731 const OS = process.platform
7136 if (OS === 'linux') {
7137 if (hexMirrors.length === 0) {
7138 throw new Error(
7139 `Could not install Erlang/OTP ${otpVersion} from any hex.pm mirror`,
7140 )
7141 }
7142 const [hexMirror, ...hexMirrorsT] = hexMirrors
7143 try {
7144 await exec(__nccwpck_require__.ab + "install-otp.sh", [
7145 osVersion,
7146 otpVersion,
7147 hexMirror,
7148 ])
7149 return
7150 } catch (err) {
7151 core.info(`install-otp.sh failed for mirror ${hexMirror}`)
9732 +
9733 + try {
9734 + if (OS === 'linux') {
9735 + if (!cachedPath) {
9736 + const tarPath = await tc.downloadTool(
9737 + `https://builds.hex.pm/builds/otp/${fullVersion}.tar.gz`,
9738 + )
9739 + const extractPath = await tc.extractTar(tarPath, undefined, [
9740 + 'zx',
9741 + '--strip-components=1',
9742 + ])
9743 + cachedPath = await tc.cacheDir(extractPath, 'otp', fullVersion)
9744 + }
9745 +
9746 + await exec(path.join(cachedPath, 'Install'), ['-minimal', cachedPath])
9747 +
9748 + const otpPath = path.join(cachedPath, 'bin')
9749 +
9750 + core.addPath(otpPath)
9751 + core.exportVariable('INSTALL_DIR_FOR_OTP', cachedPath)
9752 +
9753 + console.log('Installed Erlang/OTP version')
9754 + await exec(path.join(otpPath, 'erl'), ['-version'])
9755 + } else if (OS === 'win32') {
9756 + if (!cachedPath) {
9757 + const exePath = await tc.downloadTool(
9758 + 'https://github.com/erlang/otp/releases/download/' +
9759 + `OTP-${otpVersion}/otp_win64_${otpVersion}.exe`,
9760 + )
9761 + cachedPath = await tc.cacheFile(exePath, 'otp.exe', 'otp', fullVersion)
9762 + }
9763 +
9764 + const otpDir = path.join(process.env.RUNNER_TEMP, '.setup-beam', 'otp')
9765 + const otpPath = path.join(otpDir, 'bin')
9766 +
9767 + await fs.promises.mkdir(otpDir, { recursive: true })
9768 + await exec(path.join(cachedPath, 'otp.exe'), ['/S', `/D=${otpDir}`])
9769 +
9770 + core.addPath(otpPath)
9771 + core.exportVariable('INSTALL_DIR_FOR_OTP', otpDir)
9772 +
9773 + console.log('Installed Erlang/OTP version')
9774 + await exec(path.join(otpPath, 'erl'), ['+V'])
7152 9775 }
9776 + } catch (err) {
9777 + core.info(`Install OTP failed for mirror ${hexMirror}`)
9778 + core.info(`${err}\n${err.stack}`)
7153 9779 await installOTP(osVersion, otpVersion, hexMirrorsT)
7154 } else if (OS === 'win32') {
7155 const script = __nccwpck_require__.ab + "install-otp.ps1"
7156 await exec(`pwsh.exe ${script} -VSN:${otpVersion}`)
7157 9780 }
7158 9781 }
7159 9782
@@ -7170,25 +9793,34 @@ async function installElixir(elixirVersion, hexMirrors) {
7170 9793 )
7171 9794 }
7172 9795 const [hexMirror, ...hexMirrorsT] = hexMirrors
7173 const OS = process.platform
7174 let script
9796 +
7175 9797 try {
7176 if (OS === 'linux') {
7177 script = __nccwpck_require__.ab + "install-elixir.sh"
7178 await exec(__nccwpck_require__.ab + "install-elixir.sh", [elixirVersion, hexMirror])
7179 return
7180 }
7181 if (OS === 'win32') {
7182 script = __nccwpck_require__.ab + "install-elixir.ps1"
7183 await exec(
7184 `pwsh.exe ${script} -VSN:${elixirVersion} -HEX_MIRROR:${hexMirror}`,
9798 + let cachedPath = tc.find('elixir', elixirVersion)
9799 +
9800 + if (!cachedPath) {
9801 + const zipPath = await tc.downloadTool(
9802 + `${hexMirror}/builds/elixir/${elixirVersion}.zip`,
7185 9803 )
7186 return
9804 + const extractPath = await tc.extractZip(zipPath)
9805 + cachedPath = await tc.cacheDir(extractPath, 'elixir', elixirVersion)
7187 9806 }
9807 +
9808 + const elixirPath = path.join(cachedPath, 'bin')
9809 + const escriptsPath = path.join(os.homedir(), '.mix', 'escripts')
9810 +
9811 + core.addPath(elixirPath)
9812 + core.addPath(escriptsPath)
9813 + core.exportVariable('INSTALL_DIR_FOR_ELIXIR', cachedPath)
9814 +
9815 + core.info('Installed Elixir version')
9816 + await exec(path.join(elixirPath, 'elixir'), ['-v'])
9817 +
9818 + await fs.promises.mkdir(escriptsPath, { recursive: true })
7188 9819 } catch (err) {
7189 core.info(`${script} failed for mirror ${hexMirror}`)
9820 + core.info(`Elixir install failed for mirror ${hexMirror}`)
9821 + core.info(`${err}\n${err.stack}`)
9822 + await installElixir(elixirVersion, hexMirrorsT)
7190 9823 }
7191 await installElixir(elixirVersion, hexMirrorsT)
7192 9824 }
7193 9825
7194 9826 /**
@@ -7246,7 +9878,6 @@ module.exports = {
7246 9878 const core = __nccwpck_require__(2186)
7247 9879 const { exec } = __nccwpck_require__(1514)
7248 9880 const http = __nccwpck_require__(6255)
7249 const os = __nccwpck_require__(2037)
7250 9881 const path = __nccwpck_require__(1017)
7251 9882 const semver = __nccwpck_require__(1383)
7252 9883 const fs = __nccwpck_require__(7147)
@@ -7306,7 +9937,6 @@ async function installOTP(otpSpec, osVersion, hexMirrors) {
7306 9937 core.startGroup(`Installing Erlang/OTP ${otpVersion} - built on ${osVersion}`)
7307 9938 await installer.installOTP(osVersion, otpVersion, hexMirrors)
7308 9939 core.setOutput('otp-version', otpVersion)
7309 core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`)
7310 9940 core.endGroup()
7311 9941
7312 9942 return otpVersion
@@ -7329,8 +9959,6 @@ async function maybeInstallElixir(elixirSpec, otpSpec, hexMirrors) {
7329 9959 const elixirMatchers = __nccwpck_require__.ab + "elixir-matchers.json"
7330 9960 core.info(`##[add-matcher]${elixirMatchers}`)
7331 9961 }
7332 core.addPath(`${os.homedir()}/.mix/escripts`)
7333 core.addPath(`${process.env.RUNNER_TEMP}/.setup-beam/elixir/bin`)
7334 9962 core.endGroup()
7335 9963
7336 9964 installed = true
@@ -7909,6 +10537,14 @@ module.exports = require("path");
7909 10537
7910 10538 /***/ }),
7911 10539
10540 +/***/ 2781:
10541 +/***/ ((module) => {
10542 +
10543 +"use strict";
10544 +module.exports = require("stream");
10545 +
10546 +/***/ }),
10547 +
7912 10548 /***/ 1576:
7913 10549 /***/ ((module) => {
7914 10550
deleted dist/install-elixir.ps1
+0 −24
@@ -1,24 +0,0 @@
1 param([Parameter(Mandatory=$true)][string]${VSN}, [Parameter(Mandatory=$true)][string]${HEX_MIRROR})
2
3 $ErrorActionPreference="Stop"
4
5 Set-Location ${Env:RUNNER_TEMP}
6
7 $FILE_INPUT="${VSN}.zip"
8 $FILE_OUTPUT="elixir.zip"
9 $DIR_FOR_BIN=".setup-beam/elixir"
10
11 $ProgressPreference="SilentlyContinue"
12 Invoke-WebRequest "${HEX_MIRROR}/builds/elixir/${FILE_INPUT}" -OutFile "${FILE_OUTPUT}"
13 $ProgressPreference="Continue"
14 New-Item "${DIR_FOR_BIN}" -ItemType Directory | Out-Null
15 $ProgressPreference="SilentlyContinue"
16 Expand-Archive -DestinationPath "${DIR_FOR_BIN}" -Path "${FILE_OUTPUT}"
17 $ProgressPreference="Continue"
18 Write-Output "Installed Elixir version follows"
19 & "${DIR_FOR_BIN}/bin/elixir.bat" "-v" | Write-Output
20
21 $ProgressPreference="Continue"
22 New-Item "%UserProfile%/.mix/escripts" -ItemType Directory | Out-Null
23
24 "INSTALL_DIR_FOR_ELIXIR=${Env:RUNNER_TEMP}/${DIR_FOR_BIN}" | Out-File -FilePath ${Env:GITHUB_ENV} -Encoding utf8 -Append
deleted dist/install-elixir.sh
+0 −21
@@ -1,21 +0,0 @@
1 #!/bin/bash
2
3 set -eo pipefail
4
5 cd "${RUNNER_TEMP}"
6
7 VSN=${1}
8 HEX_MIRROR=${2}
9 FILE_INPUT="${VSN}.zip"
10 FILE_OUTPUT=elixir.zip
11 DIR_FOR_BIN=.setup-beam/elixir
12
13 wget -q -O "${FILE_OUTPUT}" "${HEX_MIRROR}/builds/elixir/${FILE_INPUT}"
14 mkdir -p "${DIR_FOR_BIN}"
15 unzip -q -o -d "${DIR_FOR_BIN}" "${FILE_OUTPUT}"
16 echo "Installed Elixir version follows"
17 ${DIR_FOR_BIN}/bin/elixir -v
18
19 mkdir -p "${HOME}/.mix/escripts"
20
21 echo "INSTALL_DIR_FOR_ELIXIR=${RUNNER_TEMP}/${DIR_FOR_BIN}" >> "${GITHUB_ENV}"
deleted dist/install-otp.ps1
+0 −20
@@ -1,20 +0,0 @@
1 param([Parameter(Mandatory=$true)][string]${VSN})
2
3 $ErrorActionPreference="Stop"
4
5 Set-Location ${Env:RUNNER_TEMP}
6
7 $FILE_INPUT="otp_win64_${VSN}.exe"
8 $FILE_OUTPUT="otp.exe"
9 $DIR_FOR_BIN="${Env:RUNNER_TEMP}\.setup-beam\otp"
10
11 $ProgressPreference="SilentlyContinue"
12 Invoke-WebRequest "https://github.com/erlang/otp/releases/download/OTP-${VSN}/${FILE_INPUT}" -OutFile "${FILE_OUTPUT}"
13 $ProgressPreference="Continue"
14 New-Item "${DIR_FOR_BIN}" -ItemType Directory | Out-Null
15 $ProgressPreference="SilentlyContinue"
16 Start-Process "${FILE_OUTPUT}" "/S /D=${DIR_FOR_BIN}" -Wait
17 Write-Output "Installed Erlang/OTP version follows"
18 & "${DIR_FOR_BIN}/bin/erl.exe" "+V" | Write-Output
19
20 "INSTALL_DIR_FOR_OTP=${DIR_FOR_BIN}" | Out-File -FilePath ${Env:GITHUB_ENV} -Encoding utf8 -Append
deleted dist/install-otp.sh
+0 −21
@@ -1,21 +0,0 @@
1 #!/bin/bash
2
3 set -eo pipefail
4
5 cd "${RUNNER_TEMP}"
6
7 OS=${1}
8 VSN=${2}
9 HEX_MIRROR=${3}
10 FILE_INPUT="${VSN}.tar.gz"
11 FILE_OUTPUT=otp.tar.gz
12 DIR_FOR_BIN=.setup-beam/otp
13
14 wget -q -O "${FILE_OUTPUT}" "${HEX_MIRROR}/builds/otp/${OS}/${FILE_INPUT}"
15 mkdir -p "${DIR_FOR_BIN}"
16 tar zxf "${FILE_OUTPUT}" -C "${DIR_FOR_BIN}" --strip-components=1
17 "${DIR_FOR_BIN}/Install" -minimal "$(pwd)/${DIR_FOR_BIN}"
18 echo "Installed Erlang/OTP version follows"
19 ${DIR_FOR_BIN}/bin/erl -version
20
21 echo "INSTALL_DIR_FOR_OTP=${RUNNER_TEMP}/${DIR_FOR_BIN}" >> "${GITHUB_ENV}"
modified package-lock.json
+56 −0

Click to load diff…

modified package.json
+1 −0

Click to load diff…

deleted src/install-elixir.ps1
+0 −24

Click to load diff…

deleted src/install-elixir.sh
+0 −21

Click to load diff…

deleted src/install-otp.ps1
+0 −20

Click to load diff…

deleted src/install-otp.sh
+0 −21

Click to load diff…

modified src/installer.js
+81 −33

Click to load diff…

modified src/setup-beam.js
+0 −4

Click to load diff…

Parents: b9783cd