Skip to content

Commit

Permalink
fix: Support comments inside devcontainer-feature.json (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlehmann authored Nov 1, 2023
1 parent 500da9a commit 81eb6bf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions devcontainer/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/go-git/go-billy/v5"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/tailscale/hujson"
)

// Extract unpacks the feature from the image and returns the
Expand Down Expand Up @@ -113,9 +114,16 @@ func Extract(fs billy.Filesystem, directory, reference string) (*Spec, error) {
return nil, fmt.Errorf("open devcontainer-feature.json: %w", err)
}
defer featureFile.Close()
var spec *Spec
err = json.NewDecoder(featureFile).Decode(&spec)
featureFileBytes, err := io.ReadAll(featureFile)
if err != nil {
return nil, fmt.Errorf("read devcontainer-feature.json: %w", err)
}
standardizedFeatureFileBytes, err := hujson.Standardize(featureFileBytes)
if err != nil {
return nil, fmt.Errorf("standardize devcontainer-feature.json: %w", err)
}
var spec *Spec
if err := json.Unmarshal(standardizedFeatureFileBytes, &spec); err != nil {
return nil, fmt.Errorf("decode devcontainer-feature.json: %w", err)
}
// See https://containers.dev/implementors/features/#devcontainer-feature-json-properties
Expand Down

0 comments on commit 81eb6bf

Please sign in to comment.