@@ -9,6 +9,7 @@ import filenamify from "filenamify";
99import { Spinner } from "@topcli/spinner" ;
1010import * as i18n from "@nodesecure/i18n" ;
1111import * as scanner from "@nodesecure/scanner" ;
12+ import { PayloadCache } from "@nodesecure/cache" ;
1213
1314// Import Internal Dependencies
1415import kleur from "../utils/styleText.js" ;
@@ -30,10 +31,13 @@ export async function auto(spec, options) {
3031 }
3132 } ;
3233
34+ const cache = new PayloadCache ( ) ;
35+ await cache . load ( ) ;
36+
3337 const payloadFile = await (
3438 typeof spec === "string" ?
35- from ( spec , optionsWithContacts ) :
36- cwd ( optionsWithContacts )
39+ from ( spec , optionsWithContacts , cache ) :
40+ cwd ( optionsWithContacts , cache )
3741 ) ;
3842 try {
3943 if ( payloadFile !== null ) {
@@ -62,7 +66,7 @@ export async function auto(spec, options) {
6266 }
6367}
6468
65- export async function cwd ( options ) {
69+ export async function cwd ( options , cache ) {
6670 const {
6771 depth : maxDepth = Infinity ,
6872 output,
@@ -85,15 +89,30 @@ export async function cwd(options) {
8589 contacts : parseContacts ( contacts )
8690 } ,
8791 isVerbose : verbose ,
88- workers : true
92+ workers : true ,
93+ async cacheLookup ( packageJSON , integrity ) {
94+ if ( integrity === null ) {
95+ return null ;
96+ }
97+
98+ const spec = `${ packageJSON . name } @${ packageJSON . version } ` ;
99+ const cachedPayload = await cache . findByIntegrity ( integrity ) ;
100+ if ( cachedPayload !== null ) {
101+ console . log (
102+ kleur . gray ( ) . bold ( i18n . getTokenSync ( "cli.cache.found" , kleur . green ( ) . bold ( spec ) ) )
103+ ) ;
104+ }
105+
106+ return cachedPayload ;
107+ }
89108 } ,
90109 initLogger ( void 0 , ! silent )
91110 ) ;
92111
93112 return await logAndWrite ( payload , output , { local : true } ) ;
94113}
95114
96- export async function from ( spec , options ) {
115+ export async function from ( spec , options , cache ) {
97116 const {
98117 depth : maxDepth = Infinity ,
99118 output,
@@ -112,7 +131,18 @@ export async function from(spec, options) {
112131 contacts : parseContacts ( contacts )
113132 } ,
114133 isVerbose : verbose ,
115- workers : true
134+ workers : true ,
135+ async cacheLookup ( manifest ) {
136+ const spec = `${ manifest . name } @${ manifest . version } ` ;
137+ const cachedPayload = await cache . findBySpec ( spec ) ;
138+ if ( cachedPayload !== null ) {
139+ console . log (
140+ kleur . gray ( ) . bold ( i18n . getTokenSync ( "cli.cache.found" , kleur . green ( ) . bold ( spec ) ) )
141+ ) ;
142+ }
143+
144+ return cachedPayload ;
145+ }
116146 } ,
117147 initLogger ( spec , ! silent )
118148 ) ;
0 commit comments