Skip to content

Commit

Permalink
fix: adjust package manager feeds (microsoft#7243)
Browse files Browse the repository at this point in the history
* Fix microsoft#7092: set default page size to 100 items

* Fixes microsoft#6854: merge community feeds into main feed, sort by downloads

* Fixes microsoft#7043: include any component tagged msbot-component

* improve error handling

* restore different checks for declarative only vs code driven components

* refactor to use includes instead of indexOf

Co-authored-by: Ben Yackley <61990921+beyackle@users.noreply.github.com>
  • Loading branch information
benbrown and beyackle committed Apr 22, 2021
1 parent 512bc15 commit 8f99d55
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 37 deletions.
2 changes: 2 additions & 0 deletions extensions/packageManager/src/node/feeds/npm/npmFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export class NpmFeed implements IFeed {
url = `${url}&from=${query.skip}`;
}

url = `${url}&popularity=1.0`;

return url;
}
}
2 changes: 2 additions & 0 deletions extensions/packageManager/src/node/feeds/nuget/nugetFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export class NuGetFeed implements IFeed {
}

const searchResult = httpResponse.data as INuGetSearchResult;
// sort these results by total downloads
searchResult.data = searchResult.data.sort((a, b) => b.totalDownloads - a.totalDownloads);
if (searchResult.data) {
return this.asPackageDefinition(searchResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface INuGetPackage {
versions: INuGetVersion[];
tags?: string | string[];
projectUrl?: string;
totalDownloads: number;
}

/**
Expand Down
33 changes: 3 additions & 30 deletions extensions/packageManager/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ import { FeedFactory } from './feeds/feedFactory';
const API_ROOT = '/api';

const hasSchema = (c) => {
// NOTE: A special case for orchestrator is included here because it does not directly include the schema
// the schema for orchestrator is in a dependent package
// additionally, our schemamerge command only returns the top level components found, even though
// it does properly discover and include the schema from this dependent package.
// without this special case, composer does not see orchestrator as being installed even though it is.
// in the future this should be resolved in the schemamerger library by causing the includesSchema property to be passed up to all parent libraries
return c.includesSchema || c.name.toLowerCase() === 'microsoft.bot.components.orchestrator';
return c.includesSchema || c.keywords?.includes('msbot-component');
};

const isAdaptiveComponent = (c) => {
Expand Down Expand Up @@ -110,18 +104,6 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
text: formatMessage('nuget'),
url: 'https://api.nuget.org/v3/index.json',
readonly: true,
defaultQuery: {
prerelease: true,
semVerLevel: '2.0.0',
query: `microsoft.bot.components+tags:${botComponentTag}`,
},
type: PackageSourceType.NuGet,
},
{
key: 'nuget-community',
text: formatMessage('community packages'),
url: 'https://api.nuget.org/v3/index.json',
readonly: true,
defaultQuery: {
prerelease: true,
semVerLevel: '2.0.0',
Expand All @@ -134,17 +116,6 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
text: formatMessage('npm'),
url: `https://registry.npmjs.org/-/v1/search`,
readonly: true,
defaultQuery: {
prerelease: true,
query: `keywords:${botComponentTag}+scope:microsoft`,
},
type: PackageSourceType.NPM,
},
{
key: 'npm-community',
text: formatMessage('JS community packages'),
url: `https://registry.npmjs.org/-/v1/search`,
readonly: true,
defaultQuery: {
prerelease: true,
query: `keywords:${botComponentTag}`,
Expand Down Expand Up @@ -227,6 +198,8 @@ export default async (composer: IExtensionRegistration): Promise<void> => {

composer.log('GETTING FEED', packageSource, packageSource.defaultQuery);

// set default page size to 100
packageSource.defaultQuery.take = 100;
const packages = await feed.getPackages(packageSource.defaultQuery);

if (Array.isArray(packages)) {
Expand Down
16 changes: 9 additions & 7 deletions extensions/packageManager/src/pages/Library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,6 @@ const Library: React.FC = () => {

updateInstalledComponents(results.data.components);
} else {
telemetryClient.track('PackageUninstallFailed', { package: selectedItem.name });

throw new Error(results.data.message);
}

Expand All @@ -526,11 +524,15 @@ const Library: React.FC = () => {
} catch (err) {
telemetryClient.track('PackageUninstallFailed', { package: selectedItem.name });

setApplicationLevelError({
status: err.response.status,
message: err.response && err.response.data.message ? err.response.data.message : err,
summary: strings.importError,
});
if (err.response) {
setApplicationLevelError({
status: err.response.status,
message: err.response && err.response.data.message ? err.response.data.message : err,
summary: strings.importError,
});
} else {
setApplicationLevelError(err);
}
}
setWorking('');
}
Expand Down

0 comments on commit 8f99d55

Please sign in to comment.