Yarn: How to change install a local package using .yarnrc files? - javascript

I was looking at this link Use different registries in yarn and npm
So let's say I want to use my own version some npm package called package instead of installing it using
yarn add package
If my folder path is C:/custom-package
I tried to put in my .yarnrc something like registry "https://package.dev/repository/npm-proxy/" "C:/custom-package/
Then run yarn add package
Still didn't work, it installs the normal package as if I'm using yarn add package
So the question is: How can I do that, what am I missing?

Related

How to insert dependencies in local package if npm package is installed globally

I have installed few npm packages globally but it does not show any dependencies in any of my package.json files. Which npm command should I use to apply dependencies in all of my package.json files?
Globally installed dependencies won't list in your local package.json file. You should still be able to use them requiring/importing into your project.
if you want to save a dependency in your package.json as well when you install it, us --save flag with npm install command.
for example
npm install --save express
It is not recommended to add a package which is installed globally to locally or vice versa.
When a package is installed globally, it is normally used as a command in the terminal. For example, create-react-app or express-generator. You might install these packages globally to use them as commands in the terminal to build React or Express app (with default scaffold).
When a package is installed locally, it means you want to use it within the application. For example, jsonwebtoken. You should install this package locally so that it can be used within the application and when somebody else clones your project they can install this package as well via npm install command.
So, the suggestion is, install the package globally if you're going to use it as a command, else install the package locally within the application. Don't mix them.

Yarn add new packages without update other packages

How do I yarn add without update other packages?
When I use yarn add react-native-charts-wrapper this command also updates my other packages.
But I don't want to update other packages.
It seems someone or you were modified your package.json's dependencies manually like: change version of package by hand or etc...
You can fix this by deleting yarn.lock and type yarn install (installs all packages on package.json)

Automatically updating dependencies in package.json

I have one question I think is pretty simple. Could you explain me why sometimes package.json is automatically updates and sometimes don't. e.g. if I installed express or gulp these plugins were added to dependencies automatically. But if I installed express-jwt or mongodb these plugins were not added
They are added to package.json when you append one of the following flags:
-S|--save|-D|--save-dev|-O|--save-optional
See https://docs.npmjs.com/cli/install for full documentation.
If we use the following command to install npm dependencies-
npm install express-jwt --save
or
npm install mongodb --save
these installed dependencies will also be added to package.json file.
When you install a package with the --save or --save-dev flag, these are persisted to the dependencies or devDependencies arrays respectively.
If no flag is added, the package is downloaded but not persisted to package.json
Edit: There's is also the more obscure --save-optional flag, but it'd say it's mostly out of scope for this particular case.

Difference between npm install --save and npm install --save-dev

Guys I know that using npm install -g we can install the node modules/packages globally, but I am not sure about the options --save and --save-dev
I have Googled it but still not clear about it. Please share your thoughts.
--save adds the third-party package to the package's dependencies. It will be installed together with the package whenever someone runs npm install yourPackage.
--save-dev adds the third-party package to the package's development dependencies. It won't be installed when someone installs your package. It's typically only installed if someone clones your source repository and runs npm install in it.
Dev dependencies, as the same suggests, are those dependencies that are only needed for developing the package. That can include test runners, compilers, packagers, etc.
Both types of dependencies are stored in the package's package.json file. --save adds to dependencies, --save-dev adds to devDependencies. From the documentation:
devDependencies
If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.
In this case, it's best to map these additional items in a devDependencies object.
These things will be installed when doing npm link or npm install from the root of a package, and can be managed like any other npm configuration param. See npm-config(7) for more on the topic.
For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepublish script to do this, and make the required package a devDependency.
Edit: As of npm 5.0.0 the installed modules are added as a dependency by default, so the --save option is no longer needed.
--save-dev is used to save the package for development purpose. Example: unit tests, minification.
--save is used to save the package required for the application to run.
--save-dev will save npm modules in development dependencies in package.json i.e it will save inside devDependencies object.
--save will save npm modules dependencies in package.json i.e it will save inside dependencies object.

What the difference between install a module with npm node console or in package.json

I'm new and I need to use node for off-line use so, I'm trying to understand how the install modules work.
It's the same if I use npm install express or included it in the package.json?
The way a package is installed will be the same whether you manually type npm install express or put it in your package.json and then do npm install. The difference comes when you try to install your Node project elsewhere.
For example, if your code was checked into GitHub and you didn't include a package.json with all of the dependencies listed, then when the project was downloaded you would have to manually re-install all of the dependencies on the command line in order for it to work. But if you had checked in a package.json with the code, then you could run npm install to install all of the dependencies at once, and not have to remember which ones were necessary.
In addition, the package.json allows you to specify an "approximate version" of a dependency to use. This way if a few packages in your project share a dependency and they all specify similar "approximate versions", only one version will be installed and it will be shared between packages. This saves some install time.
Nothing actually. But you don't want to do that again and again. So you might as well put your module dependencies in your package.json

Categories

Resources