-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (35 loc) · 1015 Bytes
/
index.js
File metadata and controls
46 lines (35 loc) · 1015 Bytes
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
import findReachableUrls from 'find-reachable-urls';
import flatMappingList from './mapping.json';
import cache from '../utils/cache';
const SUPPORTED_JAVA_VERSIONS = [9, 8, 7];
export default async function (pkg) {
const targetAsPath = pkg.replace(/\./g, '/');
const isBuildIn = !!pkg.match(/^javax?/);
if (!isBuildIn) {
const url = flatMappingList[pkg];
if (url) {
return url;
}
}
const cacheKey = `java_${pkg}`;
const cacheValue = await cache.get(cacheKey);
if (cacheValue) {
return cacheValue;
}
const urls = SUPPORTED_JAVA_VERSIONS.reduce(
(memo, version) => memo.concat(
`https://docs.oracle.com/javase/${version}/docs/api/${targetAsPath}.html`,
`https://docs.oracle.com/javaee/${version}/api/${targetAsPath}.html`,
),
[],
);
const reachableUrl = await findReachableUrls(
urls,
{ firstMatch: true },
);
if (!reachableUrl) {
return undefined;
}
await cache.set(cacheKey, reachableUrl);
return reachableUrl;
}