@renovatebot/osv-offline-db 2.5.0 → 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 CHANGED
@@ -1,3 +1,3 @@
1
- export { OsvOfflineDb } from './lib/db';
2
- export { Ecosystem, ecosystems } from './lib/ecosystem';
3
- export * as Osv from './lib/osv';
1
+ export { OsvOfflineDb } from './lib/db.ts';
2
+ export { Ecosystem, ecosystems } from './lib/ecosystem.ts';
3
+ export * as Osv from './lib/osv.ts';
package/dist/index.js CHANGED
@@ -1,41 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Osv = exports.ecosystems = exports.OsvOfflineDb = void 0;
37
- var db_1 = require("./lib/db");
38
- Object.defineProperty(exports, "OsvOfflineDb", { enumerable: true, get: function () { return db_1.OsvOfflineDb; } });
39
- var ecosystem_1 = require("./lib/ecosystem");
40
- Object.defineProperty(exports, "ecosystems", { enumerable: true, get: function () { return ecosystem_1.ecosystems; } });
41
- exports.Osv = __importStar(require("./lib/osv"));
1
+ export { OsvOfflineDb } from "./lib/db.js";
2
+ export { ecosystems } from "./lib/ecosystem.js";
3
+ export * as Osv from "./lib/osv.js";
package/dist/lib/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Ecosystem } from './ecosystem';
2
- import type { Vulnerability } from './osv';
1
+ import { Ecosystem } from './ecosystem.ts';
2
+ import type { Vulnerability } from './osv.ts';
3
3
  export declare class OsvOfflineDb {
4
4
  private disposed;
5
5
  static readonly rootDirectory: string;
package/dist/lib/db.js CHANGED
@@ -1,22 +1,16 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OsvOfflineDb = void 0;
7
- const promises_1 = require("node:fs/promises");
8
- const node_fs_1 = require("node:fs");
9
- const node_util_1 = require("node:util");
10
- const node_path_1 = __importDefault(require("node:path"));
11
- const node_os_1 = require("node:os");
12
- const node_readline_1 = __importDefault(require("node:readline"));
13
- const purl_helper_1 = require("./purl-helper");
14
- const debug_1 = __importDefault(require("debug"));
15
- const logger = (0, debug_1.default)('osv-offline:db');
16
- const readAsync = (0, node_util_1.promisify)(node_fs_1.read);
17
- class OsvOfflineDb {
1
+ import { stat } from 'node:fs/promises';
2
+ import { closeSync, createReadStream, read as fsRead, openSync } from 'node:fs';
3
+ import { promisify } from 'node:util';
4
+ import path from 'node:path';
5
+ import { tmpdir } from 'node:os';
6
+ import readline from 'node:readline';
7
+ import { packageToPurl } from "./purl-helper.js";
8
+ import debug from 'debug';
9
+ const logger = debug('osv-offline:db');
10
+ const readAsync = promisify(fsRead);
11
+ export class OsvOfflineDb {
18
12
  disposed = false;
19
- static rootDirectory = process.env.OSV_OFFLINE_ROOT_DIR ?? node_path_1.default.join((0, node_os_1.tmpdir)(), 'osv-offline');
13
+ static rootDirectory = process.env.OSV_OFFLINE_ROOT_DIR ?? path.join(tmpdir(), 'osv-offline');
20
14
  _data = {};
21
15
  _db = {};
22
16
  _pendingAcs = new Set();
@@ -33,7 +27,7 @@ class OsvOfflineDb {
33
27
  async _load(ecosystem) {
34
28
  const cached = this._data[ecosystem];
35
29
  if (cached) {
36
- const fileStat = await (0, promises_1.stat)(cached.filePath).catch(() => null);
30
+ const fileStat = await stat(cached.filePath).catch(() => null);
37
31
  // Check if the data currently in memory is still the same object we checked against
38
32
  // If not, another request has already handled the reload/unload
39
33
  if (this._data[ecosystem] !== cached) {
@@ -56,8 +50,8 @@ class OsvOfflineDb {
56
50
  const ac = new AbortController();
57
51
  this._pendingAcs.add(ac);
58
52
  try {
59
- const filePath = node_path_1.default.join(OsvOfflineDb.rootDirectory, `${ecosystem.toLowerCase()}.nedb`);
60
- const fileStat = await (0, promises_1.stat)(filePath).catch(() => null);
53
+ const filePath = path.join(OsvOfflineDb.rootDirectory, `${ecosystem.toLowerCase()}.nedb`);
54
+ const fileStat = await stat(filePath).catch(() => null);
61
55
  if (!fileStat) {
62
56
  logger(`Missing data for ecosystem '${ecosystem}'`);
63
57
  delete this._db[ecosystem];
@@ -65,7 +59,7 @@ class OsvOfflineDb {
65
59
  }
66
60
  const data = {
67
61
  filePath,
68
- fd: (0, node_fs_1.openSync)(filePath, 'r'),
62
+ fd: openSync(filePath, 'r'),
69
63
  index: new Map(),
70
64
  mtime: fileStat.mtimeMs,
71
65
  };
@@ -85,8 +79,8 @@ class OsvOfflineDb {
85
79
  }
86
80
  }
87
81
  async _buildIndex(ac, data) {
88
- const fileStream = (0, node_fs_1.createReadStream)(data.filePath);
89
- const rl = node_readline_1.default.createInterface({
82
+ const fileStream = createReadStream(data.filePath);
83
+ const rl = readline.createInterface({
90
84
  input: fileStream,
91
85
  crlfDelay: Infinity,
92
86
  });
@@ -145,7 +139,7 @@ class OsvOfflineDb {
145
139
  }));
146
140
  if (this.disposed)
147
141
  return [];
148
- const targetPurl = (0, purl_helper_1.packageToPurl)(ecosystem, packageName);
142
+ const targetPurl = packageToPurl(ecosystem, packageName);
149
143
  return advisories.filter((vuln) => vuln.affected?.some((a) => a.package?.name === packageName &&
150
144
  (a.package.ecosystem === ecosystem ||
151
145
  a.package.ecosystem.startsWith(`${ecosystem}:`)) &&
@@ -170,11 +164,10 @@ class OsvOfflineDb {
170
164
  }
171
165
  _unload(d) {
172
166
  try {
173
- (0, node_fs_1.closeSync)(d.fd);
167
+ closeSync(d.fd);
174
168
  }
175
169
  catch {
176
170
  // ignore
177
171
  }
178
172
  }
179
173
  }
180
- exports.OsvOfflineDb = OsvOfflineDb;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ecosystems = void 0;
4
1
  // https://github.com/google/osv.dev/blob/b8ec0096f93f062993dee57f8b902f257993be88/osv/ecosystems/_ecosystems.py#L38-L68
5
- exports.ecosystems = [
2
+ export const ecosystems = [
6
3
  'crates.io',
7
4
  'Go',
8
5
  'Hackage',
package/dist/lib/osv.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1,2 @@
1
- import type { Ecosystem } from './ecosystem';
1
+ import type { Ecosystem } from './ecosystem.ts';
2
2
  export declare function packageToPurl(ecosystem: Ecosystem, packageName: string): string;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packageToPurl = packageToPurl;
4
1
  // https://github.com/google/osv.dev/blob/edacbd3c32b1d632bad8c5b506a14d0850b2e537/osv/purl_helpers.py#L18-L30
5
2
  const PURL_ECOSYSTEMS = {
6
3
  'crates.io': 'cargo',
@@ -19,7 +16,7 @@ function urlEncode(packageName) {
19
16
  const parts = packageName.split('/');
20
17
  return parts.map(encodeURIComponent).join('/');
21
18
  }
22
- function packageToPurl(ecosystem, packageName) {
19
+ export function packageToPurl(ecosystem, packageName) {
23
20
  let packageNamePurl = packageName;
24
21
  const purlType = PURL_ECOSYSTEMS[ecosystem];
25
22
  if (purlType === 'maven') {
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@renovatebot/osv-offline-db",
3
- "version": "2.5.0",
3
+ "version": "3.0.0",
4
4
  "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
5
  "license": "MIT",
7
- "type": "commonjs",
6
+ "type": "module",
8
7
  "publishConfig": {
9
8
  "access": "public"
10
9
  },
@@ -24,6 +23,7 @@
24
23
  "fs-extra": "11.3.4"
25
24
  },
26
25
  "engines": {
27
- "node": ">=22.12.0"
26
+ "node": ">=22.12.0",
27
+ "pnpm": ">=10.0.0"
28
28
  }
29
29
  }