knip 3.13.0 → 3.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,14 +5,13 @@ export const ENABLERS = ['next'];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
6
  export const ENTRY_FILE_PATTERNS = ['next.config.{js,ts,cjs,mjs}'];
7
7
  const productionEntryFilePatternsWithoutSrc = [
8
- 'middleware.{js,ts}',
9
- 'app/**/route.{js,ts}',
8
+ '{instrumentation,middleware}.{js,ts}',
10
9
  'app/global-error.{js,jsx,ts,tsx}',
11
10
  'app/**/{error,layout,loading,not-found,page,template}.{js,jsx,ts,tsx}',
12
- 'instrumentation.{js,ts}',
11
+ 'app/**/{route,default}.{js,ts}',
13
12
  'app/{manifest,sitemap,robots}.{js,ts}',
14
- 'app/**/{icon,apple-icon}.{js,ts,tsx}',
15
- 'app/**/{opengraph,twitter}-image.{js,ts,tsx}',
13
+ 'app/**/{icon,apple-icon}.{js,jsx,ts,tsx}',
14
+ 'app/**/{opengraph,twitter}-image.{js,jsx,ts,tsx}',
16
15
  'pages/**/*.{js,jsx,ts,tsx}',
17
16
  ];
18
17
  export const PRODUCTION_ENTRY_FILE_PATTERNS = [
@@ -1,23 +1,29 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  import { toEntryPattern } from '../../util/protocols.js';
4
5
  export const NAME = 'tsup';
5
6
  export const ENABLERS = ['tsup'];
6
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- export const CONFIG_FILE_PATTERNS = ['tsup.config.js'];
8
- const findTsupDependencies = async (configFilePath) => {
9
- let localConfig = await load(configFilePath);
8
+ export const CONFIG_FILE_PATTERNS = ['tsup.config.{js,ts,cjs,json}', 'package.json'];
9
+ const findTsupDependencies = async (configFilePath, options) => {
10
+ const { manifest } = options;
11
+ let localConfig = basename(configFilePath) === 'package.json' ? manifest.tsup : await load(configFilePath);
10
12
  if (typeof localConfig === 'function')
11
13
  localConfig = await localConfig({});
12
14
  if (!localConfig)
13
15
  return [];
14
- const entryPatterns = [localConfig].flat().flatMap(config => {
16
+ const entryPatterns = [localConfig]
17
+ .flat()
18
+ .flatMap(config => {
15
19
  if (!config.entry)
16
20
  return [];
17
21
  if (Array.isArray(config.entry))
18
- return config.entry.map(toEntryPattern);
19
- return Object.values(config.entry).map(toEntryPattern);
20
- });
22
+ return config.entry;
23
+ return Object.values(config.entry);
24
+ })
25
+ .filter(entry => !entry.startsWith('!'))
26
+ .map(toEntryPattern);
21
27
  return entryPatterns;
22
28
  };
23
29
  export const findDependencies = timerify(findTsupDependencies);
@@ -1,14 +1,14 @@
1
1
  import { compact } from '../../util/array.js';
2
2
  import { dirname, isInternal, toAbsolute } from '../../util/path.js';
3
3
  import { timerify } from '../../util/Performance.js';
4
- import { hasDependency, load } from '../../util/plugin.js';
4
+ import { hasDependency, loadJSON } from '../../util/plugin.js';
5
5
  import { loadTSConfig } from '../../util/tsconfig-loader.js';
6
6
  export const NAME = 'TypeScript';
7
7
  export const ENABLERS = ['typescript'];
8
8
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
9
9
  export const CONFIG_FILE_PATTERNS = ['tsconfig.json', 'tsconfig.*.json'];
10
10
  const resolveExtensibleConfig = async (configFilePath) => {
11
- const localConfig = await load(configFilePath);
11
+ const localConfig = await loadJSON(configFilePath);
12
12
  if (!localConfig)
13
13
  return;
14
14
  localConfig.extends = localConfig.extends ? [localConfig.extends].flat() : [];
@@ -1,11 +1,11 @@
1
1
  import { OwnershipEngine } from '@snyk/github-codeowners/dist/lib/ownership/index.js';
2
- import chalk from 'chalk';
2
+ import picocolors from 'picocolors';
3
3
  import { toRelative, relative, resolve } from '../util/path.js';
4
4
  import { getTitle, logTitle, logIssueLine } from './util.js';
5
5
  const logIssueSet = (issues) => {
6
6
  issues
7
7
  .sort((a, b) => (a.owner < b.owner ? -1 : 1))
8
- .forEach(issue => console.log(chalk.cyan(issue.owner), toRelative(issue.symbol)));
8
+ .forEach(issue => console.log(picocolors.cyan(issue.owner), toRelative(issue.symbol)));
9
9
  };
10
10
  const logIssueRecord = (issues) => {
11
11
  const sortedByFilePath = issues.sort((a, b) => (a.owner < b.owner ? -1 : 1));
@@ -1,5 +1,5 @@
1
- import chalk from 'chalk';
2
1
  import EasyTable from 'easy-table';
2
+ import picocolors from 'picocolors';
3
3
  import { ROOT_WORKSPACE_NAME } from '../constants.js';
4
4
  import { relative } from '../util/path.js';
5
5
  import { getTitle, logTitle, logIssueSet, identity } from './util.js';
@@ -8,7 +8,7 @@ const truncate = (text) => (text.length > TRUNCATE_WIDTH ? text.slice(0, TRUNCAT
8
8
  const logIssueRecord = (issues) => {
9
9
  const table = new EasyTable();
10
10
  issues.forEach(issue => {
11
- const print = issue.severity === 'warn' ? chalk.grey : identity;
11
+ const print = issue.severity === 'warn' ? picocolors.gray : identity;
12
12
  table.cell('symbol', print(issue.symbols ? truncate(issue.symbols.map(s => s.symbol).join(', ')) : issue.symbol));
13
13
  issue.parentSymbol && table.cell('parentSymbol', print(issue.parentSymbol));
14
14
  issue.symbolType && table.cell('symbolType', print(issue.symbolType));
@@ -46,7 +46,7 @@ export default ({ report, issues, configurationHints, noConfigHints, isShowProgr
46
46
  const { type, workspaceName, identifier } = hint;
47
47
  const message = `Unused item in ${type}`;
48
48
  const workspace = workspaceName && workspaceName !== ROOT_WORKSPACE_NAME ? ` (workspace: ${workspaceName})` : ``;
49
- console.warn(chalk.grey(`${message}${workspace}:`), identifier);
49
+ console.warn(picocolors.gray(`${message}${workspace}:`), identifier);
50
50
  });
51
51
  }
52
52
  if (totalIssues === 0 && isShowProgress) {
@@ -1,16 +1,16 @@
1
- import chalk from 'chalk';
1
+ import picocolors from 'picocolors';
2
2
  import { ISSUE_TYPE_TITLE } from '../constants.js';
3
3
  import { toRelative, relative } from '../util/path.js';
4
4
  export const identity = (text) => text;
5
5
  export const getTitle = (reportType) => {
6
6
  return ISSUE_TYPE_TITLE[reportType];
7
7
  };
8
- export const logTitle = (title, count) => console.log(`${chalk.bold.yellow.underline(title)} (${count})`);
8
+ export const logTitle = (title, count) => console.log(`${picocolors.bold(picocolors.yellow(picocolors.underline(title)))} (${count})`);
9
9
  export const logIssueLine = ({ owner, filePath, symbols, parentSymbol, severity }) => {
10
10
  const symbol = symbols ? `: ${symbols.map(s => s.symbol).join(', ')}` : '';
11
11
  const parent = parentSymbol ? ` (${parentSymbol})` : '';
12
- const print = severity === 'warn' ? chalk.grey : identity;
13
- console.log(`${owner ? `${chalk.cyan(owner)} ` : ''}${print(`${relative(filePath)}${symbol}${parent}`)}`);
12
+ const print = severity === 'warn' ? picocolors.gray : identity;
13
+ console.log(`${owner ? `${picocolors.cyan(owner)} ` : ''}${print(`${relative(filePath)}${symbol}${parent}`)}`);
14
14
  };
15
15
  export const logIssueSet = (issues) => {
16
16
  issues.sort().forEach(value => console.log(toRelative(value)));
@@ -1,10 +1,10 @@
1
1
  import util from 'node:util';
2
- import chalk from 'chalk';
2
+ import picocolors from 'picocolors';
3
3
  import parsedArgValues from './cli-arguments.js';
4
4
  const { debug } = parsedArgValues;
5
5
  const IS_ENABLED = debug ?? false;
6
6
  const inspectOptions = { maxArrayLength: null, depth: null, colors: true };
7
- const ctx = (text) => typeof text === 'string' ? chalk.yellow(`[${text}]`) : `${chalk.yellow(`[${text[0]}]`)} ${chalk.cyan(text[1])}`;
7
+ const ctx = (text) => typeof text === 'string' ? picocolors.yellow(`[${text}]`) : `${picocolors.yellow(`[${text[0]}]`)} ${picocolors.cyan(text[1])}`;
8
8
  const logArray = (collection) => {
9
9
  console.log(util.inspect(collection.sort(), inspectOptions));
10
10
  };
package/dist/util/fs.d.ts CHANGED
@@ -7,3 +7,4 @@ export declare const loadYAML: (filePath: string) => Promise<unknown>;
7
7
  export declare const parseJSON: (filePath: string, contents: string) => Promise<any>;
8
8
  export declare const parseYAML: (contents: string) => Promise<unknown>;
9
9
  export declare function isTypeModule(path: string): boolean;
10
+ export declare const _loadJSON: (filePath: string) => Promise<any>;
package/dist/util/fs.js CHANGED
@@ -3,7 +3,9 @@ import { readFile } from 'node:fs/promises';
3
3
  import yaml from 'js-yaml';
4
4
  import stripJsonComments from 'strip-json-comments';
5
5
  import { LoaderError } from './errors.js';
6
+ import { FAKE_PATH } from './loader.js';
6
7
  import { dirname, join } from './path.js';
8
+ import { timerify } from './Performance.js';
7
9
  export const isDirectory = (filePath) => {
8
10
  const stat = statSync(filePath, { throwIfNoEntry: false });
9
11
  return stat !== undefined && stat.isDirectory();
@@ -26,6 +28,8 @@ export const loadFile = async (filePath) => {
26
28
  }
27
29
  };
28
30
  export const loadJSON = async (filePath) => {
31
+ if (filePath === FAKE_PATH)
32
+ return;
29
33
  const contents = await loadFile(filePath);
30
34
  return parseJSON(filePath, contents);
31
35
  };
@@ -59,3 +63,4 @@ export function isTypeModule(path) {
59
63
  }
60
64
  return false;
61
65
  }
66
+ export const _loadJSON = timerify(loadJSON);
@@ -1,4 +1,5 @@
1
1
  export { _load as load, _loadFile as loadFile } from './loader.js';
2
+ export { _loadJSON as loadJSON } from './fs.js';
2
3
  export { _tryResolve as tryResolve } from './require.js';
3
4
  export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
4
5
  import type { RawPluginConfiguration } from '../types/config.js';
@@ -1,4 +1,5 @@
1
1
  export { _load as load, _loadFile as loadFile } from './loader.js';
2
+ export { _loadJSON as loadJSON } from './fs.js';
2
3
  export { _tryResolve as tryResolve } from './require.js';
3
4
  export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
4
5
  import { arrayify } from './array.js';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "3.13.0";
1
+ export declare const version = "3.13.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '3.13.0';
1
+ export const version = '3.13.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "3.13.0",
3
+ "version": "3.13.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -60,7 +60,6 @@
60
60
  "@pnpm/logger": "5.0.0",
61
61
  "@pnpm/workspace.pkgs-graph": "^2.0.13",
62
62
  "@snyk/github-codeowners": "1.1.0",
63
- "chalk": "^5.3.0",
64
63
  "easy-table": "1.2.0",
65
64
  "fast-glob": "3.3.2",
66
65
  "globby": "^14.0.0",
@@ -68,6 +67,7 @@
68
67
  "js-yaml": "4.1.0",
69
68
  "micromatch": "4.0.5",
70
69
  "minimist": "1.2.8",
70
+ "picocolors": "1.0.0",
71
71
  "pretty-ms": "8.0.0",
72
72
  "strip-json-comments": "5.0.1",
73
73
  "summary": "2.1.0",
@@ -75,8 +75,8 @@
75
75
  "zod-validation-error": "2.1.0"
76
76
  },
77
77
  "peerDependencies": {
78
- "typescript": ">=5.0.4",
79
- "@types/node": ">=18"
78
+ "@types/node": ">=18",
79
+ "typescript": ">=5.0.4"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@jest/types": "29.6.3",