Repository: ember-cli/ember-try
Pull request #850 (2022-05-13 14:30:30)

Add support for npm overrides
This PR is supposed to help with the issue that is described in https://github.com/emberjs/ember-render-modifiers/issues/64

Essentially npm thinks that ranges shouldn't be satisfied if you are using pre-releases. You can overcome this if you use an `overrides` in npm which works in a very similar way to yarn resolutions. 

The issue is that if you provide an `overrides` config to ember-try it will just ignore it: 

```
{
  name: 'ember-release',
  npm: {
    devDependencies: {
      'ember-source': await getChannelURL('release'),
    },
    overrides: {
      'ember-source': '$ember-source',
    },
  },
},
```

This PR implements npm overrides in much the same way as yarn resolutions 👍  in fact I copy and pasted all of the resolutions tests and just changed resolutions to overrides in most cases 😂 

codecov[bot]: # [Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/850?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli) Report
> Merging [#850](https://codecov.io/gh/ember-cli/ember-try/pull/850?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli) (1992e87) into [master](https://codecov.io/gh/ember-cli/ember-try/commit/61fed6b79109bcccf981ff4ea0638f3adfa73652?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli) (61fed6b) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #850      +/-   ##
==========================================
+ Coverage   94.36%   94.37%   +0.01%     
==========================================
  Files          17       17              
  Lines         550      551       +1     
==========================================
+ Hits          519      520       +1     
  Misses         31       31              
```


| [Impacted Files](https://codecov.io/gh/ember-cli/ember-try/pull/850?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli) | Coverage Δ | |
|---|---|---|
| [lib/dependency-manager-adapters/npm.js](https://codecov.io/gh/ember-cli/ember-try/pull/850/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli#diff-bGliL2RlcGVuZGVuY3ktbWFuYWdlci1hZGFwdGVycy9ucG0uanM=) | `98.34% <100.00%> (+0.01%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/850?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/850?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli). Last update [61fed6b...1992e87](https://codecov.io/gh/ember-cli/ember-try/pull/850?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ember-cli).

kategengler: Thanks! Can you also add something to the readme about this feature?

Patch:
diff --git a/README.md b/README.md
index ce8828e..beee886 100644
--- a/README.md
+++ b/README.md
@@ -143,6 +143,14 @@ module.exports = async function() {
           devDependencies: {
             'ember-source': '2.11.0'
           },
+          /*
+            You can optionally define npm overrides to enforce a  specific dependency version
+            to be installed. This is useful if other libraries you depend on include different
+            versions of a package. This does nothing if `useYarn` is true;
+          */
+          overrides: {
+            'lodash': '5.0.0'
+          }
           /*
             When `useYarn` is true, you can optionally define yarn resolutions to enforce a
             specific dependency version to be installed. This is useful if other libraries
diff --git a/lib/dependency-manager-adapters/npm.js b/lib/dependency-manager-adapters/npm.js
index 3f5dee8..cc73055 100644
--- a/lib/dependency-manager-adapters/npm.js
+++ b/lib/dependency-manager-adapters/npm.js
@@ -178,6 +178,8 @@ module.exports = CoreObject.extend({
 
     if (this.useYarnCommand) {
       this._overridePackageJSONDependencies(packageJSON, depSet, 'resolutions');
+    } else {
+      this._overridePackageJSONDependencies(packageJSON, depSet, 'overrides');
     }
 
     return packageJSON;


Test patch:
diff --git a/test/dependency-manager-adapters/npm-adapter-test.js b/test/dependency-manager-adapters/npm-adapter-test.js
index 1443ba6..c406570 100644
--- a/test/dependency-manager-adapters/npm-adapter-test.js
+++ b/test/dependency-manager-adapters/npm-adapter-test.js
@@ -536,6 +536,75 @@ describe('npmAdapter', () => {
       expect(resultJSON.resolutions).to.be.undefined;
     });
 
+    it('adds a override for the specified dependency version', () => {
+      let npmAdapter = new NpmAdapter({
+        cwd: tmpdir,
+      });
+      let packageJSON = {
+        dependencies: { 'ember-cli-babel': '5.0.0' },
+      };
+      let depSet = {
+        dependencies: { 'ember-cli-babel': '6.0.0' },
+        overrides: { 'ember-cli-babel': '6.0.0' },
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.overrides['ember-cli-babel']).to.equal('6.0.0');
+    });
+
+    it('removes a dependency from overrides if its version is null', () => {
+      let npmAdapter = new NpmAdapter({
+        cwd: tmpdir,
+      });
+      let packageJSON = {
+        dependencies: { 'ember-cli-babel': '5.0.0' },
+        overrides: { 'ember-cli-babel': '5.0.0' },
+      };
+      let depSet = {
+        dependencies: { 'ember-cli-babel': '6.0.0' },
+        overrides: { 'ember-cli-babel': null },
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.overrides['ember-cli-babel']).to.be.undefined;
+    });
+
+    it('doesnt add overrides if there are none specified', () => {
+      let npmAdapter = new NpmAdapter({
+        cwd: tmpdir,
+      });
+      let packageJSON = {
+        dependencies: { 'ember-cli-babel': '5.0.0' },
+      };
+      let depSet = {
+        dependencies: { 'ember-cli-babel': '6.0.0' },
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.resolutions).to.be.undefined;
+    });
+
+    it('doesnt add overrides when using yarn', () => {
+      let npmAdapter = new NpmAdapter({
+        cwd: tmpdir,
+        useYarnCommand: true,
+      });
+      let packageJSON = {
+        dependencies: { 'ember-cli-babel': '5.0.0' },
+      };
+      let depSet = {
+        dependencies: { 'ember-cli-babel': '6.0.0' },
+        overrides: { 'ember-cli-babel': '6.0.0' },
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.overrides).to.be.undefined;
+    });
+
     it('changes specified npm dev dependency versions', () => {
       let npmAdapter = new NpmAdapter({ cwd: tmpdir });
       let packageJSON = {