Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: drop fs-extra in favour of native node:fs #444

Merged
merged 7 commits into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@tsconfig/strictest": "^2.0.5",
"@types/babel__code-frame": "^7.0.6",
"@types/debug": "^4.1.12",
"@types/fs-extra": "^11.0.1",
"@types/minimist": "^1.2.2",
"@types/node": "^16.0.0",
"@types/prompts": "^2.0.13",
Expand All @@ -48,7 +47,6 @@
"chalk": "^4.1.1",
"execa": "^5.1.1",
"fast-json-stable-stringify": "^2.1.0",
"fs-extra": "^11.1.0",
"lint-staged": "^11.0.0",
"minimist": "^1.2.5",
"npm-run-all2": "^5.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/vite-plugin-checker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"chalk": "^4.1.1",
"chokidar": "^3.5.1",
"commander": "^8.0.0",
"fs-extra": "^11.1.0",
"npm-run-path": "^4.0.1",
"strip-ansi": "^6.0.0",
"tiny-invariant": "^1.1.0",
Expand All @@ -54,7 +53,6 @@
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/eslint": "^7.29.0",
"@types/fs-extra": "^11.0.1",
"@vue/language-core": "~2.1.6",
"esbuild": "^0.25.0",
"meow": "^9.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { access, readFile, rm, writeFile } from 'node:fs/promises'
import { access, cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import fsExtra from 'fs-extra'

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

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

if (shouldBuildFixture) {
await rm(targetTsDir, { force: true, recursive: true })
await mkdir(targetTsDir)
await mkdir(targetTsDir, { recursive: true })
const sourceTsDir = path.resolve(_require.resolve('typescript'), '../..')
await copy(sourceTsDir, targetTsDir)
await cp(sourceTsDir, targetTsDir, { recursive: true })
await writeFile(vueTscFlagFile, proxyApiPath)

// 2. sync modification of lib/tsc.js with vue-tsc
Expand Down
18 changes: 10 additions & 8 deletions playground/vitestGlobalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs-extra'
import { rmSync } from 'node:fs'
import fs from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { glob } from 'tinyglobby'
Expand All @@ -15,15 +16,16 @@ export async function setup(): Promise<void> {
args: process.env.CI ? ['--no-sandbox', '--disable-setuid-sandbox'] : undefined,
})

await fs.mkdirp(DIR)
await fs.mkdir(DIR, { recursive: true })
await fs.writeFile(path.join(DIR, 'wsEndpoint'), browserServer.wsEndpoint())

const tempDir = path.resolve(__dirname, '../playground-temp')
await fs.ensureDir(tempDir)
await fs.emptyDir(tempDir)
await fs.rm(tempDir, { force: true, recursive: true })
await fs.mkdir(tempDir, { recursive: true })
await fs
.copy(path.resolve(__dirname, '../playground'), tempDir, {
.cp(path.resolve(__dirname, '../playground'), tempDir, {
dereference: false,
recursive: true,
filter(file) {
const _file = file.replace(/\\/g, '/')
return !_file.includes('__tests__') && !file.match(/dist(\/|$)/)
Expand All @@ -42,16 +44,16 @@ export async function setup(): Promise<void> {
if (process.env['VITEST_TEST_CJS']) {
const packageJsons = await glob(`${tempDir}/**/package.json`)
for (const packageJson of packageJsons) {
const packageJsonContents = await fs.readJson(packageJson)
const packageJsonContents = await fs.readFile(packageJson, 'utf-8').then(r => JSON.parse(r.toString()))
delete packageJsonContents['module']
await fs.writeJson(packageJson, packageJsonContents, { spaces: 2 })
await fs.writeFile(packageJson, JSON.stringify(packageJsonContents, null, 2))
}
}
}

export async function teardown(): Promise<void> {
browserServer?.close()
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
fs.removeSync(path.resolve(__dirname, '../playground-temp'))
rmSync(path.resolve(__dirname, '../playground-temp'), { force: true, recursive: true })
}
}
11 changes: 6 additions & 5 deletions playground/vitestSetup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import execa from 'execa'
import fs from 'fs-extra'
import fs from 'node:fs/promises'
import { existsSync } from 'node:fs'
import type * as http from 'node:http'
import os from 'node:os'
import path, { dirname, join, resolve } from 'node:path'
Expand Down Expand Up @@ -88,7 +89,7 @@ beforeAll(async (s) => {
return
}

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

// when `root` dir is present, use it as vite's root
const testCustomRoot = resolve(testDir, 'root')
rootDir = fs.existsSync(testCustomRoot) ? testCustomRoot : testDir
rootDir = existsSync(testCustomRoot) ? testCustomRoot : testDir

const testCustomServe = [
resolve(dirname(rootDir), 'serve.ts'),
resolve(dirname(rootDir), 'serve.js'),
].find((i) => fs.existsSync(i))
].find((i) => existsSync(i))

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

let config: InlineConfig | undefined
if (fs.existsSync(testCustomConfig)) {
if (existsSync(testCustomConfig)) {
// test has custom server configuration.
config = await import(testCustomConfig).then((r) => r.default)
}
Expand Down
37 changes: 0 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions scripts/patchCjs.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import fs from 'node:fs/promises'
import path, { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import fs from 'fs-extra'

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

async function main() {
await fs.outputJson(
await fs.writeFile(
path.resolve(
__dirname,
'../packages/vite-plugin-checker/dist/cjs/package.json',
),
{ type: 'commonjs' },
{
spaces: 2,
},
JSON.stringify({ type: 'commonjs' }, null, 2),
)
}

Expand Down
12 changes: 7 additions & 5 deletions scripts/vitestGlobalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { rmSync } from 'node:fs'
import fs from 'node:fs/promises'
import path from 'node:path'
import fs from 'fs-extra'

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

export async function setup(): Promise<void> {
await fs.ensureDir(tempRuntimePath)
await fs.emptyDir(tempRuntimePath)
await fs.copy(
await fs.rm(tempRuntimePath, { force: true, recursive: true })
await fs.mkdir(tempRuntimePath, { recursive: true })
await fs.cp(
path.resolve(__dirname, '../packages/vite-plugin-checker/dist/@runtime'),
tempRuntimePath,
{
recursive: true,
dereference: false,
},
)
}

export async function teardown(): Promise<void> {
fs.removeSync(tempRuntimePath)
rmSync(tempRuntimePath, { force: true, recursive: true })
}
Loading