snyk 1.1216.0 → 1.1217.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.
@@ -10737,7 +10737,7 @@ function getConnectionOptions(connectionOptions) {
10737
10737
  return {
10738
10738
  ...connectionOptions,
10739
10739
  // Ensure requestId is set.
10740
- requestId: (_a = connectionOptions.requestId) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
10740
+ requestId: (_a = connectionOptions.requestId) !== null && _a !== void 0 ? _a : uuid_1.v4(),
10741
10741
  };
10742
10742
  }
10743
10743
  function getAnalysisContext(analysisContext) {
@@ -10752,7 +10752,7 @@ async function pollAnalysis(options) {
10752
10752
  });
10753
10753
  // eslint-disable-next-line no-constant-condition
10754
10754
  while (true) {
10755
- analysisResponse = await (0, http_1.getAnalysis)(options);
10755
+ analysisResponse = await http_1.getAnalysis(options);
10756
10756
  if (analysisResponse.type === 'error') {
10757
10757
  return analysisResponse;
10758
10758
  }
@@ -10790,7 +10790,7 @@ async function analyzeBundle(options) {
10790
10790
  exports.analyzeBundle = analyzeBundle;
10791
10791
  function normalizeResultFiles(files, baseDir) {
10792
10792
  return Object.entries(files).reduce((obj, [path, positions]) => {
10793
- const filePath = (0, files_1.resolveBundleFilePath)(baseDir, path);
10793
+ const filePath = files_1.resolveBundleFilePath(baseDir, path);
10794
10794
  obj[filePath] = positions;
10795
10795
  return obj;
10796
10796
  }, {});
@@ -10803,7 +10803,7 @@ async function analyzeFolders(options) {
10803
10803
  var _a, _b;
10804
10804
  const connectionOptions = getConnectionOptions(options.connection);
10805
10805
  const analysisContext = getAnalysisContext(options.analysisContext);
10806
- const fileBundle = await (0, bundles_1.createBundleFromFolders)({
10806
+ const fileBundle = await bundles_1.createBundleFromFolders({
10807
10807
  ...connectionOptions,
10808
10808
  ...options.fileOptions,
10809
10809
  languages: options.languages,
@@ -10814,7 +10814,7 @@ async function analyzeFolders(options) {
10814
10814
  bundleHash: fileBundle.bundleHash,
10815
10815
  ...connectionOptions,
10816
10816
  ...options.analysisOptions,
10817
- shard: (0, files_1.calcHash)(fileBundle.baseDir),
10817
+ shard: files_1.calcHash(fileBundle.baseDir),
10818
10818
  ...analysisContext,
10819
10819
  };
10820
10820
  let analysisResults;
@@ -10823,7 +10823,7 @@ async function analyzeFolders(options) {
10823
10823
  let reportResults;
10824
10824
  if (isReport && options.reportOptions) {
10825
10825
  // Analyze and upload bundle results.
10826
- const reportRes = await (0, report_1.reportBundle)({
10826
+ const reportRes = await report_1.reportBundle({
10827
10827
  ...config,
10828
10828
  report: options.reportOptions,
10829
10829
  });
@@ -10931,9 +10931,9 @@ function mergeLegacyResults(oldAnalysisResults, newAnalysisResults, limitToFiles
10931
10931
  return obj;
10932
10932
  }, {});
10933
10933
  // expand relative file names to absolute ones only for legacy results
10934
- const changedFiles = [...limitToFiles, ...removedFiles].map(path => (0, files_1.resolveBundleFilePath)(baseDir, path));
10934
+ const changedFiles = [...limitToFiles, ...removedFiles].map(path => files_1.resolveBundleFilePath(baseDir, path));
10935
10935
  const files = {
10936
- ...(0, lodash_omit_1.default)(oldAnalysisResults.files, changedFiles),
10936
+ ...lodash_omit_1.default(oldAnalysisResults.files, changedFiles),
10937
10937
  ...newFiles,
10938
10938
  };
10939
10939
  return {
@@ -10943,12 +10943,12 @@ function mergeLegacyResults(oldAnalysisResults, newAnalysisResults, limitToFiles
10943
10943
  };
10944
10944
  }
10945
10945
  async function extendAnalysis(options) {
10946
- const { files, removedFiles } = await (0, files_1.prepareExtendingBundle)(options.fileBundle.baseDir, options.fileBundle.supportedFiles, options.fileBundle.fileIgnores, options.files, options.fileOptions.symlinksEnabled);
10946
+ const { files, removedFiles } = await files_1.prepareExtendingBundle(options.fileBundle.baseDir, options.fileBundle.supportedFiles, options.fileBundle.fileIgnores, options.files, options.fileOptions.symlinksEnabled);
10947
10947
  if (!files.length && !removedFiles.length) {
10948
10948
  return null; // nothing to extend, just return null
10949
10949
  }
10950
10950
  // Extend remote bundle
10951
- const remoteBundle = await (0, bundles_1.remoteBundleFactory)({
10951
+ const remoteBundle = await bundles_1.remoteBundleFactory({
10952
10952
  ...options.connection,
10953
10953
  bundleHash: options.fileBundle.bundleHash,
10954
10954
  baseDir: options.fileBundle.baseDir,
@@ -10966,7 +10966,7 @@ async function extendAnalysis(options) {
10966
10966
  bundleHash: remoteBundle.bundleHash,
10967
10967
  ...options.connection,
10968
10968
  ...options.analysisOptions,
10969
- shard: (0, files_1.calcHash)(fileBundle.baseDir),
10969
+ shard: files_1.calcHash(fileBundle.baseDir),
10970
10970
  limitToFiles,
10971
10971
  });
10972
10972
  analysisResults = mergeBundleResults(options.analysisResults, analysisResults, limitToFiles, removedFiles, options.fileBundle.baseDir);
@@ -10980,7 +10980,7 @@ exports.extendAnalysis = extendAnalysis;
10980
10980
  async function analyzeScmProject(options) {
10981
10981
  const connectionOptions = getConnectionOptions(options.connection);
10982
10982
  const analysisContext = getAnalysisContext(options.analysisContext);
10983
- const { analysisResult: analysisResults, uploadResult: reportResults } = await (0, report_1.reportScm)({
10983
+ const { analysisResult: analysisResults, uploadResult: reportResults } = await report_1.reportScm({
10984
10984
  ...connectionOptions,
10985
10985
  ...options.analysisOptions,
10986
10986
  ...options.reportOptions,
@@ -11016,9 +11016,9 @@ async function* prepareRemoteBundle(options) {
11016
11016
  let { bundleHash } = options;
11017
11017
  let cumulativeProgress = 0;
11018
11018
  emitter_1.emitter.createBundleProgress(cumulativeProgress, options.files.length);
11019
- for (const chunkedFiles of (0, files_1.composeFilePayloads)(options.files)) {
11019
+ for (const chunkedFiles of files_1.composeFilePayloads(options.files)) {
11020
11020
  const apiParams = {
11021
- ...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'extraHeaders', 'removedFiles', 'requestId', 'org']),
11021
+ ...lodash_pick_1.default(options, ['baseURL', 'sessionToken', 'source', 'extraHeaders', 'removedFiles', 'requestId', 'org']),
11022
11022
  files: chunkedFiles.reduce((d, f) => {
11023
11023
  // deepcode ignore PrototypePollution: FP this is an internal code
11024
11024
  d[f.bundlePath] = f.hash;
@@ -11027,11 +11027,11 @@ async function* prepareRemoteBundle(options) {
11027
11027
  };
11028
11028
  if (!bundleHash) {
11029
11029
  // eslint-disable-next-line no-await-in-loop
11030
- response = await (0, http_1.createBundle)(apiParams);
11030
+ response = await http_1.createBundle(apiParams);
11031
11031
  }
11032
11032
  else {
11033
11033
  // eslint-disable-next-line no-await-in-loop
11034
- response = await (0, http_1.extendBundle)({ bundleHash, ...apiParams });
11034
+ response = await http_1.extendBundle({ bundleHash, ...apiParams });
11035
11035
  }
11036
11036
  cumulativeProgress += chunkedFiles.length;
11037
11037
  emitter_1.emitter.createBundleProgress(cumulativeProgress, options.files.length);
@@ -11053,7 +11053,7 @@ async function* prepareRemoteBundle(options) {
11053
11053
  async function uploadRemoteBundle(options) {
11054
11054
  let uploadedFiles = 0;
11055
11055
  emitter_1.emitter.uploadBundleProgress(0, options.files.length);
11056
- const apiParams = (0, lodash_pick_1.default)(options, [
11056
+ const apiParams = lodash_pick_1.default(options, [
11057
11057
  'baseURL',
11058
11058
  'sessionToken',
11059
11059
  'source',
@@ -11064,10 +11064,10 @@ async function uploadRemoteBundle(options) {
11064
11064
  ]);
11065
11065
  const uploadFileChunks = async (bucketFiles) => {
11066
11066
  // Note: we specifically create __new__ isolated bundles here to faster files upload
11067
- const resp = await (0, http_1.createBundle)({
11067
+ const resp = await http_1.createBundle({
11068
11068
  ...apiParams,
11069
11069
  files: bucketFiles.reduce((d, f) => {
11070
- d[f.bundlePath] = (0, lodash_pick_1.default)(f, ['hash', 'content']);
11070
+ d[f.bundlePath] = lodash_pick_1.default(f, ['hash', 'content']);
11071
11071
  return d;
11072
11072
  }, {}),
11073
11073
  });
@@ -11077,10 +11077,10 @@ async function uploadRemoteBundle(options) {
11077
11077
  }
11078
11078
  };
11079
11079
  const files = [];
11080
- for (const bucketFiles of (0, files_1.composeFilePayloads)(options.files)) {
11080
+ for (const bucketFiles of files_1.composeFilePayloads(options.files)) {
11081
11081
  files.push(bucketFiles);
11082
11082
  }
11083
- await (0, p_map_1.default)(files, async (task) => await uploadFileChunks(task), {
11083
+ await p_map_1.default(files, async (task) => await uploadFileChunks(task), {
11084
11084
  concurrency: constants_1.UPLOAD_CONCURRENCY,
11085
11085
  });
11086
11086
  }
@@ -11090,15 +11090,15 @@ async function fullfillRemoteBundle(options) {
11090
11090
  // Check remove bundle to make sure no missing files left
11091
11091
  let attempts = 0;
11092
11092
  let { remoteBundle } = options;
11093
- const connectionOptions = (0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'org', 'extraHeaders']);
11093
+ const connectionOptions = lodash_pick_1.default(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'org', 'extraHeaders']);
11094
11094
  while (remoteBundle.missingFiles.length && attempts < (options.maxAttempts || constants_1.MAX_UPLOAD_ATTEMPTS)) {
11095
- const missingFiles = await (0, files_1.resolveBundleFiles)(options.baseDir, remoteBundle.missingFiles);
11095
+ const missingFiles = await files_1.resolveBundleFiles(options.baseDir, remoteBundle.missingFiles);
11096
11096
  await uploadRemoteBundle({
11097
11097
  ...connectionOptions,
11098
11098
  bundleHash: remoteBundle.bundleHash,
11099
11099
  files: missingFiles,
11100
11100
  });
11101
- const bundleResponse = await (0, http_1.checkBundle)({ ...connectionOptions, bundleHash: remoteBundle.bundleHash });
11101
+ const bundleResponse = await http_1.checkBundle({ ...connectionOptions, bundleHash: remoteBundle.bundleHash });
11102
11102
  if (bundleResponse.type === 'error') {
11103
11103
  throw new Error('Failed to get remote bundle');
11104
11104
  }
@@ -11110,7 +11110,7 @@ async function fullfillRemoteBundle(options) {
11110
11110
  }
11111
11111
  async function remoteBundleFactory(options) {
11112
11112
  let remoteBundle = null;
11113
- const baseOptions = (0, lodash_pick_1.default)(options, [
11113
+ const baseOptions = lodash_pick_1.default(options, [
11114
11114
  'baseURL',
11115
11115
  'sessionToken',
11116
11116
  'source',
@@ -11119,7 +11119,7 @@ async function remoteBundleFactory(options) {
11119
11119
  'org',
11120
11120
  'extraHeaders',
11121
11121
  ]);
11122
- const bundleFactory = prepareRemoteBundle((0, lodash_omit_1.default)(options, ['baseDir']));
11122
+ const bundleFactory = prepareRemoteBundle(lodash_omit_1.default(options, ['baseDir']));
11123
11123
  for await (const response of bundleFactory) {
11124
11124
  if (response.type === 'error') {
11125
11125
  throw response.error;
@@ -11141,7 +11141,7 @@ exports.remoteBundleFactory = remoteBundleFactory;
11141
11141
  */
11142
11142
  async function getSupportedFiles(baseURL, source, requestId, languages) {
11143
11143
  emitter_1.emitter.supportedFilesLoaded(null);
11144
- const resp = await (0, http_1.getFilters)(baseURL, source, undefined, requestId);
11144
+ const resp = await http_1.getFilters(baseURL, source, undefined, requestId);
11145
11145
  if (resp.type === 'error') {
11146
11146
  throw resp.error;
11147
11147
  }
@@ -11186,16 +11186,16 @@ exports.createBundleFromFolders = createBundleFromFolders;
11186
11186
  */
11187
11187
  async function createBundleWithCustomFiles(options, supportedFiles) {
11188
11188
  // Scan for custom ignore rules
11189
- const fileIgnores = await (0, files_1.collectIgnoreRules)(options.paths, options.symlinksEnabled, options.defaultFileIgnores);
11190
- const baseDir = (0, files_1.determineBaseDir)(options.paths);
11189
+ const filePolicies = await files_1.collectFilePolicies(options.paths, options.symlinksEnabled, options.defaultFileIgnores);
11190
+ const baseDir = files_1.determineBaseDir(options.paths);
11191
11191
  emitter_1.emitter.scanFilesProgress(0);
11192
11192
  const bundleFiles = [];
11193
11193
  const skippedOversizedFiles = [];
11194
11194
  let totalFiles = 0;
11195
- const bundleFileCollector = (0, files_1.collectBundleFiles)({
11196
- ...(0, lodash_pick_1.default)(options, ['paths', 'symlinksEnabled']),
11195
+ const bundleFileCollector = files_1.collectBundleFiles({
11196
+ ...lodash_pick_1.default(options, ['paths', 'symlinksEnabled']),
11197
11197
  baseDir,
11198
- fileIgnores,
11198
+ filePolicies,
11199
11199
  supportedFiles,
11200
11200
  });
11201
11201
  for await (const f of bundleFileCollector) {
@@ -11204,7 +11204,7 @@ async function createBundleWithCustomFiles(options, supportedFiles) {
11204
11204
  emitter_1.emitter.scanFilesProgress(totalFiles);
11205
11205
  }
11206
11206
  const bundleOptions = {
11207
- ...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'org', 'extraHeaders']),
11207
+ ...lodash_pick_1.default(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'org', 'extraHeaders']),
11208
11208
  baseDir,
11209
11209
  files: bundleFiles,
11210
11210
  };
@@ -11218,7 +11218,7 @@ async function createBundleWithCustomFiles(options, supportedFiles) {
11218
11218
  ...remoteBundle,
11219
11219
  baseDir,
11220
11220
  supportedFiles,
11221
- fileIgnores,
11221
+ fileIgnores: [...filePolicies.excludes, ...filePolicies.ignores],
11222
11222
  skippedOversizedFiles,
11223
11223
  };
11224
11224
  }
@@ -11433,11 +11433,7 @@ exports.emitter = new EmitterDC();
11433
11433
 
11434
11434
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11435
11435
  if (k2 === undefined) k2 = k;
11436
- var desc = Object.getOwnPropertyDescriptor(m, k);
11437
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11438
- desc = { enumerable: true, get: function() { return m[k]; } };
11439
- }
11440
- Object.defineProperty(o, k2, desc);
11436
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11441
11437
  }) : (function(o, m, k, k2) {
11442
11438
  if (k2 === undefined) k2 = k;
11443
11439
  o[k2] = m[k];
@@ -11458,7 +11454,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11458
11454
  return (mod && mod.__esModule) ? mod : { "default": mod };
11459
11455
  };
11460
11456
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11461
- exports.isMatch = exports.composeFilePayloads = exports.resolveBundleFilePath = exports.resolveBundleFiles = exports.getFileInfo = exports.calcHash = exports.getBundleFilePath = exports.prepareExtendingBundle = exports.collectBundleFiles = exports.determineBaseDir = exports.collectIgnoreRules = exports.getGlobPatterns = exports.parseFileIgnores = exports.notEmpty = void 0;
11457
+ exports.isMatch = exports.composeFilePayloads = exports.resolveBundleFilePath = exports.resolveBundleFiles = exports.getFileInfo = exports.calcHash = exports.getBundleFilePath = exports.prepareExtendingBundle = exports.collectBundleFiles = exports.determineBaseDir = exports.collectFilePolicies = exports.getGlobPatterns = exports.parseFileIgnores = exports.notEmpty = void 0;
11462
11458
  const nodePath = __importStar(__webpack_require__(71017));
11463
11459
  const fs = __importStar(__webpack_require__(57147));
11464
11460
  const fast_glob_1 = __importDefault(__webpack_require__(13294));
@@ -11503,7 +11499,7 @@ const fgOptions = {
11503
11499
  };
11504
11500
  function filterSupportedFiles(files, supportedFiles) {
11505
11501
  const patters = getGlobPatterns(supportedFiles);
11506
- return (0, multimatch_1.default)(files, patters, multiMatchOptions);
11502
+ return multimatch_1.default(files, patters, multiMatchOptions);
11507
11503
  }
11508
11504
  function parseIgnoreRulesToGlobs(rules, baseDir) {
11509
11505
  // Mappings from .gitignore format to glob format:
@@ -11553,7 +11549,7 @@ function parseFileIgnores(path) {
11553
11549
  const f = fs.readFileSync(path, { encoding: 'utf8' });
11554
11550
  if (path.includes(constants_1.DOTSNYK_FILENAME)) {
11555
11551
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
11556
- const parsed = (0, yaml_1.parse)(f);
11552
+ const parsed = yaml_1.parse(f);
11557
11553
  const codeIgnoredPaths = parsed.exclude.code || [];
11558
11554
  const globalIgnoredPaths = parsed.exclude.global || [];
11559
11555
  rules = [...codeIgnoredPaths, ...globalIgnoredPaths];
@@ -11571,7 +11567,13 @@ function parseFileIgnores(path) {
11571
11567
  console.log(`${path} is not accessible. Please check permissions and adjust .dcignore file to not even test this file`);
11572
11568
  }
11573
11569
  }
11574
- return parseIgnoreRulesToGlobs(rules, dirname);
11570
+ try {
11571
+ return parseIgnoreRulesToGlobs(rules, dirname);
11572
+ }
11573
+ catch (err) {
11574
+ console.error('Could not parse ignore rules to glob', { path });
11575
+ throw new Error('Please make sure ignore file follows correct syntax');
11576
+ }
11575
11577
  }
11576
11578
  exports.parseFileIgnores = parseFileIgnores;
11577
11579
  function getGlobPatterns(supportedFiles) {
@@ -11607,25 +11609,48 @@ function generateAllCaseGlobPattern(fileExtension) {
11607
11609
  }, []);
11608
11610
  return caseInsensitivePatterns.join('');
11609
11611
  }
11610
- async function collectIgnoreRules(dirs, symlinksEnabled = false, fileIgnores = constants_1.IGNORES_DEFAULT) {
11612
+ /**
11613
+ * Recursively collect all exclude and ignore rules from "dirs".
11614
+ *
11615
+ * Exclude rules from .snyk files and ignore rules from .[*]ignore files are collected separately.
11616
+ * Any .[*]ignore files in paths excluded by .snyk exclude rules are ignored.
11617
+ */
11618
+ async function collectFilePolicies(dirs, symlinksEnabled = false, fileIgnores = constants_1.IGNORES_DEFAULT) {
11611
11619
  const tasks = dirs.map(async (folder) => {
11612
11620
  const fileStats = await lStat(folder);
11613
11621
  // Check if symlink and exclude if requested
11614
- if (!fileStats || (fileStats.isSymbolicLink() && !symlinksEnabled) || fileStats.isFile())
11615
- return [];
11616
- // Find ignore files inside this directory
11617
- const localIgnoreFiles = await (0, fast_glob_1.default)(constants_1.IGNORE_FILES_NAMES.map(i => `*${i}`), {
11622
+ if (!fileStats || (fileStats.isSymbolicLink() && !symlinksEnabled) || fileStats.isFile()) {
11623
+ return {
11624
+ excludes: [],
11625
+ ignores: [],
11626
+ };
11627
+ }
11628
+ // Find .snyk and .[*]ignore files inside this directory.
11629
+ const allIgnoredFiles = await fast_glob_1.default(constants_1.IGNORE_FILES_NAMES.map(i => `*${i}`), {
11618
11630
  ...fgOptions,
11619
11631
  cwd: folder,
11620
11632
  followSymbolicLinks: symlinksEnabled,
11621
11633
  });
11622
- // Read ignore files and merge new patterns
11623
- return (0, lodash_union_1.default)(...localIgnoreFiles.map(parseFileIgnores));
11634
+ // Parse rules from all .snyk files inside this directory.
11635
+ const snykFiles = allIgnoredFiles.filter(f => f.endsWith(constants_1.DOTSNYK_FILENAME));
11636
+ const snykExcludeRules = lodash_union_1.default(...snykFiles.map(parseFileIgnores));
11637
+ // Parse rules from relevant .[*]ignore files inside this directory.
11638
+ // Exclude ignore files under paths excluded by .snyk files.
11639
+ const ignoreFiles = allIgnoredFiles.filter(f => !f.endsWith(constants_1.DOTSNYK_FILENAME) && multimatch_1.default([nodePath.dirname(f)], snykExcludeRules).length === 0);
11640
+ const ignoreFileRules = lodash_union_1.default(...ignoreFiles.map(parseFileIgnores));
11641
+ return {
11642
+ excludes: snykExcludeRules,
11643
+ ignores: ignoreFileRules,
11644
+ };
11624
11645
  });
11625
- const customRules = await Promise.all(tasks);
11626
- return (0, lodash_union_1.default)(fileIgnores, ...customRules);
11646
+ const collectedRules = await Promise.all(tasks);
11647
+ return {
11648
+ excludes: lodash_union_1.default(...collectedRules.map(policies => policies.excludes)),
11649
+ // Merge external and collected ignore rules
11650
+ ignores: lodash_union_1.default(fileIgnores, ...collectedRules.map(policies => policies.ignores)),
11651
+ };
11627
11652
  }
11628
- exports.collectIgnoreRules = collectIgnoreRules;
11653
+ exports.collectFilePolicies = collectFilePolicies;
11629
11654
  function determineBaseDir(paths) {
11630
11655
  if (paths.length === 1) {
11631
11656
  const path = paths[0];
@@ -11638,9 +11663,9 @@ function determineBaseDir(paths) {
11638
11663
  return '';
11639
11664
  }
11640
11665
  exports.determineBaseDir = determineBaseDir;
11641
- async function* searchFiles(patterns, cwd, symlinksEnabled, ignores) {
11642
- const positiveIgnores = ignores.filter(rule => !rule.startsWith('!'));
11643
- const negativeIgnores = ignores.filter(rule => rule.startsWith('!')).map(rule => rule.substring(1));
11666
+ async function* searchFiles(patterns, cwd, symlinksEnabled, policies) {
11667
+ const positiveIgnores = [...policies.excludes, ...policies.ignores.filter(rule => !rule.startsWith('!'))];
11668
+ const negativeIgnores = policies.ignores.filter(rule => rule.startsWith('!')).map(rule => rule.substring(1));
11644
11669
  // We need to use the ignore rules directly in the stream. Otherwise we would expand all the branches of the file system
11645
11670
  // that should be ignored, leading to performance issues (the parser would look stuck while analyzing each ignored file).
11646
11671
  // However, fast-glob doesn't address the negative rules in the ignore option correctly.
@@ -11657,6 +11682,7 @@ async function* searchFiles(patterns, cwd, symlinksEnabled, ignores) {
11657
11682
  for await (const filePath of positiveSearcher) {
11658
11683
  yield filePath;
11659
11684
  }
11685
+ const deepPatterns = patterns.map(p => `**/${p}`);
11660
11686
  // TODO: This is incorrect because the .gitignore format allows to specify exceptions to previous rules, therefore
11661
11687
  // the separation between positive and negative ignores is incorrect in a scenario with 2+ exeptions like the one below:
11662
11688
  // `node_module/` <= ignores everything in a `node_module` folder and it's relative subfolders
@@ -11668,9 +11694,11 @@ async function* searchFiles(patterns, cwd, symlinksEnabled, ignores) {
11668
11694
  cwd,
11669
11695
  followSymbolicLinks: symlinksEnabled,
11670
11696
  baseNameMatch: false,
11697
+ // Exclude rules should still be respected
11698
+ ignore: policies.excludes,
11671
11699
  });
11672
11700
  for await (const filePath of negativeSearcher) {
11673
- if (isMatch(filePath.toString(), patterns.map(p => `**/${p}`)))
11701
+ if (isMatch(filePath.toString(), deepPatterns))
11674
11702
  yield filePath;
11675
11703
  }
11676
11704
  }
@@ -11679,7 +11707,7 @@ async function* searchFiles(patterns, cwd, symlinksEnabled, ignores) {
11679
11707
  * Returns bundle files from requested paths
11680
11708
  * If a file exceeds the maximum file size, it returns a string with its path
11681
11709
  * */
11682
- async function* collectBundleFiles({ symlinksEnabled = false, baseDir, fileIgnores, paths, supportedFiles, }) {
11710
+ async function* collectBundleFiles({ symlinksEnabled = false, baseDir, filePolicies, paths, supportedFiles, }) {
11683
11711
  const cache = new cache_1.Cache(constants_1.CACHE_KEY, baseDir);
11684
11712
  const files = [];
11685
11713
  const dirs = [];
@@ -11700,7 +11728,7 @@ async function* collectBundleFiles({ symlinksEnabled = false, baseDir, fileIgnor
11700
11728
  // Scan folders
11701
11729
  const globPatterns = getGlobPatterns(supportedFiles);
11702
11730
  for (const folder of dirs) {
11703
- const searcher = searchFiles(globPatterns, folder, symlinksEnabled, fileIgnores);
11731
+ const searcher = searchFiles(globPatterns, folder, symlinksEnabled, filePolicies);
11704
11732
  // eslint-disable-next-line no-await-in-loop
11705
11733
  for await (const filePath of searcher) {
11706
11734
  const fileInfo = await getFileInfo(filePath.toString(), baseDir, false, cache);
@@ -11712,7 +11740,7 @@ async function* collectBundleFiles({ symlinksEnabled = false, baseDir, fileIgnor
11712
11740
  }
11713
11741
  // Sanitize files
11714
11742
  if (files.length) {
11715
- const searcher = searchFiles(filterSupportedFiles(files, supportedFiles), baseDir, symlinksEnabled, fileIgnores);
11743
+ const searcher = searchFiles(filterSupportedFiles(files, supportedFiles), baseDir, symlinksEnabled, filePolicies);
11716
11744
  for await (const filePath of searcher) {
11717
11745
  const fileInfo = await getFileInfo(filePath.toString(), baseDir, false, cache);
11718
11746
  // dc ignore AttrAccessOnNull: false positive, there is a precondition with &&
@@ -11737,7 +11765,7 @@ async function prepareExtendingBundle(baseDir, supportedFiles, fileIgnores = con
11737
11765
  if (isWindows) {
11738
11766
  processingFiles = processingFiles.map(f => f.replace(/\\/g, '/')); // fg requires forward-slashes in Windows globs
11739
11767
  }
11740
- const entries = await (0, fast_glob_1.default)(processingFiles, {
11768
+ const entries = await fast_glob_1.default(processingFiles, {
11741
11769
  ...fgOptions,
11742
11770
  cwd: baseDir,
11743
11771
  followSymbolicLinks: symlinksEnabled,
@@ -11878,7 +11906,7 @@ function* composeFilePayloads(files, bucketSize = constants_1.MAX_PAYLOAD / 2) {
11878
11906
  }
11879
11907
  exports.composeFilePayloads = composeFilePayloads;
11880
11908
  function isMatch(filePath, rules) {
11881
- return !!(0, multimatch_1.default)([filePath], rules, { ...multiMatchOptions, matchBase: false }).length;
11909
+ return !!multimatch_1.default([filePath], rules, { ...multiMatchOptions, matchBase: false }).length;
11882
11910
  }
11883
11911
  exports.isMatch = isMatch;
11884
11912
  //# sourceMappingURL=files.js.map
@@ -11934,14 +11962,14 @@ const GENERIC_ERROR_MESSAGES = {
11934
11962
  };
11935
11963
  async function compressAndEncode(payload) {
11936
11964
  // encode payload and compress;
11937
- const deflate = (0, util_1.promisify)(zlib_1.gzip);
11965
+ const deflate = util_1.promisify(zlib_1.gzip);
11938
11966
  const compressedPayload = await deflate(Buffer.from(JSON.stringify(payload)).toString('base64'));
11939
11967
  return compressedPayload;
11940
11968
  }
11941
11969
  exports.compressAndEncode = compressAndEncode;
11942
11970
  function startSession(options) {
11943
11971
  const { source, authHost } = options;
11944
- const draftToken = (0, uuid_1.v4)();
11972
+ const draftToken = uuid_1.v4();
11945
11973
  return {
11946
11974
  draftToken,
11947
11975
  loginURL: `${authHost}/login?token=${draftToken}&utm_medium=${source}&utm_source=${source}&utm_campaign=${source}&docker=false`,
@@ -11960,7 +11988,7 @@ exports.getVerifyCallbackUrl = getVerifyCallbackUrl;
11960
11988
  async function getIpFamily(authHost) {
11961
11989
  const family = 6;
11962
11990
  // Dispatch a FORCED IPv6 request to test client's ISP and network capability
11963
- const res = await (0, needle_1.makeRequest)({
11991
+ const res = await needle_1.makeRequest({
11964
11992
  url: getVerifyCallbackUrl(authHost),
11965
11993
  method: 'post',
11966
11994
  family, // family param forces the handler to dispatch a request using IP at "family" version
@@ -11979,7 +12007,7 @@ async function checkSession(options) {
11979
12007
  type: 'success',
11980
12008
  value: '',
11981
12009
  };
11982
- const res = await (0, needle_1.makeRequest)({
12010
+ const res = await needle_1.makeRequest({
11983
12011
  url: getVerifyCallbackUrl(options.authHost),
11984
12012
  body: {
11985
12013
  token: options.draftToken,
@@ -11998,7 +12026,7 @@ async function checkSession(options) {
11998
12026
  exports.checkSession = checkSession;
11999
12027
  async function getFilters(baseURL, source, attempts = constants_1.MAX_RETRY_ATTEMPTS, requestId) {
12000
12028
  const apiName = 'filters';
12001
- const res = await (0, needle_1.makeRequest)({
12029
+ const res = await needle_1.makeRequest({
12002
12030
  headers: { source, ...(requestId && { 'snyk-request-id': requestId }) },
12003
12031
  url: `${baseURL}/${apiName}`,
12004
12032
  method: 'get',
@@ -12039,7 +12067,7 @@ async function createBundle(options) {
12039
12067
  body: payloadBody,
12040
12068
  isJson: false,
12041
12069
  };
12042
- const res = await (0, needle_1.makeRequest)(payload);
12070
+ const res = await needle_1.makeRequest(payload);
12043
12071
  if (res.success) {
12044
12072
  return { type: 'success', value: res.body };
12045
12073
  }
@@ -12053,7 +12081,7 @@ const CHECK_BUNDLE_ERROR_MESSAGES = {
12053
12081
  [constants_1.ErrorCodes.notFound]: 'Uploaded bundle has expired',
12054
12082
  };
12055
12083
  async function checkBundle(options) {
12056
- const res = await (0, needle_1.makeRequest)({
12084
+ const res = await needle_1.makeRequest({
12057
12085
  headers: {
12058
12086
  ...commonHttpHeaders(options),
12059
12087
  },
@@ -12074,8 +12102,8 @@ const EXTEND_BUNDLE_ERROR_MESSAGES = {
12074
12102
  [constants_1.ErrorCodes.notFound]: 'Parent bundle has expired',
12075
12103
  };
12076
12104
  async function extendBundle(options) {
12077
- const payloadBody = await compressAndEncode((0, lodash_pick_1.default)(options, ['files', 'removedFiles']));
12078
- const res = await (0, needle_1.makeRequest)({
12105
+ const payloadBody = await compressAndEncode(lodash_pick_1.default(options, ['files', 'removedFiles']));
12106
+ const res = await needle_1.makeRequest({
12079
12107
  headers: {
12080
12108
  'content-type': 'application/octet-stream',
12081
12109
  'content-encoding': 'gzip',
@@ -12123,10 +12151,10 @@ async function getAnalysis(options) {
12123
12151
  limitToFiles: options.limitToFiles || [],
12124
12152
  ...(options.shard ? { shard: options.shard } : null),
12125
12153
  },
12126
- ...(0, lodash_pick_1.default)(options, ['severity', 'prioritized', 'legacy', 'analysisContext']),
12154
+ ...lodash_pick_1.default(options, ['severity', 'prioritized', 'legacy', 'analysisContext']),
12127
12155
  },
12128
12156
  };
12129
- const res = await (0, needle_1.makeRequest)(config);
12157
+ const res = await needle_1.makeRequest(config);
12130
12158
  if (res.success)
12131
12159
  return { type: 'success', value: res.body };
12132
12160
  return generateError(res.errorCode, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis');
@@ -12163,10 +12191,10 @@ async function initReport(options) {
12163
12191
  limitToFiles: options.limitToFiles || [],
12164
12192
  ...(options.shard ? { shard: options.shard } : null),
12165
12193
  },
12166
- ...(0, lodash_pick_1.default)(options, ['severity', 'prioritized', 'legacy', 'analysisContext']),
12194
+ ...lodash_pick_1.default(options, ['severity', 'prioritized', 'legacy', 'analysisContext']),
12167
12195
  },
12168
12196
  };
12169
- const res = await (0, needle_1.makeRequest)(config);
12197
+ const res = await needle_1.makeRequest(config);
12170
12198
  if (res.success)
12171
12199
  return { type: 'success', value: res.body.reportId };
12172
12200
  return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport');
@@ -12184,7 +12212,7 @@ async function getReport(options) {
12184
12212
  url: `${options.baseURL}/report/${options.pollId}`,
12185
12213
  method: 'get',
12186
12214
  };
12187
- const res = await (0, needle_1.makeRequest)(config);
12215
+ const res = await needle_1.makeRequest(config);
12188
12216
  if (res.success)
12189
12217
  return { type: 'success', value: res.body };
12190
12218
  return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message);
@@ -12205,10 +12233,10 @@ async function initScmReport(options) {
12205
12233
  projectId: options.projectId,
12206
12234
  commitHash: options.commitId,
12207
12235
  },
12208
- ...(0, lodash_pick_1.default)(options, ['severity', 'prioritized', 'analysisContext']),
12236
+ ...lodash_pick_1.default(options, ['severity', 'prioritized', 'analysisContext']),
12209
12237
  },
12210
12238
  };
12211
- const res = await (0, needle_1.makeRequest)(config);
12239
+ const res = await needle_1.makeRequest(config);
12212
12240
  if (res.success)
12213
12241
  return { type: 'success', value: res.body.testId };
12214
12242
  return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport');
@@ -12226,7 +12254,7 @@ async function getScmReport(options) {
12226
12254
  url: `${options.baseURL}/test/${options.pollId}`,
12227
12255
  method: 'get',
12228
12256
  };
12229
- const res = await (0, needle_1.makeRequest)(config);
12257
+ const res = await needle_1.makeRequest(config);
12230
12258
  if (res.success)
12231
12259
  return { type: 'success', value: res.body };
12232
12260
  return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message);
@@ -12243,11 +12271,7 @@ exports.getScmReport = getScmReport;
12243
12271
 
12244
12272
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12245
12273
  if (k2 === undefined) k2 = k;
12246
- var desc = Object.getOwnPropertyDescriptor(m, k);
12247
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12248
- desc = { enumerable: true, get: function() { return m[k]; } };
12249
- }
12250
- Object.defineProperty(o, k2, desc);
12274
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12251
12275
  }) : (function(o, m, k, k2) {
12252
12276
  if (k2 === undefined) k2 = k;
12253
12277
  o[k2] = m[k];
@@ -12318,11 +12342,7 @@ var AnalysisSeverity;
12318
12342
 
12319
12343
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12320
12344
  if (k2 === undefined) k2 = k;
12321
- var desc = Object.getOwnPropertyDescriptor(m, k);
12322
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12323
- desc = { enumerable: true, get: function() { return m[k]; } };
12324
- }
12325
- Object.defineProperty(o, k2, desc);
12345
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12326
12346
  }) : (function(o, m, k, k2) {
12327
12347
  if (k2 === undefined) k2 = k;
12328
12348
  o[k2] = m[k];
@@ -12401,7 +12421,7 @@ async function makeRequest(payload, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
12401
12421
  let error;
12402
12422
  let response;
12403
12423
  try {
12404
- response = await (0, needle_1.default)(method, url, data, options);
12424
+ response = await needle_1.default(method, url, data, options);
12405
12425
  emitter_1.emitter.apiRequestLog(`<= Response: ${response.statusCode} ${JSON.stringify(response.body)}`);
12406
12426
  const success = !!(response.statusCode && response.statusCode >= 200 && response.statusCode < 300);
12407
12427
  if (success)
@@ -12451,11 +12471,7 @@ exports.makeRequest = makeRequest;
12451
12471
 
12452
12472
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12453
12473
  if (k2 === undefined) k2 = k;
12454
- var desc = Object.getOwnPropertyDescriptor(m, k);
12455
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12456
- desc = { enumerable: true, get: function() { return m[k]; } };
12457
- }
12458
- Object.defineProperty(o, k2, desc);
12474
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12459
12475
  }) : (function(o, m, k, k2) {
12460
12476
  if (k2 === undefined) k2 = k;
12461
12477
  o[k2] = m[k];
@@ -12500,7 +12516,7 @@ async function initAndPollReportGeneric(initReportFunc, getReportFunc, options)
12500
12516
  while (true) {
12501
12517
  // eslint-disable-next-line no-await-in-loop
12502
12518
  apiResponse = await getReportFunc({
12503
- ...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'org']),
12519
+ ...lodash_pick_1.default(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'org']),
12504
12520
  pollId,
12505
12521
  });
12506
12522
  if (apiResponse.type === 'error') {
@@ -94763,6 +94779,8 @@ class Settings {
94763
94779
  if (this.stats) {
94764
94780
  this.objectMode = true;
94765
94781
  }
94782
+ // Remove the cast to the array in the next major (#404).
94783
+ this.ignore = [].concat(this.ignore);
94766
94784
  }
94767
94785
  _getValue(option, value) {
94768
94786
  return option === undefined ? value : option;
@@ -102377,6 +102395,7 @@ const EMPTY = ''
102377
102395
  const SPACE = ' '
102378
102396
  const ESCAPE = '\\'
102379
102397
  const REGEX_TEST_BLANK_LINE = /^\s+$/
102398
+ const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/
102380
102399
  const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/
102381
102400
  const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/
102382
102401
  const REGEX_SPLITALL_CRLF = /\r?\n/g
@@ -102388,10 +102407,14 @@ const REGEX_SPLITALL_CRLF = /\r?\n/g
102388
102407
  const REGEX_TEST_INVALID_PATH = /^\.*\/|^\.+$/
102389
102408
 
102390
102409
  const SLASH = '/'
102391
- const KEY_IGNORE = typeof Symbol !== 'undefined'
102392
- ? Symbol.for('node-ignore')
102393
- /* istanbul ignore next */
102394
- : 'node-ignore'
102410
+
102411
+ // Do not use ternary expression here, since "istanbul ignore next" is buggy
102412
+ let TMP_KEY_IGNORE = 'node-ignore'
102413
+ /* istanbul ignore else */
102414
+ if (typeof Symbol !== 'undefined') {
102415
+ TMP_KEY_IGNORE = Symbol.for('node-ignore')
102416
+ }
102417
+ const KEY_IGNORE = TMP_KEY_IGNORE
102395
102418
 
102396
102419
  const define = (object, key, value) =>
102397
102420
  Object.defineProperty(object, key, {value})
@@ -102558,18 +102581,27 @@ const REPLACERS = [
102558
102581
  : '\\/.+'
102559
102582
  ],
102560
102583
 
102561
- // intermediate wildcards
102584
+ // normal intermediate wildcards
102562
102585
  [
102563
102586
  // Never replace escaped '*'
102564
102587
  // ignore rule '\*' will match the path '*'
102565
102588
 
102566
102589
  // 'abc.*/' -> go
102567
- // 'abc.*' -> skip this rule
102568
- /(^|[^\\]+)\\\*(?=.+)/g,
102590
+ // 'abc.*' -> skip this rule,
102591
+ // coz trailing single wildcard will be handed by [trailing wildcard]
102592
+ /(^|[^\\]+)(\\\*)+(?=.+)/g,
102569
102593
 
102570
102594
  // '*.js' matches '.js'
102571
102595
  // '*.js' doesn't match 'abc'
102572
- (_, p1) => `${p1}[^\\/]*`
102596
+ (_, p1, p2) => {
102597
+ // 1.
102598
+ // > An asterisk "*" matches anything except a slash.
102599
+ // 2.
102600
+ // > Other consecutive asterisks are considered regular asterisks
102601
+ // > and will match according to the previous rules.
102602
+ const unescaped = p2.replace(/\\\*/g, '[^\\/]*')
102603
+ return p1 + unescaped
102604
+ }
102573
102605
  ],
102574
102606
 
102575
102607
  [
@@ -102680,6 +102712,7 @@ const isString = subject => typeof subject === 'string'
102680
102712
  const checkPattern = pattern => pattern
102681
102713
  && isString(pattern)
102682
102714
  && !REGEX_TEST_BLANK_LINE.test(pattern)
102715
+ && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern)
102683
102716
 
102684
102717
  // > A line starting with # serves as a comment.
102685
102718
  && pattern.indexOf('#') !== 0
@@ -102945,7 +102978,7 @@ module.exports = factory
102945
102978
 
102946
102979
  // Windows
102947
102980
  // --------------------------------------------------------------
102948
- /* istanbul ignore if */
102981
+ /* istanbul ignore if */
102949
102982
  if (
102950
102983
  // Detect `process` so that it can run in browsers.
102951
102984
  typeof process !== 'undefined'