Skip to content

Commit 793d794

Browse files
authored
Merge pull request #42 from ryanwe/master
Add support for TypeScript
2 parents 824b9f1 + de85810 commit 793d794

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ module.exports = function requireDir(dir, opts) {
103103
var path = filesMinusDirs[file];
104104

105105
if (path) {
106+
// ignore TypeScript declaration files. They should never be
107+
// `require`d
108+
if (/\.d\.ts$/.test(path)) {
109+
continue;
110+
}
111+
106112
// if duplicates are wanted, key off the full name always, and
107113
// also the base if it hasn't been taken yet (since this ext
108114
// has higher priority than any that follow it). if duplicates

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
, "devDependencies":
88
{ "coffee-script": "~1.3.3"
99
, "mkdirp": "^0.5.0"
10+
, "ts-node": "^1.3.0"
11+
, "typescript": "^1.8.0"
1012
}
1113
, "engines":
1214
{ "node": "*"

test/simple.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@ assert.deepEqual(requireDir('./simple'), {
1717
c: 'c',
1818
});
1919

20+
// now register TypeScript and do it again:
21+
// note that we include typescript files but not declarations.
22+
require('ts-node/register');
23+
assert.deepEqual(requireDir('./simple'), {
24+
a: 'a',
25+
b: 'b',
26+
c: 'c',
27+
e: 'e',
28+
});
29+
2030
console.log('Simple tests passed.');

test/simple/e.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export = 'e';

test/simple/f.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo: 'bar';

0 commit comments

Comments
 (0)