Skip to content

Commit

Permalink
Merge 7a2d4e9 into 4540780
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona authored Mar 23, 2023
2 parents 4540780 + 7a2d4e9 commit d92f586
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ module.exports = async function() {
devDependencies: {
'ember-source': '2.11.0'
},
/*
You can optionally define npm overrides to enforce a specific dependency version
to be installed. This is useful if other libraries you depend on include different
versions of a package. This does nothing if `useYarn` is true;
*/
overrides: {
'lodash': '5.0.0'
}
/*
When `useYarn` is true, you can optionally define yarn resolutions to enforce a
specific dependency version to be installed. This is useful if other libraries
Expand Down
2 changes: 2 additions & 0 deletions lib/dependency-manager-adapters/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ module.exports = CoreObject.extend({

if (this.useYarnCommand) {
this._overridePackageJSONDependencies(packageJSON, depSet, 'resolutions');
} else {
this._overridePackageJSONDependencies(packageJSON, depSet, 'overrides');
}

return packageJSON;
Expand Down
69 changes: 69 additions & 0 deletions test/dependency-manager-adapters/npm-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,75 @@ describe('npmAdapter', () => {
expect(resultJSON.resolutions).to.be.undefined;
});

it('adds a override for the specified dependency version', () => {
let npmAdapter = new NpmAdapter({
cwd: tmpdir,
});
let packageJSON = {
dependencies: { 'ember-cli-babel': '5.0.0' },
};
let depSet = {
dependencies: { 'ember-cli-babel': '6.0.0' },
overrides: { 'ember-cli-babel': '6.0.0' },
};

let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);

expect(resultJSON.overrides['ember-cli-babel']).to.equal('6.0.0');
});

it('removes a dependency from overrides if its version is null', () => {
let npmAdapter = new NpmAdapter({
cwd: tmpdir,
});
let packageJSON = {
dependencies: { 'ember-cli-babel': '5.0.0' },
overrides: { 'ember-cli-babel': '5.0.0' },
};
let depSet = {
dependencies: { 'ember-cli-babel': '6.0.0' },
overrides: { 'ember-cli-babel': null },
};

let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);

expect(resultJSON.overrides['ember-cli-babel']).to.be.undefined;
});

it('doesnt add overrides if there are none specified', () => {
let npmAdapter = new NpmAdapter({
cwd: tmpdir,
});
let packageJSON = {
dependencies: { 'ember-cli-babel': '5.0.0' },
};
let depSet = {
dependencies: { 'ember-cli-babel': '6.0.0' },
};

let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);

expect(resultJSON.resolutions).to.be.undefined;
});

it('doesnt add overrides when using yarn', () => {
let npmAdapter = new NpmAdapter({
cwd: tmpdir,
useYarnCommand: true,
});
let packageJSON = {
dependencies: { 'ember-cli-babel': '5.0.0' },
};
let depSet = {
dependencies: { 'ember-cli-babel': '6.0.0' },
overrides: { 'ember-cli-babel': '6.0.0' },
};

let resultJSON = npmAdapter._packageJSONForDependencySet(packageJSON, depSet);

expect(resultJSON.overrides).to.be.undefined;
});

it('changes specified npm dev dependency versions', () => {
let npmAdapter = new NpmAdapter({ cwd: tmpdir });
let packageJSON = {
Expand Down

0 comments on commit d92f586

Please sign in to comment.