snyk 1.747.0 → 1.748.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.
@@ -192305,29 +192305,34 @@ async function printIfEcho(line) {
192305
192305
  debugLog(maybeMatch[1]);
192306
192306
  }
192307
192307
  }
192308
- async function getInjectedScriptPath() {
192308
+ function getPluginFileName(options) {
192309
+ return options.gradleAcceptLegacyConfigRoles
192310
+ ? 'init.gradle'
192311
+ : 'legacy-init.gradle';
192312
+ }
192313
+ async function injectedPlugin(scriptName) {
192309
192314
  let initGradleAsset = null;
192310
192315
  if (/index.js$/.test(__filename)) {
192311
192316
  // running from ./dist
192312
192317
  // path.join call has to be exactly in this format, needed by "pkg" to build a standalone Snyk CLI binary:
192313
192318
  // https://www.npmjs.com/package/pkg#detecting-assets-in-source-code
192314
- initGradleAsset = path.join(__dirname, '../lib/init.gradle');
192319
+ initGradleAsset = path.join(__dirname, '../lib', scriptName);
192315
192320
  }
192316
192321
  else if (/index.ts$/.test(__filename)) {
192317
192322
  // running from ./lib
192318
- initGradleAsset = path.join(__dirname, 'init.gradle');
192323
+ initGradleAsset = path.join(__dirname, scriptName);
192319
192324
  }
192320
192325
  else {
192321
- throw new Error('Cannot locate Snyk init.gradle script');
192326
+ throw new Error(`Cannot locate Snyk ${scriptName} script`);
192322
192327
  }
192323
192328
  // We could be running from a bundled CLI generated by `pkg`.
192324
192329
  // The Node filesystem in that case is not real: https://github.com/zeit/pkg#snapshot-filesystem
192325
192330
  // Copying the injectable script into a temp file.
192326
192331
  try {
192327
- const tmpInitGradle = tmp.fileSync({ postfix: '-init.gradle' });
192332
+ const tmpInitGradle = tmp.fileSync({ postfix: `-${scriptName}` });
192328
192333
  fs.writeSync(tmpInitGradle.fd, fs.readFileSync(initGradleAsset));
192329
192334
  return {
192330
- injectedScripPath: tmpInitGradle.name,
192335
+ injectedPluginFilePath: tmpInitGradle.name,
192331
192336
  cleanupCallback: tmpInitGradle.removeCallback,
192332
192337
  };
192333
192338
  }
@@ -192378,8 +192383,7 @@ function getVersionBuildInfo(gradleVersionOutput) {
192378
192383
  debugLog('version build info not present, skipping ahead: ' + error);
192379
192384
  }
192380
192385
  }
192381
- async function getAllDeps(root, targetFile, options) {
192382
- const command = getCommand(root, targetFile);
192386
+ async function getGradleVersion(root, command) {
192383
192387
  debugLog('`gradle -v` command run: ' + command);
192384
192388
  let gradleVersionOutput = '[COULD NOT RUN gradle -v]';
192385
192389
  try {
@@ -192390,29 +192394,40 @@ async function getAllDeps(root, targetFile, options) {
192390
192394
  catch (_) {
192391
192395
  // intentionally empty
192392
192396
  }
192393
- if (gradleVersionOutput.match(/Gradle 1/)) {
192394
- throw new Error('Gradle 1.x is not supported');
192395
- }
192396
- const { injectedScripPath, cleanupCallback } = await getInjectedScriptPath();
192397
- const args = buildArgs(root, targetFile, injectedScripPath, options);
192397
+ return gradleVersionOutput;
192398
+ }
192399
+ async function getAllDepsWithPlugin(root, targetFile, options) {
192400
+ const command = getCommand(root, targetFile);
192401
+ const pluginFileName = getPluginFileName(options);
192402
+ const { injectedPluginFilePath, cleanupCallback } = await injectedPlugin(pluginFileName);
192403
+ const args = buildArgs(root, targetFile, injectedPluginFilePath, options);
192398
192404
  const fullCommandText = 'gradle command: ' + command + ' ' + args.join(' ');
192399
192405
  debugLog('Executing ' + fullCommandText);
192406
+ const stdoutText = await subProcess.execute(command, args, { cwd: root }, printIfEcho);
192407
+ if (cleanupCallback) {
192408
+ cleanupCallback();
192409
+ }
192410
+ const extractedJSON = extractJsonFromScriptOutput(stdoutText);
192411
+ const jsonAttrsPretty = gradle_attributes_pretty_1.getGradleAttributesPretty(stdoutText);
192412
+ logger(`The following attributes and their possible values were found in your configurations: ${jsonAttrsPretty}`);
192413
+ return extractedJSON;
192414
+ }
192415
+ async function getAllDeps(root, targetFile, options) {
192416
+ const command = getCommand(root, targetFile);
192417
+ const gradleVersion = await getGradleVersion(root, command);
192418
+ if (gradleVersion.match(/Gradle 1/)) {
192419
+ throw new Error('Gradle 1.x is not supported');
192420
+ }
192400
192421
  try {
192401
- const stdoutText = await subProcess.execute(command, args, { cwd: root }, printIfEcho);
192402
- if (cleanupCallback) {
192403
- cleanupCallback();
192404
- }
192405
- const extractedJSON = extractJsonFromScriptOutput(stdoutText);
192406
- const jsonAttrsPretty = gradle_attributes_pretty_1.getGradleAttributesPretty(stdoutText);
192407
- logger(`The following attributes and their possible values were found in your configurations: ${jsonAttrsPretty}`);
192408
- const versionBuildInfo = getVersionBuildInfo(gradleVersionOutput);
192422
+ const extractedJSON = await getAllDepsWithPlugin(root, targetFile, options);
192423
+ const versionBuildInfo = getVersionBuildInfo(gradleVersion);
192409
192424
  if (versionBuildInfo) {
192410
192425
  extractedJSON.versionBuildInfo = versionBuildInfo;
192411
192426
  }
192412
192427
  return await processProjectsInExtractedJSON(root, extractedJSON);
192413
192428
  }
192414
- catch (error0) {
192415
- const error = error0;
192429
+ catch (err) {
192430
+ const error = err;
192416
192431
  const gradleErrorMarkers = /^\s*>\s.*$/;
192417
192432
  const gradleErrorEssence = error.message
192418
192433
  .split('\n')
@@ -192420,7 +192435,7 @@ async function getAllDeps(root, targetFile, options) {
192420
192435
  .join('\n');
192421
192436
  const orange = chalk.rgb(255, 128, 0);
192422
192437
  const blackOnYellow = chalk.bgYellowBright.black;
192423
- gradleVersionOutput = orange(gradleVersionOutput);
192438
+ const gradleVersionOutput = orange(gradleVersion);
192424
192439
  let mainErrorMessage = `Error running Gradle dependency analysis.
192425
192440
 
192426
192441
  Please ensure you are calling the \`snyk\` command with correct arguments.
@@ -192471,7 +192486,6 @@ to
192471
192486
  error.message = `${chalk.red.bold('Gradle Error (short):\n' + gradleErrorEssence)}
192472
192487
 
192473
192488
  ${blackOnYellow('===== DEBUG INFORMATION START =====')}
192474
- ${orange(fullCommandText)}
192475
192489
  ${orange(gradleVersionOutput)}
192476
192490
  ${orange(error.message)}
192477
192491
  ${blackOnYellow('===== DEBUG INFORMATION END =====')}
@@ -192609,6 +192623,7 @@ exports.exportsForTests = {
192609
192623
  getVersionBuildInfo,
192610
192624
  toCamelCase,
192611
192625
  getGradleAttributesPretty: gradle_attributes_pretty_1.getGradleAttributesPretty,
192626
+ getPluginFileName,
192612
192627
  };
192613
192628
  //# sourceMappingURL=index.js.map
192614
192629