Search Unity

Scoped registry in package.json not working

Discussion in 'Package Manager' started by JonInception, Apr 15, 2020.

  1. JonInception

    JonInception

    Joined:
    Feb 25, 2018
    Posts:
    7
    Hi,
    I'm developing an open source (openUPM) package, and would like users to be able to install my package via openupm cli or through git directly.

    My package has a dependency on another openupm package, and I've configured the package.json to have a scoped registry for it.

    However, when I try to include my package as a dependency in a 3rd, test project- the package manager cannot resolve the scoped registry, unless I manually add it into the test project's manifest.json

    This means that users will not be able to add my projects with custom registries via git url, unless they add all the dependencies' scoped registries!

    Is this behaviour by design?

    Attaching:
    * package.json of my package,
    * manifest.json (that won't resolve) of the test project.

    Unity version: 2019.2.21f1
     

    Attached Files:

    ddalacu likes this.
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Thanks for reporting the issue. For OpenUPM specific question, you can create an issue on the GitHub. https://github.com/openupm/openupm/issues

    Your issue is that the package is not installed via openupm-cli, but installed via Git URL instead. UPM can not find your custom dependencies, because it doesn't have any knowledge to locate it.

    To fix it
    1. Revert your change of manitfest.json, by removing the dependency of com.jonlevin.worldmap, and remove the "lock" entry entirely.
    2. Install openupm-cli https://github.com/openupm/openupm-cli#installation, which will resolve custom dependencies of scoped registry.
    3. Install via
      openupm add com.jonlevin.worldmap

    It will generate the mantifest.json like below,

    Code (CSharp):
    1. {
    2.   "dependencies": {
    3.     "com.unity.addressables": "1.7.5",
    4.     ...
    5.   "scopedRegistries": [
    6.     {
    7.       "name": "package.openupm.com",
    8.       "url": "https://package.openupm.com",
    9.       "scopes": [
    10.         "com.dbrizov.naughtyattributes",
    11.         "com.jonlevin.worldmap",
    12.         "com.openupm"
    13.       ]
    14.     }
    15.   ]
    Notice that "com.dbrizov.naughtyattributes" has been added to scoped registries.
     
  3. Deleted User

    Deleted User

    Guest

    I
    Hey, thanks for the quick response.

    My issue is not with openupm, hence why I didn't report it in github.
    It is also not about git urls
    To confirm I've recreated this with a project that uses a custom registry (not openupm), and only proper versions (no git urls)

    My point is:
    If a registry is scoped within the package.json, you shouldn't have to scope it again in the manifest.json.

    I'm not sure if this is by design or a bug, but regardless I think it would be very powerful to be able to scope a registry only in the package.json, so it's transparent to the consumer project.
     
    Zamaroht likes this.
  4. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Okay, I see your point. Considering a scoped package can depends on both custom packages (from the same scoped registry perhaps) and official packages from the official registry. It will be a fallback logic, try the current scoped registry first, then the official one. That's what openupm-cli does when resolving package dependencies and adding to the scoped list.

    Well, it's convenience but non-deterministic.
     
  5. Deleted User

    Deleted User

    Guest

    Also true, but the use-case I had in mind is if you provide a non-scoped package (or git url), which does depend on scoped registries.
    There's no real reason that the top-level consumer should "know" about it's dependencies registries

    You mean it's non-deterministic because you could have a non scoped package in package.json, and later scope it in a project's manifest?

    If so- this is the way it works right now as well - you declare dependency in package.json, and only later scope it in manifest, so a package can't know what registry will provide its dependencies at runtime.

    If you wanted the package to deterministically control its registries, you'd have to use isolated "scoped-registry-scopes" per package, so that manifest (top-level) scoped registries cannot influence their dependencies' registries

    Perhaps better that the top-level project controls scopes, so it can override the registries to provide custom versions of packages, or just faster cdn if needed.

    But it could still fall back on package.json scoped registries. Only argument I can think against it is security. But using a 3rd party package already implies trust, so why not trust it's scoped registries?
     
    ImpossibleRobert likes this.
  6. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Sorry that I'm missing something here. After revisit the files you uploaded I noticed the "scopedRegistry" was added to the package.json, which is not supported AFAIK. The "scopedRegistry" is only available for mantifest.json.

    It can be an interesting feature request to let the package.json specify the scoped dependencies.
     
  7. Pixel2015

    Pixel2015

    Joined:
    Mar 10, 2016
    Posts:
    35
    Guys I am actually trying to solve this problem as well. We have for example internal company scoped registry where some of the packages are dependent on Google registries not just Unity ones. Is there any way to specify this in the package so Unity Package Manager automatically adds these scoped registries to project automatically?

    This seems like such a critical feature once more people assets and packages start using Package Manager for distribution I am kind of surprised it is not already supported.
     
    Zamaroht likes this.
  8. JonInception

    JonInception

    Joined:
    Feb 25, 2018
    Posts:
    7
    Afaik Unity still doesn't support it :(
    We also have custom + GooglePlay registried scoped, and a dependency tree that makes this a bit annoying.
    Our workaround was to add All scoped registries to a Github Template repo for packages, which has scopedRegistries the manifest.

    (If you open alot of package repos having a Template + Package Initialization script is a lifesaver anyway, to save configing the package/manifest/Asmdef/basic project settings each time).

    But if someone is reading this at Unity - please add scoped packageJsons + '^2.0.0' version syntax, they're sorely missed and could really help enterprise & community usage :)
     
    Zamaroht, ddalacu and Favo-Yang like this.
  9. Zamaroht

    Zamaroht

    Joined:
    Nov 4, 2013
    Posts:
    23
    Hello! Just a heads up that I would find this really useful too.
     
  10. mrekuc

    mrekuc

    Joined:
    Apr 17, 2009
    Posts:
    116
    I agree. We also have some internal packages to make things easier. Some reference packages on OpenUPM. We should be able to used scoped registries within our package.json instead of having to manually update the manifest file with them. Would be so uch easier to just let someone install the package and have those dependencies load with it instead of doing all of it prior to adding our custom package.
     
    ImpossibleRobert likes this.
  11. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    527
    I cannot understand why this is not supported. I am providing an SDK to my players and inside the SDK I want to include the MRTK scoped registry. This is not possible as I understand now and it is a killer for that scenario. I cannot tell the users to include this manually in their projects, in EVERY project. Why not simply inherit this from the package? Please make it happen, Unity & @Favo-Yang
     
  12. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Personally, I would like to see self-located package dependency. To make it easier to install a package depends on another scoped registry. But I have little impaction on Pacman's roadmap. In fact, it's a sensitive product, which try to balance user convenience and their biz value/damage. So you'd better reference a Unity staff to this thread to get their input.

    One workaround is the package installer from needle-tools, which generates a legacy .unitypackage to help you import a scoped registry. But it doesn't support setting up multiple registries at the moment. So you have to provide .unitypackage files, one for MRTK, one for your packages, and describe that in the SDK setup guideline. Take your risk to use the tools, it's a smart tool but perhaps eat the pie of Unity Package Guideline.
     
  13. tobermanar

    tobermanar

    Joined:
    Aug 17, 2016
    Posts:
    9
    I would be interested in such feature as well !

    Does anybody where to ask Unity for this feature ? Is it done already ?
     
  14. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
    This is an absolute necessity. Packages should be able to install their dependencies without user intervention. That is the whole point.
     
  15. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    Add it to the basket of broken design issues of Unity.
     
  16. magomezca4

    magomezca4

    Joined:
    Nov 10, 2022
    Posts:
    4
    Please add this
     
  17. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    527
  18. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    340
  19. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    527
    It covers the use case of local usage for your own sake. The asset indexes existing usages of packages in your projects and also grabs the entered registries along the way so when adding it to a new project it can immediately add it to the manifest as well.
     
  20. JosephStar318

    JosephStar318

    Joined:
    Jun 20, 2022
    Posts:
    20
    I would really want this feature to be official. package.json needs scoped registry support!
     
  21. JLifeDev

    JLifeDev

    Joined:
    Feb 8, 2016
    Posts:
    12
    I can't understand why unity not add this feature.
     
  22. JLifeDev

    JLifeDev

    Joined:
    Feb 8, 2016
    Posts:
    12
    starikcetin and Favo-Yang like this.
  23. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    527
    In case anybody has it or wants to get it: My tool "Asset Inventory" does also do this (add scoped registry) automatically in case you add a custom package in one project which you have already used in another project. Just a simple UI click :) And of course it actually does a lot of different things, scoped registries were just a necessary by-product.