Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Never bundle when saving as peer/peerOptional
Browse files Browse the repository at this point in the history
There's a bit of logic in npm/cli that sets the `saveBundle` option to
false based on the various `--save-xyz` flags.  It is easier and safer
to just never bundle if we're saving a peer dep, in the one place where
that decision is made.
  • Loading branch information
isaacs committed Mar 19, 2021
1 parent 252371e commit e582c52
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/add-rm-pkg-deps.js
Expand Up @@ -71,7 +71,7 @@ const addSingle = ({pkg, spec, saveBundle, saveType}) => {
pkg.devDependencies[name] = pkg.peerDependencies[name]
}

if (saveBundle) {
if (saveBundle && saveType !== 'peer' && saveType !== 'peerOptional') {
// keep it sorted, keep it unique
const bd = new Set(pkg.bundleDependencies || [])
bd.add(spec.name)
Expand Down
30 changes: 30 additions & 0 deletions test/add-rm-pkg-deps.js
Expand Up @@ -38,6 +38,36 @@ t.test('add', t => {
bundleDependencies: ['bar', 'foo'],
}, 'move to bundle deps, foo to deps, leave bar version unchanged')

t.strictSame(add({
pkg: {
dependencies: { bar: '1' },
devDependencies: { foo: '2' },
},
add: [foo1, bar],
saveBundle: true,
saveType: 'peer',
}), {
devDependencies: { foo: '1' },
peerDependencies: { foo: '1', bar: '*' },
}, 'never bundle peerDeps')

t.strictSame(add({
pkg: {
dependencies: { bar: '1' },
devDependencies: { foo: '2' },
},
add: [foo1, bar],
saveBundle: true,
saveType: 'peerOptional',
}), {
devDependencies: { foo: '1' },
peerDependencies: { foo: '1', bar: '*' },
peerDependenciesMeta: {
foo: { optional: true },
bar: { optional: true },
},
}, 'never bundle peerDeps')

t.strictSame(add({
pkg: {},
add: [foo1, bar],
Expand Down

0 comments on commit e582c52

Please sign in to comment.