forked from OctoLinker/OctoLinker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (52 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import insertLink from '@octolinker/helper-insert-link';
import processJSON from '@octolinker/helper-process-json';
import { isSemver } from '@octolinker/helper-version';
import { javascriptFile } from '@octolinker/plugin-javascript';
import {
jsonRegExKeyValue,
jsonRegExValue,
} from '@octolinker/helper-regex-builder';
import liveResolverQuery from '@octolinker/resolver-live-query';
import gitUrl from '@octolinker/resolver-git-url';
import githubShorthand from '@octolinker/resolver-github-shorthand';
import resolverTrustedUrl from '@octolinker/resolver-trusted-url';
function linkDependency(blob, key, value) {
const isValidSemver = isSemver(value);
const regex = jsonRegExKeyValue(key, value);
return insertLink(blob, regex, this, {
type: isValidSemver ? 'liveResolverQuery' : 'git',
});
}
function linkFile(blob, key, value) {
const regex = jsonRegExValue(key, value);
return insertLink(blob, regex, this, { type: 'file' });
}
export default {
name: 'BowerManifest',
needsContext: true,
resolve(path, [target], { type }) {
if (type === 'file') {
return javascriptFile({ target, path });
}
if (type === 'liveResolverQuery') {
return liveResolverQuery({ type: 'bower', target });
}
return [gitUrl({ target }), githubShorthand({ target })].map((url) =>
resolverTrustedUrl({ target: url }),
);
},
getPattern() {
return {
pathRegexes: [/bower\.json$/],
githubClasses: [],
};
},
parseBlob(blob) {
return processJSON(blob, this, {
'$.dependencies': linkDependency,
'$.devDependencies': linkDependency,
'$.resolutions': linkDependency,
'$.main': linkFile,
});
},
};