Skip to content

Commit 20e3799

Browse files
committed
use NodeJS.ErrnoException instead of FsError
1 parent 450e3d2 commit 20e3799

File tree

7 files changed

+19
-27
lines changed

7 files changed

+19
-27
lines changed

src/fix-eperm.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { promises, chmodSync, FsError } from './fs.js'
1+
import { chmodSync, promises } from './fs.js'
22
const { chmod } = promises
33

44
export const fixEPERM =
55
(fn: (path: string) => Promise<any>) => async (path: string) => {
66
try {
77
return await fn(path)
88
} catch (er) {
9-
const fer = er as FsError
9+
const fer = er as NodeJS.ErrnoException
1010
if (fer?.code === 'ENOENT') {
1111
return
1212
}
1313
if (fer?.code === 'EPERM') {
1414
try {
1515
await chmod(path, 0o666)
1616
} catch (er2) {
17-
const fer2 = er2 as FsError
17+
const fer2 = er2 as NodeJS.ErrnoException
1818
if (fer2?.code === 'ENOENT') {
1919
return
2020
}
@@ -30,15 +30,15 @@ export const fixEPERMSync = (fn: (path: string) => any) => (path: string) => {
3030
try {
3131
return fn(path)
3232
} catch (er) {
33-
const fer = er as FsError
33+
const fer = er as NodeJS.ErrnoException
3434
if (fer?.code === 'ENOENT') {
3535
return
3636
}
3737
if (fer?.code === 'EPERM') {
3838
try {
3939
chmodSync(path, 0o666)
4040
} catch (er2) {
41-
const fer2 = er2 as FsError
41+
const fer2 = er2 as NodeJS.ErrnoException
4242
if (fer2?.code === 'ENOENT') {
4343
return
4444
}

src/fs.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
import fs from 'fs'
44

5-
export type FsError = Error & {
6-
code?: string
7-
path?: string
8-
}
9-
105
// sync ones just take the sync version from node
116
export {
127
chmodSync,

src/ignore-enoent.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FsError } from './fs.js'
21

32
export const ignoreENOENT = async (p: Promise<any>) =>
43
p.catch(er => {
@@ -11,7 +10,7 @@ export const ignoreENOENTSync = (fn: () => any) => {
1110
try {
1211
return fn()
1312
} catch (er) {
14-
if ((er as FsError)?.code !== 'ENOENT') {
13+
if ((er as NodeJS.ErrnoException)?.code !== 'ENOENT') {
1514
throw er
1615
}
1716
}

src/readdir-or-error.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// returns an array of entries if readdir() works,
22
// or the error that readdir() raised if not.
3-
import { FsError, promises, readdirSync } from './fs.js'
3+
import { promises, readdirSync } from './fs.js'
44
const { readdir } = promises
55
export const readdirOrError = (path: string) =>
6-
readdir(path).catch(er => er as FsError)
6+
readdir(path).catch(er => er as NodeJS.ErrnoException)
77
export const readdirOrErrorSync = (path: string) => {
88
try {
99
return readdirSync(path)
1010
} catch (er) {
11-
return er as FsError
11+
return er as NodeJS.ErrnoException
1212
}
1313
}

src/retry-busy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// note: max backoff is the maximum that any *single* backoff will do
22

33
import { RimrafOptions } from '.'
4-
import { FsError } from './fs.js'
54

65
export const MAXBACKOFF = 200
76
export const RATE = 1.2
@@ -23,7 +22,7 @@ export const retryBusy = (fn: (path: string) => Promise<any>) => {
2322
try {
2423
return await fn(path)
2524
} catch (er) {
26-
const fer = er as FsError
25+
const fer = er as NodeJS.ErrnoException
2726
if (fer?.path === path && fer?.code && codes.has(fer.code)) {
2827
backoff = Math.ceil(backoff * rate)
2928
total = backoff + total
@@ -56,7 +55,7 @@ export const retryBusySync = (fn: (path: string) => any) => {
5655
try {
5756
return fn(path)
5857
} catch (er) {
59-
const fer = er as FsError
58+
const fer = er as NodeJS.ErrnoException
6059
if (
6160
fer?.path === path &&
6261
fer?.code &&

src/rimraf-move-remove.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'
1818

1919
import {
2020
chmodSync,
21-
FsError,
2221
promises as fsPromises,
2322
renameSync,
2423
rmdirSync,
@@ -54,16 +53,16 @@ const unlinkFixEPERMSync = (path: string) => {
5453
try {
5554
unlinkSync(path)
5655
} catch (er) {
57-
if ((er as FsError)?.code === 'EPERM') {
56+
if ((er as NodeJS.ErrnoException)?.code === 'EPERM') {
5857
try {
5958
return chmodSync(path, 0o666)
6059
} catch (er2) {
61-
if ((er2 as FsError)?.code === 'ENOENT') {
60+
if ((er2 as NodeJS.ErrnoException)?.code === 'ENOENT') {
6261
return
6362
}
6463
throw er
6564
}
66-
} else if ((er as FsError)?.code === 'ENOENT') {
65+
} else if ((er as NodeJS.ErrnoException)?.code === 'ENOENT') {
6766
return
6867
}
6968
throw er

src/rimraf-windows.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
// Note: "move then remove" is 2-10 times slower, and just as unreliable.
1010

1111
import { parse, resolve } from 'path'
12-
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'
12+
import { RimrafOptions } from '.'
1313
import { fixEPERM, fixEPERMSync } from './fix-eperm.js'
14+
import { promises, rmdirSync, unlinkSync } from './fs.js'
15+
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'
1416
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error.js'
1517
import { retryBusy, retryBusySync } from './retry-busy.js'
1618
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js'
17-
import { FsError, promises, rmdirSync, unlinkSync } from './fs.js'
18-
import { RimrafOptions } from '.'
1919
const { unlink, rmdir } = promises
2020

2121
const rimrafWindowsFile = retryBusy(fixEPERM(unlink))
@@ -30,7 +30,7 @@ const rimrafWindowsDirMoveRemoveFallback = async (
3030
try {
3131
await rimrafWindowsDir(path, opt)
3232
} catch (er) {
33-
if ((er as FsError)?.code === 'ENOTEMPTY') {
33+
if ((er as NodeJS.ErrnoException)?.code === 'ENOTEMPTY') {
3434
return await rimrafMoveRemove(path, opt)
3535
}
3636
throw er
@@ -44,7 +44,7 @@ const rimrafWindowsDirMoveRemoveFallbackSync = (
4444
try {
4545
rimrafWindowsDirSync(path, opt)
4646
} catch (er) {
47-
if ((er as FsError)?.code === 'ENOTEMPTY') {
47+
if ((er as NodeJS.ErrnoException)?.code === 'ENOTEMPTY') {
4848
return rimrafMoveRemoveSync(path, opt)
4949
}
5050
throw er

0 commit comments

Comments
 (0)