Skip to content

Conversation

@sanket28
Copy link
Contributor

This adds source map file support to push and pull for services and libraries.

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

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

Choose a reason for hiding this comment

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

I think you need to escape the . otherwise it will match any character

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is working for me. Do you have an example that breaks this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sanket28 It works for files that ends in js.map, but it will also accept files that end in jsamap, jsbmap, jscmap, and so on...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I got that but do you have a working example that breaks? Like a unit test or Go playground link? I have tested this before with different file extensions and it's working for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sanket28

func TestRegex(t *testing.T) {
	r := `^code\/libraries\/([^\/]+)\/([^\/]+)\.(?:js|json|js.map)$`
	re := regexp.MustCompile(r)
	matches := re.FindStringSubmatch("code/libraries/service/service.jsamap")
	if len(matches) > 0 {
		t.Fatalf("Got %d matches, expected 0: %v", len(matches), matches)
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added the escape

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants