Yarn add new packages without update other packages - javascript

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)

Related

yarn.lock file is not updating after I update the version of a dependency in package.json and run yarn install or just yarn

In the repository of a project, I already have package.json and yarn.lock files. I'm updating the version of a particular package from version 2.0.14 to version 2.0.16.
When I do yarn install or just yarn, I can see the changes related to the updated package but the yarn.lock file is not updating.
Is there is any command to generate the updated yarn.lock file?
Try using yarn install --force as this will re-download all packages (in their locked versions unless too old) and refresh the lock file if necessary. yarn install should already do this, but in case it doesn't, you can force it to.

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

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?

How do I update a single dependency in package-lock.json, without any side effects?

I am looking to update the following NPM (v5) dependency in my application from version 1.0.0 to 1.0.1 without any change to my package.json file.
"dependencies": {
"package": "~1.0.0"
},
My current package-lock.json file references the dependency as version 1.0.0, so as expected, running npm install installs version 1.0.0 of the package.
The issue lies when running either npm install package#1.0.1 or npm update package where both commands seem to change how the package version reference in package.json
Is there a single command I can run to achieve a minor version update to only the package-lock.json file?
Thanks in advance!
Run npm update <package>.
This will update it to the latest version that satisfies the requirements specified in your package.json and reflect the update in the package-lock.json.
package-lock.json is generated by npm and it's difficult to modify without npm since it contains package hashes.
If you're only referencing modules using the patch version (~1.0.0) I think it's safe to do the following:
Backup package.json and delete it
Run npm update package. This will use package-lock.json as a reference and will also update package-lock.json
Restore package.json
Running npm update package now will not update package.json since package-lock.json is the newer version
If you're looking for a one line command:
mv package.json package.json.tmp && npm update package && mv package.json.tmp package.json
Again, this is safe to do only when dealing with patch versions (~1.0.0). If you specify minor (^1.0.0) or major (1.0.0) versions you may want to update package.json directly.

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.

How to install multiple gulp packages at once using node?

I just switched to gulp task runner to automate my workflow, but there is this problem whenever i want to start a new project i have to install all packages required in gulpfile.js using the following command:
npm install --save-dev {package name}
Imagine there are 20 of them, it's a bit boring. How can simplify this?
You can add multiple package names to npm install:
npm install --save-dev package1 package2 package3
npm will install and save the specified packages in your package.json.
Personally I use mostly the same gulp plugins for all of my projects. I copy the devDependencies bit from the package.json of one of my previous projects into my newly created package.json, then I run npm i which installs all dependencies listed in package.json. It's a huge timesaver, especially since I usually copy my gulpfile.js as well.
Note: don't forget to run npm outdated if it's been a while since your previous project started, to check if any of the dependencies have been updated in the meantime.
You can also use brace expansion for installing many similarly named packages:
npm i -D babel-{core,preset-es2015,preset-react}

Categories

Resources