Skip to content

Commit

Permalink
fix: do not overwrite bundled dependency ranges with * (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Mar 14, 2022
1 parent abcdb36 commit b8e4604
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fixer.js
Expand Up @@ -129,7 +129,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
11 changes: 10 additions & 1 deletion test/dependencies.js
Expand Up @@ -32,12 +32,21 @@ tap.test('warn if bundleDependencies array contains anything else but strings',
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 b8e4604

Please sign in to comment.