mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
feat: return latest dis-tag readme whether main metadata readme is emtpy
This commit is contained in:
parent
eb4f196c0d
commit
e75376b82f
2 changed files with 33 additions and 6 deletions
|
@ -12,7 +12,7 @@ import _ from 'lodash';
|
||||||
import async from 'async';
|
import async from 'async';
|
||||||
import {ErrorCode, isObject, getLatestVersion, tagVersion, validate_name, semverSort, DIST_TAGS} from './utils';
|
import {ErrorCode, isObject, getLatestVersion, tagVersion, validate_name, semverSort, DIST_TAGS} from './utils';
|
||||||
import {
|
import {
|
||||||
generatePackageTemplate, normalizePackage, generateRevision, cleanUpReadme,
|
generatePackageTemplate, normalizePackage, generateRevision, getLatestReadme, cleanUpReadme,
|
||||||
fileExist, noSuchFile, DEFAULT_REVISION, pkgFileName,
|
fileExist, noSuchFile, DEFAULT_REVISION, pkgFileName,
|
||||||
} from './storage-utils';
|
} from './storage-utils';
|
||||||
import {loadPlugin} from '../lib/plugin-loader';
|
import {loadPlugin} from '../lib/plugin-loader';
|
||||||
|
@ -127,6 +127,11 @@ class LocalStorage implements IStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
let change = false;
|
let change = false;
|
||||||
|
// updating readme
|
||||||
|
packageLocalJson.readme = getLatestReadme(packageInfo);
|
||||||
|
if (packageInfo.readme !== packageLocalJson.readme) {
|
||||||
|
change = true;
|
||||||
|
}
|
||||||
for (let versionId in packageInfo.versions) {
|
for (let versionId in packageInfo.versions) {
|
||||||
if (_.isNil(packageLocalJson.versions[versionId])) {
|
if (_.isNil(packageLocalJson.versions[versionId])) {
|
||||||
let version = packageInfo.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) {
|
if ('time' in packageInfo) {
|
||||||
packageLocalJson.time = packageInfo.time;
|
packageLocalJson.time = packageInfo.time;
|
||||||
change = true;
|
change = true;
|
||||||
|
|
|
@ -63,6 +63,32 @@ function generateRevision(rev: string): string {
|
||||||
return ((+_rev[0] || 0) + 1) + '-' + crypto.pseudoRandomBytes(8).toString('hex');
|
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 {
|
function cleanUpReadme(version: Version): Version {
|
||||||
if (_.isNil(version) === false) {
|
if (_.isNil(version) === false) {
|
||||||
delete version.readme;
|
delete version.readme;
|
||||||
|
@ -157,6 +183,7 @@ export {
|
||||||
generatePackageTemplate,
|
generatePackageTemplate,
|
||||||
normalizePackage,
|
normalizePackage,
|
||||||
generateRevision,
|
generateRevision,
|
||||||
|
getLatestReadme,
|
||||||
cleanUpReadme,
|
cleanUpReadme,
|
||||||
DEFAULT_REVISION,
|
DEFAULT_REVISION,
|
||||||
fileExist,
|
fileExist,
|
||||||
|
|
Loading…
Reference in a new issue