MCPcopy Index your code
hub / github.com/dagger/dagger / directoryAsModuleSource

Method directoryAsModuleSource

core/schema/modulesource.go:861–960  ·  view source on GitHub ↗
(
	ctx context.Context,
	contextDir dagql.ObjectResult[*core.Directory],
	args directoryAsModuleArgs,
)

Source from the content-addressed store, hash-verified

859}
860
861func (s *moduleSourceSchema) directoryAsModuleSource(
862 ctx context.Context,
863 contextDir dagql.ObjectResult[*core.Directory],
864 args directoryAsModuleArgs,
865) (inst dagql.Result[*core.ModuleSource], err error) {
866 query, err := core.CurrentQuery(ctx)
867 if err != nil {
868 return inst, err
869 }
870 dag, err := query.Server.Server(ctx)
871 if err != nil {
872 return inst, fmt.Errorf("failed to get dag server: %w", err)
873 }
874
875 sourceRootSubpath := args.SourceRootPath
876 if sourceRootSubpath == "" {
877 sourceRootSubpath = "."
878 }
879
880 dirSrc := &core.ModuleSource{
881 ConfigExists: true, // we can't load uninitialized dir modules, we'll error out later if it's not there
882 SourceRootSubpath: sourceRootSubpath,
883 ContextDirectory: contextDir,
884 Kind: core.ModuleSourceKindDir,
885 DirSrc: &core.DirModuleSource{
886 OriginalContextDir: contextDir,
887 OriginalSourceRootSubpath: args.SourceRootPath,
888 },
889 }
890 if dirSrc.SourceRootSubpath == "" {
891 dirSrc.SourceRootSubpath = "."
892 }
893
894 configPath := filepath.Join(dirSrc.SourceRootSubpath, modules.Filename)
895 var configContents string
896 err = dag.Select(ctx, contextDir, &configContents,
897 dagql.Selector{
898 Field: "file",
899 Args: []dagql.NamedInput{
900 {Name: "path", Value: dagql.String(configPath)},
901 },
902 },
903 dagql.Selector{Field: "contents"},
904 )
905 if err != nil {
906 return inst, fmt.Errorf("failed to load dir module dagger config: %w", err)
907 }
908 if err := s.initFromModConfig([]byte(configContents), dirSrc); err != nil {
909 return inst, err
910 }
911
912 // load this module source's deps in parallel
913 bk, err := query.Engine(ctx)
914 if err != nil {
915 return inst, fmt.Errorf("failed to get engine client: %w", err)
916 }
917
918 var eg errgroup.Group

Callers

nothing calls this directly

Calls 14

initFromModConfigMethod · 0.95
LoadUserDefaultsMethod · 0.95
CurrentQueryFunction · 0.92
StringTypeAlias · 0.92
NewLoaderFunction · 0.92
ResolveDepToSourceFunction · 0.92
NewResultForCurrentCallFunction · 0.92
SDKForModuleMethod · 0.80
ServerMethod · 0.65
SelectMethod · 0.65
EngineMethod · 0.65

Tested by

no test coverage detected