Socket
Socket
Sign inDemoInstall

knip

Package Overview
Dependencies
Maintainers
1
Versions
407
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knip - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

dist/util/debug.d.ts

8

dist/cli.js

@@ -13,3 +13,3 @@ #!/usr/bin/env node

const errors_1 = require("./util/errors");
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'no-progress': noProgress = false, reporter = 'symbols', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], }, } = (0, node_util_1.parseArgs)({
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'no-progress': noProgress = false, reporter = 'symbols', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], debug: isDebug = false, 'debug-level': debugLevel = '1', }, } = (0, node_util_1.parseArgs)({
options: {

@@ -29,2 +29,4 @@ help: { type: 'boolean' },

jsdoc: { type: 'string', multiple: true },
debug: { type: 'boolean' },
'debug-level': { type: 'string' },
},

@@ -54,2 +56,6 @@ });

jsDoc,
debug: {
isEnabled: isDebug,
level: isDebug ? Number(debugLevel) : 0,
},
});

@@ -56,0 +62,0 @@ printReport({ report, issues, workingDir, isDev });

@@ -20,2 +20,4 @@ "use strict";

--jsdoc Enable JSDoc parsing, with options: public
--debug Show debug output
--debug-level Set verbosity of debug output (default: 1, max: 2)

@@ -22,0 +24,0 @@ Issue groups: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates

@@ -15,4 +15,6 @@ "use strict";

const errors_1 = require("./util/errors");
const debug_1 = require("./util/debug");
const main = async (options) => {
const { cwd, workingDir, configFilePath = 'knip.json', tsConfigFilePath, include, exclude, ignore, gitignore, isDev, isShowProgress, jsDoc, } = options;
const { cwd, workingDir, configFilePath = 'knip.json', tsConfigFilePath, include, exclude, ignore, gitignore, isDev, isShowProgress, jsDoc, debug, } = options;
(0, debug_1.debugLogObject)(options, 1, 'Unresolved onfiguration', options);
const localConfigurationPath = configFilePath && (await (0, fs_1.findFile)(workingDir, configFilePath));

@@ -28,2 +30,3 @@ const manifestPath = await (0, fs_1.findFile)(workingDir, 'package.json');

const resolvedConfig = (0, config_1.resolveConfig)(manifest.knip ?? localConfiguration, { workingDir: dir, isDev });
(0, debug_1.debugLogObject)(options, 1, 'Resolved onfiguration', resolvedConfig);
if (!resolvedConfig) {

@@ -55,6 +58,9 @@ throw new errors_1.ConfigurationError('Unable to find `entryFiles` and/or `projectFiles` in configuration.');

});
(0, debug_1.debugLogFiles)(options, 1, 'Globbed entry paths', entryPaths);
const production = (0, project_1.createProject)({ projectOptions, paths: entryPaths });
const entryFiles = production.getSourceFiles();
(0, debug_1.debugLogSourceFiles)(options, 1, 'Included entry source files', entryFiles);
production.resolveSourceFileDependencies();
const productionFiles = production.getSourceFiles();
(0, debug_1.debugLogSourceFiles)(options, 1, 'Included production source files', productionFiles);
const projectPaths = await (0, path_1.resolvePaths)({

@@ -67,4 +73,6 @@ cwd,

});
(0, debug_1.debugLogFiles)(options, 1, 'Globbed project paths', projectPaths);
const project = (0, project_1.createProject)({ projectOptions, paths: projectPaths });
const projectFiles = project.getSourceFiles();
(0, debug_1.debugLogSourceFiles)(options, 1, 'Included project source files', projectFiles);
const config = {

@@ -84,6 +92,8 @@ workingDir,

},
debug,
};
const { issues, counters } = await (0, runner_1.findIssues)(config);
(0, debug_1.debugLogObject)(options, 2, 'Issues', issues);
return { report, issues, counters };
};
exports.main = main;

12

dist/runner.js

@@ -14,2 +14,3 @@ "use strict";

const log_1 = require("./log");
const debug_1 = require("./util/debug");
const lineRewriter = new log_1.LineRewriter();

@@ -22,2 +23,6 @@ async function findIssues(configuration) {

const [usedEntryFiles, usedNonEntryFiles] = (0, project_1.partitionSourceFiles)(usedProductionFiles, entryFiles);
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'usedProductionFiles', usedProductionFiles);
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'unreferencedProductionFiles', unreferencedProductionFiles);
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'usedEntryFiles', usedEntryFiles);
(0, debug_1.debugLogSourceFiles)(configuration, 1, 'usedNonEntryFiles', usedNonEntryFiles);
const issues = {

@@ -49,4 +54,4 @@ files: new Set(unreferencedProductionFiles.map(file => file.getFilePath())),

return;
const counter = unreferencedProductionFiles.length + counters.processed;
const total = unreferencedProductionFiles.length + usedNonEntryFiles.length;
const counter = counters.processed;
const total = projectFiles.length;
const percentage = Math.floor((counter / total) * 100);

@@ -84,2 +89,3 @@ const messages = [(0, log_1.getLine)(`${percentage}%`, `of files processed (${counter} of ${total})`)];

usedEntryFiles.forEach(sourceFile => {
counters.processed++;
const unresolvedDependencies = getUnresolvedDependencies(sourceFile);

@@ -97,2 +103,3 @@ unresolvedDependencies.forEach(issue => addSymbolIssue('unresolved', issue));

usedNonEntryFiles.forEach(sourceFile => {
counters.processed++;
const filePath = sourceFile.getFilePath();

@@ -183,3 +190,2 @@ if (report.dependencies || report.unlisted) {

}
counters.processed++;
});

@@ -186,0 +192,0 @@ }

@@ -50,2 +50,6 @@ import { SourceFile } from 'ts-morph';

jsDoc: string[];
debug: {
isEnabled: boolean;
level: number;
};
};

@@ -69,3 +73,7 @@ export declare type Report = {

};
debug: {
isEnabled: boolean;
level: number;
};
};
export {};
{
"name": "knip",
"version": "0.4.2",
"description": "Find unused files and exports in your TypeScript project",
"version": "0.5.0",
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript project",
"keywords": [

@@ -9,3 +9,5 @@ "find",

"unused",
"unreferenced",
"files",
"dependencies",
"exports",

@@ -12,0 +14,0 @@ "types",

@@ -96,2 +96,4 @@ # ✂️ Knip

--jsdoc Enable JSDoc parsing, with options: public
--debug Show debug output
--debug-level Set verbosity of debug output (default: 1, max: 2)

@@ -98,0 +100,0 @@ Issue groups: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates

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