How to upgrade package to latest version using yarn? - javascript

I would like to upgrade eslint package to latest version.
yarn upgrade eslint --latest do nothing.
How can I update to latest version via yarn?

Recipe of my recent technique.
Some time ago command below started failing to work
yarn upgrade somePackage -- latest
It's started to has side effects like updating other packages as babel, typescript etc. I don't see any comments about this behavior in official documentation. Going to codebase of yarn is a bit overhead in order to solve so "basic" task
Currently in order to update single package i use
yarn add somePackage
In order to update to latest i use
yarn add somePackage#latest
So, in your case i recommend you to try
yarn add eslint#latest
Please, let me know if it works or not )

Related

What happens when there are multiple versions available in organisation npm

I am fairly new to versioning a library, I wanted to get a clarity on my concern and please explain how does npm work.
I am trying to build a library and publish it to my organization npm registry. Now I have an alpha release which is already available in nexus and I did an npm install and the library works fine.
Now I when I create a stable release and make the library available for my organisation to use, when this happens the version tag will be updated to v1.0.0 and when I do an npm install the latest stable version will be available.
Post this, if I create further more alpha builds the version now has an alpha build tag appended to the version. Now when I do an npm install in a fresh project setup which version will I get:
stable version
new alpha version
I am a new to this, if anyone can explain how npm install will work and what version will I get that will be super helpful.
Thanks
What npm i will do for you, depends on what you stated in package.json.
{
"dependencies":{
"foo":"1.0.0", //match version exactly
"baz":">1.0.2", //must be greater than version
"elf":"~1.2.3", //everything from 1.2.3 to <1.3.0
"thr":"^1.2.3", //from 1.2.3 to <2.0.0
}
}
More details here
If you want to know the exact version of the package installed after npm i you could look it up in package-lock.json

Can I update Electron version in a project based on an Electron boilerplate?

Problem:
I've created a project based on this Electron-Vue boilerplate:
https://github.com/SimulatedGREG/electron-vue
The problem is, it's not really being maintained, it uses an outdated version of Electron (which also means it uses an outdated version of node.js)
Question:
Can I update the Electron version to the latest or it's going to break something?
If yes, how do I do it? do I just run upgrade commands for all related to Electron dependencies?:
yarn upgrade electron --latest
yarn upgrade electron-debug --latest
... etc
?

How to install latest STABLE version of a Javascript package via a package manager?

How to install latest stable version of a Javascript package via a package manager?
(no alphas, betas, etc.)
I tried NPM and did not find a solution. This question is similar.
I tried Bower and find nothing. Here is a question with no answer here.
Please help. Which package manager should I choose? Maybe there are another options around?
PS
For example: knockout.js, npm givers beta for latest. I don't want beta! I also would like to set the same limitation for dependencies - pull only stable versions.
Installing a package without specifying a version will always install the latest version published to npm, including pre-releases (alpha, beta etc.):
npm install knockout
However, if you specify the version range, even only as a wildcard *, pre-release versions are explicitly excluded:
npm install knockout#*
See the npm docs for more info. Also, you can test this in npm's semver calculator.

How does yarn work when it encounters ^ (caret)?

How does yarn work when it encounter a ^ (caret) in package.json dependencies?
Let's say I have react: ^16.0.0 and when I yarn install, it will create a lock on that version (16.0.0).
Now sometime later when react 16.1.0 is released, and I yarn install again with the lock file, will yarn upgrade it to that version or follow what is in the lock file which is 16.0.0?
Thanks.
yarn install will install the exact version in the lockfile. That's the great benefit of a lockfile, everyone working on your project gets the exact same version of the package regardless of when the do yarn install. (e.g. I do yarn install today, when 16.0.0 is the current version, but you do yarn install tomorrow when 16.1.0 is the current version. We'll still both get 16.0.0 because that's what our lockfile says we should get. Our development environments are exactly the same, which is what we want. Likewise if we deploy in 2 weeks when 16.2.0 is the current version, 16.0.0 will get deployed; thus our dev and prod environments are exactly the same, too)
If 16.1.0 is released and you want to update your project to use it, use yarn upgrade. Note that you can upgrade all of your packages, or just one specific package, as well as update to the latest version of a package or a specific version of a package. https://yarnpkg.com/lang/en/docs/cli/upgrade/
Version Control Your package.json and yarn.lock
By adding these two files to version control, you'll easily be able to revert your project to a specific point in time in regards to your packages.
The selected answer is wrong.
caret means following
^3.1.4 will allow a version range from >=3.1.4 <4.0.0

How to manage multiple versions of the same NPM dependency?

Situation
I've written a bunch of D3.js charts using the latest version of D3 (4.9.1).
However I also need to include the occasional C3.js chart in my app, problem is- C3 requires D3 v3.5.0.
What I've considered so far
Forking C3 to update it to the latest version of D3 (it's not really feasible though)
Using a different package manager, such as Yarn
Just forgetting about C3.... (don't want to do this, as it will involve a lot of re-work!)
Specifying a URL of an older version in the bower.json. However, I still was not able to reference to just that version for C3, and the latest for everything else.
"d3": "^4.9.1",
"d3-3.5.0": "https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.0/d3.min.js"
Question
Is it possible to manage multiple versions of the same dependency, cleanly?
And if not, what would be a sensible work-around?
TLDR
Aliased versions of a dependency can be created with both NPM or Yarn using:
npm install <package_name_alias>#npm:<package_name>
Intro
Having multiple versions of the same dependency is really not ideal if it can be helped.
But if, for example you're migrating to the latest version of a given package, while continuing to support legacy features in the interim, then it may be necessary.
Ensure you're using a recent version of NPM (at least v6.9.0 when support for this was added).
Install
So, to for example install both Vue 2, and the latest Vue 3 with NPN package aliases, we would do:
npm i vue
npm i vue-legacy#npm:vue#2.6.14
Or, with Yarn:
yarn add vue
yarn add vue-legacy#npm:vue#2.6.14
Import
Then, when it comes time to use the dependency,
import Vue from 'vue'; // Will use the latest version
import Vue from 'vue-legacy'; // Will use V 2.6.14
Package.json
In the package.json, this will look like:
"dependencies": {
"vue": "^3.2.33",
"vue-legacy": "npm:vue#^2.6.14"
}
You can also add this into your package.json manually, remove the lock file, and run npm install / yarn to fetch
Alternate Sources
You can also install packages directly from GitHub using this method. Useful to get a specific version, even if not yet published to NPM, or if you wish to use your own fork of the project.
npm install package-name#github:username/repository

Categories

Resources