Skip to content

Commit

Permalink
fix: cdk backwards compatibility (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-stewart authored Feb 22, 2024
1 parent e5d3a91 commit 4a0f3b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
22 changes: 19 additions & 3 deletions lwcomponent/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,30 @@ func LoadLocalComponents() (components map[string]CDKComponent, err error) {

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

0 comments on commit 4a0f3b5

Please sign in to comment.