Skip to content

Commit

Permalink
fix: return correct project name for multi-projects case
Browse files Browse the repository at this point in the history
  • Loading branch information
dkontorovskyy committed Jul 30, 2019
1 parent 16cebed commit 4c042a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/parse-sbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -204,8 +204,8 @@ function parseSbtPluginResults(sbtOutput: string): DepTree {
}

const depTree = {
name: '.',
version: '1.0.0',
name: packageName,
version: packageVersion,
dependencies: {},
};

Expand Down
4 changes: 2 additions & 2 deletions test/functional/parse-sbt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 4c042a2

Please sign in to comment.