Repository: ember-cli/ember-try
Pull request #259 (2019-01-11 16:57:14)

Add yarn resolutions
This PR adds resolution support for ember-try configs that are using yarn.
It uses the same merging strategy that the dependencies, devDependencies, and
peerDependencies use.

codecov[bot]: # [Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=h1) Report
> Merging [#259](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=desc) into [master](https://codecov.io/gh/ember-cli/ember-try/commit/e165e5d277edf9fe714fab830653d15efd82b215?src=pr&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/ember-cli/ember-try/pull/259/graphs/tree.svg?width=650&token=5fmkpw9NH2&height=150&src=pr)](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #259      +/-   ##
==========================================
+ Coverage   95.36%   95.37%   +0.01%     
==========================================
  Files          17       17              
  Lines         539      541       +2     
==========================================
+ Hits          514      516       +2     
  Misses         25       25
```


| [Impacted Files](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [lib/dependency-manager-adapters/npm.js](https://codecov.io/gh/ember-cli/ember-try/pull/259/diff?src=pr&el=tree#diff-bGliL2RlcGVuZGVuY3ktbWFuYWdlci1hZGFwdGVycy9ucG0uanM=) | `93.97% <100%> (+0.14%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=footer). Last update [e165e5d...6a08b29](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

codecov[bot]: # [Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=h1) Report
> Merging [#259](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=desc) into [master](https://codecov.io/gh/ember-cli/ember-try/commit/e165e5d277edf9fe714fab830653d15efd82b215?src=pr&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/ember-cli/ember-try/pull/259/graphs/tree.svg?width=650&token=5fmkpw9NH2&height=150&src=pr)](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #259      +/-   ##
==========================================
+ Coverage   95.36%   95.37%   +0.01%     
==========================================
  Files          17       17              
  Lines         539      541       +2     
==========================================
+ Hits          514      516       +2     
  Misses         25       25
```


| [Impacted Files](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [lib/dependency-manager-adapters/npm.js](https://codecov.io/gh/ember-cli/ember-try/pull/259/diff?src=pr&el=tree#diff-bGliL2RlcGVuZGVuY3ktbWFuYWdlci1hZGFwdGVycy9ucG0uanM=) | `93.97% <100%> (+0.14%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=footer). Last update [e165e5d...6a08b29](https://codecov.io/gh/ember-cli/ember-try/pull/259?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

ryanto: Ok great! I just rebased off master and everything is green.

Patch:
diff --git a/lib/dependency-manager-adapters/npm.js b/lib/dependency-manager-adapters/npm.js
index 13bbefc..bcbfb67 100644
--- a/lib/dependency-manager-adapters/npm.js
+++ b/lib/dependency-manager-adapters/npm.js
@@ -129,6 +129,10 @@ module.exports = CoreObject.extend({
     this._overridePackageJSONDependencies(packageJSON, depSet, 'devDependencies');
     this._overridePackageJSONDependencies(packageJSON, depSet, 'peerDependencies');
 
+    if (this.useYarnCommand) {
+      this._overridePackageJSONDependencies(packageJSON, depSet, 'resolutions');
+    }
+
     return packageJSON;
   },
   _overridePackageJSONDependencies(packageJSON, depSet, kindOfDependency) {


Test patch:
diff --git a/test/dependency-manager-adapters/npm-adapter-test.js b/test/dependency-manager-adapters/npm-adapter-test.js
index ace4c4c..aec7858 100644
--- a/test/dependency-manager-adapters/npm-adapter-test.js
+++ b/test/dependency-manager-adapters/npm-adapter-test.js
@@ -166,6 +166,78 @@ describe('npmAdapter', () => {
       expect(resultJSON.dependencies['ember-cli-babel']).to.equal('6.0.0');
     });
 
+    it('adds a resolution for the specified dependency version', () => {
+      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' },
+        resolutions: { 'ember-cli-babel': '6.0.0' }
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.resolutions['ember-cli-babel']).to.equal('6.0.0');
+    });
+
+    it('removes a dependency from resolutions if its version is null', () => {
+      let npmAdapter = new NpmAdapter({
+        cwd: tmpdir,
+        useYarnCommand: true
+      });
+      let packageJSON = {
+        dependencies: { 'ember-cli-babel': '5.0.0' },
+        resolutions: { 'ember-cli-babel': '5.0.0' },
+      };
+      let depSet = {
+        dependencies: { 'ember-cli-babel': '6.0.0' },
+        resolutions: { 'ember-cli-babel': null },
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.resolutions['ember-cli-babel']).to.be.undefined;
+    });
+
+    it('doesnt add resolutions if there are none specified', () => {
+      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' },
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.resolutions).to.be.undefined;
+    });
+
+    it('doesnt add resolutions when not using yarn', () => {
+      let npmAdapter = new NpmAdapter({
+        cwd: tmpdir,
+        useYarnCommand: false
+      });
+      let packageJSON = {
+        dependencies: { 'ember-cli-babel': '5.0.0' },
+      };
+      let depSet = {
+        dependencies: { 'ember-cli-babel': '6.0.0' },
+        resolutions: { 'ember-cli-babel': '6.0.0' }
+      };
+
+      let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+      expect(resultJSON.resolutions).to.be.undefined;
+    });
+
     it('changes specified npm dev dependency versions', () => {
       let npmAdapter = new NpmAdapter({ cwd: tmpdir });
       let packageJSON = { devDependencies: { 'ember-feature-flags': '1.0.0' }, dependencies: { 'ember-cli-babel': '5.0.0' } };
diff --git a/test/dependency-manager-adapters/workspace-adapter-test.js b/test/dependency-manager-adapters/workspace-adapter-test.js
index a7bfd0c..7786b06 100644
--- a/test/dependency-manager-adapters/workspace-adapter-test.js
+++ b/test/dependency-manager-adapters/workspace-adapter-test.js
@@ -146,6 +146,7 @@ describe('workspaceAdapter', () => {
         devDependencies: { 'ember-feature-flags': '1.0.0' },
         dependencies: { 'ember-cli-babel': '5.0.0' },
         peerDependencies: { 'ember-cli-sass': '1.2.3' },
+        resolutions: { 'ember-data': '3.0.0' },
       });
 
       workspaceAdapter = new WorkspaceAdapter({
@@ -167,6 +168,7 @@ describe('workspaceAdapter', () => {
           devDependencies: { 'ember-feature-flags': '1.0.0' },
           dependencies: { 'ember-cli-babel': '6.0.0' },
           peerDependencies: { 'ember-cli-sass': '1.2.3' },
+          resolutions: { 'ember-data': '3.0.0' },
         });
       });
     });
@@ -181,6 +183,7 @@ describe('workspaceAdapter', () => {
           devDependencies: { 'ember-feature-flags': '2.0.1' },
           dependencies: { 'ember-cli-babel': '5.0.0' },
           peerDependencies: { 'ember-cli-sass': '1.2.3' },
+          resolutions: { 'ember-data': '3.0.0' },
         });
       });
     });
@@ -195,6 +198,22 @@ describe('workspaceAdapter', () => {
           devDependencies: { 'ember-feature-flags': '1.0.0' },
           dependencies: { 'ember-cli-babel': '5.0.0' },
           peerDependencies: { 'ember-cli-sass': '4.5.6' },
+          resolutions: { 'ember-data': '3.0.0' },
+        });
+      });
+    });
+
+    it('changes specified resolution versions', () => {
+      return workspaceAdapter.changeToDependencySet({
+        npm: {
+          resolutions: { 'ember-data': '3.5.0' },
+        },
+      }).then(() => {
+        assertFileContainsJSON('packages/test/package.json', {
+          devDependencies: { 'ember-feature-flags': '1.0.0' },
+          dependencies: { 'ember-cli-babel': '5.0.0' },
+          peerDependencies: { 'ember-cli-sass': '1.2.3' },
+          resolutions: { 'ember-data': '3.5.0' },
         });
       });
     });
@@ -209,6 +228,7 @@ describe('workspaceAdapter', () => {
           devDependencies: {},
           dependencies: { 'ember-cli-babel': '5.0.0' },
           peerDependencies: { 'ember-cli-sass': '1.2.3' },
+          resolutions: { 'ember-data': '3.0.0' },
         });
       });
     });