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

SPM Module name conflicts with Contentstack struct #21

Open
TheNightmanCodeth opened this issue Aug 2, 2023 · 11 comments · May be fixed by #34
Open

SPM Module name conflicts with Contentstack struct #21

TheNightmanCodeth opened this issue Aug 2, 2023 · 11 comments · May be fixed by #34
Assignees
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed question Further information is requested

Comments

@TheNightmanCodeth
Copy link

When adding the library via SPM, the module name does not match that of the Cocoapods version and conflicts with the Contentstack struct.

This leads to issues when a type name in the library conflicts with one in the project it's added to. For example:

APIError is a common type name. In order to differentiate, we might use ContentstackSwift.APIError. In the SPM library, this is not possible because the module name is Contentstack. When differentiating via Contentstack.APIError, the compiler thinks we want to reference Contentstack(module).Contentstack(struct).APIError which does not exist.

This can be resolved simply by changing the module name in Package.swift to ContentstackSwift like so:

let package = Package(

    ...

    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "ContentstackSwift",
            targets: ["ContentstackSwift"]) // <- Here
    ],

    ...

    targets: [
        .target(
            name: "ContentstackSwift", // <- Here
            dependencies: ["ContentstackUtils"],
            path: "Sources"),
        .testTarget(
            name: "ContentstackTests",
            dependencies: ["ContentstackSwift", "DVR"], // <- Here
            path: "Tests")
    ]
)

Additionally, this allows migration to SPM without any need to refactor pre-existing code

@ishaileshmishra
Copy link
Member

Thanks for raising the issue @TheNightmanCodeth, We will look into this.

@TheNightmanCodeth
Copy link
Author

Thanks! You guys rock 🥳

@ishaileshmishra ishaileshmishra self-assigned this Oct 16, 2023
@ishaileshmishra ishaileshmishra added documentation Improvements or additions to documentation help wanted Extra attention is needed question Further information is requested labels Oct 16, 2023
@ishaileshmishra
Copy link
Member

ishaileshmishra commented Oct 19, 2023

Hi @TheNightmanCodeth , we are still checking this issue, meanwhile can you please give it a try to change the module name from Contentstack to ContentstackSwift:

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "Contentstack",
    products: [
        .library(
            name: "ContentstackSwift", // Change the module name here
            targets: ["ContentstackSwift"]) // Update the target name as well
    ],
    dependencies: [],
    targets: [
        .target(
            name: "ContentstackSwift", // Change the target name here
            dependencies: [],
            path: "Sources"
        ),
        .testTarget(
            name: "ContentstackTests",
            dependencies: ["ContentstackSwift"],
            path: "Tests"
        )
    ]
)

By changing both the module name and target name to ContentstackSwift, you can prevent conflicts with existing type names and provide a smoother transition to SPM without the need to refactor pre-existing code.

Please let us know if above does not resolve the issue.

@TheNightmanCodeth
Copy link
Author

Hi, @ishaileshmishra, yes, that is what I said. It does me no good until y'all merge the changes in on your end so we can add the SPM dependency without conflict.

@learnwithgabbar
Copy link

Hi, @ishaileshmishra, yes, that is what I said. It does me no good until y'all merge the changes in on your end so we can add the SPM dependency without conflict.

Great, @TheNightmanCodeth or could we use CS for the main struct within the Contentstack like Alamofire uses AF, Kingfisher user KF

@aj-pilot
Copy link

@ishaileshmishra Any update on this, as it is blocking us to upgrade the dependency

TheNightmanCodeth added a commit to TheNightmanCodeth/contentstack-swift that referenced this issue May 8, 2024
@TheNightmanCodeth TheNightmanCodeth linked a pull request May 8, 2024 that will close this issue
@DanAckermanPFJ
Copy link

Hi @ishaileshmishra Any updates on this issue? We are past a year on the original PR.

@abhinav-from-contentstack
Copy link
Contributor

Hi @DanAckermanPFJ, I'll check with the team and get back to you shortly.

@learnwithgabbar
Copy link

Is there any Update as I can't Access the APIError declared in the Package with ContentStack.APIError syntax

@learnwithgabbar
Copy link

@abhinav-from-contentstack are you folks planning to fix this issue?

@learnwithgabbar
Copy link

@ishaileshmishra @abhinav-from-contentstack any planned fixed for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants