kezhenxu94 commented on a change in pull request #51:
URL: https://github.com/apache/skywalking-eyes/pull/51#discussion_r681404026



##########
File path: pkg/deps/npm.go
##########
@@ -141,79 +119,132 @@ func (resolver *NpmResolver) NeedSkipInstallPkgs() bool {
 }
 
 // InstallPkgs runs command 'npm install' to install node packages
-func (resolver *NpmResolver) InstallPkgs(root string) error {
+func (resolver *NpmResolver) InstallPkgs() {
        cmd := exec.Command("npm", "install")
-       cmd.Dir = root
        logger.Log.Println(fmt.Sprintf("Run command: %v, please wait", 
cmd.String()))
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
+       // Error occurs all the time in npm commands, so no return statement 
here
        if err := cmd.Run(); err != nil {
-               return err
+               logger.Log.Errorln(err)

Review comment:
       Do we want to log it again because the stderr has already printed this 
right?

##########
File path: pkg/deps/npm.go
##########
@@ -141,79 +119,132 @@ func (resolver *NpmResolver) NeedSkipInstallPkgs() bool {
 }
 
 // InstallPkgs runs command 'npm install' to install node packages
-func (resolver *NpmResolver) InstallPkgs(root string) error {
+func (resolver *NpmResolver) InstallPkgs() {
        cmd := exec.Command("npm", "install")
-       cmd.Dir = root
        logger.Log.Println(fmt.Sprintf("Run command: %v, please wait", 
cmd.String()))
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
+       // Error occurs all the time in npm commands, so no return statement 
here
        if err := cmd.Run(); err != nil {
-               return err
+               logger.Log.Errorln(err)
        }
-       return nil
 }
 
-// ResolvePackageLicense resolves the licenses of the given packages.
-func (resolver *NpmResolver) ResolvePackageLicense(depName string, report 
*Report) error {
-       depFiles, err := ioutil.ReadDir(depName)
+// ListPkgPaths runs npm command to list all the production only packages' 
absolute paths, one path per line
+// Note that although the flag `--long` can show more information line like a 
package's name,
+// its realization and printing format is not uniform in different npm-cli 
versions
+func (resolver *NpmResolver) ListPkgPaths() (io.Reader, error) {
+       buffer := &bytes.Buffer{}
+       cmd := exec.Command("npm", "ls", "--all", "--production", "--parseable")
+       cmd.Stderr = os.Stderr
+       cmd.Stdout = buffer
+       // Error occurs all the time in npm commands, so no return statement 
here
+       err := cmd.Run()
+       return buffer, err

Review comment:
       maybe we can remove the return value `error` because 
   
   - the error is mostly expected
   - we don't deal with the error when invoking this function
   - the stderr is printed and we don't need to get the error when invoking 
this function




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to