New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-unused-exports

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-unused-exports - npm Package Compare versions

Comparing version 9.0.3 to 9.0.4

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [9.0.4] - 12 Feb 2023
### Changed
- Improve handling of transitive imports like 'a -> b -> c' especially where 'export *' is used - #216
- Improve output format when the unused item involves an 'export *'.
## [9.0.3] - 5 Feb 2023

@@ -2,0 +9,0 @@

4

lib/analyzer.d.ts

@@ -1,4 +0,4 @@

import { Analysis, ExtraCommandLineOptions, File } from './types';
import { Analysis, ExtraCommandLineOptions, ExtraOptionsForPresentation, File } from './types';
export { Analysis } from './types';
declare const _default: (files: File[], extraOptions?: ExtraCommandLineOptions | undefined) => Analysis;
declare const _default: (files: File[], extraOptions?: (ExtraCommandLineOptions & ExtraOptionsForPresentation) | undefined) => Analysis;
export default _default;

@@ -31,3 +31,3 @@ "use strict";

});
return { exports: exports, path: file.fullPath };
return { exports: exports, path: file.fullPath, fileWasImported: false };
};

@@ -43,4 +43,5 @@ var getExportMap = function (files) {

Object.keys(file.imports).forEach(function (key) {
var _a, _b, _c, _d;
var ex = (_a = exportMap[util_1.removeFileExtensionToAllowForJs(key)]) === null || _a === void 0 ? void 0 : _a.exports;
var _a, _b, _c;
var importedFileExports = exportMap[util_1.removeFileExtensionToAllowForJs(key)] || null;
var ex = (importedFileExports === null || importedFileExports === void 0 ? void 0 : importedFileExports.exports) || null;
// Handle imports from an index file

@@ -51,3 +52,3 @@ if (!ex) {

var indexKey = util_1.indexCandidates[c];
ex = ((_b = exportMap[indexKey]) === null || _b === void 0 ? void 0 : _b.exports) || undefined;
ex = ((_a = exportMap[indexKey]) === null || _a === void 0 ? void 0 : _a.exports) || undefined;
if (ex)

@@ -60,3 +61,3 @@ break;

var indexKey = key + util_1.indexCandidateExtensions[c];
ex = ((_c = exportMap[indexKey]) === null || _c === void 0 ? void 0 : _c.exports) || undefined;
ex = ((_b = exportMap[indexKey]) === null || _b === void 0 ? void 0 : _b.exports) || undefined;
if (ex)

@@ -68,3 +69,3 @@ break;

var indexKey = key.substring(0, key.length - '/index'.length);
ex = ((_d = exportMap[indexKey]) === null || _d === void 0 ? void 0 : _d.exports) || undefined;
ex = ((_c = exportMap[indexKey]) === null || _c === void 0 ? void 0 : _c.exports) || undefined;
}

@@ -93,4 +94,8 @@ }

}
// DEV DEBUG - console.log(`Marking as used: ${imp} in ${file.path}`);
ex[imp].usageCount++;
};
if (!!importedFileExports) {
importedFileExports.fileWasImported = true;
}
file.imports[key].forEach(function (imp) {

@@ -128,2 +133,8 @@ imp === '*' ? Object.keys(ex).forEach(addUsage) : addUsage(imp);

if (importedFileExports) {
// DEV DEBUG
/* console.log(
`Marking as used: ${key} in ${removeExportStarPrefix(ex)}`,
);
console.dir(Object.keys(exportMap));*/
importedFileExports.fileWasImported = true;
importedFileExports.exports[key].usageCount++;

@@ -176,2 +187,12 @@ }

};
var makeExportStarRelativeForPresentation = function (baseUrl, filePath) {
if (!filePath.startsWith('*')) {
return filePath;
}
var filePathNoStar = util_1.removeExportStarPrefix(filePath);
if (!!baseUrl && filePathNoStar.startsWith(baseUrl)) {
return "* -> " + filePathNoStar.substring(baseUrl.length);
}
return filePath;
};
exports.default = (function (files, extraOptions) {

@@ -189,3 +210,10 @@ var filteredFiles = filterFiles(files, extraOptions);

return;
var unusedExports = Object.keys(exports).filter(function (k) { return exports[k].usageCount === 0; });
var unusedExports = Object.keys(exports).filter(function (k) {
// If the file was imported at least once, then do NOT consider any of its 'export (import) *' as unused.
// This avoids false positives with transitive import/exports like a -> b -> c.
if (expItem.fileWasImported && k.startsWith('*')) {
return false;
}
return exports[k].usageCount === 0;
});
if (unusedExports.length === 0) {

@@ -198,3 +226,3 @@ return;

analysis[path].push({
exportName: e,
exportName: makeExportStarRelativeForPresentation(extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.baseUrl, e),
location: exports[e].location,

@@ -201,0 +229,0 @@ });

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -39,4 +50,5 @@ var ts = require("typescript");

var tsConfig = loadTsConfig(tsconfigPath, args.tsFiles);
return analyzer_1.default(parser_1.default(tsConfig, args.options), args.options);
var options = __assign(__assign({}, args.options), { baseUrl: tsConfig.baseUrl });
return analyzer_1.default(parser_1.default(tsConfig, args.options), options);
});
//# sourceMappingURL=app.js.map

@@ -49,2 +49,5 @@ export interface Imports {

}
export interface ExtraOptionsForPresentation {
baseUrl?: string;
}
export {};
{
"name": "ts-unused-exports",
"version": "9.0.3",
"version": "9.0.4",
"description": "ts-unused-exports finds unused exported symbols in your Typescript project",

@@ -24,2 +24,3 @@ "main": "lib/app.js",

"scripts": {
"bump": "npm version patch",
"build": "tsc",

@@ -26,0 +27,0 @@ "exec": "bin/ts-unused-exports",

@@ -185,2 +185,8 @@ # ts-unused-exports

## Tooling
### eslint plugins
`ts-unused-exports` can also be executed via this [eslint plugin](https://github.com/gajus/eslint-plugin-canonical#no-unused-exports) by Gajus Kuizinas.
## Changelog (Release History)

@@ -187,0 +193,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc