snyk 1.1294.1 → 1.1294.2

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.
@@ -202349,6 +202349,7 @@ const Debug = __webpack_require__(15158);
202349
202349
  const promises_1 = __webpack_require__(73292);
202350
202350
  const path = __webpack_require__(71017);
202351
202351
  const debug = Debug("snyk");
202352
+ const nodeModulesRegex = /^(.*?)(?:[\\\/]node_modules)/;
202352
202353
  async function createTempProjectDir(projectDir) {
202353
202354
  const tmpDir = await (0, promises_1.mkdtemp)("snyk");
202354
202355
  const tempProjectRoot = path.join(tmpDir, projectDir);
@@ -202367,11 +202368,19 @@ async function fileExists(path) {
202367
202368
  async function createSyntheticManifest(tempRootManifestDir) {
202368
202369
  const tempRootManifestPath = path.join(tempRootManifestDir, manifestName);
202369
202370
  debug(`Creating an empty synthetic manifest file: ${tempRootManifestPath}`);
202370
- await (0, promises_1.writeFile)(tempRootManifestPath, "{}", "utf-8");
202371
+ try {
202372
+ await (0, promises_1.writeFile)(tempRootManifestPath, "{}", "utf-8");
202373
+ }
202374
+ catch (error) {
202375
+ debug(`Error while writing file ${tempRootManifestPath} : ${error.message}`);
202376
+ }
202371
202377
  }
202372
202378
  async function saveOnDisk(tempDir, modules, filePathToContent) {
202373
202379
  for (const module of modules) {
202374
202380
  const manifestContent = filePathToContent[module];
202381
+ if (!manifestContent) {
202382
+ continue;
202383
+ }
202375
202384
  await createFile(path.join(tempDir, module), manifestContent);
202376
202385
  }
202377
202386
  }
@@ -202411,16 +202420,72 @@ async function persistNodeModules(project, filePathToContent, fileNamesGroupedBy
202411
202420
  }
202412
202421
  exports.persistNodeModules = persistNodeModules;
202413
202422
  async function createFile(filePath, fileContent) {
202414
- await (0, promises_1.mkdir)(path.dirname(filePath), { recursive: true });
202415
- await (0, promises_1.writeFile)(filePath, fileContent, "utf-8");
202423
+ try {
202424
+ await (0, promises_1.mkdir)(path.dirname(filePath), { recursive: true });
202425
+ await (0, promises_1.writeFile)(filePath, fileContent, "utf-8");
202426
+ }
202427
+ catch (error) {
202428
+ debug(`Error while creating file ${filePath} : ${error.message}`);
202429
+ }
202430
+ }
202431
+ function isYarnCacheDependency(filePath) {
202432
+ if (filePath.includes(".yarn/cache") ||
202433
+ filePath.includes(".cache/yarn") ||
202434
+ filePath.includes("yarn\\cache") ||
202435
+ filePath.includes("cache\\yarn") ||
202436
+ filePath.includes("Cache\\Yarn") ||
202437
+ filePath.includes("Yarn\\Cache")) {
202438
+ return true;
202439
+ }
202440
+ return false;
202441
+ }
202442
+ function isNpmCacheDependency(filePath) {
202443
+ if (filePath.includes(".npm/") || filePath.includes("\\npm-cache")) {
202444
+ return true;
202445
+ }
202446
+ return false;
202447
+ }
202448
+ function isPnpmCacheDependency(filePath) {
202449
+ if (filePath.includes("pnpm-store") ||
202450
+ filePath.includes("pnpm/store") ||
202451
+ filePath.includes("pnpm\\store")) {
202452
+ return true;
202453
+ }
202454
+ return false;
202455
+ }
202456
+ function getNodeModulesParentDir(filePath) {
202457
+ const nodeModulesParentDirMatch = nodeModulesRegex.exec(filePath);
202458
+ if (nodeModulesParentDirMatch && nodeModulesParentDirMatch.length > 1) {
202459
+ const nodeModulesParentDir = nodeModulesParentDirMatch[1];
202460
+ if (nodeModulesParentDir === "") {
202461
+ return "/"; // ensuring the same behavior of path.dirname for '/' dir
202462
+ }
202463
+ return nodeModulesParentDir;
202464
+ }
202465
+ return null;
202466
+ }
202467
+ function getGroupingDir(filePath) {
202468
+ const nodeModulesParentDir = getNodeModulesParentDir(filePath);
202469
+ if (nodeModulesParentDir) {
202470
+ return nodeModulesParentDir;
202471
+ }
202472
+ return path.dirname(filePath);
202416
202473
  }
202417
202474
  function groupFilesByDirectory(filePathToContent) {
202418
202475
  var _a;
202419
202476
  const filesByDir = new Map();
202420
- for (const filePath of Object.keys(filePathToContent)) {
202421
- const directory = filePath.includes("node_modules")
202422
- ? filePath.split("/node_modules")[0]
202423
- : path.dirname(filePath);
202477
+ const filePaths = Object.keys(filePathToContent);
202478
+ for (const filePath of filePaths) {
202479
+ if (isNpmCacheDependency(filePath)) {
202480
+ continue;
202481
+ }
202482
+ if (isYarnCacheDependency(filePath)) {
202483
+ continue;
202484
+ }
202485
+ if (isPnpmCacheDependency(filePath)) {
202486
+ continue;
202487
+ }
202488
+ const directory = getGroupingDir(filePath);
202424
202489
  if (!filesByDir.has(directory)) {
202425
202490
  filesByDir.set(directory, new Set());
202426
202491
  }
@@ -202430,8 +202495,11 @@ function groupFilesByDirectory(filePathToContent) {
202430
202495
  }
202431
202496
  exports.groupFilesByDirectory = groupFilesByDirectory;
202432
202497
  async function cleanupAppNodeModules(appRootDir) {
202498
+ if (!appRootDir) {
202499
+ return;
202500
+ }
202433
202501
  try {
202434
- (0, promises_1.rm)(appRootDir, { recursive: true });
202502
+ await (0, promises_1.rm)(appRootDir, { recursive: true });
202435
202503
  }
202436
202504
  catch (error) {
202437
202505
  debug(`Error while removing ${appRootDir} : ${error.message}`);
@@ -202485,6 +202553,9 @@ async function depGraphFromNodeModules(filePathToContent, nodeProjects, fileName
202485
202553
  const scanResults = [];
202486
202554
  for (const project of nodeProjects) {
202487
202555
  const { tempDir, tempProjectPath, manifestPath } = await (0, node_modules_utils_1.persistNodeModules)(project, filePathToContent, fileNamesGroupedByDirectory);
202556
+ if (!tempDir) {
202557
+ continue;
202558
+ }
202488
202559
  if (!tempProjectPath) {
202489
202560
  await (0, node_modules_utils_1.cleanupAppNodeModules)(tempDir);
202490
202561
  continue;
@@ -202494,6 +202565,10 @@ async function depGraphFromNodeModules(filePathToContent, nodeProjects, fileName
202494
202565
  dev: false,
202495
202566
  noFromArrays: true,
202496
202567
  });
202568
+ if (pkgTree.numDependencies === 0) {
202569
+ await (0, node_modules_utils_1.cleanupAppNodeModules)(tempDir);
202570
+ continue;
202571
+ }
202497
202572
  const depGraph = await dep_graph_1.legacy.depTreeToGraph(pkgTree, pkgTree.type || "npm");
202498
202573
  scanResults.push({
202499
202574
  facts: [
@@ -202571,27 +202646,23 @@ function findProjectsAndManifests(fileNamesGroupedByDirectory) {
202571
202646
  const expectedManifest = path.join(directoryPath, "package.json");
202572
202647
  const expectedNpmLockFile = path.join(directoryPath, "package-lock.json");
202573
202648
  const expectedYarnLockFile = path.join(directoryPath, "yarn.lock");
202574
- const hasManifestFileOnly = filesInDirectory.has(expectedManifest) &&
202575
- !(filesInDirectory.has(expectedNpmLockFile) ||
202576
- filesInDirectory.has(expectedYarnLockFile));
202577
- const hasNoManifestFile = !filesInDirectory.has(expectedManifest);
202578
- if (hasManifestFileOnly && filesInDirectory.size === 1) {
202579
- continue;
202580
- }
202581
- if (hasManifestFileOnly || hasNoManifestFile) {
202582
- nodeProjects.push(directoryPath);
202649
+ const hasManifestFile = filesInDirectory.has(expectedManifest);
202650
+ const hasLockFile = filesInDirectory.has(expectedNpmLockFile) ||
202651
+ filesInDirectory.has(expectedYarnLockFile);
202652
+ if (hasManifestFile && hasLockFile) {
202653
+ manifestLockPathPairs.push({
202654
+ manifest: expectedManifest,
202655
+ // TODO: correlate filtering action with expected lockfile types
202656
+ lock: filesInDirectory.has(expectedNpmLockFile)
202657
+ ? expectedNpmLockFile
202658
+ : expectedYarnLockFile,
202659
+ lockType: filesInDirectory.has(expectedNpmLockFile)
202660
+ ? lockFileParser.LockfileType.npm
202661
+ : lockFileParser.LockfileType.yarn,
202662
+ });
202583
202663
  continue;
202584
202664
  }
202585
- manifestLockPathPairs.push({
202586
- manifest: expectedManifest,
202587
- // TODO: correlate filtering action with expected lockfile types
202588
- lock: filesInDirectory.has(expectedNpmLockFile)
202589
- ? expectedNpmLockFile
202590
- : expectedYarnLockFile,
202591
- lockType: filesInDirectory.has(expectedNpmLockFile)
202592
- ? lockFileParser.LockfileType.npm
202593
- : lockFileParser.LockfileType.yarn,
202594
- });
202665
+ nodeProjects.push(directoryPath);
202595
202666
  }
202596
202667
  return [manifestLockPathPairs, nodeProjects];
202597
202668
  }