Skip to content

allow "noTypeDefinitions" flag to pass through to filing-cabinet #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var tree = dependencyTree({
entry: 'module'
}, // optional
filter: path => path.indexOf('node_modules') === -1, // optional
nonExistent: [] // optional
nonExistent: [], // optional
noTypeDefinitions: false // optional
});

// Returns a post-order traversal (list form) of the tree with duplicate sub-trees pruned.
Expand All @@ -51,6 +52,7 @@ var list = dependencyTree.toList({
* `detective`: object with configuration specific to detectives used to find dependencies of a file
- for example `detective.amd.skipLazyLoaded: true` tells the AMD detective to omit inner requires
- See [precinct's usage docs](https://github.com/dependents/node-precinct#usage) for the list of module types you can pass options to.
* `noTypeDefinitions`: if truthy, prefer `.js` files over `.d.ts` files

#### Format Details

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Config = require('./lib/Config');
* @param {Object} [options.visited] - Cache of visited, absolutely pathed files that should not be reprocessed.
* Format is a filename -> tree as list lookup table
* @param {Array} [options.nonExistent] - List of partials that do not exist
* @param {Boolean} [options.noTypeDefinitions=false] - For typescript files, whether to prefer *.js over *.d.ts
* @param {Boolean} [options.isListForm=false]
* @param {String|Object} [options.tsConfig] Path to a typescript config (or a preloaded one).
* @return {Object}
Expand Down Expand Up @@ -109,7 +110,8 @@ module.exports._getDependencies = function(config) {
config: config.requireConfig,
webpackConfig: config.webpackConfig,
nodeModulesConfig: config.nodeModulesConfig,
tsConfig: config.tsConfig
tsConfig: config.tsConfig,
noTypeDefinitions: config.noTypeDefinitions
});

if (!result) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Config {
this.nodeModulesConfig = options.nodeModulesConfig;
this.detectiveConfig = options.detective || options.detectiveConfig || {};
this.tsConfig = options.tsConfig;

this.noTypeDefinitions = options.noTypeDefinitions;
this.filter = options.filter;

if (!this.filename) { throw new Error('filename not given'); }
Expand Down
7 changes: 7 additions & 0 deletions test/example/ts/noTypeDefinitions/.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "1.0.0",
"compilerOptions": {
"module": "commonjs",
"declaration": true
}
}
2 changes: 2 additions & 0 deletions test/example/ts/noTypeDefinitions/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import b from './b';
import c from './c';
1 change: 1 addition & 0 deletions test/example/ts/noTypeDefinitions/b.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (): void;
5 changes: 5 additions & 0 deletions test/example/ts/noTypeDefinitions/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
exports.__esModule = true;
function default_1() { }
exports["default"] = default_1;
;
1 change: 1 addition & 0 deletions test/example/ts/noTypeDefinitions/c.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (): void;
5 changes: 5 additions & 0 deletions test/example/ts/noTypeDefinitions/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";
exports.__esModule = true;
function default_1() { }
exports["default"] = default_1;
;
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,24 @@ describe('dependencyTree', function() {

assert.equal(results[0], path.join(directory, 'b.ts'));
});

it('respects "noTypeDefinitions" flag', function() {
const directory = path.join(__dirname, 'example/ts/noTypeDefinitions');
const tsConfigPath = path.join(directory, '.tsconfig');

const results = dependencyTree.toList({
filename: `${directory}/a.ts`,
directory,
tsConfig: tsConfigPath,
noTypeDefinitions: true
});

assert.deepStrictEqual(results, [
path.join(directory, 'b.js'),
path.join(directory, 'c.js'),
path.join(directory, 'a.ts')
]);
})
});
});

Expand Down