Repository: ember-cli/ember-cli
Pull request #6132 (2016-07-31 03:54:53)

[Bugfix] Destroy in-repo-addon
Remove traces when destroying an in-repo-addon as described in #6037.

Directory removing logic is based off the latest comment of that issue. Please let me know if I misunderstood that bit.


Patch:
diff --git a/blueprints/in-repo-addon/index.js b/blueprints/in-repo-addon/index.js
index 2dc4f5e8f..d26aadf93 100755
--- a/blueprints/in-repo-addon/index.js
+++ b/blueprints/in-repo-addon/index.js
@@ -30,6 +30,28 @@ module.exports = {
       paths.push(newPath);
     }
 
+    fs.writeFileSync(packagePath, JSON.stringify(contents, null, 2));
+  },
+
+  afterUninstall: function(options) {
+    var packagePath = path.join(this.project.root, 'package.json');
+    var contents    = fs.readJsonSync(packagePath);
+    var name        = stringUtil.dasherize(options.entity.name);
+    var newPath     = ['lib', name].join('/');
+    var paths;
+    var newPathIndex;
+
+    contents['ember-addon'] = contents['ember-addon'] || {};
+    paths = contents['ember-addon']['paths'] = contents['ember-addon']['paths'] || [];
+    newPathIndex = paths.indexOf(newPath);
+
+    if (newPathIndex > -1) {
+      paths.splice(newPathIndex, 1);
+      if (paths.length === 0) {
+        delete contents['ember-addon']['paths'];
+      }
+    }
+
     fs.writeFileSync(packagePath, JSON.stringify(contents, null, 2));
   }
 };
diff --git a/package.json b/package.json
index 60401c5d0..8a8e157df 100644
--- a/package.json
+++ b/package.json
@@ -114,7 +114,7 @@
     "through": "^2.3.6",
     "tiny-lr": "0.2.1",
     "tree-sync": "^1.1.0",
-    "walk-sync": "^0.3.0",
+    "walk-sync": "^0.2.6",
     "yam": "0.0.21"
   },
   "devDependencies": {


Test patch:
diff --git a/tests/unit/blueprints/in-repo-addon-test.js b/tests/unit/blueprints/in-repo-addon-test.js
index c382dcf93..aa18a8b75 100644
--- a/tests/unit/blueprints/in-repo-addon-test.js
+++ b/tests/unit/blueprints/in-repo-addon-test.js
@@ -5,9 +5,11 @@ var path = require('path');
 var blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
 var setupTestHooks = blueprintHelpers.setupTestHooks;
 var emberNew = blueprintHelpers.emberNew;
-var emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
+var emberGenerate = blueprintHelpers.emberGenerate;
+var emberDestroy = blueprintHelpers.emberDestroy;
 
 var expect = require('ember-cli-blueprint-test-helpers/chai').expect;
+var file = require('ember-cli-blueprint-test-helpers/chai').file;
 
 describe('Acceptance: ember generate and destroy in-repo-addon', function() {
   setupTestHooks(this, {
@@ -22,23 +24,33 @@ describe('Acceptance: ember generate and destroy in-repo-addon', function() {
         expect(fs.readJsonSync('package.json')['ember-addon']).to.be.undefined;
       })
       .then(function() {
-        return emberGenerateDestroy(args, function(file) {
-          expect(file('lib/foo-bar/package.json')).to.exist;
-          expect(file('lib/foo-bar/index.js')).to.exist;
-
-          expect(fs.readJsonSync('lib/foo-bar/package.json')).to.deep.equal({
-            "name": "foo-bar",
-            "keywords": [
-              "ember-addon",
-            ],
-          });
-
-          expect(fs.readJsonSync('package.json')['ember-addon']).to.deep.equal({
-            "paths": [
-              "lib/foo-bar",
-            ],
-          });
+        return emberGenerate(args);
+      })
+      .then(function() {
+        expect(file('lib/foo-bar/package.json')).to.exist;
+        expect(file('lib/foo-bar/index.js')).to.exist;
+
+        expect(fs.readJsonSync('lib/foo-bar/package.json')).to.deep.equal({
+          "name": "foo-bar",
+          "keywords": [
+            "ember-addon",
+          ],
+        });
+
+        expect(fs.readJsonSync('package.json')['ember-addon']).to.deep.equal({
+          "paths": [
+            "lib/foo-bar",
+          ],
         });
+      })
+      .then(function() {
+        return emberDestroy(args);
+      })
+      .then(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;
       });
   });
 });