ts-unused-exports
Advanced tools
Comparing version 6.3.0 to 7.0.0
@@ -0,1 +1,10 @@ | ||
## [7.0.0] - 11 Nov 2020 | ||
### Changed | ||
- BREAKING CHANGE: Makes TypeScript a peer dependency (Issue #159) | ||
Migration path: | ||
If you already have a version of the TypeScript compiler installed in the same spot as ts-unused-exports no migration steps are necessary (it will work out of the box). | ||
Otherwise you'll have to install the TypeScript compiler there yourself (e.g. with `npm i -D typescript`). | ||
## [6.3.0] - 11 Nov 2020 | ||
@@ -50,3 +59,3 @@ | ||
- Handle dynamic imports within a TSX div or fragment | ||
- Add basic support for export * as namespace. | ||
- Add basic support for export \* as namespace. | ||
@@ -53,0 +62,0 @@ ## [6.1.2] - 1 Apr 2020 |
@@ -40,18 +40,3 @@ "use strict"; | ||
}; | ||
var processImportsOfExportedAsNamespace = function (file, exportMap) { | ||
/* Basic support for export-as-namespace. | ||
* If a file is exported as a namespace, and that namespace is imported, | ||
* then we mark *all* exports of that file as used. | ||
* A more accurate analysis would require scanning for all usages of the exports, via that namespace. | ||
*/ | ||
file.pathsExportedAsNamespace.forEach(function (exportedAsNamespace) { | ||
var _a; | ||
var what = (_a = exportMap[exportedAsNamespace]) === null || _a === void 0 ? void 0 : _a.exports; | ||
if (what) { | ||
Object.keys(what).forEach(function (exported) { return what[exported].usageCount++; }); | ||
} | ||
}); | ||
}; | ||
var processImports = function (file, exportMap) { | ||
processImportsOfExportedAsNamespace(file, exportMap); | ||
Object.keys(file.imports).forEach(function (key) { | ||
@@ -99,15 +84,16 @@ var _a, _b; | ||
}; | ||
var expandExportFromStar = function (files, exportMap) { | ||
files.forEach(function (file) { | ||
var fileExports = exportMap[file.path]; | ||
file.exports | ||
.filter(function (ex) { return ex.startsWith('*:'); }) | ||
.forEach(function (ex) { | ||
var _a; | ||
delete fileExports.exports[ex]; | ||
var exports = (_a = exportMap[util_1.cleanRelativePath(ex)]) === null || _a === void 0 ? void 0 : _a.exports; | ||
if (exports) { | ||
Object.keys(exports) | ||
.filter(function (e) { return e != 'default'; }) | ||
.forEach(function (key) { | ||
var expandExportFromStarOrStarAsForFile = function (file, exportMap, prefix, isWithAlias) { | ||
var fileExports = exportMap[file.path]; | ||
file.exports | ||
.filter(function (ex) { return ex.startsWith(prefix); }) | ||
.forEach(function (ex) { | ||
var _a; | ||
delete fileExports.exports[ex]; | ||
var exports = (_a = exportMap[util_1.removeExportStarPrefix(ex)]) === null || _a === void 0 ? void 0 : _a.exports; | ||
if (exports) { | ||
Object.keys(exports) | ||
.filter(function (e) { return e != 'default'; }) | ||
.forEach(function (key) { | ||
if (!isWithAlias) { | ||
// Copy the exports from the imported file: | ||
if (!fileExports.exports[key]) { | ||
@@ -121,7 +107,27 @@ var export1 = exports[key]; | ||
fileExports.exports[key].usageCount = 0; | ||
}); | ||
} | ||
}); | ||
} | ||
// else is export-as: so this file exports a new namespace. | ||
// Mark the items as imported, for the imported file: | ||
var importedFileExports = exportMap[util_1.removeExportStarPrefix(ex)]; | ||
if (importedFileExports) { | ||
importedFileExports.exports[key].usageCount++; | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
// export * from 'a' (no 'alias') | ||
var expandExportFromStarForFile = function (file, exportMap) { | ||
expandExportFromStarOrStarAsForFile(file, exportMap, '*:', false); | ||
}; | ||
// export * as X from 'a' (has 'alias') | ||
var expandExportFromStarAsForFile = function (file, exportMap) { | ||
expandExportFromStarOrStarAsForFile(file, exportMap, '*as:', true); | ||
}; | ||
var expandExportFromStar = function (files, exportMap) { | ||
files.forEach(function (file) { | ||
expandExportFromStarForFile(file, exportMap); | ||
expandExportFromStarAsForFile(file, exportMap); | ||
}); | ||
}; | ||
// Allow disabling of *results*, by path from command line (useful for large projects) | ||
@@ -128,0 +134,0 @@ var shouldPathBeExcludedFromResults = function (path, extraOptions) { |
@@ -14,2 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hasValidArgs = exports.extractOptionsFromFiles = void 0; | ||
var fs_1 = require("fs"); | ||
@@ -16,0 +17,0 @@ function processOptions(filesAndOptions, options) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.runCli = void 0; | ||
var chalk = require("chalk"); | ||
@@ -4,0 +5,0 @@ var app_1 = require("./app"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNodeDisabledViaComment = void 0; | ||
var ts = require("typescript"); | ||
@@ -4,0 +5,0 @@ // Parse Comments (that can disable ts-unused-exports) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getFrom = exports.getFromText = exports.STAR = void 0; | ||
exports.STAR = ['*']; | ||
@@ -4,0 +5,0 @@ var TRIM_QUOTES = /^['"](.*)['"]$/; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addDynamicImports = exports.mayContainDynamicImports = void 0; | ||
var ts = require("typescript"); | ||
@@ -4,0 +5,0 @@ var common_1 = require("./common"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addExportCore = exports.extractExportNames = exports.extractExportFromImport = exports.extractExportStatement = void 0; | ||
var ts = require("typescript"); | ||
@@ -4,0 +5,0 @@ var common_1 = require("./common"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addImportCore = exports.extractImport = void 0; | ||
var common_1 = require("./common"); | ||
@@ -62,11 +63,16 @@ var path_1 = require("path"); | ||
var matchedPath = void 0; | ||
return isRelativeToBaseDir(baseDir, from) | ||
? path_1.join(baseUrl, from) | ||
: tsconfigPathsMatcher && | ||
(matchedPath = tsconfigPathsMatcher(from, undefined, undefined, EXTENSIONS)) | ||
? declarationFilePatch(matchedPath).replace("" + baseDir + path_1.sep, '') | ||
: undefined; | ||
if (isRelativeToBaseDir(baseDir, from)) { | ||
return path_1.join(baseUrl, from); | ||
} | ||
if (tsconfigPathsMatcher && | ||
(matchedPath = tsconfigPathsMatcher(from, undefined, undefined, EXTENSIONS))) { | ||
var absoluteRootDir = path_1.resolve(rootDir); | ||
return declarationFilePatch(matchedPath) | ||
.replace("" + absoluteRootDir + path_1.sep, '') | ||
.replace("" + baseDir + path_1.sep, ''); | ||
} | ||
return from; | ||
} | ||
}; | ||
var key = getKey(from) || from; | ||
var key = getKey(from); | ||
var items = imports[key] || []; | ||
@@ -73,0 +79,0 @@ imports[key] = items.concat(what).filter(util_1.isUnique); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addImportsFromNamespace = void 0; | ||
var namespaceBlacklist_1 = require("./namespaceBlacklist"); | ||
@@ -4,0 +5,0 @@ var getPossibleImportedNamespaces = function (imports) { |
@@ -8,3 +8,2 @@ "use strict"; | ||
var import_1 = require("./import"); | ||
var util_1 = require("./util"); | ||
var comment_1 = require("./comment"); | ||
@@ -30,7 +29,3 @@ var nodeProcessor_1 = require("./nodeProcessor"); | ||
var tsconfigPathsMatcher = (!!paths && tsconfigPaths.createMatchPath(baseDir, paths)) || undefined; | ||
var pathsExportedAsNamespace = []; | ||
var addImport = function (fw) { | ||
if (fw.isExportStarAs) { | ||
pathsExportedAsNamespace.push(util_1.cleanRelativePath(fw.from)); | ||
} | ||
return import_1.addImportCore(fw, rootDir, path, imports, baseDir, baseUrl, tsconfigPathsMatcher); | ||
@@ -53,3 +48,2 @@ }; | ||
exportLocations: exportLocations, | ||
pathsExportedAsNamespace: pathsExportedAsNamespace, | ||
}; | ||
@@ -56,0 +50,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.namespaceBlacklist = void 0; | ||
var ts = require("typescript"); | ||
@@ -4,0 +5,0 @@ // A blacklist of node kinds that do NOT need to be searched for namespace usages. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.processNode = void 0; | ||
var ts = require("typescript"); | ||
@@ -28,3 +29,6 @@ var common_1 = require("./common"); | ||
} | ||
else { | ||
if (what != common_1.STAR) { | ||
if (imported.isExportStarAs) { | ||
addExport("*as:" + key, node); | ||
} | ||
what.forEach(function (w) { return exportNames.push(w); }); | ||
@@ -31,0 +35,0 @@ } |
import ts = require('typescript'); | ||
export declare function isUnique<T>(value: T, index: number, self: T[]): boolean; | ||
export declare function cleanRelativePath(path: string): string; | ||
export declare function removeExportStarPrefix(path: string): string; | ||
export declare function recurseIntoChildren(next: ts.Node, fun: (node: ts.Node) => boolean): boolean; | ||
export declare function findAllChildrenOfKind(node: ts.Node, kind: ts.SyntaxKind): ts.Node[]; | ||
export declare function findFirstChildOfKind(node: ts.Node, kind: ts.SyntaxKind): ts.Node | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.findFirstChildOfKind = exports.findAllChildrenOfKind = exports.recurseIntoChildren = exports.removeExportStarPrefix = exports.isUnique = void 0; | ||
var ts = require("typescript"); | ||
@@ -9,6 +10,10 @@ var namespaceBlacklist_1 = require("./namespaceBlacklist"); | ||
exports.isUnique = isUnique; | ||
function cleanRelativePath(path) { | ||
return path.slice(2); | ||
function removeExportStarPrefix(path) { | ||
if (path.startsWith('*:')) | ||
return path.slice(2); | ||
else if (path.startsWith('*as:')) | ||
return path.slice(4); | ||
return path; | ||
} | ||
exports.cleanRelativePath = cleanRelativePath; | ||
exports.removeExportStarPrefix = removeExportStarPrefix; | ||
// A whitelist, to over-ride namespaceBlacklist. | ||
@@ -15,0 +20,0 @@ // |
@@ -10,3 +10,2 @@ export interface Imports { | ||
exportLocations: LocationInFile[]; | ||
pathsExportedAsNamespace: string[]; | ||
} | ||
@@ -13,0 +12,0 @@ export interface LocationInFile { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.USAGE = void 0; | ||
exports.USAGE = "\n usage: ts-unused-exports path/to/tsconfig.json [file1.ts file2.ts] [options]\n \n where options are any of:\n --allowUnusedEnums\n --allowUnusedTypes\n --excludeDeclarationFiles\n --excludePathsFromReport=path1;path2\n --exitWithCount\n --exitWithUnusedTypesCount\n --ignoreFiles=<regex>\n --ignoreProductionFiles\n --ignoreTestFiles\n --maxIssues\n --searchNamespaces\n --showLineNumber\n --silent\n\n Note: if no file is specified after tsconfig, the files will be read from the\n tsconfig's \"files\" key which must be present.\n\n If the files are specified, their path must be relative to the tsconfig file.\n For example, given:\n /\n |-- config\n | -- tsconfig.json\n -- src\n -- file.ts\n\n Then the usage would be:\n ts-unused-exports config/tsconfig.json ../src/file.ts\n "; | ||
//# sourceMappingURL=usage.js.map |
{ | ||
"name": "ts-unused-exports", | ||
"version": "6.3.0", | ||
"version": "7.0.0", | ||
"description": "ts-unused-exports finds unused exported symbols in your Typescript project", | ||
@@ -53,9 +53,17 @@ "main": "lib/app.js", | ||
"prettier": "^1.19.1", | ||
"ts-node": "^8.8.1" | ||
"ts-node": "^8.8.1", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"chalk": "^3.0.0", | ||
"tsconfig-paths": "^3.9.0", | ||
"typescript": "^3.8.3" | ||
"tsconfig-paths": "^3.9.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": ">=3.8.3" | ||
}, | ||
"peerDependenciesMeta": { | ||
"typescript": { | ||
"optional": false | ||
} | ||
} | ||
} |
@@ -76,2 +76,4 @@ # ts-unused-exports | ||
As of version 7.0.0 the TypeScript compiler is a _peer dependency_ of `ts-unused-exports`. This means that if the TypeScript compiler is not already in the same spot as `ts-unused-exports`, you have to install it yourself (e.g. with `npm i -D typescript`). | ||
## Why should I use this? | ||
@@ -78,0 +80,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
122286
1584
181
14
+ Addedtypescript@5.8.2(transitive)
- Removedtypescript@^3.8.3
- Removedtypescript@3.9.10(transitive)