@@ -32,7 +32,7 @@ import Path from 'path';
32
32
import { Writable } from 'stream' ;
33
33
34
34
import chalk from 'chalk' ;
35
- import * as LmdbStore from 'lmdb-store ' ;
35
+ import * as LmdbStore from 'lmdb' ;
36
36
import { getMatchingRoot } from '@osd/cross-platform' ;
37
37
38
38
const GLOBAL_ATIME = `${ Date . now ( ) } ` ;
@@ -96,8 +96,8 @@ export class Cache {
96
96
// keys which haven't been used in 30 days. We use `unref()` to
97
97
// make sure this timer doesn't hold other processes open
98
98
// unexpectedly
99
- this . timer = setTimeout ( ( ) => {
100
- this . pruneOldKeys ( ) ;
99
+ this . timer = setTimeout ( async ( ) => {
100
+ await this . pruneOldKeys ( ) ;
101
101
} , 30 * MINUTE ) ;
102
102
103
103
// timer.unref is not defined in jest which emulates the dom by default
@@ -134,12 +134,13 @@ export class Cache {
134
134
async update ( path : string , file : { mtime : string ; code : string ; map : any } ) {
135
135
const key = this . getKey ( path ) ;
136
136
137
- await Promise . all ( [
138
- this . safePut ( this . atimes , key , GLOBAL_ATIME ) ,
139
- this . safePut ( this . mtimes , key , file . mtime ) ,
140
- this . safePut ( this . codes , key , file . code ) ,
141
- this . safePut ( this . sourceMaps , key , JSON . stringify ( file . map ) ) ,
142
- ] ) ;
137
+ this . safePut ( this . atimes , key , GLOBAL_ATIME ) ;
138
+ this . safePut ( this . mtimes , key , file . mtime ) ;
139
+ this . safePut ( this . codes , key , file . code ) ;
140
+
141
+ if ( file . map != null ) {
142
+ this . safePut ( this . sourceMaps , key , JSON . stringify ( file . map ) ) ;
143
+ }
143
144
}
144
145
145
146
close ( ) {
@@ -172,9 +173,9 @@ export class Cache {
172
173
}
173
174
}
174
175
175
- private async safePut < V > ( db : LmdbStore . Database < V , string > , key : string , value : V ) {
176
+ private safePut < V > ( db : LmdbStore . Database < V , string > , key : string , value : V ) {
176
177
try {
177
- await db . put ( key , value ) ;
178
+ db . putSync ( key , value ) ;
178
179
this . debug ( 'PUT' , db , key ) ;
179
180
} catch ( error ) {
180
181
this . logError ( 'PUT' , db , key , error ) ;
@@ -204,7 +205,6 @@ export class Cache {
204
205
const validKeys : string [ ] = [ ] ;
205
206
const invalidKeys : string [ ] = [ ] ;
206
207
207
- // @ts -expect-error See https://github.com/DoctorEvidence/lmdb-store/pull/18
208
208
for ( const { key, value } of this . atimes . getRange ( ) ) {
209
209
const atime = parseInt ( `${ value } ` , 10 ) ;
210
210
if ( Number . isNaN ( atime ) || atime < ATIME_LIMIT ) {
0 commit comments