Skip to content

Commit

Permalink
Bypass OctoLinker API for nuget urls (OctoLinker#792)
Browse files Browse the repository at this point in the history
By default OctoLinker validates external URLs via https://octolinker-api.now.sh/ to ensure the linked URL is valid and reachable. This obviously slows down the startup since OctoLinker needs to wait for the API response. There is a special resolver called `resolver-trusted-url` which allows you to opt-out from this behaviour. This is useful for documenation pages or registry urls where you can ensure the right url.
  • Loading branch information
stefanbuck authored Jan 26, 2020
1 parent 49be306 commit 938a971
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
15 changes: 9 additions & 6 deletions packages/plugin-dot-net-core/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ describe('dotNetCore', () => {
const path = '/blob/path/dummy';

it('resolves Microsoft.NETCore.App to https://www.nuget.org/packages/Microsoft.NETCore.App', () => {
expect(dotNetCore.resolve(path, ['Microsoft.NETCore.App'])).toBe(
'https://www.nuget.org/packages/Microsoft.NETCore.App',
);
expect(dotNetCore.resolve(path, ['Microsoft.NETCore.App'])).toEqual({
target: 'https://www.nuget.org/packages/Microsoft.NETCore.App',
type: 'trusted-url',
});
});

it('resolves Microsoft.Extensions.Configuration.FileExtensions to https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions', () => {
expect(
dotNetCore.resolve(path, [
'Microsoft.Extensions.Configuration.FileExtensions',
]),
).toBe(
'https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions',
);
).toEqual({
target:
'https://www.nuget.org/packages/Microsoft.Extensions.Configuration.FileExtensions',
type: 'trusted-url',
});
});
});
14 changes: 8 additions & 6 deletions packages/plugin-dot-net/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ describe('dotNet', () => {
const path = '/blob/path/dummy';

it('resolves EntityFramework to https://www.nuget.org/packages/EntityFramework', () => {
expect(dotNet.resolve(path, ['EntityFramework'])).toBe(
'https://www.nuget.org/packages/EntityFramework',
);
expect(dotNet.resolve(path, ['EntityFramework'])).toEqual({
target: 'https://www.nuget.org/packages/EntityFramework',
type: 'trusted-url',
});
});

it('resolves Stanford.NLP.CoreNLP to https://www.nuget.org/packages/Stanford.NLP.CoreNLP', () => {
expect(dotNet.resolve(path, ['Stanford.NLP.CoreNLP'])).toBe(
'https://www.nuget.org/packages/Stanford.NLP.CoreNLP',
);
expect(dotNet.resolve(path, ['Stanford.NLP.CoreNLP'])).toEqual({
target: 'https://www.nuget.org/packages/Stanford.NLP.CoreNLP',
type: 'trusted-url',
});
});
});
6 changes: 5 additions & 1 deletion packages/resolver-nuget/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import resolverTrustedUrl from '@octolinker/resolver-trusted-url';

export default function({ target }) {
return `https://www.nuget.org/packages/${target}`;
return resolverTrustedUrl({
target: `https://www.nuget.org/packages/${target}`,
});
}
5 changes: 4 additions & 1 deletion packages/resolver-nuget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"description": "",
"repository": "https://github.com/octolinker/octolinker/tree/master/packages/resolver-nuget",
"license": "MIT",
"main": "./index.js"
"main": "./index.js",
"dependencies": {
"@octolinker/resolver-trusted-url": "1.0.0"
}
}

0 comments on commit 938a971

Please sign in to comment.