Skip to content

Commit 461d37b

Browse files
authoredJul 29, 2024··
chore: remove fs-extra dev dependency (#17782)
1 parent b947fdc commit 461d37b

File tree

7 files changed

+48
-59
lines changed

7 files changed

+48
-59
lines changed
 

‎package.json

-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"@types/debug": "^4.1.12",
4949
"@types/estree": "^1.0.5",
5050
"@types/etag": "^1.8.3",
51-
"@types/fs-extra": "^11.0.4",
5251
"@types/less": "^3.0.6",
5352
"@types/micromatch": "^4.0.9",
5453
"@types/node": "^20.14.11",
@@ -62,7 +61,6 @@
6261
"eslint-plugin-n": "^17.9.0",
6362
"eslint-plugin-regexp": "^2.6.0",
6463
"execa": "^9.3.0",
65-
"fs-extra": "^11.2.0",
6664
"globals": "^15.8.0",
6765
"lint-staged": "^15.2.7",
6866
"npm-run-all2": "^6.2.2",

‎packages/create-vite/__tests__/cli.spec.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { join } from 'node:path'
1+
import fs from 'node:fs'
2+
import path from 'node:path'
23
import type { SyncOptions, SyncResult } from 'execa'
34
import { execaCommandSync } from 'execa'
4-
import fs from 'fs-extra'
55
import { afterEach, beforeAll, expect, test } from 'vitest'
66

7-
const CLI_PATH = join(__dirname, '..')
7+
const CLI_PATH = path.join(__dirname, '..')
88

99
const projectName = 'test-app'
10-
const genPath = join(__dirname, projectName)
10+
const genPath = path.join(__dirname, projectName)
1111

1212
const run = <SO extends SyncOptions>(
1313
args: string[],
@@ -19,30 +19,30 @@ const run = <SO extends SyncOptions>(
1919
// Helper to create a non-empty directory
2020
const createNonEmptyDir = () => {
2121
// Create the temporary directory
22-
fs.mkdirpSync(genPath)
22+
fs.mkdirSync(genPath, { recursive: true })
2323

2424
// Create a package.json file
25-
const pkgJson = join(genPath, 'package.json')
25+
const pkgJson = path.join(genPath, 'package.json')
2626
fs.writeFileSync(pkgJson, '{ "foo": "bar" }')
2727
}
2828

2929
// Vue 3 starter template
3030
const templateFiles = fs
31-
.readdirSync(join(CLI_PATH, 'template-vue'))
31+
.readdirSync(path.join(CLI_PATH, 'template-vue'))
3232
// _gitignore is renamed to .gitignore
3333
.map((filePath) => (filePath === '_gitignore' ? '.gitignore' : filePath))
3434
.sort()
3535

36-
beforeAll(() => fs.remove(genPath))
37-
afterEach(() => fs.remove(genPath))
36+
beforeAll(() => fs.rmSync(genPath, { recursive: true, force: true }))
37+
afterEach(() => fs.rmSync(genPath, { recursive: true, force: true }))
3838

3939
test('prompts for the project name if none supplied', () => {
4040
const { stdout } = run([])
4141
expect(stdout).toContain('Project name:')
4242
})
4343

4444
test('prompts for the framework if none supplied when target dir is current directory', () => {
45-
fs.mkdirpSync(genPath)
45+
fs.mkdirSync(genPath, { recursive: true })
4646
const { stdout } = run(['.'], { cwd: genPath })
4747
expect(stdout).toContain('Select a framework:')
4848
})

‎playground/resolve-config/__tests__/serve.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// this is automatically detected by playground/vitestSetup.ts and will replace
22
// the default e2e test serve behavior
33

4+
import fs from 'node:fs/promises'
45
import path from 'node:path'
5-
import fs from 'fs-extra'
66
import { isBuild, rootDir } from '~utils'
77

88
const configNames = ['js', 'cjs', 'mjs', 'ts', 'mts', 'cts']
@@ -17,7 +17,9 @@ export async function serve() {
1717
for (const configName of configNames) {
1818
const pathToConf = fromTestDir(configName, `vite.config.${configName}`)
1919

20-
await fs.copy(fromTestDir('root'), fromTestDir(configName))
20+
await fs.cp(fromTestDir('root'), fromTestDir(configName), {
21+
recursive: true,
22+
})
2123
await fs.rename(fromTestDir(configName, 'vite.config.ts'), pathToConf)
2224

2325
if (['cjs', 'cts'].includes(configName)) {
@@ -35,9 +37,12 @@ export async function serve() {
3537
}
3638

3739
// copy directory and add package.json with "type": "module"
38-
await fs.copy(fromTestDir(configName), fromTestDir(`${configName}-module`))
39-
await fs.writeJSON(fromTestDir(`${configName}-module`, 'package.json'), {
40-
type: 'module',
40+
await fs.cp(fromTestDir(configName), fromTestDir(`${configName}-module`), {
41+
recursive: true,
4142
})
43+
await fs.writeFile(
44+
fromTestDir(`${configName}-module`, 'package.json'),
45+
'{ "type": "module" }',
46+
)
4247
}
4348
}

‎playground/vitestGlobalSetup.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import fs from 'node:fs/promises'
12
import path from 'node:path'
2-
import fs from 'fs-extra'
33
import type { GlobalSetupContext } from 'vitest/node'
44
import type { BrowserServer } from 'playwright-chromium'
55
import { chromium } from 'playwright-chromium'
@@ -21,10 +21,11 @@ export async function setup({ provide }: GlobalSetupContext): Promise<void> {
2121
provide('wsEndpoint', browserServer.wsEndpoint())
2222

2323
const tempDir = path.resolve(__dirname, '../playground-temp')
24-
await fs.ensureDir(tempDir)
25-
await fs.emptyDir(tempDir)
24+
await fs.rm(tempDir, { recursive: true, force: true })
25+
await fs.mkdir(tempDir, { recursive: true })
2626
await fs
27-
.copy(path.resolve(__dirname, '../playground'), tempDir, {
27+
.cp(path.resolve(__dirname, '../playground'), tempDir, {
28+
recursive: true,
2829
dereference: false,
2930
filter(file) {
3031
file = file.replace(/\\/g, '/')
@@ -45,6 +46,8 @@ export async function setup({ provide }: GlobalSetupContext): Promise<void> {
4546
export async function teardown(): Promise<void> {
4647
await browserServer?.close()
4748
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
48-
fs.removeSync(path.resolve(__dirname, '../playground-temp'))
49+
await fs.rm(path.resolve(__dirname, '../playground-temp'), {
50+
recursive: true,
51+
})
4952
}
5053
}

‎playground/vitestSetup.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type * as http from 'node:http'
2-
import path, { dirname, resolve } from 'node:path'
3-
import fs from 'fs-extra'
2+
import fs from 'node:fs'
3+
import path from 'node:path'
44
import { chromium } from 'playwright-chromium'
55
import type {
66
ConfigEnv,
@@ -25,7 +25,7 @@ import { beforeAll, inject } from 'vitest'
2525

2626
// #region env
2727

28-
export const workspaceRoot = resolve(__dirname, '../')
28+
export const workspaceRoot = path.resolve(__dirname, '../')
2929

3030
export const isBuild = !!process.env.VITE_TEST_BUILD
3131
export const isServe = !isBuild
@@ -125,20 +125,20 @@ beforeAll(async (s) => {
125125

126126
testPath = suite.filepath!
127127
testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1]
128-
testDir = dirname(testPath)
128+
testDir = path.dirname(testPath)
129129

130130
// if this is a test placed under playground/xxx/__tests__
131131
// start a vite server in that directory.
132132
if (testName) {
133-
testDir = resolve(workspaceRoot, 'playground-temp', testName)
133+
testDir = path.resolve(workspaceRoot, 'playground-temp', testName)
134134

135135
// when `root` dir is present, use it as vite's root
136-
const testCustomRoot = resolve(testDir, 'root')
136+
const testCustomRoot = path.resolve(testDir, 'root')
137137
rootDir = fs.existsSync(testCustomRoot) ? testCustomRoot : testDir
138138

139139
const testCustomServe = [
140-
resolve(dirname(testPath), 'serve.ts'),
141-
resolve(dirname(testPath), 'serve.js'),
140+
path.resolve(path.dirname(testPath), 'serve.ts'),
141+
path.resolve(path.dirname(testPath), 'serve.js'),
142142
].find((i) => fs.existsSync(i))
143143

144144
if (testCustomServe) {
@@ -182,7 +182,7 @@ async function loadConfig(configEnv: ConfigEnv) {
182182
let config: UserConfig | null = null
183183

184184
// config file named by convention as the *.spec.ts folder
185-
const variantName = path.basename(dirname(testPath))
185+
const variantName = path.basename(path.dirname(testPath))
186186
if (variantName !== '__tests__') {
187187
const configVariantPath = path.resolve(
188188
rootDir,

‎pnpm-lock.yaml

-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/releaseUtils.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { readdirSync, writeFileSync } from 'node:fs'
1+
import fs from 'node:fs/promises'
22
import path from 'node:path'
33
import colors from 'picocolors'
44
import type { Options as ExecaOptions, ResultPromise } from 'execa'
55
import { execa } from 'execa'
6-
import fs from 'fs-extra'
76

87
export function run<EO extends ExecaOptions>(
98
bin: string,
@@ -14,7 +13,9 @@ export function run<EO extends ExecaOptions>(
1413
}
1514

1615
export async function getLatestTag(pkgName: string): Promise<string> {
17-
const pkgJson = await fs.readJson(`packages/${pkgName}/package.json`)
16+
const pkgJson = JSON.parse(
17+
await fs.readFile(`packages/${pkgName}/package.json`, 'utf-8'),
18+
)
1819
const version = pkgJson.version
1920
return pkgName === 'vite' ? `v${version}` : `${pkgName}@${version}`
2021
}
@@ -48,17 +49,20 @@ export async function logRecentCommits(pkgName: string): Promise<void> {
4849
}
4950

5051
export async function updateTemplateVersions(): Promise<void> {
51-
const viteVersion = fs.readJSONSync('packages/vite/package.json').version
52+
const vitePkgJson = JSON.parse(
53+
await fs.readFile('packages/vite/package.json', 'utf-8'),
54+
)
55+
const viteVersion = vitePkgJson.version
5256
if (/beta|alpha|rc/.test(viteVersion)) return
5357

5458
const dir = 'packages/create-vite'
55-
const templates = readdirSync(dir).filter((dir) =>
59+
const templates = (await fs.readdir(dir)).filter((dir) =>
5660
dir.startsWith('template-'),
5761
)
5862
for (const template of templates) {
5963
const pkgPath = path.join(dir, template, `package.json`)
60-
const pkg = fs.readJSONSync(pkgPath)
64+
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'))
6165
pkg.devDependencies.vite = `^` + viteVersion
62-
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
66+
await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
6367
}
6468
}

0 commit comments

Comments
 (0)
Please sign in to comment.