Skip to content

Commit

Permalink
fix an issue with empty children dependencies (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
osrufung authored Oct 24, 2022
1 parent 962d87f commit 31f7024
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/PodExtractor/Module+Podfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ struct Podfile: Decodable {

struct ChildrenDefinition: Decodable {
let name: String
let dependencies: [Dependency]
let dependencies: [Dependency]?
let children: [ChildrenDefinition]?
var asTarget: [Module] {
let target = Module(name: name, dependencies: dependencies.compactMap(\.name))
let target = Module(name: name, dependencies: dependencies?.compactMap(\.name) ?? [])
let children = children ?? []
return children.reduce([target]) { $0 + $1.asTarget }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/jungle/Commands/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Jungle: AsyncParsableCommand {
static var configuration = CommandConfiguration(
commandName: "jungle",
abstract: "Displays dependency statistics",
version: "1.0.0",
version: "1.0.1",
subcommands: [HistoryCommand.self, CompareCommand.self, GraphCommand.self],
defaultSubcommand: CompareCommand.self
)
Expand Down
2 changes: 0 additions & 2 deletions Sources/jungle/Models/Outputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ struct CompareStatsOutput: Codable {
let name: String
let moduleCount: Int
let complexity: Int
let modules: Int

init(label: String, graph: Graph) {
name = label
moduleCount = graph.nodes.count
complexity = graph.multiGraphComplexity
modules = graph.nodes.count
}
}
98 changes: 97 additions & 1 deletion Tests/PodExtractorTests/PodExtractorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final class PodExtractorTests: XCTestCase {
XCTAssertEqual(modules.count, 2)
}

func testTargetModulesFromPodfileLock() throws {
func testTargetModulesFromPodfile() throws {

// Example Podfile from https://github.com/artsy/eidolon
let podfile = """
Expand Down Expand Up @@ -242,4 +242,100 @@ final class PodExtractorTests: XCTestCase {
"RxBlocking"]
)
}

func testTargetModulesFromPodfileNoDependenciesInChildren() throws {

let podfile = """
{
"target_definitions": [
{
"name": "Pods",
"abstract": true,
"platform": {
"ios": "16.0"
},
"uses_frameworks": {
"linkage": "dynamic",
"packaging": "framework"
},
"inhibit_warnings": {
"all": true
},
"children": [
{
"name": "FromCocoaToSPM",
"inhibit_warnings": {
"for_pods": [
"Appboy-iOS-SDK",
"Alamofire",
"Amplitude"
]
},
"dependencies": [
{
"Appboy-iOS-SDK": [
"4.5.1"
]
},
{
"Alamofire": [
"5.6.1"
]
},
{
"Amplitude": [
"8.11.0"
]
},
{
"AppFeature": [
{
"path": "InternalDependencies/AppFeature"
}
]
},
{
"ProductsFeature": [
{
"path": "InternalDependencies/ProductsFeature"
}
]
},
{
"SettingsFeature": [
{
"path": "InternalDependencies/SettingsFeature"
}
]
},
{
"UIComponents": [
{
"path": "InternalDependencies/UIComponents"
}
]
}
],
"children": [
{
"name": "FromCocoaToSPMTests",
"abstract": false,
"inheritance": "search_paths"
},
{
"name": "FromCocoaToSPMUITests"
}
]
}
]
}
]
}
"""

let targets = try modulesFromJSONPodfile(podfile)

XCTAssertEqual(targets.count, 3)

}
}

0 comments on commit 31f7024

Please sign in to comment.