-
Notifications
You must be signed in to change notification settings - Fork 0
Source map support #102
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
base: master
Are you sure you want to change the base?
Source map support #102
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package cblib | |
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
|
|
@@ -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) | ||
| } | ||
|
|
@@ -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)) | ||
| } | ||
|
|
||
|
|
@@ -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 { | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.ErrNotExistand returning an error if some other err is returned.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done