Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
* release/2.1.0:
  Use dll instead of exe for Cake Bakery
  (#681) packageName needs to be lowerCase for v3-flatcontainer
  (maint) added some logging
  Bump @types/node from 16.11.12 to 18.8.3
  Bump typescript from 4.5.3 to 4.8.4
  Bump minimist from 1.2.5 to 1.2.6
  Bump glob and @types/glob
  Bump https-proxy-agent from 5.0.0 to 5.0.1
  Bump node-fetch and @types/node-fetch
  Bump ini from 2.0.0 to 3.0.1
  Bump mocha and @types/mocha
  Bump depcheck from 1.4.2 to 1.4.3
  • Loading branch information
gep13 committed Oct 9, 2022
2 parents cbad3e3 + 64443b7 commit 7abcee2
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 290 deletions.
603 changes: 357 additions & 246 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,26 +626,26 @@
"dependencies": {
"adm-zip": "^0.5.9",
"byline": "^5.0.0",
"https-proxy-agent": "^5.0.0",
"ini": "^2.0.0",
"node-fetch": "^2.6.6",
"https-proxy-agent": "^5.0.1",
"ini": "^3.0.1",
"node-fetch": "^2.6.7",
"request": "^2.88.2",
"xml2js": "^0.4.23"
},
"devDependencies": {
"@types/byline": "^4.2.33",
"@types/glob": "^7.2.0",
"@types/glob": "^8.0.0",
"@types/ini": "^1.3.31",
"@types/mocha": "^9.0.0",
"@types/node": "^16.11.12",
"@types/node-fetch": "^2.5.12",
"@types/mocha": "^10.0.0",
"@types/node": "^18.8.3",
"@types/node-fetch": "^2.6.2",
"@types/vscode": "^1.24.0",
"@types/xml2js": "^0.4.9",
"depcheck": "^1.4.2",
"glob": "^7.2.0",
"mocha": "^9.1.3",
"depcheck": "^1.4.3",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"typemoq": "^2.1.0",
"typescript": "^4.5.3",
"typescript": "^4.8.4",
"vscode-test": "^1.6.1"
},
"extensionDependencies": [
Expand Down
17 changes: 13 additions & 4 deletions src/addPackage/actions/fetchCakePackages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as qs from 'querystring';
import fetch from 'node-fetch';
import { logger } from '../../shared'
import { Response } from 'node-fetch';
import { getFetchOptions } from '../../shared/utils';
import { window, workspace } from 'vscode';
Expand Down Expand Up @@ -32,8 +33,16 @@ export default async function fetchCakePackages(
take: take
});

return await fetch(
`${searchUrl}?${queryParams}`,
getFetchOptions(workspace.getConfiguration('http'))
);
try {
const fullUrl = `${searchUrl}?${queryParams}`;
logger.logInfo(`Fetching available packages for query '${value}' using URL: ${fullUrl}`);
return await fetch(
fullUrl,
getFetchOptions(workspace.getConfiguration('http'))
);
} catch (e: any) {
logger.logError("Error fetching available packages from NuGet for query: "+value);
logger.logToOutput(e);
throw e;
}
}
31 changes: 20 additions & 11 deletions src/addPackage/actions/fetchPackageVersions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { window, workspace } from 'vscode';
import fetch from 'node-fetch';
import { logger } from '../../shared'
import { getFetchOptions } from '../../shared/utils';
import { CANCEL } from '../../constants';
import { NUGET_LOADING_VERSIONS } from '../../shared/messages';
Expand All @@ -14,16 +15,24 @@ export default async function fetchPackageVersions(
return Promise.reject(CANCEL);
}

window.setStatusBarMessage(NUGET_LOADING_VERSIONS);
if(!versionsUrl) {
versionsUrl = await getNugetServiceUrl(NuGetServiceType.FlatContainer3);
}
try {
window.setStatusBarMessage(NUGET_LOADING_VERSIONS);
if(!versionsUrl) {
versionsUrl = await getNugetServiceUrl(NuGetServiceType.FlatContainer3);
}

const response = await fetch(
versionsUrl.replace(/\/?$/,`/${selectedPackageName}/index.json`),
getFetchOptions(workspace.getConfiguration('http'))
);

window.setStatusBarMessage('');
return { response, selectedPackageName };
versionsUrl = versionsUrl.replace(/\/?$/,`/${selectedPackageName.toLowerCase()}/index.json`)
logger.logInfo(`Fetching package versions for package '${selectedPackageName}' using URL: ${versionsUrl}`);
const response = await fetch(
versionsUrl,
getFetchOptions(workspace.getConfiguration('http'))
);

window.setStatusBarMessage('');
return { response, selectedPackageName };
} catch (e: any) {
logger.logError("Error fetching package versions from NuGet for package: "+selectedPackageName);
logger.logToOutput(e);
throw e;
}
}
2 changes: 1 addition & 1 deletion src/addPackage/actions/handleVersionsResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function handleVersionsResponse({
}): Promise<any> | Promise<never> {
if (!response.ok) {
return handleError<Promise<never>>(
null,
response,
NUGET_BAD_VERSIONING,
Promise.reject.bind(Promise)
);
Expand Down
2 changes: 1 addition & 1 deletion src/bakery/cakeBakery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CakeBakery {
public getTargetPath(): string {
return path.join(
this.extensionPath,
'Cake.Bakery/tools/Cake.Bakery.exe'
'Cake.Bakery/tools/Cake.Bakery.dll'
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/cakeMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ async function _registerCakeBakery(context: vscode.ExtensionContext) {
// Read in file
//import omnisharpCakeConfig from getOmnisharpCakeConfigFile();
var omnisharpCakeConfig = JSON.parse(fs.readFileSync(getOmnisharpCakeConfigFile(), 'utf-8'))
console.log(omnisharpCakeConfig.cake.bakeryPath);
logger.logInfo(`existing bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`);
omnisharpCakeConfig.cake.bakeryPath = targetPath;
logger.logInfo(`new bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`);
fs.writeFileSync(getOmnisharpCakeConfigFile(), JSON.stringify(omnisharpCakeConfig));

// lets force a restart of the Omnisharp server to use new config
Expand Down
10 changes: 9 additions & 1 deletion src/shared/log.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { window, OutputChannel } from 'vscode';
import { window, OutputChannel, extensions } from 'vscode';
import { OUTPUT_CHANNEL_NAME } from '../constants';

interface IPackageJson {
// see https://code.visualstudio.com/api/references/extension-manifest
name: string;
version: string;
}

let channel: OutputChannel;

export function logToOutput(...items: string[]): void {
Expand Down Expand Up @@ -32,6 +38,8 @@ export function logInfo(info: string, notify: boolean = false) {
function getChannel(name: string): OutputChannel {
if (!channel) {
channel = window.createOutputChannel(name);
const thisExtension = (extensions.getExtension("cake-build.cake-vscode")?.packageJSON ?? {}) as IPackageJson;
channel.appendLine(`This is ${thisExtension.name}, version ${thisExtension.version}`);
}

return channel;
Expand Down
30 changes: 18 additions & 12 deletions src/shared/nugetServiceUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetch from 'node-fetch';
import * as logger from './log';
import { workspace } from 'vscode';
import { NUGET_SERVICE_INDEX_URL } from '../constants';
import { getFetchOptions } from './utils';
Expand All @@ -9,18 +10,23 @@ export enum NuGetServiceType {
SearchQueryService = 'SearchQueryService'
}
export async function getNugetServiceUrl(type: NuGetServiceType) : Promise<string> {
// TODO: the url's won't change every 5 min. - should we cache the call to the services?
const response = await fetch(NUGET_SERVICE_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];
}
try {
// TODO: the url's won't change every 5 min. - should we cache the call to the services?
const response = await fetch(NUGET_SERVICE_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);
if(!resource){
throw new Error("Service endpoint not Found: "+type);
}
return resource['@id'] as string;
} catch (e: any) {
logger.logError("Error reading NuGet Service Url for type: "+type);
logger.logToOutput(e);
throw e;
}

return resource['@id'] as string;
}
11 changes: 9 additions & 2 deletions src/shared/utils/handleError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { logger } from '../../shared'
/**
* Writes an error to the console but rejects with the given message
* Writes an error to the logger but rejects with the given message
*
* @param {Error} err
* @param {string} displayMessage
Expand All @@ -10,7 +11,13 @@ export function handleError<T>(
displayMessage: string,
rejector: (reason?: any) => T
): T {
console.error(err || displayMessage);
logger.logError(displayMessage);
if(err){
if(typeof(err) == "object") {
err = JSON.stringify(err);
}
logger.logToOutput(err);
}
return rejector(displayMessage);
}

Expand Down

0 comments on commit 7abcee2

Please sign in to comment.