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.3.0 to 0.4.0

dist/util/fs.d.ts

19

dist/cli.js

@@ -12,6 +12,7 @@ #!/usr/bin/env node

const config_1 = require("./util/config");
const path_1 = require("./util/path");
const fs_1 = require("./util/fs");
const ignore_1 = require("./util/ignore");
const reporters_1 = __importDefault(require("./reporters"));
const _1 = require(".");
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], dev: isDev = false, 'no-progress': noProgress = false, reporter = 'symbols', jsdoc = [], 'max-issues': maxIssues = '0', }, } = (0, node_util_1.parseArgs)({
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], dev: isDev = false, 'no-progress': noProgress = false, ignore = [], 'no-gitignore': isNoGitIgnore = false, reporter = 'symbols', jsdoc = [], 'max-issues': maxIssues = '0', }, } = (0, node_util_1.parseArgs)({
options: {

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

'max-issues': { type: 'string' },
ignore: { type: 'string', multiple: true },
'no-gitignore': { type: 'boolean' },
'no-progress': { type: 'boolean' },

@@ -41,4 +44,4 @@ reporter: { type: 'string' },

const main = async () => {
const localConfigurationPath = await (0, path_1.findFile)(workingDir, configFilePath);
const manifestPath = await (0, path_1.findFile)(workingDir, 'package.json');
const localConfigurationPath = await (0, fs_1.findFile)(workingDir, configFilePath);
const manifestPath = await (0, fs_1.findFile)(workingDir, 'package.json');
const localConfiguration = localConfigurationPath && require(localConfigurationPath);

@@ -59,3 +62,3 @@ const manifest = manifestPath && require(manifestPath);

let tsConfigPaths = [];
const tsConfigPath = await (0, path_1.findFile)(workingDir, tsConfigFilePath ?? 'tsconfig.json');
const tsConfigPath = await (0, fs_1.findFile)(workingDir, tsConfigFilePath ?? 'tsconfig.json');
if (tsConfigFilePath && !tsConfigPath) {

@@ -77,2 +80,7 @@ console.error(`Unable to find ${tsConfigFilePath}\n`);

}
const ignorePatterns = ignore.map(ignore_1.convertPattern);
if (!isNoGitIgnore) {
const patterns = await (0, ignore_1.readIgnorePatterns)(cwd, workingDir);
patterns.forEach(pattern => ignorePatterns.push(pattern));
}
const config = {

@@ -86,2 +94,3 @@ workingDir,

tsConfigPaths,
ignorePatterns,
isShowProgress,

@@ -88,0 +97,0 @@ jsDocOptions: {

@@ -8,12 +8,14 @@ "use strict";

Options:
-c/--config [file] Configuration file path (default: ./knip.json or package.json#knip)
-t/--tsConfig [file] TypeScript configuration path (default: ./tsconfig.json)
--dir Working directory (default: current working directory)
--include Report only listed issue group(s) (see below)
--exclude Exclude issue group(s) from report (see below)
--dev Include \`devDependencies\` in report(s) (default: false)
--no-progress Don't show dynamic progress updates
--max-issues Maximum number of issues before non-zero exit code (default: 0)
--reporter Select reporter: symbols, compact (default: symbols)
--jsdoc Enable JSDoc parsing, with options: public (default: disabled)
-c/--config [file] Configuration file path (default: ./knip.json or package.json#knip)
-t/--tsConfig [file] TypeScript configuration path (default: ./tsconfig.json)
--dir Working directory (default: current working directory)
--include Report only listed issue group(s) (see below)
--exclude Exclude issue group(s) from report (see below)
--ignore Ignore files matching this glob pattern (can be set multiple times)
--no-gitignore Don't use .gitignore
--dev Include \`devDependencies\` in report(s)
--no-progress Don't show dynamic progress updates
--max-issues Maximum number of issues before non-zero exit code (default: 0)
--reporter Select reporter: symbols, compact (default: symbols)
--jsdoc Enable JSDoc parsing, with options: public

@@ -27,2 +29,3 @@ Issue groups: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates

$ knip -c ./knip.js --reporter compact --jsdoc public
$ knip --ignore 'lib/**/*.ts' --ignore build

@@ -29,0 +32,0 @@ More info: https://github.com/webpro/knip`);

@@ -23,7 +23,7 @@ declare type SymbolType = 'type' | 'interface' | 'enum';

};
export declare type IssueType = keyof Issues;
declare type IssueType = keyof Issues;
export declare type ProjectIssueType = Extract<IssueType, 'files' | 'dependencies' | 'devDependencies'>;
export declare type SymbolIssueType = Exclude<IssueType, ProjectIssueType>;
export declare type IssueGroup = 'files' | 'dependencies' | 'unlisted' | 'exports' | 'nsExports' | 'types' | 'nsTypes' | 'duplicates';
export declare type BaseLocalConfiguration = {
declare type BaseLocalConfiguration = {
entryFiles: string[];

@@ -50,2 +50,3 @@ projectFiles: string[];

tsConfigPaths: string[];
ignorePatterns: string[];
isShowProgress: boolean;

@@ -52,0 +53,0 @@ jsDocOptions: {

@@ -1,1 +0,3 @@

export declare const findFile: (cwd: string, fileName: string) => Promise<string | undefined>;
import type { Configuration } from '../types';
export declare const addWorkingDirToPattern: (workingDir: string, pattern: string) => string;
export declare const resolvePaths: (configuration: Configuration, patterns: string[]) => string[];

@@ -6,24 +6,14 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.findFile = void 0;
const promises_1 = __importDefault(require("node:fs/promises"));
exports.resolvePaths = exports.addWorkingDirToPattern = void 0;
const node_path_1 = __importDefault(require("node:path"));
const isFile = async (filePath) => {
try {
const stats = await promises_1.default.stat(filePath);
return stats.isFile();
}
catch {
return false;
}
const addWorkingDirToPattern = (workingDir, pattern) => {
if (pattern.startsWith('!'))
return '!' + node_path_1.default.join(workingDir, pattern.slice(1));
return node_path_1.default.join(workingDir, pattern);
};
const findFile = async (cwd, fileName) => {
const filePath = node_path_1.default.join(cwd, fileName);
if (await isFile(filePath)) {
return filePath;
}
else {
const parentDir = node_path_1.default.resolve(cwd, '..');
return parentDir === '/' ? undefined : (0, exports.findFile)(parentDir, fileName);
}
exports.addWorkingDirToPattern = addWorkingDirToPattern;
const resolvePaths = (configuration, patterns) => {
const { workingDir } = configuration;
return patterns.map(pattern => (0, exports.addWorkingDirToPattern)(workingDir, pattern));
};
exports.findFile = findFile;
exports.resolvePaths = resolvePaths;
import { Project } from 'ts-morph';
import type { SourceFile } from 'ts-morph';
import type { Configuration } from '../types';
export declare const createProject: (configuration: Configuration, paths?: string | string[]) => Promise<Project>;
export declare const createProject: (configuration: Configuration, paths?: string[]) => Promise<Project>;
export declare const partitionSourceFiles: (projectFiles: SourceFile[], productionFiles: SourceFile[]) => SourceFile[][];
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.partitionSourceFiles = exports.createProject = void 0;
const node_path_1 = __importDefault(require("node:path"));
const ts_morph_1 = require("ts-morph");
const resolvePaths = (cwd, patterns) => {
return [patterns].flat().map(pattern => {
if (pattern.startsWith('!'))
return '!' + node_path_1.default.join(cwd, pattern.slice(1));
return node_path_1.default.join(cwd, pattern);
});
};
const path_1 = require("./path");
const createProject = async (configuration, paths) => {
const { tsConfigFilePath, workingDir } = configuration;
const { tsConfigFilePath, ignorePatterns } = configuration;
const tsConfig = tsConfigFilePath ? { tsConfigFilePath } : { compilerOptions: { allowJs: true } };

@@ -24,4 +14,6 @@ const workspace = new ts_morph_1.Project({

});
if (paths)
workspace.addSourceFilesAtPaths(resolvePaths(workingDir, paths));
if (paths) {
const resolvedPaths = (0, path_1.resolvePaths)(configuration, paths);
workspace.addSourceFilesAtPaths([...resolvedPaths, ...ignorePatterns]);
}
return workspace;

@@ -28,0 +20,0 @@ };

{
"name": "knip",
"version": "0.3.0",
"version": "0.4.0",
"description": "Find unused files and exports in your TypeScript project",

@@ -5,0 +5,0 @@ "keywords": [

@@ -82,12 +82,14 @@ # ✂️ Knip

Options:
-c/--config [file] Configuration file path (default: ./knip.json or package.json#knip)
-t/--tsConfig [file] TypeScript configuration path (default: ./tsconfig.json)
--dir Working directory (default: current working directory)
--include Report only listed issue group(s) (see below)
--exclude Exclude issue group(s) from report (see below)
--dev Include `devDependencies` in report(s) (default: false)
--no-progress Don't show dynamic progress updates
--max-issues Maximum number of issues before non-zero exit code (default: 0)
--reporter Select reporter: symbols, compact (default: symbols)
--jsdoc Enable JSDoc parsing, with options: public (default: disabled)
-c/--config [file] Configuration file path (default: ./knip.json or package.json#knip)
-t/--tsConfig [file] TypeScript configuration path (default: ./tsconfig.json)
--dir Working directory (default: current working directory)
--include Report only listed issue group(s) (see below)
--exclude Exclude issue group(s) from report (see below)
--ignore Ignore files matching this glob pattern (can be set multiple times)
--no-gitignore Don't use .gitignore
--dev Include `devDependencies` in report(s)
--no-progress Don't show dynamic progress updates
--max-issues Maximum number of issues before non-zero exit code (default: 0)
--reporter Select reporter: symbols, compact (default: symbols)
--jsdoc Enable JSDoc parsing, with options: public

@@ -101,2 +103,3 @@ Issue groups: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates

$ knip -c ./knip.js --reporter compact --jsdoc public
$ knip --ignore 'lib/**/*.ts' --ignore build

@@ -103,0 +106,0 @@ More info: https://github.com/webpro/knip

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