Skip to content

Commit

Permalink
Add support for merging/clobbering ember in package.json. (#429)
Browse files Browse the repository at this point in the history
Add support for merging/clobbering `ember` in `package.json`.
  • Loading branch information
rwjblue authored Dec 11, 2019
2 parents 5edecef + bd14802 commit d5d761a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
},
{
Expand Down
1 change: 1 addition & 0 deletions lib/dependency-manager-adapters/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
62 changes: 62 additions & 0 deletions test/dependency-manager-adapters/npm-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions test/dependency-manager-adapters/workspace-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit d5d761a

Please sign in to comment.