Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions pkg/npm/bom.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func (exec *Execute) generatePnpmBOMFiles(packageJSONFiles []string, cliPath str
// createNpmBOM generates a BOM for npm/yarn projects using cyclonedx-npm
func (exec *Execute) createNpmBOM(packageJSONFiles []string) error {
// Primary attempt with cyclonedx-npm
cycloneDxNpmInstallParams := []string{"install", "--no-save", cycloneDxNpmPackageVersion, "--prefix", tmpInstallFolder}
cycloneDxNpmRunParams := []string{"--output-format", "XML", "--spec-version", CycloneDxSchemaVersion, "--omit", "dev", "--output-file"}
cycloneDxNpmInstallParams := []string{"install", "--no-save", cycloneDxNpmPackageVersion, "--prefix", tmpInstallFolder, "--no-workspaces"}
cycloneDxNpmRunParams := []string{"--output-format", "XML", "--spec-version", CycloneDxSchemaVersion, "--omit", "dev", "--ignore-npm-errors", "--output-file"}

err := exec.createBOMWithParams(cycloneDxNpmInstallParams, cycloneDxNpmRunParams, packageJSONFiles)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/npm/bom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ func TestBom(t *testing.T) {
Options: options,
}
err := exec.CreateBOM([]string{"package.json", filepath.Join("src", "package.json")})
cycloneDxNpmInstallParams := []string{"install", "--no-save", "@cyclonedx/cyclonedx-npm@2.1.0", "--prefix", "./tmp"}
cycloneDxNpmInstallParams := []string{"install", "--no-save", "@cyclonedx/cyclonedx-npm@2.1.0", "--prefix", "./tmp", "--no-workspaces"}
cycloneDxNpmRunParams := []string{
"--output-format",
"XML",
"--spec-version",
CycloneDxSchemaVersion,
"--omit",
"dev",
"--ignore-npm-errors",
"--output-file",
}

Expand All @@ -56,7 +57,7 @@ func TestBom(t *testing.T) {
utils.AddFile("package-lock.json", []byte("{}"))
utils.AddFile(filepath.Join("src", "package.json"), []byte("{\"scripts\": { \"ci-lint\": \"exit 0\" } }"))
utils.AddFile(filepath.Join("src", "package-lock.json"), []byte("{}"))
utils.execRunner.ShouldFailOnCommand = map[string]error{"npm install --no-save @cyclonedx/cyclonedx-npm@2.1.0 --prefix ./tmp": fmt.Errorf("failed to install CycloneDX BOM")}
utils.execRunner.ShouldFailOnCommand = map[string]error{"npm install --no-save @cyclonedx/cyclonedx-npm@2.1.0 --prefix ./tmp --no-workspaces": fmt.Errorf("failed to install CycloneDX BOM")}

options := ExecutorOptions{}
options.DefaultNpmRegistry = "foo.bar"
Expand Down Expand Up @@ -86,6 +87,7 @@ func TestBom(t *testing.T) {
"--output-format", "XML",
"--spec-version", CycloneDxSchemaVersion,
"--omit", "dev",
"--ignore-npm-errors",
"--output-file", "bom-npm.xml",
"package.json",
}, " ")
Expand Down