Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

npmjs as a scoped registry

Discussion in 'Package Manager' started by starikcetin, Sep 19, 2019.

  1. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    245
    Is it possible to use https://www.npmjs.com/ as a scoped registry? If so, where can I find some information on the setup required?
     
  2. samuelb_unity

    samuelb_unity

    Unity Technologies

    Joined:
    Nov 13, 2017
    Posts:
    53
    starikcetin likes this.
  3. samuelb_unity

    samuelb_unity

    Unity Technologies

    Joined:
    Nov 13, 2017
    Posts:
    53
    Hi @starikcetin,

    I reached out to my team about whether we have a stance on using npmjs to host Unity Package Manager (UPM) packages. While it is technically feasible (I can add a scoped registry with
    "url": "http://registry.npmjs.com/"
    to my Unity project manifest and add packages to my project) you might find this goes against npmjs's policies on acceptable use:

    https://www.npmjs.com/policies/open-source-terms#acceptable-use

    For example
    Currently a UPM package is functionally compatible with the npm command-line client but it may not always be the case as we continue to add our own features. And the fact that a UPM package does not work in a regular Javascript project may go against npmjs's policy of what a "package" can be. So for now our advice would be: do so at your own risk!
     
    Last edited: Sep 20, 2019
    starikcetin likes this.
  4. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    245
    I appreciate you taking your time to investigate this. Thank you very much.
     
  5. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    245
    I sent a support ticket to npmjs guys asking about the acceptable use policy regarding UPM, I will let you guys know about their response.
     
    samuelb_unity likes this.
  6. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    366
    Also note that npm's scoping and Unity's scoping are fundamentally incompatible. npm uses the «@scope/name» format while unity uses the reverse DNS notation, e.g. «com.unity.render-pipelines.high-definition».
    • Unity does not allow the @ or / characters in package names, you therefore cannot use npm scopes in Unity
    • npmjs.com doesn't allow dots in package names, you therefore cannot use Unity scopes on npmjs.com
    • npmjs.com also requires scopes for any non-public package
    This is unfortunately also the reason why the GitHub Package Registry is incompatible with Unity.
     
  7. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    245
    I got a response:
    It seems it is not against npmjs policies to use it for UPM.
     
    Last edited: Oct 1, 2019
    maximeb_unity and Favo-Yang like this.
  8. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    143
    Hi @Adrian,

    We haven't seen that package names cannot contain dots on npm registries. Perhaps this is a policy specific to the npmjs.org registry, but the rule that they describe in the documentation is that a package cannot *start* with a dot, which is something we also enforce, therefore it should be possible to publish to npmjs.org a Unity package. However, it is true that these packages cannot be made private on that registry because npm scopes are needed for that, which Unity doesn't support - and, quite accurately, this is the reason why GitHub Package Registry cannot be used with Unity packages at this time.
     
    starikcetin likes this.
  9. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    298
    I had published an upm package on npm, and it can be consumed by the upm system with no issue.

    Code (JavaScript):
    1. "scopedRegistries": [                    
    2.   {                                      
    3.     "name": "npmjs",                      
    4.     "url": "https://registry.npmjs.org/",
    5.     "scopes": [                          
    6.       "com.littlebigfun"                  
    7.     ]                                    
    8.   }                                      
    9. ],                                          
    @maximeb_unity may I ask for what reason Unity is not playing well with @Scope semantic? I understand the reverse dns notation is already a decision, but it doesn't seems conflict with "@" keyword. In npm, @Username/pkg-xyz and pkg-xyz are two different packages and have no fallback logic to each other.

    Code (JavaScript):
    1. com.littlebigfun.addressable-import
    2. @favoyang/com.littlebigfun.addressable-import
    For scoped registry, we could add "@favoyang/com.littlebigfun" as scopes to tell the system where to locate the package. Or even better add "@favoyang" as scopes could also work.

    Code (JavaScript):
    1. "scopedRegistries": [                      
    2.   {                                        
    3.     "name": "npmjs",                      
    4.     "url": "https://registry.github.com/favoyang",  
    5.     "scopes": [                            
    6.       "@favoyang/com.littlebigfun"                  
    7.     ]                                      
    8.   }                                        
    9. ],    
     
    starikcetin likes this.
  10. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    366
    Oh, good to hear it actually works. I was going by the npmjs.com documentation on creating a package.json file, which states regarding the name: