Skip to content

Commit 9483051

Browse files
authored
perf: drop fs-extra in favour of native node:fs (#444)
1 parent bed8f92 commit 9483051

File tree

8 files changed

+29
-70
lines changed

8 files changed

+29
-70
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"@tsconfig/strictest": "^2.0.5",
4040
"@types/babel__code-frame": "^7.0.6",
4141
"@types/debug": "^4.1.12",
42-
"@types/fs-extra": "^11.0.1",
4342
"@types/minimist": "^1.2.2",
4443
"@types/node": "^16.0.0",
4544
"@types/prompts": "^2.0.13",
@@ -48,7 +47,6 @@
4847
"chalk": "^4.1.1",
4948
"execa": "^5.1.1",
5049
"fast-json-stable-stringify": "^2.1.0",
51-
"fs-extra": "^11.1.0",
5250
"lint-staged": "^11.0.0",
5351
"minimist": "^1.2.5",
5452
"npm-run-all2": "^5.0.0",

packages/vite-plugin-checker/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"chalk": "^4.1.1",
4242
"chokidar": "^3.5.1",
4343
"commander": "^8.0.0",
44-
"fs-extra": "^11.1.0",
4544
"npm-run-path": "^4.0.1",
4645
"strip-ansi": "^6.0.0",
4746
"tiny-invariant": "^1.1.0",
@@ -54,7 +53,6 @@
5453
"devDependencies": {
5554
"@biomejs/biome": "^1.8.3",
5655
"@types/eslint": "^7.29.0",
57-
"@types/fs-extra": "^11.0.1",
5856
"@vue/language-core": "~2.1.6",
5957
"esbuild": "^0.25.0",
6058
"meow": "^9.0.0",

packages/vite-plugin-checker/src/checkers/vueTsc/prepareVueTsc.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { access, readFile, rm, writeFile } from 'node:fs/promises'
1+
import { access, cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
22
import { createRequire } from 'node:module'
33
import path, { dirname } from 'node:path'
44
import { fileURLToPath } from 'node:url'
5-
import fsExtra from 'fs-extra'
65

7-
const { copy, mkdir } = fsExtra
86
const _require = createRequire(import.meta.url)
97

108
// isomorphic __dirname https://antfu.me/posts/isomorphic-dirname
@@ -54,9 +52,9 @@ export async function prepareVueTsc() {
5452

5553
if (shouldBuildFixture) {
5654
await rm(targetTsDir, { force: true, recursive: true })
57-
await mkdir(targetTsDir)
55+
await mkdir(targetTsDir, { recursive: true })
5856
const sourceTsDir = path.resolve(_require.resolve('typescript'), '../..')
59-
await copy(sourceTsDir, targetTsDir)
57+
await cp(sourceTsDir, targetTsDir, { recursive: true })
6058
await writeFile(vueTscFlagFile, proxyApiPath)
6159

6260
// 2. sync modification of lib/tsc.js with vue-tsc

playground/vitestGlobalSetup.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import fs from 'fs-extra'
1+
import { rmSync } from 'node:fs'
2+
import fs from 'node:fs/promises'
23
import os from 'node:os'
34
import path from 'node:path'
45
import { glob } from 'tinyglobby'
@@ -15,15 +16,16 @@ export async function setup(): Promise<void> {
1516
args: process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : undefined,
1617
})
1718

18-
await fs.mkdirp(DIR)
19+
await fs.mkdir(DIR, { recursive: true })
1920
await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint())
2021

2122
const tempDir = path.resolve(__dirname, '../playground-temp')
22-
await fs.ensureDir(tempDir)
23-
await fs.emptyDir(tempDir)
23+
await fs.rm(tempDir, { force: true, recursive: true })
24+
await fs.mkdir(tempDir, { recursive: true })
2425
await fs
25-
.copy(path.resolve(__dirname, '../playground'), tempDir, {
26+
.cp(path.resolve(__dirname, '../playground'), tempDir, {
2627
dereference: false,
28+
recursive: true,
2729
filter(file) {
2830
const _file = file.replace(/\\/g, '/')
2931
return !_file.includes('__tests__') && !file.match(/dist(\/|$)/)
@@ -42,16 +44,16 @@ export async function setup(): Promise<void> {
4244
if (process.env['VITEST_TEST_CJS']) {
4345
const packageJsons = await glob(`${tempDir}/**/package.json`)
4446
for (const packageJson of packageJsons) {
45-
const packageJsonContents = await fs.readJson(packageJson)
47+
const packageJsonContents = await fs.readFile(packageJson, 'utf-8').then(r => JSON.parse(r.toString()))
4648
delete packageJsonContents['module']
47-
await fs.writeJson(packageJson, packageJsonContents, { spaces: 2 })
49+
await fs.writeFile(packageJson, JSON.stringify(packageJsonContents, null, 2))
4850
}
4951
}
5052
}
5153

5254
export async function teardown(): Promise<void> {
5355
browserServer?.close()
5456
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
55-
fs.removeSync(path.resolve(__dirname, '../playground-temp'))
57+
rmSync(path.resolve(__dirname, '../playground-temp'), { force: true, recursive: true })
5658
}
5759
}

playground/vitestSetup.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import execa from 'execa'
2-
import fs from 'fs-extra'
2+
import fs from 'node:fs/promises'
3+
import { existsSync } from 'node:fs'
34
import type * as http from 'node:http'
45
import os from 'node:os'
56
import path, { dirname, join, resolve } from 'node:path'
@@ -88,7 +89,7 @@ beforeAll(async (s) => {
8889
return
8990
}
9091

91-
const wsEndpoint = fs.readFileSync(join(DIR, 'wsEndpoint'), 'utf-8')
92+
const wsEndpoint = await fs.readFile(join(DIR, 'wsEndpoint'), 'utf-8')
9293
if (!wsEndpoint) {
9394
throw new Error('wsEndpoint not found')
9495
}
@@ -109,12 +110,12 @@ beforeAll(async (s) => {
109110

110111
// when `root` dir is present, use it as vite's root
111112
const testCustomRoot = resolve(testDir, 'root')
112-
rootDir = fs.existsSync(testCustomRoot) ? testCustomRoot : testDir
113+
rootDir = existsSync(testCustomRoot) ? testCustomRoot : testDir
113114

114115
const testCustomServe = [
115116
resolve(dirname(rootDir), 'serve.ts'),
116117
resolve(dirname(rootDir), 'serve.js'),
117-
].find((i) => fs.existsSync(i))
118+
].find((i) => existsSync(i))
118119

119120
if (testCustomServe && isServe) {
120121
// test has custom server configuration.
@@ -160,7 +161,7 @@ export async function startDefaultServe({
160161
const testCustomConfig = resolve(testDir, 'vite.config.js')
161162

162163
let config: InlineConfig | undefined
163-
if (fs.existsSync(testCustomConfig)) {
164+
if (existsSync(testCustomConfig)) {
164165
// test has custom server configuration.
165166
config = await import(testCustomConfig).then((r) => r.default)
166167
}

pnpm-lock.yaml

Lines changed: 0 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/patchCjs.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
import fs from 'node:fs/promises'
12
import path, { dirname } from 'node:path'
23
import { fileURLToPath } from 'node:url'
3-
import fs from 'fs-extra'
44

55
const __filename = fileURLToPath(import.meta.url)
66
const __dirname = dirname(__filename)
77

88
async function main() {
9-
await fs.outputJson(
9+
await fs.writeFile(
1010
path.resolve(
1111
__dirname,
1212
'../packages/vite-plugin-checker/dist/cjs/package.json',
1313
),
14-
{ type: 'commonjs' },
15-
{
16-
spaces: 2,
17-
},
14+
JSON.stringify({ type: 'commonjs' }, null, 2),
1815
)
1916
}
2017

scripts/vitestGlobalSetup.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
import { rmSync } from 'node:fs'
2+
import fs from 'node:fs/promises'
13
import path from 'node:path'
2-
import fs from 'fs-extra'
34

45
const tempRuntimePath = path.resolve(
56
__dirname,
67
'../packages/vite-plugin-checker/src/@runtime',
78
)
89

910
export async function setup(): Promise<void> {
10-
await fs.ensureDir(tempRuntimePath)
11-
await fs.emptyDir(tempRuntimePath)
12-
await fs.copy(
11+
await fs.rm(tempRuntimePath, { force: true, recursive: true })
12+
await fs.mkdir(tempRuntimePath, { recursive: true })
13+
await fs.cp(
1314
path.resolve(__dirname, '../packages/vite-plugin-checker/dist/@runtime'),
1415
tempRuntimePath,
1516
{
17+
recursive: true,
1618
dereference: false,
1719
},
1820
)
1921
}
2022

2123
export async function teardown(): Promise<void> {
22-
fs.removeSync(tempRuntimePath)
24+
rmSync(tempRuntimePath, { force: true, recursive: true })
2325
}

0 commit comments

Comments
 (0)