@renovatebot/osv-offline 1.5.12 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/download.d.ts +1 -1
- package/dist/lib/download.js +10 -38
- package/dist/lib/osv-offline.d.ts +1 -1
- package/dist/lib/osv-offline.js +4 -4
- package/package.json +8 -11
package/dist/lib/download.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Result } from './types';
|
|
2
|
-
export declare function tryDownloadDb(
|
|
2
|
+
export declare function tryDownloadDb(): Promise<Result>;
|
package/dist/lib/download.js
CHANGED
|
@@ -5,22 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.tryDownloadDb = tryDownloadDb;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
|
-
const rest_1 = require("@octokit/rest");
|
|
10
8
|
const got_1 = __importDefault(require("got"));
|
|
11
|
-
const
|
|
12
|
-
const util_1 = require("util");
|
|
9
|
+
const promises_1 = require("node:stream/promises");
|
|
13
10
|
const osv_offline_db_1 = require("@renovatebot/osv-offline-db");
|
|
14
11
|
const path_1 = __importDefault(require("path"));
|
|
15
12
|
const luxon_1 = require("luxon");
|
|
16
13
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
17
14
|
const types_1 = require("./types");
|
|
18
|
-
|
|
19
|
-
const baseParameters = {
|
|
20
|
-
owner: 'renovatebot',
|
|
21
|
-
repo: 'osv-offline',
|
|
22
|
-
};
|
|
23
|
-
async function tryDownloadDb(githubToken) {
|
|
15
|
+
async function tryDownloadDb() {
|
|
24
16
|
await fs_extra_1.default.ensureDir(osv_offline_db_1.OsvOfflineDb.rootDirectory);
|
|
25
17
|
if (process.env['OSV_OFFLINE_DISABLE_DOWNLOAD']?.toLowerCase() === 'true') {
|
|
26
18
|
return (0, types_1.success)();
|
|
@@ -30,44 +22,24 @@ async function tryDownloadDb(githubToken) {
|
|
|
30
22
|
try {
|
|
31
23
|
stats = await fs_extra_1.default.stat(path_1.default.join(osv_offline_db_1.OsvOfflineDb.rootDirectory, `osv-offline.zip`));
|
|
32
24
|
}
|
|
33
|
-
catch
|
|
25
|
+
catch {
|
|
34
26
|
// ignored
|
|
35
27
|
}
|
|
36
28
|
if (stats !== undefined &&
|
|
37
29
|
luxon_1.DateTime.utc().diff(luxon_1.DateTime.fromJSDate(stats.mtime)).as('days') < 1) {
|
|
38
30
|
return (0, types_1.success)();
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
auth: githubToken ?? process.env['GITHUB_COM_TOKEN'],
|
|
42
|
-
request: { fetch: node_fetch_1.default },
|
|
43
|
-
};
|
|
44
|
-
let latestRelease = null;
|
|
32
|
+
// only download databases if local databases are missing or remote is newer
|
|
45
33
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
const stream = got_1.default.stream('https://github.com/renovatebot/osv-offline/releases/latest/download/osv-offline.zip');
|
|
35
|
+
const zipPath = path_1.default.join(osv_offline_db_1.OsvOfflineDb.rootDirectory, 'osv-offline.zip');
|
|
36
|
+
const writeStream = fs_extra_1.default.createWriteStream(zipPath);
|
|
37
|
+
await (0, promises_1.pipeline)(stream, writeStream);
|
|
38
|
+
const zip = new adm_zip_1.default(zipPath);
|
|
39
|
+
zip.extractAllTo(osv_offline_db_1.OsvOfflineDb.rootDirectory);
|
|
49
40
|
}
|
|
50
41
|
catch (err) {
|
|
51
42
|
return (0, types_1.failure)(err);
|
|
52
43
|
}
|
|
53
|
-
const asset = latestRelease?.assets.find((asset) => asset.name === 'osv-offline.zip');
|
|
54
|
-
// if local database is the same size as remote database, don't download again
|
|
55
|
-
if (asset?.size === stats?.size) {
|
|
56
|
-
return (0, types_1.success)();
|
|
57
|
-
}
|
|
58
|
-
if (asset !== undefined) {
|
|
59
|
-
// only download databases if local databases are missing or remote is newer
|
|
60
|
-
try {
|
|
61
|
-
const stream = got_1.default.stream(asset.browser_download_url);
|
|
62
|
-
const zipPath = path_1.default.join(osv_offline_db_1.OsvOfflineDb.rootDirectory, asset.name);
|
|
63
|
-
const writeStream = fs_extra_1.default.createWriteStream(zipPath);
|
|
64
|
-
await pipeline(stream, writeStream);
|
|
65
|
-
const zip = new adm_zip_1.default(zipPath);
|
|
66
|
-
zip.extractAllTo(osv_offline_db_1.OsvOfflineDb.rootDirectory);
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
return (0, types_1.failure)(err);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
44
|
return (0, types_1.success)();
|
|
73
45
|
}
|
|
@@ -10,7 +10,7 @@ export declare class OsvOffline {
|
|
|
10
10
|
* Asynchronously creates a new instance of {@link OsvOffline}
|
|
11
11
|
* @returns A new instance of {@link OsvOffline}
|
|
12
12
|
*/
|
|
13
|
-
static create(
|
|
13
|
+
static create(): Promise<OsvOffline>;
|
|
14
14
|
/**
|
|
15
15
|
* Query the local database for any package vulnerabilities
|
|
16
16
|
* @param ecosystem The package ecosystem
|
package/dist/lib/osv-offline.js
CHANGED
|
@@ -10,8 +10,8 @@ class OsvOffline {
|
|
|
10
10
|
/**
|
|
11
11
|
* Asynchronous code required as part of class instantiation
|
|
12
12
|
*/
|
|
13
|
-
async initialize(
|
|
14
|
-
const result = await (0, download_1.tryDownloadDb)(
|
|
13
|
+
async initialize() {
|
|
14
|
+
const result = await (0, download_1.tryDownloadDb)();
|
|
15
15
|
if (!result.success) {
|
|
16
16
|
throw result.error;
|
|
17
17
|
}
|
|
@@ -21,9 +21,9 @@ class OsvOffline {
|
|
|
21
21
|
* Asynchronously creates a new instance of {@link OsvOffline}
|
|
22
22
|
* @returns A new instance of {@link OsvOffline}
|
|
23
23
|
*/
|
|
24
|
-
static async create(
|
|
24
|
+
static async create() {
|
|
25
25
|
const instance = new OsvOffline();
|
|
26
|
-
await instance.initialize(
|
|
26
|
+
await instance.initialize();
|
|
27
27
|
return instance;
|
|
28
28
|
}
|
|
29
29
|
/**
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renovatebot/osv-offline",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"type": "commonjs",
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"access": "public"
|
|
9
10
|
},
|
|
@@ -12,22 +13,18 @@
|
|
|
12
13
|
"url": "https://github.com/renovatebot/osv-offline.git"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"@renovatebot/osv-offline-db": "1.7.
|
|
16
|
-
"@octokit/rest": "^20.1.1",
|
|
16
|
+
"@renovatebot/osv-offline-db": "1.7.1",
|
|
17
17
|
"adm-zip": "~0.5.16",
|
|
18
18
|
"fs-extra": "^11.3.0",
|
|
19
19
|
"got": "^11.8.6",
|
|
20
|
-
"luxon": "^3.5.0"
|
|
21
|
-
"node-fetch": "^2.7.0"
|
|
20
|
+
"luxon": "^3.5.0"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@types/adm-zip": "0.5.7",
|
|
25
24
|
"@types/fs-extra": "11.0.4",
|
|
26
|
-
"@types/luxon": "3.4.2"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"ts-node": "10.9.2",
|
|
31
|
-
"typescript": "5.7.3"
|
|
25
|
+
"@types/luxon": "3.4.2"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.12.0"
|
|
32
29
|
}
|
|
33
30
|
}
|