-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking: Make typescript an optional dependency.
- Loading branch information
Showing
7 changed files
with
47 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function loadModule(name: string, message: string): unknown { | ||
try { | ||
// eslint-disable-next-line | ||
return require(name); | ||
} catch { | ||
throw new Error(`${message} Please install with \`yarn add --dev ${name}\`.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { loadModule } from '../../src/helpers/loadModule'; | ||
|
||
describe('loadModule()', () => { | ||
it('doesnt error if module exists', () => { | ||
expect(() => loadModule('typescript', '')).not.toThrow(); | ||
}); | ||
|
||
it('errors if module does not exist', () => { | ||
expect(() => loadModule('unknown-module', 'Fake module!')).toThrow( | ||
'Fake module! Please install with `yarn add --dev unknown-module`.', | ||
); | ||
}); | ||
}); |