Skip to content

Commit

Permalink
Connecting up the augmentor
Browse files Browse the repository at this point in the history
  • Loading branch information
grantnelson-wf committed Jan 21, 2025
1 parent 13c626e commit df8064f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 12 additions & 2 deletions build/augmentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Augmentor struct {
packages map[string]*pkgOverrideInfo
}

func (aug *Augmentor) Augment(xctx XContext, pkg *PackageData, fileSet *token.FileSet, file *ast.File) {
func (aug *Augmentor) Augment(xctx XContext, pkg *PackageData, fileSet *token.FileSet, file *ast.File) error {
pkgAug := aug.getPackageOverrides(xctx, pkg, fileSet)

augmentOriginalImports(pkg.ImportPath, file)
Expand All @@ -80,10 +80,20 @@ func (aug *Augmentor) Augment(xctx XContext, pkg *PackageData, fileSet *token.Fi
// additional methods and information from the natives.
err := astutil.ConcatenateFiles(file, pkgAug.overlayFiles...)
if err != nil {
panic(fmt.Errorf("failed to concatenate overlay files onto %q: %w", fileSet.Position(file.Package).Filename, err))
return fmt.Errorf("failed to concatenate overlay files onto %q: %w", fileSet.Position(file.Package).Filename, err)
}
pkgAug.overlayFiles = nil
}

return nil
}

func (aug *Augmentor) GetJSFiles(pkg *PackageData) []JSFile {
pkgAug, ok := aug.packages[pkg.ImportPath]
if !ok {
return nil
}
return pkgAug.jsFiles
}

// getPackageOverrides looks up an already loaded package override
Expand Down
7 changes: 5 additions & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ func parseAndAugment(xctx XContext, pkg *PackageData, fileSet *token.FileSet) ([

aug := &Augmentor{}
for _, file := range originalFiles {
aug.Augment(xctx, pkg, fileSet, file)
err := aug.Augment(xctx, pkg, fileSet, file)
if err != nil {
return nil, nil, err
}
}

jsFiles := aug.packages[pkg.ImportPath].jsFiles
jsFiles := aug.GetJSFiles(pkg)
return originalFiles, jsFiles, nil
}

Expand Down

0 comments on commit df8064f

Please sign in to comment.