diff --git a/package.json b/package.json index d05c834..bc960f4 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@types/react": "16.8.16", "@types/react-dom": "16.8.4", "@types/react-router-dom": "4.3.2", + "@types/validator": "10.11.1", "@verdaccio/babel-preset": "0.2.1", "@verdaccio/eslint-config": "0.0.1", "@verdaccio/types": "6.1.0", @@ -156,7 +157,7 @@ }, "husky": { "hooks": { - "pre-commit": "commitlint -e $GIT_PARAMS" + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, "license": "MIT", diff --git a/src/components/Header/__snapshots__/Header.test.tsx.snap b/src/components/Header/__snapshots__/Header.test.tsx.snap index 547a7a4..228f683 100644 --- a/src/components/Header/__snapshots__/Header.test.tsx.snap +++ b/src/components/Header/__snapshots__/Header.test.tsx.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`
component with logged in state should load the component in logged in state 1`] = `"
"`; +exports[`
component with logged in state should load the component in logged in state 1`] = `"
"`; -exports[`
component with logged out state should load the component in logged out state 1`] = `"
"`; +exports[`
component with logged out state should load the component in logged out state 1`] = `"
"`; diff --git a/src/components/Loading/__snapshots__/Loading.test.tsx.snap b/src/components/Loading/__snapshots__/Loading.test.tsx.snap index 5d29230..502a45a 100644 --- a/src/components/Loading/__snapshots__/Loading.test.tsx.snap +++ b/src/components/Loading/__snapshots__/Loading.test.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should render the component in default state 1`] = `"
"`; +exports[` component should render the component in default state 1`] = `"
"`; diff --git a/src/components/Logo/Logo.tsx b/src/components/Logo/Logo.tsx index b8abe82..0436255 100644 --- a/src/components/Logo/Logo.tsx +++ b/src/components/Logo/Logo.tsx @@ -23,6 +23,7 @@ const StyledLogo = styled('div')` background-repeat: no-repeat; width: ${({ size }) => size}; height: ${({ size }) => size}; + } `; const Logo: React.FC = ({ size = Size.Small }) => { return ; diff --git a/src/components/Logo/__snapshots__/Logo.test.tsx.snap b/src/components/Logo/__snapshots__/Logo.test.tsx.snap index 5a6b61a..837e012 100644 --- a/src/components/Logo/__snapshots__/Logo.test.tsx.snap +++ b/src/components/Logo/__snapshots__/Logo.test.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should render the component in default state 1`] = `"
"`; +exports[` component should render the component in default state 1`] = `"
"`; diff --git a/src/history.ts b/src/history.ts deleted file mode 100644 index a8f41b8..0000000 --- a/src/history.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { createBrowserHistory } from 'history'; -import { getBaseNamePath } from './utils/url'; - -const history = createBrowserHistory({ - basename: getBaseNamePath(), -}); - -export default history; diff --git a/src/router.tsx b/src/router.tsx index dcc0e2b..394b8ee 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -2,12 +2,16 @@ import React, { Component, ReactElement } from 'react'; import { Router, Route, Switch } from 'react-router-dom'; +import { createBrowserHistory } from 'history'; import { AppContextConsumer, AppStateInterface } from './App/App'; import { asyncComponent } from './utils/asyncComponent'; -import history from './history'; import Header from './components/Header'; +const history = createBrowserHistory({ + basename: window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix, +}); + const NotFound = asyncComponent(() => import('./components/NotFound')); const VersionPackage = asyncComponent(() => import('./pages/version/Version')); const HomePage = asyncComponent(() => import('./pages/home')); diff --git a/src/utils/url.test.ts b/src/utils/url.test.ts new file mode 100644 index 0000000..33b99b1 --- /dev/null +++ b/src/utils/url.test.ts @@ -0,0 +1,27 @@ +import { isURL, isEmail, getRegistryURL } from './url'; + +describe('url', () => { + test('isURL() - should return true for localhost', () => { + expect(isURL('http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeTruthy(); + }); + + test('isURL() - should return false when protocol is missing', () => { + expect(isURL('localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz')).toBeFalsy(); + }); + + test('isEmail() - should return true if valid', () => { + expect(isEmail('email@domain.com')).toBeTruthy(); + }); + test('isEmail() - should return false if invalid', () => { + expect(isEmail('')).toBeFalsy(); + }); + + test('getRegistryURL() - should keep slash if location is a sub directory', () => { + history.pushState({}, 'page title', '/-/web/detail'); + expect(getRegistryURL()).toBe('http://localhost/-/web/detail'); + history.pushState({}, 'page title', '/'); + }); + test('getRegistryURL() - should not add slash if location is not a sub directory', () => { + expect(getRegistryURL()).toBe('http://localhost'); + }); +}); diff --git a/src/utils/url.ts b/src/utils/url.ts index 68da74f..d428410 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -2,10 +2,11 @@ import isURLValidator from 'validator/lib/isURL'; import isEmailValidator from 'validator/lib/isEmail'; import '../../types'; -export function isURL(url): boolean { +export function isURL(url: string): boolean { return isURLValidator(url || '', { protocols: ['http', 'https', 'git+https'], require_protocol: true, + require_tld: false, }); } @@ -17,11 +18,3 @@ export function getRegistryURL(): string { // Don't add slash if it's not a sub directory return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`; } - -export function getBaseNamePath(): string { - return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix; -} - -export function getRootPath(): string { - return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.base; -} diff --git a/yarn.lock b/yarn.lock index f1b4a56..3b9815c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1743,6 +1743,11 @@ resolved "https://registry.verdaccio.org/@types%2funist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e" integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ== +"@types/validator@10.11.1": + version "10.11.1" + resolved "https://registry.npmjs.org/@types/validator/-/validator-10.11.1.tgz#76e983ce155261838463b73728856cf8bc628d53" + integrity sha512-bVhLqvb+5xUNWRFnuuecRVISTvsG6AdhrB2kb/tChgtuTTqARqlQ3rLhOPy8cINZEUB8PkR+goyWF6fWxg4iSw== + "@types/vfile-message@*": version "1.0.1" resolved "https://registry.verdaccio.org/@types%2fvfile-message/-/vfile-message-1.0.1.tgz#e1e9895cc6b36c462d4244e64e6d0b6eaf65355a" @@ -8088,9 +8093,9 @@ lockfile@1.0.4: dependencies: signal-exit "^3.0.2" -lodash._reinterpolate@~3.0.0: +lodash._reinterpolate@^3.0.0: version "3.0.0" - resolved "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" + resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= lodash.camelcase@^4.3.0: @@ -8154,9 +8159,9 @@ lodash.memoize@^4.1.2: integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4= lodash.merge@^4.6.1: - version "4.6.1" - resolved "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54" - integrity sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ== + version "4.6.2" + resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" + integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== lodash.once@^4.0.0: version "4.1.1" @@ -8174,19 +8179,19 @@ lodash.sortby@^4.7.0: integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= lodash.template@^4.0.2: - version "4.4.0" - resolved "https://registry.npmjs.org/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0" - integrity sha1-5zoDhcg1VZF0bgILmWecaQ5o+6A= + version "4.5.0" + resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab" + integrity sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A== dependencies: - lodash._reinterpolate "~3.0.0" + lodash._reinterpolate "^3.0.0" lodash.templatesettings "^4.0.0" lodash.templatesettings@^4.0.0: - version "4.1.0" - resolved "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.1.0.tgz#2b4d4e95ba440d915ff08bc899e4553666713316" - integrity sha1-K01OlbpEDZFf8IvImeRVNmZxMxY= + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz#e481310f049d3cf6d47e912ad09313b154f0fb33" + integrity sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ== dependencies: - lodash._reinterpolate "~3.0.0" + lodash._reinterpolate "^3.0.0" lodash.unescape@4.0.1: version "4.0.1"