Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: respect default detection depth of 4" #5549

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ export const CALL_PATH_LEADING_ELEMENTS = 2;

// Number of function names to show in the end of an abbreviated call path
export const CALL_PATH_TRAILING_ELEMENTS = 2;

// Number of subdirectories to search when running monitor or test
export const MAX_DETECTION_DEPTH = 4;
47 changes: 21 additions & 26 deletions src/lib/find-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import * as pathLib from 'path';

import * as sortBy from 'lodash.sortby';
import * as groupBy from 'lodash.groupby';
import * as assign from 'lodash.assign';
import { detectPackageManagerFromFile } from './detect';
import * as debugModule from 'debug';
import {
PNPM_FEATURE_FLAG,
SUPPORTED_MANIFEST_FILES,
} from './package-managers';
import * as merge from 'lodash.merge';
import { MAX_DETECTION_DEPTH } from './constants';

const debug = debugModule('snyk:find-files');

Expand Down Expand Up @@ -56,12 +55,28 @@ interface FindFilesRes {
const ignoreFolders = ['node_modules', '.build'];

interface FindFilesConfig {
path: string;
ignore?: string[];
filter?: string[];
levelsDeep?: number;
featureFlags?: Set<string>;
}

type DefaultFindConfig = {
path: string;
ignore: string[];
filter: string[];
levelsDeep: number;
featureFlags: Set<string>;
}
};

const defaultFindConfig: DefaultFindConfig = {
path: '',
ignore: [],
filter: [],
levelsDeep: 4,
featureFlags: new Set<string>(),
};

/**
* Find all files in given search path. Returns paths to files found.
Expand All @@ -71,10 +86,8 @@ interface FindFilesConfig {
* @param filter (optional) file names to find. If not provided all files are returned.
* @param levelsDeep (optional) how many levels deep to search, defaults to two, this path and one sub directory.
*/
export async function find(
findConfig: Partial<FindFilesConfig>,
): Promise<FindFilesRes> {
const config = getFindConfig(findConfig);
export async function find(findConfig: FindFilesConfig): Promise<FindFilesRes> {
const config: DefaultFindConfig = assign({}, defaultFindConfig, findConfig);
const found: string[] = [];
const foundAll: string[] = [];

Expand Down Expand Up @@ -139,28 +152,10 @@ function findFile(path: string, filter: string[] = []): string | null {
return null;
}

function getFindConfig(option: Partial<FindFilesConfig>): FindFilesConfig {
const result = merge(
{
path: '',
ignore: [],
filter: [],
levelsDeep: MAX_DETECTION_DEPTH,
featureFlags: new Set<string>(),
},
option,
);

if (isNaN(result.levelsDeep) || result.levelsDeep === null) {
result.levelsDeep = MAX_DETECTION_DEPTH;
}
return result;
}

async function findInDirectory(
findConfig: FindFilesConfig,
): Promise<FindFilesRes> {
const config = getFindConfig(findConfig);
const config: DefaultFindConfig = assign({}, defaultFindConfig, findConfig);
const files = await readDirectory(config.path);
const toFind = files
.filter((file) => !config.ignore.includes(file))
Expand Down
3 changes: 1 addition & 2 deletions src/lib/plugins/get-deps-from-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { convertSingleResultToMultiCustom } from './convert-single-splugin-res-t
import { convertMultiResultToMultiCustom } from './convert-multi-plugin-res-to-multi-custom';
import { processYarnWorkspaces } from './nodejs-plugin/yarn-workspaces-parser';
import { ScannedProject } from '@snyk/cli-interface/legacy/common';
import { MAX_DETECTION_DEPTH } from '../constants';

const debug = debugModule('snyk-test');

Expand All @@ -44,7 +43,7 @@ export async function getDepsFromPlugin(
): Promise<pluginApi.MultiProjectResult | MultiProjectResultCustom> {
if (Object.keys(multiProjectProcessors).some((key) => options[key])) {
const scanType = options.yarnWorkspaces ? 'yarnWorkspaces' : 'allProjects';
const levelsDeep = options.detectionDepth || MAX_DETECTION_DEPTH;
const levelsDeep = options.detectionDepth;
const ignore = options.exclude ? options.exclude.split(',') : [];

const { files: targetFiles, allFilesFound } = await find({
Expand Down
3 changes: 0 additions & 3 deletions src/lib/plugins/get-extra-project-count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { legacyPlugin as pluginApi } from '@snyk/cli-interface';
import { find } from '../find-files';
import { AUTO_DETECTABLE_FILES } from '../detect';
import { Options } from '../types';
import { MAX_DETECTION_DEPTH } from '../constants';

export async function getExtraProjectCount(
root: string,
Expand All @@ -24,8 +23,6 @@ export async function getExtraProjectCount(
path: root,
ignore: [],
filter: AUTO_DETECTABLE_FILES,
levelsDeep: MAX_DETECTION_DEPTH,
featureFlags: new Set(),
});
const foundProjectsCount =
extraTargetFiles.length > 1 ? extraTargetFiles.length - 1 : undefined;
Expand Down
2 changes: 0 additions & 2 deletions test/acceptance/workspaces/mono-repo-nested/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions test/acceptance/workspaces/mono-repo-nested/README.md

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading