Skip to content

Commit a23a9c4

Browse files
committed
fix(arborist): save bundleDependencies to package.json when reifying
1 parent 0cc9d4c commit a23a9c4

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

lib/utils/config/definitions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ define('save', {
15871587
default: true,
15881588
defaultDescription: `\`true\` unless when using \`npm update\` or
15891589
\`npm dedupe\` where it defaults to \`false\``,
1590-
usage: '-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer',
1590+
usage: '-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle',
15911591
type: Boolean,
15921592
short: 'S',
15931593
description: `

workspaces/arborist/lib/arborist/reify.js

+5
Original file line numberDiff line numberDiff line change
@@ -1369,13 +1369,18 @@ module.exports = cls => class Reifier extends cls {
13691369
devDependencies = {},
13701370
optionalDependencies = {},
13711371
peerDependencies = {},
1372+
// bundleDependencies is not required by PackageJson like the other fields here
1373+
// PackageJson also doesn't omit an empty array for this field so defaulting this
1374+
// to an empty array would add that field to every package.json file.
1375+
bundleDependencies,
13721376
} = tree.package
13731377

13741378
pkgJson.update({
13751379
dependencies,
13761380
devDependencies,
13771381
optionalDependencies,
13781382
peerDependencies,
1383+
bundleDependencies,
13791384
})
13801385
await pkgJson.save()
13811386
}

workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs

+4
Original file line numberDiff line numberDiff line change
@@ -33164,6 +33164,10 @@ exports[`test/arborist/reify.js TAP save-prod, with optional > must match snapsh
3316433164
{"dependencies":{"abbrev":"^1.1.1"}}
3316533165
`
3316633166

33167+
exports[`test/arborist/reify.js TAP saveBundle > must match snapshot 1`] = `
33168+
{"dependencies":{"abbrev":"^1.1.1"},"bundleDependencies":["abbrev"]}
33169+
`
33170+
3316733171
exports[`test/arborist/reify.js TAP saving the ideal tree save some stuff > lock after save 1`] = `
3316833172
Object {
3316933173
"dependencies": Object {

workspaces/arborist/test/arborist/reify.js

+11
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,17 @@ t.test('save-prod, with optional', async t => {
17831783
t.matchSnapshot(fs.readFileSync(path + '/package.json', 'utf8'))
17841784
})
17851785

1786+
t.test('saveBundle', async t => {
1787+
const path = t.testdir({
1788+
'package.json': JSON.stringify({
1789+
dependencies: { abbrev: '*' },
1790+
}),
1791+
})
1792+
const arb = newArb({ path })
1793+
await arb.reify({ add: ['abbrev'], saveType: 'prod', saveBundle: true })
1794+
t.matchSnapshot(fs.readFileSync(path + '/package.json', 'utf8'))
1795+
})
1796+
17861797
t.test('no saveType: dev w/ compatible peer', async t => {
17871798
const path = t.testdir({
17881799
'package.json': JSON.stringify({

0 commit comments

Comments
 (0)