File tree Expand file tree Collapse file tree 5 files changed +24
-31
lines changed Expand file tree Collapse file tree 5 files changed +24
-31
lines changed Original file line number Diff line number Diff line change @@ -928,7 +928,8 @@ export async function loadConfigFromFile(
928928 // check package.json for type: "module" and set `isESM` to true
929929 try {
930930 const pkg = lookupFile ( configRoot , [ 'package.json' ] )
931- isESM = ! ! pkg && JSON . parse ( pkg ) . type === 'module'
931+ isESM =
932+ ! ! pkg && JSON . parse ( fs . readFileSync ( pkg , 'utf-8' ) ) . type === 'module'
932933 } catch ( e ) { }
933934 }
934935
Original file line number Diff line number Diff line change 11import fs from 'node:fs'
2+ import path from 'node:path'
23import { parse } from 'dotenv'
34import { expand } from 'dotenv-expand'
4- import { arraify , lookupFile } from './utils'
5+ import { arraify , tryStatSync } from './utils'
56import type { UserConfig } from './config'
67
78export function loadEnv (
@@ -26,12 +27,10 @@ export function loadEnv(
2627
2728 const parsed = Object . fromEntries (
2829 envFiles . flatMap ( ( file ) => {
29- const path = lookupFile ( envDir , [ file ] , {
30- pathOnly : true ,
31- rootDir : envDir ,
32- } )
33- if ( ! path ) return [ ]
34- return Object . entries ( parse ( fs . readFileSync ( path ) ) )
30+ const filePath = path . join ( envDir , file )
31+ if ( ! tryStatSync ( filePath ) ?. isFile ( ) ) return [ ]
32+
33+ return Object . entries ( parse ( fs . readFileSync ( filePath ) ) )
3534 } ) ,
3635 )
3736
Original file line number Diff line number Diff line change @@ -1186,13 +1186,10 @@ const lockfileFormats = [
11861186 { name : 'pnpm-lock.yaml' , checkPatches : false } , // Included in lockfile
11871187 { name : 'bun.lockb' , checkPatches : true } ,
11881188]
1189+ const lockfileNames = lockfileFormats . map ( ( l ) => l . name )
11891190
11901191export function getDepHash ( config : ResolvedConfig , ssr : boolean ) : string {
1191- const lockfilePath = lookupFile (
1192- config . root ,
1193- lockfileFormats . map ( ( l ) => l . name ) ,
1194- { pathOnly : true } ,
1195- )
1192+ const lockfilePath = lookupFile ( config . root , lockfileNames )
11961193 let content = lockfilePath ? fs . readFileSync ( lockfilePath , 'utf-8' ) : ''
11971194 if ( lockfilePath ) {
11981195 const lockfileName = path . basename ( lockfilePath )
Original file line number Diff line number Diff line change @@ -217,7 +217,11 @@ function cjsSsrCollectExternals(
217217 seen : Set < string > ,
218218 logger : Logger ,
219219) {
220- const rootPkgContent = lookupFile ( root , [ 'package.json' ] )
220+ const rootPkgPath = lookupFile ( root , [ 'package.json' ] )
221+ if ( ! rootPkgPath ) {
222+ return
223+ }
224+ const rootPkgContent = fs . readFileSync ( rootPkgPath , 'utf-8' )
221225 if ( ! rootPkgContent ) {
222226 return
223227 }
Original file line number Diff line number Diff line change @@ -390,28 +390,20 @@ export function tryStatSync(file: string): fs.Stats | undefined {
390390 // Ignore errors
391391 }
392392}
393- interface LookupFileOptions {
394- pathOnly ?: boolean
395- rootDir ?: string
396- }
397393
398394export function lookupFile (
399395 dir : string ,
400- formats : string [ ] ,
401- options ?: LookupFileOptions ,
396+ fileNames : string [ ] ,
402397) : string | undefined {
403- for ( const format of formats ) {
404- const fullPath = path . join ( dir , format )
405- if ( tryStatSync ( fullPath ) ?. isFile ( ) ) {
406- return options ?. pathOnly ? fullPath : fs . readFileSync ( fullPath , 'utf-8' )
398+ while ( dir ) {
399+ for ( const fileName of fileNames ) {
400+ const fullPath = path . join ( dir , fileName )
401+ if ( tryStatSync ( fullPath ) ?. isFile ( ) ) return fullPath
407402 }
408- }
409- const parentDir = path . dirname ( dir )
410- if (
411- parentDir !== dir &&
412- ( ! options ?. rootDir || parentDir . startsWith ( options ?. rootDir ) )
413- ) {
414- return lookupFile ( parentDir , formats , options )
403+ const parentDir = path . dirname ( dir )
404+ if ( parentDir === dir ) return
405+
406+ dir = parentDir
415407 }
416408}
417409
You can’t perform that action at this time.
0 commit comments