From 560f550b7dea2ccd6af88949656666a2761a5b8f Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Mon, 30 Nov 2020 23:31:58 +0100 Subject: [PATCH 1/4] (GH-473) checking the latest available Cake.Tool version on nuget, rather than calling "dotnet tool search". This was done because running "dotnet tool search" would only work starting with .NET 5. --- src/shared/cakeTool.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/shared/cakeTool.ts b/src/shared/cakeTool.ts index a22ab490..2b984648 100644 --- a/src/shared/cakeTool.ts +++ b/src/shared/cakeTool.ts @@ -1,6 +1,9 @@ import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; -import { window, Memento, ExtensionContext } from 'vscode'; +import { window, Memento, ExtensionContext, workspace } from 'vscode'; +import fetch from 'node-fetch'; +import { getFetchOptions } from './utils'; import { Version } from './version'; +import { logError, logToOutput } from './log'; export class CakeTool { @@ -36,10 +39,28 @@ export class CakeTool { }); } + /** + * returns the latest available version of Cake.Tool on nuget + */ public async getAvailableVersion(): Promise { - const proc = spawn('dotnet', ['tool', 'search', 'cake.tool']); - const ver = await this.getCakeVersionFromProc(proc); - return ver; + const url = 'https://azuresearch-usnc.nuget.org/query?q=Cake.Tool&prerelease=false'; + try { + const search = await fetch( + url, + getFetchOptions(workspace.getConfiguration('http'))); + const searchResult: any = await search.json(); + const cakeTool = (searchResult?.data || []).find((x:any) => x.id === "Cake.Tool"); + const version = cakeTool?.version; + if(!version) { + logToOutput("Could not find a latest version for Cake.Tool from: "+url); + return null; + } + return Version.parse(version); + } + catch (ex: any) { + logError(ex, true); + } + return null } /** From 6a4bf8292af4afcf54ed1a89aca53a51911e5ec9 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Tue, 1 Dec 2020 20:46:18 +0100 Subject: [PATCH 2/4] (GH-473) implemented a helper to get NuGet service URLs The hard-coded url in cakeTool was replaced with a call to getNugetServiceUrl(). Also the constants NUGET_SEARCH_URL and NUGET_VERSIONS_URL have been removed and replaced with calls to getNugetServiceUrl(). --- src/addPackage/actions/fetchCakePackages.ts | 18 +++++---- .../actions/fetchPackageVersions.ts | 39 ++++++++++--------- src/constants.ts | 3 +- src/shared/cakeTool.ts | 3 +- src/shared/nugetServiceUrl.ts | 26 +++++++++++++ 5 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 src/shared/nugetServiceUrl.ts diff --git a/src/addPackage/actions/fetchCakePackages.ts b/src/addPackage/actions/fetchCakePackages.ts index 2a7cd058..fea877bd 100644 --- a/src/addPackage/actions/fetchCakePackages.ts +++ b/src/addPackage/actions/fetchCakePackages.ts @@ -5,23 +5,25 @@ import { getFetchOptions } from '../../shared/utils'; import { window, workspace } from 'vscode'; import { CAKE_SEARCH_PAGE_SIZE, - NUGET_SEARCH_URL, CANCEL } from '../../constants'; -import { - NUGET_SEARCHING_PACKAGES -} from '../../shared/messages'; +import { NUGET_SEARCHING_PACKAGES } from '../../shared/messages'; +import { getNugetServiceUrl, NuGetServiceType } from '../../shared/nugetServiceUrl'; -export default function fetchCakePackages( +export default async function fetchCakePackages( value: string | undefined, - searchUrl: string = NUGET_SEARCH_URL, + searchUrl?: string, take: string = CAKE_SEARCH_PAGE_SIZE -): Promise | Promise { +): Promise { if (!value) { // User has canceled the process. return Promise.reject(CANCEL); } + if(!searchUrl){ + searchUrl = await getNugetServiceUrl(NuGetServiceType.SearchAutocompleteService); + } + window.setStatusBarMessage(NUGET_SEARCHING_PACKAGES); const queryParams = qs.stringify({ @@ -30,7 +32,7 @@ export default function fetchCakePackages( take: take }); - return fetch( + return await fetch( `${searchUrl}?${queryParams}`, getFetchOptions(workspace.getConfiguration('http')) ); diff --git a/src/addPackage/actions/fetchPackageVersions.ts b/src/addPackage/actions/fetchPackageVersions.ts index 442f4d38..1cd39e64 100644 --- a/src/addPackage/actions/fetchPackageVersions.ts +++ b/src/addPackage/actions/fetchPackageVersions.ts @@ -1,28 +1,29 @@ import { window, workspace } from 'vscode'; import fetch from 'node-fetch'; -import { Response } from 'node-fetch'; import { getFetchOptions } from '../../shared/utils'; -import { NUGET_VERSIONS_URL, CANCEL } from '../../constants'; +import { CANCEL } from '../../constants'; import { NUGET_LOADING_VERSIONS } from '../../shared/messages'; +import { getNugetServiceUrl, NuGetServiceType } from '../../shared/nugetServiceUrl'; -export default function fetchPackageVersions( +export default async function fetchPackageVersions( selectedPackageName: string | undefined, - versionsUrl: string = NUGET_VERSIONS_URL -): Promise | Promise { - return new Promise((resolve, reject) => { - if (!selectedPackageName) { - // User has canceled the process. - return reject(CANCEL); - } + versionsUrl?: string +): Promise { + if (!selectedPackageName) { + // User has canceled the process. + return Promise.reject(CANCEL); + } - window.setStatusBarMessage(NUGET_LOADING_VERSIONS); + window.setStatusBarMessage(NUGET_LOADING_VERSIONS); + if(!versionsUrl) { + versionsUrl = await getNugetServiceUrl(NuGetServiceType.FlatContainer3); + } - fetch( - `${versionsUrl}${selectedPackageName}/index.json`, - getFetchOptions(workspace.getConfiguration('http')) - ).then((response: Response) => { - window.setStatusBarMessage(''); - resolve({ response, selectedPackageName }); - }); - }); + const response = await fetch( + versionsUrl.replace(/\/?$/,`/${selectedPackageName}/index.json`), + getFetchOptions(workspace.getConfiguration('http')) + ); + + window.setStatusBarMessage(''); + return { response, selectedPackageName }; } diff --git a/src/constants.ts b/src/constants.ts index 2b9295e7..a3d06098 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,8 +5,7 @@ export const DEFAULT_SCRIPT_NAME = 'build.cake'; export const OUTPUT_CHANNEL_NAME = 'Cake Workspace'; export const ERROR_INVALID_SETTINGS = 'Invalid installation options! Please try again.'; export const ERROR_NO_WORKSPACE = 'You have not yet opened a folder.'; -export const NUGET_SEARCH_URL = 'https://api-v2v3search-0.nuget.org/autocomplete'; -export const NUGET_VERSIONS_URL = "https://api.nuget.org/v3-flatcontainer/"; +export const NUGET_SEVICE_INDEX_URL = 'https://api.nuget.org/v3/index.json'; export const DEFAULT_RESPONSE_TIMEOUT = 10000; export const CAKE_DEFAULT_NAME = "Cake"; export const CAKE_BAKERY_PACKAGE_URL = 'http://nuget.org/api/v2/package/Cake.Bakery/'; diff --git a/src/shared/cakeTool.ts b/src/shared/cakeTool.ts index 2b984648..0ae152aa 100644 --- a/src/shared/cakeTool.ts +++ b/src/shared/cakeTool.ts @@ -4,6 +4,7 @@ import fetch from 'node-fetch'; import { getFetchOptions } from './utils'; import { Version } from './version'; import { logError, logToOutput } from './log'; +import { getNugetServiceUrl, NuGetServiceType } from './nugetServiceUrl'; export class CakeTool { @@ -43,7 +44,7 @@ export class CakeTool { * returns the latest available version of Cake.Tool on nuget */ public async getAvailableVersion(): Promise { - const url = 'https://azuresearch-usnc.nuget.org/query?q=Cake.Tool&prerelease=false'; + const url = (await getNugetServiceUrl(NuGetServiceType.SearchQueryService)) + '?q=Cake.Tool&prerelease=false'; try { const search = await fetch( url, diff --git a/src/shared/nugetServiceUrl.ts b/src/shared/nugetServiceUrl.ts new file mode 100644 index 00000000..b2a11c20 --- /dev/null +++ b/src/shared/nugetServiceUrl.ts @@ -0,0 +1,26 @@ +import fetch from 'node-fetch'; +import { workspace } from 'vscode'; +import { NUGET_SEVICE_INDEX_URL } from '../constants'; +import { getFetchOptions } from './utils'; + +export enum NuGetServiceType { + SearchAutocompleteService = 'SearchAutocompleteService', + FlatContainer3 = 'PackageBaseAddress/3.0.0', + SearchQueryService = 'SearchQueryService' +} +export async function getNugetServiceUrl(type: NuGetServiceType) : Promise { + // TODO: the url's won't change every 5 min. - should we cache the call to the services? + const response = await fetch(NUGET_SEVICE_INDEX_URL, getFetchOptions(workspace.getConfiguration('http'))); + const json: any = await response.json(); + const resources = (json.resources as any[] || []).filter((x:any) => x['@type'] === type); + let resource = resources.find((x: any) => (x.comment as string).toLowerCase().indexOf('primary') >= 0); + if(!resource && resources.length > 0) { + resource = resources[0]; + } + + if(!resource){ + throw new Error("Service endpoint not Found: "+type); + } + + return resource['@id'] as string; +} \ No newline at end of file From 495e78bebf84f9acf658b7602026bce80c0271ac Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2020 20:34:53 +0000 Subject: [PATCH 3/4] Bump adm-zip from 0.5.0 to 0.5.1 Bumps [adm-zip](https://github.com/cthackers/adm-zip) from 0.5.0 to 0.5.1. - [Release notes](https://github.com/cthackers/adm-zip/releases) - [Commits](https://github.com/cthackers/adm-zip/commits) Signed-off-by: dependabot-preview[bot] --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 513ea2cf..1fd08018 100644 --- a/package-lock.json +++ b/package-lock.json @@ -261,9 +261,9 @@ "dev": true }, "adm-zip": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.0.tgz", - "integrity": "sha512-X6W8Pb1LFdDOQGMsO6OLGmRmyTzIxg5zjXitKjf2fQbqva4iAjcxWS4c01DH+HJ19n3qoQ9TstIRCxJmPOtDow==" + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.1.tgz", + "integrity": "sha512-a5ABmIFUJ9OxHV5zrXM9Q41JzpRIflFtdgpL4UQM9DsTHHxQzPRaeyAdnMW7kxL0NRWm/NHafJdj6pO+ty7L2g==" }, "agent-base": { "version": "4.3.0", diff --git a/package.json b/package.json index 2ff1c80c..2df7e61b 100644 --- a/package.json +++ b/package.json @@ -700,7 +700,7 @@ "depcheck": "depcheck" }, "dependencies": { - "adm-zip": "^0.5.0", + "adm-zip": "^0.5.1", "byline": "^5.0.0", "https-proxy-agent": "^5.0.0", "ini": "^1.3.4", From cc88d86222b2c22d57a2bdb7adfe56112f68b69c Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Tue, 1 Dec 2020 21:15:50 +0000 Subject: [PATCH 4/4] (build) Update to latest Cake.VsCode.Recipe --- recipe.cake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/recipe.cake b/recipe.cake index a8aec88d..06ad519e 100644 --- a/recipe.cake +++ b/recipe.cake @@ -1,10 +1,9 @@ -#load "nuget:https://www.nuget.org/api/v2?package=Cake.VsCode.Recipe&version=0.3.0" +#load "nuget:https://www.nuget.org/api/v2?package=Cake.VsCode.Recipe&version=0.4.0" if(BuildSystem.IsLocalBuild) { Environment.SetVariableNames( - githubUserNameVariable: "CAKE_GITHUB_USERNAME", - githubPasswordVariable: "CAKE_GITHUB_PASSWORD" + githubTokenVariable: "CAKE_GITHUB_PAT" ); } else