snyk 1.1162.0 → 1.1163.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.
@@ -4093,9 +4093,20 @@ async function buildDepGraph(root, manifestFilePath, lockfilePath, lockfileVersi
4093
4093
  const lockFileContents = fs.readFileSync(lockFileFullPath, 'utf-8');
4094
4094
  switch (lockfileVersion) {
4095
4095
  case snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.YarnLockV1:
4096
- return await lockFileParser.parseYarnLockV1Project(manifestFileContents, lockFileContents, options);
4096
+ return await lockFileParser.parseYarnLockV1Project(manifestFileContents, lockFileContents, {
4097
+ includeDevDeps: options.includeDevDeps,
4098
+ includeOptionalDeps: options.includeOptionalDeps,
4099
+ includePeerDeps: options.includePeerDeps || false,
4100
+ pruneLevel: 'withinTopLevelDeps',
4101
+ strictOutOfSync: options.strictOutOfSync,
4102
+ });
4097
4103
  case snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.YarnLockV2:
4098
- return await lockFileParser.parseYarnLockV2Project(manifestFileContents, lockFileContents, options);
4104
+ return await lockFileParser.parseYarnLockV2Project(manifestFileContents, lockFileContents, {
4105
+ includeDevDeps: options.includeDevDeps,
4106
+ includeOptionalDeps: options.includeOptionalDeps,
4107
+ pruneWithinTopLevelDeps: true,
4108
+ strictOutOfSync: options.strictOutOfSync,
4109
+ });
4099
4110
  case snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.NpmLockV2:
4100
4111
  case snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.NpmLockV3:
4101
4112
  return await lockFileParser.parseNpmLockV2Project(manifestFileContents, lockFileContents, options);
@@ -4350,7 +4361,6 @@ async function processYarnWorkspaces(root, settings, targetFiles) {
4350
4361
  },
4351
4362
  scannedProjects: [],
4352
4363
  };
4353
- let rootWorkspaceManifestContent = {};
4354
4364
  // the folders must be ordered highest first
4355
4365
  for (const directory of Object.keys(yarnTargetFiles)) {
4356
4366
  debug(`Processing ${directory} as a potential Yarn workspace`);
@@ -4373,7 +4383,6 @@ async function processYarnWorkspaces(root, settings, targetFiles) {
4373
4383
  }
4374
4384
  if (packageJsonFileName === workspaceRoot) {
4375
4385
  isRootPackageJson = true;
4376
- rootWorkspaceManifestContent = JSON.parse(packageJson.content);
4377
4386
  }
4378
4387
  }
4379
4388
  if (!(isYarnWorkspacePackage || isRootPackageJson)) {
@@ -4385,21 +4394,38 @@ async function processYarnWorkspaces(root, settings, targetFiles) {
4385
4394
  ? pathUtil.dirname(yarnWorkspacesFilesMap[packageJsonFileName].root)
4386
4395
  : pathUtil.dirname(packageJsonFileName);
4387
4396
  const rootYarnLockfileName = pathUtil.join(rootDir, 'yarn.lock');
4388
- const yarnLock = await get_file_contents_1.getFileContents(root, rootYarnLockfileName);
4389
- if (rootWorkspaceManifestContent.hasOwnProperty('resolutions') &&
4390
- lockFileParser.getYarnLockfileType(yarnLock.content) ===
4391
- lockFileParser.LockfileType.yarn2) {
4392
- const parsedManifestContent = JSON.parse(packageJson.content);
4393
- packageJson.content = JSON.stringify({
4394
- ...parsedManifestContent,
4395
- resolutions: rootWorkspaceManifestContent['resolutions'],
4396
- });
4397
+ const yarnLock = get_file_contents_1.getFileContents(root, rootYarnLockfileName);
4398
+ const lockfileVersion = lockFileParser.getYarnLockfileVersion(yarnLock.content);
4399
+ let res;
4400
+ switch (lockfileVersion) {
4401
+ case lockFileParser.NodeLockfileVersion.YarnLockV1:
4402
+ res = await lockFileParser.parseYarnLockV1Project(packageJson.content, yarnLock.content, {
4403
+ includeDevDeps: settings.dev || false,
4404
+ includeOptionalDeps: false,
4405
+ includePeerDeps: false,
4406
+ pruneLevel: 'withinTopLevelDeps',
4407
+ strictOutOfSync: settings.strictOutOfSync === undefined
4408
+ ? true
4409
+ : settings.strictOutOfSync,
4410
+ });
4411
+ break;
4412
+ case lockFileParser.NodeLockfileVersion.YarnLockV2:
4413
+ res = await lockFileParser.parseYarnLockV2Project(packageJson.content, yarnLock.content, {
4414
+ includeDevDeps: settings.dev || false,
4415
+ includeOptionalDeps: false,
4416
+ pruneWithinTopLevelDeps: true,
4417
+ strictOutOfSync: settings.strictOutOfSync === undefined
4418
+ ? true
4419
+ : settings.strictOutOfSync,
4420
+ });
4421
+ break;
4422
+ default:
4423
+ throw new Error('Failed to build dep graph from current project');
4397
4424
  }
4398
- const res = await lockFileParser.buildDepTree(packageJson.content, yarnLock.content, settings.dev, lockFileParser.LockfileType.yarn, settings.strictOutOfSync !== false);
4399
4425
  const project = {
4400
4426
  packageManager: 'yarn',
4401
4427
  targetFile: pathUtil.relative(root, packageJson.fileName),
4402
- depTree: res,
4428
+ depGraph: res,
4403
4429
  plugin: {
4404
4430
  name: 'snyk-nodejs-lockfile-parser',
4405
4431
  runtime: process.version,
@@ -6252,11 +6278,13 @@ const snyk_module_1 = __webpack_require__(60390);
6252
6278
  const depGraphLib = __webpack_require__(71479);
6253
6279
  const theme = __webpack_require__(86988);
6254
6280
  const json_1 = __webpack_require__(27019);
6281
+ const pMap = __webpack_require__(86301);
6255
6282
  const legacy_1 = __webpack_require__(34013);
6256
6283
  const errors_1 = __webpack_require__(55191);
6257
6284
  const snyk = __webpack_require__(9146);
6258
6285
  const is_ci_1 = __webpack_require__(10090);
6259
6286
  const common = __webpack_require__(53110);
6287
+ const common_1 = __webpack_require__(53110);
6260
6288
  const config_1 = __webpack_require__(25425);
6261
6289
  const analytics = __webpack_require__(82744);
6262
6290
  const print_deps_1 = __webpack_require__(79792);
@@ -6272,8 +6300,7 @@ const assemble_payloads_1 = __webpack_require__(38080);
6272
6300
  const request_1 = __webpack_require__(52050);
6273
6301
  const spinner_1 = __webpack_require__(86766);
6274
6302
  const dep_graph_1 = __webpack_require__(73399);
6275
- const common_1 = __webpack_require__(70527);
6276
- const common_2 = __webpack_require__(53110);
6303
+ const common_2 = __webpack_require__(70527);
6277
6304
  const debug = debugModule('snyk:run-test');
6278
6305
  // Controls the number of simultaneous test requests that can be in-flight.
6279
6306
  const MAX_CONCURRENCY = 5;
@@ -6380,53 +6407,35 @@ async function sendAndParseResults(payloads, spinnerLbl, root, options) {
6380
6407
  if (!options.quiet) {
6381
6408
  await spinner_1.spinner(spinnerLbl);
6382
6409
  }
6383
- const requests = [];
6384
- for (const originalPayload of payloads) {
6385
- const request = async () => {
6386
- let step = 0;
6387
- let error;
6388
- while (step < common_2.RETRY_ATTEMPTS) {
6389
- debug(`sendTestPayload retry step ${step} out of ${common_2.RETRY_ATTEMPTS}`);
6390
- try {
6391
- /** sendTestPayload() deletes the request.body from the payload once completed. */
6392
- const payload = Object.assign({}, originalPayload);
6393
- const response = await sendTestPayload(payload);
6394
- return { payload, originalPayload, response };
6410
+ const sendRequest = async (originalPayload) => {
6411
+ let step = 0;
6412
+ let error;
6413
+ while (step < common_1.RETRY_ATTEMPTS) {
6414
+ debug(`sendTestPayload retry step ${step} out of ${common_1.RETRY_ATTEMPTS}`);
6415
+ try {
6416
+ /** sendTestPayload() deletes the request.body from the payload once completed. */
6417
+ const payload = Object.assign({}, originalPayload);
6418
+ const response = await sendTestPayload(payload);
6419
+ return { payload, originalPayload, response };
6420
+ }
6421
+ catch (err) {
6422
+ error = err;
6423
+ step++;
6424
+ if (err instanceof errors_1.InternalServerError ||
6425
+ err instanceof errors_1.BadGatewayError ||
6426
+ err instanceof errors_1.ServiceUnavailableError) {
6427
+ await common_2.sleep(common_1.RETRY_DELAY);
6395
6428
  }
6396
- catch (err) {
6397
- error = err;
6398
- step++;
6399
- if (err instanceof errors_1.InternalServerError ||
6400
- err instanceof errors_1.BadGatewayError ||
6401
- err instanceof errors_1.ServiceUnavailableError) {
6402
- await common_1.sleep(common_2.RETRY_DELAY);
6403
- }
6404
- else {
6405
- break;
6406
- }
6429
+ else {
6430
+ break;
6407
6431
  }
6408
6432
  }
6409
- throw error;
6410
- };
6411
- requests.push(request);
6412
- }
6413
- // Start block adapted from https://gist.github.com/jcouyang/632709f30e12a7879a73e9e132c0d56b?permalink_comment_id=3591045#gistcomment-3591045
6414
- let index = 0;
6415
- const responses = [];
6416
- const execRequest = async () => {
6417
- while (index < requests.length) {
6418
- // index is shared across "threads", so capture the current value for this
6419
- // iteration on this "thread" and increment it for the rest of the world.
6420
- const curIndex = index++;
6421
- responses[curIndex] = await requests[curIndex]();
6422
6433
  }
6434
+ throw error;
6423
6435
  };
6424
- const threads = [];
6425
- for (let thread = 0; thread < MAX_CONCURRENCY; thread++) {
6426
- threads.push(execRequest());
6427
- }
6428
- await Promise.all(threads);
6429
- // End block adapted from https://gist.github.com/jcouyang/632709f30e12a7879a73e9e132c0d56b?permalink_comment_id=3591045#gistcomment-3591045
6436
+ const responses = await pMap(payloads, sendRequest, {
6437
+ concurrency: MAX_CONCURRENCY,
6438
+ });
6430
6439
  for (const { payload, originalPayload, response } of responses) {
6431
6440
  const { depGraph, payloadPolicy, pkgManager, targetFile, projectName, foundProjectCount, displayTargetFile, dockerfilePackages, platform, scanResult, hasUnknownVersions, } = prepareResponseForParsing(originalPayload, response, options);
6432
6441
  const ecosystem = ecosystems_1.getEcosystem(options);