Skip to content

Commit 68ce04f

Browse files
committed
formatting
1 parent 37680c5 commit 68ce04f

20 files changed

+341
-190
lines changed

map.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default test =>
22
test.startsWith('/test/integration/') ? null : (
3-
(test.endsWith('/bin.ts') ? test.replace(/\.ts$/, '.mts') : test).replace(
4-
/^test/,
5-
'src',
6-
)
3+
(test.endsWith('/bin.ts') ?
4+
test.replace(/\.ts$/, '.mts')
5+
: test
6+
).replace(/^test/, 'src')
77
)

src/bin.mts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import type { RimrafAsyncOptions } from './index.js'
33
import { rimraf } from './index.js'
44
import { loadPackageJson } from 'package-json-from-dist'
55

6-
const { version } = loadPackageJson(import.meta.url, '../package.json') as {
6+
const { version } = loadPackageJson(
7+
import.meta.url,
8+
'../package.json',
9+
) as {
710
version: string
811
}
912

@@ -57,7 +60,10 @@ const prompt = async (rl: Interface, q: string) =>
5760
new Promise<string>(res => rl.question(q, res))
5861

5962
const interactiveRimraf = async (
60-
impl: (path: string | string[], opt?: RimrafAsyncOptions) => Promise<boolean>,
63+
impl: (
64+
path: string | string[],
65+
opt?: RimrafAsyncOptions,
66+
) => Promise<boolean>,
6167
paths: string[],
6268
opt: RimrafAsyncOptions,
6369
) => {
@@ -99,7 +105,10 @@ const interactiveRimraf = async (
99105
}
100106
while (!allRemaining) {
101107
const a = (
102-
await prompt(rl, `rm? ${relative(cwd, path)}\n[(Yes)/No/All/Quit] > `)
108+
await prompt(
109+
rl,
110+
`rm? ${relative(cwd, path)}\n[(Yes)/No/All/Quit] > `,
111+
)
103112
).trim()
104113
if (/^n/i.test(a)) {
105114
return false
@@ -227,7 +236,9 @@ const main = async (...args: string[]) => {
227236
if (opt.preserveRoot !== false) {
228237
for (const path of paths.map(p => resolve(p))) {
229238
if (path === parse(path).root) {
230-
console.error(`rimraf: it is dangerous to operate recursively on '/'`)
239+
console.error(
240+
`rimraf: it is dangerous to operate recursively on '/'`,
241+
)
231242
console.error('use --no-preserve-root to override this failsafe')
232243
return 1
233244
}

src/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
} from './opt-arg.js'
88
import pathArg from './path-arg.js'
99
import { rimrafManual, rimrafManualSync } from './rimraf-manual.js'
10-
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js'
10+
import {
11+
rimrafMoveRemove,
12+
rimrafMoveRemoveSync,
13+
} from './rimraf-move-remove.js'
1114
import { rimrafNative, rimrafNativeSync } from './rimraf-native.js'
1215
import { rimrafPosix, rimrafPosixSync } from './rimraf-posix.js'
1316
import { rimrafWindows, rimrafWindowsSync } from './rimraf-windows.js'
@@ -57,13 +60,19 @@ const wrapSync =
5760
}
5861

5962
export const nativeSync = wrapSync(rimrafNativeSync)
60-
export const native = Object.assign(wrap(rimrafNative), { sync: nativeSync })
63+
export const native = Object.assign(wrap(rimrafNative), {
64+
sync: nativeSync,
65+
})
6166

6267
export const manualSync = wrapSync(rimrafManualSync)
63-
export const manual = Object.assign(wrap(rimrafManual), { sync: manualSync })
68+
export const manual = Object.assign(wrap(rimrafManual), {
69+
sync: manualSync,
70+
})
6471

6572
export const windowsSync = wrapSync(rimrafWindowsSync)
66-
export const windows = Object.assign(wrap(rimrafWindows), { sync: windowsSync })
73+
export const windows = Object.assign(wrap(rimrafWindows), {
74+
sync: windowsSync,
75+
})
6776

6877
export const posixSync = wrapSync(rimrafPosixSync)
6978
export const posix = Object.assign(wrap(rimrafPosix), { sync: posixSync })

src/opt-arg.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const isRimrafOptions = (o: any): o is RimrafOptions =>
1313
typeOrUndef(o.retryDelay, 'number') &&
1414
typeOrUndef(o.backoff, 'number') &&
1515
typeOrUndef(o.maxBackoff, 'number') &&
16-
(typeOrUndef(o.glob, 'boolean') || (o.glob && typeof o.glob === 'object')) &&
16+
(typeOrUndef(o.glob, 'boolean') ||
17+
(o.glob && typeof o.glob === 'object')) &&
1718
typeOrUndef(o.filter, 'function')
1819

1920
export const assertRimrafOptions: (o: any) => void = (

src/path-arg.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const pathArg = (path: string, opt: RimrafAsyncOptions = {}) => {
1111
: type === 'object' ? inspect(path)
1212
: `type ${type} ${path}`
1313
const msg =
14-
'The "path" argument must be of type string. ' + `Received ${received}`
14+
'The "path" argument must be of type string. ' +
15+
`Received ${received}`
1516
throw Object.assign(new TypeError(msg), {
1617
path,
1718
code: 'ERR_INVALID_ARG_TYPE',
@@ -31,7 +32,8 @@ const pathArg = (path: string, opt: RimrafAsyncOptions = {}) => {
3132
const { root } = parse(path)
3233

3334
if (path === root && opt.preserveRoot !== false) {
34-
const msg = 'refusing to remove root directory without preserveRoot:false'
35+
const msg =
36+
'refusing to remove root directory without preserveRoot:false'
3537
throw Object.assign(new Error(msg), {
3638
path,
3739
code: 'ERR_PRESERVE_ROOT',

src/rimraf-move-remove.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
import { basename, parse, resolve } from 'path'
1515
import { defaultTmp, defaultTmpSync } from './default-tmp.js'
1616
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'
17-
import { lstatSync, promises, renameSync, rmdirSync, unlinkSync } from './fs.js'
17+
import {
18+
lstatSync,
19+
promises,
20+
renameSync,
21+
rmdirSync,
22+
unlinkSync,
23+
} from './fs.js'
1824
import { Dirent, Stats } from 'fs'
1925
import { RimrafAsyncOptions, RimrafSyncOptions } from './index.js'
2026
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error.js'
@@ -23,7 +29,8 @@ import { errorCode } from './error.js'
2329
const { lstat, rename, unlink, rmdir } = promises
2430

2531
// crypto.randomBytes is much slower, and Math.random() is enough here
26-
const uniqueFilename = (path: string) => `.${basename(path)}.${Math.random()}`
32+
const uniqueFilename = (path: string) =>
33+
`.${basename(path)}.${Math.random()}`
2734

2835
const unlinkFixEPERM = fixEPERM(unlink)
2936
const unlinkFixEPERMSync = fixEPERMSync(unlinkSync)
@@ -112,7 +119,10 @@ const tmpUnlink = async <T>(
112119
return await rm(tmpFile)
113120
}
114121

115-
export const rimrafMoveRemoveSync = (path: string, opt: RimrafSyncOptions) => {
122+
export const rimrafMoveRemoveSync = (
123+
path: string,
124+
opt: RimrafSyncOptions,
125+
) => {
116126
opt?.signal?.throwIfAborted()
117127
return (
118128
ignoreENOENTSync(() =>

src/rimraf-posix.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'
1313
import { errorCode } from './error.js'
1414
const { lstat, rmdir, unlink } = promises
1515

16-
export const rimrafPosix = async (path: string, opt: RimrafAsyncOptions) => {
16+
export const rimrafPosix = async (
17+
path: string,
18+
opt: RimrafAsyncOptions,
19+
) => {
1720
opt?.signal?.throwIfAborted()
1821
return (
1922
(await ignoreENOENT(
@@ -25,8 +28,9 @@ export const rimrafPosix = async (path: string, opt: RimrafAsyncOptions) => {
2528
export const rimrafPosixSync = (path: string, opt: RimrafSyncOptions) => {
2629
opt?.signal?.throwIfAborted()
2730
return (
28-
ignoreENOENTSync(() => rimrafPosixDirSync(path, opt, lstatSync(path))) ??
29-
true
31+
ignoreENOENTSync(() =>
32+
rimrafPosixDirSync(path, opt, lstatSync(path)),
33+
) ?? true
3034
)
3135
}
3236

@@ -59,7 +63,9 @@ const rimrafPosixDir = async (
5963

6064
const removedAll = (
6165
await Promise.all(
62-
entries.map(ent => rimrafPosixDir(resolve(path, ent.name), opt, ent)),
66+
entries.map(ent =>
67+
rimrafPosixDir(resolve(path, ent.name), opt, ent),
68+
),
6369
)
6470
).every(v => v === true)
6571

src/rimraf-windows.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import { lstatSync, promises, rmdirSync, unlinkSync } from './fs.js'
1616
import { ignoreENOENT, ignoreENOENTSync } from './ignore-enoent.js'
1717
import { readdirOrError, readdirOrErrorSync } from './readdir-or-error.js'
1818
import { retryBusy, retryBusySync } from './retry-busy.js'
19-
import { rimrafMoveRemove, rimrafMoveRemoveSync } from './rimraf-move-remove.js'
19+
import {
20+
rimrafMoveRemove,
21+
rimrafMoveRemoveSync,
22+
} from './rimraf-move-remove.js'
2023
import { errorCode } from './error.js'
2124
const { unlink, rmdir, lstat } = promises
2225

@@ -66,7 +69,10 @@ const START = Symbol('start')
6669
const CHILD = Symbol('child')
6770
const FINISH = Symbol('finish')
6871

69-
export const rimrafWindows = async (path: string, opt: RimrafAsyncOptions) => {
72+
export const rimrafWindows = async (
73+
path: string,
74+
opt: RimrafAsyncOptions,
75+
) => {
7076
opt?.signal?.throwIfAborted()
7177
return (
7278
(await ignoreENOENT(
@@ -75,7 +81,10 @@ export const rimrafWindows = async (path: string, opt: RimrafAsyncOptions) => {
7581
)
7682
}
7783

78-
export const rimrafWindowsSync = (path: string, opt: RimrafSyncOptions) => {
84+
export const rimrafWindowsSync = (
85+
path: string,
86+
opt: RimrafSyncOptions,
87+
) => {
7988
opt?.signal?.throwIfAborted()
8089
return (
8190
ignoreENOENTSync(() =>
@@ -187,7 +196,9 @@ const rimrafWindowsDirSync = (
187196
if (opt.filter && !opt.filter(path, ent)) {
188197
return false
189198
}
190-
ignoreENOENTSync(() => rimrafWindowsDirMoveRemoveFallbackSync(path, opt))
199+
ignoreENOENTSync(() =>
200+
rimrafWindowsDirMoveRemoveFallbackSync(path, opt),
201+
)
191202
}
192203
return true
193204
}

test/bin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { RimrafOptions } from '../src/index.js'
55
import { basename, join, resolve } from 'path'
66
import { loadPackageJson } from 'package-json-from-dist'
77

8-
const { version } = loadPackageJson(import.meta.url, '../package.json') as {
8+
const { version } = loadPackageJson(
9+
import.meta.url,
10+
'../package.json',
11+
) as {
912
version: string
1013
}
1114

test/fs.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ type MockCb = (e: Error | null, m?: string) => void
1313
type MockFsCb = Record<string, (cb: MockCb) => void>
1414
type MockFsPromise = Record<string, () => Promise<void>>
1515

16-
const mockFs = async (t: Test, fs: MockFsCb = {}, fsp: MockFsPromise = {}) =>
16+
const mockFs = async (
17+
t: Test,
18+
fs: MockFsCb = {},
19+
fsp: MockFsPromise = {},
20+
) =>
1721
(await t.mockImport('../src/fs.js', {
1822
fs: t.createMock(realFS, fs),
1923
'fs/promises': t.createMock(realFSP, fsp),
@@ -24,19 +28,17 @@ const mockFSMethodPass =
2428
(...args: unknown[]) => {
2529
process.nextTick(() => (args.at(-1) as MockCb)(null, method))
2630
}
27-
const mockFSPromiseMethodPass =
28-
(_method: string) =>
29-
() => new Promise<void>((resolve, _reject) => {
31+
const mockFSPromiseMethodPass = (_method: string) => () =>
32+
new Promise<void>((resolve, _reject) => {
3033
resolve()
3134
})
3235
const mockFSMethodFail =
3336
(_: string) =>
3437
(...args: unknown[]) => {
3538
process.nextTick(() => (args.at(-1) as MockCb)(new Error('oops')))
3639
}
37-
const mockFSPromiseMethodFail =
38-
(_method: string) =>
39-
() => new Promise<void>((_resolve, reject) => {
40+
const mockFSPromiseMethodFail = (_method: string) => () =>
41+
new Promise<void>((_resolve, reject) => {
4042
reject(new Error('oops'))
4143
})
4244

@@ -47,7 +49,6 @@ const mockFSPromisesFail: MockFsPromise = {}
4749
const mockFSPromisesPass: MockFsPromise = {}
4850

4951
for (const method of Object.keys(fs.promises)) {
50-
5152
// of course fs.rm is missing when we shouldn't use native :)
5253
// also, readdirSync is clubbed to always return file types
5354
if (method !== 'rm' || useNative()) {

0 commit comments

Comments
 (0)