MCPcopy
hub / github.com/vitejs/vite / load

Method load

packages/vite/src/node/server/pluginContainer.ts:816–840  ·  view source on GitHub ↗
(
    options: {
      id: string
      resolveDependencies?: boolean
    } & Partial<PartialNull<ModuleOptions>>,
  )

Source from the content-addressed store, hash-verified

814 }
815
816 async load(
817 options: {
818 id: string
819 resolveDependencies?: boolean
820 } & Partial<PartialNull<ModuleOptions>>,
821 ): Promise<ModuleInfo> {
822 // We may not have added this to our module graph yet, so ensure it exists
823 await this._container.moduleGraph?.ensureEntryFromUrl(unwrapId(options.id))
824 // Not all options passed to this function make sense in the context of loading individual files,
825 // but we can at least update the module info properties we support
826 this._updateModuleInfo(options.id, options)
827
828 const loadResult = await this._container.load(options.id)
829 const code = typeof loadResult === 'object' ? loadResult?.code : loadResult
830 if (code != null) {
831 await this._container.transform(code, options.id)
832 }
833
834 const moduleInfo = this.getModuleInfo(options.id)
835 // This shouldn't happen due to calling ensureEntryFromUrl, but 1) our types can't ensure that
836 // and 2) moduleGraph may not have been provided (though in the situations where that happens,
837 // we should never have plugins calling this.load)
838 if (!moduleInfo) throw Error(`Failed to load module with id ${options.id}`)
839 return moduleInfo
840 }
841
842 getModuleInfo(id: string): ModuleInfo | null {
843 return this._container.getModuleInfo(id)

Callers 6

loadMethod · 0.45
loadAndTransformFunction · 0.45
transformFunction · 0.45
handlerFunction · 0.45
index.spec.tsFile · 0.45

Calls 5

_updateModuleInfoMethod · 0.95
getModuleInfoMethod · 0.95
unwrapIdFunction · 0.90
ensureEntryFromUrlMethod · 0.45
transformMethod · 0.45

Tested by 1

transformFunction · 0.36