Skip to content
Open
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
50 changes: 50 additions & 0 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cblib
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -809,6 +810,13 @@ func writeService(name string, data map[string]interface{}) error {
return err
}

sourceMap, ok := data["source_map"].(string)
if ok && sourceMap != "" {
if err := ioutil.WriteFile(mySvcDir+"/"+name+".js.map", []byte(data["source_map"].(string)), 0666); err != nil {
return err
}
}

omitServiceFields(data)
return writeEntity(mySvcDir, name, data)
}
Expand Down Expand Up @@ -935,6 +943,12 @@ func writeLibrary(name string, data map[string]interface{}) error {
if err := ioutil.WriteFile(myLibDir+"/"+name+".js", []byte(data["code"].(string)), 0666); err != nil {
return err
}
sourceMap, ok := data["source_map"].(string)
if ok && sourceMap != "" {
if err := ioutil.WriteFile(myLibDir+"/"+name+".js.map", []byte(data["source_map"].(string)), 0666); err != nil {
return err
}
}
return writeEntity(myLibDir, name, whitelistLibrary(data))
}

Expand Down Expand Up @@ -1154,6 +1168,18 @@ func getCodeStuff(dirName string) ([]map[string]interface{}, error) {
fmt.Printf("ioutil.ReadFile failed: %s\n", err)
return nil, err
}
_, err = os.Stat(myRootDir + "/" + realDirName + ".js.map")
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to check if the file exists? If so, I recommend checking fs.ErrNotExist and returning an error if some other err is returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

bytsMap, err := ioutil.ReadFile(myRootDir + "/" + realDirName + ".js.map")
if err != nil {
fmt.Printf("ioutil.ReadFile for source map failed: %s\n", err)
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the error get printed out already? Won't this result in the error being printed twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a lot of places we just return the error and dont print it at all so its better this way

}
myObj["source_map"] = string(bytsMap)
} else if !errors.Is(err, os.ErrNotExist) {
fmt.Printf("os.Stat for source map failed: %s\n", err)
return nil, err
}
myObj["code"] = string(byts)
delete(myObj, "source")
rval = append(rval, myObj)
Expand Down Expand Up @@ -1428,6 +1454,7 @@ func getCollection(name string) (map[string]interface{}, error) {
func getService(name string) (map[string]interface{}, error) {
svcRootDir := svcDir + "/" + name
codeFile := name + ".js"
sourceMapFile := name + ".js.map"
schemaFile := name + ".json"

svcMap, err := getObject(svcRootDir, schemaFile)
Expand All @@ -1438,13 +1465,25 @@ func getService(name string) (map[string]interface{}, error) {
if err != nil {
return nil, err
}
_, err = os.Stat(svcRootDir + "/" + sourceMapFile)
if err == nil {
bytsMap, err := ioutil.ReadFile(svcRootDir + "/" + sourceMapFile)
if err != nil {
return nil, err
}
svcMap["source_map"] = string(bytsMap)
} else if !errors.Is(err, os.ErrNotExist) {
fmt.Printf("os.Stat for source map failed: %s\n", err)
return nil, err
}
svcMap["code"] = string(byts)
return svcMap, nil
}

func getLibrary(name string) (map[string]interface{}, error) {
libRootDir := libDir + "/" + name
codeFile := name + ".js"
sourceMapFile := name + ".js.map"
schemaFile := name + ".json"

libMap, err := getObject(libRootDir, schemaFile)
Expand All @@ -1455,6 +1494,17 @@ func getLibrary(name string) (map[string]interface{}, error) {
if err != nil {
return nil, err
}
_, err = os.Stat(libRootDir + "/" + sourceMapFile)
if err == nil {
bytsMap, err := ioutil.ReadFile(libRootDir + "/" + sourceMapFile)
if err != nil {
return nil, err
}
libMap["source_map"] = string(bytsMap)
} else if !errors.Is(err, os.ErrNotExist) {
fmt.Printf("os.Stat for source map failed: %s\n", err)
return nil, err
}
libMap["code"] = string(byts)
return libMap, nil
}
Expand Down
2 changes: 1 addition & 1 deletion push.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func pushSystemZip(systemInfo *types.System_meta, client *cb.DevClient, options
}

if dryRun.HasErrors() {
return fmt.Errorf(dryRun.String())
return fmt.Errorf("%s", dryRun.String())
}

if !dryRun.HasChanges() {
Expand Down
4 changes: 2 additions & 2 deletions syspath/code_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

const (
servicePathRegexStr = `^code\/services\/([^\/]+)\/([^\/]+)\.(?:js|json)$`
libraryPathRegexStr = `^code\/libraries\/([^\/]+)\/([^\/]+)\.(?:js|json)$`
servicePathRegexStr = `^code\/services\/([^\/]+)\/([^\/]+)\.(?:js|json|js\.map)$`
libraryPathRegexStr = `^code\/libraries\/([^\/]+)\/([^\/]+)\.(?:js|json|js\.map)$`
)

var (
Expand Down
4 changes: 4 additions & 0 deletions syspath/syspath.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func IsJsonFile(path string) bool {
return getFileExtension(path) == "json"
}

func IsJsMapFile(path string) bool {
return getFileExtension(path) == "map"
}

func GetFileName(path string) string {
_, fileName := pth.Split(path)
return fileName
Expand Down