Skip to content

Commit

Permalink
Exit process when there are no input files - fixes #83.
Browse files Browse the repository at this point in the history
  • Loading branch information
vseventer committed Apr 24, 2023
1 parent 0d3ba3d commit e567896
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

## 4.2.0
* Exit process when there are no input files ([#83](/~https://github.com/vseventer/sharp-cli/issues/83)).

## 4.1.1 (March 21, 2023)
* Fixes bug with AVIF filename formatting [#28](/~https://github.com/vseventer/sharp-cli/issues/82).
* Fixes bug with AVIF filename formatting ([#28](/~https://github.com/vseventer/sharp-cli/issues/82)).

## 4.1.0 (December 15, 2022)
* Recategorized top-level options under Global, Input, Output, and Optimization Options.
Expand Down
4 changes: 4 additions & 0 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ module.exports = {
return list.concat(glob.sync(input, { absolute: true }))
}, [])

if (files.length === 0) {
return Promise.reject(new Error('No input files'))
}

// Process files.
const isBatch = files.length > 1
const promises = files.map((src) => {
Expand Down
10 changes: 10 additions & 0 deletions test/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ describe('convert', () => {
return convert
.files([input], dest, options)
})
it('must warn if there is no files', () => {
return convert
.files([])
.then(() => { throw new Error('STOP') })
.catch((err) => {
expect(err).to.exist()
expect(err).to.have.property('message')
expect(err.message).to.contain('No input files')
})
})
})
describe('stream', () => {
// Default output.
Expand Down

0 comments on commit e567896

Please sign in to comment.