Skip to content

Commit

Permalink
Merge pull request #4671 from pangaeatech/pangaeatech/nuget-devSupport
Browse files Browse the repository at this point in the history
Adding "devDependencies" support for nuget projects.
  • Loading branch information
feelepxyz authored Jan 27, 2022
2 parents 573b6bf + b54332d commit 5a421b1
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def dependency_set
requirements: [{
requirement: dependency_version(dependency_node),
file: packages_config.name,
groups: [],
groups: [dependency_type(dependency_node)],
source: nil
}]
)
Expand All @@ -57,6 +57,12 @@ def dependency_version(dependency_node)
dependency_node.attribute("version")&.value&.strip ||
dependency_node.at_xpath("./version")&.content&.strip
end

def dependency_type(dependency_node)
val = dependency_node.attribute("developmentDependency")&.value&.strip ||
dependency_node.at_xpath("./developmentDependency")&.content&.strip
val.to_s.downcase == "true" ? "devDependencies" : "dependencies"
end
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ def dependency_set(project_file:)
req = dependency_requirement(dependency_node, project_file)
version = dependency_version(dependency_node, project_file)
prop_name = req_property_name(dependency_node)
is_dev = dependency_node.name == "DevelopmentDependency"

dependency = build_dependency(name, req, version, prop_name, project_file)
dependency = build_dependency(name, req, version, prop_name, project_file, dev: is_dev)
dependency_set << dependency if dependency
end

# Look for SDK references; see:
# https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk
add_sdk_references(doc, dependency_set, project_file)
Expand Down Expand Up @@ -109,7 +111,7 @@ def add_sdk_refs_from_sdk_tags(doc, dependency_set, project_file)
end
end

def build_dependency(name, req, version, prop_name, project_file)
def build_dependency(name, req, version, prop_name, project_file, dev: false)
return unless name

# Exclude any dependencies specified using interpolation
Expand All @@ -118,7 +120,7 @@ def build_dependency(name, req, version, prop_name, project_file)
requirement = {
requirement: req,
file: project_file.name,
groups: [],
groups: [dev ? "devDependencies" : "dependencies"],
source: nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,26 @@
[{
requirement: "1.0.0",
file: "packages.config",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
end
end

describe "the second dependency" do
subject(:dependency) { dependencies.at(1) }

it "has the right details" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).
to eq("Microsoft.Net.Compilers")
expect(dependency.version).to eq("1.0.1")
expect(dependency.requirements).to eq(
[{
requirement: "1.0.1",
file: "packages.config",
groups: ["devDependencies"],
source: nil
}]
)
Expand Down
61 changes: 46 additions & 15 deletions nuget/spec/dependabot/nuget/file_parser/project_file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
[{
requirement: "1.1.1",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand All @@ -51,7 +51,7 @@
[{
requirement: nil,
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand All @@ -69,7 +69,7 @@
[{
requirement: "4.3.0",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand Down Expand Up @@ -167,7 +167,7 @@
[{
requirement: "0.1.434",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil,
metadata: { property_name: "NukeVersion" }
}]
Expand All @@ -192,7 +192,7 @@
[{
requirement: "0.1.434",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil,
metadata: { property_name: "NukeVersion" }
}]
Expand All @@ -218,7 +218,7 @@
[{
requirement: "$(UnknownVersion)",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil,
metadata: { property_name: "UnknownVersion" }
}]
Expand All @@ -231,9 +231,40 @@
context "with a nuproj" do
let(:file_body) { fixture("csproj", "basic.nuproj") }

it "has the right details" do
expect(dependencies.map(&:name)).
to match_array(%w(nanoFramework.CoreLibrary))
it "gets the right number of dependencies" do
expect(dependencies.count).to eq(2)
end

describe "the first dependency" do
subject(:dependency) { dependencies.first }

it "has the right details" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).to eq("nanoFramework.CoreLibrary")
expect(dependency.version).to eq("1.0.0-preview062")
expect(dependency.requirements).to eq([{
requirement: "[1.0.0-preview062]",
file: "my.csproj",
groups: ["dependencies"],
source: nil
}])
end
end

describe "the second dependency" do
subject(:dependency) { dependencies.at(1) }

it "has the right details" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).to eq("nanoFramework.CoreExtra")
expect(dependency.version).to eq("1.0.0-preview061")
expect(dependency.requirements).to eq([{
requirement: "[1.0.0-preview061]",
file: "my.csproj",
groups: ["devDependencies"],
source: nil
}])
end
end
end

Expand Down Expand Up @@ -261,7 +292,7 @@
expect(dependency.requirements).to eq([{
requirement: "1.2.3",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}])
end
Expand All @@ -277,7 +308,7 @@
expect(dependency.requirements).to eq([{
requirement: "0.1.0-beta",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}])
end
Expand All @@ -299,7 +330,7 @@
expect(dependency.requirements).to eq([{
requirement: "1.2.3",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}])
end
Expand All @@ -315,7 +346,7 @@
expect(dependency.requirements).to eq([{
requirement: "0.1.0-beta",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}])
end
Expand All @@ -337,7 +368,7 @@
expect(dependency.requirements).to eq([{
requirement: "1.2.3",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}])
end
Expand All @@ -353,7 +384,7 @@
expect(dependency.requirements).to eq([{
requirement: "0.1.0-beta",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}])
end
Expand Down
58 changes: 48 additions & 10 deletions nuget/spec/dependabot/nuget/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
[{
requirement: "1.1.1",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand All @@ -56,7 +56,7 @@
[{
requirement: "4.3.0",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand Down Expand Up @@ -85,12 +85,12 @@
[{
requirement: "1.1.1",
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}, {
requirement: "1.0.1",
file: "my.vbproj",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand All @@ -108,7 +108,7 @@
[{
requirement: "2.3.0",
file: "my.vbproj",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand Down Expand Up @@ -139,7 +139,26 @@
[{
requirement: "1.0.0",
file: "packages.config",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
end
end

describe "the second dependency" do
subject(:dependency) { dependencies.at(1) }

it "has the right details" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).
to eq("Microsoft.Net.Compilers")
expect(dependency.version).to eq("1.0.1")
expect(dependency.requirements).to eq(
[{
requirement: "1.0.1",
file: "packages.config",
groups: ["devDependencies"],
source: nil
}]
)
Expand Down Expand Up @@ -167,7 +186,26 @@
[{
requirement: "1.0.0",
file: "dir/packages.config",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
end
end

describe "the second dependency" do
subject(:dependency) { dependencies.at(1) }

it "has the right details" do
expect(dependency).to be_a(Dependabot::Dependency)
expect(dependency.name).
to eq("Microsoft.Net.Compilers")
expect(dependency.version).to eq("1.0.1")
expect(dependency.requirements).to eq(
[{
requirement: "1.0.1",
file: "dir/packages.config",
groups: ["devDependencies"],
source: nil
}]
)
Expand Down Expand Up @@ -234,7 +272,7 @@
[{
requirement: "2.3.0",
file: "commonprops.props",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand Down Expand Up @@ -264,7 +302,7 @@
[{
requirement: "1.1.1",
file: "packages.props",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand Down Expand Up @@ -294,7 +332,7 @@
[{
requirement: "1.1.1",
file: "directory.packages.props",
groups: [],
groups: ["dependencies"],
source: nil
}]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
requirement: declaring_requirement_string,
file: "packages.config",
groups: [],
groups: ["dependencies"],
source: nil
}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
requirement: declaring_requirement_string,
file: "my.csproj",
groups: [],
groups: ["dependencies"],
source: nil
}
end
Expand Down
Loading

0 comments on commit 5a421b1

Please sign in to comment.