Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knip

Package Overview
Dependencies
Maintainers
1
Versions
423
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.10.0 to 0.11.0

dist/util/glob.d.ts

2

dist/help.js

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

--max-issues Maximum number of issues before non-zero exit code (default: 0)
--reporter Select reporter: symbols, compact, codeowners (default: symbols)
--reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
--reporter-options Pass extra options to the reporter (as JSON string, see example)

@@ -22,0 +22,0 @@ --jsdoc Enable JSDoc parsing, with options: public

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

const path_1 = require("./util/path");
const glob_1 = require("./util/glob");
const project_1 = require("./util/project");

@@ -24,2 +25,5 @@ const runner_1 = require("./runner");

const manifest = manifestPath && require(manifestPath);
if (!manifestPath || !manifest) {
throw new errors_1.ConfigurationError('Unable to find package.json');
}
const configFilePath = configFilePathArg ?? 'knip.json';

@@ -59,3 +63,3 @@ const resolvedConfigFilePath = await (0, fs_1.findFile)(cwd, workingDir, configFilePath);

updateMessage('Resolving entry files...');
const entryPaths = await (0, path_1.resolvePaths)({
const entryPaths = await (0, glob_1.glob)({
cwd,

@@ -70,8 +74,8 @@ workingDir,

const entryFiles = production.getSourceFiles();
(0, debug_1.debugLogSourceFiles)(debug, 1, 'Included entry source files', entryFiles);
(0, debug_1.debugLogSourceFiles)(debug, 1, 'Resolved entry source files', entryFiles);
production.resolveSourceFileDependencies();
const productionFiles = production.getSourceFiles();
(0, debug_1.debugLogSourceFiles)(debug, 1, 'Included production source files', productionFiles);
const productionFiles = (0, project_1.removeExternalSourceFiles)(production);
(0, debug_1.debugLogSourceFiles)(debug, 1, 'Resolved production source files', productionFiles);
updateMessage('Resolving project files...');
const projectPaths = await (0, path_1.resolvePaths)({
const projectPaths = await (0, glob_1.glob)({
cwd,

@@ -86,3 +90,3 @@ workingDir,

const projectFiles = project.getSourceFiles();
(0, debug_1.debugLogSourceFiles)(debug, 1, 'Included project source files', projectFiles);
(0, debug_1.debugLogSourceFiles)(debug, 1, 'Resolved project source files', projectFiles);
return { entryFiles, productionFiles, projectFiles };

@@ -105,2 +109,3 @@ }

isIncludeEntryFiles: !resolvedConfig || isIncludeEntryFiles,
manifestPath,
dependencies: Object.keys(manifest.dependencies ?? {}),

@@ -107,0 +112,0 @@ peerDependencies: Object.keys(manifest.peerDependencies ?? {}),

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

...(report.files && { files: false }),
...(report.dependencies && { dependencies: [] }),
...(report.devDependencies && { devDependencies: [] }),
...(report.unlisted && { unlisted: [] }),

@@ -31,0 +33,0 @@ ...((report.exports || report.nsExports) && { exports: [] }),

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

const { entryFiles, productionFiles, projectFiles, isIncludeEntryFiles } = configuration;
const { manifestPath } = configuration;
const updateMessage = (0, progress_1.getMessageUpdater)(configuration);

@@ -29,4 +30,4 @@ const { getUnresolvedDependencies, getUnusedDependencies, getUnusedDevDependencies } = (0, dependencies_1.getDependencyAnalyzer)(configuration);

files: new Set(unreferencedProductionFiles.map(file => file.getFilePath())),
dependencies: new Set(),
devDependencies: new Set(),
dependencies: {},
devDependencies: {},
unlisted: {},

@@ -41,4 +42,4 @@ exports: {},

files: issues.files.size,
dependencies: issues.dependencies.size,
devDependencies: issues.dependencies.size,
dependencies: 0,
devDependencies: 0,
unlisted: 0,

@@ -62,9 +63,2 @@ exports: 0,

};
const addProjectIssue = (issueType, issue) => {
if (!issues[issueType].has(issue.symbol)) {
issues[issueType].add(issue.symbol);
counters[issueType]++;
}
updateCounters(issue);
};
updateMessage('Connecting the dots...');

@@ -181,6 +175,6 @@ if (report.dependencies ||

const unusedDependencies = getUnusedDependencies();
unusedDependencies.forEach(symbol => addProjectIssue('dependencies', { filePath: '', symbol }));
unusedDependencies.forEach(symbol => addSymbolIssue('dependencies', { filePath: manifestPath, symbol }));
if (isDev) {
const unusedDevDependencies = getUnusedDevDependencies();
unusedDevDependencies.forEach(symbol => addProjectIssue('devDependencies', { filePath: '', symbol }));
unusedDevDependencies.forEach(symbol => addSymbolIssue('devDependencies', { filePath: manifestPath, symbol }));
}

@@ -187,0 +181,0 @@ }

@@ -13,4 +13,4 @@ import { SourceFile } from 'ts-morph';

files: IssueSet;
dependencies: IssueSet;
devDependencies: IssueSet;
dependencies: IssueRecords;
devDependencies: IssueRecords;
unlisted: IssueRecords;

@@ -24,4 +24,3 @@ exports: IssueRecords;

export declare type IssueType = keyof Issues;
export declare type ProjectIssueType = Extract<IssueType, 'files' | 'dependencies' | 'devDependencies'>;
export declare type SymbolIssueType = Exclude<IssueType, ProjectIssueType>;
export declare type SymbolIssueType = Exclude<IssueType, 'files'>;
export declare type Report = {

@@ -65,2 +64,3 @@ [key in keyof Issues]: boolean;

isIncludeEntryFiles: boolean;
manifestPath: string;
dependencies: string[];

@@ -67,0 +67,0 @@ peerDependencies: string[];

@@ -19,9 +19,6 @@ "use strict";

return;
console.debug(`[knip] ${name} (${filePaths.length}):`);
if (debug.level > 1) {
console.debug(`[knip] ${name} (${filePaths.length}):`);
logArray(filePaths);
}
else {
console.debug(`[knip] ${name} (${filePaths.length})`);
}
};

@@ -32,9 +29,7 @@ exports.debugLogFiles = debugLogFiles;

return;
console.debug(`[knip] ${name} (${sourceFiles.length})`);
if (debug.level > 1) {
console.debug(`[knip] ${name} (${sourceFiles.length}):`);
logArray(sourceFiles.map(sourceFile => sourceFile.getFilePath()));
const files = sourceFiles.map(sourceFile => sourceFile.getFilePath());
logArray(files);
}
else {
console.debug(`[knip] ${name} (${sourceFiles.length})`);
}
};

@@ -41,0 +36,0 @@ exports.debugLogSourceFiles = debugLogSourceFiles;

export declare const relative: (to: string) => string;
export declare const resolvePaths: ({ cwd, workingDir, patterns, ignore, gitignore, }: {
cwd: string;
workingDir: string;
patterns: string[];
ignore: string[];
gitignore: boolean;
}) => Promise<string[]>;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.resolvePaths = exports.relative = void 0;
exports.relative = void 0;
const node_path_1 = __importDefault(require("node:path"));

@@ -12,21 +12,1 @@ const cwd = process.cwd();

exports.relative = relative;
let _globby;
const glob = async function (patterns, options) {
if (!_globby) {
const { globby } = await eval('import("globby")');
_globby = globby;
}
return _globby(patterns, options);
};
const prependDirToPattern = (workingDir, pattern) => {
if (pattern.startsWith('!'))
return '!' + node_path_1.default.posix.join(workingDir, pattern.slice(1));
return node_path_1.default.posix.join(workingDir, pattern);
};
const resolvePaths = async ({ cwd, workingDir, patterns, ignore, gitignore, }) => glob(patterns.map(pattern => prependDirToPattern(node_path_1.default.posix.relative(cwd, workingDir), pattern)), {
cwd,
ignore: [...ignore, '**/node_modules'],
gitignore,
absolute: true,
});
exports.resolvePaths = resolvePaths;
import { Project } from 'ts-morph';
import type { ProjectOptions, SourceFile } from 'ts-morph';
export declare const createProject: (projectOptions: ProjectOptions, paths?: string[]) => Project;
export declare const removeExternalSourceFiles: (project: Project) => SourceFile[];
export declare const partitionSourceFiles: (projectFiles: SourceFile[], productionFiles: SourceFile[]) => SourceFile[][];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.partitionSourceFiles = exports.createProject = void 0;
exports.partitionSourceFiles = exports.removeExternalSourceFiles = exports.createProject = void 0;
const ts_morph_1 = require("ts-morph");
const createProject = (projectOptions, paths) => {
const workspace = new ts_morph_1.Project(projectOptions);
const project = new ts_morph_1.Project(projectOptions);
if (paths)
workspace.addSourceFilesAtPaths(paths);
return workspace;
project.addSourceFilesAtPaths(paths);
return project;
};
exports.createProject = createProject;
const removeExternalSourceFiles = (project) => project.getSourceFiles().filter(sourceFile => {
if (/\/node_modules\//.test(sourceFile.getFilePath())) {
project.removeSourceFile(sourceFile);
return false;
}
return true;
});
exports.removeExternalSourceFiles = removeExternalSourceFiles;
const partitionSourceFiles = (projectFiles, productionFiles) => {

@@ -13,0 +21,0 @@ const productionFilePaths = productionFiles.map(file => file.getFilePath());

{
"name": "knip",
"version": "0.10.0",
"version": "0.11.0",
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript project",

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

@@ -86,5 +86,6 @@ # ✂️ Knip

--dev Include `devDependencies` in report(s)
--include-entry-files Report unused exports and types for entry files
--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, codeowners (default: symbols)
--reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
--reporter-options Pass extra options to the reporter (as JSON string, see example)

@@ -314,5 +315,18 @@ --jsdoc Enable JSDoc parsing, with options: public

{
"file": "package.json",
"owners": ["@org/admin"],
"files": false,
"dependencies": ["jquery", "moment"],
"devDependencies": [],
"unlisted": [],
"exports": [],
"types": [],
"duplicates": []
},
{
"file": "src/Registration.tsx",
"owners": ["@org/owner"],
"files": true,
"dependencies": [],
"devDependencies": [],
"unlisted": ["react"],

@@ -319,0 +333,0 @@ "exports": ["lowercaseFirstLetter", "RegistrationBox"],

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