@verdaccio/ui-components 2.0.0-6-next.7 → 2.0.0-6-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/build/Theme/ThemeProvider.js +2 -2
- package/build/components/ActionBar/ActionBar.js +2 -2
- package/build/components/ActionBar/ActionBarAction.js +9 -11
- package/build/components/Dependencies/Dependencies.js +2 -2
- package/build/components/Deprecated/Deprecated.js +3 -8
- package/build/components/Developers/Developers.js +6 -6
- package/build/components/Developers/Title.js +4 -4
- package/build/components/Developers/get-unique-developer-values.js +1 -1
- package/build/components/Distribution/Dist.js +9 -6
- package/build/components/Distribution/utils.js +0 -1
- package/build/components/Distribution/utilts.spec.js +18 -0
- package/build/components/Engines/Engines.js +9 -0
- package/build/components/HeaderInfoDialog/HeaderInfoDialog.js +3 -2
- package/build/components/Icons/License.js.map +1 -1
- package/build/components/Install/InstallListItem.js +4 -4
- package/build/components/Label/Label.js +1 -0
- package/build/components/LoginDialog/LoginDialog.js +35 -39
- package/build/components/LoginDialog/LoginDialogForm.js +1 -1
- package/build/components/NotFound/NotFound.js +1 -1
- package/build/components/Package/Package.js +16 -18
- package/build/components/Readme/Readme.js.map +1 -1
- package/build/components/Readme/Readme.spec.js.map +1 -1
- package/build/components/Search/AutoComplete/AutoComplete.js +3 -3
- package/build/components/Search/Search.js +1 -1
- package/build/components/Search/SearchItem.js +1 -1
- package/build/components/TextField/TextField.js +3 -0
- package/build/hooks/useLocalStorage.js +2 -2
- package/build/providers/AppConfigurationProvider/AppConfigurationProvider.js +2 -2
- package/build/providers/TranslatorProvider/TranslatorProvider.js +10 -12
- package/build/providers/TranslatorProvider/TranslatorProvider.spec.js +52 -0
- package/build/sections/Detail/ContainerContent.js +4 -4
- package/build/sections/Detail/Detail.js +6 -6
- package/build/sections/Footer/Footer.js +1 -1
- package/build/sections/Header/Header.js +2 -2
- package/build/sections/Header/HeaderRight.js +2 -2
- package/build/sections/Header/HeaderSettingsDialog.js +3 -2
- package/build/sections/Header/LanguageSwitch.js +3 -3
- package/build/src/components/ActionBar/ActionBarAction.d.ts +1 -34
- package/build/src/components/Author/styles.d.ts +1 -20
- package/build/src/components/Dependencies/styles.d.ts +2 -30
- package/build/src/components/Deprecated/Deprecated.d.ts +1 -11
- package/build/src/components/Developers/Developers.d.ts +1 -34
- package/build/src/components/Developers/styles.d.ts +1 -34
- package/build/src/components/Distribution/Dist.stories.d.ts +4 -1
- package/build/src/components/Distribution/styles.d.ts +3 -76
- package/build/src/components/Distribution/utils.d.ts +2 -1
- package/build/src/components/Engines/styles.d.ts +1 -21
- package/build/src/components/Help/styles.d.ts +1 -10
- package/build/src/components/Icons/Earth.d.ts +2 -2
- package/build/src/components/Icons/FileBinary.d.ts +2 -2
- package/build/src/components/Icons/Law.d.ts +2 -2
- package/build/src/components/Icons/License.d.ts +2 -2
- package/build/src/components/Icons/SvgIcon.d.ts +1 -1
- package/build/src/components/Icons/Time.d.ts +2 -2
- package/build/src/components/Icons/Version.d.ts +2 -2
- package/build/src/components/MenuItem/MenuItem.d.ts +1 -1
- package/build/src/components/Package/styles.d.ts +3 -61
- package/build/src/components/RegistryInfoDialog/styles.d.ts +1 -11
- package/build/src/components/Search/AutoComplete/styles.d.ts +1 -1
- package/build/src/components/Search/Search.d.ts +1 -1
- package/build/src/components/Search/styles.d.ts +2 -16
- package/build/src/components/TextField/TextField.d.ts +1 -1
- package/build/src/providers/TranslatorProvider/TranslatorProvider.d.ts +2 -1
- package/build/src/providers/TranslatorProvider/TranslatorProvider.spec.d.ts +1 -0
- package/build/src/sections/Header/LanguageSwitch.d.ts +3 -23
- package/build/src/sections/Header/RegistryInfoDialog/styles.d.ts +1 -11
- package/build/src/sections/Header/styles.d.ts +8 -166
- package/build/src/types/packageMeta.d.ts +6 -6
- package/build/store/models/configuration.js +11 -13
- package/build/store/models/download.js +25 -27
- package/build/store/models/login.js +33 -35
- package/build/store/models/manifest.js +34 -36
- package/build/store/models/packages.js +24 -26
- package/build/store/models/search.js +37 -39
- package/build/utils/routes.js +4 -4
- package/package.json +21 -18
- package/src/Theme/ThemeProvider.tsx +0 -1
- package/src/components/Deprecated/Deprecated.tsx +1 -1
- package/src/components/Distribution/Dist.stories.tsx +45 -2
- package/src/components/Distribution/Dist.test.tsx +33 -6
- package/src/components/Distribution/Dist.tsx +13 -5
- package/src/components/Distribution/utils.ts +3 -2
- package/src/components/Distribution/utilts.spec.ts +17 -0
- package/src/components/Package/Package.tsx +1 -1
- package/src/providers/TranslatorProvider/TranslatorProvider.spec.tsx +52 -0
- package/src/providers/TranslatorProvider/TranslatorProvider.tsx +2 -1
- package/src/providers/VersionProvider/VersionProvider.test.tsx +1 -1
- package/src/types/index.d.ts +2 -0
- package/src/types/packageMeta.ts +6 -6
- package/tsconfig.build.json +1 -0
- package/tsconfig.json +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/ui-components",
|
|
3
|
-
"version": "2.0.0-6-next.
|
|
3
|
+
"version": "2.0.0-6-next.9",
|
|
4
4
|
"description": "theme ui component",
|
|
5
5
|
"author": "Juan Picado <juanpicado19@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,19 +8,23 @@
|
|
|
8
8
|
"main": "./build/index.js",
|
|
9
9
|
"types": "build/index.d.ts",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@emotion/react": "^11.10.
|
|
12
|
-
"@emotion/styled": "^11.10.
|
|
13
|
-
"@mui/icons-material": "5.11.
|
|
14
|
-
"@mui/material": "5.
|
|
15
|
-
"@mui/styles": "5.
|
|
11
|
+
"@emotion/react": "^11.10.6",
|
|
12
|
+
"@emotion/styled": "^11.10.6",
|
|
13
|
+
"@mui/icons-material": "5.11.16",
|
|
14
|
+
"@mui/material": "5.12.0",
|
|
15
|
+
"@mui/styles": "5.12.0",
|
|
16
|
+
"@mui/system": "5.12.0",
|
|
16
17
|
"@rematch/core": "2.2.0",
|
|
17
18
|
"@rematch/loading": "2.1.2",
|
|
18
19
|
"@rematch/persist": "2.1.2",
|
|
19
|
-
"@
|
|
20
|
+
"@fontsource/material-icons": "^4.5.4",
|
|
21
|
+
"@fontsource/roboto": "^4.5.8",
|
|
22
|
+
"country-flag-icons": "1.5.5",
|
|
20
23
|
"dayjs": "1.11.7",
|
|
21
24
|
"dompurify": "2.4.5",
|
|
22
25
|
"github-markdown-css": "5.1.0",
|
|
23
26
|
"highlight.js": "11.7.0",
|
|
27
|
+
"history": "4.10.1",
|
|
24
28
|
"i18next": "20.6.1",
|
|
25
29
|
"localstorage-memory": "1.0.3",
|
|
26
30
|
"lodash": "4.17.21",
|
|
@@ -28,26 +32,23 @@
|
|
|
28
32
|
"normalize.css": "8.0.1",
|
|
29
33
|
"react": "18.2.0",
|
|
30
34
|
"react-dom": "18.2.0",
|
|
35
|
+
"react-hook-form": "7.41.1",
|
|
31
36
|
"react-i18next": "12.1.1",
|
|
32
37
|
"react-json-view": "1.21.3",
|
|
38
|
+
"react-markdown": "8.0.5",
|
|
33
39
|
"react-redux": "7.2.9",
|
|
34
|
-
"react-hook-form": "7.41.1",
|
|
35
40
|
"react-router": "5.3.4",
|
|
36
41
|
"react-router-dom": "5.3.4",
|
|
37
42
|
"react-virtualized": "9.22.3",
|
|
38
|
-
"country-flag-icons": "1.5.5",
|
|
39
|
-
"history": "4.10.1",
|
|
40
|
-
"react-markdown": "8.0.5",
|
|
41
|
-
"remark-gfm": "3.0.1",
|
|
42
43
|
"redux": "4.2.1",
|
|
44
|
+
"remark-gfm": "3.0.1",
|
|
43
45
|
"validator": "13.9.0"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
48
|
+
"@verdaccio/types": "11.0.0-6-next.25",
|
|
46
49
|
"@babel/core": "^7.20.7",
|
|
47
|
-
"@emotion/babel-plugin": "11.10.
|
|
50
|
+
"@emotion/babel-plugin": "11.10.6",
|
|
48
51
|
"@emotion/jest": "11.10.5",
|
|
49
|
-
"@fontsource/material-icons": "^4.5.4",
|
|
50
|
-
"@fontsource/roboto": "^4.5.8",
|
|
51
52
|
"@storybook/addon-actions": "^6.5.15",
|
|
52
53
|
"@storybook/addon-essentials": "^6.5.15",
|
|
53
54
|
"@storybook/addon-interactions": "^6.5.15",
|
|
@@ -59,6 +60,9 @@
|
|
|
59
60
|
"@testing-library/dom": "8.19.1",
|
|
60
61
|
"@testing-library/jest-dom": "5.16.5",
|
|
61
62
|
"@testing-library/react": "13.4.0",
|
|
63
|
+
"@types/hast": "^2.0.0",
|
|
64
|
+
"@types/react-router": "^5.1.20",
|
|
65
|
+
"@types/unist": "^2.0.0",
|
|
62
66
|
"babel-loader": "^8.3.0",
|
|
63
67
|
"mockdate": "3.0.5",
|
|
64
68
|
"msw": "0.49.2"
|
|
@@ -74,8 +78,7 @@
|
|
|
74
78
|
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
|
75
79
|
"build:js": "babel src/ --out-dir build/ --copy-files --no-copy-ignored --extensions \".ts,.tsx\" --source-maps --ignore \"src/**/*.stories.tsx\" --ignore \"src/**/*.test.tsx\" --ignore \"src/**/*.test.ts\"",
|
|
76
80
|
"build": "pnpm run build:js && pnpm run build:types",
|
|
77
|
-
"
|
|
81
|
+
"start": "start-storybook -p 6006 -s ./public",
|
|
78
82
|
"build-storybook": "build-storybook"
|
|
79
|
-
}
|
|
80
|
-
"readme": "# UI Components\n\nA collection of components ready to use for building complex user interfaces.\n\n- `components`: Independent components to use to build different layouts, all components are based on [MUI (Material UI)](https://mui.com/).\n- `providers`: Providers are useful components that uses the React [`Context`](https://reactjs.org/docs/context.html), for instance, the `VersionProvider` connects the Redux store with independent components. The `AppConfigurationProvider` is able to read the\n- `store`: The Redux store powered by [`Rematch`](https://rematchjs.org), could be used with the global object `__VERDACCIO_BASENAME_UI_OPTIONS` that verdaccio uses to provide the UI configuration.\n- `theme`: The `ThemeProvider` is an abstraction of the _material-ui_ theme provider.\n- `sections`: A group of components to setup quickly sections of the application, like the sidebar, header of footer.\n- `layouts`: Are the combination of one or more sections ready to use.\n- `hooks`: A collection of useful React hooks.\n\n```bash\nnpm i -D @verdaccio/ui-components@6-next\n```\n\n## Requirements\n\nThe set of components requires libraries available in a project:\n\n- React >17\n- Material UI >5.x\n- Redux >4.x\n- Emotion >11\n- i18next >20.x\n- TypeScript is optional but recommended.\n\n### The store\n\nAll components assume there is a Redux storage, thus a `<Provider/>` wrap is the required that wrap the application.\n\n```jsx\nimport { store } from '@verdaccio/ui-components';\n\n<Provider store={store}>....APP</Provider>;\n```\n\nThe default storage is powered by Rematch and contains the required `dispatch` to fetch data from the registry.\n\n- Fetch all private packages\n\n```jsx\nimport { useDispatch, useSelector } from 'react-redux';\n\nconst packages = useSelector((state: RootState) => state.packages.response);\nuseEffect(() => {\n dispatch.packages.getPackages();\n}, [dispatch]);\n```\n\n## How to use it\n\n```jsx\nimport React from 'react';\nimport { Route, Router, Switch } from 'react-router-dom';\nimport { Provider } from 'react-redux';\nimport {\n Home,\n store,\n Loading,\n NotFound,\n Route as Routes,\n TranslatorProvider,\n VersionProvider,\n loadable,\n} from '@verdaccio/ui-components';\n\n// to enable webpack code splitting\nconst VersionPage = loadable(() => import('../pages/Version'));\n\nconst App: React.FC = () => {\n // configuration from config.yaml\n const { configOptions } = useConfig();\n const listLanguages = [{lng: 'en-US', icon: <someSVGIcon>, menuKey: 'lng.english'}];\n return (\n <Provider store={store}>\n <AppConfigurationProvider>\n <ThemeProvider>\n <TranslatorProvider i18n={i18n} listLanguages={listLanguages} onMount={() => {}}>\n <Suspense fallback={<Loading />}>\n <Router history={history}>\n <Header HeaderInfoDialog={CustomInfoDialog} />\n <Switch>\n <Route exact={true} path={Routes.ROOT}>\n <Home />\n </Route>\n <Route exact={true} path={Routes.SCOPE_PACKAGE}>\n <VersionProvider>\n <VersionPage />\n </VersionProvider>\n </Route>\n </Switch>\n </Router>\n {configOptions.showFooter && <Footer />}\n </Suspense>\n </TranslatorProvider>\n </ThemeProvider>\n </AppConfigurationProvider>\n </Provider>\n );\n};\n``\n```\n"
|
|
83
|
+
}
|
|
81
84
|
}
|
|
@@ -30,7 +30,6 @@ const ThemeProvider: React.FC<{ children: any }> = ({ children }) => {
|
|
|
30
30
|
const themeMode: ThemeMode = isDarkMode ? 'dark' : 'light';
|
|
31
31
|
|
|
32
32
|
const currentTheme = getTheme(themeMode, configOptions.primaryColor);
|
|
33
|
-
|
|
34
33
|
return (
|
|
35
34
|
<ThemeContext.Provider value={{ isDarkMode, setIsDarkMode }}>
|
|
36
35
|
<StyledEngineProvider injectFirst={true}>
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
title: 'Dist',
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export const
|
|
9
|
+
export const AllProperties: any = () => (
|
|
10
10
|
<Dist
|
|
11
11
|
packageMeta={{
|
|
12
12
|
latest: {
|
|
@@ -16,7 +16,50 @@ export const DistFileAll: any = () => (
|
|
|
16
16
|
fileCount: 7,
|
|
17
17
|
unpackedSize: 10,
|
|
18
18
|
},
|
|
19
|
-
license: '',
|
|
19
|
+
license: 'MIT',
|
|
20
|
+
},
|
|
21
|
+
_uplinks: {},
|
|
22
|
+
}}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const NoFileSize: any = () => (
|
|
27
|
+
<Dist
|
|
28
|
+
packageMeta={{
|
|
29
|
+
latest: {
|
|
30
|
+
name: 'verdaccio1',
|
|
31
|
+
version: '4.0.0',
|
|
32
|
+
dist: {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
fileCount: undefined,
|
|
35
|
+
unpackedSize: 10,
|
|
36
|
+
},
|
|
37
|
+
license: 'MIT',
|
|
38
|
+
},
|
|
39
|
+
_uplinks: {},
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const OnlyLicense: any = () => (
|
|
45
|
+
<Dist
|
|
46
|
+
packageMeta={{
|
|
47
|
+
latest: {
|
|
48
|
+
name: 'verdaccio1',
|
|
49
|
+
version: '4.0.0',
|
|
50
|
+
license: { type: 'MIT' },
|
|
51
|
+
},
|
|
52
|
+
_uplinks: {},
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const NoRender: any = () => (
|
|
58
|
+
<Dist
|
|
59
|
+
packageMeta={{
|
|
60
|
+
latest: {
|
|
61
|
+
name: 'verdaccio1',
|
|
62
|
+
version: '4.0.0',
|
|
20
63
|
},
|
|
21
64
|
_uplinks: {},
|
|
22
65
|
}}
|
|
@@ -14,7 +14,7 @@ describe('<Dist /> component', () => {
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
test('should render the component in default state', () => {
|
|
17
|
-
const
|
|
17
|
+
const { getByText } = render(
|
|
18
18
|
withDistComponent({
|
|
19
19
|
latest: {
|
|
20
20
|
name: 'verdaccio1',
|
|
@@ -28,11 +28,16 @@ describe('<Dist /> component', () => {
|
|
|
28
28
|
_uplinks: {},
|
|
29
29
|
})
|
|
30
30
|
);
|
|
31
|
-
expect(
|
|
31
|
+
expect(getByText('sidebar.distribution.title')).toBeInTheDocument();
|
|
32
|
+
expect(getByText('sidebar.distribution.file-count')).toBeInTheDocument();
|
|
33
|
+
expect(getByText('sidebar.distribution.size')).toBeInTheDocument();
|
|
34
|
+
expect(getByText('sidebar.distribution.size')).toBeInTheDocument();
|
|
35
|
+
expect(getByText('7', { exact: false })).toBeInTheDocument();
|
|
36
|
+
expect(getByText('10.00 Bytes', { exact: false })).toBeInTheDocument();
|
|
32
37
|
});
|
|
33
38
|
|
|
34
39
|
test('should render the component with license as string', () => {
|
|
35
|
-
const
|
|
40
|
+
const { getByText } = render(
|
|
36
41
|
withDistComponent({
|
|
37
42
|
latest: {
|
|
38
43
|
name: 'verdaccio2',
|
|
@@ -46,11 +51,11 @@ describe('<Dist /> component', () => {
|
|
|
46
51
|
_uplinks: {},
|
|
47
52
|
})
|
|
48
53
|
);
|
|
49
|
-
expect(
|
|
54
|
+
expect(getByText('MIT', { exact: false })).toBeInTheDocument();
|
|
50
55
|
});
|
|
51
56
|
|
|
52
57
|
test('should render the component with license as object', () => {
|
|
53
|
-
const
|
|
58
|
+
const { getByText } = render(
|
|
54
59
|
withDistComponent({
|
|
55
60
|
latest: {
|
|
56
61
|
name: 'verdaccio3',
|
|
@@ -67,6 +72,28 @@ describe('<Dist /> component', () => {
|
|
|
67
72
|
_uplinks: {},
|
|
68
73
|
})
|
|
69
74
|
);
|
|
70
|
-
expect(
|
|
75
|
+
expect(getByText('MIT', { exact: false })).toBeInTheDocument();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('should not render if latest is missing', () => {
|
|
79
|
+
const { queryAllByText } = render(
|
|
80
|
+
withDistComponent({
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
latest: undefined,
|
|
83
|
+
_uplinks: {},
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
expect(queryAllByText('sidebar.distribution.title')).toHaveLength(0);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('should not render if latest content is missing', () => {
|
|
90
|
+
const { queryAllByText } = render(
|
|
91
|
+
withDistComponent({
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
latest: { dist: undefined, license: undefined },
|
|
94
|
+
_uplinks: {},
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
expect(queryAllByText('sidebar.distribution.title')).toHaveLength(0);
|
|
71
98
|
});
|
|
72
99
|
});
|
|
@@ -25,23 +25,31 @@ const DistChip: FC<{ name: string; children?: React.ReactElement | string }> = (
|
|
|
25
25
|
const Dist: FC<{ packageMeta: PackageMetaInterface }> = ({ packageMeta }) => {
|
|
26
26
|
const { t } = useTranslation();
|
|
27
27
|
|
|
28
|
-
if (!packageMeta) {
|
|
28
|
+
if (!packageMeta?.latest) {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const { dist, license } = packageMeta
|
|
32
|
+
const { dist, license } = packageMeta.latest;
|
|
33
|
+
|
|
34
|
+
if (!dist && !license) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
33
37
|
|
|
34
38
|
return (
|
|
35
39
|
<List
|
|
36
40
|
subheader={<StyledText variant="subtitle1">{t('sidebar.distribution.title')}</StyledText>}
|
|
37
41
|
>
|
|
38
42
|
<DistListItem>
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
{dist?.fileCount && (
|
|
44
|
+
<DistChip name={t('sidebar.distribution.file-count')}>{`${dist.fileCount}`}</DistChip>
|
|
45
|
+
)}
|
|
46
|
+
{dist?.unpackedSize ? (
|
|
41
47
|
<DistChip name={t('sidebar.distribution.size')}>{fileSizeSI(dist.unpackedSize)}</DistChip>
|
|
42
48
|
) : null}
|
|
43
49
|
|
|
44
|
-
<DistChip name={t('sidebar.distribution.license')}>
|
|
50
|
+
<DistChip name={t('sidebar.distribution.license')}>
|
|
51
|
+
{formatLicense(license as string)}
|
|
52
|
+
</DistChip>
|
|
45
53
|
</DistListItem>
|
|
46
54
|
</List>
|
|
47
55
|
);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { LicenseInterface } from '../../types/packageMeta';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Formats license field for webui.
|
|
3
5
|
* @see https://docs.npmjs.com/files/package.json#license
|
|
4
6
|
*/
|
|
5
7
|
// License should use type License defined above, but conflicts with the unit test that provide array or empty object
|
|
6
|
-
|
|
7
|
-
export function formatLicense(license: any): string | undefined {
|
|
8
|
+
export function formatLicense(license: string | LicenseInterface): string | undefined {
|
|
8
9
|
if (typeof license === 'string') {
|
|
9
10
|
return license;
|
|
10
11
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fileSizeSI, formatLicense } from './utils';
|
|
2
|
+
|
|
3
|
+
test('formatLicense as string', () => {
|
|
4
|
+
expect(formatLicense('MIT')).toEqual('MIT');
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
test('formatLicense as format object', () => {
|
|
8
|
+
expect(formatLicense({ type: 'MIT' })).toEqual('MIT');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('fileSizeSI as number 1000', () => {
|
|
12
|
+
expect(fileSizeSI(1000)).toEqual('1.00 kB');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('fileSizeSI as number 0', () => {
|
|
16
|
+
expect(fileSizeSI(0)).toEqual('0.00 Bytes');
|
|
17
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import i18n from 'i18next';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { initReactI18next } from 'react-i18next';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
|
|
7
|
+
import TranslatorProvider, { useLanguage } from './TranslatorProvider';
|
|
8
|
+
|
|
9
|
+
i18n.use(initReactI18next).init({
|
|
10
|
+
lng: 'en-US',
|
|
11
|
+
fallbackLng: 'en-US',
|
|
12
|
+
whitelist: ['en-US'],
|
|
13
|
+
load: 'currentOnly',
|
|
14
|
+
react: {
|
|
15
|
+
useSuspense: false,
|
|
16
|
+
},
|
|
17
|
+
resources: {
|
|
18
|
+
'en-US': {
|
|
19
|
+
translation: {
|
|
20
|
+
'copy-to-clipboard': 'Copy to clipboard',
|
|
21
|
+
'author-anonymous': 'Anonymous',
|
|
22
|
+
'author-unknown': 'Unknown',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
debug: false,
|
|
27
|
+
interpolation: {
|
|
28
|
+
escapeValue: false,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const RandomComponent = () => {
|
|
33
|
+
const { language } = useLanguage();
|
|
34
|
+
const { t } = useTranslation();
|
|
35
|
+
return (
|
|
36
|
+
<div>
|
|
37
|
+
<div>{language}</div>
|
|
38
|
+
<div>{t('copy-to-clipboard')}</div>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
test('should provide translation', () => {
|
|
44
|
+
const mount = jest.fn();
|
|
45
|
+
const { getByText } = render(
|
|
46
|
+
<TranslatorProvider i18n={i18n} listLanguages={[]} onMount={mount}>
|
|
47
|
+
<RandomComponent />
|
|
48
|
+
</TranslatorProvider>
|
|
49
|
+
);
|
|
50
|
+
expect(getByText('en-US')).toBeInTheDocument();
|
|
51
|
+
expect(getByText('Copy to clipboard')).toBeInTheDocument();
|
|
52
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { i18n } from 'i18next';
|
|
1
2
|
import React, { FunctionComponent, createContext, useCallback, useContext, useEffect } from 'react';
|
|
2
3
|
import { I18nextProvider } from 'react-i18next';
|
|
3
4
|
|
|
@@ -24,7 +25,7 @@ const I18nTranslatorContext = createContext<TranslatorProviderProps>({
|
|
|
24
25
|
*/
|
|
25
26
|
const TranslatorProvider: FunctionComponent<{
|
|
26
27
|
children: React.ReactElement<any>;
|
|
27
|
-
i18n:
|
|
28
|
+
i18n: i18n;
|
|
28
29
|
listLanguages: any;
|
|
29
30
|
onMount: () => {};
|
|
30
31
|
}> = ({ children, onMount, i18n, listLanguages }) => {
|
|
@@ -16,7 +16,7 @@ function CustomComponent() {
|
|
|
16
16
|
const { packageMeta, packageName, packageVersion } = useVersion();
|
|
17
17
|
return (
|
|
18
18
|
<div>
|
|
19
|
-
<div>{packageMeta?.latest?.license}</div>
|
|
19
|
+
<div>{packageMeta?.latest?.license as string}</div>
|
|
20
20
|
<div>{packageName}</div>
|
|
21
21
|
<div>{packageVersion}</div>
|
|
22
22
|
</div>
|
package/src/types/packageMeta.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type Latest = {
|
|
|
4
4
|
author?: Author;
|
|
5
5
|
deprecated?: string;
|
|
6
6
|
name: string;
|
|
7
|
-
dist
|
|
7
|
+
dist?: {
|
|
8
8
|
fileCount: number;
|
|
9
9
|
unpackedSize: number;
|
|
10
10
|
tarball?: string;
|
|
@@ -15,7 +15,7 @@ export type Latest = {
|
|
|
15
15
|
pnpm?: string;
|
|
16
16
|
yarn?: string;
|
|
17
17
|
};
|
|
18
|
-
license?:
|
|
18
|
+
license?: undefined | LicenseInterface | string;
|
|
19
19
|
version: string;
|
|
20
20
|
homepage?: string;
|
|
21
21
|
bugs?: {
|
|
@@ -50,12 +50,12 @@ export interface Developer {
|
|
|
50
50
|
|
|
51
51
|
interface Funding {
|
|
52
52
|
type?: string;
|
|
53
|
-
url
|
|
53
|
+
url?: string;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
interface LicenseInterface {
|
|
57
|
-
type
|
|
58
|
-
url
|
|
56
|
+
export interface LicenseInterface {
|
|
57
|
+
type?: string;
|
|
58
|
+
url?: string;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export interface DistTags {
|
package/tsconfig.build.json
CHANGED