Skip to content

Commit

Permalink
fix: do not overwrite bundled dependency ranges with *
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Jan 27, 2022
1 parent 7e1a78d commit c652796
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module.exports = {
if (!data.dependencies) {
data.dependencies = {}
}
if (Object.prototype.hasOwnProperty.call(data.dependencies, bd)) {
if (!Object.prototype.hasOwnProperty.call(data.dependencies, bd)) {
this.warn('nonDependencyBundleDependency', bd)
data.dependencies[bd] = '*'
}
Expand Down
14 changes: 10 additions & 4 deletions test/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ tap.test('warn if bundleDependencies array contains anything else but strings',
function warn (w) {
warnings.push(w)
}
normalize({
bundleDependencies: ['abc', 123, {foo: 'bar'}],
}, warn)
var pkg = {
dependencies: {
def: '^1.0.0',
},
bundleDependencies: ['abc', 'def', 123, { foo: 'bar' }],
}
normalize(pkg, warn)

var wanted1 = safeFormat(warningMessages.nonStringBundleDependency, 123)
var wanted2 = safeFormat(warningMessages.nonStringBundleDependency, {foo: 'bar'})
var wanted3 = safeFormat(warningMessages.nonDependencyBundleDependency, 'abc')
t.ok(~warnings.indexOf(wanted1), wanted1)
t.ok(~warnings.indexOf(wanted2), wanted2)
t.notOk(~warnings.indexOf(wanted3), wanted3)
t.ok(~warnings.indexOf(wanted3), wanted3)
t.equal(pkg.dependencies.abc, '*', 'added bundled dep to dependencies with *')
t.equal(pkg.dependencies.def, '^1.0.0', 'left def dependency alone')
t.end()
})

0 comments on commit c652796

Please sign in to comment.