Skip to content

Commit

Permalink
fix: don't fail when there are no dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
orkamara committed Oct 29, 2019
1 parent f801d08 commit 6f0d6eb
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/nuget-parser/dotnet-core-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ function constructTree(roots: string[], nodes: Dependency[], links: DepLink[]) {

const tree = _.pick(treeMap, roots);
const freqSysDeps = _.pick(treeMap, Object.keys(freqDeps));
tree['freqSystemDependencies'] = {
name: 'freqSystemDependencies',
version: '0.0.0',
dependencies: freqSysDeps
};
if (!_.isEmpty(freqSysDeps)) {
tree['freqSystemDependencies'] = {
name: 'freqSystemDependencies',
version: '0.0.0',
dependencies: freqSysDeps
};
}
return tree;
}

Expand Down Expand Up @@ -197,7 +199,7 @@ export async function parse(tree, manifest) {

initFreqDepsDict();

const directDependencies = collectFlatList(selectedFrameworkObj.dependencies);
const directDependencies = selectedFrameworkObj.dependencies ? collectFlatList(selectedFrameworkObj.dependencies) : [];
debug(`directDependencies: '${directDependencies}'`);

tree.dependencies = buildBfsTree(selectedTargetObj, directDependencies);
Expand Down
8 changes: 8 additions & 0 deletions test/csproj.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as _ from 'lodash';

import * as tap from 'tap';
const test = tap.test;
import * as plugin from '../lib/index';
Expand All @@ -6,6 +8,7 @@ import {getTargetFrameworksFromProjFile} from '../lib/nuget-parser/csproj-parser
const multipleFrameworksPath = './test/stubs/target_framework/csproj_multiple/';
const noProjectPath = './test/stubs/target_framework/no_csproj/';
const noValidFrameworksPath = './test/stubs/target_framework/no_target_valid_framework';
const noDeps = './test/stubs/target_framework/no-dependencies/';
const manifestFile = 'obj/project.assets.json';

test('parse dotnet with csproj containing multiple versions retrieves first one', async (t) => {
Expand All @@ -20,6 +23,11 @@ test('parse dotnet with vbproj', async (t) => {
t.equal(res.plugin.targetRuntime, 'netcoreapp2.0');
});

test('parse dotnet with no deps', async (t) => {
const res = await plugin.inspect(noDeps, manifestFile);
t.equal(_.isEmpty(res.package.dependencies), true);
});

test('parse dotnet with no valid framework defined', async (t) => {
try {
await plugin.inspect(noValidFrameworksPath, manifestFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": 3,
"targets": {
".NETFramework,Version=v4.7.2": {}
},
"libraries": {},
"projectFileDependencyGroups": {
".NETFramework,Version=v4.7.2": []
},
"packageFolders": {
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\ma\\csproj_no_deps.csproj",
"projectName": "csproj_no_deps",
"projectPath": "C:\\Users\\ma\\csproj_no_deps.csproj",
"packagesPath": "C:\\Users\\ma\\.nuget\\packages\\",
"outputPath": "C:\\Users\\ma\\obj",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
],
"originalTargetFrameworks": [
"net472"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net472": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net472": {}
}
}
}

0 comments on commit 6f0d6eb

Please sign in to comment.