Repository: ember-cli/ember-try
Pull request #429 (2019-12-11 20:20:36)

Add support for merging/clobbering `ember` in `package.json`.
Implements the changes specified in emberjs/rfcs#558.


Patch:
diff --git a/README.md b/README.md
index fb0dd1a..3acfdfe 100644
--- a/README.md
+++ b/README.md
@@ -180,6 +180,14 @@ module.exports = function() {
           resolutions: {
             'lodash': '5.0.0'
           }
+          /*
+            In order to easily test multiple editions ember-try merges any `ember` property specified
+            into the applications `package.json`. Values specified in the ember-try configuration will
+            override values that pre-existed in the original `package.json`.
+          */
+          ember: {
+            'edition': 'octane'
+          }
         }
       },
       {
diff --git a/lib/dependency-manager-adapters/npm.js b/lib/dependency-manager-adapters/npm.js
index 12fdca2..8fdb234 100644
--- a/lib/dependency-manager-adapters/npm.js
+++ b/lib/dependency-manager-adapters/npm.js
@@ -161,6 +161,7 @@ module.exports = CoreObject.extend({
     this._overridePackageJSONDependencies(packageJSON, depSet, 'dependencies');
     this._overridePackageJSONDependencies(packageJSON, depSet, 'devDependencies');
     this._overridePackageJSONDependencies(packageJSON, depSet, 'peerDependencies');
+    this._overridePackageJSONDependencies(packageJSON, depSet, 'ember');
 
     if (this.useYarnCommand) {
       this._overridePackageJSONDependencies(packageJSON, depSet, 'resolutions');


Test patch:
diff --git a/test/dependency-manager-adapters/npm-adapter-test.js b/test/dependency-manager-adapters/npm-adapter-test.js
index 239a747..562d5fe 100644
--- a/test/dependency-manager-adapters/npm-adapter-test.js
+++ b/test/dependency-manager-adapters/npm-adapter-test.js
@@ -312,6 +312,68 @@ describe('npmAdapter', () => {
       expect(resultJSON.dependencies['ember-cli-babel']).to.equal('6.0.0');
     });
 
+    describe('ember property', () => {
+      it('adds the ember property to project package.json', () => {
+        let npmAdapter = new NpmAdapter({
+          cwd: tmpdir,
+          useYarnCommand: true
+        });
+        let packageJSON = {};
+        let depSet = {
+          ember: { edition: 'octane' }
+        };
+
+        let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+        expect(resultJSON).to.deep.equal({ ember: { edition: 'octane' }});
+      });
+
+      it('merges the ember property to project package.json', () => {
+        let npmAdapter = new NpmAdapter({
+          cwd: tmpdir,
+          useYarnCommand: true
+        });
+        let packageJSON = { ember: { foo: 'bar' } };
+        let depSet = {
+          ember: { edition: 'octane' }
+        };
+
+        let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+        expect(resultJSON).to.deep.equal({ ember: { foo: 'bar', edition: 'octane' }});
+      });
+
+      it('overrides existing fields inside the ember property to project package.json', () => {
+        let npmAdapter = new NpmAdapter({
+          cwd: tmpdir,
+          useYarnCommand: true
+        });
+        let packageJSON = { ember: { edition: 'classic' } };
+        let depSet = {
+          ember: { edition: 'octane' }
+        };
+
+        let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+        expect(resultJSON).to.deep.equal({ ember: { edition: 'octane' }});
+      });
+
+      it('removes any items with a null value', () => {
+        let npmAdapter = new NpmAdapter({
+          cwd: tmpdir,
+          useYarnCommand: true
+        });
+        let packageJSON = { ember: { edition: 'octane' } };
+        let depSet = {
+          ember: { edition: null }
+        };
+
+        let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);
+
+        expect(resultJSON).to.deep.equal({ ember: { }});
+      });
+    });
+
     it('adds a resolution for the specified dependency version', () => {
       let npmAdapter = new NpmAdapter({
         cwd: tmpdir,
diff --git a/test/dependency-manager-adapters/workspace-adapter-test.js b/test/dependency-manager-adapters/workspace-adapter-test.js
index 090c487..8c7cd4c 100644
--- a/test/dependency-manager-adapters/workspace-adapter-test.js
+++ b/test/dependency-manager-adapters/workspace-adapter-test.js
@@ -297,6 +297,20 @@ describe('workspaceAdapter', () => {
       });
     });
 
+    it('changes specified ember properties', () => {
+      return workspaceAdapter.changeToDependencySet({
+        ember: { edition: 'octane' },
+      }).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.0.0' },
+          ember: { edition: 'octane' },
+        });
+      });
+    });
+
     it('can remove a package', () => {
       return workspaceAdapter.changeToDependencySet({
         devDependencies: { 'ember-feature-flags': null },