Skip to content

Commit

Permalink
chore: clean some leftovers from Vite core (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Dec 5, 2022
1 parent 9094c8b commit d2a3931
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 971 deletions.
3 changes: 0 additions & 3 deletions .github/renovate.json5
Expand Up @@ -13,15 +13,12 @@
],
"ignoreDeps": [
// manually bumping
"esbuild",
"rollup",
"node",
"typescript",

// breaking changes
"source-map", // `source-map:v0.7.0+` needs more investigation
"dotenv-expand", // `dotenv-expand:6.0.0+` has breaking changes (#6858)
"kill-port", // `kill-port:^2.0.0 has perf issues (#8392)
"miniflare", // `miniflare:v2.0.0+` only supports node 16.7
],
}
44 changes: 3 additions & 41 deletions package.json
Expand Up @@ -30,61 +30,37 @@
"release": "tsx scripts/release.ts"
},
"devDependencies": {
"@babel/types": "^7.20.5",
"@microsoft/api-extractor": "^7.33.6",
"@rollup/plugin-typescript": "^10.0.1",
"@types/babel__core": "^7.1.20",
"@types/babel__standalone": "^7.1.4",
"@types/convert-source-map": "^1.5.2",
"@types/cross-spawn": "^6.0.2",
"@types/debug": "^4.1.7",
"@types/estree": "^1.0.0",
"@types/etag": "^1.8.1",
"@types/fs-extra": "^9.0.13",
"@types/less": "^3.0.3",
"@types/micromatch": "^4.0.2",
"@types/minimist": "^1.2.2",
"@types/node": "^17.0.42",
"@types/picomatch": "^2.3.0",
"@types/prompts": "^2.4.1",
"@types/resolve": "^1.20.2",
"@types/sass": "~1.43.1",
"@types/semver": "^7.3.13",
"@types/stylus": "^0.48.38",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0",
"conventional-changelog-cli": "^2.2.2",
"esbuild": "^0.15.9",
"eslint": "^8.28.0",
"eslint-define-config": "^1.12.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-regexp": "^1.11.0",
"execa": "^6.1.0",
"fast-glob": "^3.2.12",
"fs-extra": "^10.1.0",
"lint-staged": "^13.0.4",
"minimist": "^1.2.7",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"playwright-chromium": "^1.28.1",
"pnpm": "^7.17.1",
"prettier": "2.8.0",
"prompts": "^2.4.2",
"resolve": "^1.22.1",
"rimraf": "^3.0.2",
"rollup": "~3.3.0",
"rollup-plugin-license": "^2.9.1",
"rollup": "~3.5.0",
"semver": "^7.3.8",
"simple-git-hooks": "^2.8.1",
"tslib": "^2.4.1",
"tsx": "^3.12.1",
"typescript": "^4.6.4",
"unbuild": "^0.9.4",
"vite": "^4.0.0-alpha.0",
"vitest": "^0.25.3",
"vue": "^3.2.45"
"vitest": "^0.25.3"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --concurrent false",
Expand All @@ -104,19 +80,5 @@
"eslint --cache --fix"
]
},
"packageManager": "pnpm@7.17.1",
"pnpm": {
"packageExtensions": {
"postcss-load-config": {
"peerDependencies": {
"postcss": "*"
}
},
"acorn-walk": {
"peerDependencies": {
"acorn": "*"
}
}
}
}
"packageManager": "pnpm@7.17.1"
}
5 changes: 1 addition & 4 deletions packages/plugin-react/tsconfig.json
Expand Up @@ -10,9 +10,6 @@
"declaration": true,
"sourceMap": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"paths": {
"vite": ["../vite/src/node/index.js"]
}
"esModuleInterop": true
}
}
4 changes: 1 addition & 3 deletions playground/package.json
Expand Up @@ -3,10 +3,8 @@
"private": true,
"version": "1.0.0",
"devDependencies": {
"convert-source-map": "^1.9.0",
"css-color-names": "^1.0.1",
"kill-port": "^1.6.1",
"node-fetch": "^3.3.0",
"sirv": "^2.0.2"
"node-fetch": "^3.3.0"
}
}
6 changes: 0 additions & 6 deletions playground/shims.d.ts
Expand Up @@ -7,9 +7,3 @@ declare module 'kill-port' {
const kill: (port: number) => Promise<void>
export default kill
}

declare module '*.vue' {
import type { ComponentOptions } from 'vue'
const component: ComponentOptions
export default component
}
110 changes: 4 additions & 106 deletions playground/test-utils.ts
Expand Up @@ -5,42 +5,17 @@ import fs from 'node:fs'
import path from 'node:path'
import colors from 'css-color-names'
import type { ConsoleMessage, ElementHandle } from 'playwright-chromium'
import type { Manifest } from 'vite'
import { normalizePath } from 'vite'
import { fromComment } from 'convert-source-map'
import { expect } from 'vitest'
import type { ExecaChildProcess } from 'execa'
import { isBuild, isWindows, page, testDir } from './vitestSetup'
import { isBuild, page, testDir } from './vitestSetup'

export * from './vitestSetup'

// make sure these ports are unique
export const ports = {
cli: 9510,
'cli-module': 9511,
'legacy/ssr': 9520,
lib: 9521,
'optimize-missing-deps': 9522,
'legacy/client-and-ssr': 9523,
'ssr-deps': 9600,
'ssr-html': 9601,
'ssr-noexternal': 9602,
'ssr-pug': 9603,
'ssr-react': 9604,
'ssr-vue': 9605,
'ssr-webworker': 9606,
'css/postcss-caching': 5005,
'css/postcss-plugins-different-dir': 5006,
'css/dynamic-import': 5007,
}
export const hmrPorts = {
'optimize-missing-deps': 24680,
'ssr-deps': 24681,
'ssr-html': 24682,
'ssr-noexternal': 24683,
'ssr-pug': 24684,
'ssr-react': 24685,
'ssr-vue': 24686,
}

const hexToNameMap: Record<string, string> = {}
Expand Down Expand Up @@ -117,38 +92,6 @@ export function removeFile(filename: string): void {
fs.unlinkSync(path.resolve(testDir, filename))
}

export function listAssets(base = ''): string[] {
const assetsDir = path.join(testDir, 'dist', base, 'assets')
return fs.readdirSync(assetsDir)
}

export function findAssetFile(
match: string | RegExp,
base = '',
assets = 'assets',
): string {
const assetsDir = path.join(testDir, 'dist', base, assets)
let files: string[]
try {
files = fs.readdirSync(assetsDir)
} catch (e) {
if (e.code === 'ENOENT') {
return ''
}
throw e
}
const file = files.find((file) => {
return file.match(match)
})
return file ? fs.readFileSync(path.resolve(assetsDir, file), 'utf-8') : ''
}

export function readManifest(base = ''): Manifest {
return JSON.parse(
fs.readFileSync(path.join(testDir, 'dist', base, 'manifest.json'), 'utf-8'),
)
}

/**
* Poll a getter until the value it returns includes the expected value.
*/
Expand All @@ -170,25 +113,6 @@ export async function untilUpdated(
}
}

/**
* Retry `func` until it does not throw error.
*/
export async function withRetry(
func: () => Promise<void>,
runInBuild = false,
): Promise<void> {
if (isBuild && !runInBuild) return
const maxTries = process.env.CI ? 200 : 50
for (let tries = 0; tries < maxTries; tries++) {
try {
await func()
return
} catch {}
await timeout(50)
}
await func()
}

type UntilBrowserLogAfterCallback = (logs: string[]) => PromiseLike<void> | void

export async function untilBrowserLogAfter(
Expand Down Expand Up @@ -288,32 +212,6 @@ async function untilBrowserLog(
return logs
}

export const extractSourcemap = (content: string): any => {
const lines = content.trim().split('\n')
return fromComment(lines[lines.length - 1]).toObject()
}

export const formatSourcemapForSnapshot = (map: any): any => {
const root = normalizePath(testDir)
const m = { ...map }
delete m.file
delete m.names
m.sources = m.sources.map((source) => source.replace(root, '/root'))
return m
}

// helper function to kill process, uses taskkill on windows to ensure child process is killed too
export async function killProcess(
serverProcess: ExecaChildProcess,
): Promise<void> {
if (isWindows) {
try {
const { execaCommandSync } = await import('execa')
execaCommandSync(`taskkill /pid ${serverProcess.pid} /T /F`)
} catch (e) {
console.error('failed to taskkill:', e)
}
} else {
serverProcess.kill('SIGTERM', { forceKillAfterTimeout: 2000 })
}
}
/**
* Before implementing a new util, check if it's not available in core https://github.com/vitejs/vite/blob/main/playground/test-utils.ts
*/

0 comments on commit d2a3931

Please sign in to comment.