Skip to content

Commit

Permalink
chore: cleanup rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Jan 8, 2024
1 parent 6d3103a commit 1f1a432
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/plugin/vite/src/util/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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<PackageJsonManifest> {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 1f1a432

Please sign in to comment.