How to install package with npm number with a different user module name

I want to install a specific revision from a github tar file named "mymodule" and call it something like "mymoduleTemp", and then download a potentially different version that will take the real name "mymodule".

So how do I do the first? I am looking for something like:

npm install https://github.com/me/mymodule/tarball/someTag -name mymoduleTemp 

Is there any way to do this? Nice to have:

  • If mymodule already exists, it does not get clobbered when mymoduleTemp is installed (i.e. ideally, the process will not be installed as mymodule and then rename the folder)
+13
source share
5 answers

An issue was requested in the npm-github repository requesting this function.

read here: https://github.com/npm/npm/issues/2943

+8
source

Starting with npm@6.9.0 you can install the package under an arbitrary module name. npm@6.9.0 provides support for package aliases.

To set tarball under an arbitrary module name, use the custom-name@tarball-url argument, for example, set a special express tarball as my-express module:

npm i my-express@https ://github.com/expressjs/express/archive/4.16.3.tar.gz

This feature also allows you to create aliases for packages published in the npm registry:

npm i express@npm :@my-scope/express

+16
source

You can do it:

  • Get tarball and extract it
  • Change name on package.json to @me/mymoduleTemp (you can skip steps 1 and 3 by editing the tarball in place with vim mymoduleTemp.tgz )
  • Compress mymoduleTemp.tgz
  • Run npm publish mymoduleTemp.tgz (with --access public if you don't want it restricted)
  • In your main project, run npm install @me/mymoduleTemp

I would recommend publishing it as a cloud package , because if you publish it as unsealed mymoduleTemp , then no one can use that name.

If you think that even publishing limited access packages pollutes the npm registry, you can simply put the new tarball on your own private server (either on GitHub or anywhere) and install it via the URL.

+1
source

Specifically for the browser, you can add an alias to package.json

https://github.com/defunctzombie/package-browser-field-spec

eg:

 { .... "browser": { "someTag": "mymoduleTemp" } } 

It also works for a "reaction-native" with the subway . I have never tested with bundles of web packages.

+1
source

in newer versions of npm it is now possible alias module name with

 npm i <alias_name>@npm:<original_package_name> 
+1
source

Source: https://habr.com/ru/post/1486423/


All Articles