@renovatebot/osv-offline 4.4.1 → 4.5.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 CHANGED
@@ -40,6 +40,12 @@ unzip -o osv-offline.zip -d "$OSV_OFFLINE_ROOT_DIR"
40
40
  - `OSV_OFFLINE_ROOT_DIR` needs one `<ecosystem>.nedb` per ecosystem, e.g. `npm.nedb`; the `<ecosystem>.idx.json` next to it is optional but recommended, as it makes opening the database about four times faster
41
41
  - to update while Renovate runs, extract a newer zip into a temporary directory on the same file system and move the files into `OSV_OFFLINE_ROOT_DIR`, the `.idx.json` files before the `.nedb` files, so no database is read while it's written
42
42
 
43
+ ## Logging
44
+
45
+ The packages log to the logger set with `configure({ logger })` of [`@containerbase/base`](https://www.npmjs.com/package/@containerbase/base), eg. a pino or Renovate logger.
46
+ Their messages start with `OSV:`, eg. for Renovate's `logLevelRemap`.
47
+ Without one, they log through [`debug`](https://github.com/debug-js/debug) (namespace `osv-offline:*`).
48
+
43
49
  ## License
44
50
 
45
51
  This package is licensed under [the MIT license](https://opensource.org/licenses/MIT).
@@ -1,14 +1,13 @@
1
1
  import { pipeline } from 'node:stream/promises';
2
2
  import path from 'path';
3
- import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
4
- import debug from 'debug';
3
+ import { OsvOfflineDb, createLogger } from '@renovatebot/osv-offline-db';
5
4
  import fs from 'fs-extra';
6
5
  import got from 'got';
7
6
  import { DateTime } from 'luxon';
8
7
  import ms from 'ms';
9
8
  import { failure, success } from "./types.js";
10
9
  import { extractZip } from "./unzip.js";
11
- const logger = debug('osv-offline:download');
10
+ const logger = createLogger('osv-offline:download');
12
11
  const defaultMaxAge = '1d';
13
12
  /**
14
13
  * 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.
@@ -21,7 +20,7 @@ export function getMaxAge() {
21
20
  // returns `undefined` for an invalid value, despite the type
22
21
  const maxAge = ms(value);
23
22
  if (maxAge === undefined) {
24
- logger(`Invalid OSV_OFFLINE_MAX_AGE '${value}', using ${defaultMaxAge}.`);
23
+ logger.warn(`Invalid OSV_OFFLINE_MAX_AGE '${value}', using ${defaultMaxAge}.`);
25
24
  return ms(defaultMaxAge);
26
25
  }
27
26
  return maxAge;
@@ -29,7 +28,7 @@ export function getMaxAge() {
29
28
  export async function tryDownloadDb() {
30
29
  await fs.ensureDir(OsvOfflineDb.rootDirectory);
31
30
  if (process.env.OSV_OFFLINE_DISABLE_DOWNLOAD?.toLowerCase() === 'true') {
32
- logger('Skipping database download.');
31
+ logger.debug('Skipping database download.');
33
32
  return success();
34
33
  }
35
34
  // if local database exists and is younger than the maximum age, don't do any network requests
@@ -42,22 +41,22 @@ export async function tryDownloadDb() {
42
41
  }
43
42
  if (stats !== undefined &&
44
43
  DateTime.utc().diff(DateTime.fromJSDate(stats.mtime)).toMillis() < getMaxAge()) {
45
- logger('Skipping download, databases are up-to-date.');
44
+ logger.debug('Skipping download, databases are up-to-date.');
46
45
  return success();
47
46
  }
48
47
  // only download databases if local databases are missing or remote is newer
49
48
  // download and extract into a temporary directory first, so a failed attempt leaves the current databases untouched
50
49
  const tmpDir = await fs.mkdtemp(path.join(OsvOfflineDb.rootDirectory, '.download-'));
51
50
  try {
52
- logger('Downloading databases ...');
51
+ logger.trace('Downloading databases ...');
53
52
  const databaseUrl = process.env.OSV_OFFLINE_DATABASE_URL ??
54
53
  'https://github.com/renovatebot/osv-offline/releases/latest/download/osv-offline.zip';
55
54
  const stream = got.stream(databaseUrl);
56
55
  const tmpZipPath = path.join(tmpDir, 'osv-offline.zip');
57
56
  const writeStream = fs.createWriteStream(tmpZipPath);
58
57
  await pipeline(stream, writeStream);
59
- logger('Downloading databases done.');
60
- logger('Extracting databases ...');
58
+ logger.trace('Downloading databases done.');
59
+ logger.trace('Extracting databases ...');
61
60
  const extractDir = path.join(tmpDir, 'extracted');
62
61
  await fs.ensureDir(extractDir);
63
62
  const files = await extractZip(tmpZipPath, extractDir);
@@ -67,7 +66,7 @@ export async function tryDownloadDb() {
67
66
  }
68
67
  // the zip's modification time marks the databases as up-to-date, so it's moved last
69
68
  await fs.rename(tmpZipPath, path.join(OsvOfflineDb.rootDirectory, 'osv-offline.zip'));
70
- logger('Extracting databases done.');
69
+ logger.trace('Extracting databases done.');
71
70
  }
72
71
  catch (err) {
73
72
  return failure(err);
@@ -1,8 +1,7 @@
1
- import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
2
- import debug from 'debug';
1
+ import { OsvOfflineDb, createLogger } from '@renovatebot/osv-offline-db';
3
2
  import { tryDownloadDb } from "./download.js";
4
3
  import { SplitDownloader } from "./split.js";
5
- const logger = debug('osv-offline:download');
4
+ const logger = createLogger('osv-offline:download');
6
5
  /**
7
6
  * Whether the databases are downloaded in the split format, one ecosystem at a time, instead of as one zip.
8
7
  */
@@ -13,9 +12,9 @@ export class OsvOffline {
13
12
  osvOfflineDb;
14
13
  splitDownloader = useSplitFormat() ? new SplitDownloader() : undefined;
15
14
  constructor() {
16
- logger('Initializing databases ...');
15
+ logger.trace('Initializing databases ...');
17
16
  this.osvOfflineDb = OsvOfflineDb.create();
18
- logger('Initializing databases done.');
17
+ logger.trace('Initializing databases done.');
19
18
  }
20
19
  /**
21
20
  * Asynchronous code required as part of class instantiation
package/dist/lib/split.js CHANGED
@@ -4,12 +4,11 @@ import path from 'node:path';
4
4
  import { Transform } from 'node:stream';
5
5
  import { pipeline } from 'node:stream/promises';
6
6
  import { createZstdDecompress } from 'node:zlib';
7
- import { OsvOfflineDb, getIndexFileName, parseSplitIndex, } from '@renovatebot/osv-offline-db';
8
- import debug from 'debug';
7
+ import { OsvOfflineDb, createLogger, getIndexFileName, parseSplitIndex, } from '@renovatebot/osv-offline-db';
9
8
  import fs from 'fs-extra';
10
9
  import got from 'got';
11
10
  import { getMaxAge } from "./download.js";
12
- const logger = debug('osv-offline:split');
11
+ const logger = createLogger('osv-offline:split');
13
12
  const defaultIndexUrl = 'https://renovatebot.github.io/osv-offline/v2/index.json';
14
13
  /** how long to wait before retrying a failed update, so an unreachable host isn't requested on every query */
15
14
  const retryDelay = 5 * 60 * 1000;
@@ -79,7 +78,7 @@ export class SplitDownloader {
79
78
  if (!(await this.hasDatabase(ecosystem))) {
80
79
  throw err;
81
80
  }
82
- logger(`Updating ecosystem '${ecosystem}' failed: ${String(err)}`);
81
+ logger.warn(`Updating ecosystem '${ecosystem}' failed: ${String(err)}`);
83
82
  }
84
83
  })();
85
84
  this.checked.set(ecosystem, entry);
@@ -95,7 +94,7 @@ export class SplitDownloader {
95
94
  // an mtime in the future, e.g. from clock skew, counts as outdated, so it can't extend the maximum age; a second
96
95
  // of tolerance, as file times are more precise than Date.now()
97
96
  if (stateStat && age > -1000 && age < this.maxAge && (await this.hasDatabase(ecosystem))) {
98
- logger(`Ecosystem '${ecosystem}' is up-to-date.`);
97
+ logger.trace(`Ecosystem '${ecosystem}' is up-to-date.`);
99
98
  return stateStat.mtimeMs;
100
99
  }
101
100
  try {
@@ -106,7 +105,7 @@ export class SplitDownloader {
106
105
  throw err;
107
106
  }
108
107
  // the index may be outdated, e.g. served by a caching proxy
109
- logger(`File of ecosystem '${ecosystem}' not found, retrying ...`);
108
+ logger.debug(`File of ecosystem '${ecosystem}' not found, retrying ...`);
110
109
  return await this.updateFromIndex(ecosystem, true);
111
110
  }
112
111
  }
@@ -117,7 +116,7 @@ export class SplitDownloader {
117
116
  const { value: index, fetched } = await this.getIndex(refresh);
118
117
  const files = index.ecosystems[ecosystem];
119
118
  if (!files) {
120
- logger(`No files for ecosystem '${ecosystem}' in the index.`);
119
+ logger.debug(`No files for ecosystem '${ecosystem}' in the index.`);
121
120
  return fetched;
122
121
  }
123
122
  const statePath = this.getStatePath(ecosystem);
@@ -125,12 +124,12 @@ export class SplitDownloader {
125
124
  if (state?.database === files.database.sha256 &&
126
125
  state.index === files.index.sha256 &&
127
126
  (await this.hasDatabase(ecosystem))) {
128
- logger(`Ecosystem '${ecosystem}' is unchanged.`);
127
+ logger.trace(`Ecosystem '${ecosystem}' is unchanged.`);
129
128
  // the files are as fresh as the index they were checked against
130
129
  await fs.utimes(statePath, new Date(fetched), new Date(fetched));
131
130
  return fetched;
132
131
  }
133
- logger(`Downloading ecosystem '${ecosystem}' ...`);
132
+ logger.trace(`Downloading ecosystem '${ecosystem}' ...`);
134
133
  await fs.ensureDir(OsvOfflineDb.rootDirectory);
135
134
  const tmpDir = await fs.mkdtemp(path.join(OsvOfflineDb.rootDirectory, '.download-'));
136
135
  try {
@@ -149,7 +148,7 @@ export class SplitDownloader {
149
148
  };
150
149
  await fs.writeJson(statePath, newState);
151
150
  await fs.utimes(statePath, new Date(fetched), new Date(fetched));
152
- logger(`Downloading ecosystem '${ecosystem}' done.`);
151
+ logger.trace(`Downloading ecosystem '${ecosystem}' done.`);
153
152
  return fetched;
154
153
  }
155
154
  finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renovatebot/osv-offline",
3
- "version": "4.4.1",
3
+ "version": "4.5.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,7 @@
12
12
  "access": "public"
13
13
  },
14
14
  "dependencies": {
15
- "@renovatebot/osv-offline-db": "4.4.1",
16
- "debug": "^4.4.3",
15
+ "@renovatebot/osv-offline-db": "4.5.0",
17
16
  "fs-extra": "^11.4.1",
18
17
  "got": "^15.1.0",
19
18
  "luxon": "^3.7.2",
@@ -22,7 +21,6 @@
22
21
  },
23
22
  "devDependencies": {
24
23
  "@types/adm-zip": "0.6.0",
25
- "@types/debug": "4.1.13",
26
24
  "@types/fs-extra": "11.0.4",
27
25
  "@types/luxon": "3.7.6",
28
26
  "@types/ms": "2.1.0",