marinofelipe / swift-package-info

Swift CLI tool that provides information about a Swift Package
MIT License
75 stars 7 forks source link

Fix and add tests to dependencies provider #9

Closed marinofelipe closed 3 years ago

marinofelipe commented 3 years ago

The dependencies provider report is not always accurate. There are cases where it reports that there are no third-party dependencies, when there actually are.

Example:

swift-package-info --for https://github.com/pointfreeco/swift-composable-architecture --product ComposableArchitecture

Results in:

+-------------------------------------------------------------------------------------------------+
|                                       Swift Package Info                                        |
|                                                                                                 |
|                                 ComposableArchitecture, 0.14.0                                  |
+--------------+----------------------------------------------------------------------------------+
| Provider     | Results                                                                          |
+--------------+----------------------------------------------------------------------------------+
| Binary Size  | Binary size increases by 442 KB                                                  |
| Platforms    | ios from v. 13.0 | macos from v. 10.15 | tvos from v. 13.0 | watchos from v. 6.0 |
| Dependencies | No third-party dependencies :)                                                   |
+--------------+----------------------------------------------------------------------------------+
> Total of 3 providers used.

When Package.swift contains third-party dependencies for ComposableArchitecture product.

marinofelipe commented 3 years ago

Partially fixed on #12.

Won't fix cases where the a target product dependency is declared by name and doesn't match the package dependency name. That's because in that case only the product name is part of the JSON, which makes it impossible to relate to a package dependency.

Example: swift-composable-architecture's Package.swift dumped JSON has the following content:

{
  "cLanguageStandard" : null,
  "cxxLanguageStandard" : null,
  "dependencies" : [
    {
      "name" : "combine-schedulers",
      "requirement" : {
        "range" : [
          {
            "lowerBound" : "0.1.0",
            "upperBound" : "1.0.0"
          }
        ]
      },
      "url" : "https:\/\/github.com\/pointfreeco\/combine-schedulers"
    },
    {
      "name" : "swift-case-paths",
      "requirement" : {
        "range" : [
          {
            "lowerBound" : "0.1.1",
            "upperBound" : "1.0.0"
          }
        ]
      },
      "url" : "https:\/\/github.com\/pointfreeco\/swift-case-paths"
    }
  ],
  "name" : "swift-composable-architecture",
  "pkgConfig" : null,
  "platforms" : [
    {
      "options" : [

      ],
      "platformName" : "ios",
      "version" : "13.0"
    },
    {
      "options" : [

      ],
      "platformName" : "macos",
      "version" : "10.15"
    },
    {
      "options" : [

      ],
      "platformName" : "tvos",
      "version" : "13.0"
    },
    {
      "options" : [

      ],
      "platformName" : "watchos",
      "version" : "6.0"
    }
  ],
  "products" : [
    {
      "name" : "ComposableArchitecture",
      "targets" : [
        "ComposableArchitecture"
      ],
      "type" : {
        "library" : [
          "automatic"
        ]
      }
    }
  ],
  "providers" : null,
  "swiftLanguageVersions" : null,
  "targets" : [
    {
      "dependencies" : [
        {
          "byName" : [
            "CasePaths",
            null
          ]
        },
        {
          "byName" : [
            "CombineSchedulers",
            null
          ]
        }
      ],
      "exclude" : [

      ],
      "name" : "ComposableArchitecture",
      "resources" : [

      ],
      "settings" : [

      ],
      "type" : "regular"
    },
    {
      "dependencies" : [
        {
          "byName" : [
            "CombineSchedulers",
            null
          ]
        },
        {
          "byName" : [
            "ComposableArchitecture",
            null
          ]
        }
      ],
      "exclude" : [

      ],
      "name" : "ComposableArchitectureTests",
      "resources" : [

      ],
      "settings" : [

      ],
      "type" : "test"
    }
  ],
  "toolsVersion" : {
    "_version" : "5.1.0"
  }
}

Where ComposableArchitecture target has two external dependencies by name, CombineSchedulers and CasePaths, and these dependencies doesn't' match/contain their package values on dependencies, respectively "combine-schedulers" and "swift-case-paths".

All other cases should be covered.