Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(format): don't transform 'repository' property when it has a child 'directory' property #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/bin-format/format.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ describe('format', () => {
expect.stringContaining(normalize('some/package.json')),
);
});
it('retains long form format for "repository" when directory property used', () => {
const disk = mockDisk();
const before = {
repository: {
url: 'git://gitlab.com/User/repo',
type: 'git',
directory: 'packages/foo',
},
};
const input = {
...DEFAULT_CONFIG,
wrappers: [createWrapper(before)],
} as ProgramInput;
const log = jest.spyOn(console, 'log').mockImplementation(() => undefined);
format(input, disk);
expect(disk.writeFileSync).not.toHaveBeenCalledWith();
expect(log).toHaveBeenCalledWith(
expect.stringMatching(/-/),
expect.stringContaining(normalize('some/package.json')),
);
});
it('uses github shorthand format for "repository"', () => {
const disk = mockDisk();
const before = {
Expand Down
2 changes: 1 addition & 1 deletion src/bin-format/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function format(input: ProgramInput, disk: Disk): void {
contents.bugs = bugsUrl;
}

if (repositoryUrl) {
if (repositoryUrl && optionalChaining?.repository?.directory == null) {
contents.repository = repositoryUrl.includes('github.com')
? repositoryUrl.replace(/^.+github\.com\//, '')
: repositoryUrl;
Expand Down