Skip to content
Merged
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
26 changes: 26 additions & 0 deletions src/__tests__/formatPkg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ describe('test getRepositoryInfo', () => {
url: 'git+https://bitbucket.org/2klicdev/2klic-sdk.git',
};

const githubRepoWithDirectory = {
type: 'git',
url: 'https://github.com/facebook/react.git',
directory: './packages/react-dom',
};

const githubRepoWithPathUrlAndDirectory = {
type: 'git',
url: 'https://github.com/facebook/react/tree/master/packages/wrong',
directory: './packages/react-dom',
};

expect(getRepositoryInfo(githubRepo)).toEqual({
host: 'github.com',
user: 'webpack',
Expand All @@ -272,6 +284,20 @@ describe('test getRepositoryInfo', () => {
project: '2klic-sdk',
path: '',
});

expect(getRepositoryInfo(githubRepoWithDirectory)).toEqual({
host: 'github.com',
user: 'facebook',
project: 'react',
path: 'packages/react-dom',
});

expect(getRepositoryInfo(githubRepoWithPathUrlAndDirectory)).toEqual({
host: 'github.com',
user: 'facebook',
project: 'react',
path: 'packages/react-dom',
});
});

it('should return null if it cannot get information', () => {
Expand Down
12 changes: 10 additions & 2 deletions src/formatPkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ function getRepositoryInfo(repository) {
}

const url = typeof repository === 'string' ? repository : repository.url;
const path = typeof repository === 'string' ? '' : repository.directory || '';

if (!url) {
return null;
Expand All @@ -354,7 +355,7 @@ function getRepositoryInfo(repository) {
project,
user,
host: domain,
path: '',
path: path.replace(/^[./]+/, ''),
};
}

Expand All @@ -363,7 +364,14 @@ function getRepositoryInfo(repository) {
* https://github.com/babel/babel/tree/master/packages/babel-core
* so we need to do it
*/
return getRepositoryInfoFromHttpUrl(url);
const repositoryInfoFromUrl = getRepositoryInfoFromHttpUrl(url);
if (!repositoryInfoFromUrl) {
return null;
}
return {
...repositoryInfoFromUrl,
path: path.replace(/^[./]+/, '') || repositoryInfoFromUrl.path,
};
}

function formatUser(user) {
Expand Down