Skip to content

Commit 9dc8387

Browse files
author
Noah Hummel
committed
feat: add noTypeDefinitions option
1 parent a1430ea commit 9dc8387

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ module.exports._getDependencies = function(config) {
109109
config: config.requireConfig,
110110
webpackConfig: config.webpackConfig,
111111
nodeModulesConfig: config.nodeModulesConfig,
112-
tsConfig: config.tsConfig
112+
tsConfig: config.tsConfig,
113+
noTypeDefinitions: config.noTypeDefinitions
113114
});
114115

115116
if (!result) {

lib/Config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Config {
1515
this.nodeModulesConfig = options.nodeModulesConfig;
1616
this.detectiveConfig = options.detective || options.detectiveConfig || {};
1717
this.tsConfig = options.tsConfig;
18+
this.noTypeDefinitions = options.noTypeDefinitions;
1819

1920
this.filter = options.filter;
2021

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { theAnswer } from './required';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const theAnswer: number;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
theAnswer: 42
3+
};

test/test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ describe('dependencyTree', function() {
205205
assert(tree.length === 3);
206206
});
207207

208+
it('resolves TypeScript imports to their type definition files by default', function() {
209+
const directory = path.join(__dirname, 'example', 'noTypeDefinitions');
210+
const filename = path.join(directory, 'entrypoint.ts');
211+
212+
const list = dependencyTree.toList({filename, directory});
213+
214+
assert(list.includes(path.join(directory, 'required.d.ts')));
215+
assert(!list.includes(path.join(directory, 'required.js')));
216+
});
217+
208218
describe('when given a detective configuration', function() {
209219
it('passes it through to precinct', function() {
210220
const spy = sinon.spy(precinct, 'paperwork');
@@ -903,6 +913,32 @@ describe('dependencyTree', function() {
903913
});
904914
});
905915

916+
describe('when noTypeDefinitions is set', function() {
917+
describe('and it is set to false', function() {
918+
it('resolves TypeScript imports to their definition files', function() {
919+
const directory = path.join(__dirname, 'example', 'noTypeDefinitions');
920+
const filename = path.join(directory, 'entrypoint.ts');
921+
922+
const list = dependencyTree.toList({filename, directory, noTypeDefinitions: false});
923+
924+
assert(list.includes(path.join(directory, 'required.d.ts')));
925+
assert(!list.includes(path.join(directory, 'required.js')));
926+
});
927+
});
928+
929+
describe('and it is set to true', function() {
930+
it('resolves TypeScript imports to their JavaScript implementation files', function() {
931+
const directory = path.join(__dirname, 'example', 'noTypeDefinitions');
932+
const filename = path.join(directory, 'entrypoint.ts');
933+
934+
const list = dependencyTree.toList({filename, directory, noTypeDefinitions: true});
935+
936+
assert(list.includes(path.join(directory, 'required.js')));
937+
assert(!list.includes(path.join(directory, 'required.d.ts')));
938+
});
939+
});
940+
});
941+
906942
describe('Config', function() {
907943
describe('when given a path to a typescript config', function() {
908944
it('pre-parses the config for performance', function() {

0 commit comments

Comments
 (0)