Skip to content

Commit

Permalink
fix: npm update save=false by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Jan 12, 2022
1 parent f21ffba commit 3cf432a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 11 additions & 3 deletions lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,27 @@ class Update extends ArboristWorkspaceCmd {
? global
: this.npm.prefix

// In the context of `npm upgrade` the save
// config value should default to `false`
const save = this.npm.config.isDefault('save')
? false
: this.npm.config.get('save')

if (this.npm.config.get('depth')) {
log.warn('update', 'The --depth option no longer has any effect. See RFC0019.\n' +
'https://github.com/npm/rfcs/blob/latest/implemented/0019-remove-update-depth-option.md')
}

const arb = new Arborist({
const opts = {
...this.npm.flatOptions,
log,
path: where,
save,
workspaces: this.workspaceNames,
})
}
const arb = new Arborist(opts)

await arb.reify({ update })
await arb.reify({ ...opts, update })
await reifyFinish(this.npm, arb)
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/mock-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class MockNpm {
// for now just set `find` to what config.find should return
// this works cause `find` is not an existing config entry
find: (k) => ({ ...realConfig.defaults, ...config })[k],
// for now isDefault is going to just return false if a value was defined
isDefault: (k) => !Object.prototype.hasOwnProperty.call(config, k),
get: (k) => ({ ...realConfig.defaults, ...config })[k],
set: (k, v) => config[k] = v,
list: [{ ...realConfig.defaults, ...config }],
Expand Down
15 changes: 10 additions & 5 deletions test/lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ t.afterEach(() => {
})

t.test('no args', async t => {
t.plan(4)
t.plan(5)

npm.prefix = '/project/a'

Expand All @@ -39,14 +39,16 @@ t.test('no args', async t => {
{
...npm.flatOptions,
path: npm.prefix,
save: false,
workspaces: null,
},
'should call arborist contructor with expected args'
)
t.match(log, {}, 'log is passed in')
}

reify ({ update }) {
reify ({ save, update }) {
t.equal(save, false, 'should default to save=false')
t.equal(update, true, 'should update all deps')
}
}
Expand All @@ -64,9 +66,10 @@ t.test('no args', async t => {
})

t.test('with args', async t => {
t.plan(4)
t.plan(5)

npm.prefix = '/project/a'
config.save = true

class Arborist {
constructor (args) {
Expand All @@ -76,14 +79,16 @@ t.test('with args', async t => {
{
...npm.flatOptions,
path: npm.prefix,
save: true,
workspaces: null,
},
'should call arborist contructor with expected args'
)
t.match(log, {}, 'log is passed in')
}

reify ({ update }) {
reify ({ save, update }) {
t.equal(save, true, 'should pass save if manually set')
t.same(update, ['ipt'], 'should update listed deps')
}
}
Expand Down Expand Up @@ -140,7 +145,7 @@ t.test('update --global', async t => {
const { path, log, ...rest } = args
t.same(
rest,
{ ...npm.flatOptions, workspaces: undefined },
{ ...npm.flatOptions, save: true, workspaces: undefined },
'should call arborist contructor with expected options'
)

Expand Down

0 comments on commit 3cf432a

Please sign in to comment.