@cyclonedx/cdxgen 11.1.10 → 11.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cdxgen.js CHANGED
@@ -579,13 +579,25 @@ const applyAdvancedOptions = (options) => {
579
579
  break;
580
580
  }
581
581
  // When the user specifies source-code-analysis as a technique, then enable deep and evidence mode.
582
- if (
583
- options?.technique &&
584
- Array.isArray(options.technique) &&
585
- options?.technique?.includes("source-code-analysis")
586
- ) {
587
- options.deep = true;
588
- options.evidence = true;
582
+ if (options?.technique && Array.isArray(options.technique)) {
583
+ if (options?.technique?.includes("source-code-analysis")) {
584
+ options.deep = true;
585
+ options.evidence = true;
586
+ }
587
+ if (options.technique.length === 1) {
588
+ thoughtLog(
589
+ `Wait, the user wants me to use only the following technique: '${options.technique.join(", ")}'.`,
590
+ );
591
+ } else {
592
+ thoughtLog(
593
+ `Alright, I will use only the following techniques: '${options.technique.join(", ")}' for the final BOM.`,
594
+ );
595
+ }
596
+ }
597
+ if (!options.installDeps) {
598
+ thoughtLog(
599
+ "I must avoid any package installations and focus solely on the available artefacts, such as lock files.",
600
+ );
589
601
  }
590
602
  return options;
591
603
  };
@@ -764,7 +776,11 @@ const checkPermissions = (filePath, options) => {
764
776
  prepareEnv(filePath, options);
765
777
  thoughtLog("Getting ready to generate the BOM ⚡️.");
766
778
  let bomNSData = (await createBom(filePath, options)) || {};
767
- thoughtLog("Tweaking the generated BOM data. Nearly there.");
779
+ if (bomNSData?.bomJson) {
780
+ thoughtLog(
781
+ "Tweaking the generated BOM data with useful annotations and properties.",
782
+ );
783
+ }
768
784
  // Add extra metadata and annotations with post processing
769
785
  bomNSData = postProcess(bomNSData, options);
770
786
  if (
@@ -972,7 +988,7 @@ const checkPermissions = (filePath, options) => {
972
988
  }
973
989
  }
974
990
  // Perform automatic validation
975
- if (options.validate) {
991
+ if (options.validate && bomNSData?.bomJson) {
976
992
  thoughtLog("Wait, let's check the generated BOM file for any issues.");
977
993
  if (!validateBom(bomNSData.bomJson)) {
978
994
  process.exit(1);
package/bin/repl.js CHANGED
@@ -137,6 +137,19 @@ cdxgenRepl.defineCommand("import", {
137
137
  this.displayPrompt();
138
138
  },
139
139
  });
140
+ cdxgenRepl.defineCommand("summary", {
141
+ help: "summarize an existing BOM",
142
+ action() {
143
+ if (sbom) {
144
+ printSummary(sbom);
145
+ } else {
146
+ console.log(
147
+ "⚠ No BOM is loaded. Use .import command to import an existing BOM",
148
+ );
149
+ }
150
+ this.displayPrompt();
151
+ },
152
+ });
140
153
  cdxgenRepl.defineCommand("exit", {
141
154
  help: "exit",
142
155
  action() {
@@ -162,13 +175,13 @@ cdxgenRepl.defineCommand("search", {
162
175
  if (sbom) {
163
176
  if (searchStr) {
164
177
  try {
165
- const originalSearchString = searchStr;
166
- let dependenciesSearchStr = searchStr;
167
- if (!searchStr.includes("~>")) {
168
- dependenciesSearchStr = `dependencies[ref ~> /${searchStr}/i or dependsOn ~> /${searchStr}/i or provides ~> /${searchStr}/i]`;
169
- searchStr = `components[group ~> /${searchStr}/i or name ~> /${searchStr}/i or description ~> /${searchStr}/i or publisher ~> /${searchStr}/i or purl ~> /${searchStr}/i or tags ~> /${searchStr}/i]`;
178
+ let fixedSearchStr = searchStr.replaceAll("/", "\\/");
179
+ let dependenciesSearchStr = fixedSearchStr;
180
+ if (!fixedSearchStr.includes("~>")) {
181
+ dependenciesSearchStr = `dependencies[ref ~> /${fixedSearchStr}/i or dependsOn ~> /${fixedSearchStr}/i or provides ~> /${fixedSearchStr}/i]`;
182
+ fixedSearchStr = `components[group ~> /${fixedSearchStr}/i or name ~> /${fixedSearchStr}/i or description ~> /${fixedSearchStr}/i or publisher ~> /${fixedSearchStr}/i or purl ~> /${fixedSearchStr}/i or tags ~> /${fixedSearchStr}/i]`;
170
183
  }
171
- const expression = jsonata(searchStr);
184
+ const expression = jsonata(fixedSearchStr);
172
185
  let components = await expression.evaluate(sbom);
173
186
  const dexpression = jsonata(dependenciesSearchStr);
174
187
  let dependencies = await dexpression.evaluate(sbom);
@@ -181,16 +194,12 @@ cdxgenRepl.defineCommand("search", {
181
194
  if (!components) {
182
195
  console.log("No results found!");
183
196
  } else {
184
- printTable(
185
- { components, dependencies },
186
- undefined,
187
- originalSearchString,
188
- );
197
+ printTable({ components, dependencies }, undefined, searchStr);
189
198
  if (dependencies?.length) {
190
199
  printDependencyTree(
191
200
  { components, dependencies },
192
201
  "dependsOn",
193
- originalSearchString,
202
+ searchStr,
194
203
  );
195
204
  }
196
205
  }