Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions i18n/english.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions i18n/french.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 36 additions & 6 deletions src/commands/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -85,15 +89,30 @@ 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)
);

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,
Expand All @@ -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)
);
Expand Down
2 changes: 1 addition & 1 deletion workspaces/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
"license": "MIT",
"dependencies": {
"@nodesecure/scanner": "10.8.0",
"@nodesecure/scanner": "10.10.0",
"cacache": "20.0.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion workspaces/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/vis-network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
},
"devDependencies": {
"@nodesecure/flags": "3.0.3",
"@nodesecure/scanner": "10.7.0"
"@nodesecure/scanner": "10.10.0"
}
}
Loading