Skip to content

Commit

Permalink
Add support for .NET Framework packages.config (OctoLinker#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
olsh authored and josephfrazier committed Jun 5, 2017
1 parent 02c0d06 commit 8b25456
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ OctoLinker is the easiest and best way to navigate between files and projects on
- `dependencies`
- `tools`

### packages.config (.NET Framework)
- `<package id="..." />`

### Go
- `import`

Expand Down
5 changes: 2 additions & 3 deletions lib/plugins/dot-net-core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import processJSON from './helper/process-json';
import { jsonRegExKeyValue } from './helper/regex-builder';
import insertLink from '../insert-link';
import nugetResolver from '../resolver/nuget';

function linkDependency(blob, key, value) {
const regex = jsonRegExKeyValue(key, value);
Expand All @@ -15,9 +16,7 @@ export default {
name: 'DotNetCore',

resolve({ target }) {
return [
`https://www.nuget.org/packages/${target}`,
];
return nugetResolver({ target });
},

getPattern() {
Expand Down
21 changes: 21 additions & 0 deletions lib/plugins/dot-net.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import nugetResolver from '../resolver/nuget';
import { NET_PACKAGE } from '../../packages/helper-grammar-regex-collection/index.js';

export default {
name: 'DotNet',

resolve({ target }) {
return nugetResolver({ target });
},

getPattern() {
return {
pathPatterns: ['/packages.config$'],
githubClasses: [],
};
},

getLinkRegexes() {
return NET_PACKAGE;
},
};
5 changes: 5 additions & 0 deletions lib/resolver/nuget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function ({ target }) {
return [
`https://www.nuget.org/packages/${target}`,
];
}
8 changes: 8 additions & 0 deletions packages/helper-grammar-regex-collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,11 @@ export const HTML_IMPORT = regex`
\s
href=${captureQuotedWord}>
`;

export const NET_PACKAGE = regex`
<\s*
package
\s*
id=${captureQuotedWord}
.*/>
`;
10 changes: 10 additions & 0 deletions packages/helper-grammar-regex-collection/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ const fixtures = {
'import (\n"octo.com/foo/bar"\n)',
],
},
NET_PACKAGE: {
valid: [
'<package id="foo" version="2.7.7.02" targetFramework="net45" />',
'< package id="foo" version="2.7.7.02" targetFramework="net45" />',
],
invalid: [
'<packages id="Antlr2.Runtime" version="2.7.7.02" targetFramework="net45" />',
'<package version="2.7.7.02" targetFramework="net45" />',
],
},
};

function fixturesIterator(fixturesList, next) {
Expand Down
18 changes: 18 additions & 0 deletions test/plugins/dot-net.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import assert from 'assert';
import dotNet from '../../lib/plugins/dot-net';

describe('dotNet', () => {
it('resolves EntityFramework to https://www.nuget.org/packages/EntityFramework', () => {
assert.deepEqual(
dotNet.resolve({ target: 'EntityFramework' }),
['https://www.nuget.org/packages/EntityFramework'],
);
});

it('resolves Stanford.NLP.CoreNLP to https://www.nuget.org/packages/Stanford.NLP.CoreNLP', () => {
assert.deepEqual(
dotNet.resolve({ target: 'Stanford.NLP.CoreNLP' }),
['https://www.nuget.org/packages/Stanford.NLP.CoreNLP'],
);
});
});

0 comments on commit 8b25456

Please sign in to comment.