From 4c042a26981a424a12e8db4c3dc5c003e18d9a2a Mon Sep 17 00:00:00 2001 From: Daniel Kontorovskyi Date: Tue, 30 Jul 2019 16:20:56 +0300 Subject: [PATCH] fix: return correct project name for multi-projects case --- lib/index.ts | 4 +++- lib/parse-sbt.ts | 6 +++--- test/functional/parse-sbt.test.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 819987ae..b912b7b6 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -117,6 +117,8 @@ async function pluginInspect(root: string, targetFile: string, options: any): Pr const sbtArgs = buildArgs(options.args, false, true); const sbtVersion = getSbtVersion(root, targetFile); const sbtPluginPath = generateSbtPluginPath(sbtVersion); + const packageName = path.basename(root); + const packageVersion = '1.0.0'; try { // We could be running from a bundled CLI generated by `pkg`. @@ -140,7 +142,7 @@ async function pluginInspect(root: string, targetFile: string, options: any): Pr name: 'snyk:sbt', runtime: 'unknown', }, - package: parser.parseSbtPluginResults(stdout), + package: parser.parseSbtPluginResults(stdout, packageName, packageVersion), }; } catch (error) { debug('Failed to produce dependency tree with custom snyk plugin due to error: ' + error.message); diff --git a/lib/parse-sbt.ts b/lib/parse-sbt.ts index 39a63fcc..3258af53 100644 --- a/lib/parse-sbt.ts +++ b/lib/parse-sbt.ts @@ -189,7 +189,7 @@ function parse(text, name, version, isCoursier): DepTree { return createSnykTree(rootTree, name, version); } -function parseSbtPluginResults(sbtOutput: string): DepTree { +function parseSbtPluginResults(sbtOutput: string, packageName: string, packageVersion: string): DepTree { // remove all other output const outputStart = 'Snyk Output Start'; const outputEnd = 'Snyk Output End'; @@ -204,8 +204,8 @@ function parseSbtPluginResults(sbtOutput: string): DepTree { } const depTree = { - name: '.', - version: '1.0.0', + name: packageName, + version: packageVersion, dependencies: {}, }; diff --git a/test/functional/parse-sbt.test.ts b/test/functional/parse-sbt.test.ts index ecabbc75..f11af5bb 100644 --- a/test/functional/parse-sbt.test.ts +++ b/test/functional/parse-sbt.test.ts @@ -98,7 +98,7 @@ test('parse `sbt dependencies` output: plugin 1.2.8', async (t) => { __dirname, '..', 'fixtures', 'sbt-plugin-1.2.8-output.txt'), 'utf8'); - const depTree = parser.parseSbtPluginResults(sbtOutput); + const depTree = parser.parseSbtPluginResults(sbtOutput, 'com.example:hello_2.12', '1.0.0'); t.equal(depTree.name, 'com.example:hello_2.12'); t.equal(depTree.version, '0.1.0-SNAPSHOT'); @@ -121,7 +121,7 @@ test('parse `sbt dependencies` output: plugin 0.13', async (t) => { __dirname, '..', 'fixtures', 'sbt-plugin-0.13-output.txt'), 'utf8'); - const depTree = parser.parseSbtPluginResults(sbtOutput); + const depTree = parser.parseSbtPluginResults(sbtOutput, 'com.example:hello_2.12', '1.0.0'); t.equal(depTree.name, 'com.example:hello_2.12'); t.equal(depTree.version, '0.1.0-SNAPSHOT');