nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.32k stars 4.97k forks source link

Trace source of installed modules #25507

Open pi0 opened 8 months ago

pi0 commented 8 months ago

When modules use installModule kit util to install another, it is often hard to trace it without explicitly checking all bundled codes. Adding to top, when users also try to manually install some.

I think something we could at least do is to support new from param for installModule(name, { from: }. so that we can trace what module installed another and find a way to encourage module authors do it.

I guess we might at least leverage it for devtools to somehow visualize.

(as another enhancement, we could make nuxt kit made modules to be auto trackable using unctx and AsyncLocalStorage it might be useful for further DX enhancements)


Reference: How i debugged it currently by patching kit today:

async function installModule(moduleToInstall, inlineOptions, nuxt = useNuxt()) {
  if (typeof moduleToInstall === 'string') {
    const { parseNodeModulePath } = await importModule('mlly')
    const modulePkgName = parseNodeModulePath(moduleToInstall).name
    if (modulePkgName) {
      const trace = new Error('').stack.split('\n')[2]
      const traceFile = /\((.+)\)/.exec(trace)?.[1]?.split(':')[0]
      const traceName = parseNodeModulePath(traceFile).name
      consola.log(`Installing module ${modulePkgName} from ${traceName}`)
    }
  }
Installing module @nuxt/ui-pro from nuxt                                                                                       
Installing module nuxt-site-config from nuxt-site-config-kit                                                                   
Installing module nuxt-simple-robots from @nuxtjs/seo                                                                          
Installing module nuxt-site-config from nuxt-site-config-kit                                                                   
Installing module @nuxtjs/sitemap from @nuxtjs/seo                                                                             
Installing module nuxt-site-config from nuxt-site-config-kit                                                                   
Installing module nuxt-og-image from @nuxtjs/seo                                                                               
Installing module nuxt-schema-org from @nuxtjs/seo                                                                             
Installing module nuxt-seo-experiments from @nuxtjs/seo                                                                        
Installing module nuxt-site-config from nuxt-site-config-kit                                                                   
Installing module nuxt-link-checker from @nuxtjs/seo                                                                          
Installing module nuxt-site-config from nuxt-site-config-kit   
danielroe commented 8 months ago

I love the idea of auto tracking modules. (It should be possible even without unctx as modules run sequentially.)

pi0 commented 8 months ago

We could rely on sequential order until when one module installs another. Also with unctx and ALS i guess we might be abe to track hooks origin too.

BobbieGoede commented 1 week ago

Something like this would be great, the source of module installation gets even harder to track when this happens in layers and their modules.

Perhaps unrelated, it feels like there's still some functionality missing for installModule, shouldn't we be able to merge/retrieve all options passed to installModule like we do with module options passed for layers?