Skip to content

Commit

Permalink
Merge pull request #10024 from bertdeblock/add-ember-source-to-peer-d…
Browse files Browse the repository at this point in the history
…ependencies-in-addon-blueprint

[ENHANCEMENT] Add `ember-source` to `peerDependencies` in `addon` blueprint
  • Loading branch information
bertdeblock committed Sep 28, 2022
2 parents 1adb237 + db749cd commit 56a4c26
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
8 changes: 0 additions & 8 deletions blueprints/addon/additional-dev-dependencies.json

This file was deleted.

20 changes: 20 additions & 0 deletions 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"
}
}
20 changes: 5 additions & 15 deletions blueprints/addon/index.js
Expand Up @@ -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');

Expand All @@ -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 = {
Expand All @@ -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 || {};

Expand All @@ -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));
},
Expand Down
2 changes: 1 addition & 1 deletion dev/update-blueprint-dependencies.js
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/addon/defaults/package.json
Expand Up @@ -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"
},
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/addon/yarn/package.json
Expand Up @@ -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"
},
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/blueprints/addon-test.js
Expand Up @@ -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',
});
});
});
});
});

0 comments on commit 56a4c26

Please sign in to comment.