knip 5.70.2 → 5.72.0

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.
Files changed (86) hide show
  1. package/dist/ConfigurationChief.d.ts +6 -0
  2. package/dist/ConsoleStreamer.js +1 -1
  3. package/dist/DependencyDeputy.js +2 -2
  4. package/dist/ProjectPrincipal.js +1 -1
  5. package/dist/WorkspaceWorker.js +1 -1
  6. package/dist/binaries/bash-parser.js +14 -1
  7. package/dist/compilers/index.d.ts +10 -0
  8. package/dist/compilers/index.js +4 -1
  9. package/dist/compilers/scss.d.ts +6 -0
  10. package/dist/compilers/scss.js +14 -0
  11. package/dist/constants.js +1 -0
  12. package/dist/graph/analyze.js +38 -22
  13. package/dist/graph-explorer/constants.d.ts +2 -0
  14. package/dist/graph-explorer/constants.js +2 -0
  15. package/dist/graph-explorer/explorer.d.ts +11 -0
  16. package/dist/graph-explorer/explorer.js +10 -0
  17. package/dist/graph-explorer/operations/build-exports-tree.d.ts +15 -0
  18. package/dist/graph-explorer/operations/build-exports-tree.js +96 -0
  19. package/dist/graph-explorer/operations/has-strictly-ns-references.d.ts +2 -0
  20. package/dist/graph-explorer/operations/has-strictly-ns-references.js +98 -0
  21. package/dist/graph-explorer/operations/is-referenced.d.ts +4 -0
  22. package/dist/graph-explorer/operations/is-referenced.js +89 -0
  23. package/dist/graph-explorer/utils.d.ts +3 -0
  24. package/dist/graph-explorer/utils.js +13 -0
  25. package/dist/graph-explorer/visitors.d.ts +12 -0
  26. package/dist/graph-explorer/visitors.js +30 -0
  27. package/dist/graph-explorer/walk-down.d.ts +5 -0
  28. package/dist/graph-explorer/walk-down.js +116 -0
  29. package/dist/index.js +2 -98
  30. package/dist/plugins/angular/index.js +3 -3
  31. package/dist/plugins/index.d.ts +1 -0
  32. package/dist/plugins/index.js +2 -0
  33. package/dist/plugins/next/index.js +4 -3
  34. package/dist/plugins/next/resolveFromAST.d.ts +1 -0
  35. package/dist/plugins/next/resolveFromAST.js +42 -1
  36. package/dist/plugins/rsbuild/index.js +8 -0
  37. package/dist/plugins/rsbuild/types.d.ts +1 -0
  38. package/dist/plugins/storybook/index.js +12 -4
  39. package/dist/plugins/storybook/types.d.ts +5 -0
  40. package/dist/plugins/svgo/index.js +1 -1
  41. package/dist/plugins/svgr/index.d.ts +3 -0
  42. package/dist/plugins/svgr/index.js +24 -0
  43. package/dist/plugins/svgr/types.d.ts +3 -0
  44. package/dist/plugins/svgr/types.js +1 -0
  45. package/dist/plugins/vite/helpers.js +1 -1
  46. package/dist/plugins/vite/index.js +4 -0
  47. package/dist/plugins/vitest/index.js +1 -1
  48. package/dist/reporters/codeclimate.js +3 -7
  49. package/dist/reporters/util/util.d.ts +2 -1
  50. package/dist/reporters/util/util.js +1 -0
  51. package/dist/reporters/watch.js +1 -1
  52. package/dist/run.d.ts +25 -0
  53. package/dist/run.js +107 -0
  54. package/dist/schema/configuration.d.ts +10 -0
  55. package/dist/schema/plugins.d.ts +5 -0
  56. package/dist/schema/plugins.js +1 -0
  57. package/dist/types/PluginNames.d.ts +2 -2
  58. package/dist/types/PluginNames.js +1 -0
  59. package/dist/types/issues.d.ts +4 -4
  60. package/dist/types/module-graph.d.ts +11 -13
  61. package/dist/typescript/ast-helpers.d.ts +5 -1
  62. package/dist/typescript/ast-helpers.js +47 -2
  63. package/dist/typescript/get-imports-and-exports.js +78 -12
  64. package/dist/typescript/resolve-module-names.js +5 -4
  65. package/dist/typescript/visitors/dynamic-imports/importCall.js +5 -19
  66. package/dist/util/Performance.js +4 -2
  67. package/dist/util/create-options.d.ts +10 -0
  68. package/dist/util/create-options.js +8 -4
  69. package/dist/util/file-entry-cache.js +1 -1
  70. package/dist/util/graph-sequencer.js +1 -1
  71. package/dist/util/module-graph.js +7 -8
  72. package/dist/util/resolve.d.ts +3 -2
  73. package/dist/util/resolve.js +25 -2
  74. package/dist/util/trace.d.ts +2 -20
  75. package/dist/util/trace.js +41 -66
  76. package/dist/util/watch.d.ts +19 -3
  77. package/dist/util/watch.js +28 -17
  78. package/dist/version.d.ts +1 -1
  79. package/dist/version.js +1 -1
  80. package/package.json +7 -7
  81. package/schema.json +4 -0
  82. package/vendor/bash-parser/index.d.ts +6 -1
  83. package/dist/util/has-strictly-ns-references.d.ts +0 -4
  84. package/dist/util/has-strictly-ns-references.js +0 -103
  85. package/dist/util/is-identifier-referenced.d.ts +0 -9
  86. package/dist/util/is-identifier-referenced.js +0 -145
@@ -13,7 +13,7 @@ const entry = ['**/*.{bench,test,test-d,spec}.?(c|m)[jt]s?(x)', ...mocks];
13
13
  const isVitestCoverageCommand = /vitest(.+)--coverage(?:\.enabled(?:=true)?)?/;
14
14
  const hasScriptWithCoverage = (scripts) => scripts ? Object.values(scripts).some(script => isVitestCoverageCommand.test(script)) : false;
15
15
  const findConfigDependencies = (localConfig, options) => {
16
- const { manifest, cwd: dir } = options;
16
+ const { manifest, configFileDir: dir } = options;
17
17
  const testConfig = localConfig.test;
18
18
  if (!testConfig)
19
19
  return [];
@@ -1,7 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { ISSUE_TYPE_TITLE } from '../constants.js';
3
2
  import { toRelative } from '../util/path.js';
4
- import { getIssueTypeTitle } from './util/util.js';
3
+ import { getIssuePrefix, getIssueTypeTitle } from './util/util.js';
5
4
  export default async ({ report, issues, cwd }) => {
6
5
  const entries = [];
7
6
  for (const [type, isReportType] of Object.entries(report)) {
@@ -52,15 +51,12 @@ function convertSeverity(severity) {
52
51
  return 'info';
53
52
  }
54
53
  }
55
- function getPrefix(type) {
56
- return ISSUE_TYPE_TITLE[type].replace(/ies$/, 'y').replace(/s$/, '');
57
- }
58
54
  function getIssueDescription({ type, symbol, symbols, parentSymbol }) {
59
55
  const symbolDescription = symbols ? `${symbols.map(s => s.symbol).join(', ')}` : symbol;
60
- return `${getPrefix(type)}: ${symbolDescription}${parentSymbol ? ` (${parentSymbol})` : ''}`;
56
+ return `${getIssuePrefix(type)}: ${symbolDescription}${parentSymbol ? ` (${parentSymbol})` : ''}`;
61
57
  }
62
58
  function getSymbolDescription({ type, symbol, parentSymbol, }) {
63
- return `${getPrefix(type)}: ${symbol.symbol}${parentSymbol ? ` (${parentSymbol})` : ''}`;
59
+ return `${getIssuePrefix(type)}: ${symbol.symbol}${parentSymbol ? ` (${parentSymbol})` : ''}`;
64
60
  }
65
61
  function createLocation(filePath, cwd, line, col) {
66
62
  if (col !== undefined) {
@@ -1,5 +1,5 @@
1
1
  import { ISSUE_TYPE_TITLE } from '../../constants.js';
2
- import type { Issue, IssueSeverity, IssueSymbol } from '../../types/issues.js';
2
+ import type { Issue, IssueSeverity, IssueSymbol, IssueType } from '../../types/issues.js';
3
3
  import { Table } from '../../util/table.js';
4
4
  export declare const dim: import("picocolors/types.js").Formatter;
5
5
  export declare const bright: import("picocolors/types.js").Formatter;
@@ -23,4 +23,5 @@ export declare const convert: (issue: Issue | IssueSymbol) => {
23
23
  export declare const getTableForType: (issues: Issue[], cwd: string, options?: {
24
24
  isUseColors?: boolean;
25
25
  }) => Table;
26
+ export declare const getIssuePrefix: (type: IssueType) => string;
26
27
  export {};
@@ -54,3 +54,4 @@ export const getTableForType = (issues, cwd, options = { isUseColors: true }) =>
54
54
  }
55
55
  return table;
56
56
  };
57
+ export const getIssuePrefix = (type) => ISSUE_TYPE_TITLE[type].replace(/ies$/, 'y').replace(/s$/, '');
@@ -23,7 +23,7 @@ export default (options, { issues, streamer, duration, size }) => {
23
23
  }
24
24
  const mem = perfObserver.getCurrentMemUsageInMb();
25
25
  const ms = duration ?? perfObserver.getCurrentDurationInMs();
26
- const summary = `${size} files in ${prettyMilliseconds(ms)} (${mem}MB)`;
26
+ const summary = `${size} files (${prettyMilliseconds(ms)} ${mem}MB)`;
27
27
  const messages = totalIssues === 0
28
28
  ? ['✂️ Excellent, Knip found no issues.', '', picocolors.gray(summary)]
29
29
  : [...lines, '', picocolors.gray(summary)];
package/dist/run.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { ConsoleStreamer } from './ConsoleStreamer.js';
2
+ import type { MainOptions } from './util/create-options.js';
3
+ export declare const run: (options: MainOptions) => Promise<{
4
+ results: {
5
+ issues: import("./types/issues.js").Issues;
6
+ counters: import("./types/issues.js").Counters;
7
+ tagHints: Set<import("./types/issues.js").TagHint>;
8
+ configurationHints: Set<import("./types/issues.js").ConfigurationHint>;
9
+ includedWorkspaceDirs: string[];
10
+ };
11
+ watchHandler: {
12
+ listener: import("fs").WatchListener<string | Buffer<ArrayBufferLike>>;
13
+ handleFileChanges: (changes: {
14
+ type: "added" | "deleted" | "modified";
15
+ filePath: string;
16
+ }[]) => Promise<{
17
+ duration: number;
18
+ mem: number;
19
+ }>;
20
+ getEntryPaths: () => Set<string>;
21
+ getGraph: () => import("./types/module-graph.js").ModuleGraph;
22
+ getIssues: () => import("./types/issues.js").Issues;
23
+ } | undefined;
24
+ streamer: ConsoleStreamer;
25
+ }>;
package/dist/run.js ADDED
@@ -0,0 +1,107 @@
1
+ import { watch } from 'node:fs';
2
+ import { formatly } from 'formatly';
3
+ import { CatalogCounselor } from './CatalogCounselor.js';
4
+ import { ConfigurationChief } from './ConfigurationChief.js';
5
+ import { ConsoleStreamer } from './ConsoleStreamer.js';
6
+ import { DependencyDeputy } from './DependencyDeputy.js';
7
+ import { analyze } from './graph/analyze.js';
8
+ import { build } from './graph/build.js';
9
+ import { IssueCollector } from './IssueCollector.js';
10
+ import { IssueFixer } from './IssueFixer.js';
11
+ import { PrincipalFactory } from './PrincipalFactory.js';
12
+ import watchReporter from './reporters/watch.js';
13
+ import { debugLogArray, debugLogObject } from './util/debug.js';
14
+ import { getGitIgnoredHandler } from './util/glob-core.js';
15
+ import { getWatchHandler } from './util/watch.js';
16
+ export const run = async (options) => {
17
+ debugLogObject('*', 'Unresolved configuration', options);
18
+ debugLogObject('*', 'Included issue types', options.includedIssueTypes);
19
+ const chief = new ConfigurationChief(options);
20
+ const deputy = new DependencyDeputy(options);
21
+ const factory = new PrincipalFactory();
22
+ const streamer = new ConsoleStreamer(options);
23
+ const fixer = new IssueFixer(options);
24
+ const collector = new IssueCollector(options);
25
+ const counselor = new CatalogCounselor(options);
26
+ streamer.cast('Reading workspace configuration');
27
+ const workspaces = await chief.getWorkspaces();
28
+ const isGitIgnored = await getGitIgnoredHandler(options);
29
+ collector.setIgnoreIssues(chief.config.ignoreIssues);
30
+ debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
31
+ debugLogObject('*', 'Included workspace configs', () => workspaces.map(w => ({ pkgName: w.pkgName, name: w.name, config: w.config, ancestors: w.ancestors })));
32
+ const { graph, entryPaths, analyzedFiles, unreferencedFiles, analyzeSourceFile } = await build({
33
+ chief,
34
+ collector,
35
+ counselor,
36
+ deputy,
37
+ factory,
38
+ isGitIgnored,
39
+ streamer,
40
+ workspaces,
41
+ options,
42
+ });
43
+ const reAnalyze = await analyze({
44
+ analyzedFiles,
45
+ counselor,
46
+ chief,
47
+ collector,
48
+ deputy,
49
+ entryPaths,
50
+ factory,
51
+ fixer,
52
+ graph,
53
+ streamer,
54
+ unreferencedFiles,
55
+ options,
56
+ });
57
+ let watchHandler;
58
+ if (options.isWatch) {
59
+ const isIgnored = (filePath) => (!!options.cacheLocation && filePath.startsWith(options.cacheLocation)) ||
60
+ filePath.includes('/.git/') ||
61
+ isGitIgnored(filePath);
62
+ const onFileChange = options.isWatch
63
+ ? ({ issues, duration }) => watchReporter(options, { issues, streamer, size: analyzedFiles.size, duration })
64
+ : undefined;
65
+ watchHandler = await getWatchHandler(options, {
66
+ analyzedFiles,
67
+ analyzeSourceFile,
68
+ chief,
69
+ collector,
70
+ analyze: reAnalyze,
71
+ factory,
72
+ graph,
73
+ isIgnored,
74
+ onFileChange,
75
+ unreferencedFiles,
76
+ entryPaths,
77
+ });
78
+ if (options.isWatch)
79
+ watch('.', { recursive: true }, watchHandler.listener);
80
+ }
81
+ const { issues, counters, tagHints, configurationHints } = collector.getIssues();
82
+ if (options.isFix) {
83
+ const touchedFiles = await fixer.fixIssues(issues);
84
+ if (options.isFormat) {
85
+ const report = await formatly(Array.from(touchedFiles));
86
+ if (report.ran && report.result && (report.result.runner === 'virtual' || report.result.code === 0)) {
87
+ debugLogArray('*', `Formatted files using ${report.formatter.name} (${report.formatter.runner})`, touchedFiles);
88
+ }
89
+ else {
90
+ debugLogObject('*', 'Formatting files failed', report);
91
+ }
92
+ }
93
+ }
94
+ if (!options.isWatch)
95
+ streamer.clear();
96
+ return {
97
+ results: {
98
+ issues,
99
+ counters,
100
+ tagHints,
101
+ configurationHints,
102
+ includedWorkspaceDirs: chief.includedWorkspaces.map(w => w.dir),
103
+ },
104
+ watchHandler,
105
+ streamer,
106
+ };
107
+ };
@@ -477,6 +477,11 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
477
477
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
478
478
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
479
479
  }, z.core.$strip>]>>;
480
+ svgr: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
481
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
482
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
483
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
484
+ }, z.core.$strip>]>>;
480
485
  syncpack: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
481
486
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
482
487
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -1073,6 +1078,11 @@ export declare const knipConfigurationSchema: z.ZodMiniObject<{
1073
1078
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1074
1079
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1075
1080
  }, z.core.$strip>]>>;
1081
+ svgr: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
1082
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1083
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1084
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1085
+ }, z.core.$strip>]>>;
1076
1086
  syncpack: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
1077
1087
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
1078
1088
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -481,6 +481,11 @@ export declare const pluginsSchema: z.ZodMiniObject<{
481
481
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
482
482
  project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
483
483
  }, z.core.$strip>]>;
484
+ svgr: z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
485
+ config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
486
+ entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
487
+ project: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
488
+ }, z.core.$strip>]>;
484
489
  syncpack: z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>, z.ZodMiniObject<{
485
490
  config: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
486
491
  entry: z.ZodMiniOptional<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniArray<z.ZodMiniString<string>>]>>;
@@ -105,6 +105,7 @@ export const pluginsSchema = z.object({
105
105
  stylelint: pluginSchema,
106
106
  svelte: pluginSchema,
107
107
  svgo: pluginSchema,
108
+ svgr: pluginSchema,
108
109
  syncpack: pluginSchema,
109
110
  tailwind: pluginSchema,
110
111
  taskfile: pluginSchema,
@@ -1,2 +1,2 @@
1
- export type PluginName = 'angular' | 'astro' | 'astro-db' | 'ava' | 'babel' | 'biome' | 'bumpp' | 'bun' | 'c8' | 'capacitor' | 'changelogen' | 'changelogithub' | 'changesets' | 'commitizen' | 'commitlint' | 'convex' | 'create-typescript-app' | 'cspell' | 'cucumber' | 'cypress' | 'danger' | 'dependency-cruiser' | 'docusaurus' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'hardhat' | 'husky' | 'i18next-parser' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'mdx' | 'mdxlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nano-staged' | 'nest' | 'netlify' | 'next' | 'node' | 'node-modules-inspector' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'oxlint' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'pnpm' | 'postcss' | 'preconstruct' | 'prettier' | 'prisma' | 'react-cosmos' | 'react-router' | 'relay' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rslib' | 'rspack' | 'rstest' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'svgo' | 'syncpack' | 'tailwind' | 'taskfile' | 'travis' | 'ts-node' | 'tsdown' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
- export declare const pluginNames: readonly ["angular", "astro", "astro-db", "ava", "babel", "biome", "bumpp", "bun", "c8", "capacitor", "changelogen", "changelogithub", "changesets", "commitizen", "commitlint", "convex", "create-typescript-app", "cspell", "cucumber", "cypress", "danger", "dependency-cruiser", "docusaurus", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "hardhat", "husky", "i18next-parser", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "mdx", "mdxlint", "metro", "mocha", "moonrepo", "msw", "nano-staged", "nest", "netlify", "next", "node", "node-modules-inspector", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "oxlint", "playwright", "playwright-ct", "playwright-test", "plop", "pnpm", "postcss", "preconstruct", "prettier", "prisma", "react-cosmos", "react-router", "relay", "release-it", "remark", "remix", "rollup", "rsbuild", "rslib", "rspack", "rstest", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "svgo", "syncpack", "tailwind", "taskfile", "travis", "ts-node", "tsdown", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
1
+ export type PluginName = 'angular' | 'astro' | 'astro-db' | 'ava' | 'babel' | 'biome' | 'bumpp' | 'bun' | 'c8' | 'capacitor' | 'changelogen' | 'changelogithub' | 'changesets' | 'commitizen' | 'commitlint' | 'convex' | 'create-typescript-app' | 'cspell' | 'cucumber' | 'cypress' | 'danger' | 'dependency-cruiser' | 'docusaurus' | 'dotenv' | 'drizzle' | 'eleventy' | 'eslint' | 'expo' | 'gatsby' | 'github-action' | 'github-actions' | 'glob' | 'graphql-codegen' | 'hardhat' | 'husky' | 'i18next-parser' | 'jest' | 'karma' | 'ladle' | 'lefthook' | 'lint-staged' | 'linthtml' | 'lockfile-lint' | 'lost-pixel' | 'markdownlint' | 'mdx' | 'mdxlint' | 'metro' | 'mocha' | 'moonrepo' | 'msw' | 'nano-staged' | 'nest' | 'netlify' | 'next' | 'node' | 'node-modules-inspector' | 'nodemon' | 'npm-package-json-lint' | 'nuxt' | 'nx' | 'nyc' | 'oclif' | 'oxlint' | 'playwright' | 'playwright-ct' | 'playwright-test' | 'plop' | 'pnpm' | 'postcss' | 'preconstruct' | 'prettier' | 'prisma' | 'react-cosmos' | 'react-router' | 'relay' | 'release-it' | 'remark' | 'remix' | 'rollup' | 'rsbuild' | 'rslib' | 'rspack' | 'rstest' | 'semantic-release' | 'sentry' | 'simple-git-hooks' | 'size-limit' | 'sst' | 'starlight' | 'storybook' | 'stryker' | 'stylelint' | 'svelte' | 'svgo' | 'svgr' | 'syncpack' | 'tailwind' | 'taskfile' | 'travis' | 'ts-node' | 'tsdown' | 'tsup' | 'tsx' | 'typedoc' | 'typescript' | 'unbuild' | 'unocss' | 'vercel-og' | 'vike' | 'vite' | 'vitest' | 'vue' | 'webdriver-io' | 'webpack' | 'wireit' | 'wrangler' | 'xo' | 'yarn' | 'yorkie';
2
+ export declare const pluginNames: readonly ["angular", "astro", "astro-db", "ava", "babel", "biome", "bumpp", "bun", "c8", "capacitor", "changelogen", "changelogithub", "changesets", "commitizen", "commitlint", "convex", "create-typescript-app", "cspell", "cucumber", "cypress", "danger", "dependency-cruiser", "docusaurus", "dotenv", "drizzle", "eleventy", "eslint", "expo", "gatsby", "github-action", "github-actions", "glob", "graphql-codegen", "hardhat", "husky", "i18next-parser", "jest", "karma", "ladle", "lefthook", "lint-staged", "linthtml", "lockfile-lint", "lost-pixel", "markdownlint", "mdx", "mdxlint", "metro", "mocha", "moonrepo", "msw", "nano-staged", "nest", "netlify", "next", "node", "node-modules-inspector", "nodemon", "npm-package-json-lint", "nuxt", "nx", "nyc", "oclif", "oxlint", "playwright", "playwright-ct", "playwright-test", "plop", "pnpm", "postcss", "preconstruct", "prettier", "prisma", "react-cosmos", "react-router", "relay", "release-it", "remark", "remix", "rollup", "rsbuild", "rslib", "rspack", "rstest", "semantic-release", "sentry", "simple-git-hooks", "size-limit", "sst", "starlight", "storybook", "stryker", "stylelint", "svelte", "svgo", "svgr", "syncpack", "tailwind", "taskfile", "travis", "ts-node", "tsdown", "tsup", "tsx", "typedoc", "typescript", "unbuild", "unocss", "vercel-og", "vike", "vite", "vitest", "vue", "webdriver-io", "webpack", "wireit", "wrangler", "xo", "yarn", "yorkie"];
@@ -94,6 +94,7 @@ export const pluginNames = [
94
94
  'stylelint',
95
95
  'svelte',
96
96
  'svgo',
97
+ 'svgr',
97
98
  'syncpack',
98
99
  'tailwind',
99
100
  'taskfile',
@@ -1,13 +1,13 @@
1
1
  import type { SYMBOL_TYPE } from '../constants.js';
2
2
  import type { Fixes } from './exports.js';
3
3
  export type SymbolType = (typeof SYMBOL_TYPE)[keyof typeof SYMBOL_TYPE];
4
- export type IssueSymbol = {
4
+ export interface IssueSymbol {
5
5
  symbol: string;
6
6
  pos?: number;
7
7
  line?: number;
8
8
  col?: number;
9
- };
10
- export type Issue = {
9
+ }
10
+ export interface Issue {
11
11
  type: SymbolIssueType;
12
12
  filePath: string;
13
13
  workspace: string;
@@ -22,7 +22,7 @@ export type Issue = {
22
22
  col?: number;
23
23
  fixes: Fixes;
24
24
  isFixed?: boolean;
25
- };
25
+ }
26
26
  export type IssueSet = Set<string>;
27
27
  export type IssueRecords = Record<string, Record<string, Issue>>;
28
28
  export type Issues = {
@@ -1,12 +1,17 @@
1
1
  import type ts from 'typescript';
2
2
  import type { Fix, Fixes } from './exports.js';
3
3
  import type { IssueSymbol, SymbolType } from './issues.js';
4
- type Identifier = string;
4
+ export type Identifier = string;
5
5
  type FilePath = string;
6
6
  type NamespaceOrAlias = string;
7
7
  type Reference = string;
8
8
  type References = Set<Reference>;
9
9
  type Tags = Set<string>;
10
+ interface SourceLocation {
11
+ pos: number;
12
+ line: number;
13
+ col: number;
14
+ }
10
15
  export type IdToFileMap = Map<Identifier, Set<FilePath>>;
11
16
  export type IdToNsToFileMap = Map<Identifier, Map<NamespaceOrAlias, Set<FilePath>>>;
12
17
  export type ImportMaps = {
@@ -19,24 +24,18 @@ export type ImportMaps = {
19
24
  reExportedNs: IdToFileMap;
20
25
  };
21
26
  export type ImportMap = Map<FilePath, ImportMaps>;
22
- export type Import = {
27
+ export interface Import extends SourceLocation {
23
28
  specifier: string;
24
29
  filePath: string | undefined;
25
30
  identifier: string | undefined;
26
- pos?: number;
27
- line?: number;
28
- col?: number;
29
31
  isTypeOnly: boolean;
30
- };
31
- export interface Export {
32
+ }
33
+ export interface Export extends SourceLocation {
32
34
  identifier: Identifier;
33
- pos: number;
34
- line: number;
35
- col: number;
36
35
  type: SymbolType;
37
36
  members: ExportMember[];
38
37
  jsDocTags: Tags;
39
- refs: [number, boolean];
38
+ self: [number, boolean];
40
39
  fixes: Fixes;
41
40
  symbol?: ts.Symbol;
42
41
  isReExport?: boolean;
@@ -47,7 +46,7 @@ export type ExportMember = {
47
46
  line: number;
48
47
  col: number;
49
48
  type: SymbolType;
50
- refs: [number, boolean];
49
+ self: [number, boolean];
51
50
  fix: Fix;
52
51
  symbol?: ts.Symbol;
53
52
  jsDocTags: Tags;
@@ -67,7 +66,6 @@ export type FileNode = {
67
66
  scripts: Set<string>;
68
67
  imported?: ImportMaps;
69
68
  internalImportCache?: ImportMap;
70
- traceRefs: References;
71
69
  };
72
70
  export type ModuleGraph = Map<FilePath, FileNode>;
73
71
  export {};
@@ -40,7 +40,7 @@ export declare const getLineAndCharacterOfPosition: (node: ts.Node, pos: number)
40
40
  col: number;
41
41
  pos: number;
42
42
  };
43
- export declare const getAccessMembers: (typeChecker: ts.TypeChecker, node: ts.Identifier) => string[];
43
+ export declare const getAccessMembers: (typeChecker: ts.TypeChecker, node: ts.Node) => string[];
44
44
  export declare const isDestructuring: (node: ts.Node) => boolean;
45
45
  export declare const getDestructuredNames: (name: ts.ObjectBindingPattern) => [string[], boolean];
46
46
  export declare const isConsiderReferencedNS: (node: ts.Identifier) => boolean;
@@ -58,6 +58,10 @@ export declare const isModuleExportsAccess: (node: ts.PropertyAccessExpression)
58
58
  export declare const getImportMap: (sourceFile: ts.SourceFile) => Map<string, string>;
59
59
  export declare const getDefaultImportName: (importMap: ReturnType<typeof getImportMap>, specifier: string) => string | undefined;
60
60
  export declare const getPropertyValues: (node: ts.ObjectLiteralExpression, propertyName: string) => Set<string>;
61
+ export declare function getThenBindings(callExpression: ts.CallExpression): {
62
+ identifier: string;
63
+ pos: number;
64
+ }[] | undefined;
61
65
  export declare const getAccessedIdentifiers: (identifier: string, scope: ts.Node) => {
62
66
  identifier: string;
63
67
  pos: number;
@@ -198,12 +198,10 @@ export const getDestructuredNames = (name) => {
198
198
  return [members, hasSpread];
199
199
  };
200
200
  export const isConsiderReferencedNS = (node) => ts.isPropertyAssignment(node.parent) ||
201
- ts.isShorthandPropertyAssignment(node.parent) ||
202
201
  (ts.isCallExpression(node.parent) && node.parent.arguments.includes(node)) ||
203
202
  ts.isSpreadAssignment(node.parent) ||
204
203
  ts.isArrayLiteralExpression(node.parent) ||
205
204
  ts.isExportAssignment(node.parent) ||
206
- (ts.isVariableDeclaration(node.parent) && node.parent.initializer === node) ||
207
205
  ts.isTypeQueryNode(node.parent.parent);
208
206
  export const isInOpaqueExpression = (node) => ts.isAwaitExpression(node.parent)
209
207
  ? isInOpaqueExpression(node.parent)
@@ -263,6 +261,18 @@ export const getImportMap = (sourceFile) => {
263
261
  importMap.set(element.name.text, importPath);
264
262
  }
265
263
  }
264
+ if (ts.isVariableStatement(statement)) {
265
+ for (const declaration of statement.declarationList.declarations) {
266
+ if (declaration.initializer &&
267
+ isRequireCall(declaration.initializer) &&
268
+ ts.isIdentifier(declaration.name) &&
269
+ ts.isStringLiteral(declaration.initializer.arguments[0])) {
270
+ const importName = declaration.name.text;
271
+ const importPath = stripQuotes(declaration.initializer.arguments[0].text);
272
+ importMap.set(importName, importPath);
273
+ }
274
+ }
275
+ }
266
276
  }
267
277
  return importMap;
268
278
  };
@@ -304,6 +314,32 @@ const isMatchAlias = (expression, identifier) => {
304
314
  expression = expression.expression;
305
315
  return expression && ts.isIdentifier(expression) && expression.escapedText === identifier;
306
316
  };
317
+ export function getThenBindings(callExpression) {
318
+ if (!ts.isFunctionLike(callExpression.arguments[0]))
319
+ return;
320
+ const fn = callExpression.arguments[0];
321
+ const param = fn.parameters[0];
322
+ if (!param)
323
+ return;
324
+ if (ts.isIdentifier(param.name)) {
325
+ const paramName = param.name.escapedText;
326
+ const identifiers = [];
327
+ for (const node of findDescendants(fn.body, ts.isPropertyAccessExpression)) {
328
+ if (ts.isIdentifier(node.expression) && node.expression.escapedText === paramName) {
329
+ identifiers.push({ identifier: String(node.name.escapedText), pos: node.name.pos });
330
+ }
331
+ }
332
+ if (identifiers.length > 0)
333
+ return identifiers;
334
+ }
335
+ else if (ts.isObjectBindingPattern(param.name)) {
336
+ return param.name.elements.map(element => {
337
+ const identifier = (element.propertyName ?? element.name).getText();
338
+ const alias = element.propertyName ? element.name.getText() : undefined;
339
+ return { identifier, alias, pos: element.pos };
340
+ });
341
+ }
342
+ }
307
343
  export const getAccessedIdentifiers = (identifier, scope) => {
308
344
  const identifiers = [];
309
345
  function visit(node) {
@@ -328,6 +364,15 @@ export const getAccessedIdentifiers = (identifier, scope) => {
328
364
  }
329
365
  }
330
366
  }
367
+ else if (ts.isCallExpression(node) &&
368
+ ts.isPropertyAccessExpression(node.expression) &&
369
+ isMatchAlias(node.expression.expression, identifier) &&
370
+ node.expression.name.escapedText === 'then') {
371
+ const accessed = getThenBindings(node);
372
+ if (accessed)
373
+ for (const acc of accessed)
374
+ identifiers.push(acc);
375
+ }
331
376
  ts.forEachChild(node, visit);
332
377
  }
333
378
  visit(scope);