Repository: ember-cli/ember-cli (js)

Issue:
Generating in-repo-addon and destroying leaves traces
### To Reproduce

Run the following

``` sh
ember addon abcd-addon && \  
    cd abcd-addon && \
    ember g in-repo-addon efgh && \
    ember d in-repo-addon efgh
```
#### Expected Result

A clean git state, with no staged changes
#### What I'm seeing instead

The change made to `package.json` in `.ember-addon.paths[]` remains

``` diff
diff --git a/package.json b/package.json
index 8c0607f..a26ff35 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,9 @@
     "ember-cli-babel": "^5.1.6"
   },
   "ember-addon": {
-    "configPath": "tests/dummy/config"
+    "configPath": "tests/dummy/config",
+    "paths": [
+      "lib/efgh"
+    ]
   }
-}
+}
\ No newline at end of file

```

---

Output from ember version --verbose:

```
ember-cli: 2.6.2
http_parser: 2.7.0
node: 5.11.1
v8: 4.6.85.31
uv: 1.8.0
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 56.1
modules: 47
openssl: 1.0.2h
os: darwin x64
```


Pull request:
Clean up `ember-addon` object in package file when destroying an in-repo addon
Closes #6037.

Patch:
diff --git a/blueprints/in-repo-addon/index.js b/blueprints/in-repo-addon/index.js
index 134dbf649..71fbc0d84 100755
--- a/blueprints/in-repo-addon/index.js
+++ b/blueprints/in-repo-addon/index.js
@@ -69,9 +69,12 @@ module.exports = {
       let newPathIndex = paths.indexOf(newPath);
       if (newPathIndex > -1) {
         paths.splice(newPathIndex, 1);
-        if (paths.length === 0) {
-          delete contents['ember-addon']['paths'];
-        }
+      }
+      if (paths.length === 0) {
+        delete contents['ember-addon']['paths'];
+      }
+      if (Object.keys(contents['ember-addon']).length === 0) {
+        delete contents['ember-addon'];
       }
     }
 


Test patch:
diff --git a/tests/unit/blueprints/in-repo-addon-test.js b/tests/unit/blueprints/in-repo-addon-test.js
index a378d44e0..ae92dfb50 100644
--- a/tests/unit/blueprints/in-repo-addon-test.js
+++ b/tests/unit/blueprints/in-repo-addon-test.js
@@ -47,7 +47,7 @@ describe('Acceptance: ember generate and destroy in-repo-addon', function () {
         expect(file('lib/foo-bar/package.json')).to.not.exist;
         expect(file('lib/foo-bar/index.js')).to.not.exist;
 
-        expect(fs.readJsonSync('package.json')['ember-addon']['paths']).to.be.undefined;
+        expect(fs.readJsonSync('package.json')['ember-addon']).to.be.undefined;
       });
   });
 });
@@ -152,9 +152,10 @@ describe('Unit: in-repo-addon blueprint', function () {
     );
   });
 
-  it('removes paths if last one', function () {
+  it('removes the `paths` array if the removed path was the last one', function () {
     td.when(readJsonSync(), { ignoreExtraArgs: true }).thenReturn({
       'ember-addon': {
+        configPath: 'tests/dummy/config',
         paths: ['lib/test-entity-name'],
       },
     });
@@ -166,10 +167,50 @@ describe('Unit: in-repo-addon blueprint', function () {
     td.verify(readJsonSync(path.normalize('test-project-root/package.json')));
     td.verify(writeFileSync(path.normalize('test-project-root/package.json'), captor.capture()));
 
-    expect(captor.value).to.equal('\
-{\n\
-  "ember-addon": {}\n\
-}\n');
+    expect(captor.value).to.equal(`{
+  "ember-addon": {
+    "configPath": "tests/dummy/config"
+  }
+}
+`);
+  });
+
+  it('removes the `paths` array if it was already empty', function () {
+    td.when(readJsonSync(), { ignoreExtraArgs: true }).thenReturn({
+      'ember-addon': {
+        configPath: 'tests/dummy/config',
+        paths: [],
+      },
+    });
+
+    blueprint.afterUninstall(options);
+
+    let captor = td.matchers.captor();
+
+    td.verify(writeFileSync(path.normalize('test-project-root/package.json'), captor.capture()));
+
+    expect(captor.value).to.equal(`{
+  "ember-addon": {
+    "configPath": "tests/dummy/config"
+  }
+}
+`);
+  });
+
+  it('removes the `ember-addon` object if it is empty', function () {
+    td.when(readJsonSync(), { ignoreExtraArgs: true }).thenReturn({
+      'ember-addon': {
+        paths: ['lib/test-entity-name'],
+      },
+    });
+
+    blueprint.afterUninstall(options);
+
+    let captor = td.matchers.captor();
+
+    td.verify(writeFileSync(path.normalize('test-project-root/package.json'), captor.capture()));
+
+    expect(captor.value).to.equal('{}\n');
   });
 
   it('alphabetizes paths', function () {