From 1530cde90eea773cc904314d80f93d462b9106f9 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 13 Aug 2023 11:20:33 +0300 Subject: [PATCH 01/10] Fix npm output Signed-off-by: Michael Sverdlov --- build/npm.go | 8 +++++--- build/utils/npm.go | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/build/npm.go b/build/npm.go index 45659e0e..6463ade8 100644 --- a/build/npm.go +++ b/build/npm.go @@ -54,10 +54,12 @@ func newNpmModule(srcPath string, containingBuild *Build) (*NpmModule, error) { func (nm *NpmModule) Build() error { if len(nm.npmArgs) > 0 { - _, errData, err := buildutils.RunNpmCmd(nm.executablePath, nm.srcPath, nm.npmArgs, &utils.NullLog{}) + output, _, err := buildutils.RunNpmCmd(nm.executablePath, nm.srcPath, nm.npmArgs, &utils.NullLog{}) + if len(output) > 0 { + nm.containingBuild.logger.Output(string(output)) + } if err != nil { - // NpmArgs[0] includes the npm command. - return errors.New("couldn't run npm " + nm.npmArgs[0] + ": " + string(errData)) + return err } // After executing the user-provided command, cleaning npmArgs is needed. nm.filterNpmArgsFlags() diff --git a/build/utils/npm.go b/build/utils/npm.go index 1be6a632..696184df 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -371,7 +371,7 @@ func RunNpmCmd(executablePath, srcPath string, npmArgs []string, log utils.Log) errResult = errBuffer.Bytes() stdResult = outBuffer.Bytes() if err != nil { - err = errors.New("error while running the command :'" + executablePath + " " + strings.Join(tmpArgs, " ") + "'\nError output is:\n" + string(errResult) + "\nCommand error: is:\n" + err.Error()) + err = fmt.Errorf("error while running '%s %s': %s\n%s", executablePath, strings.Join(tmpArgs, " "), string(errResult), err.Error()) return } // The npm command is the first element in tmpArgs array. @@ -441,6 +441,9 @@ func ReadPackageInfo(data []byte, npmVersion *version.Version) (*PackageInfo, er } func (pi *PackageInfo) BuildInfoModuleId() string { + if pi.Name == "" || pi.Version == "" { + return "" + } nameBase := fmt.Sprintf("%s:%s", pi.Name, pi.Version) if pi.Scope == "" { return nameBase @@ -450,6 +453,7 @@ func (pi *PackageInfo) BuildInfoModuleId() string { func (pi *PackageInfo) GetDeployPath() string { fileName := fmt.Sprintf("%s-%s.tgz", pi.Name, pi.Version) + // The hyphen part below "/-/" is there in order to follow the layout used by the public NPM registry. if pi.Scope == "" { return fmt.Sprintf("%s/-/%s", pi.Name, fileName) } From e06b38b7393493fb5acb324682725f6c8296b9cb Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 13 Aug 2023 11:22:14 +0300 Subject: [PATCH 02/10] Fix npm output Signed-off-by: Michael Sverdlov --- build/npm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/npm.go b/build/npm.go index 6463ade8..883eb780 100644 --- a/build/npm.go +++ b/build/npm.go @@ -56,7 +56,7 @@ func (nm *NpmModule) Build() error { if len(nm.npmArgs) > 0 { output, _, err := buildutils.RunNpmCmd(nm.executablePath, nm.srcPath, nm.npmArgs, &utils.NullLog{}) if len(output) > 0 { - nm.containingBuild.logger.Output(string(output)) + nm.containingBuild.logger.Info(string(output)) } if err != nil { return err From d7ce945e15a7d2be630af8168426e479e671be48 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sat, 19 Aug 2023 11:14:56 +0300 Subject: [PATCH 03/10] Fix docs Signed-off-by: Michael Sverdlov --- build/utils/npm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/utils/npm.go b/build/utils/npm.go index 696184df..df5fc3b2 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -488,7 +488,7 @@ func GetNpmConfigCache(srcPath, executablePath string, npmArgs []string, log uti data, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(append(npmArgs, "--json=false"), "config"), log) // Some warnings and messages of npm are printed to stderr. They don't cause the command to fail, but we'd want to show them to the user. if len(errData) > 0 { - log.Warn("error while running the command :'" + executablePath + " " + strings.Join(npmArgs, " ") + ":\n" + string(errData)) + log.Warn("error while running the command: '" + executablePath + " " + strings.Join(npmArgs, " ") + ":\n" + string(errData)) } if err != nil { return "", fmt.Errorf("'%s %s' npm config command failed with an error: %s", executablePath, strings.Join(npmArgs, " "), err.Error()) From 6d0913033815d6bd965880ba2191e78dd1e1f2d3 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sat, 19 Aug 2023 11:16:09 +0300 Subject: [PATCH 04/10] Fix docs Signed-off-by: Michael Sverdlov --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index c2c36f8c..4848b166 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.25.7 github.com/xeipuuv/gojsonschema v1.2.0 - golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b + golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 ) require ( @@ -23,6 +23,6 @@ require ( github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - golang.org/x/sys v0.1.0 // indirect + golang.org/x/sys v0.11.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 65cd60bd..0f1e7399 100644 --- a/go.sum +++ b/go.sum @@ -34,11 +34,11 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI= -golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= +golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From f2b17c7a2def11d204fa4a856e0f5c25a5dad925 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 20 Aug 2023 18:10:16 +0300 Subject: [PATCH 05/10] Fix docs Signed-off-by: Michael Sverdlov --- build/npm.go | 2 +- build/utils/npm.go | 4 ++-- build/utils/npm_test.go | 32 +++++++++++++++++--------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/build/npm.go b/build/npm.go index 883eb780..66d52e04 100644 --- a/build/npm.go +++ b/build/npm.go @@ -56,7 +56,7 @@ func (nm *NpmModule) Build() error { if len(nm.npmArgs) > 0 { output, _, err := buildutils.RunNpmCmd(nm.executablePath, nm.srcPath, nm.npmArgs, &utils.NullLog{}) if len(output) > 0 { - nm.containingBuild.logger.Info(string(output)) + nm.containingBuild.logger.Output(strings.TrimSpace(string(output))) } if err != nil { return err diff --git a/build/utils/npm.go b/build/utils/npm.go index df5fc3b2..9234f3c3 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -371,11 +371,11 @@ func RunNpmCmd(executablePath, srcPath string, npmArgs []string, log utils.Log) errResult = errBuffer.Bytes() stdResult = outBuffer.Bytes() if err != nil { - err = fmt.Errorf("error while running '%s %s': %s\n%s", executablePath, strings.Join(tmpArgs, " "), string(errResult), err.Error()) + err = fmt.Errorf("error while running '%s %s': %s\n%s", executablePath, strings.Join(tmpArgs, " "), strings.TrimSpace(string(errResult)), err.Error()) return } // The npm command is the first element in tmpArgs array. - log.Debug("npm " + tmpArgs[0] + " standard output is:\n" + string(stdResult)) + log.Debug("npm " + tmpArgs[0] + " standard output is:\n" + strings.TrimSpace(string(stdResult))) return } diff --git a/build/utils/npm_test.go b/build/utils/npm_test.go index b0bb6e81..fc995b30 100644 --- a/build/utils/npm_test.go +++ b/build/utils/npm_test.go @@ -199,7 +199,7 @@ func TestDependencyWithNoIntegrity(t *testing.T) { } // A project built differently for each operating system. -func TestDependenciesTreeDiffrentBetweenOss(t *testing.T) { +func TestDependenciesTreeDifferentBetweenOKs(t *testing.T) { npmVersion, _, err := GetNpmVersionAndExecPath(logger) assert.NoError(t, err) path, err := filepath.Abs(filepath.Join("..", "testdata")) @@ -242,19 +242,21 @@ func TestNpmProdFlag(t *testing.T) { {"--prod", 1}, } for _, entry := range testDependencyScopes { - projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project3", false, npmVersion) - defer cleanup() - cacachePath := filepath.Join(projectPath, "tmpcache") - npmArgs := []string{"--cache=" + cacachePath, entry.scope} - - // Install dependencies in the npm project. - _, _, err = RunNpmCmd("npm", projectPath, AppendNpmCommand(npmArgs, "ci"), logger) - assert.NoError(t, err) - - // Calculate dependencies with scope. - dependencies, err := CalculateNpmDependenciesList("npm", projectPath, "build-info-go-tests", npmArgs, true, logger) - assert.NoError(t, err) - assert.Len(t, dependencies, entry.totalDeps) + func() { + projectPath, cleanup := testdatautils.CreateNpmTest(t, path, "project3", false, npmVersion) + defer cleanup() + cacachePath := filepath.Join(projectPath, "tmpcache") + npmArgs := []string{"--cache=" + cacachePath, entry.scope} + + // Install dependencies in the npm project. + _, _, err = RunNpmCmd("npm", projectPath, AppendNpmCommand(npmArgs, "ci"), logger) + assert.NoError(t, err) + + // Calculate dependencies with scope. + dependencies, err := CalculateNpmDependenciesList("npm", projectPath, "build-info-go-tests", npmArgs, true, logger) + assert.NoError(t, err) + assert.Len(t, dependencies, entry.totalDeps) + }() } } @@ -296,7 +298,7 @@ func TestGetConfigCacheNpmIntegration(t *testing.T) { // 2. node_module doesn't exist in the project and generating dependencies needs package-lock. func validateDependencies(t *testing.T, projectPath string, npmArgs []string) { // Install dependencies in the npm project. - _, _, err := RunNpmCmd("npm", projectPath, AppendNpmCommand(npmArgs,"ci"), logger) + _, _, err := RunNpmCmd("npm", projectPath, AppendNpmCommand(npmArgs, "ci"), logger) assert.NoError(t, err) // Calculate dependencies. From 613515b798f1b066ef8ddce03672d5b3336fa6d2 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 20 Aug 2023 18:36:57 +0300 Subject: [PATCH 06/10] Fix docs Signed-off-by: Michael Sverdlov --- build/utils/npm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/utils/npm.go b/build/utils/npm.go index 9234f3c3..fa4a99d5 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -488,7 +488,7 @@ func GetNpmConfigCache(srcPath, executablePath string, npmArgs []string, log uti data, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(append(npmArgs, "--json=false"), "config"), log) // Some warnings and messages of npm are printed to stderr. They don't cause the command to fail, but we'd want to show them to the user. if len(errData) > 0 { - log.Warn("error while running the command: '" + executablePath + " " + strings.Join(npmArgs, " ") + ":\n" + string(errData)) + log.Warn("error while running the command '" + executablePath + " " + strings.Join(npmArgs, " ") + "' :\n" + string(errData)) } if err != nil { return "", fmt.Errorf("'%s %s' npm config command failed with an error: %s", executablePath, strings.Join(npmArgs, " "), err.Error()) From cc245a2e8b6db889cc599a0a88560f881ece8615 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 20 Aug 2023 18:44:17 +0300 Subject: [PATCH 07/10] Fix docs Signed-off-by: Michael Sverdlov --- build/utils/npm.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build/utils/npm.go b/build/utils/npm.go index fa4a99d5..3bebc733 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -123,10 +123,10 @@ func runNpmLsWithNodeModules(executablePath, srcPath string, npmArgs []string, l data, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(npmArgs, "ls"), log) if err != nil { // It is optional for the function to return this error. - log.Warn("npm list command failed with error:", err.Error()) + log.Warn(err.Error()) } if len(errData) > 0 { - log.Warn("Some errors occurred while collecting dependencies info:\n" + string(errData)) + log.Warn("Encountered some issues while running 'npm ls' command:\n" + string(errData)) } return } @@ -145,10 +145,10 @@ func runNpmLsWithoutNodeModules(executablePath, srcPath string, npmArgs []string npmArgs = append(npmArgs, "--json", "--all", "--long", "--package-lock-only") data, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(npmArgs, "ls"), log) if err != nil { - log.Warn("npm list command failed with error:", err.Error()) + log.Warn(err.Error()) } if len(errData) > 0 { - log.Warn("Some errors occurred while collecting dependencies info:\n" + string(errData)) + log.Warn("Encountered some issues while running 'npm ls' command:\n" + string(errData)) } return data, nil } @@ -157,9 +157,9 @@ func installPackageLock(executablePath, srcPath string, npmArgs []string, log ut if npmVersion.AtLeast("6.0.0") { npmArgs = append(npmArgs, "--package-lock-only") // Installing package-lock to generate the dependencies map. - _, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(npmArgs, "install"), log) + _, _, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(npmArgs, "install"), log) if err != nil { - return errors.New("Some errors occurred while installing package-lock: " + string(errData)) + return err } return nil } @@ -491,7 +491,7 @@ func GetNpmConfigCache(srcPath, executablePath string, npmArgs []string, log uti log.Warn("error while running the command '" + executablePath + " " + strings.Join(npmArgs, " ") + "' :\n" + string(errData)) } if err != nil { - return "", fmt.Errorf("'%s %s' npm config command failed with an error: %s", executablePath, strings.Join(npmArgs, " "), err.Error()) + return "", err } cachePath := filepath.Join(strings.Trim(string(data), "\n"), "_cacache") found, err := utils.IsDirExists(cachePath, true) From 0d4f499822dd565ed913d6ca0fd57e6bffec3d7e Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 20 Aug 2023 18:49:42 +0300 Subject: [PATCH 08/10] Fix docs Signed-off-by: Michael Sverdlov --- build/utils/npm.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/build/utils/npm.go b/build/utils/npm.go index 3bebc733..d79cb195 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -354,14 +354,14 @@ func appendScopes(oldScopes []string, newScopes []string) []string { func RunNpmCmd(executablePath, srcPath string, npmArgs []string, log utils.Log) (stdResult, errResult []byte, err error) { log.Debug("Running npm " + npmArgs[0] + " command.") - tmpArgs := make([]string, 0) + args := make([]string, 0) for i := 0; i < len(npmArgs); i++ { if strings.TrimSpace(npmArgs[i]) != "" { - tmpArgs = append(tmpArgs, npmArgs[i]) + args = append(args, npmArgs[i]) } } - command := exec.Command(executablePath, tmpArgs...) + command := exec.Command(executablePath, args...) command.Dir = srcPath outBuffer := bytes.NewBuffer([]byte{}) command.Stdout = outBuffer @@ -371,11 +371,10 @@ func RunNpmCmd(executablePath, srcPath string, npmArgs []string, log utils.Log) errResult = errBuffer.Bytes() stdResult = outBuffer.Bytes() if err != nil { - err = fmt.Errorf("error while running '%s %s': %s\n%s", executablePath, strings.Join(tmpArgs, " "), strings.TrimSpace(string(errResult)), err.Error()) + err = fmt.Errorf("error while running '%s %s': %s\n%s", executablePath, strings.Join(args, " "), strings.TrimSpace(string(errResult)), err.Error()) return } - // The npm command is the first element in tmpArgs array. - log.Debug("npm " + tmpArgs[0] + " standard output is:\n" + strings.TrimSpace(string(stdResult))) + log.Debug("npm '" + strings.Join(args, " ") + "' standard output is:\n" + strings.TrimSpace(string(stdResult))) return } From 653b9eb24cfb5008623f26a0e9915d619d9a3ed5 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 20 Aug 2023 19:51:30 +0300 Subject: [PATCH 09/10] Fix docs Signed-off-by: Michael Sverdlov --- build/utils/npm.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/utils/npm.go b/build/utils/npm.go index d79cb195..ae44e329 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -126,7 +126,7 @@ func runNpmLsWithNodeModules(executablePath, srcPath string, npmArgs []string, l log.Warn(err.Error()) } if len(errData) > 0 { - log.Warn("Encountered some issues while running 'npm ls' command:\n" + string(errData)) + log.Warn("Encountered some issues while running 'npm ls' command:\n" + strings.TrimSpace(string(errData))) } return } @@ -148,7 +148,7 @@ func runNpmLsWithoutNodeModules(executablePath, srcPath string, npmArgs []string log.Warn(err.Error()) } if len(errData) > 0 { - log.Warn("Encountered some issues while running 'npm ls' command:\n" + string(errData)) + log.Warn("Encountered some issues while running 'npm ls' command:\n" + strings.TrimSpace(string(errData))) } return data, nil } @@ -487,7 +487,7 @@ func GetNpmConfigCache(srcPath, executablePath string, npmArgs []string, log uti data, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(append(npmArgs, "--json=false"), "config"), log) // Some warnings and messages of npm are printed to stderr. They don't cause the command to fail, but we'd want to show them to the user. if len(errData) > 0 { - log.Warn("error while running the command '" + executablePath + " " + strings.Join(npmArgs, " ") + "' :\n" + string(errData)) + log.Warn("Encountered some issues while running 'npm get cache' command:\n" + string(errData)) } if err != nil { return "", err From c81fcc999d210e8240117b49662aa838461d901f Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Sun, 20 Aug 2023 19:56:18 +0300 Subject: [PATCH 10/10] Fix docs Signed-off-by: Michael Sverdlov --- build/utils/npm.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/build/utils/npm.go b/build/utils/npm.go index ae44e329..114783ef 100644 --- a/build/utils/npm.go +++ b/build/utils/npm.go @@ -124,8 +124,7 @@ func runNpmLsWithNodeModules(executablePath, srcPath string, npmArgs []string, l if err != nil { // It is optional for the function to return this error. log.Warn(err.Error()) - } - if len(errData) > 0 { + } else if len(errData) > 0 { log.Warn("Encountered some issues while running 'npm ls' command:\n" + strings.TrimSpace(string(errData))) } return @@ -146,8 +145,7 @@ func runNpmLsWithoutNodeModules(executablePath, srcPath string, npmArgs []string data, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(npmArgs, "ls"), log) if err != nil { log.Warn(err.Error()) - } - if len(errData) > 0 { + } else if len(errData) > 0 { log.Warn("Encountered some issues while running 'npm ls' command:\n" + strings.TrimSpace(string(errData))) } return data, nil @@ -485,12 +483,11 @@ func removeVersionPrefixes(packageInfo *PackageInfo) { func GetNpmConfigCache(srcPath, executablePath string, npmArgs []string, log utils.Log) (string, error) { npmArgs = append([]string{"get", "cache"}, npmArgs...) data, errData, err := RunNpmCmd(executablePath, srcPath, AppendNpmCommand(append(npmArgs, "--json=false"), "config"), log) - // Some warnings and messages of npm are printed to stderr. They don't cause the command to fail, but we'd want to show them to the user. - if len(errData) > 0 { - log.Warn("Encountered some issues while running 'npm get cache' command:\n" + string(errData)) - } if err != nil { return "", err + } else if len(errData) > 0 { + // Some warnings and messages of npm are printed to stderr. They don't cause the command to fail, but we'd want to show them to the user. + log.Warn("Encountered some issues while running 'npm get cache' command:\n" + string(errData)) } cachePath := filepath.Join(strings.Trim(string(data), "\n"), "_cacache") found, err := utils.IsDirExists(cachePath, true)