Skip to content

Commit 2c09a8c

Browse files
committed
Move to standard Node.js rm
1 parent 909a1bb commit 2c09a8c

File tree

10 files changed

+32
-33
lines changed

10 files changed

+32
-33
lines changed

packages/esbuild-why/test/index.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import esbuildPkg from '@size-limit/esbuild'
2-
import { readFile } from 'node:fs/promises'
2+
import { readFile, rm } from 'node:fs/promises'
33
import { join } from 'node:path'
44
import open from 'open'
5-
import { rm } from 'size-limit'
65
import { afterEach, expect, it, vi } from 'vitest'
76

87
import esbuildWhyPkg from '..'
@@ -18,7 +17,7 @@ function fixture(name) {
1817
}
1918

2019
afterEach(async () => {
21-
await rm(DIST)
20+
await rm(DIST, { force: true, recursive: true })
2221
vi.clearAllMocks()
2322
})
2423

packages/esbuild/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ function getFiles(buildResult, check) {
3131

3232
if (check.entry) {
3333
for (let entry of check.entry) {
34-
let matches = Object.keys(outputs).filter(key => parse(key).name === entry)
35-
if(matches.length === 0) {
34+
let matches = Object.keys(outputs).filter(
35+
key => parse(key).name === entry
36+
)
37+
if (matches.length === 0) {
3638
throw new SizeLimitError('unknownEntry', entry)
3739
}
38-
for(let match of matches) {
40+
for (let match of matches) {
3941
entries[match] = outputs[match]
4042
}
4143
}
@@ -61,7 +63,7 @@ export default [
6163
async before(config) {
6264
if (config.saveBundle) {
6365
if (config.cleanDir) {
64-
await rm(config.saveBundle)
66+
await rm(config.saveBundle, { force: true, recursive: true })
6567
} else {
6668
let notEmpty = await isDirNotEmpty(config.saveBundle)
6769
if (notEmpty) {
@@ -73,7 +75,7 @@ export default [
7375

7476
async finally(config, check) {
7577
if (check.esbuildOutfile && !config.saveBundle) {
76-
await rm(check.esbuildOutfile)
78+
await rm(check.esbuildOutfile, { force: true, recursive: true })
7779
}
7880
},
7981

packages/esbuild/test/index.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import filePkg from '@size-limit/file'
22
import { existsSync } from 'node:fs'
3-
import { mkdir, writeFile } from 'node:fs/promises'
3+
import { mkdir, rm, writeFile } from 'node:fs/promises'
44
import { join } from 'node:path'
5-
import { rm, SizeLimitError } from 'size-limit'
5+
import { SizeLimitError } from 'size-limit'
66
import { afterEach, describe, expect, it, vi } from 'vitest'
77

88
import esbuildPkg from '../index.js'
@@ -37,7 +37,7 @@ async function getSize(check) {
3737
}
3838

3939
afterEach(async () => {
40-
await rm(DIST)
40+
await rm(DIST, { force: true, recursive: true })
4141
vi.clearAllMocks()
4242
})
4343

packages/size-limit/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import fs from 'node:fs/promises'
2+
13
import calc from './calc.js'
24
import { Plugins } from './load-plugins.js'
35

46
export { processImport } from './process-import.js'
5-
export { rm } from './rm.js'
67
export { SizeLimitError } from './size-limit-error.js'
78

89
/**
@@ -30,3 +31,7 @@ export default async function (plugins, files) {
3031
return value
3132
})
3233
}
34+
35+
export async function rm(dir) {
36+
await fs.rm(dir, { force: true, recursive: true })
37+
}

packages/size-limit/rm.js

-5
This file was deleted.

packages/time/test/cache.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { writeFile } from 'node:fs/promises'
1+
import { rm, writeFile } from 'node:fs/promises'
22
import { join } from 'node:path'
3-
import { rm } from 'size-limit'
43
import { afterEach, beforeAll, expect, it } from 'vitest'
54

65
import { getCache, saveCache } from '../cache'
76

87
const CACHE = join(__dirname, '..', '..', '.cache')
98

10-
beforeAll(() => rm(CACHE))
11-
afterEach(() => rm(CACHE))
9+
beforeAll(() => rm(CACHE, { force: true, recursive: true }))
10+
afterEach(() => rm(CACHE, { force: true, recursive: true }))
1211

1312
it('returns false by default', async () => {
1413
expect(await getCache()).toBe(false)

packages/webpack-css/test/index.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import filePkg from '@size-limit/file'
22
import webpackPkg from '@size-limit/webpack'
3+
import { rm } from 'node:fs/promises'
34
import { join } from 'node:path'
4-
import { rm } from 'size-limit'
55
import { afterEach, expect, it, vi } from 'vitest'
66

77
import webpackCssPkg from '../index.js'
@@ -29,7 +29,7 @@ async function run(config) {
2929
}
3030

3131
afterEach(async () => {
32-
await rm(DIST)
32+
await rm(DIST, { force: true, recursive: true })
3333
vi.clearAllMocks()
3434
})
3535

packages/webpack-why/test/index.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import filePkg from '@size-limit/file'
22
import webpackPkg from '@size-limit/webpack'
33
import { existsSync } from 'node:fs'
4-
import { mkdir, readFile, writeFile } from 'node:fs/promises'
4+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises'
55
import { join } from 'node:path'
6-
import { rm } from 'size-limit'
76
import { afterEach, expect, it, vi } from 'vitest'
87

98
import webpackWhyPkg from '../index.js'
@@ -31,7 +30,7 @@ async function run(config) {
3130
}
3231

3332
afterEach(async () => {
34-
await rm(DIST)
33+
await rm(DIST, { force: true, recursive: true })
3534
vi.clearAllMocks()
3635
})
3736

packages/webpack/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { nanoid } from 'nanoid/non-secure'
2-
import { readdir } from 'node:fs/promises'
2+
import { readdir, rm } from 'node:fs/promises'
33
import { tmpdir } from 'node:os'
44
import { join } from 'node:path'
5-
import { rm, SizeLimitError } from 'size-limit'
5+
import { SizeLimitError } from 'size-limit'
66

77
import { convertConfig } from './convert-config.js'
88
import { getConfig } from './get-config.js'
@@ -59,7 +59,7 @@ export default [
5959
async before(config) {
6060
if (config.saveBundle) {
6161
if (config.cleanDir) {
62-
await rm(config.saveBundle)
62+
await rm(config.saveBundle, { force: true, recursive: true })
6363
} else {
6464
let notEmpty = await isDirNotEmpty(config.saveBundle)
6565
if (notEmpty) {
@@ -71,7 +71,7 @@ export default [
7171

7272
async finally(config, check) {
7373
if (check.webpackOutput && !config.saveBundle) {
74-
await rm(check.webpackOutput)
74+
await rm(check.webpackOutput, { force: true, recursive: true })
7575
}
7676
},
7777

packages/webpack/test/index.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import filePkg from '@size-limit/file'
22
import { existsSync } from 'node:fs'
3-
import { mkdir, writeFile } from 'node:fs/promises'
3+
import { mkdir, rm, writeFile } from 'node:fs/promises'
44
import { join } from 'node:path'
5-
import { rm, SizeLimitError } from 'size-limit'
5+
import { SizeLimitError } from 'size-limit'
66
import { afterEach, describe, expect, it, vi } from 'vitest'
77

88
import webpackPkg from '../index.js'
@@ -37,7 +37,7 @@ async function getSize(check) {
3737
}
3838

3939
afterEach(async () => {
40-
await rm(DIST)
40+
await rm(DIST, { force: true, recursive: true })
4141
vi.clearAllMocks()
4242
})
4343

0 commit comments

Comments
 (0)