@@ -13,6 +13,7 @@ import { findPackageRoot } from '../utils/find-package-root';
1313import { findConfig } from '../utils/find-config' ;
1414import { MicrofrontendConfigIsomorphic } from '../../microfrontends-config/isomorphic' ;
1515import { getApplicationContext } from '../utils/get-application-context' ;
16+ import { logger } from '../../../bin/logger' ;
1617import { getOutputFilePath } from './utils/get-output-file-path' ;
1718import { validateSchema } from './validation' ;
1819
@@ -129,7 +130,14 @@ class MicrofrontendsServer {
129130 filePath ?: string ;
130131 cookies ?: { name : string ; value : string } [ ] ;
131132 } = { } ) : MicrofrontendsServer {
133+ logger . debug ( '[MFE Config] Starting config inference' , {
134+ appName,
135+ directory : directory || process . cwd ( ) ,
136+ filePath,
137+ } ) ;
138+
132139 if ( filePath ) {
140+ logger . debug ( '[MFE Config] Using explicit filePath:' , filePath ) ;
133141 return MicrofrontendsServer . fromFile ( {
134142 filePath,
135143 cookies,
@@ -138,20 +146,31 @@ class MicrofrontendsServer {
138146
139147 try {
140148 const packageRoot = findPackageRoot ( directory ) ;
149+ logger . debug ( '[MFE Config] Package root:' , packageRoot ) ;
150+
141151 const applicationContext = getApplicationContext ( {
142152 appName,
143153 packageRoot,
144154 } ) ;
155+ logger . debug ( '[MFE Config] Application context:' , applicationContext ) ;
145156
146157 const customConfigFilename =
147158 process . env . VC_MICROFRONTENDS_CONFIG_FILE_NAME ;
148159
160+ if ( customConfigFilename ) {
161+ logger . debug (
162+ '[MFE Config] Custom config filename from VC_MICROFRONTENDS_CONFIG_FILE_NAME:' ,
163+ customConfigFilename ,
164+ ) ;
165+ }
166+
149167 // see if we have a config file at the package root
150168 const maybeConfig = findConfig ( {
151169 dir : packageRoot ,
152170 customConfigFilename,
153171 } ) ;
154172 if ( maybeConfig ) {
173+ logger . debug ( '[MFE Config] Config found at package root:' , maybeConfig ) ;
155174 return MicrofrontendsServer . fromFile ( {
156175 filePath : maybeConfig ,
157176 cookies,
@@ -161,48 +180,85 @@ class MicrofrontendsServer {
161180 // if we don't have a microfrontends configuration file, see if we have another package in the repo that references this one
162181 const repositoryRoot = findRepositoryRoot ( ) ;
163182 const isMonorepo = isRepositoryMonorepo ( { repositoryRoot } ) ;
183+ logger . debug (
184+ '[MFE Config] Repository root:' ,
185+ repositoryRoot ,
186+ 'Is monorepo:' ,
187+ isMonorepo ,
188+ ) ;
189+
164190 const configFromEnv = process . env . VC_MICROFRONTENDS_CONFIG ;
165191 // the environment variable, if specified, takes precedence over other inference methods
166192 if ( typeof configFromEnv === 'string' ) {
193+ logger . debug (
194+ '[MFE Config] Checking VC_MICROFRONTENDS_CONFIG:' ,
195+ configFromEnv ,
196+ ) ;
167197 const maybeConfigFromEnv = resolve ( packageRoot , configFromEnv ) ;
168198 if ( maybeConfigFromEnv ) {
199+ logger . debug (
200+ '[MFE Config] Config loaded from VC_MICROFRONTENDS_CONFIG:' ,
201+ maybeConfigFromEnv ,
202+ ) ;
169203 return MicrofrontendsServer . fromFile ( {
170204 filePath : maybeConfigFromEnv ,
171205 cookies,
172206 } ) ;
173207 }
174208 } else {
175209 // when the VC_MICROFRONTENDS_CONFIG environment variable is not set, try to find the config in the .vercel directory first
210+ const vercelDir = join ( packageRoot , '.vercel' ) ;
211+ logger . debug (
212+ '[MFE Config] Searching for config in .vercel directory:' ,
213+ vercelDir ,
214+ ) ;
176215 const maybeConfigFromVercel = findConfig ( {
177- dir : join ( packageRoot , '.vercel' ) ,
216+ dir : vercelDir ,
178217 customConfigFilename,
179218 } ) ;
180219 if ( maybeConfigFromVercel ) {
220+ logger . debug (
221+ '[MFE Config] Config found in .vercel directory:' ,
222+ maybeConfigFromVercel ,
223+ ) ;
181224 return MicrofrontendsServer . fromFile ( {
182225 filePath : maybeConfigFromVercel ,
183226 cookies,
184227 } ) ;
185228 }
186229
187230 if ( isMonorepo ) {
231+ logger . debug (
232+ '[MFE Config] Inferring microfrontends location in monorepo for application:' ,
233+ applicationContext . name ,
234+ ) ;
188235 // find the default package
189236 const defaultPackage = inferMicrofrontendsLocation ( {
190237 repositoryRoot,
191238 applicationContext,
192239 customConfigFilename,
193240 } ) ;
241+ logger . debug (
242+ '[MFE Config] Inferred package location:' ,
243+ defaultPackage ,
244+ ) ;
194245
195246 // see if we have a config file at the package root
196247 const maybeConfigFromDefault = findConfig ( {
197248 dir : defaultPackage ,
198249 customConfigFilename,
199250 } ) ;
200251 if ( maybeConfigFromDefault ) {
252+ logger . debug (
253+ '[MFE Config] Config found in inferred package:' ,
254+ maybeConfigFromDefault ,
255+ ) ;
201256 return MicrofrontendsServer . fromFile ( {
202257 filePath : maybeConfigFromDefault ,
203258 cookies,
204259 } ) ;
205260 }
261+ logger . debug ( '[MFE Config] No config found in inferred package' ) ;
206262 }
207263 }
208264 // will be caught below
@@ -234,8 +290,13 @@ class MicrofrontendsServer {
234290 cookies ?: { name : string ; value : string } [ ] ;
235291 } ) : MicrofrontendsServer {
236292 try {
293+ logger . debug ( '[MFE Config] Reading config from file:' , filePath ) ;
237294 const configJson = fs . readFileSync ( filePath , 'utf-8' ) ;
238295 const config = MicrofrontendsServer . validate ( configJson ) ;
296+ logger . debug (
297+ '[MFE Config] Config loaded with applications:' ,
298+ Object . keys ( config . applications ) ,
299+ ) ;
239300
240301 return new MicrofrontendsServer ( {
241302 config,
0 commit comments