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

Method initializeGoModule

js/modules/resolution.go:72–93  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

70}
71
72func (mr *ModuleResolver) initializeGoModule(name string) (sobek.ModuleRecord, error) {
73 if mr.locked {
74 return nil, fmt.Errorf(notPreviouslyResolvedModule, name)
75 }
76 mod, ok := mr.goModules[name]
77 if !ok {
78 mr.unknownModules = append(mr.unknownModules, name)
79 return &unknownModule{name: name, requested: make(map[string]struct{})}, nil
80 }
81 // we don't want to report extensions and we would have hit cache if this isn't the first time
82 if !strings.HasPrefix(name, "k6/x/") {
83 err := mr.usage.Strings("modules", name)
84 if err != nil {
85 mr.logger.WithError(err).Warnf("Error while reporting usage of module %q", name)
86 }
87 }
88 k6m, ok := mod.(Module)
89 if !ok {
90 return &basicGoModule{m: mod}, nil
91 }
92 return &goModule{m: k6m}, nil
93}
94
95func isESM(prg *ast.Program) bool {
96 // NOTE(@mstoykov): this only exists in order for k6 to figure out if code should be tried as CommonJS

Callers 1

resolveMethod · 0.95

Calls 3

ErrorfMethod · 0.80
StringsMethod · 0.80
WarnfMethod · 0.80

Tested by

no test coverage detected