Skip to content

Commit cad5ac9

Browse files
authored
Merge pull request conventional-changelog#101 from griffithtp/fix/76_download-button-hidden-for-localhost
fix: 76 download button hidden for localhost
2 parents 46ae0d2 + ecc4521 commit cad5ac9

File tree

6 files changed

+40
-18
lines changed

6 files changed

+40
-18
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@types/react": "16.8.16",
2424
"@types/react-dom": "16.8.4",
2525
"@types/react-router-dom": "4.3.2",
26+
"@types/validator": "10.11.1",
2627
"@verdaccio/babel-preset": "0.2.1",
2728
"@verdaccio/eslint-config": "0.0.1",
2829
"@verdaccio/types": "6.1.0",

src/history.ts

-8
This file was deleted.

src/router.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import React, { Component, ReactElement } from 'react';
44
import { Router, Route, Switch } from 'react-router-dom';
5+
import { createBrowserHistory } from 'history';
56
import { AppContextConsumer, AppStateInterface } from './App/App';
67

78
import { asyncComponent } from './utils/asyncComponent';
8-
import history from './history';
99
import Header from './components/Header';
1010

11+
const history = createBrowserHistory({
12+
basename: window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix,
13+
});
14+
1115
const NotFound = asyncComponent(() => import('./components/NotFound'));
1216
const VersionPackage = asyncComponent(() => import('./pages/version/Version'));
1317
const HomePage = asyncComponent(() => import('./pages/home'));

src/utils/url.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { isURL, isEmail, getRegistryURL } from './url';
2+
3+
describe('url', () => {
4+
test('isURL() - should return true for localhost', () => {
5+
expect(isURL('http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeTruthy();
6+
});
7+
8+
test('isURL() - should return false when protocol is missing', () => {
9+
expect(isURL('localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeFalsy();
10+
});
11+
12+
test('isEmail() - should return true if valid', () => {
13+
expect(isEmail('[email protected]')).toBeTruthy();
14+
});
15+
test('isEmail() - should return false if invalid', () => {
16+
expect(isEmail('')).toBeFalsy();
17+
});
18+
19+
test('getRegistryURL() - should keep slash if location is a sub directory', () => {
20+
history.pushState({}, 'page title', '/-/web/detail');
21+
expect(getRegistryURL()).toBe('http://localhost/-/web/detail');
22+
history.pushState({}, 'page title', '/');
23+
});
24+
test('getRegistryURL() - should not add slash if location is not a sub directory', () => {
25+
expect(getRegistryURL()).toBe('http://localhost');
26+
});
27+
});

src/utils/url.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import isURLValidator from 'validator/lib/isURL';
22
import isEmailValidator from 'validator/lib/isEmail';
33
import '../../types';
44

5-
export function isURL(url): boolean {
5+
export function isURL(url: string): boolean {
66
return isURLValidator(url || '', {
77
protocols: ['http', 'https', 'git+https'],
88
require_protocol: true,
9+
require_tld: false,
910
});
1011
}
1112

@@ -17,11 +18,3 @@ export function getRegistryURL(): string {
1718
// Don't add slash if it's not a sub directory
1819
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
1920
}
20-
21-
export function getBaseNamePath(): string {
22-
return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix;
23-
}
24-
25-
export function getRootPath(): string {
26-
return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
27-
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,11 @@
17431743
resolved "https://registry.verdaccio.org/@types%2funist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
17441744
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
17451745

1746+
1747+
version "10.11.1"
1748+
resolved "https://registry.npmjs.org/@types/validator/-/validator-10.11.1.tgz#76e983ce155261838463b73728856cf8bc628d53"
1749+
integrity sha512-bVhLqvb+5xUNWRFnuuecRVISTvsG6AdhrB2kb/tChgtuTTqARqlQ3rLhOPy8cINZEUB8PkR+goyWF6fWxg4iSw==
1750+
17461751
"@types/vfile-message@*":
17471752
version "1.0.1"
17481753
resolved "https://registry.verdaccio.org/@types%2fvfile-message/-/vfile-message-1.0.1.tgz#e1e9895cc6b36c462d4244e64e6d0b6eaf65355a"

0 commit comments

Comments
 (0)