Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cdk backwards compatibility #1549

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 19 additions & 3 deletions lwcomponent/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
return
}

CreateHostInfo(componentDir, component.Description, component.Type)

Check failure on line 213 in lwcomponent/catalog.go

View workflow job for this annotation

GitHub Actions / run-tests

Error return value is not checked (errcheck)

if component.ApiInfo != nil &&
(component.ApiInfo.ComponentType == BinaryType || component.ApiInfo.ComponentType == CommandType) {
Expand Down Expand Up @@ -347,14 +347,30 @@

components = make(map[string]CDKComponent, len(subDir))

// Prototype backwards compatibility
prototypeState, err := LocalState()
prototypeComponents := make(map[string]Component, len(prototypeState.Components))
for _, component := range prototypeState.Components {
prototypeComponents[component.Name] = component
}

for _, file := range subDir {
if !file.IsDir() {
continue
}

hostInfo, err := NewHostInfo(filepath.Join(cacheDir, file.Name()))
if err != nil {
continue
hostInfo, _ := NewHostInfo(filepath.Join(cacheDir, file.Name()))
if hostInfo == nil {

component, found := prototypeComponents[file.Name()]
if !found {
continue
}

hostInfo, err = CreateHostInfo(filepath.Join(cacheDir, file.Name()), component.Description, component.Type)
if err != nil {
return nil, err
}
}

if hostInfo.Development() {
Expand Down
8 changes: 4 additions & 4 deletions lwcomponent/host_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewHostInfo(dir string) (*HostInfo, error) {
return &info, nil
}

func CreateHostInfo(dir string, desc string, componentType Type) error {
func CreateHostInfo(dir string, desc string, componentType Type) (*HostInfo, error) {
path := filepath.Join(dir, InfoFile)

if !file.FileExists(path) {
Expand All @@ -58,13 +58,13 @@ func CreateHostInfo(dir string, desc string, componentType Type) error {

buf := new(bytes.Buffer)
if err := json.NewEncoder(buf).Encode(info); err != nil {
return err
return nil, err
}

return os.WriteFile(path, buf.Bytes(), 0644)
return info, os.WriteFile(path, buf.Bytes(), 0644)
}

return nil
return NewHostInfo(dir)
}

func (h *HostInfo) Delete() error {
Expand Down
Loading