Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(arborist): add named updates validation #4307

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions workspaces/arborist/lib/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ module.exports = cls => class IdealTreeBuilder extends cls {
this[_complete] = !!options.complete
this[_preferDedupe] = !!options.preferDedupe
this[_legacyBundling] = !!options.legacyBundling

// validates list of update names, they must
// be dep names only, no semver ranges are supported
const validationError =
new TypeError('Update arguments must not contain semver ranges')
ruyadorno marked this conversation as resolved.
Show resolved Hide resolved
validationError.code = 'EUPDATEARGS'
for (const name of update.names) {
const spec = npa(name)
if (spec.fetchSpec !== 'latest') {
throw validationError
}
}
this[_updateNames] = update.names

this[_updateAll] = update.all
Expand Down
16 changes: 16 additions & 0 deletions workspaces/arborist/test/arborist/build-ideal-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,22 @@ t.test('update global', async t => {
})
t.matchSnapshot(await printIdeal(path, { global: true, update: ['wrappy'] }),
'updating sub-dep has no effect')

const invalidArgs = [
'once@1.4.0',
'once@next',
'once@^1.0.0',
'once@>=2.0.0',
'once@2',
]
for (const updateName of invalidArgs) {
t.rejects(
printIdeal(path, { global: true, update: [updateName] }),
{ code: 'EUPDATEARGS' },
'should throw an error when using semver ranges'
)
}

t.matchSnapshot(await printIdeal(path, { global: true, update: ['once'] }),
'update a single dep')
t.matchSnapshot(await printIdeal(path, { global: true, update: true }),
Expand Down