Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions internal/templates/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,15 @@ func FetchAndApply(params ApplyParams, selected SelectedTemplate) ([]string, err

// Extract to temp dir
tmpDir := params.TmpDir
var extractDir string
if tmpDir == "" {
tmpDir = os.TempDir()
extractDir, err = os.MkdirTemp("", "devcontainer-template-")
if err != nil {
return nil, fmt.Errorf("create extract dir: %w", err)
}
} else {
extractDir = filepath.Join(tmpDir, "template-"+ref.ID)
}
extractDir := filepath.Join(tmpDir, "template-"+ref.ID)
if err := fsys.MkdirAll(extractDir); err != nil {
return nil, fmt.Errorf("create extract dir: %w", err)
}
Expand Down Expand Up @@ -191,7 +196,9 @@ func mergeFeatures(fsys pfs.FS, workspaceFolder string, featureOpts []TemplateFe
return fmt.Errorf("parse %s: %w", configPath, stdErr)
}
var config map[string]json.RawMessage
json.Unmarshal(stdData, &config)
if err := json.Unmarshal(stdData, &config); err != nil {
return fmt.Errorf("unmarshal %s: %w", configPath, err)
}
existing := map[string]bool{}
_, hasFeatures := config["features"]
if hasFeatures {
Expand Down Expand Up @@ -262,8 +269,12 @@ func applyOptionDefaults(fsys pfs.FS, extractDir string, userOptions map[string]
if err != nil {
return merged
}
standardized, err := hujson.Standardize(data)
if err != nil {
return merged
}
var meta TemplateMetadata
if err := json.Unmarshal(data, &meta); err != nil {
if err := json.Unmarshal(standardized, &meta); err != nil {
return merged
}
for key, raw := range meta.Options {
Expand Down
Loading