Skip to content

Commit

Permalink
feat: load go extensions based on go app's manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Nov 28, 2024
1 parent 9430a3a commit 79f17ad
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion core/src/ten_runtime/binding/go/tools/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,20 @@ func (ab *AppBuilder) autoDetectExtensions() error {
return nil
}

// Load the app's `manifest.json` to get the list of extension dependencies.
manifest, err := LoadManifest(ab.options.AppDir)
if err != nil {
return fmt.Errorf("Failed to load manifest.json: %v", err)
}

// Collect names of extensions from dependencies.
extensionNames := make(map[string]bool)
for _, dep := range manifest.Dependencies {
if dep.Type == "extension" {
extensionNames[dep.Name] = true
}
}

entries, err := os.ReadDir(extBaseDir)
if err != nil {
return err
Expand All @@ -1075,6 +1089,18 @@ func (ab *AppBuilder) autoDetectExtensions() error {
continue
}

// Check if the extension is in the list of extension dependencies.
extensionName := entry.Name()
if _, ok := extensionNames[extensionName]; !ok {
if ab.options.Verbose {
log.Printf(
"Skipping extension [%s], not in manifest dependencies.\n",
extensionName,
)
}
continue
}

extDir := path.Join(extBaseDir, entry.Name())
ext, err := LoadExtensionModule(extDir, ab.options.Verbose)
if err != nil {
Expand Down Expand Up @@ -1113,8 +1139,17 @@ func (ab *AppBuilder) autoDetectExtensions() error {

// -------------- manifest ---------------

type Dependency struct {
Type string `json:"type"`
Name string `json:"name"`
Version string `json:"version"`
}

type TenPackageManifest struct {
Type string `json:"type"`
Type string `json:"type"`
Name string `json:"name"`
Version string `json:"version"`
Dependencies []Dependency `json:"dependencies"`
}

func LoadManifest(pkgDir string) (*TenPackageManifest, error) {
Expand Down

0 comments on commit 79f17ad

Please sign in to comment.