@@ -871,6 +871,109 @@ if (foo) {
871871Entries in `optionalDependencies` will override entries of the same name in
872872`dependencies`, so it' s usually best to only put in one place.
873873
874+ # ## overrides
875+
876+ If you need to make specific changes to dependencies of your dependencies, for
877+ example replacing the version of a dependency with a known security issue,
878+ replacing an existing dependency with a fork, or making sure that the same
879+ version of a package is used everywhere, then you may add an override.
880+
881+ Overrides provide a way to replace a package in your dependency tree with
882+ another version, or another package entirely. These changes can be scoped as
883+ specific or as vague as desired.
884+
885+ To make sure the package ` foo` is always installed as version ` 1.0.0` no matter
886+ what version your dependencies rely on:
887+
888+ ` ` ` json
889+ {
890+ " overrides" : {
891+ " foo" : " 1.0.0"
892+ }
893+ }
894+ ` ` `
895+
896+ The above is a short hand notation, the full object form can be used to allow
897+ overriding a package itself as well as a child of the package. This will cause
898+ ` foo` to always be ` 1.0.0` while also making ` bar` at any depth beyond ` foo`
899+ also ` 1.0.0` :
900+
901+ ` ` ` json
902+ {
903+ " overrides" : {
904+ " foo" : {
905+ " ." : " 1.0.0" ,
906+ " bar" : " 1.0.0"
907+ }
908+ }
909+ }
910+ ` ` `
911+
912+ To only override ` foo` to be ` 1.0.0` when it' s a child (or grandchild, or great
913+ grandchild, etc) of the package `bar`:
914+
915+ ```json
916+ {
917+ "overrides": {
918+ "bar": {
919+ "foo": "1.0.0"
920+ }
921+ }
922+ }
923+ ```
924+
925+ Keys can be nested to any arbitrary length. To override `foo` only when it' s a
926+ child of ` bar` and only when ` bar` is a child of ` baz` :
927+
928+ ` ` ` json
929+ {
930+ " overrides" : {
931+ " baz" : {
932+ " bar" : {
933+ " foo" : " 1.0.0"
934+ }
935+ }
936+ }
937+ }
938+ ` ` `
939+
940+ The key of an override can also include a version, or range of versions.
941+ To override ` foo` to ` 1.0.0` , but only when it' s a child of `bar@2.0.0`:
942+
943+ ```json
944+ {
945+ "overrides": {
946+ "bar@2.0.0": {
947+ "foo": "1.0.0"
948+ }
949+ }
950+ }
951+ ```
952+
953+ You may not set an override for a package that you directly depend on unless
954+ both the dependency and the override itself share the exact same spec. To make
955+ this limitation easier to deal with, overrides may also be defined as a
956+ reference to a spec for a direct dependency by prefixing the name of the
957+ package you wish the version to match with a `$`.
958+
959+ ```json
960+ {
961+ "dependencies": {
962+ "foo": "^1.0.0"
963+ },
964+ "overrides": {
965+ // BAD, will throw an EOVERRIDE error
966+ // "foo": "^2.0.0"
967+ // GOOD, specs match so override is allowed
968+ // "foo": "^1.0.0"
969+ // BEST, the override is defined as a reference to the dependency
970+ "foo": "$foo",
971+ // the referenced package does not need to match the overridden one
972+ "bar": "$foo"
973+ }
974+ }
975+ ```
976+
874977### engines
875978
876979You can specify the version of node that your stuff works on:
0 commit comments