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

Function modifyLocalModule

cmd/dagger/module.go:1199–1240  ·  view source on GitHub ↗

modifyLocalModule is a helper that loads a local module source, applies a transformation, and exports the generated context directory back to disk.

(ctx context.Context, transform func(*dagger.Client, *dagger.ModuleSource) *dagger.ModuleSource)

Source from the content-addressed store, hash-verified

1197// modifyLocalModule is a helper that loads a local module source, applies a
1198// transformation, and exports the generated context directory back to disk.
1199func modifyLocalModule(ctx context.Context, transform func(*dagger.Client, *dagger.ModuleSource) *dagger.ModuleSource) error {
1200 return withEngine(ctx, client.Params{
1201 SkipWorkspaceModules: true,
1202 }, func(ctx context.Context, engineClient *client.Client) error {
1203 dag := engineClient.Dagger()
1204
1205 modRef, err := getModuleSourceRefWithDefault()
1206 if err != nil {
1207 return err
1208 }
1209 modSrc := dag.ModuleSource(modRef, dagger.ModuleSourceOpts{
1210 RequireKind: dagger.ModuleSourceKindLocalSource,
1211 })
1212
1213 alreadyExists, err := modSrc.ConfigExists(ctx)
1214 if err != nil {
1215 return localModuleErrorf("failed to check if module already exists: %w", err)
1216 }
1217 if !alreadyExists {
1218 return fmt.Errorf("module must be fully initialized")
1219 }
1220
1221 contextDirPath, err := modSrc.LocalContextDirectoryPath(ctx)
1222 if err != nil {
1223 return localModuleErrorf("failed to get local context directory path: %w", err)
1224 }
1225
1226 modSrc = transform(dag, modSrc)
1227 if engineVersion := getCompatVersion(); engineVersion != "" {
1228 modSrc = modSrc.WithEngineVersion(engineVersion)
1229 }
1230
1231 _, err = modSrc.
1232 GeneratedContextDirectory().
1233 Export(ctx, contextDirPath)
1234 if err != nil {
1235 return fmt.Errorf("failed to update dependencies: %w", err)
1236 }
1237
1238 return nil
1239 })
1240}
1241
1242func localModuleErrorf(format string, err error) error {
1243 if err == nil {

Callers 1

module.goFile · 0.85

Calls 11

withEngineFunction · 0.85
localModuleErrorfFunction · 0.85
getCompatVersionFunction · 0.85
DaggerMethod · 0.80
ExportMethod · 0.65
ModuleSourceMethod · 0.45
ConfigExistsMethod · 0.45
WithEngineVersionMethod · 0.45

Tested by

no test coverage detected