@renovatebot/osv-offline 2.5.1 → 3.0.0
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/index.d.ts +1 -1
- package/dist/index.js +2 -7
- package/dist/lib/download.d.ts +1 -1
- package/dist/lib/download.js +24 -30
- package/dist/lib/osv-offline.js +7 -14
- package/dist/lib/types.js +2 -6
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Osv, Ecosystem } from '@renovatebot/osv-offline-db';
|
|
2
|
-
export { OsvOffline } from './lib/osv-offline';
|
|
2
|
+
export { OsvOffline } from './lib/osv-offline.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.OsvOffline = exports.Osv = void 0;
|
|
4
|
-
var osv_offline_db_1 = require("@renovatebot/osv-offline-db");
|
|
5
|
-
Object.defineProperty(exports, "Osv", { enumerable: true, get: function () { return osv_offline_db_1.Osv; } });
|
|
6
|
-
var osv_offline_1 = require("./lib/osv-offline");
|
|
7
|
-
Object.defineProperty(exports, "OsvOffline", { enumerable: true, get: function () { return osv_offline_1.OsvOffline; } });
|
|
1
|
+
export { Osv } from '@renovatebot/osv-offline-db';
|
|
2
|
+
export { OsvOffline } from "./lib/osv-offline.js";
|
package/dist/lib/download.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Result } from './types';
|
|
1
|
+
import { Result } from './types.ts';
|
|
2
2
|
export declare function tryDownloadDb(): Promise<Result>;
|
package/dist/lib/download.js
CHANGED
|
@@ -1,55 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
14
|
-
const types_1 = require("./types");
|
|
15
|
-
const debug_1 = __importDefault(require("debug"));
|
|
16
|
-
const logger = (0, debug_1.default)('osv-offline:download');
|
|
17
|
-
async function tryDownloadDb() {
|
|
18
|
-
await fs_extra_1.default.ensureDir(osv_offline_db_1.OsvOfflineDb.rootDirectory);
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import got from 'got';
|
|
3
|
+
import { pipeline } from 'node:stream/promises';
|
|
4
|
+
import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { DateTime } from 'luxon';
|
|
7
|
+
import AdmZip from 'adm-zip';
|
|
8
|
+
import { failure, success } from "./types.js";
|
|
9
|
+
import debug from 'debug';
|
|
10
|
+
const logger = debug('osv-offline:download');
|
|
11
|
+
export async function tryDownloadDb() {
|
|
12
|
+
await fs.ensureDir(OsvOfflineDb.rootDirectory);
|
|
19
13
|
if (process.env.OSV_OFFLINE_DISABLE_DOWNLOAD?.toLowerCase() === 'true') {
|
|
20
14
|
logger('Skipping database download.');
|
|
21
|
-
return
|
|
15
|
+
return success();
|
|
22
16
|
}
|
|
23
17
|
// if local database exists and is less than a day old, don't do any network requests
|
|
24
18
|
let stats;
|
|
25
19
|
try {
|
|
26
|
-
stats = await
|
|
20
|
+
stats = await fs.stat(path.join(OsvOfflineDb.rootDirectory, `osv-offline.zip`));
|
|
27
21
|
}
|
|
28
22
|
catch {
|
|
29
23
|
// ignored
|
|
30
24
|
}
|
|
31
25
|
if (stats !== undefined &&
|
|
32
|
-
|
|
26
|
+
DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).as('days') < 1) {
|
|
33
27
|
logger('Skipping download, databases are up-to-date.');
|
|
34
|
-
return
|
|
28
|
+
return success();
|
|
35
29
|
}
|
|
36
30
|
// only download databases if local databases are missing or remote is newer
|
|
37
31
|
try {
|
|
38
32
|
logger('Downloading databases ...');
|
|
39
33
|
const databaseUrl = process.env.OSV_OFFLINE_DATABASE_URL ??
|
|
40
34
|
'https://github.com/renovatebot/osv-offline/releases/latest/download/osv-offline.zip';
|
|
41
|
-
const stream =
|
|
42
|
-
const zipPath =
|
|
43
|
-
const writeStream =
|
|
44
|
-
await
|
|
35
|
+
const stream = got.stream(databaseUrl);
|
|
36
|
+
const zipPath = path.join(OsvOfflineDb.rootDirectory, 'osv-offline.zip');
|
|
37
|
+
const writeStream = fs.createWriteStream(zipPath);
|
|
38
|
+
await pipeline(stream, writeStream);
|
|
45
39
|
logger('Downloading databases done.');
|
|
46
40
|
logger('Extracting databases ...');
|
|
47
|
-
const zip = new
|
|
48
|
-
zip.extractAllTo(
|
|
41
|
+
const zip = new AdmZip(zipPath);
|
|
42
|
+
zip.extractAllTo(OsvOfflineDb.rootDirectory);
|
|
49
43
|
logger('Extracting databases done.');
|
|
50
44
|
}
|
|
51
45
|
catch (err) {
|
|
52
|
-
return
|
|
46
|
+
return failure(err);
|
|
53
47
|
}
|
|
54
|
-
return
|
|
48
|
+
return success();
|
|
55
49
|
}
|
package/dist/lib/osv-offline.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.OsvOffline = void 0;
|
|
7
|
-
const osv_offline_db_1 = require("@renovatebot/osv-offline-db");
|
|
8
|
-
const download_1 = require("./download");
|
|
9
|
-
const debug_1 = __importDefault(require("debug"));
|
|
10
|
-
const logger = (0, debug_1.default)('osv-offline:download');
|
|
11
|
-
class OsvOffline {
|
|
1
|
+
import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
|
|
2
|
+
import { tryDownloadDb } from "./download.js";
|
|
3
|
+
import debug from 'debug';
|
|
4
|
+
const logger = debug('osv-offline:download');
|
|
5
|
+
export class OsvOffline {
|
|
12
6
|
osvOfflineDb;
|
|
13
7
|
constructor() {
|
|
14
8
|
logger('Initializing databases ...');
|
|
15
|
-
this.osvOfflineDb =
|
|
9
|
+
this.osvOfflineDb = OsvOfflineDb.create();
|
|
16
10
|
logger('Initializing databases done.');
|
|
17
11
|
}
|
|
18
12
|
/**
|
|
19
13
|
* Asynchronous code required as part of class instantiation
|
|
20
14
|
*/
|
|
21
15
|
static async initialize() {
|
|
22
|
-
const result = await
|
|
16
|
+
const result = await tryDownloadDb();
|
|
23
17
|
if (!result.success) {
|
|
24
18
|
throw result.error;
|
|
25
19
|
}
|
|
@@ -46,4 +40,3 @@ class OsvOffline {
|
|
|
46
40
|
this.osvOfflineDb?.[Symbol.dispose]();
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
|
-
exports.OsvOffline = OsvOffline;
|
package/dist/lib/types.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.success = success;
|
|
4
|
-
exports.failure = failure;
|
|
5
|
-
function success() {
|
|
1
|
+
export function success() {
|
|
6
2
|
return { success: true };
|
|
7
3
|
}
|
|
8
|
-
function failure(error) {
|
|
4
|
+
export function failure(error) {
|
|
9
5
|
return { success: false, error };
|
|
10
6
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renovatebot/osv-offline",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
6
5
|
"license": "MIT",
|
|
7
|
-
"type": "
|
|
6
|
+
"type": "module",
|
|
8
7
|
"publishConfig": {
|
|
9
8
|
"access": "public"
|
|
10
9
|
},
|
|
@@ -18,7 +17,7 @@
|
|
|
18
17
|
"fs-extra": "^11.3.4",
|
|
19
18
|
"got": "^15.0.3",
|
|
20
19
|
"luxon": "^3.7.2",
|
|
21
|
-
"@renovatebot/osv-offline-db": "
|
|
20
|
+
"@renovatebot/osv-offline-db": "3.0.0"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@types/adm-zip": "0.5.8",
|
|
@@ -28,6 +27,7 @@
|
|
|
28
27
|
"@types/node": "22.19.17"
|
|
29
28
|
},
|
|
30
29
|
"engines": {
|
|
31
|
-
"node": ">=22.12.0"
|
|
30
|
+
"node": ">=22.12.0",
|
|
31
|
+
"pnpm": ">=10.0.0"
|
|
32
32
|
}
|
|
33
33
|
}
|