-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add npm resolver
- Loading branch information
Showing
25 changed files
with
621 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package npm | ||
|
||
import ( | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
type ICmdFactory interface { | ||
MakeInstallCmd(command string, file string) (*exec.Cmd, error) | ||
} | ||
|
||
type IExecPath interface { | ||
LookPath(file string) (string, error) | ||
} | ||
|
||
type ExecPath struct { | ||
} | ||
|
||
func (ExecPath) LookPath(file string) (string, error) { | ||
return exec.LookPath(file) | ||
} | ||
|
||
type CmdFactory struct { | ||
execPath IExecPath | ||
} | ||
|
||
func (cmdf CmdFactory) MakeInstallCmd(command string, file string) (*exec.Cmd, error) { | ||
path, err := cmdf.execPath.LookPath(command) | ||
|
||
fileDir := filepath.Dir(file) | ||
|
||
return &exec.Cmd{ | ||
Path: path, | ||
Args: []string{ | ||
//"yes |", // Answer 'y' to any prompts... | ||
command, | ||
"install", | ||
"--ignore-scripts", // Avoid risky scripts | ||
"--audit=false", // Do not run audit | ||
"--bin-links=false", // We don't need symlinks to binaries as we won't run any code | ||
}, | ||
Dir: fileDir, | ||
}, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package npm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMakeInstallCmd(t *testing.T) { | ||
npmCommand := "npm" | ||
cmd, err := CmdFactory{ | ||
execPath: ExecPath{}, | ||
}.MakeInstallCmd(npmCommand, "file") | ||
assert.NoError(t, err) | ||
assert.NotNil(t, cmd) | ||
args := cmd.Args | ||
assert.Contains(t, args, "npm") | ||
assert.Contains(t, args, "install") | ||
} |
Oops, something went wrong.