ts-unused-exports
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -41,3 +41,3 @@ "use strict"; | ||
}; | ||
exports.default = function (files) { | ||
exports.default = (function (files) { | ||
var exportMap = getExportMap(files); | ||
@@ -54,2 +54,2 @@ expandExportFromStar(files, exportMap); | ||
return analysis; | ||
}; | ||
}); |
@@ -26,5 +26,5 @@ "use strict"; | ||
}; | ||
exports.default = function (tsconfigPath, files) { | ||
exports.default = (function (tsconfigPath, files) { | ||
var tsConfig = loadTsConfig(tsconfigPath, files); | ||
return analyzer_1.default(parser_1.default(path_1.dirname(tsconfigPath), tsConfig.files, tsConfig.baseUrl)); | ||
}; | ||
}); |
@@ -81,4 +81,6 @@ "use strict"; | ||
var isRelativeToBaseDir = function (baseDir, from) { | ||
return fs_1.existsSync(path_1.resolve(baseDir, from + ".ts")) | ||
return fs_1.existsSync(path_1.resolve(baseDir, from + ".js")) | ||
|| fs_1.existsSync(path_1.resolve(baseDir, from + ".ts")) | ||
|| fs_1.existsSync(path_1.resolve(baseDir, from + ".tsx")) | ||
|| fs_1.existsSync(path_1.resolve(baseDir, from, 'index.js')) | ||
|| fs_1.existsSync(path_1.resolve(baseDir, from, 'index.ts')) | ||
@@ -159,2 +161,5 @@ || fs_1.existsSync(path_1.resolve(baseDir, from, 'index.tsx')); | ||
return tsxPath; | ||
var jsIndexPath = path + "/index.js"; | ||
if (fs_1.existsSync(path_1.resolve(rootDir, jsIndexPath))) | ||
return jsIndexPath; | ||
var tsIndexPath = path + "/index.ts"; | ||
@@ -166,4 +171,11 @@ if (fs_1.existsSync(path_1.resolve(rootDir, tsIndexPath))) | ||
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 jsPath = path + ".js"; | ||
if (fs_1.existsSync(path_1.resolve(rootDir, jsPath))) | ||
return jsPath; | ||
if (fs_1.existsSync(path_1.resolve(rootDir, path))) { | ||
return null; // we have an explicit path that is *not* a TS (e.g. `.sass`). | ||
} | ||
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 - " + jsPath + "\n - " + path + " (only to skip it later)\n "; | ||
}; }; | ||
var notNull = function (v) { return v !== null; }; | ||
var parsePaths = function (rootDir, paths, baseUrl, otherFiles) { | ||
@@ -176,3 +188,4 @@ 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(resolvePath(rootDir)); | ||
.map(resolvePath(rootDir)) | ||
.filter(notNull); | ||
return missingImports.length | ||
@@ -183,4 +196,4 @@ ? parsePaths(rootDir, missingImports, baseUrl, files) | ||
}; | ||
exports.default = function (rootDir, paths, baseUrl) { | ||
exports.default = (function (rootDir, paths, baseUrl) { | ||
return parsePaths(rootDir, paths, baseUrl, []); | ||
}; | ||
}); |
{ | ||
"name": "ts-unused-exports", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "ts-unused-exports finds unused exported symbols in your Typescript project", | ||
@@ -34,3 +34,3 @@ "main": "lib/app.js", | ||
"jasmine": "^2.4.1", | ||
"tslint": "^4.3.1", | ||
"tslint": "^4.5.1", | ||
"typings": "^1.3.0" | ||
@@ -40,4 +40,4 @@ }, | ||
"strip-json-comments": "^2.0.1", | ||
"typescript": "^2.1.5" | ||
"typescript": "^2.7.2" | ||
} | ||
} |
@@ -27,2 +27,4 @@ const { join } = require('path'); | ||
,'./import-default.ts'], undefined); | ||
itIs('non-ts' , ['./import-other.ts'] , [ 'b', 'c', 'd', 'default' ]); | ||
it('handles export * from', () => { | ||
@@ -100,3 +102,2 @@ const result = testExports(['./import-export-star.ts']); | ||
}); | ||
}); |
@@ -95,4 +95,6 @@ import { existsSync, readFileSync } from 'fs'; | ||
const isRelativeToBaseDir = (baseDir:string, from:string) => | ||
existsSync(resolve(baseDir, `${from}.ts`)) | ||
existsSync(resolve(baseDir, `${from}.js`)) | ||
|| existsSync(resolve(baseDir, `${from}.ts`)) | ||
|| existsSync(resolve(baseDir, `${from}.tsx`)) | ||
|| existsSync(resolve(baseDir, from, 'index.js')) | ||
|| existsSync(resolve(baseDir, from, 'index.ts')) | ||
@@ -184,3 +186,3 @@ || existsSync(resolve(baseDir, from, 'index.tsx')) | ||
const resolvePath = (rootDir:string) => (path:string):string => { | ||
const resolvePath = (rootDir:string) => (path:string):string|null => { | ||
const tsPath = `${path}.ts`; | ||
@@ -192,2 +194,5 @@ if (existsSync(resolve(rootDir, tsPath))) return tsPath; | ||
const jsIndexPath = `${path}/index.js`; | ||
if (existsSync(resolve(rootDir, jsIndexPath))) return jsIndexPath; | ||
const tsIndexPath = `${path}/index.ts`; | ||
@@ -199,2 +204,9 @@ if (existsSync(resolve(rootDir, tsIndexPath))) return tsIndexPath; | ||
const jsPath = `${path}.js`; | ||
if (existsSync(resolve(rootDir, jsPath))) return jsPath; | ||
if (existsSync(resolve(rootDir, path))) { | ||
return null; // we have an explicit path that is *not* a TS (e.g. `.sass`). | ||
} | ||
throw `Cannot find module '${path}'. | ||
@@ -206,5 +218,9 @@ I've tried the following paths and none of them works: | ||
- ${tsxIndexPath} | ||
- ${jsPath} | ||
- ${path} (only to skip it later) | ||
`; | ||
}; | ||
const notNull = <T>(v:T | null): v is T => v !== null; | ||
const parsePaths = ( | ||
@@ -228,3 +244,4 @@ rootDir:string, | ||
.filter(i => !found[i]) | ||
.map(resolvePath(rootDir)); | ||
.map(resolvePath(rootDir)) | ||
.filter(notNull); | ||
@@ -231,0 +248,0 @@ return missingImports.length |
225240
55
4873
Updatedtypescript@^2.7.2