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

chore: remove fs-extra dev dependency #17782

Merged
merged 1 commit into from
Jul 29, 2024
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 @@ -48,7 +48,6 @@
"@types/debug": "^4.1.12",
"@types/estree": "^1.0.5",
"@types/etag": "^1.8.3",
"@types/fs-extra": "^11.0.4",
"@types/less": "^3.0.6",
"@types/micromatch": "^4.0.9",
"@types/node": "^20.14.11",
Expand All @@ -62,7 +61,6 @@
"eslint-plugin-n": "^17.9.0",
"eslint-plugin-regexp": "^2.6.0",
"execa": "^9.3.0",
"fs-extra": "^11.2.0",
"globals": "^15.8.0",
"lint-staged": "^15.2.7",
"npm-run-all2": "^6.2.2",
Expand Down
20 changes: 10 additions & 10 deletions packages/create-vite/__tests__/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { join } from 'node:path'
import fs from 'node:fs'
import path from 'node:path'
import type { SyncOptions, SyncResult } from 'execa'
import { execaCommandSync } from 'execa'
import fs from 'fs-extra'
import { afterEach, beforeAll, expect, test } from 'vitest'

const CLI_PATH = join(__dirname, '..')
const CLI_PATH = path.join(__dirname, '..')

const projectName = 'test-app'
const genPath = join(__dirname, projectName)
const genPath = path.join(__dirname, projectName)

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

// Create a package.json file
const pkgJson = join(genPath, 'package.json')
const pkgJson = path.join(genPath, 'package.json')
fs.writeFileSync(pkgJson, '{ "foo": "bar" }')
}

// Vue 3 starter template
const templateFiles = fs
.readdirSync(join(CLI_PATH, 'template-vue'))
.readdirSync(path.join(CLI_PATH, 'template-vue'))
// _gitignore is renamed to .gitignore
.map((filePath) => (filePath === '_gitignore' ? '.gitignore' : filePath))
.sort()

beforeAll(() => fs.remove(genPath))
afterEach(() => fs.remove(genPath))
beforeAll(() => fs.rmSync(genPath, { recursive: true, force: true }))
afterEach(() => fs.rmSync(genPath, { recursive: true, force: true }))

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

test('prompts for the framework if none supplied when target dir is current directory', () => {
fs.mkdirpSync(genPath)
fs.mkdirSync(genPath, { recursive: true })
const { stdout } = run(['.'], { cwd: genPath })
expect(stdout).toContain('Select a framework:')
})
Expand Down
15 changes: 10 additions & 5 deletions playground/resolve-config/__tests__/serve.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// this is automatically detected by playground/vitestSetup.ts and will replace
// the default e2e test serve behavior

import fs from 'node:fs/promises'
import path from 'node:path'
import fs from 'fs-extra'
import { isBuild, rootDir } from '~utils'

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

await fs.copy(fromTestDir('root'), fromTestDir(configName))
await fs.cp(fromTestDir('root'), fromTestDir(configName), {
recursive: true,
})
await fs.rename(fromTestDir(configName, 'vite.config.ts'), pathToConf)

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

// copy directory and add package.json with "type": "module"
await fs.copy(fromTestDir(configName), fromTestDir(`${configName}-module`))
await fs.writeJSON(fromTestDir(`${configName}-module`, 'package.json'), {
type: 'module',
await fs.cp(fromTestDir(configName), fromTestDir(`${configName}-module`), {
recursive: true,
})
await fs.writeFile(
fromTestDir(`${configName}-module`, 'package.json'),
'{ "type": "module" }',
)
}
}
13 changes: 8 additions & 5 deletions playground/vitestGlobalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import fs from 'fs-extra'
import type { GlobalSetupContext } from 'vitest/node'
import type { BrowserServer } from 'playwright-chromium'
import { chromium } from 'playwright-chromium'
Expand All @@ -21,10 +21,11 @@ export async function setup({ provide }: GlobalSetupContext): Promise<void> {
provide('wsEndpoint', browserServer.wsEndpoint())

const tempDir = path.resolve(__dirname, '../playground-temp')
await fs.ensureDir(tempDir)
await fs.emptyDir(tempDir)
await fs.rm(tempDir, { recursive: true, force: true })
await fs.mkdir(tempDir, { recursive: true })
await fs
.copy(path.resolve(__dirname, '../playground'), tempDir, {
.cp(path.resolve(__dirname, '../playground'), tempDir, {
recursive: true,
dereference: false,
filter(file) {
file = file.replace(/\\/g, '/')
Expand All @@ -45,6 +46,8 @@ export async function setup({ provide }: GlobalSetupContext): Promise<void> {
export async function teardown(): Promise<void> {
await browserServer?.close()
if (!process.env.VITE_PRESERVE_BUILD_ARTIFACTS) {
fs.removeSync(path.resolve(__dirname, '../playground-temp'))
await fs.rm(path.resolve(__dirname, '../playground-temp'), {
recursive: true,
})
}
}
18 changes: 9 additions & 9 deletions playground/vitestSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as http from 'node:http'
import path, { dirname, resolve } from 'node:path'
import fs from 'fs-extra'
import fs from 'node:fs'
import path from 'node:path'
import { chromium } from 'playwright-chromium'
import type {
ConfigEnv,
Expand All @@ -25,7 +25,7 @@ import { beforeAll, inject } from 'vitest'

// #region env

export const workspaceRoot = resolve(__dirname, '../')
export const workspaceRoot = path.resolve(__dirname, '../')

export const isBuild = !!process.env.VITE_TEST_BUILD
export const isServe = !isBuild
Expand Down Expand Up @@ -125,20 +125,20 @@ beforeAll(async (s) => {

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

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

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

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

if (testCustomServe) {
Expand Down Expand Up @@ -182,7 +182,7 @@ async function loadConfig(configEnv: ConfigEnv) {
let config: UserConfig | null = null

// config file named by convention as the *.spec.ts folder
const variantName = path.basename(dirname(testPath))
const variantName = path.basename(path.dirname(testPath))
if (variantName !== '__tests__') {
const configVariantPath = path.resolve(
rootDir,
Expand Down
21 changes: 0 additions & 21 deletions pnpm-lock.yaml

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

18 changes: 11 additions & 7 deletions scripts/releaseUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { readdirSync, writeFileSync } from 'node:fs'
import fs from 'node:fs/promises'
import path from 'node:path'
import colors from 'picocolors'
import type { Options as ExecaOptions, ResultPromise } from 'execa'
import { execa } from 'execa'
import fs from 'fs-extra'

export function run<EO extends ExecaOptions>(
bin: string,
Expand All @@ -14,7 +13,9 @@ export function run<EO extends ExecaOptions>(
}

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

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

const dir = 'packages/create-vite'
const templates = readdirSync(dir).filter((dir) =>
const templates = (await fs.readdir(dir)).filter((dir) =>
dir.startsWith('template-'),
)
for (const template of templates) {
const pkgPath = path.join(dir, template, `package.json`)
const pkg = fs.readJSONSync(pkgPath)
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'))
pkg.devDependencies.vite = `^` + viteVersion
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
}
}