snyk 1.1072.0 → 1.1073.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.
@@ -3864,21 +3864,34 @@ async function inspect(root, targetFile, options = {}) {
3864
3864
  const isLockFileBased = targetFile.endsWith('package-lock.json') ||
3865
3865
  targetFile.endsWith('yarn.lock');
3866
3866
  const getLockFileDeps = isLockFileBased && !options.traverseNodeModules;
3867
- const depTree = getLockFileDeps
3867
+ const depRes = getLockFileDeps
3868
3868
  ? await lockParser.parse(root, targetFile, options)
3869
3869
  : await modulesParser.parse(root, targetFile, options);
3870
- if ((_a = depTree === null || depTree === void 0 ? void 0 : depTree.meta) === null || _a === void 0 ? void 0 : _a.lockfileVersion) {
3871
- analytics.add('lockfileVersion', depTree.meta.lockfileVersion);
3870
+ let scannedProjects = [];
3871
+ if (isResDepGraph(depRes)) {
3872
+ if (depRes.pkgManager.version) {
3873
+ analytics.add('lockfileVersion', depRes.pkgManager.version);
3874
+ }
3875
+ scannedProjects = [{ depGraph: depRes }];
3876
+ }
3877
+ else {
3878
+ if ((_a = depRes.meta) === null || _a === void 0 ? void 0 : _a.lockfileVersion) {
3879
+ analytics.add('lockfileVersion', depRes.meta.lockfileVersion);
3880
+ }
3881
+ scannedProjects = [{ depTree: depRes }];
3872
3882
  }
3873
3883
  return {
3874
3884
  plugin: {
3875
3885
  name: 'snyk-nodejs-lockfile-parser',
3876
3886
  runtime: process.version,
3877
3887
  },
3878
- scannedProjects: [{ depTree }],
3888
+ scannedProjects,
3879
3889
  };
3880
3890
  }
3881
3891
  exports.inspect = inspect;
3892
+ function isResDepGraph(depRes) {
3893
+ return 'rootPkg' in depRes;
3894
+ }
3882
3895
 
3883
3896
 
3884
3897
  /***/ }),
@@ -3897,6 +3910,7 @@ const spinner_1 = __webpack_require__(86766);
3897
3910
  const analytics = __webpack_require__(82744);
3898
3911
  const fs = __webpack_require__(35747);
3899
3912
  const lockFileParser = __webpack_require__(423);
3913
+ const snyk_nodejs_lockfile_parser_1 = __webpack_require__(423);
3900
3914
  async function parse(root, targetFile, options) {
3901
3915
  const lockFileFullPath = path.resolve(root, targetFile);
3902
3916
  if (!fs.existsSync(lockFileFullPath)) {
@@ -3922,9 +3936,19 @@ async function parse(root, targetFile, options) {
3922
3936
  });
3923
3937
  const resolveModuleSpinnerLabel = `Analyzing npm dependencies for ${lockFileFullPath}`;
3924
3938
  debug(resolveModuleSpinnerLabel);
3939
+ const strictOutOfSync = options.strictOutOfSync !== false;
3940
+ const lockfileVersion = lockFileParser.getLockfileVersionFromFile(lockFileFullPath);
3941
+ if (lockfileVersion === snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.YarnLockV1 ||
3942
+ lockfileVersion === snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.YarnLockV2) {
3943
+ return await buildDepGraph(root, manifestFileFullPath, lockFileFullPath, lockfileVersion, {
3944
+ includeDevDeps: options.dev || false,
3945
+ includeOptionalDeps: true,
3946
+ strictOutOfSync,
3947
+ pruneCycles: true,
3948
+ });
3949
+ }
3925
3950
  try {
3926
3951
  await spinner_1.spinner(resolveModuleSpinnerLabel);
3927
- const strictOutOfSync = options.strictOutOfSync !== false;
3928
3952
  return lockFileParser.buildDepTreeFromFiles(root, manifestFileFullPath, lockFileFullPath, options.dev, strictOutOfSync);
3929
3953
  }
3930
3954
  finally {
@@ -3932,6 +3956,26 @@ async function parse(root, targetFile, options) {
3932
3956
  }
3933
3957
  }
3934
3958
  exports.parse = parse;
3959
+ async function buildDepGraph(root, manifestFilePath, lockfilePath, lockfileVersion, options) {
3960
+ const manifestFileFullPath = path.resolve(root, manifestFilePath);
3961
+ const lockFileFullPath = path.resolve(root, lockfilePath);
3962
+ if (!fs.existsSync(manifestFileFullPath)) {
3963
+ throw new snyk_nodejs_lockfile_parser_1.InvalidUserInputError('Target file package.json not found at ' +
3964
+ `location: ${manifestFileFullPath}`);
3965
+ }
3966
+ if (!fs.existsSync(lockFileFullPath)) {
3967
+ throw new snyk_nodejs_lockfile_parser_1.InvalidUserInputError('Lockfile not found at location: ' + lockFileFullPath);
3968
+ }
3969
+ const manifestFileContents = fs.readFileSync(manifestFileFullPath, 'utf-8');
3970
+ const lockFileContents = fs.readFileSync(lockFileFullPath, 'utf-8');
3971
+ switch (lockfileVersion) {
3972
+ case snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.YarnLockV1:
3973
+ return await lockFileParser.parseYarnLockV1Project(manifestFileContents, lockFileContents, options);
3974
+ case snyk_nodejs_lockfile_parser_1.NodeLockfileVersion.YarnLockV2:
3975
+ return lockFileParser.parseYarnLockV2Project(manifestFileContents, lockFileContents, options);
3976
+ }
3977
+ throw new Error('Failed to build dep graph from current project');
3978
+ }
3935
3979
 
3936
3980
 
3937
3981
  /***/ }),