ts-unused-exports
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -151,2 +151,17 @@ "use strict"; | ||
}; | ||
var resolvePath = function (rootDir) { return function (path) { | ||
var tsPath = path + ".ts"; | ||
if (fs_1.existsSync(path_1.resolve(rootDir, tsPath))) | ||
return tsPath; | ||
var tsxPath = path + ".tsx"; | ||
if (fs_1.existsSync(path_1.resolve(rootDir, tsxPath))) | ||
return tsxPath; | ||
var tsIndexPath = path + "/index.ts"; | ||
if (fs_1.existsSync(path_1.resolve(rootDir, tsIndexPath))) | ||
return tsIndexPath; | ||
var tsxIndexPath = path + "/index.tsx"; | ||
if (fs_1.existsSync(path_1.resolve(rootDir, tsxIndexPath))) | ||
return tsxIndexPath; | ||
throw "Cannot find module '" + path + "'.\n I've tried the following paths and none of them works:\n - " + tsPath + "\n - " + tsxPath + "\n - " + tsIndexPath + "\n - " + tsxIndexPath + "\n "; | ||
}; }; | ||
var parsePaths = function (rootDir, paths, baseUrl, otherFiles) { | ||
@@ -159,3 +174,3 @@ var files = otherFiles.concat(paths | ||
var missingImports = (_a = []).concat.apply(_a, files.map(function (f) { return Object.keys(f.imports); })).filter(function (i) { return !found[i]; }) | ||
.map(function (i) { return i + ".ts"; }); | ||
.map(resolvePath(rootDir)); | ||
return missingImports.length | ||
@@ -162,0 +177,0 @@ ? parsePaths(rootDir, missingImports, baseUrl, files) |
{ | ||
"name": "ts-unused-exports", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "ts-unused-exports finds unused exported symbols in your Typescript project", | ||
@@ -5,0 +5,0 @@ "main": "lib/app.js", |
@@ -34,2 +34,7 @@ const { join } = require('path'); | ||
it('handles import from directory index', () => { | ||
const result = testWith(['./index-dir/index.ts']); | ||
expect(result).toEqual({}); | ||
}); | ||
describe('indexed modules', () => { | ||
@@ -36,0 +41,0 @@ const testIndex = (paths, expected) => expect( |
@@ -183,2 +183,24 @@ import { existsSync, readFileSync } from 'fs'; | ||
const resolvePath = (rootDir:string) => (path:string):string => { | ||
const tsPath = `${path}.ts`; | ||
if (existsSync(resolve(rootDir, tsPath))) return tsPath; | ||
const tsxPath = `${path}.tsx`; | ||
if (existsSync(resolve(rootDir, tsxPath))) return tsxPath; | ||
const tsIndexPath = `${path}/index.ts`; | ||
if (existsSync(resolve(rootDir, tsIndexPath))) return tsIndexPath; | ||
const tsxIndexPath = `${path}/index.tsx`; | ||
if (existsSync(resolve(rootDir, tsxIndexPath))) return tsxIndexPath; | ||
throw `Cannot find module '${path}'. | ||
I've tried the following paths and none of them works: | ||
- ${tsPath} | ||
- ${tsxPath} | ||
- ${tsIndexPath} | ||
- ${tsxIndexPath} | ||
`; | ||
}; | ||
const parsePaths = ( | ||
@@ -202,3 +224,3 @@ rootDir:string, | ||
.filter(i => !found[i]) | ||
.map(i => `${i}.ts`); | ||
.map(resolvePath(rootDir)); | ||
@@ -205,0 +227,0 @@ return missingImports.length |
223850
53
4842