Skip to content

Commit c60294b

Browse files
committed
Fix find root
1 parent 898d691 commit c60294b

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

packages/next-plugin/src/find-root.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import { dirname, join } from 'node:path'
44
export function findRoot(dir: string): string {
55
let root = dir
66
let prev = null
7-
const collectecd: string[] = []
7+
let result: string = process.cwd()
88
while (prev === null || root !== prev) {
9-
if (existsSync(join(root, 'package.json')) && !collectecd.includes(root)) {
10-
collectecd.push(root)
9+
if (existsSync(join(root, 'package.json'))) {
10+
result = root
1111
}
1212
prev = root
1313
root = dirname(root)
1414
}
15-
if (collectecd.length > 0) {
16-
return collectecd.pop()!
17-
}
18-
return process.cwd()
15+
return result
1916
}

0 commit comments

Comments
 (0)