snyk 1.1201.0 → 1.1202.0

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.
@@ -1276,7 +1276,6 @@ const api_token_1 = __webpack_require__(95181);
1276
1276
  const resolve_test_facts_1 = __webpack_require__(85164);
1277
1277
  const common_2 = __webpack_require__(69813);
1278
1278
  const utils_1 = __webpack_require__(97875);
1279
- const json_1 = __webpack_require__(27019);
1280
1279
  async function testEcosystem(ecosystem, paths, options) {
1281
1280
  const plugin = plugins_1.getPlugin(ecosystem);
1282
1281
  // TODO: this is an intermediate step before consolidating ecosystem plugins
@@ -1317,12 +1316,7 @@ exports.selectAndExecuteTestStrategy = selectAndExecuteTestStrategy;
1317
1316
  async function formatUnmanagedResults(results, target) {
1318
1317
  const [result] = await utils_1.getUnmanagedDepGraph(results);
1319
1318
  const depGraph = utils_1.convertDepGraph(result);
1320
- const template = `DepGraph data:
1321
- ${json_1.jsonStringifyLargeObject(depGraph)}
1322
- DepGraph target:
1323
- ${target}
1324
- DepGraph end`;
1325
- return types_1.TestCommandResult.createJsonTestCommandResult(template);
1319
+ return types_1.TestCommandResult.createJsonTestCommandResult(common_1.depGraphToOutputString(depGraph, target));
1326
1320
  }
1327
1321
  exports.formatUnmanagedResults = formatUnmanagedResults;
1328
1322
  async function testDependencies(scans, options) {
@@ -2722,38 +2716,6 @@ function isMultiProjectScan(options) {
2722
2716
  exports.isMultiProjectScan = isMultiProjectScan;
2723
2717
 
2724
2718
 
2725
- /***/ }),
2726
-
2727
- /***/ 27019:
2728
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2729
-
2730
- "use strict";
2731
-
2732
- Object.defineProperty(exports, "__esModule", ({ value: true }));
2733
- exports.jsonStringifyLargeObject = void 0;
2734
- const debug = __webpack_require__(15158)('snyk-json');
2735
- /**
2736
- * Attempt to json-stringify an object which is potentially very large and might exceed the string limit.
2737
- * If it does exceed the string limit, try again without pretty-print to hopefully come out below the string limit.
2738
- * @param obj the object from which you want to get a JSON string
2739
- */
2740
- function jsonStringifyLargeObject(obj) {
2741
- let res = '';
2742
- try {
2743
- // first try pretty-print
2744
- res = JSON.stringify(obj, null, 2);
2745
- return res;
2746
- }
2747
- catch (err) {
2748
- // if that doesn't work, try non-pretty print
2749
- debug('JSON.stringify failed - trying again without pretty print', err);
2750
- res = JSON.stringify(obj);
2751
- return res;
2752
- }
2753
- }
2754
- exports.jsonStringifyLargeObject = jsonStringifyLargeObject;
2755
-
2756
-
2757
2719
  /***/ }),
2758
2720
 
2759
2721
  /***/ 80777:
@@ -6148,6 +6110,15 @@ async function assembleEcosystemPayloads(ecosystem, options) {
6148
6110
  // WARNING! This mutates the payload. The project name logic should be handled in the plugin.
6149
6111
  scanResult.name =
6150
6112
  options['project-name'] || config_1.default.PROJECT_NAME || scanResult.name;
6113
+ if (options['print-graph'] && !options['print-deps']) {
6114
+ // not every scanResult has a 'depGraph' fact, for example the JAR
6115
+ // fingerprints. I don't think we have another option than to skip
6116
+ // those.
6117
+ const dg = scanResult.facts.find((dg) => dg.type === 'depGraph');
6118
+ if (dg) {
6119
+ console.log(common_1.depGraphToOutputString(dg.data.toJSON(), constructProjectName(scanResult)));
6120
+ }
6121
+ }
6151
6122
  payloads.push({
6152
6123
  method: 'POST',
6153
6124
  url: `${config_1.default.API}${options.testDepGraphDockerEndpoint ||
@@ -6179,6 +6150,32 @@ async function assembleEcosystemPayloads(ecosystem, options) {
6179
6150
  }
6180
6151
  }
6181
6152
  exports.assembleEcosystemPayloads = assembleEcosystemPayloads;
6153
+ // constructProjectName attempts to construct the project name the same way that
6154
+ // registry does. This is a bit difficult because in Registry, the code is
6155
+ // distributed over multiple functions and files that need to be kept in sync...
6156
+ function constructProjectName(sr) {
6157
+ var _a, _b;
6158
+ let suffix = '';
6159
+ if (sr.identity.targetFile) {
6160
+ suffix = ':' + sr.identity.targetFile;
6161
+ }
6162
+ if (sr.name) {
6163
+ return sr.name + suffix;
6164
+ }
6165
+ const targetImage = (_a = sr.target) === null || _a === void 0 ? void 0 : _a.image;
6166
+ if (targetImage) {
6167
+ return targetImage + suffix;
6168
+ }
6169
+ const dgFact = sr.facts.find((d) => d.type === 'depGraph');
6170
+ // not every scanResult has a depGraph, for example the JAR fingerprints.
6171
+ if (dgFact) {
6172
+ const name = (_b = dgFact.data) === null || _b === void 0 ? void 0 : _b.rootPkg.name;
6173
+ if (name) {
6174
+ return name + suffix;
6175
+ }
6176
+ }
6177
+ return 'no-name' + suffix;
6178
+ }
6182
6179
 
6183
6180
 
6184
6181
  /***/ }),
@@ -6356,7 +6353,6 @@ const theme_1 = __webpack_require__(86988);
6356
6353
  const snyk_module_1 = __webpack_require__(60390);
6357
6354
  const depGraphLib = __webpack_require__(71479);
6358
6355
  const theme = __webpack_require__(86988);
6359
- const json_1 = __webpack_require__(27019);
6360
6356
  const pMap = __webpack_require__(86301);
6361
6357
  const legacy_1 = __webpack_require__(34013);
6362
6358
  const errors_1 = __webpack_require__(55191);
@@ -6837,7 +6833,7 @@ async function assembleLocalPayloads(root, options) {
6837
6833
  : pkg.name;
6838
6834
  // print dep graph if `--print-graph` is set
6839
6835
  if (options['print-graph'] && !options['print-deps']) {
6840
- await spinner_1.spinner.clear(spinnerLbl)();
6836
+ spinner_1.spinner.clear(spinnerLbl)();
6841
6837
  let root;
6842
6838
  if (scannedProject.depGraph) {
6843
6839
  root = pkg;
@@ -6846,9 +6842,7 @@ async function assembleLocalPayloads(root, options) {
6846
6842
  const tempDepTree = pkg;
6847
6843
  root = await depGraphLib.legacy.depTreeToGraph(tempDepTree, packageManager ? packageManager : '');
6848
6844
  }
6849
- console.log('DepGraph data:');
6850
- console.log(json_1.jsonStringifyLargeObject(root.toJSON()));
6851
- console.log('DepGraph target:\n' + targetFile + '\nDepGraph end');
6845
+ console.log(common.depGraphToOutputString(root.toJSON(), targetFile || ''));
6852
6846
  }
6853
6847
  const body = {
6854
6848
  // WARNING: be careful changing this as it affects project uniqueness