diff --git a/i18n/english.js b/i18n/english.js index cc240af2..686b2b5e 100644 --- a/i18n/english.js +++ b/i18n/english.js @@ -19,6 +19,9 @@ const cli = { executionTime: tS`The error occured at ${0} during the execution`, stack: tS`Stack: ${0}` }, + cache: { + found: tS`${0} found in the cache` + }, commands: { option_depth: "Maximum dependencies depth to fetch", option_output: "Json file output name", diff --git a/i18n/french.js b/i18n/french.js index 39176f3e..22c0a738 100644 --- a/i18n/french.js +++ b/i18n/french.js @@ -19,6 +19,9 @@ const cli = { executionTime: tS`L'erreur s'est produite à ${0} pendant l'exécution`, stack: tS`Stack: ${0}` }, + cache: { + found: tS`${0} trouvé dans le cache` + }, commands: { option_depth: "Niveau de profondeur de dépendances maximum à aller chercher", option_output: "Nom de sortie du fichier json", diff --git a/package.json b/package.json index acab3d62..760cb14f 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "@nodesecure/ossf-scorecard-sdk": "4.0.1", "@nodesecure/rc": "5.5.0", "@nodesecure/report": "4.2.2", - "@nodesecure/scanner": "10.8.0", + "@nodesecure/scanner": "10.10.0", "@nodesecure/server": "1.0.0", "@nodesecure/utils": "^2.2.0", "@nodesecure/vulnera": "3.1.0", diff --git a/src/commands/scanner.js b/src/commands/scanner.js index 44575f72..e25de274 100644 --- a/src/commands/scanner.js +++ b/src/commands/scanner.js @@ -9,6 +9,7 @@ import filenamify from "filenamify"; import { Spinner } from "@topcli/spinner"; import * as i18n from "@nodesecure/i18n"; import * as scanner from "@nodesecure/scanner"; +import { PayloadCache } from "@nodesecure/cache"; // Import Internal Dependencies import kleur from "../utils/styleText.js"; @@ -30,10 +31,13 @@ export async function auto(spec, options) { } }; + const cache = new PayloadCache(); + await cache.load(); + const payloadFile = await ( typeof spec === "string" ? - from(spec, optionsWithContacts) : - cwd(optionsWithContacts) + from(spec, optionsWithContacts, cache) : + cwd(optionsWithContacts, cache) ); try { if (payloadFile !== null) { @@ -62,7 +66,7 @@ export async function auto(spec, options) { } } -export async function cwd(options) { +export async function cwd(options, cache) { const { depth: maxDepth = Infinity, output, @@ -85,7 +89,22 @@ export async function cwd(options) { contacts: parseContacts(contacts) }, isVerbose: verbose, - workers: true + workers: true, + async cacheLookup(packageJSON, integrity) { + if (integrity === null) { + return null; + } + + const spec = `${packageJSON.name}@${packageJSON.version}`; + const cachedPayload = await cache.findByIntegrity(integrity); + if (cachedPayload !== null) { + console.log( + kleur.gray().bold(i18n.getTokenSync("cli.cache.found", kleur.green().bold(spec))) + ); + } + + return cachedPayload; + } }, initLogger(void 0, !silent) ); @@ -93,7 +112,7 @@ export async function cwd(options) { return await logAndWrite(payload, output, { local: true }); } -export async function from(spec, options) { +export async function from(spec, options, cache) { const { depth: maxDepth = Infinity, output, @@ -112,7 +131,18 @@ export async function from(spec, options) { contacts: parseContacts(contacts) }, isVerbose: verbose, - workers: true + workers: true, + async cacheLookup(manifest) { + const spec = `${manifest.name}@${manifest.version}`; + const cachedPayload = await cache.findBySpec(spec); + if (cachedPayload !== null) { + console.log( + kleur.gray().bold(i18n.getTokenSync("cli.cache.found", kleur.green().bold(spec))) + ); + } + + return cachedPayload; + } }, initLogger(spec, !silent) ); diff --git a/workspaces/cache/package.json b/workspaces/cache/package.json index cb149d28..a219ff0d 100644 --- a/workspaces/cache/package.json +++ b/workspaces/cache/package.json @@ -28,7 +28,7 @@ "author": "GENTILHOMME Thomas ", "license": "MIT", "dependencies": { - "@nodesecure/scanner": "10.8.0", + "@nodesecure/scanner": "10.10.0", "cacache": "20.0.4" }, "devDependencies": { diff --git a/workspaces/server/package.json b/workspaces/server/package.json index 3ef607e6..b989ef7e 100644 --- a/workspaces/server/package.json +++ b/workspaces/server/package.json @@ -37,7 +37,7 @@ "@nodesecure/i18n": "4.1.0", "@nodesecure/npm-registry-sdk": "4.5.2", "@nodesecure/ossf-scorecard-sdk": "4.0.1", - "@nodesecure/scanner": "10.8.0", + "@nodesecure/scanner": "10.10.0", "cacache": "20.0.4", "chokidar": "5.0.0", "find-my-way": "9.5.0", diff --git a/workspaces/vis-network/package.json b/workspaces/vis-network/package.json index 3eaf1e21..d99777ec 100644 --- a/workspaces/vis-network/package.json +++ b/workspaces/vis-network/package.json @@ -43,6 +43,6 @@ }, "devDependencies": { "@nodesecure/flags": "3.0.3", - "@nodesecure/scanner": "10.7.0" + "@nodesecure/scanner": "10.10.0" } }