mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
feat: update readme v4 (#1312)
* feat: update readme v4 * chore: update @verdaccio/ui-theme@0.1.9 * chore: update @verdaccio/ui-theme@0.1.10
This commit is contained in:
parent
a588588cf3
commit
7686417f29
7 changed files with 21 additions and 18 deletions
|
@ -17,7 +17,8 @@
|
|||
"dependencies": {
|
||||
"@verdaccio/local-storage": "2.1.0",
|
||||
"@verdaccio/streams": "2.0.0",
|
||||
"@verdaccio/ui-theme": "0.1.7",
|
||||
"@verdaccio/readme": "1.0.3",
|
||||
"@verdaccio/ui-theme": "0.1.10",
|
||||
"JSONStream": "1.3.5",
|
||||
"async": "3.0.1-0",
|
||||
"body-parser": "1.19.0",
|
||||
|
@ -41,7 +42,7 @@
|
|||
"mkdirp": "0.5.1",
|
||||
"mv": "2.1.1",
|
||||
"pkginfo": "0.4.1",
|
||||
"request": "2.88.0",
|
||||
"request": "2.87.0",
|
||||
"semver": "6.0.0",
|
||||
"verdaccio-audit": "1.2.0",
|
||||
"verdaccio-htpasswd": "2.0.0"
|
||||
|
|
|
@ -10,7 +10,8 @@ import semver from 'semver';
|
|||
import YAML from 'js-yaml';
|
||||
import URL from 'url';
|
||||
import createError from 'http-errors';
|
||||
import marked from 'marked';
|
||||
// $FlowFixMe
|
||||
import sanitizyReadme from '@verdaccio/readme';
|
||||
|
||||
import { HTTP_STATUS, API_ERROR, DEFAULT_PORT, DEFAULT_DOMAIN, DEFAULT_PROTOCOL, CHARACTER_ENCODING, HEADERS, DIST_TAGS, DEFAULT_USER } from './constants';
|
||||
import { generateGravatarUrl, GENERIC_AVATAR } from '../utils/user';
|
||||
|
@ -487,14 +488,14 @@ export function addGravatarSupport(pkgInfo: Object, online: boolean = true): Obj
|
|||
* @return {String} converted html template
|
||||
*/
|
||||
export function parseReadme(packageName: string, readme: string): string {
|
||||
if (readme) {
|
||||
return marked(readme);
|
||||
if (_.isEmpty(readme) === false) {
|
||||
return sanitizyReadme(readme);
|
||||
}
|
||||
|
||||
// logs readme not found error
|
||||
Logger.logger.error({ packageName }, '@{packageName}: No readme found');
|
||||
|
||||
return marked('ERROR: No README data found!');
|
||||
return sanitizyReadme('ERROR: No README data found!');
|
||||
}
|
||||
|
||||
export function buildToken(type: string, token: string): string {
|
||||
|
|
|
@ -5,6 +5,7 @@ export default function (server, server2) {
|
|||
describe('should test readme', () => {
|
||||
const README_PKG1 = 'readme-test';
|
||||
const README_PKG2 = 'readme-test-no-readme';
|
||||
const README_MESSAGE = 'this is a readme';
|
||||
|
||||
beforeAll(async function() {
|
||||
await server.putPackage('readme-test', require('./pkg-readme.json'))
|
||||
|
@ -16,20 +17,21 @@ export default function (server, server2) {
|
|||
test('add pkg', () => {});
|
||||
|
||||
describe('should check readme file', () => {
|
||||
const matchReadme = (serverRef, pkgName = README_PKG1, readmeMessage = 'this is a readme') => {
|
||||
const matchReadme = (serverRef, pkgName = README_PKG1, readmeMessage = README_MESSAGE) => {
|
||||
return serverRef.request({
|
||||
uri: `/-/verdaccio/package/readme/${pkgName}`
|
||||
}).status(HTTP_STATUS.OK).then(function(body) {
|
||||
expect(body).toEqual(`<p>${readmeMessage}</p>\n`);
|
||||
|
||||
expect(body).toEqual(`<p>${readmeMessage}</p>`);
|
||||
});
|
||||
};
|
||||
|
||||
test('should fetch server2 over uplink server1', () => {
|
||||
return matchReadme(server, README_PKG1, 'this is a readme');
|
||||
return matchReadme(server, README_PKG1, README_MESSAGE);
|
||||
});
|
||||
|
||||
test('should fetch package on local server1', () => {
|
||||
return matchReadme(server2, README_PKG1, 'this is a readme');
|
||||
return matchReadme(server2, README_PKG1, README_MESSAGE);
|
||||
});
|
||||
|
||||
test('should fetch not found readme server2 over uplink server1', () => {
|
||||
|
|
|
@ -37,6 +37,5 @@ exports[`Utilities parseReadme should parse makrdown text to html template 1`] =
|
|||
<li>Hat tip to anyone whose code was used</li>
|
||||
<li>Inspiration</li>
|
||||
<li>etc</li>
|
||||
</ul>
|
||||
"
|
||||
</ul>"
|
||||
`;
|
||||
|
|
|
@ -374,7 +374,7 @@ describe('Utilities', () => {
|
|||
test('should parse makrdown text to html template', () => {
|
||||
const markdown = '# markdown';
|
||||
expect(parseReadme('testPackage', markdown)).toEqual(
|
||||
'<h1 id="markdown">markdown</h1>\n'
|
||||
'<h1 id="markdown">markdown</h1>'
|
||||
);
|
||||
expect(
|
||||
parseReadme('testPackage', String(readmeFile('markdown.md')))
|
||||
|
@ -387,13 +387,13 @@ describe('Utilities', () => {
|
|||
const randomTextMarkdown = 'simple text \n # markdown';
|
||||
|
||||
expect(parseReadme('testPackage', randomText)).toEqual(
|
||||
'<p>%%%%%**##==</p>\n'
|
||||
'<p>%%%%%**##==</p>'
|
||||
);
|
||||
expect(parseReadme('testPackage', simpleText)).toEqual(
|
||||
'<p>simple text</p>\n'
|
||||
'<p>simple text</p>'
|
||||
);
|
||||
expect(parseReadme('testPackage', randomTextMarkdown)).toEqual(
|
||||
'<p>simple text </p>\n<h1 id="markdown">markdown</h1>\n'
|
||||
'<p>simple text </p>\n<h1 id="markdown">markdown</h1>'
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -401,7 +401,7 @@ describe('Utilities', () => {
|
|||
const noData = '';
|
||||
const spy = jest.spyOn(Logger.logger, 'error');
|
||||
expect(parseReadme('testPackage', noData)).toEqual(
|
||||
'<p>ERROR: No README data found!</p>\n'
|
||||
'<p>ERROR: No README data found!</p>'
|
||||
);
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
{ packageName: 'testPackage' },
|
||||
|
|
|
@ -12,7 +12,7 @@ auth:
|
|||
password: test
|
||||
|
||||
logs:
|
||||
- { type: stdout, format: pretty, level: warn }
|
||||
- { type: stdout, format: pretty, level: trace }
|
||||
|
||||
packages:
|
||||
'@*/*':
|
||||
|
|
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue