-
Notifications
You must be signed in to change notification settings - Fork 17
/
prune_build_process.go
55 lines (45 loc) · 1.39 KB
/
prune_build_process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package npminstall
import (
"fmt"
"os"
"strings"
"github.com/paketo-buildpacks/packit/v2/pexec"
"github.com/paketo-buildpacks/packit/v2/scribe"
)
func NewPruneBuildProcess(executable Executable, environment EnvironmentConfig, logger scribe.Logger) PruneBuildProcess {
return PruneBuildProcess{
executable: executable,
environment: environment,
logger: logger,
}
}
type PruneBuildProcess struct {
executable Executable
environment EnvironmentConfig
logger scribe.Logger
}
func (r PruneBuildProcess) ShouldRun(workingDir string, metadata map[string]interface{}, npmrcPath string) (bool, string, error) {
return true, "", nil
}
func (r PruneBuildProcess) Run(modulesDir, cacheDir, workingDir, npmrcPath string, launch bool) error {
environment := os.Environ()
if value, ok := r.environment.Lookup("NPM_CONFIG_LOGLEVEL"); ok {
environment = append(environment, fmt.Sprintf("NPM_CONFIG_LOGLEVEL=%s", value))
}
if npmrcPath != "" {
environment = append(environment, fmt.Sprintf("NPM_CONFIG_GLOBALCONFIG=%s", npmrcPath))
}
args := []string{"prune"}
r.logger.Subprocess("Running 'npm %s'", strings.Join(args, " "))
err := r.executable.Execute(pexec.Execution{
Args: args,
Dir: workingDir,
Stdout: r.logger.ActionWriter,
Stderr: r.logger.ActionWriter,
Env: environment,
})
if err != nil {
return fmt.Errorf("npm install failed: %w", err)
}
return nil
}