File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 11import path from 'path' ;
22import fs from 'fs' ;
3+ import { fileURLToPath } from 'url' ; // Explicitly import fileURLToPath.
34
45let memoizedRoot = null ;
56
@@ -8,16 +9,18 @@ function getProjectRoot() {
89 return memoizedRoot ;
910 }
1011
11- let currentDir = path . dirname ( new URL ( import . meta. url ) . pathname ) ;
12-
12+ // Convert import.meta.url to a file path
13+ const currentFilePath = fileURLToPath ( import . meta. url ) ;
14+ let currentDir = path . dirname ( currentFilePath ) ;
15+
1316 while ( currentDir !== path . parse ( currentDir ) . root ) {
1417 if ( fs . existsSync ( path . join ( currentDir , 'package.json' ) ) ) {
1518 memoizedRoot = currentDir ;
1619 return memoizedRoot ;
1720 }
1821 currentDir = path . dirname ( currentDir ) ;
1922 }
20-
23+
2124 throw new Error ( 'Unable to find the project root containing package.json' ) ;
2225}
2326
You can’t perform that action at this time.
0 commit comments