mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
Merge pull request #687 from aremishevsky/master
feat: return latest dis-tag readme whether main metadata readme is emtpy
This commit is contained in:
commit
3a70a36a6d
2 changed files with 33 additions and 6 deletions
|
@ -12,7 +12,7 @@ import _ from 'lodash';
|
|||
import async from 'async';
|
||||
import {ErrorCode, isObject, getLatestVersion, tagVersion, validate_name, semverSort, DIST_TAGS} from './utils';
|
||||
import {
|
||||
generatePackageTemplate, normalizePackage, generateRevision, cleanUpReadme,
|
||||
generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme,
|
||||
fileExist, noSuchFile, DEFAULT_REVISION, pkgFileName,
|
||||
} from './storage-utils';
|
||||
import {loadPlugin} from '../lib/plugin-loader';
|
||||
|
@ -127,6 +127,11 @@ class LocalStorage implements IStorage {
|
|||
}
|
||||
|
||||
let change = false;
|
||||
// updating readme
|
||||
packageLocalJson.readme = getLatestReadme(packageInfo);
|
||||
if (packageInfo.readme !== packageLocalJson.readme) {
|
||||
change = true;
|
||||
}
|
||||
for (let versionId in packageInfo.versions) {
|
||||
if (_.isNil(packageLocalJson.versions[versionId])) {
|
||||
let version = packageInfo.versions[versionId];
|
||||
|
@ -180,11 +185,6 @@ class LocalStorage implements IStorage {
|
|||
}
|
||||
}
|
||||
|
||||
if (packageInfo.readme !== packageLocalJson.readme) {
|
||||
packageLocalJson.readme = packageInfo.readme;
|
||||
change = true;
|
||||
}
|
||||
|
||||
if ('time' in packageInfo) {
|
||||
packageLocalJson.time = packageInfo.time;
|
||||
change = true;
|
||||
|
|
|
@ -63,6 +63,32 @@ function generateRevision(rev: string): string {
|
|||
return ((+_rev[0] || 0) + 1) + '-' + crypto.pseudoRandomBytes(8).toString('hex');
|
||||
}
|
||||
|
||||
function getLatestReadme(pkg: Package): string {
|
||||
const versions = pkg['versions'] || {};
|
||||
const distTags = pkg['dist-tags'] || {};
|
||||
const latestVersion = distTags['latest'] ? versions[distTags['latest']] || {} : {};
|
||||
let readme = _.trim(pkg.readme || latestVersion.readme || '');
|
||||
if (readme) {
|
||||
return readme;
|
||||
}
|
||||
// In case of empty readme - trying to get ANY readme in the following order: 'next','beta','alpha','test','dev','canary'
|
||||
const readmeDistTagsPriority = [
|
||||
'next',
|
||||
'beta',
|
||||
'alpha',
|
||||
'test',
|
||||
'dev',
|
||||
'canary'];
|
||||
readmeDistTagsPriority.map(function(tag) {
|
||||
if (readme) {
|
||||
return readme;
|
||||
}
|
||||
const data = distTags[tag] ? versions[distTags[tag]] || {} : {};
|
||||
readme = _.trim(data.readme || readme);
|
||||
});
|
||||
return readme;
|
||||
}
|
||||
|
||||
function cleanUpReadme(version: Version): Version {
|
||||
if (_.isNil(version) === false) {
|
||||
delete version.readme;
|
||||
|
@ -157,6 +183,7 @@ export {
|
|||
generatePackageTemplate,
|
||||
normalizePackage,
|
||||
generateRevision,
|
||||
getLatestReadme,
|
||||
cleanUpReadme,
|
||||
DEFAULT_REVISION,
|
||||
fileExist,
|
||||
|
|
Loading…
Reference in a new issue