diff --git a/index.js b/index.js index d923b98..a4122be 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/package.json b/package.json index c0a4973..203d3af 100644 --- a/package.json +++ b/package.json @@ -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": "*" diff --git a/test/simple.js b/test/simple.js index 31e9458..7fea2c5 100644 --- a/test/simple.js +++ b/test/simple.js @@ -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.'); diff --git a/test/simple/e.ts b/test/simple/e.ts new file mode 100644 index 0000000..bd0c424 --- /dev/null +++ b/test/simple/e.ts @@ -0,0 +1 @@ +export = 'e'; diff --git a/test/simple/f.d.ts b/test/simple/f.d.ts new file mode 100644 index 0000000..e60ad98 --- /dev/null +++ b/test/simple/f.d.ts @@ -0,0 +1 @@ +export const foo: 'bar';