MCPcopy
hub / github.com/grafana/k6 / LoadMainModule

Method LoadMainModule

js/modules/resolution.go:219–240  ·  view source on GitHub ↗

LoadMainModule loads a main module and resolves all it dependencies checking for any linking issues. It does not run any javascript code, just compiling it and resolving module dependencies.

(pwd *url.URL, specifier string, data []byte)

Source from the content-addressed store, hash-verified

217// LoadMainModule loads a main module and resolves all it dependencies checking for any linking issues.
218// It does not run any javascript code, just compiling it and resolving module dependencies.
219func (mr *ModuleResolver) LoadMainModule(pwd *url.URL, specifier string, data []byte) error {
220 if _, err := mr.resolveLoaded(pwd, specifier, data); err != nil {
221 return err
222 }
223
224 mod, err := mr.resolve(pwd, specifier)
225 if err != nil {
226 return err
227 }
228 if err = mod.Link(); err != nil {
229 return err
230 }
231 _, ok := mod.(sobek.CyclicModuleRecord)
232 if !ok {
233 panic("somehow running source data for " + specifier + " didn't produce a cyclic module record")
234 }
235
236 if len(mr.unknownModules) > 0 {
237 return newUnknownModulesError(mr.unknownModules)
238 }
239 return nil
240}
241
242// ModuleSystem is implementing an ESM like module system to resolve js modules for k6 usage
243type ModuleSystem struct {

Callers 2

prepareFirstRunnerMethod · 0.95
RunSourceDataMethod · 0.80

Calls 4

resolveLoadedMethod · 0.95
resolveMethod · 0.95
newUnknownModulesErrorFunction · 0.85
LinkMethod · 0.45

Tested by

no test coverage detected