knip 5.33.2 → 5.33.3

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.
@@ -34,7 +34,7 @@ export declare class WorkspaceWorker {
34
34
  isStrict: boolean;
35
35
  rootIgnore: Configuration['ignore'];
36
36
  negatedWorkspacePatterns: string[];
37
- enabledPluginsMap: Record<"angular" | "astro" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "drizzle" | "eleventy" | "eslint" | "gatsby" | "githubActions" | "graphqlCodegen" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "lintStaged" | "lockfileLint" | "lostPixel" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nodeTestRunner" | "npmPackageJsonLint" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "playwrightCt" | "postcss" | "preconstruct" | "prettier" | "reactCosmos" | "releaseIt" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "semanticRelease" | "sentry" | "simpleGitHooks" | "sizeLimit" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "travis" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vercelOg" | "vike" | "vite" | "vitest" | "vue" | "webdriverIo" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie", boolean>;
37
+ enabledPluginsMap: Record<"astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "travis" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo", boolean>;
38
38
  enabledPlugins: PluginName[];
39
39
  enabledPluginsInAncestors: string[];
40
40
  cache: CacheConsultant<CacheItem>;
@@ -54,7 +54,7 @@ export declare class WorkspaceWorker {
54
54
  entryFilePatterns: Set<string>;
55
55
  productionEntryFilePatterns: Set<string>;
56
56
  referencedDependencies: ReferencedDependencies;
57
- enabledPlugins: ("angular" | "astro" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "drizzle" | "eleventy" | "eslint" | "gatsby" | "githubActions" | "graphqlCodegen" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "lintStaged" | "lockfileLint" | "lostPixel" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nodeTestRunner" | "npmPackageJsonLint" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "playwrightCt" | "postcss" | "preconstruct" | "prettier" | "reactCosmos" | "releaseIt" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "semanticRelease" | "sentry" | "simpleGitHooks" | "sizeLimit" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "travis" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vercelOg" | "vike" | "vite" | "vitest" | "vue" | "webdriverIo" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie")[];
57
+ enabledPlugins: ("astro" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cucumber" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "ladle" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "moonrepo" | "msw" | "nest" | "netlify" | "next" | "nuxt" | "nx" | "nyc" | "oclif" | "playwright" | "postcss" | "preconstruct" | "prettier" | "remark" | "remix" | "rollup" | "rsbuild" | "rspack" | "sentry" | "storybook" | "stryker" | "stylelint" | "svelte" | "syncpack" | "tailwind" | "travis" | "tsup" | "typedoc" | "typescript" | "unbuild" | "unocss" | "vue" | "vike" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "xo" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "lockfileLint" | "lostPixel" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "reactCosmos" | "releaseIt" | "semanticRelease" | "simpleGitHooks" | "sizeLimit" | "vercelOg" | "webdriverIo")[];
58
58
  }>;
59
59
  onDispose(): void;
60
60
  }
@@ -2,7 +2,7 @@ import { _glob } from '#p/util/glob.js';
2
2
  import { getDependenciesFromScripts } from '../../util/plugin.js';
3
3
  const title = 'Travis CI';
4
4
  const enablers = 'This plugin is enabled when a `.travis.yml` file is found in the root folder.';
5
- const isEnabled = async ({ cwd }) => Boolean(await _glob({ cwd, patterns: ['.travis.yml'] }));
5
+ const isEnabled = async ({ cwd }) => (await _glob({ cwd, patterns: ['.travis.yml'] })).length > 0;
6
6
  const config = ['.travis.yml'];
7
7
  const resolveConfig = async (config, options) => {
8
8
  if (!config)
@@ -24,7 +24,7 @@ export declare const isObjectEnumerationCallExpressionArgument: (node: ts.Identi
24
24
  export declare const isTopLevel: (node: ts.Node) => boolean;
25
25
  export declare const getTypeName: (node: ts.Identifier) => ts.QualifiedName | undefined;
26
26
  export declare const isImportSpecifier: (node: ts.Node) => boolean;
27
- export declare const isReferencedInExportedType: (node: ts.Node) => boolean;
27
+ export declare const isReferencedInExport: (node: ts.Node) => boolean;
28
28
  export declare const getExportKeywordNode: (node: ts.Node) => ts.ExportKeyword | undefined;
29
29
  export declare const getDefaultKeywordNode: (node: ts.Node) => ts.DefaultKeyword | undefined;
30
30
  export declare const hasRequireCall: (node: ts.Node) => boolean;
@@ -172,7 +172,11 @@ const getAncestorTypeDeclaration = (node) => {
172
172
  node = node.parent;
173
173
  }
174
174
  };
175
- export const isReferencedInExportedType = (node) => {
175
+ export const isReferencedInExport = (node) => {
176
+ if (ts.isTypeQueryNode(node.parent) && isExported(node.parent.parent))
177
+ return true;
178
+ if (ts.isTypeReferenceNode(node.parent) && isExported(node.parent.parent))
179
+ return true;
176
180
  const typeNode = getAncestorTypeDeclaration(node);
177
181
  return Boolean(typeNode && isExported(typeNode));
178
182
  };
@@ -1,4 +1,4 @@
1
1
  import ts from 'typescript';
2
2
  import type { Export, ExportMember } from '../types/dependency-graph.js';
3
3
  export declare const isType: (item: Export | ExportMember) => boolean;
4
- export declare const findInternalReferences: (item: Export | ExportMember, sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker, referencedSymbolsInExportedTypes: Set<ts.Symbol>) => [number, boolean];
4
+ export declare const findInternalReferences: (item: Export | ExportMember, sourceFile: ts.SourceFile, typeChecker: ts.TypeChecker, referencedSymbolsInExport: Set<ts.Symbol>, isBindingElement?: boolean) => [number, boolean];
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  import { isIdChar } from '../util/regex.js';
3
3
  export const isType = (item) => item.type === 'type' || item.type === 'interface' || item.type === 'enum';
4
- export const findInternalReferences = (item, sourceFile, typeChecker, referencedSymbolsInExportedTypes) => {
4
+ export const findInternalReferences = (item, sourceFile, typeChecker, referencedSymbolsInExport, isBindingElement) => {
5
5
  if (!item.symbol)
6
6
  return [0, false];
7
7
  if (item.identifier === '')
@@ -12,7 +12,7 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
12
12
  const id = item.identifier;
13
13
  const symbols = new Set();
14
14
  let refCount = 0;
15
- let isSymbolInExportedType = false;
15
+ let isSymbolInExport = false;
16
16
  let index = 0;
17
17
  while (index < text.length && (index = text.indexOf(id, index)) !== -1) {
18
18
  if (!isIdChar(text.charAt(index - 1)) && !isIdChar(text.charAt(index + id.length))) {
@@ -20,21 +20,23 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
20
20
  if (!isExportDeclaration) {
21
21
  const symbol = typeChecker.getSymbolAtLocation(ts.getTokenAtPosition(sourceFile, index));
22
22
  if (symbol) {
23
- const isInExportedType = referencedSymbolsInExportedTypes.has(symbol);
24
- if (isInExportedType)
25
- isSymbolInExportedType = true;
23
+ const isInExport = referencedSymbolsInExport.has(symbol);
24
+ if (isInExport)
25
+ isSymbolInExport = true;
26
26
  if (item.symbol === symbol) {
27
27
  refCount++;
28
- if (isInExportedType || isType(item))
29
- return [refCount, isSymbolInExportedType];
28
+ if (isInExport || isType(item))
29
+ return [refCount, isSymbolInExport];
30
+ if (isBindingElement)
31
+ return [refCount, true];
30
32
  }
31
33
  const declaration = symbol.declarations?.[0];
32
34
  if (declaration) {
33
35
  if (item.symbol === declaration.name?.flowNode?.node?.symbol) {
34
- return [++refCount, isSymbolInExportedType];
36
+ return [++refCount, isSymbolInExport];
35
37
  }
36
38
  if (ts.isImportSpecifier(declaration) && symbols.has(symbol)) {
37
- return [++refCount, isSymbolInExportedType];
39
+ return [++refCount, isSymbolInExport];
38
40
  }
39
41
  }
40
42
  symbols.add(symbol);
@@ -43,5 +45,5 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
43
45
  }
44
46
  index += id.length;
45
47
  }
46
- return [refCount, isSymbolInExportedType];
48
+ return [refCount, isSymbolInExport];
47
49
  };
@@ -6,7 +6,7 @@ import { addNsValue, addValue, createImports } from '../util/dependency-graph.js
6
6
  import { getPackageNameFromFilePath, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
7
7
  import { extname, isInNodeModules } from '../util/path.js';
8
8
  import { shouldIgnore } from '../util/tag.js';
9
- import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeName, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isObjectEnumerationCallExpressionArgument, isReferencedInExportedType, } from './ast-helpers.js';
9
+ import { getAccessMembers, getDestructuredIds, getJSDocTags, getLineAndCharacterOfPosition, getTypeName, isAccessExpression, isConsiderReferencedNS, isDestructuring, isImportSpecifier, isObjectEnumerationCallExpressionArgument, isReferencedInExport, } from './ast-helpers.js';
10
10
  import { findInternalReferences, isType } from './find-internal-references.js';
11
11
  import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
12
12
  import getExportVisitors from './visitors/exports/index.js';
@@ -45,7 +45,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
45
45
  const scripts = new Set();
46
46
  const traceRefs = new Set();
47
47
  const importedInternalSymbols = new Map();
48
- const referencedSymbolsInExportedTypes = new Set();
48
+ const referencedSymbolsInExport = new Set();
49
49
  const visitors = getVisitors(sourceFile);
50
50
  const addNsMemberRefs = (internalImport, namespace, member) => {
51
51
  if (typeof member === 'string') {
@@ -280,10 +280,8 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
280
280
  }
281
281
  }
282
282
  }
283
- if (!isTopLevel && symbol.exportSymbol) {
284
- if (ts.isTypeQueryNode(node.parent) || isReferencedInExportedType(node)) {
285
- referencedSymbolsInExportedTypes.add(symbol.exportSymbol);
286
- }
283
+ if (!isTopLevel && symbol.exportSymbol && isReferencedInExport(node)) {
284
+ referencedSymbolsInExport.add(symbol.exportSymbol);
287
285
  }
288
286
  }
289
287
  }
@@ -308,17 +306,22 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
308
306
  for (const node of pragmaImports)
309
307
  addImport(node, sourceFile);
310
308
  for (const item of exports.values()) {
311
- const isType_ = isType(item);
312
- if (item.symbol && referencedSymbolsInExportedTypes.has(item.symbol)) {
309
+ if (item.symbol && referencedSymbolsInExport.has(item.symbol)) {
313
310
  item.refs = [1, true];
314
311
  }
315
- else if (ignoreExportsUsedInFile === true ||
316
- (typeof ignoreExportsUsedInFile === 'object' && item.type !== 'unknown' && ignoreExportsUsedInFile[item.type]) ||
317
- isType_) {
318
- item.refs = findInternalReferences(item, sourceFile, typeChecker, referencedSymbolsInExportedTypes);
312
+ else {
313
+ const isBindingElement = item.symbol?.valueDeclaration && ts.isBindingElement(item.symbol.valueDeclaration);
314
+ if (ignoreExportsUsedInFile === true ||
315
+ (typeof ignoreExportsUsedInFile === 'object' &&
316
+ item.type !== 'unknown' &&
317
+ ignoreExportsUsedInFile[item.type]) ||
318
+ isType(item) ||
319
+ isBindingElement) {
320
+ item.refs = findInternalReferences(item, sourceFile, typeChecker, referencedSymbolsInExport, isBindingElement);
321
+ }
319
322
  }
320
323
  for (const member of item.members) {
321
- member.refs = findInternalReferences(member, sourceFile, typeChecker, referencedSymbolsInExportedTypes);
324
+ member.refs = findInternalReferences(member, sourceFile, typeChecker, referencedSymbolsInExport);
322
325
  member.symbol = undefined;
323
326
  }
324
327
  item.symbol = undefined;
@@ -19,6 +19,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
19
19
  : undefined;
20
20
  return {
21
21
  node: element,
22
+ symbol: element.symbol,
22
23
  identifier: element.name.escapedText.toString(),
23
24
  type: SymbolType.UNKNOWN,
24
25
  pos: element.name.getStart(),
@@ -33,6 +34,7 @@ export default visit(() => true, (node, { isFixExports, isFixTypes, isReportClas
33
34
  const fix = isFixExports ? [element.getStart(), element.getEnd(), FIX_FLAGS.NONE] : undefined;
34
35
  return {
35
36
  node: element,
37
+ symbol: element.symbol,
36
38
  identifier: element.getText(),
37
39
  type: SymbolType.UNKNOWN,
38
40
  pos: element.getStart(),
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.33.2";
1
+ export declare const version = "5.33.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.33.2';
1
+ export const version = '5.33.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.33.2",
3
+ "version": "5.33.3",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {