File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -123,27 +123,49 @@ export function isSkipped(name: string): boolean {
123123 return process . env [ skipEnvVar ] === '1' || process . env [ skipEnvVar ] === 'true'
124124}
125125
126+ // Cache for DDEV detection to avoid repeated filesystem checks
127+ let _ddevProjectCache : boolean | null = null
128+
126129/**
127130 * Check if the current project is a DDEV project
131+ * Result is cached after first call for performance.
128132 * @returns True if .ddev/config.yaml exists and ddev binary is available
129133 */
130134export async function isDdevProject ( ) : Promise < boolean > {
135+ // Return cached result if available
136+ if ( _ddevProjectCache !== null ) {
137+ return _ddevProjectCache
138+ }
139+
131140 // Allow explicit disable via env var
132141 if ( process . env . DDEV_PHP === 'false' || process . env . DDEV_PHP === '0' ) {
142+ _ddevProjectCache = false
133143 return false
134144 }
135145
136146 const hasConfig = await fs . pathExists ( '.ddev/config.yaml' )
137- if ( ! hasConfig ) return false
147+ if ( ! hasConfig ) {
148+ _ddevProjectCache = false
149+ return false
150+ }
138151
139152 try {
140153 await which ( 'ddev' )
154+ _ddevProjectCache = true
141155 return true
142156 } catch {
157+ _ddevProjectCache = false
143158 return false
144159 }
145160}
146161
162+ /**
163+ * Reset DDEV detection cache (useful for testing)
164+ */
165+ export function resetDdevCache ( ) : void {
166+ _ddevProjectCache = null
167+ }
168+
147169/**
148170 * Get the DDEV project name from .ddev/config.yaml
149171 * @returns The project name or null if not found
Original file line number Diff line number Diff line change 55 formatDuration ,
66 isSkipped ,
77 isDdevProject ,
8+ resetDdevCache ,
89 exec ,
910 ensureMutagenSync
1011} from '../../shared/core'
@@ -42,6 +43,7 @@ describe('core.ts', () => {
4243 beforeEach ( ( ) => {
4344 vi . clearAllMocks ( )
4445 vi . resetModules ( )
46+ resetDdevCache ( ) // Reset DDEV cache between tests
4547 process . env = { ...process . env } // Clone env
4648 delete process . env . DDEV_PHP // Ensure this doesn't interfere
4749 } )
You can’t perform that action at this time.
0 commit comments