Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Buck committed Oct 20, 2019
1 parent fe292cc commit 9954c7f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
5 changes: 4 additions & 1 deletion packages/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ async function run(rootElement) {
}
}

const [, user, repo] = window.location.pathname.split('/');
const currentRepoSlug = `${user}/${repo}`;

matches = matches
.filter(result => result !== undefined)
.map(({ link, urls }) => {
const urlsSorted = helperSortUrls(urls, link.innerText);

return {
link,
urls: normaliseResolverResults(urlsSorted),
urls: normaliseResolverResults(urlsSorted, currentRepoSlug),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ Array [
exports[`normaliseResolverResults converts {BASE_URL}/file.js 1`] = `
Array [
Object {
"branch": undefined,
"path": undefined,
"repo": undefined,
"type": "internal-link",
"url": "https://github.com/file.js",
"user": "file.js",
"target": "https://github.com/file.js",
"type": "ping",
},
]
`;
Expand Down Expand Up @@ -65,25 +61,29 @@ Array [
exports[`normaliseResolverResults converts {BASE_URL}/foo/bar/blob/master/file.js,{BASE_URL}/foo/bar/blob/master/file.js 1`] = `
Array [
Object {
"target": "https://github.com/foo/bar/blob/master/file.js",
"type": "ping",
"branch": "master",
"path": "file.js",
"repo": "bar",
"type": "internal-link",
"url": "https://github.com/foo/bar/blob/master/file.js",
"user": "foo",
},
Object {
"target": "https://github.com/foo/bar/blob/master/file.js",
"type": "ping",
"branch": "master",
"path": "file.js",
"repo": "bar",
"type": "internal-link",
"url": "https://github.com/foo/bar/blob/master/file.js",
"user": "foo",
},
]
`;

exports[`normaliseResolverResults converts {BASE_URL}file.js 1`] = `
Array [
Object {
"branch": undefined,
"path": undefined,
"repo": undefined,
"type": "internal-link",
"url": "https://github.comfile.js",
"user": undefined,
"target": "https://github.comfile.js",
"type": "ping",
},
]
`;
Expand Down
4 changes: 2 additions & 2 deletions packages/helper-normalise-resolver-results/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ const registry = ({ registry: type, target }) => ({
target,
});

export default function(urls) {
export default function(urls, slug) {
return [].concat(urls).map(url => {
if (typeof url === 'string') {
if (url.startsWith('{BASE_URL}') && urls.length === 1) {
if (url.startsWith(`{BASE_URL}/${slug}/`)) {
return internal(url);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/helper-normalise-resolver-results/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('normaliseResolverResults', () => {
{ registry: 'npm', target: 'foo' },
() => {},
])('converts %s', url => {
expect(normaliseResolverResults([].concat(url))).toMatchSnapshot();
expect(
normaliseResolverResults([].concat(url), 'foo/bar'),
).toMatchSnapshot();
});
});

0 comments on commit 9954c7f

Please sign in to comment.