@renovatebot/osv-offline 3.0.13 → 3.1.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/README.md +9 -0
- package/dist/lib/download.js +21 -2
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
[](https://github.com/renovatebot/osv-offline/actions/workflows/build.yml)
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
|
|
7
|
+
## Environment variables
|
|
8
|
+
|
|
9
|
+
| Name | Description | Default |
|
|
10
|
+
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
11
|
+
| `OSV_OFFLINE_ROOT_DIR` | Directory of the downloaded databases | `<tmpdir>/osv-offline` |
|
|
12
|
+
| `OSV_OFFLINE_DATABASE_URL` | URL of the database zip | `https://github.com/renovatebot/osv-offline/releases/latest/download/osv-offline.zip` |
|
|
13
|
+
| `OSV_OFFLINE_DISABLE_DOWNLOAD` | Set to `true` to use the databases in `OSV_OFFLINE_ROOT_DIR` without downloading them | - |
|
|
14
|
+
| `OSV_OFFLINE_MAX_AGE` | How old the downloaded databases may be before they are downloaded again, as a [`ms`](https://github.com/vercel/ms) duration, e.g. `4h` | `1d` |
|
|
15
|
+
|
|
7
16
|
## License
|
|
8
17
|
|
|
9
18
|
This package is licensed under [the MIT license](https://opensource.org/licenses/MIT).
|
package/dist/lib/download.js
CHANGED
|
@@ -4,17 +4,35 @@ import { pipeline } from 'node:stream/promises';
|
|
|
4
4
|
import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { DateTime } from 'luxon';
|
|
7
|
+
import ms from 'ms';
|
|
7
8
|
import { failure, success } from "./types.js";
|
|
8
9
|
import { extractZip } from "./unzip.js";
|
|
9
10
|
import debug from 'debug';
|
|
10
11
|
const logger = debug('osv-offline:download');
|
|
12
|
+
const defaultMaxAge = '1d';
|
|
13
|
+
/**
|
|
14
|
+
* Returns how many milliseconds old the local databases may be before they are downloaded again: `OSV_OFFLINE_MAX_AGE` (e.g. `4h`), or one day.
|
|
15
|
+
*/
|
|
16
|
+
function getMaxAge() {
|
|
17
|
+
const value = process.env.OSV_OFFLINE_MAX_AGE;
|
|
18
|
+
if (!value) {
|
|
19
|
+
return ms(defaultMaxAge);
|
|
20
|
+
}
|
|
21
|
+
// returns `undefined` for an invalid value, despite the type
|
|
22
|
+
const maxAge = ms(value);
|
|
23
|
+
if (maxAge === undefined) {
|
|
24
|
+
logger(`Invalid OSV_OFFLINE_MAX_AGE '${value}', using ${defaultMaxAge}.`);
|
|
25
|
+
return ms(defaultMaxAge);
|
|
26
|
+
}
|
|
27
|
+
return maxAge;
|
|
28
|
+
}
|
|
11
29
|
export async function tryDownloadDb() {
|
|
12
30
|
await fs.ensureDir(OsvOfflineDb.rootDirectory);
|
|
13
31
|
if (process.env.OSV_OFFLINE_DISABLE_DOWNLOAD?.toLowerCase() === 'true') {
|
|
14
32
|
logger('Skipping database download.');
|
|
15
33
|
return success();
|
|
16
34
|
}
|
|
17
|
-
// if local database exists and is
|
|
35
|
+
// if local database exists and is younger than the maximum age, don't do any network requests
|
|
18
36
|
let stats;
|
|
19
37
|
try {
|
|
20
38
|
stats = await fs.stat(path.join(OsvOfflineDb.rootDirectory, `osv-offline.zip`));
|
|
@@ -23,7 +41,8 @@ export async function tryDownloadDb() {
|
|
|
23
41
|
// ignored
|
|
24
42
|
}
|
|
25
43
|
if (stats !== undefined &&
|
|
26
|
-
DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).
|
|
44
|
+
DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).toMillis() <
|
|
45
|
+
getMaxAge()) {
|
|
27
46
|
logger('Skipping download, databases are up-to-date.');
|
|
28
47
|
return success();
|
|
29
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renovatebot/osv-offline",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
"url": "https://github.com/renovatebot/osv-offline.git"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@renovatebot/osv-offline-db": "3.0
|
|
15
|
+
"@renovatebot/osv-offline-db": "3.1.0",
|
|
16
16
|
"debug": "^4.4.3",
|
|
17
17
|
"fs-extra": "^11.4.1",
|
|
18
18
|
"got": "^15.1.0",
|
|
19
19
|
"luxon": "^3.7.2",
|
|
20
|
+
"ms": "^2.1.3",
|
|
20
21
|
"yauzl": "^3.4.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
@@ -24,6 +25,7 @@
|
|
|
24
25
|
"@types/debug": "4.1.13",
|
|
25
26
|
"@types/fs-extra": "11.0.4",
|
|
26
27
|
"@types/luxon": "3.7.6",
|
|
28
|
+
"@types/ms": "2.1.0",
|
|
27
29
|
"@types/node": "22.20.5",
|
|
28
30
|
"@types/yauzl": "3.4.0",
|
|
29
31
|
"adm-zip": "0.6.1"
|