@@ -166,7 +166,7 @@ struct PackageToJSPlugin: CommandPlugin {
166
166
}
167
167
}
168
168
169
- static let JAVASCRIPTKIT_PACKAGE_ID : Package . ID = " javascriptkit "
169
+ static let JAVASCRIPTKIT_PRODUCT_ID : Product . ID = " JavaScriptKit "
170
170
171
171
func performBuildCommand( context: PluginContext , arguments: [ String ] ) throws {
172
172
if arguments. contains ( where: { [ " -h " , " --help " ] . contains ( $0) } ) {
@@ -396,7 +396,7 @@ struct PackageToJSPlugin: CommandPlugin {
396
396
guard
397
397
let selfPackage = findPackageInDependencies (
398
398
package : package ,
399
- id : Self . JAVASCRIPTKIT_PACKAGE_ID
399
+ including : Self . JAVASCRIPTKIT_PRODUCT_ID
400
400
)
401
401
else {
402
402
throw PackageToJSError ( " Failed to find JavaScriptKit in dependencies!? " )
@@ -649,12 +649,24 @@ extension PackageManager.BuildResult {
649
649
}
650
650
}
651
651
652
- private func findPackageInDependencies( package : Package , id: Package . ID ) -> Package ? {
652
+ /// Find the package that contains the product with the given name
653
+ /// - Parameters:
654
+ /// - package: The package to search in
655
+ /// - productName: The name of the product to find
656
+ /// - Returns: The package that contains the product with the given name
657
+ /// - Note: Why not use `Package.ID`? `Package.ID` is not always equal to the package repository name
658
+ /// as it's derived from the directory name when the package is dependent on another package as a
659
+ // local package.
660
+ private func findPackageInDependencies( package : Package , including productName: String ) -> Package ? {
653
661
var visited : Set < Package . ID > = [ ]
654
662
func visit( package : Package ) -> Package ? {
655
663
if visited. contains ( package . id) { return nil }
656
664
visited. insert ( package . id)
657
- if package . id == id { return package }
665
+ for product in package . products {
666
+ if product. name == productName {
667
+ return package
668
+ }
669
+ }
658
670
for dependency in package . dependencies {
659
671
if let found = visit ( package : dependency. package ) {
660
672
return found
0 commit comments