mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
feat: browse web package version (#1457)
* feat: allow endpoint to query by version * chore: update @verdaccio/ui-theme * test: add unit test for sidebar endpoint by version
This commit is contained in:
parent
06f659c331
commit
d5303f407b
5 changed files with 66 additions and 15 deletions
|
@ -20,7 +20,7 @@
|
||||||
"@verdaccio/local-storage": "2.2.1",
|
"@verdaccio/local-storage": "2.2.1",
|
||||||
"@verdaccio/readme": "8.0.0",
|
"@verdaccio/readme": "8.0.0",
|
||||||
"@verdaccio/streams": "8.0.0",
|
"@verdaccio/streams": "8.0.0",
|
||||||
"@verdaccio/ui-theme": "0.2.3",
|
"@verdaccio/ui-theme": "0.3.0",
|
||||||
"JSONStream": "1.3.5",
|
"JSONStream": "1.3.5",
|
||||||
"async": "3.1.0",
|
"async": "3.1.0",
|
||||||
"body-parser": "1.19.0",
|
"body-parser": "1.19.0",
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { addScope, addGravatarSupport, deleteProperties, sortByName, parseReadme, formatAuthor, convertDistRemoteToLocalTarballUrls } from '../../../lib/utils';
|
import {
|
||||||
|
addScope,
|
||||||
|
addGravatarSupport,
|
||||||
|
deleteProperties,
|
||||||
|
sortByName,
|
||||||
|
parseReadme,
|
||||||
|
formatAuthor,
|
||||||
|
convertDistRemoteToLocalTarballUrls,
|
||||||
|
isVersionValid
|
||||||
|
} from '../../../lib/utils';
|
||||||
import { allow } from '../../middleware';
|
import { allow } from '../../middleware';
|
||||||
import { DIST_TAGS, HEADER_TYPE, HEADERS, HTTP_STATUS } from '../../../lib/constants';
|
import { DIST_TAGS, HEADER_TYPE, HEADERS, HTTP_STATUS } from '../../../lib/constants';
|
||||||
import { generateGravatarUrl } from '../../../utils/user';
|
import { generateGravatarUrl } from '../../../utils/user';
|
||||||
|
@ -104,22 +113,28 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth,
|
||||||
req,
|
req,
|
||||||
callback: function(err: Error, info: $SidebarPackage): void {
|
callback: function(err: Error, info: $SidebarPackage): void {
|
||||||
if (_.isNil(err)) {
|
if (_.isNil(err)) {
|
||||||
|
const {v} = req.query;
|
||||||
let sideBarInfo: any = _.clone(info);
|
let sideBarInfo: any = _.clone(info);
|
||||||
sideBarInfo.versions = convertDistRemoteToLocalTarballUrls(info, req, config.url_prefix).versions;
|
sideBarInfo.versions = convertDistRemoteToLocalTarballUrls(info, req, config.url_prefix).versions;
|
||||||
sideBarInfo.latest = sideBarInfo.versions[info[DIST_TAGS].latest];
|
if (isVersionValid(info, v)) {
|
||||||
sideBarInfo.latest.author = formatAuthor(sideBarInfo.latest.author);
|
sideBarInfo.latest = sideBarInfo.versions[v];
|
||||||
sideBarInfo = deleteProperties(['readme', '_attachments', '_rev', 'name'], sideBarInfo);
|
sideBarInfo.latest.author = formatAuthor(sideBarInfo.latest.author);
|
||||||
if (config.web) {
|
} else {
|
||||||
sideBarInfo = addGravatarSupport(sideBarInfo, config.web.gravatar);
|
sideBarInfo.latest = sideBarInfo.versions[info[DIST_TAGS].latest];
|
||||||
|
sideBarInfo.latest.author = formatAuthor(sideBarInfo.latest.author);
|
||||||
|
}
|
||||||
|
sideBarInfo = deleteProperties(['readme', '_attachments', '_rev', 'name'], sideBarInfo);
|
||||||
|
if (config.web) {
|
||||||
|
sideBarInfo = addGravatarSupport(sideBarInfo, config.web.gravatar);
|
||||||
|
} else {
|
||||||
|
sideBarInfo = addGravatarSupport(sideBarInfo);
|
||||||
|
}
|
||||||
|
next(sideBarInfo);
|
||||||
} else {
|
} else {
|
||||||
sideBarInfo = addGravatarSupport(sideBarInfo);
|
res.status(HTTP_STATUS.NOT_FOUND);
|
||||||
|
res.end();
|
||||||
}
|
}
|
||||||
next(sideBarInfo);
|
|
||||||
} else {
|
|
||||||
res.status(HTTP_STATUS.NOT_FOUND);
|
|
||||||
res.end();
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
|
@ -599,3 +598,13 @@ export function encodeScopedUri(packageName) {
|
||||||
export function hasDiffOneKey(versions) {
|
export function hasDiffOneKey(versions) {
|
||||||
return Object.keys(versions).length !== 1;
|
return Object.keys(versions).length !== 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isVersionValid(packageMeta, packageVersion): boolean {
|
||||||
|
const hasVersion = typeof packageVersion !== 'undefined';
|
||||||
|
if (!hasVersion) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasMatchVersion = Object.keys(packageMeta.versions).includes(packageVersion);
|
||||||
|
return hasMatchVersion;
|
||||||
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ describe('endpoint web unit test', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//FIXME: disable, we need to inspect why fails randomly
|
//FIXME: disabled, we need to inspect why fails randomly
|
||||||
test.skip('should display scoped readme 404', (done) => {
|
test.skip('should display scoped readme 404', (done) => {
|
||||||
request(app)
|
request(app)
|
||||||
.get('/-/verdaccio/package/readme/@scope/404')
|
.get('/-/verdaccio/package/readme/@scope/404')
|
||||||
|
@ -115,6 +115,23 @@ describe('endpoint web unit test', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should display sidebar info by version', (done) => {
|
||||||
|
request(app)
|
||||||
|
.get('/-/verdaccio/sidebar/@scope/pk1-test?v=1.0.6')
|
||||||
|
.expect(HTTP_STATUS.OK)
|
||||||
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||||
|
.end(function(err, res) {
|
||||||
|
const sideBarInfo = res.body;
|
||||||
|
const latestVersion = publishMetadata.versions[publishMetadata[DIST_TAGS].latest];
|
||||||
|
|
||||||
|
expect(sideBarInfo.latest.author).toBeDefined();
|
||||||
|
expect(sideBarInfo.latest.author.avatar).toMatch(/www.gravatar.com/);
|
||||||
|
expect(sideBarInfo.latest.author.name).toBe(latestVersion.author.name);
|
||||||
|
expect(sideBarInfo.latest.author.email).toBe(latestVersion.author.email);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('should display sidebar info 404', (done) => {
|
test('should display sidebar info 404', (done) => {
|
||||||
request(app)
|
request(app)
|
||||||
.get('/-/verdaccio/sidebar/@scope/404')
|
.get('/-/verdaccio/sidebar/@scope/404')
|
||||||
|
@ -124,6 +141,16 @@ describe('endpoint web unit test', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should display sidebar info 404 with version', (done) => {
|
||||||
|
request(app)
|
||||||
|
.get('/-/verdaccio/sidebar/@scope/pk1-test?v=0.0.0-not-found')
|
||||||
|
.expect(HTTP_STATUS.NOT_FOUND)
|
||||||
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
||||||
|
.end(function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Search', () => {
|
describe('Search', () => {
|
||||||
|
|
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue