Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for npm overrides #850

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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