Repository: ember-cli/ember-cli
Pull request #10024 (2022-09-20 16:28:00)

[ENHANCEMENT] Add `ember-source` to `peerDependencies` in `addon` blueprint
Didn't have the right permissions to modify the original PR: #9864.

Closes #9864.


Patch:
diff --git a/blueprints/addon/additional-dev-dependencies.json b/blueprints/addon/additional-dev-dependencies.json
deleted file mode 100644
index 897398e6b..000000000
--- a/blueprints/addon/additional-dev-dependencies.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-  "devDependencies": {
-    "@embroider/test-setup": "^1.8.3",
-    "ember-disable-prototype-extensions": "^1.1.3",
-    "ember-try": "^2.0.0",
-    "ember-source-channel-url": "^3.0.0"
-  }
-}
diff --git a/blueprints/addon/additional-package.json b/blueprints/addon/additional-package.json
new file mode 100644
index 000000000..f0724ca55
--- /dev/null
+++ b/blueprints/addon/additional-package.json
@@ -0,0 +1,20 @@
+{
+  "keywords": [
+    "ember-addon"
+  ],
+  "scripts": {
+    "test:ember-compatibility": "ember try:each"
+  },
+  "devDependencies": {
+    "@embroider/test-setup": "^1.8.3",
+    "ember-disable-prototype-extensions": "^1.1.3",
+    "ember-source-channel-url": "^3.0.0",
+    "ember-try": "^2.0.0"
+  },
+  "peerDependencies": {
+    "ember-source": "^3.28.0 || ^4.0.0"
+  },
+  "ember-addon": {
+    "configPath": "tests/dummy/config"
+  }
+}
diff --git a/blueprints/addon/index.js b/blueprints/addon/index.js
index 2678f06c6..98916b5f9 100644
--- a/blueprints/addon/index.js
+++ b/blueprints/addon/index.js
@@ -5,7 +5,7 @@ const path = require('path');
 const walkSync = require('walk-sync');
 const chalk = require('chalk');
 const stringUtil = require('ember-cli-string-utils');
-const { uniq } = require('ember-cli-lodash-subset');
+const { merge, uniq } = require('ember-cli-lodash-subset');
 const SilentError = require('silent-error');
 const sortPackageJson = require('sort-package-json');
 
@@ -22,7 +22,7 @@ const replacers = {
   },
 };
 
-const ADDITIONAL_DEV_DEPENDENCIES = require('./additional-dev-dependencies.json').devDependencies;
+const ADDITIONAL_PACKAGE = require('./additional-package.json');
 
 const description = 'The default blueprint for ember-cli addons.';
 module.exports = {
@@ -43,9 +43,9 @@ module.exports = {
 
     contents.name = stringUtil.dasherize(this.options.entity.name);
     contents.description = this.description;
+
     delete contents.private;
-    contents.scripts = contents.scripts || {};
-    contents.keywords = contents.keywords || [];
+
     contents.dependencies = contents.dependencies || {};
     contents.devDependencies = contents.devDependencies || {};
 
@@ -67,17 +67,7 @@ module.exports = {
     // 100% of addons don't need ember-cli-app-version, make it opt-in instead
     delete contents.devDependencies['ember-cli-app-version'];
 
-    if (contents.keywords.indexOf('ember-addon') === -1) {
-      contents.keywords.push('ember-addon');
-    }
-
-    Object.assign(contents.devDependencies, ADDITIONAL_DEV_DEPENDENCIES);
-
-    // add `ember-compatibility` script in addons
-    contents.scripts['test:ember-compatibility'] = 'ember try:each';
-
-    contents['ember-addon'] = contents['ember-addon'] || {};
-    contents['ember-addon'].configPath = 'tests/dummy/config';
+    merge(contents, ADDITIONAL_PACKAGE);
 
     return stringifyAndNormalize(sortPackageJson(contents));
   },
diff --git a/dev/update-blueprint-dependencies.js b/dev/update-blueprint-dependencies.js
index a3b373ce1..d8a86ca72 100644
--- a/dev/update-blueprint-dependencies.js
+++ b/dev/update-blueprint-dependencies.js
@@ -43,7 +43,7 @@ const OPTIONS = nopt({
 
 const PACKAGE_FILES = [
   '../blueprints/app/files/package.json',
-  '../blueprints/addon/additional-dev-dependencies.json',
+  '../blueprints/addon/additional-package.json',
   '../tests/fixtures/app/defaults/package.json',
   '../tests/fixtures/app/npm/package.json',
   '../tests/fixtures/app/yarn/package.json',


Test patch:
diff --git a/tests/fixtures/addon/defaults/package.json b/tests/fixtures/addon/defaults/package.json
index bd74082b0..037eec94f 100644
--- a/tests/fixtures/addon/defaults/package.json
+++ b/tests/fixtures/addon/defaults/package.json
@@ -65,6 +65,9 @@
     "qunit-dom": "^2.0.0",
     "webpack": "^5.74.0"
   },
+  "peerDependencies": {
+    "ember-source": "^3.28.0 || ^4.0.0"
+  },
   "engines": {
     "node": "14.* || 16.* || >= 18"
   },
diff --git a/tests/fixtures/addon/yarn/package.json b/tests/fixtures/addon/yarn/package.json
index 4765f86ba..cd5cc8de3 100644
--- a/tests/fixtures/addon/yarn/package.json
+++ b/tests/fixtures/addon/yarn/package.json
@@ -66,6 +66,9 @@
     "qunit-dom": "^2.0.0",
     "webpack": "^5.74.0"
   },
+  "peerDependencies": {
+    "ember-source": "^3.28.0 || ^4.0.0"
+  },
   "engines": {
     "node": "14.* || 16.* || >= 18"
   },
diff --git a/tests/unit/blueprints/addon-test.js b/tests/unit/blueprints/addon-test.js
index e0129e9a0..3472bdc05 100644
--- a/tests/unit/blueprints/addon-test.js
+++ b/tests/unit/blueprints/addon-test.js
@@ -184,6 +184,23 @@ describe('blueprint - addon', function () {
         expect(json.dependencies).to.deep.equal({ a: '1', b: '1' });
         expect(json.devDependencies).to.deep.equal({ a: '1', b: '1' });
       });
+
+      it('adds `ember-source` to `peerDependencies`', function () {
+        let output = blueprint.updatePackageJson(
+          JSON.stringify({
+            peerDependencies: {
+              'foo-bar': '^1.0.0',
+            },
+          })
+        );
+
+        let json = JSON.parse(output);
+
+        expect(json.peerDependencies).to.deep.equal({
+          'ember-source': '^3.28.0 || ^4.0.0',
+          'foo-bar': '^1.0.0',
+        });
+      });
     });
   });
 });