1- const _ = require ( 'lodash' )
2- const os = require ( 'os' )
3- const md5 = require ( 'md5' )
4- const path = require ( 'path' )
5- const debugVerbose = require ( 'debug' ) ( 'cypress-verbose:server:util:file' )
6- const Promise = require ( 'bluebird' )
7- const lockFile = Promise . promisifyAll ( require ( 'lockfile' ) )
8- const { fs } = require ( './fs' )
9- const env = require ( './env' )
10- const exit = require ( './exit' )
11- const { default : pQueue } = require ( 'p-queue' )
1+ import _ from 'lodash'
2+ import os from 'os'
3+ import md5 from 'md5'
4+ import path from 'path'
5+ import debugModule from 'debug'
6+ import Promise from 'bluebird'
7+ import lockFileModule from 'lockfile'
8+ import { fs } from './fs'
9+ import * as env from './env'
10+ import exit from './exit'
11+ import pQueue from 'p-queue'
12+ const lockFile = Promise . promisifyAll ( lockFileModule )
13+
14+ const debugVerbose = debugModule ( 'cypress-verbose:server:util:file' )
1215
1316const DEBOUNCE_LIMIT = 1000
1417const LOCK_TIMEOUT = 2000
1518
1619function getUid ( ) {
1720 try {
18- // eslint-disable-next-line no-restricted-properties
21+ // @ts -expect-error - process.geteuid is defined
1922 return process . geteuid ( )
2023 } catch ( err ) {
2124 // process.geteuid() can fail, return a constant
@@ -24,8 +27,28 @@ function getUid () {
2427 }
2528}
2629
27- class File {
28- constructor ( options = { } ) {
30+ export class File {
31+ _lockFileDir ! : string
32+ _lockFilePath ! : string
33+ _queue ! : pQueue
34+ _cache ! : Record < string , any >
35+ _lastRead ! : number
36+ path : string
37+
38+ static noopFile = {
39+ get ( ) {
40+ return Promise . resolve ( { } )
41+ } ,
42+ set ( ) {
43+ return Promise . resolve ( )
44+ } ,
45+ transaction ( ) { } ,
46+ remove ( ) {
47+ return Promise . resolve ( )
48+ } ,
49+ }
50+
51+ constructor ( options : { path ?: string } = { } ) {
2952 if ( ! options . path ) {
3053 throw new Error ( 'Must specify path to file when creating new FileUtil()' )
3154 }
@@ -70,13 +93,13 @@ class File {
7093 get ( ...args ) {
7194 debugVerbose ( 'get values from %s' , this . path )
7295
73- return this . _get ( false , ...args )
96+ return this . _get ( false , ...( args as [ string , any ] ) )
7497 }
7598
7699 set ( ...args ) {
77100 debugVerbose ( 'set values in %s' , this . path )
78101
79- return this . _set ( false , ...args )
102+ return this . _set ( false , ...( args as [ string , any ] ) )
80103 }
81104
82105 remove ( ) {
@@ -136,6 +159,7 @@ class File {
136159 . then ( ( ) => {
137160 debugVerbose ( 'read %s' , this . path )
138161
162+ // @ts -expect-error
139163 return fs . readJsonAsync ( this . path , 'utf8' )
140164 } )
141165 . catch ( ( err ) => {
@@ -208,6 +232,7 @@ class File {
208232 . then ( ( ) => {
209233 debugVerbose ( 'write %s' , this . path )
210234
235+ // @ts -expect-error
211236 return fs . outputJsonAsync ( this . path , this . _cache , { spaces : 2 } )
212237 } )
213238 . finally ( ( ) => {
@@ -221,6 +246,7 @@ class File {
221246 debugVerbose ( 'attempt to get lock on %s' , this . path )
222247
223248 return fs
249+ // @ts -expect-error
224250 . ensureDirAsync ( this . _lockFileDir )
225251 . then ( ( ) => {
226252 // polls every 100ms up to 2000ms to obtain lock, otherwise rejects
@@ -245,18 +271,3 @@ class File {
245271 } )
246272 }
247273}
248-
249- File . noopFile = {
250- get ( ) {
251- return Promise . resolve ( { } )
252- } ,
253- set ( ) {
254- return Promise . resolve ( )
255- } ,
256- transaction ( ) { } ,
257- remove ( ) {
258- return Promise . resolve ( )
259- } ,
260- }
261-
262- module . exports = File
0 commit comments