Skip to content

Commit

Permalink
fix: change bundleDependencies to array (#4680)
Browse files Browse the repository at this point in the history
* fix: change bundleDependencies to array

* add changeset

* fixed testid
  • Loading branch information
mbtools committed Jun 14, 2024
1 parent 199aea3 commit 117eb1c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .changeset/twenty-queens-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@verdaccio/ui-theme': patch
'@verdaccio/ui-components': patch
'@verdaccio/types': patch
---

fix: change bundleDependencies to array
2 changes: 1 addition & 1 deletion packages/core/types/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface Version {
devDependencies?: Dependencies;
optionalDependencies?: Dependencies;
peerDependenciesMeta?: PeerDependenciesMeta;
bundleDependencies?: Dependencies;
bundleDependencies?: string[];
acceptDependencies?: Dependencies;
keywords?: string | string[];
nodeVersion?: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/ui-theme/src/i18n/crowdin/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
},
"dependencies": {
"has-no-dependencies": "{{package}} has no dependencies.",
"dependency-block": "{{package}}@{{version}}"
"dependency-block": "{{package}}: {{version}}",
"dependency-block-bundle": "{{package}}"
},
"form": {
"username": "Username",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ const packageMeta = {
shelljs: '^0.7.8',
'update-notifier': '^2.1.0',
},
bundleDependencies: {
'styled-components': '5.0.0',
'cross-spawn': '^5.0.1',
jscodeshift: '^0.3.30',
json5: '^0.5.1',
'latest-version': '^3.1.0',
'merge-dirs': '^0.2.1',
opencollective: '^1.0.3',
shelljs: '^0.7.8',
'update-notifier': '^2.1.0',
},
bundleDependencies: [
'styled-components',
'cross-spawn',
'jscodeshift',
'json5',
'latest-version',
'merge-dirs',
'opencollective',
'shelljs',
'update-notifier',
],
},
_uplinks: {},
};
Expand Down
35 changes: 19 additions & 16 deletions packages/ui-components/src/components/Dependencies/Dependencies.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import styled from '@emotion/styled';
import Box from '@mui/material/Box';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import React from 'react';
import React, { Fragment } from 'react';
import { useTranslation } from 'react-i18next';

import { Theme } from '../../Theme';
Expand Down Expand Up @@ -31,8 +32,8 @@ const Dependencies: React.FC<{ packageMeta: any }> = ({ packageMeta }) => {
dependencies,
devDependencies,
peerDependencies,
bundleDependencies,
optionalDependencies,
bundleDependencies,
};
const hasDependencies =
hasKeys(dependencies) ||
Expand All @@ -44,20 +45,22 @@ const Dependencies: React.FC<{ packageMeta: any }> = ({ packageMeta }) => {
return (
<CardWrap>
<CardContent>
{Object.entries(dependencyMap).map(([dependencyType, dependencies]) => {
if (!dependencies || Object.keys(dependencies).length === 0) {
return null;
}
return (
<>
<DependencyBlock
dependencies={dependencies}
key={dependencyType}
title={dependencyType}
/>
</>
);
})}
<Box data-testid="dependencies-box" sx={{ m: 2 }}>
{Object.entries(dependencyMap).map(([dependencyType, dependencies]) => {
if (!dependencies || Object.keys(dependencies).length === 0) {
return null;
}
return (
<Fragment key={dependencyType}>
<DependencyBlock
dependencies={dependencies}
key={dependencyType}
title={dependencyType}
/>
</Fragment>
);
})}
</Box>
</CardContent>
</CardWrap>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
import userEvent from '@testing-library/user-event';
import React from 'react';
import { MemoryRouter, Route } from 'react-router';

import { render, screen } from '../../test/test-react-testing-library';
import { fireEvent, render, screen } from '../../test/test-react-testing-library';
import { DependencyBlock } from './DependencyBlock';

const mockHistory = jest.fn();

jest.mock('react-router-dom', () => ({
useHistory: () => ({
push: mockHistory,
}),
}));

describe('<DependencyBlock /> component', () => {
test('renders dependency block', () => {
render(<DependencyBlock dependencies={{ jquery: '1.0.0' }} title="foo" />);

expect(screen.getByText('foo (1)')).toBeInTheDocument();
expect(screen.getByText('dependencies.dependency-block')).toBeInTheDocument();
});

userEvent.click(screen.getByText('dependencies.dependency-block'));
test('renders bundleDependencies block', () => {
render(<DependencyBlock dependencies={{ semver: '7.6.0' }} title="bundleDependencies" />);

expect(screen.getByText('bundleDependencies (1)')).toBeInTheDocument();
expect(screen.getByText('dependencies.dependency-block-bundle')).toBeInTheDocument();
});

test.todo('test the click event');
test.skip('handle change route handler', () => {
test('handle change of route', async () => {
render(
<MemoryRouter
initialEntries={[`/-/web/detail/some-dep`, `/-/web/detail/jquery`]}
Expand All @@ -28,6 +39,8 @@ describe('<DependencyBlock /> component', () => {
</MemoryRouter>
);

userEvent.click(screen.getByTestId('jquery'));
fireEvent.click(screen.getByTestId('jquery'));

await expect(mockHistory).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,38 @@ export const DependencyBlock: React.FC<DependencyBlockProps> = ({ title, depende
history.push(`/-/web/detail/${name}`);
}

function labelText(title: string, name: string, version: string): string {
if (title === 'bundleDependencies') {
return t('dependencies.dependency-block-bundle', { package: name });
} else {
return t('dependencies.dependency-block', { package: name, version });
}
}

return (
<Box data-testid={title} sx={{ margin: theme.spacing(2) }}>
<StyledText sx={{ marginBottom: theme.spacing(1) }} variant="subtitle1">
{`${title} (${deps.length})`}
</StyledText>
<Tags>
{deps.map(([name, version]) => (
<Tag
className={'dep-tag'}
clickable={true}
data-testid={name}
key={name}
label={t('dependencies.dependency-block', { package: name, version })}
// eslint-disable-next-line
onClick={() => {
handleClick(name);
}}
/>
))}
{deps.map(([name, version]: [string, string]) => {
// Bundle dependencies are stored as array, for example [ 0: "semver" ]
// so the package name arrives here in the version field
const packageName = title == 'bundleDependencies' ? version : name;
return (
<Tag
className={'dep-tag'}
clickable={true}
data-testid={packageName}
key={packageName}
label={labelText(title, packageName, version)}
// eslint-disable-next-line
onClick={() => {
handleClick(packageName);
}}
/>
);
})}
</Tags>
</Box>
);
Expand Down

0 comments on commit 117eb1c

Please sign in to comment.