Why npm has newer version of packages than bower - npm

I am using ng-prettyjson in my project. For dependencies management I am using bower.
After setting dependency to the ng-prettyjson to the next one "ng-prettyjson": "~0.1.6", I am receiving information
> bower not-cached git://github.com/darul75/ng-prettyjson.git#~0.1.6
> bower resolve git://github.com/darul75/ng-prettyjson.git#~0.1.6
> bower ENORESTARGET No tag found that was able to satisfy ~0.1.6
>
> Additional error details: Available versions: 0.1.3, 0.1.1
If you check on ng-prettyjson github page it is true - only 2 releases, but if you take a look into ng-prettyjson npm repository there is 0.1.6. as the latest version. What is more if you try to install this component with npm you will install 0.1.6 version.
Is there any way to instruct bower to use as well npm repository for searching dependencies? Does it make sense to do such a thing?

You cannot instruct bower to do this. This is because Bower will need additional information about the bower component (like dependencies, version, etc.). This information is needed to resolve the dependencies in your bower-components folder.
Most dependencies have build automation to update their bower and npm repositories, so I think you will not always get this problem. If you really need the most recent version of prettyjson, you could use npm for this specific dependency, or ask the developer to update it's bower repository.

I have just released a new version, thank you for warning me about it, you can download version here or with bower.
0.1.6 release

Related

Do published packages take priority over workspaces when running npm install?

I have a monorepo project and I'm migrating to npm#7. Before npm workspaces, I had to publish packages to a private feed and then consume them in my app (I didn't bother with npm link shenanigans). Not ideal, but I made do.
Then npm introduced workspaces, and now I'm trying to migrate. While resolving peer dependency conflicts, I noticed that when I made changes to any package.json files, npm install would return the same errors unless I updated package versions to something that hadn't been published yet. I wasn't expecting this kind of behavior.
So how does npm determine where to search for a package first? Does npm install download packages from the registry before looking at workspaces? Is this intentional, and if so, why?

npm install not updating package to the latest dist-tag

I am publishing artifact to npm repository with a custom tag 'dev-latest'. After executing npm install in a project where I have this dependency defined, the latest version is not updated.
After new artifact is published I see that dev-latest points to the latest version:
npm view #kosmos/equote-lib dist-tags
{ 'dev-latest': '1.0.0-dev20190125.1',
latest: '1.0.0-rel20190122.0',
'rel-latest': '1.0.0-rel20190123.0' }
Locally i have installed previous version. In my package.json my dependency is defined:
"#kosmos/equote-lib": "dev-latest",
after executing npm install to update whole project my package is not updated to the latest version.
When I do npm install #kosmos/equote-lib#dev-latest it will update it but also change my package.json entry to the specific package version.
Other solution is to remove node_modules and the I will get latest version as well.
I would expect that using tag will remove the need of specifying the version in package.json Is there a way to implement the desired behavior ?
I think I found the good answer here: https://stackoverflow.com/a/19824154/1347496
Basically in case you have already installed the modules locally you should use npm update to update one/all dependencies. In my case while using tags I do
npm update --no-save
to not to overwrite my package.json

How do I see ALL the versions of a package on NPM?

I've been using bower info package and npm view package to see which package manager has more versions of numerous packages and have found that bower goes much farther back to older versions of the packages. Do old verions simply 'expire' on npm and cannot be installed through npm after a period of type? Or is there a way for me to see older versions?

Update npm package with fixed dependency from command line

I have an npm package with a fixed version that has an update.
Example package.json extract:
devDependencies: {
"someFixedVersionPackage": "1.0.0", //1.1.0 is latest
"anotherFixedVersionPackage": "2.3.2", //2.3.4 is latest
}
Does an npm command exist which installs the latest version of that package and updates the package.json, preferably all packages at once?
To be clear, I want the package.json snippet above to be updated to this, in addition to the packages themselves being updated:
devDependencies: {
"someFixedVersionPackage": "1.1.0", //latest
"anotherFixedVersionPackage": "2.3.4", //latest
}
Thank you.
Why doesn't npm update work here?
As per the documentation on npm update:
This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.
It will also install missing packages. As with all commands that install packages, the --dev flag will cause devDependencies to be processed as well.
Since your packages are defined with a fixed version, the update sub-command will not update those to respect semantic versioning. Therefore, it will only automatically update your packages if you specify a greater version range for each package. Note that it is actually typical in an npm project to specify a loose range version; one that is meant to avoid breaking changes but still leaves room for improvements and fixes.
Still, why shouldn't I fix dependency versions in my package.json?
But they are fixed because I wanted them so. After testing newer versions, I want to update them via command line as were created.
Having a list of dependencies with a fixed version does not mean that the dependencies installed will always be the same, because the dependencies of your dependencies will most likely also be defined with a version range. In order to keep track of a list of tested version-tagged dependencies, npm provides another mechanism: package locks.
Before version 5 of npm, you can create a "npm-shrinkwrap.json" file with the shrinkwrap command:
npm shrinkwrap
This command locks down the versions of a package's dependencies so that you can control exactly which versions of each dependency will be used when your package is installed.
Since npm 5, a "package-lock.json" is automatically generated when an npm operation modifies the "node_modules" tree or "package.json".
Rather than modifying package.json, either one of these package locks will override the default behaviour of npm install, installing dependencies with the versions specified by the lock, right when they were created or manually updated. With that out of the way, your dependencies can now be expanded without the risk of dependents installing untested package versions.
Shrinkwraps are used for publishing packages. To shrinkwrap a package:
Run npm install in the package root to install the current versions of all dependencies.
Validate that the package works as expected with these versions.
Run npm shrinkwrap, add npm-shrinkwrap.json to git, and publish your package.
At this point, dependency versions can be loosened in your package.json (this will hopefully be done only once every major dependency update), so that later on they can be updated at will with npm update:
"devDependencies": {
"someFixedVersionPackage": "^1.0.0",
"anotherFixedVersionPackage": "^2.3.2",
}
The package-lock.json file can be used instead of a shrinkwrap, and is more suitable for reproducing a development environment. It should also be committed to the repository.
So how do I update my dependencies?
Calling npm update will do what's mentioned above: update dependencies while respecting semantic versioning. To add or upgrade a dependency in a package:
Run npm install in the package root to install the current versions of all dependencies.
Add or update dependencies. npm install --save each new or updated package individually to update the package.json, as well as the existing package locks ("package-lock.json" and "npm-shrinkwrap.json"). Note that they must be explicitly named in order to be installed: running npm install with no arguments will merely reproduce the locked dependencies.
Validate that the package works as expected with the new dependencies.
Commit the new package locks.
Moreover, here are a few tips for a smooth transition from a project with fixed dependencies:
If you haven't done so, expand the version range by adding a tilde (~) before the version specifier, or a caret (^). npm update will then attempt to install all patch revisions and minor revisions, respectively (major version 0 is a corner-case, see the documentation). For instance, "^1.0.0" can now be updated to "^1.1.0", and "~2.3.2" can be updated to "~2.3.4". Adding the --save or --save-dev flags will also update the "package.json" with the installed version (while keeping the previous range specifiers).
Run npm outdated to check which packages are outdated. Entries in red will be updated automatically with npm update. Other entries will require a manual intervention.
For packages with major version bumps, install that package with a version specification (e.g. npm install browserify#11.2.0 --save-dev). Further issues that may arise with the update will have to be handled manually. It usually helps to read the news feed or the release history on that package to further understand what has changed from previous versions.
This is not simple enough, is there another way to do this?
Before continuing, it is always worth mentioning that packages have a SemVer-compliant version definition for a reason. One should avoid blindly installing the latest version of every single package. Although such a full update can be done and tools are available for that, some caution is advised. For instance, you would not want to install React 15 if the remaining React components and libraries are not compatible with react#15.x.x. See also npm's blog post: Why use SemVer?
I'll take my chances. What other tools are there?
To name a few:
npm-check-updates will do what was initially asked in the question: install and update the versions of all dependencies, regardless of the given range constraint. This would be the least recommended tool for the job, however.
updtr will update dependencies one by one and roll back to the previous version if the project's tests fail, which may save time in projects with good test coverage.
npm-check provides an interactive command-line interface, which allows you to easily select which packages to update.
Is this any different with npm 5?
Since major version 5, npm will automatically create a "package-lock.json", which will fill the role of specifying the dependency tree when a shrinkwrap does not exist. A more detailed description can be found in the package-locks documentation. In general, npm-shrinkwrap.json is meant to be used when publishing, whereas package-lock.json is to be used in development. This is why you should also commit "package-lock.json" to the repository.
What about with Yarn?
Yarn, an npm-compatible dependency manager, creates a lock file automatically on use, which behaves similarly to the npm shrinkwrap. Calling yarn upgrade «package» will update one dependency to the version in the latest tag, regardless of the version range recorded in the package.json or the lock file. Using yarn upgrade-interactive also allows you to selectively upgrade packages to the latest version, not unlike npm-check.
$ yarn outdated
yarn outdated v0.16.1
Package Current Wanted Latest
babel-eslint 7.0.0 7.0.0 7.1.0
chai 3.0.0 3.0.0 3.5.0
Done in 0.84s.
$ yarn upgrade babel-eslint chai
yarn upgrade v0.16.1
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
├─ babel-eslint#7.1.0
└─ chai#3.5.0
Running the following command will do what you want:
npm install someFixedVersionPackage#latest anotherFixedVersionPackage#latest --save-dev --save-exact
Breakdown:
npm install someFixedVersionPackage#latest will install the latest version of the package
The --save-dev flag will cause it to update the version in your package.json's devDependencies
The --save-exact flag will cause it to save a fixed version instead of a semver range operator
Link to the npm install docs
I've been looking for an easy way to update npm dependencies for a long time. Then I found this tool: https://github.com/dylang/npm-check
It shows you which dependencies are out of date in a nice ui and allows you to update them. It even tells you which ones are likely to break due to major changes and warns you of unused dependencies.

ember-cli packages installation

Why some npm packages for ember-cli (like ember-cli-simple-auth or ember-cli-simple-auth-token) needs to be installed with the following two statements
npm install --save-dev ember-cli-simple-auth-token
ember generate simple-auth-token
?
I don't actually understand the second one which apparently simply add a bower dependency:
bash
me#imac1 ~/dev/wishhhh/ember $ ember generate simple-auth-token
version: 0.1.2
installing
Installing browser packages via Bower...
cached git://github.com/simplabs/ember-simple-auth-component.git#0.6.7
Installed browser packages via Bower.
Why do I need it?
You are correct in that all it does is install a bower package.
The reason this is requires is it prevents duplicate bower dependencies in your app. Early in addon development, people were installing bower components with an npm postInstall hook. While this worked, it added a lot of extra file size and possible conflicting bower dependencies.
This is the current pattern that addon developers are using to include bower dependencies in your project. This will likely be changed in the future but that is why for now.
(Answered referencing ember-cli 0.1.2)