Skip to content

Commit

Permalink
fix: throw a proper error when no files are found
Browse files Browse the repository at this point in the history
  • Loading branch information
homer0 committed Feb 19, 2024
1 parent 15c6e03 commit 159e06f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ const restoreShebangs = (shebangs) =>
* @throws {Error} If there's a problem while transforming a file.
*/
const transformOutput = async (files, options) => {
if (!files.length) {
throw new Error('No files to transform were found');
}

const transformOptions = {
verbose: 0,
dry: false,
Expand Down
14 changes: 14 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,20 @@ describe('index', () => {
});
});

it('should throw if the no files are provided', () => {
// Given
const files = [];
const options = {
input: ['src'],
output: 'esm',
};
expect.assertions(1);
// When
return transformOutput(files, options).catch((error) => {
expect(error.message).toMatch(/No files to transform were found/i);
});
});

it('should remove and restore the shebang of a file', async () => {
// Given
const files = [
Expand Down

0 comments on commit 159e06f

Please sign in to comment.