From 1f1a432c1d8f7b9ad5317336dfb20f036b1bf250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Wang=28=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7=29?= <308487730@qq.com> Date: Mon, 8 Jan 2024 19:32:02 +0800 Subject: [PATCH] chore: cleanup rename function --- packages/plugin/vite/src/util/package.ts | 6 +++--- .../test/ViteTypeScriptTemplate_spec_slow.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/plugin/vite/src/util/package.ts b/packages/plugin/vite/src/util/package.ts index 9b54ef0e05..f35a6241a2 100644 --- a/packages/plugin/vite/src/util/package.ts +++ b/packages/plugin/vite/src/util/package.ts @@ -14,7 +14,7 @@ export interface SourceAndDestination { dest: string; } -function isRootDirectory(dir: string) { +function isRootPath(dir: string) { // Linux or Windows root path return dir === '/' || /^[A-Z]:\\$/i.test(dir); } @@ -30,7 +30,7 @@ export async function lookupNodeModulesPaths(root: string, paths: string[] = []) } root = path.join(root, '..'); - return isRootDirectory(root) ? paths : await lookupNodeModulesPaths(root, paths); + return isRootPath(root) ? paths : await lookupNodeModulesPaths(root, paths); } export async function readPackageJson(root = process.cwd()): Promise { @@ -57,7 +57,7 @@ export async function resolveDependencies(root: string) { let curPath = prePath, depPath = null, packageJson = null; - while (!packageJson && !isRootDirectory(curPath)) { + while (!packageJson && !isRootPath(curPath)) { const allNodeModules = await lookupNodeModulesPaths(curPath); for (const nodeModules of allNodeModules) { diff --git a/packages/template/vite-typescript/test/ViteTypeScriptTemplate_spec_slow.ts b/packages/template/vite-typescript/test/ViteTypeScriptTemplate_spec_slow.ts index 565769df86..6c33598884 100644 --- a/packages/template/vite-typescript/test/ViteTypeScriptTemplate_spec_slow.ts +++ b/packages/template/vite-typescript/test/ViteTypeScriptTemplate_spec_slow.ts @@ -21,7 +21,16 @@ describe('ViteTypeScriptTemplate', () => { after(async () => { await yarnOrNpmSpawn(['link:remove']); await killWindowsEsbuildExe(); - await fs.remove(dir); + try { + await fs.remove(dir); + } catch (err1) { + console.log('[plugin-vite] err1:', err1); + try { + fs.rmSync(dir, { recursive: true, force: true }); + } catch (err2) { + console.log('[plugin-vite] err2:', err2); + } + } }); describe('template files are copied to project', () => {