Hi,
Thanks to forum user @JakHussain , there is now a known method to use GitHub Packages Registry with Unity Package Manager. See the original post where @JakHussain shared his clever finding.
WARNING: Using GitHub Packages registries with Unity Package Manager comes with a couple of limitations (Goto the end of the post for the list). Please be aware that we are posting this only to share community knowledge. Unity doesn’t officially support GitHub Packages Registry. Use it at your own risk.
There are a couple of steps needed to make it work.
1 - You need to configure the publishConfig setting as described in GitHub Packages Registry documentation in a special way. You need to suffix the pakcage scope:
"publishConfig": { "registry": "https://npm.pkg.github.com/@USER" },
Where USER is the Github organization or user (i.e.the scope). Basically, we are cheating on how NPM works and inject the scope in the registry URL instead of prefixing the package name. This is one half of the trick. Unity Package Manager doesn’t accept the @ and / characters in package names. By moving the scope reference in the registry URL we don’t need these characters in the package name anymore!
Add the publisConfig configuration in your package manifest (package.json)
2 - Set the name of your package without an NPM scope
This is the other part of the magic. As stated in step #1, make sure you don’t prefix you package name with an NPM scope ( @ )
Example:
"name": "com.my-company.my-package",
Not:
"name": "@USER/com.my-company.my-package",
WARNING: If you have previously published a package with an NPM scope in the name, it won’t work. Your package should not have an MPM scope for all existing versions. It won’t work otherwise.
3 - Publish your package
For that step, you can refer to GitHub documentation.
4- Configure the scope registry in your Unity project manifest
"scopedRegistries": [
{
"name": "Company Packages",
"url": "https://npm.pkg.github.com/@USER",
"scopes": [
"com.my-company"
]
}
],
The URL must match the one configured in your publishConfig above in step #1.
5 - Setup Npm Auth configuration
WARNING: GitHub Packages registry always requires authentication. For private and public packages.
For this one, I’ll refer you to another post I’ve made explaining how .
6 - Add your package in your project manifest
GitHub Package Registry packages won’t show up in the Package Manager UI All section. You have to install the package manually in your project manifest.
Known limitations
- The main limitation is discoverability. Even if your Github Packages registry-based scoped registry is correctly configured, packages won’t show up in the Package Manager UI’s All section. GitHub doesn’t support any of the NPM search API endpoints (/-/all or /-/v1/search). You will have to resort to GitHub UI to search packages and manually add them to your project manifest.
- Even if the GitHub Registry package is public, your users will need to provide authentication.
As you can see, using GitHub Packages Registry with Unity Package Manager is not trivial. But, if you really need it, you can make it work!
Hope this post will be useful to some of you. Again, thank you to @JakHussain for discovering how it can be done!
Regards,
Pascal and the Unity Package Manager team.
