Peer dependencies for Angular compatible projects? - node.js

Trying to figure out how to declare RxJS as a peer dependency for an Angular 6 project I'm working on. For example I looked at angular/flex-layout and it declares it's RxJS dependency like this:
"requiredAngularVersion": ">=6.0.0 <7.0.0",
"dependencies": {
"rxjs": "^6.0.0"
}
Just curious why it's declared like that and not like this:
"requiredAngularVersion": ">=6.0.0 <7.0.0",
"peerDependencies": {
"rxjs": "^6.0.0"
}
Side Note
Noticed that some projects are matching their major semver version to Angular's Major version. So for example I'll be using major version 6 for the #fireflysemantics/slice in order to match it up with Angular 6.

Just curious why it's declared like that and not like this:
It should be a peerDependency. They probably don't want to force people to use 6.0.x which is what dependencies does.

Related

How to make user install same version of depency A as depency B is using?

I used the variables in the title of this topics, but I also have the live example.
The alpha version 1.5.0-alpha.0 of the package #yamato-daiwa/es-extensions-localization-japanese depends on version 1.5.1 of #yamato-daiwa/es-extensions:
{
"name": "#yamato-daiwa/es-extensions-localization-japanese",
"version": "1.5.0-alpha.0",
"dependencies": {
"#yamato-daiwa/es-extensions": "1.5.1"
},
"peerDependencies": {
"#yamato-daiwa/es-extensions": ">=1.5.0 <1.6.0"
},
// ...
}
If to install the correct versions of both packages, both distributables will be put directly below node_modules/#yamato-daiwa:
{
"private": true,
"dependencies": {
"#yamato-daiwa/es-extensions": "1.5.1",
"#yamato-daiwa/es-extensions-localization-japanese": "1.5.0-alpha.0"
}
}
Now let's assume that I made a mistake and installed the version 1.5.0 of #yamato-daiwa/es-extensions. In this case, the additional instance of #yamato-daiwa/es-extensions will be put below node_modules/#yamato-daiwa/es-extensions-localization-japanese/node_modules.
The localization will be applied anymore, but there also will be any error, so if it was not the experiment, I could not undestrand the cause.
How to make use install the appropriate version of #yamato-daiwa/es-extensions? Is more strict peerDependencies like "#yamato-daiwa/es-extensions": "1.5.1" will be enough?
As you noted - you have 2 installations #yamato-daiwa/es-extensions - in main app's node_modules and in #yamato-daiwa/es-extensions-localization-japanese node_modules. Your application uses the package from its node_modules folder, but the localization uses another instance from its node_modules. That's why localization is not working.
To prevent this, you should enable strict-peer-deps property in the project's .npmrc file. npm will treat non-compatible peer dependencies as a failure.

How to update a dependency within a dependency?

I would like to update a 'handlebars' node module that is a dependency of Vue-Cli (see screenshot).
What's the correct way to do this?
Thank you
Add a resolutions field to your package.json file and define your version overrides.
It will look like this
{
...
"dependencies": {
...
},
"devDependencies": {
...
},
"resolutions": {
"EXAMPLE_PACKAGE": "EXAMPLE_PACKAGE_NEEDED_VERSION"
}
}
It shouldn't update the package in the dependency. But your application will use the needed version. It can be useful for example if some dependencies in your dependency have important security updates, and your dependency has not updated the version yet.

How to patch jest-rutime when using Yarn 2?

I am trying to follow the instructions in this repository to patch Jest.
Patch Jest.
It is suggested to use patch-package but I figured out that I can use yarn patch when using Yarn 2.
I managed to patch jest-runtime but seems Jest doesn’t seem to require jest-runtime in its package so I don’t know where it comes from to use it as a reference to declare the patched file.
Jest package.json
I understand if Jest was the one that needs to be patched I could declare it like this:
package.json
"devDependencies": {
"jest": "patch:jest#26.6.3#./patches/jest.patch"
}
I tried to use the same logic to include the following code to include jest-runtime but it didn't work.
"devDependencies": {
"jest": "^26.6.3",
"jest-runtime": "patch:jest-runtime#26.6.3#./patches/jest-runtime.patch"
}
How can I declare this patched jest-runtime so Jest can use it?
The Resolutions field in the manifest is the correct approach to declare the patched modules that we didn't add to devDependencies such as submodules.
The resolutions field allows you to instruct Yarn to use a specific resolution instead of anything the resolver would normally pick. This is useful to enforce all your packages to use a single version of a dependency, or backport a fix.
The fix for that issue:
{
...
"dependencies": {
"jest": "^26.6.3",
},
"resolutions": {
"jest-runtime": "patch:jest-runtime#26.6.3#./patches/jest-runtime.patch"
},
}

How to fix broken Typescript definitions when definitions files are updated

I have a project that uses Typescript, using the newer #types/foo style of installing typings packages.
When my build server installs all npm modules, sometimes I get a complete failure when compiling the typescript as some dependent definitions are no longer matching up.
For instance, I now have a problem with #types/gulp. In its package.json, dependencies are listed as:
"dependencies": {
"#types/node": "*",
"#types/orchestrator": "*",
"#types/vinyl": "*"
},
But now #types/orchestrator has updated, and it now breaks the version of #types/gulp that I have defined in my apps package.json.
How am I supposed to lock down version of dependencies like this so I no longer get this problem, or is there another workaround?
Unfortunately, I suddenly get these issues which sets development back by hours trying to sort it out. This makes using Typescript in a fast moving environment difficult.
How am I supposed to lock down version of dependencies like this so I no longer get this problem
Run npm shrinkwrap or just specify an exact version:
"#types/vinyl": "6.3.12"

npm install using pre-release versions

i want to use pre-release versions in my package.json to get some dependencies in the latest version (containing als pre-releases) but for some reasons it doesn't work in my case. The pre-releases are fully ignored. As an example lets use angular. If I ask "angular": ">=1.4.0-rc.0 <1.4.1" as an dependency, i would expect that i would get the version 1.4.0-rc.2 installed, but i get just the version 1.4.0.
The npm info angular shows, that there are some rc versions available like
...
'1.4.0-beta.4',
'1.4.0-beta.5',
'1.4.0-beta.6',
'1.4.0-rc.0',
'1.4.0-rc.1',
'1.4.0-rc.2',
My package.json looks as follows right now
"dependencies": {
"angular": ">=1.4.0-rc.0 <1.4.1"
}
Any ideas why i dont get any rc versions? What do i have to do to get it working?
This seems logical, the order of versions is normally the following (for angular releases 1.4.x):
1.4.0-beta.0
1.4.0-beta.2
1.4.0-beta.3
1.4.0-beta.4
1.4.0-beta.5
1.4.0-beta.6
1.4.0-rc.0
1.4.0-rc.1
1.4.0-rc.2
1.4.0
1.4.1
If you request "angular": ">=1.4.0-rc.0 <1.4.1", The latest version that is less strictly 1.4.1 is 1.4.0
Anyway, if you demand "angular": ">=1.4.0-rc.0 <1.4.0", the latest version will be 1.4.0-rc.2

Resources