Skip to content

Commit

Permalink
Merge pull request #42 from ryanwe/master
Browse files Browse the repository at this point in the history
Add support for TypeScript
  • Loading branch information
aseemk committed Oct 6, 2016
2 parents 824b9f1 + de85810 commit 793d794
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ module.exports = function requireDir(dir, opts) {
var path = filesMinusDirs[file];

if (path) {
// ignore TypeScript declaration files. They should never be
// `require`d
if (/\.d\.ts$/.test(path)) {
continue;
}

// if duplicates are wanted, key off the full name always, and
// also the base if it hasn't been taken yet (since this ext
// has higher priority than any that follow it). if duplicates
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
, "devDependencies":
{ "coffee-script": "~1.3.3"
, "mkdirp": "^0.5.0"
, "ts-node": "^1.3.0"
, "typescript": "^1.8.0"
}
, "engines":
{ "node": "*"
Expand Down
10 changes: 10 additions & 0 deletions test/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ assert.deepEqual(requireDir('./simple'), {
c: 'c',
});

// now register TypeScript and do it again:
// note that we include typescript files but not declarations.
require('ts-node/register');
assert.deepEqual(requireDir('./simple'), {
a: 'a',
b: 'b',
c: 'c',
e: 'e',
});

console.log('Simple tests passed.');
1 change: 1 addition & 0 deletions test/simple/e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export = 'e';
1 change: 1 addition & 0 deletions test/simple/f.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo: 'bar';

0 comments on commit 793d794

Please sign in to comment.