diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index beba882..17ab0b4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,5 @@ -# These owners will be the default owners for everything in -# the repo. Unless a later match takes precedence, -# review when someone opens a pull request. -# For more on how to customize the CODEOWNERS file - https://help.github.com/en/articles/about-code-owners -* @NuGet/nuget-client +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# review when someone opens a pull request. +# For more on how to customize the CODEOWNERS file - https://help.github.com/en/articles/about-code-owners +* @NuGet/nuget-client diff --git a/.gitignore b/.gitignore index 493c175..05c7d7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,93 +1,93 @@ -__tests__/runner/* - -# comment out in distribution branches -/node_modules - -# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test - -# parcel-bundler cache (https://parceljs.org/) -.cache - -# next.js build output -.next - -# nuxt.js build output -.nuxt - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ +__tests__/runner/* + +# comment out in distribution branches +/node_modules + +# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ diff --git a/.prettierrc.json b/.prettierrc.json index 3a6baac..f6736bc 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,11 +1,11 @@ -{ - "printWidth": 80, - "tabWidth": 2, - "useTabs": false, - "semi": true, - "singleQuote": true, - "trailingComma": "none", - "bracketSpacing": false, - "arrowParens": "avoid", - "parser": "typescript" +{ + "printWidth": 80, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "singleQuote": true, + "trailingComma": "none", + "bracketSpacing": false, + "arrowParens": "avoid", + "parser": "typescript" } \ No newline at end of file diff --git a/LICENSE b/LICENSE index 7589b5c..522214a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,23 +1,23 @@ - -The MIT License (MIT) - -Copyright (c) 2019 Microsoft and contributors -Copyright (c) 2018 GitHub, Inc. and contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + +The MIT License (MIT) + +Copyright (c) 2019 Microsoft and contributors +Copyright (c) 2018 GitHub, Inc. and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/__tests__/pick-version.test.ts b/__tests__/pick-version.test.ts index 5baf17f..06ca25c 100644 --- a/__tests__/pick-version.test.ts +++ b/__tests__/pick-version.test.ts @@ -1,107 +1,107 @@ -import nock = require('nock'); -import pickVersion from '../src/pick-version'; - -const HOST = 'https://dist.nuget.org'; -const PATH = '/tools.json'; -const TOOLS_JSON = { - 'nuget.exe': [ - { - version: '5.3.1', - url: 'https://dist.nuget.org/win-x86-commandline/v5.3.1/nuget.exe', - stage: 'ReleasedAndBlessed', - uploaded: '2019-10-24T21:00:00.0000000Z' - }, - { - version: '5.3.0', - url: 'https://dist.nuget.org/win-x86-commandline/v5.3.0/nuget.exe', - stage: 'ReleasedAndBlessed', - uploaded: '2019-09-23T21:00:00.0000000Z' - }, - { - version: '5.3.0-preview3', - url: - 'https://dist.nuget.org/win-x86-commandline/v5.3.0-preview3/nuget.exe', - stage: 'EarlyAccessPreview', - uploaded: '2019-09-04T17:00:00.0000000Z' - }, - { - version: '3.2.0', - url: 'https://dist.nuget.org/win-x86-commandline/v3.2.0/nuget.exe', - stage: 'Released', - uploaded: '2015-09-16T14:00:00.0000000-07:00' - }, - { - version: '2.8.6', - url: 'https://dist.nuget.org/win-x86-commandline/v2.8.6/nuget.exe', - stage: 'ReleasedAndBlessed', - uploaded: '2015-09-01T12:30:00.0000000-07:00' - } - ] -}; - -test('picks a version based on concrete version', async () => { - const srv = nock(HOST); - srv.get(PATH).reply(200, TOOLS_JSON); - let tool = await pickVersion('5.3.0'); - srv.done(); - expect(tool).toStrictEqual({ - version: '5.3.0', - url: 'https://dist.nuget.org/win-x86-commandline/v5.3.0/nuget.exe', - stage: 'ReleasedAndBlessed', - uploaded: new Date('2019-09-23T21:00:00.0000000Z') - }); -}); - -test('picks a version based on semver range', async () => { - const srv = nock(HOST); - srv.get(PATH).reply(200, TOOLS_JSON); - let tool = await pickVersion('5.3'); - srv.done(); - expect(tool).toStrictEqual({ - version: '5.3.1', - url: 'https://dist.nuget.org/win-x86-commandline/v5.3.1/nuget.exe', - stage: 'ReleasedAndBlessed', - uploaded: new Date('2019-10-24T21:00:00.0000000Z') - }); -}); - -test('picks a version based on stage', async () => { - const srv = nock(HOST); - srv - .get(PATH) - .times(2) - .reply(200, TOOLS_JSON); - let tool = await pickVersion('latest'); - expect(tool).toStrictEqual({ - version: '5.3.1', - url: 'https://dist.nuget.org/win-x86-commandline/v5.3.1/nuget.exe', - stage: 'ReleasedAndBlessed', - uploaded: new Date('2019-10-24T21:00:00.0000000Z') - }); - tool = await pickVersion('preview'); - srv.done(); - expect(tool).toStrictEqual({ - version: '5.3.0-preview3', - url: 'https://dist.nuget.org/win-x86-commandline/v5.3.0-preview3/nuget.exe', - stage: 'EarlyAccessPreview', - uploaded: new Date('2019-09-04T17:00:00.0000000Z') - }); -}); - -test('errors when no version could be found', async () => { - const srv = nock(HOST); - srv.get(PATH).reply(200, TOOLS_JSON); - let promise = pickVersion('4'); - promise.catch(() => {}).finally(() => srv.done()); - expect(promise).rejects.toThrow("No valid versions could be found for '4'."); -}); - -test('errors if an invalid label is passed in', async () => { - const srv = nock(HOST); - srv.get(PATH).reply(200, TOOLS_JSON); - let promise = pickVersion('yesterday'); - promise.catch(() => {}).finally(() => srv.done()); - expect(promise).rejects.toThrow( - "Invalid release label: 'yesterday'. Valid labels are 'latest' and 'preview'." - ); -}); +import nock = require('nock'); +import pickVersion from '../src/pick-version'; + +const HOST = 'https://dist.nuget.org'; +const PATH = '/tools.json'; +const TOOLS_JSON = { + 'nuget.exe': [ + { + version: '5.3.1', + url: 'https://dist.nuget.org/win-x86-commandline/v5.3.1/nuget.exe', + stage: 'ReleasedAndBlessed', + uploaded: '2019-10-24T21:00:00.0000000Z' + }, + { + version: '5.3.0', + url: 'https://dist.nuget.org/win-x86-commandline/v5.3.0/nuget.exe', + stage: 'ReleasedAndBlessed', + uploaded: '2019-09-23T21:00:00.0000000Z' + }, + { + version: '5.3.0-preview3', + url: + 'https://dist.nuget.org/win-x86-commandline/v5.3.0-preview3/nuget.exe', + stage: 'EarlyAccessPreview', + uploaded: '2019-09-04T17:00:00.0000000Z' + }, + { + version: '3.2.0', + url: 'https://dist.nuget.org/win-x86-commandline/v3.2.0/nuget.exe', + stage: 'Released', + uploaded: '2015-09-16T14:00:00.0000000-07:00' + }, + { + version: '2.8.6', + url: 'https://dist.nuget.org/win-x86-commandline/v2.8.6/nuget.exe', + stage: 'ReleasedAndBlessed', + uploaded: '2015-09-01T12:30:00.0000000-07:00' + } + ] +}; + +test('picks a version based on concrete version', async () => { + const srv = nock(HOST); + srv.get(PATH).reply(200, TOOLS_JSON); + let tool = await pickVersion('5.3.0'); + srv.done(); + expect(tool).toStrictEqual({ + version: '5.3.0', + url: 'https://dist.nuget.org/win-x86-commandline/v5.3.0/nuget.exe', + stage: 'ReleasedAndBlessed', + uploaded: new Date('2019-09-23T21:00:00.0000000Z') + }); +}); + +test('picks a version based on semver range', async () => { + const srv = nock(HOST); + srv.get(PATH).reply(200, TOOLS_JSON); + let tool = await pickVersion('5.3'); + srv.done(); + expect(tool).toStrictEqual({ + version: '5.3.1', + url: 'https://dist.nuget.org/win-x86-commandline/v5.3.1/nuget.exe', + stage: 'ReleasedAndBlessed', + uploaded: new Date('2019-10-24T21:00:00.0000000Z') + }); +}); + +test('picks a version based on stage', async () => { + const srv = nock(HOST); + srv + .get(PATH) + .times(2) + .reply(200, TOOLS_JSON); + let tool = await pickVersion('latest'); + expect(tool).toStrictEqual({ + version: '5.3.1', + url: 'https://dist.nuget.org/win-x86-commandline/v5.3.1/nuget.exe', + stage: 'ReleasedAndBlessed', + uploaded: new Date('2019-10-24T21:00:00.0000000Z') + }); + tool = await pickVersion('preview'); + srv.done(); + expect(tool).toStrictEqual({ + version: '5.3.0-preview3', + url: 'https://dist.nuget.org/win-x86-commandline/v5.3.0-preview3/nuget.exe', + stage: 'EarlyAccessPreview', + uploaded: new Date('2019-09-04T17:00:00.0000000Z') + }); +}); + +test('errors when no version could be found', async () => { + const srv = nock(HOST); + srv.get(PATH).reply(200, TOOLS_JSON); + let promise = pickVersion('4'); + promise.catch(() => {}).finally(() => srv.done()); + expect(promise).rejects.toThrow("No valid versions could be found for '4'."); +}); + +test('errors if an invalid label is passed in', async () => { + const srv = nock(HOST); + srv.get(PATH).reply(200, TOOLS_JSON); + let promise = pickVersion('yesterday'); + promise.catch(() => {}).finally(() => srv.done()); + expect(promise).rejects.toThrow( + "Invalid release label: 'yesterday'. Valid labels are 'latest' and 'preview'." + ); +}); diff --git a/lib/installer.js b/lib/installer.js index 899714a..98b4c50 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -1,59 +1,59 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(require("@actions/core")); -const tc = __importStar(require("@actions/tool-cache")); -const fs = __importStar(require("fs")); -const path = __importStar(require("path")); -const exec_1 = require("@actions/exec"); -const pick_version_1 = __importDefault(require("./pick-version")); -async function install(spec = 'latest', apiKey, apiKeySource) { - const tool = await pick_version_1.default(spec); - core.debug(`Found NuGet version: ${tool.version}`); - let cachePath = await tc.find('nuget.exe', tool.version); - if (!cachePath) { - const nugetExePath = await tc.downloadTool(tool.url); - cachePath = await tc.cacheFile(nugetExePath, 'nuget.exe', 'nuget.exe', tool.version); - } - core.debug(`nuget.exe cache path: ${cachePath}.`); - core.exportVariable('NUGET', `${cachePath}/nuget.exe`); - if (process.platform !== 'win32') { - core.debug(`Creating dummy 'nuget' script.`); - const scriptPath = path.join(cachePath, 'nuget'); - fs.writeFileSync(scriptPath, `#!/bin/sh\nmono $MONO_OPTIONS ${path.join(cachePath, 'nuget.exe')} "$@"`); - fs.chmodSync(scriptPath, '755'); - } - core.addPath(cachePath); - core.setOutput('nuget-version', tool.version); - console.log(`Installed nuget.exe version ${tool.version}`); - if (apiKey) { - const args = ['SetApiKey', apiKey]; - if (apiKeySource) { - args.push('-source', apiKeySource); - } - await exec_1.exec(path.join(cachePath, process.platform === 'win32' ? 'nuget.exe' : 'nuget'), args, { silent: true }); - console.log('Set up configured NuGet API key.'); - } -} -exports.default = install; +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(require("@actions/core")); +const tc = __importStar(require("@actions/tool-cache")); +const fs = __importStar(require("fs")); +const path = __importStar(require("path")); +const exec_1 = require("@actions/exec"); +const pick_version_1 = __importDefault(require("./pick-version")); +async function install(spec = 'latest', apiKey, apiKeySource) { + const tool = await pick_version_1.default(spec); + core.debug(`Found NuGet version: ${tool.version}`); + let cachePath = await tc.find('nuget.exe', tool.version); + if (!cachePath) { + const nugetExePath = await tc.downloadTool(tool.url); + cachePath = await tc.cacheFile(nugetExePath, 'nuget.exe', 'nuget.exe', tool.version); + } + core.debug(`nuget.exe cache path: ${cachePath}.`); + core.exportVariable('NUGET', `${cachePath}/nuget.exe`); + if (process.platform !== 'win32') { + core.debug(`Creating dummy 'nuget' script.`); + const scriptPath = path.join(cachePath, 'nuget'); + fs.writeFileSync(scriptPath, `#!/bin/sh\nmono $MONO_OPTIONS ${path.join(cachePath, 'nuget.exe')} "$@"`); + fs.chmodSync(scriptPath, '755'); + } + core.addPath(cachePath); + core.setOutput('nuget-version', tool.version); + console.log(`Installed nuget.exe version ${tool.version}`); + if (apiKey) { + const args = ['SetApiKey', apiKey]; + if (apiKeySource) { + args.push('-source', apiKeySource); + } + await exec_1.exec(path.join(cachePath, process.platform === 'win32' ? 'nuget.exe' : 'nuget'), args, { silent: true }); + console.log('Set up configured NuGet API key.'); + } +} +exports.default = install; diff --git a/lib/main.js b/lib/main.js index 6f62363..12f5972 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,35 +1,35 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(require("@actions/core")); -const installer_1 = __importDefault(require("./installer")); -async function run() { - try { - await installer_1.default(core.getInput('nuget-version'), core.getInput('nuget-api-key'), core.getInput('nuget-api-key-source')); - } - catch (error) { - core.setFailed(error.message); - } -} -run(); +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(require("@actions/core")); +const installer_1 = __importDefault(require("./installer")); +async function run() { + try { + await installer_1.default(core.getInput('nuget-version'), core.getInput('nuget-api-key'), core.getInput('nuget-api-key-source')); + } + catch (error) { + core.setFailed(error.message); + } +} +run(); diff --git a/lib/pick-version.js b/lib/pick-version.js index 7000efa..bacddba 100644 --- a/lib/pick-version.js +++ b/lib/pick-version.js @@ -1,69 +1,69 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const rest = __importStar(require("typed-rest-client/RestClient")); -const semver = __importStar(require("semver")); -var Stage; -(function (Stage) { - Stage["latest"] = "ReleasedAndBlessed"; - Stage["preview"] = "EarlyAccessPreview"; - Stage["_released"] = "Released"; -})(Stage || (Stage = {})); -async function pickVersion(spec) { - spec = spec.trim(); - let versions = await fetchVersions(); - let range = semver.validRange(spec, true); - let selected; - if (range) { - selected = versions.find(v => semver.satisfies(v.version, range, true)); - } - else { - let stage = spec == 'latest' - ? Stage.latest - : spec == 'preview' - ? Stage.preview - : null; - if (!stage) { - throw new Error(`Invalid release label: '${spec}'. Valid labels are 'latest' and 'preview'.`); - } - selected = versions.find(v => v.stage === stage); - } - if (!selected) { - throw new Error(`No valid versions could be found for '${spec}'.`); - } - return selected; -} -exports.default = pickVersion; -async function fetchVersions() { - const http = new rest.RestClient('nuget/setup-nuget-exe', undefined, undefined, { - allowRetries: true, - maxRetries: 3 - }); - return (await http - .get('https://dist.nuget.org/tools.json') - .then(j => j.result || { 'nuget.exe': [] }) - .then(n => n['nuget.exe'])).map(v => { - return { - ...v, - uploaded: new Date(v.uploaded) - }; - }); -} +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const rest = __importStar(require("typed-rest-client/RestClient")); +const semver = __importStar(require("semver")); +var Stage; +(function (Stage) { + Stage["latest"] = "ReleasedAndBlessed"; + Stage["preview"] = "EarlyAccessPreview"; + Stage["_released"] = "Released"; +})(Stage || (Stage = {})); +async function pickVersion(spec) { + spec = spec.trim(); + let versions = await fetchVersions(); + let range = semver.validRange(spec, true); + let selected; + if (range) { + selected = versions.find(v => semver.satisfies(v.version, range, true)); + } + else { + let stage = spec == 'latest' + ? Stage.latest + : spec == 'preview' + ? Stage.preview + : null; + if (!stage) { + throw new Error(`Invalid release label: '${spec}'. Valid labels are 'latest' and 'preview'.`); + } + selected = versions.find(v => v.stage === stage); + } + if (!selected) { + throw new Error(`No valid versions could be found for '${spec}'.`); + } + return selected; +} +exports.default = pickVersion; +async function fetchVersions() { + const http = new rest.RestClient('nuget/setup-nuget-exe', undefined, undefined, { + allowRetries: true, + maxRetries: 3 + }); + return (await http + .get('https://dist.nuget.org/tools.json') + .then(j => j.result || { 'nuget.exe': [] }) + .then(n => n['nuget.exe'])).map(v => { + return { + ...v, + uploaded: new Date(v.uploaded) + }; + }); +}