Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing error on no dependencies targets #8

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

}
}