Skip to content
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

Fix npm commands missing standard output #181

Merged
merged 10 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 5 additions & 3 deletions build/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Info(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()
Expand Down
6 changes: 5 additions & 1 deletion build/utils/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
Loading