diff --git a/src/fix-eperm.ts b/src/fix-eperm.ts index 17372a9..5e7d5fe 100644 --- a/src/fix-eperm.ts +++ b/src/fix-eperm.ts @@ -1,4 +1,4 @@ -import { promises, chmodSync, FsError } from './fs.js' +import { chmodSync, promises } from './fs.js' const { chmod } = promises export const fixEPERM = @@ -6,7 +6,7 @@ export const fixEPERM = try { return await fn(path) } catch (er) { - const fer = er as FsError + const fer = er as NodeJS.ErrnoException if (fer?.code === 'ENOENT') { return } @@ -14,7 +14,7 @@ export const fixEPERM = try { await chmod(path, 0o666) } catch (er2) { - const fer2 = er2 as FsError + const fer2 = er2 as NodeJS.ErrnoException if (fer2?.code === 'ENOENT') { return } @@ -30,7 +30,7 @@ export const fixEPERMSync = (fn: (path: string) => any) => (path: string) => { try { return fn(path) } catch (er) { - const fer = er as FsError + const fer = er as NodeJS.ErrnoException if (fer?.code === 'ENOENT') { return } @@ -38,7 +38,7 @@ export const fixEPERMSync = (fn: (path: string) => any) => (path: string) => { try { chmodSync(path, 0o666) } catch (er2) { - const fer2 = er2 as FsError + const fer2 = er2 as NodeJS.ErrnoException if (fer2?.code === 'ENOENT') { return } diff --git a/src/fs.ts b/src/fs.ts index 4ee7128..692298a 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -2,11 +2,6 @@ import fs from 'fs' -export type FsError = Error & { - code?: string - path?: string -} - // sync ones just take the sync version from node export { chmodSync, diff --git a/src/ignore-enoent.ts b/src/ignore-enoent.ts index ec1dc77..076f31c 100644 --- a/src/ignore-enoent.ts +++ b/src/ignore-enoent.ts @@ -1,4 +1,3 @@ -import { FsError } from './fs.js' export const ignoreENOENT = async (p: Promise) => p.catch(er => { @@ -11,7 +10,7 @@ export const ignoreENOENTSync = (fn: () => any) => { try { return fn() } catch (er) { - if ((er as FsError)?.code !== 'ENOENT') { + if ((er as NodeJS.ErrnoException)?.code !== 'ENOENT') { throw er } } diff --git a/src/readdir-or-error.ts b/src/readdir-or-error.ts index 82dd531..693365f 100644 --- a/src/readdir-or-error.ts +++ b/src/readdir-or-error.ts @@ -1,13 +1,13 @@ // returns an array of entries if readdir() works, // or the error that readdir() raised if not. -import { FsError, promises, readdirSync } from './fs.js' +import { promises, readdirSync } from './fs.js' const { readdir } = promises export const readdirOrError = (path: string) => - readdir(path).catch(er => er as FsError) + readdir(path).catch(er => er as NodeJS.ErrnoException) export const readdirOrErrorSync = (path: string) => { try { return readdirSync(path) } catch (er) { - return er as FsError + return er as NodeJS.ErrnoException } } diff --git a/src/retry-busy.ts b/src/retry-busy.ts index 69c4778..5f2eb3c 100644 --- a/src/retry-busy.ts +++ b/src/retry-busy.ts @@ -1,7 +1,6 @@ // note: max backoff is the maximum that any *single* backoff will do import { RimrafOptions } from '.' -import { FsError } from './fs.js' export const MAXBACKOFF = 200 export const RATE = 1.2 @@ -23,7 +22,7 @@ export const retryBusy = (fn: (path: string) => Promise) => { try { return await fn(path) } catch (er) { - const fer = er as FsError + const fer = er as NodeJS.ErrnoException if (fer?.path === path && fer?.code && codes.has(fer.code)) { backoff = Math.ceil(backoff * rate) total = backoff + total @@ -56,7 +55,7 @@ export const retryBusySync = (fn: (path: string) => any) => { try { return fn(path) } catch (er) { - const fer = er as FsError + const fer = er as NodeJS.ErrnoException if ( fer?.path === path && fer?.code && diff --git a/src/rimraf-move-remove.ts b/src/rimraf-move-remove.ts index e9b4822..821eff4 100644 --- a/src/rimraf-move-remove.ts +++ b/src/rimraf-move-remove.ts @@ -18,7 +18,6 @@ import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js' import { chmodSync, - FsError, promises as fsPromises, renameSync, rmdirSync, @@ -54,16 +53,16 @@ const unlinkFixEPERMSync = (path: string) => { try { unlinkSync(path) } catch (er) { - if ((er as FsError)?.code === 'EPERM') { + if ((er as NodeJS.ErrnoException)?.code === 'EPERM') { try { return chmodSync(path, 0o666) } catch (er2) { - if ((er2 as FsError)?.code === 'ENOENT') { + if ((er2 as NodeJS.ErrnoException)?.code === 'ENOENT') { return } throw er } - } else if ((er as FsError)?.code === 'ENOENT') { + } else if ((er as NodeJS.ErrnoException)?.code === 'ENOENT') { return } throw er diff --git a/src/rimraf-windows.ts b/src/rimraf-windows.ts index 57259ce..176f3e7 100644 --- a/src/rimraf-windows.ts +++ b/src/rimraf-windows.ts @@ -9,13 +9,13 @@ // Note: "move then remove" is 2-10 times slower, and just as unreliable. import { parse, resolve } from 'path' -import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js' +import { RimrafOptions } from '.' import { fixEPERM, fixEPERMSync } from './fix-eperm.js' +import { promises, rmdirSync, unlinkSync } from './fs.js' +import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js' import { readdirOrError, readdirOrErrorSync } from './readdir-or-error.js' import { retryBusy, retryBusySync } from './retry-busy.js' import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js' -import { FsError, promises, rmdirSync, unlinkSync } from './fs.js' -import { RimrafOptions } from '.' const { unlink, rmdir } = promises const rimrafWindowsFile = retryBusy(fixEPERM(unlink)) @@ -30,7 +30,7 @@ const rimrafWindowsDirMoveRemoveFallback = async ( try { await rimrafWindowsDir(path, opt) } catch (er) { - if ((er as FsError)?.code === 'ENOTEMPTY') { + if ((er as NodeJS.ErrnoException)?.code === 'ENOTEMPTY') { return await rimrafMoveRemove(path, opt) } throw er @@ -44,7 +44,7 @@ const rimrafWindowsDirMoveRemoveFallbackSync = ( try { rimrafWindowsDirSync(path, opt) } catch (er) { - if ((er as FsError)?.code === 'ENOTEMPTY') { + if ((er as NodeJS.ErrnoException)?.code === 'ENOTEMPTY') { return rimrafMoveRemoveSync(path, opt) } throw er