knip 5.4.0 → 5.6.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 (34) hide show
  1. package/dist/ConfigurationChief.d.ts +1 -0
  2. package/dist/ConfigurationValidator.d.ts +56 -0
  3. package/dist/ConfigurationValidator.js +1 -0
  4. package/dist/WorkspaceWorker.d.ts +2 -2
  5. package/dist/compilers/index.d.ts +10 -0
  6. package/dist/index.js +23 -122
  7. package/dist/manifest/index.js +2 -2
  8. package/dist/plugins/_template/index.d.ts +1 -2
  9. package/dist/plugins/index.d.ts +1 -0
  10. package/dist/plugins/index.js +1 -0
  11. package/dist/plugins/jest/index.js +4 -0
  12. package/dist/plugins/wrangler/index.d.ts +10 -0
  13. package/dist/plugins/wrangler/index.js +15 -0
  14. package/dist/plugins/wrangler/types.d.ts +3 -0
  15. package/dist/plugins/wrangler/types.js +1 -0
  16. package/dist/plugins.d.ts +1 -1
  17. package/dist/types/config.d.ts +1 -0
  18. package/dist/typescript/SourceFile.d.ts +9 -1
  19. package/dist/typescript/getImportsAndExports.js +4 -4
  20. package/dist/typescript/resolveModuleNames.js +1 -1
  21. package/dist/typescript/visitors/dynamic-imports/importType.js +2 -2
  22. package/dist/typescript/visitors/helpers.d.ts +2 -1
  23. package/dist/typescript/visitors/helpers.js +25 -6
  24. package/dist/util/get-reexporting-entry-file.d.ts +3 -0
  25. package/dist/util/get-reexporting-entry-file.js +55 -0
  26. package/dist/util/globby.js +2 -2
  27. package/dist/util/is-identifier-referenced.d.ts +2 -0
  28. package/dist/util/is-identifier-referenced.js +44 -0
  29. package/dist/version.d.ts +1 -1
  30. package/dist/version.js +1 -1
  31. package/package.json +1 -1
  32. package/schema.json +5 -1
  33. /package/dist/util/{handleReferencedDependency.d.ts → handle-dependency.d.ts} +0 -0
  34. /package/dist/util/{handleReferencedDependency.js → handle-dependency.js} +0 -0
@@ -115,6 +115,7 @@ export declare class ConfigurationChief {
115
115
  vitest?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
116
116
  webpack?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
117
117
  wireit?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
118
+ wrangler?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
118
119
  yorkie?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
119
120
  drizzle?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
120
121
  githubActions?: (boolean | import("./types/config.js").EnsuredPluginConfiguration) | undefined;
@@ -740,6 +740,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
740
740
  entry?: string | string[] | undefined;
741
741
  project?: string | string[] | undefined;
742
742
  }>]>>;
743
+ wrangler: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
744
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
745
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
746
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
747
+ }, "strip", z.ZodTypeAny, {
748
+ config?: string | string[] | undefined;
749
+ entry?: string | string[] | undefined;
750
+ project?: string | string[] | undefined;
751
+ }, {
752
+ config?: string | string[] | undefined;
753
+ entry?: string | string[] | undefined;
754
+ project?: string | string[] | undefined;
755
+ }>]>>;
743
756
  yorkie: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
744
757
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
745
758
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -1032,6 +1045,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
1032
1045
  entry?: string | string[] | undefined;
1033
1046
  project?: string | string[] | undefined;
1034
1047
  } | undefined;
1048
+ wrangler?: string | boolean | string[] | {
1049
+ config?: string | string[] | undefined;
1050
+ entry?: string | string[] | undefined;
1051
+ project?: string | string[] | undefined;
1052
+ } | undefined;
1035
1053
  yorkie?: string | boolean | string[] | {
1036
1054
  config?: string | string[] | undefined;
1037
1055
  entry?: string | string[] | undefined;
@@ -1316,6 +1334,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
1316
1334
  entry?: string | string[] | undefined;
1317
1335
  project?: string | string[] | undefined;
1318
1336
  } | undefined;
1337
+ wrangler?: string | boolean | string[] | {
1338
+ config?: string | string[] | undefined;
1339
+ entry?: string | string[] | undefined;
1340
+ project?: string | string[] | undefined;
1341
+ } | undefined;
1319
1342
  yorkie?: string | boolean | string[] | {
1320
1343
  config?: string | string[] | undefined;
1321
1344
  entry?: string | string[] | undefined;
@@ -2024,6 +2047,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
2024
2047
  entry?: string | string[] | undefined;
2025
2048
  project?: string | string[] | undefined;
2026
2049
  }>]>>;
2050
+ wrangler: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
2051
+ config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2052
+ entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2053
+ project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2054
+ }, "strip", z.ZodTypeAny, {
2055
+ config?: string | string[] | undefined;
2056
+ entry?: string | string[] | undefined;
2057
+ project?: string | string[] | undefined;
2058
+ }, {
2059
+ config?: string | string[] | undefined;
2060
+ entry?: string | string[] | undefined;
2061
+ project?: string | string[] | undefined;
2062
+ }>]>>;
2027
2063
  yorkie: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
2028
2064
  config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
2029
2065
  entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
@@ -2333,6 +2369,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
2333
2369
  entry?: string | string[] | undefined;
2334
2370
  project?: string | string[] | undefined;
2335
2371
  } | undefined;
2372
+ wrangler?: string | boolean | string[] | {
2373
+ config?: string | string[] | undefined;
2374
+ entry?: string | string[] | undefined;
2375
+ project?: string | string[] | undefined;
2376
+ } | undefined;
2336
2377
  yorkie?: string | boolean | string[] | {
2337
2378
  config?: string | string[] | undefined;
2338
2379
  entry?: string | string[] | undefined;
@@ -2609,6 +2650,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
2609
2650
  entry?: string | string[] | undefined;
2610
2651
  project?: string | string[] | undefined;
2611
2652
  } | undefined;
2653
+ wrangler?: string | boolean | string[] | {
2654
+ config?: string | string[] | undefined;
2655
+ entry?: string | string[] | undefined;
2656
+ project?: string | string[] | undefined;
2657
+ } | undefined;
2612
2658
  yorkie?: string | boolean | string[] | {
2613
2659
  config?: string | string[] | undefined;
2614
2660
  entry?: string | string[] | undefined;
@@ -2910,6 +2956,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
2910
2956
  entry?: string | string[] | undefined;
2911
2957
  project?: string | string[] | undefined;
2912
2958
  } | undefined;
2959
+ wrangler?: string | boolean | string[] | {
2960
+ config?: string | string[] | undefined;
2961
+ entry?: string | string[] | undefined;
2962
+ project?: string | string[] | undefined;
2963
+ } | undefined;
2913
2964
  yorkie?: string | boolean | string[] | {
2914
2965
  config?: string | string[] | undefined;
2915
2966
  entry?: string | string[] | undefined;
@@ -3186,6 +3237,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
3186
3237
  entry?: string | string[] | undefined;
3187
3238
  project?: string | string[] | undefined;
3188
3239
  } | undefined;
3240
+ wrangler?: string | boolean | string[] | {
3241
+ config?: string | string[] | undefined;
3242
+ entry?: string | string[] | undefined;
3243
+ project?: string | string[] | undefined;
3244
+ } | undefined;
3189
3245
  yorkie?: string | boolean | string[] | {
3190
3246
  config?: string | string[] | undefined;
3191
3247
  entry?: string | string[] | undefined;
@@ -117,6 +117,7 @@ const pluginsSchema = z.object({
117
117
  vitest: pluginSchema,
118
118
  webpack: pluginSchema,
119
119
  wireit: pluginSchema,
120
+ wrangler: pluginSchema,
120
121
  yorkie: pluginSchema,
121
122
  });
122
123
  const baseWorkspaceConfigurationSchema = z.object({
@@ -27,7 +27,7 @@ export declare class WorkspaceWorker {
27
27
  isStrict: boolean;
28
28
  rootIgnore: Configuration['ignore'];
29
29
  negatedWorkspacePatterns: string[];
30
- enabledPluginsMap: Record<"astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "msw" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "vercelOg", boolean>;
30
+ enabledPluginsMap: Record<"astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "msw" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "vercelOg", boolean>;
31
31
  enabledPlugins: PluginName[];
32
32
  enabledPluginsInAncestors: string[];
33
33
  constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }: WorkspaceManagerOptions);
@@ -46,7 +46,7 @@ export declare class WorkspaceWorker {
46
46
  entryFilePatterns: Set<string>;
47
47
  productionEntryFilePatterns: Set<string>;
48
48
  referencedDependencies: ReferencedDependencies;
49
- enabledPlugins: ("astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "msw" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "vercelOg")[];
49
+ enabledPlugins: ("astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "msw" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "vercelOg")[];
50
50
  }>;
51
51
  }
52
52
  export {};
@@ -297,6 +297,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
297
297
  entry?: string | string[] | undefined;
298
298
  project?: string | string[] | undefined;
299
299
  } | undefined;
300
+ wrangler?: string | boolean | string[] | {
301
+ config?: string | string[] | undefined;
302
+ entry?: string | string[] | undefined;
303
+ project?: string | string[] | undefined;
304
+ } | undefined;
300
305
  yorkie?: string | boolean | string[] | {
301
306
  config?: string | string[] | undefined;
302
307
  entry?: string | string[] | undefined;
@@ -573,6 +578,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
573
578
  entry?: string | string[] | undefined;
574
579
  project?: string | string[] | undefined;
575
580
  } | undefined;
581
+ wrangler?: string | boolean | string[] | {
582
+ config?: string | string[] | undefined;
583
+ entry?: string | string[] | undefined;
584
+ project?: string | string[] | undefined;
585
+ } | undefined;
576
586
  yorkie?: string | boolean | string[] | {
577
587
  config?: string | string[] | undefined;
578
588
  entry?: string | string[] | undefined;
package/dist/index.js CHANGED
@@ -8,10 +8,12 @@ import { IssueFixer } from './IssueFixer.js';
8
8
  import { getFilteredScripts } from './manifest/helpers.js';
9
9
  import { PrincipalFactory } from './PrincipalFactory.js';
10
10
  import { ProjectPrincipal } from './ProjectPrincipal.js';
11
- import { debugLogObject, debugLogArray, debugLog, exportLookupLog } from './util/debug.js';
11
+ import { debugLogObject, debugLogArray, debugLog } from './util/debug.js';
12
+ import { getReExportingEntryFileHandler } from './util/get-reexporting-entry-file.js';
12
13
  import { _glob, negate } from './util/glob.js';
13
14
  import { getGitIgnoredFn } from './util/globby.js';
14
- import { getHandler } from './util/handleReferencedDependency.js';
15
+ import { getHandler } from './util/handle-dependency.js';
16
+ import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
15
17
  import { getEntryPathFromManifest, getPackageNameFromModuleSpecifier } from './util/modules.js';
16
18
  import { dirname, join } from './util/path.js';
17
19
  import { hasMatch } from './util/regex.js';
@@ -168,7 +170,6 @@ export const main = async (unresolvedConfiguration) => {
168
170
  const importedSymbols = {};
169
171
  const unreferencedFiles = new Set();
170
172
  const entryPaths = new Set();
171
- const exportedClasses = new Set();
172
173
  for (const principal of principals) {
173
174
  principal.init();
174
175
  const handleReferencedDependency = getHandler(collector, deputy, chief);
@@ -277,93 +278,8 @@ export const main = async (unresolvedConfiguration) => {
277
278
  if (isSkipLibs)
278
279
  factory.deletePrincipal(principal);
279
280
  }
280
- const isIdentifierReferenced = (filePath, id, importsForExport, depth = 0) => {
281
- if (!importsForExport) {
282
- exportLookupLog(depth, `no imports found from`, filePath);
283
- return false;
284
- }
285
- if (importsForExport.identifiers.has(id)) {
286
- exportLookupLog(depth, `imported from`, filePath);
287
- return true;
288
- }
289
- for (const ns of importsForExport.importedNs) {
290
- if (importsForExport.identifiers.has(`${ns}.${id}`)) {
291
- exportLookupLog(depth, `imported on ${ns} from`, filePath);
292
- return true;
293
- }
294
- }
295
- if (importsForExport.isReExport) {
296
- for (const filePath of importsForExport.isReExportedBy) {
297
- if (isIdentifierReferenced(filePath, id, importedSymbols[filePath], depth + 1)) {
298
- exportLookupLog(depth, `re-exported by`, filePath);
299
- return true;
300
- }
301
- }
302
- for (const [filePath, alias] of importsForExport.isReExportedAs) {
303
- if (isIdentifierReferenced(filePath, alias, importedSymbols[filePath], depth + 1)) {
304
- exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
305
- return true;
306
- }
307
- }
308
- for (const [filePath, ns] of importsForExport.isReExportedNs) {
309
- if (isIdentifierReferenced(filePath, `${ns}.${id}`, importedSymbols[filePath], depth + 1)) {
310
- exportLookupLog(depth, `re-exported on ${ns} by`, filePath);
311
- return true;
312
- }
313
- }
314
- }
315
- exportLookupLog(depth, `not imported from`, filePath);
316
- return false;
317
- };
318
- const getReExportingEntryFile = (importedModule, id, depth = 0) => {
319
- if (!importedModule)
320
- return undefined;
321
- if (importedModule.isReExport) {
322
- for (const filePath of importedModule.isReExportedBy) {
323
- if (entryPaths.has(filePath)) {
324
- if (filePath in exportedSymbols && id in exportedSymbols[filePath]) {
325
- exportLookupLog(depth, `re-exported by entry`, filePath);
326
- return filePath;
327
- }
328
- else if (importedModule.hasStar) {
329
- exportLookupLog(depth, `re-exported (*) by entry`, filePath);
330
- return filePath;
331
- }
332
- }
333
- else {
334
- exportLookupLog(depth, `re-exported by`, filePath);
335
- const file = getReExportingEntryFile(importedSymbols[filePath], id, depth + 1);
336
- if (file)
337
- return file;
338
- }
339
- }
340
- for (const [filePath, namespace] of importedModule.isReExportedNs) {
341
- if (entryPaths.has(filePath)) {
342
- exportLookupLog(depth, `re-exported on ${namespace} by entry`, filePath);
343
- return filePath;
344
- }
345
- else {
346
- exportLookupLog(depth, `re-exported on ${namespace} by`, filePath);
347
- const file = getReExportingEntryFile(importedSymbols[filePath], namespace, depth + 1);
348
- if (file)
349
- return file;
350
- }
351
- }
352
- for (const [filePath, alias] of importedModule.isReExportedAs) {
353
- if (entryPaths.has(filePath)) {
354
- exportLookupLog(depth, `re-exported as ${alias} by entry`, filePath);
355
- return filePath;
356
- }
357
- else {
358
- exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
359
- const file = getReExportingEntryFile(importedSymbols[filePath], alias, depth + 1);
360
- if (file)
361
- return file;
362
- }
363
- }
364
- }
365
- exportLookupLog(depth, `${id} is not re-exported by entry file`, '');
366
- };
281
+ const isIdentifierReferenced = getIsIdentifierReferencedHandler(importedSymbols);
282
+ const getReExportingEntryFile = getReExportingEntryFileHandler(entryPaths, exportedSymbols, importedSymbols);
367
283
  const isExportedItemReferenced = (exportedItem) => {
368
284
  return (exportedItem.refs > 0 &&
369
285
  (typeof chief.config.ignoreExportsUsedInFile === 'object'
@@ -374,6 +290,7 @@ export const main = async (unresolvedConfiguration) => {
374
290
  streamer.cast('Analyzing source files...');
375
291
  for (const [filePath, exportItems] of Object.entries(exportedSymbols)) {
376
292
  const workspace = chief.findWorkspaceByFilePath(filePath);
293
+ const principal = workspace && factory.getPrincipalByPackageName(workspace.pkgName);
377
294
  if (workspace) {
378
295
  const { isIncludeEntryExports } = workspace.config;
379
296
  if (!isIncludeEntryExports && entryPaths.has(filePath))
@@ -390,20 +307,17 @@ export const main = async (unresolvedConfiguration) => {
390
307
  continue;
391
308
  if (importsForExport) {
392
309
  if (!isIncludeEntryExports) {
393
- exportLookupLog(-1, `Looking up re-exporting file for ${identifier} from`, filePath);
394
- if (getReExportingEntryFile(importsForExport, identifier))
310
+ if (getReExportingEntryFile(importsForExport, identifier, 0, filePath))
395
311
  continue;
396
312
  }
397
- exportLookupLog(-1, `Looking up ${identifier} export from`, filePath);
398
313
  if (isIdentifierReferenced(filePath, identifier, importsForExport)) {
399
- if (exportedItem.type === 'enum') {
314
+ if (report.enumMembers && exportedItem.type === 'enum') {
400
315
  exportedItem.members?.forEach(member => {
401
316
  if (hasMatch(workspace.ignoreMembers, member.identifier))
402
317
  return;
403
318
  if (shouldIgnore(member.jsDocTags, tags))
404
319
  return;
405
320
  if (member.refs === 0) {
406
- exportLookupLog(-1, `Looking up export member ${identifier}.${member.identifier} from`, filePath);
407
321
  if (!isIdentifierReferenced(filePath, `${identifier}.${member.identifier}`, importsForExport)) {
408
322
  collector.addIssue({
409
323
  type: 'enumMembers',
@@ -419,7 +333,18 @@ export const main = async (unresolvedConfiguration) => {
419
333
  });
420
334
  }
421
335
  if (isReportClassMembers && exportedItem.type === 'class') {
422
- exportedClasses.add([filePath, exportedItem]);
336
+ const members = exportedItem.members.filter(member => !hasMatch(workspace.ignoreMembers, member.identifier) && !shouldIgnore(member.jsDocTags, tags));
337
+ principal?.findUnusedMembers(filePath, members).forEach(member => {
338
+ collector.addIssue({
339
+ type: 'classMembers',
340
+ filePath,
341
+ symbol: member.identifier,
342
+ parentSymbol: exportedItem.identifier,
343
+ pos: member.pos,
344
+ line: member.line,
345
+ col: member.col,
346
+ });
347
+ });
423
348
  }
424
349
  continue;
425
350
  }
@@ -429,11 +354,8 @@ export const main = async (unresolvedConfiguration) => {
429
354
  if (hasStrictlyNsReferences && ((!report.nsTypes && isType) || (!report.nsExports && !isType)))
430
355
  continue;
431
356
  if (!isExportedItemReferenced(exportedItem)) {
432
- if (!isSkipLibs) {
433
- const principal = factory.getPrincipalByPackageName(workspace.pkgName);
434
- if (principal?.hasReferences(filePath, exportedItem))
435
- continue;
436
- }
357
+ if (!isSkipLibs && principal?.hasReferences(filePath, exportedItem))
358
+ continue;
437
359
  const type = getType(hasStrictlyNsReferences, isType);
438
360
  collector.addIssue({
439
361
  type,
@@ -469,27 +391,6 @@ export const main = async (unresolvedConfiguration) => {
469
391
  const unusedIgnoredWorkspaces = chief.getUnusedIgnoredWorkspaces();
470
392
  unusedIgnoredWorkspaces.forEach(identifier => collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier }));
471
393
  const { issues, counters, configurationHints } = collector.getIssues();
472
- if (isReportClassMembers) {
473
- streamer.cast('Validating expensive classy memberships...');
474
- for (const [filePath, exportedItem] of exportedClasses) {
475
- const workspace = chief.findWorkspaceByFilePath(filePath);
476
- const principal = workspace && factory.getPrincipalByPackageName(workspace.pkgName);
477
- if (principal) {
478
- const members = exportedItem.members.filter(member => !hasMatch(workspace.ignoreMembers, member.identifier) && !shouldIgnore(member.jsDocTags, tags));
479
- principal.findUnusedMembers(filePath, members).forEach(member => {
480
- collector.addIssue({
481
- type: 'classMembers',
482
- filePath,
483
- symbol: member.identifier,
484
- parentSymbol: exportedItem.identifier,
485
- pos: member.pos,
486
- line: member.line,
487
- col: member.col,
488
- });
489
- });
490
- }
491
- }
492
- }
493
394
  if (isFix) {
494
395
  await fixer.fixIssues(issues);
495
396
  }
@@ -1,7 +1,7 @@
1
1
  import { isDefinitelyTyped } from '../util/modules.js';
2
2
  import { timerify } from '../util/Performance.js';
3
3
  import { loadPackageManifest } from './helpers.js';
4
- const _getDependencyMetaData = ({ cwd, dir, packageNames }) => {
4
+ const getMetaDataFromPackageJson = ({ cwd, dir, packageNames }) => {
5
5
  const hostDependencies = new Map();
6
6
  const installedBinaries = new Map();
7
7
  const hasTypesIncluded = new Set();
@@ -47,4 +47,4 @@ const _getDependencyMetaData = ({ cwd, dir, packageNames }) => {
47
47
  hasTypesIncluded,
48
48
  };
49
49
  };
50
- export const getDependencyMetaData = timerify(_getDependencyMetaData);
50
+ export const getDependencyMetaData = timerify(getMetaDataFromPackageJson);
@@ -1,9 +1,8 @@
1
- import type { IgnorePatterns } from '#p/types/config.js';
2
1
  import type { IsPluginEnabled, ResolveConfig } from '#p/types/plugins.js';
3
2
  import type { PluginConfig } from './types.js';
4
3
  declare const _default: {
5
4
  title: string;
6
- enablers: IgnorePatterns;
5
+ enablers: import("#p/types/config.js").IgnorePatterns;
7
6
  isEnabled: IsPluginEnabled;
8
7
  config: string[];
9
8
  entry: string[];
@@ -53,4 +53,5 @@ export { default as vitest } from './vitest/index.js';
53
53
  export { default as vue } from './vue/index.js';
54
54
  export { default as webpack } from './webpack/index.js';
55
55
  export { default as wireit } from './wireit/index.js';
56
+ export { default as wrangler } from './wrangler/index.js';
56
57
  export { default as yorkie } from './yorkie/index.js';
@@ -53,4 +53,5 @@ export { default as vitest } from './vitest/index.js';
53
53
  export { default as vue } from './vue/index.js';
54
54
  export { default as webpack } from './webpack/index.js';
55
55
  export { default as wireit } from './wireit/index.js';
56
+ export { default as wrangler } from './wrangler/index.js';
56
57
  export { default as yorkie } from './yorkie/index.js';
@@ -58,6 +58,8 @@ const resolveDependencies = async (config, options) => {
58
58
  : []).filter(value => !/\$[0-9]/.test(value));
59
59
  const testResultsProcessor = config.testResultsProcessor ? [config.testResultsProcessor] : [];
60
60
  const snapshotResolver = config.snapshotResolver ? [config.snapshotResolver] : [];
61
+ const testSequencer = config.testSequencer ? [config.testSequencer] : [];
62
+ const globalSetup = config.globalSetup ? [config.globalSetup] : [];
61
63
  return [
62
64
  ...presets,
63
65
  ...projects,
@@ -72,6 +74,8 @@ const resolveDependencies = async (config, options) => {
72
74
  ...moduleNameMapper,
73
75
  ...testResultsProcessor,
74
76
  ...snapshotResolver,
77
+ ...testSequencer,
78
+ ...globalSetup,
75
79
  ];
76
80
  };
77
81
  const resolveEntryPaths = async (localConfig, options) => {
@@ -0,0 +1,10 @@
1
+ import type { IsPluginEnabled, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { WranglerConfig } from './types.js';
3
+ declare const _default: {
4
+ title: string;
5
+ enablers: string[];
6
+ isEnabled: IsPluginEnabled;
7
+ config: string[];
8
+ resolveEntryPaths: ResolveEntryPaths<WranglerConfig>;
9
+ };
10
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { hasDependency } from '#p/util/plugin.js';
2
+ const title = 'Wrangler';
3
+ const enablers = ['wrangler'];
4
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
+ const config = ['wrangler.{json,toml}'];
6
+ const resolveEntryPaths = async (config) => {
7
+ return config.main ? [config.main] : [];
8
+ };
9
+ export default {
10
+ title,
11
+ enablers,
12
+ isEnabled,
13
+ config,
14
+ resolveEntryPaths,
15
+ };
@@ -0,0 +1,3 @@
1
+ export type WranglerConfig = {
2
+ main?: string;
3
+ };
@@ -0,0 +1 @@
1
+ export {};
package/dist/plugins.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { Plugin } from './types/plugins.js';
2
- declare const plugins: Record<"astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "msw" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "vercelOg", Plugin>;
2
+ declare const plugins: Record<"astro" | "svelte" | "vue" | "angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eleventy" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "linthtml" | "markdownlint" | "mocha" | "msw" | "netlify" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "tsup" | "typedoc" | "typescript" | "unbuild" | "vite" | "vitest" | "webpack" | "wireit" | "wrangler" | "yorkie" | "drizzle" | "githubActions" | "graphqlCodegen" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "vercelOg", Plugin>;
3
3
  export { plugins };
@@ -7,6 +7,7 @@ export type RawConfiguration = z.infer<typeof ConfigurationValidator>;
7
7
  export type RawPluginConfiguration = z.infer<typeof pluginSchema>;
8
8
  type NormalizedGlob = string[];
9
9
  export type IgnorePatterns = (string | RegExp)[];
10
+ export type EnablerPatterns = IgnorePatterns;
10
11
  export type PluginName = keyof typeof Plugins;
11
12
  export type PluginMap = typeof Plugins;
12
13
  export type EnsuredPluginConfiguration = {
@@ -5,7 +5,15 @@ type SymbolWithExports = ts.Symbol & {
5
5
  };
6
6
  type PragmaMap = {
7
7
  arguments: {
8
- factory: string;
8
+ factory?: string;
9
+ path?: {
10
+ value?: string;
11
+ pos?: number;
12
+ };
13
+ types?: {
14
+ value?: string;
15
+ pos?: number;
16
+ };
9
17
  };
10
18
  };
11
19
  export interface BoundSourceFile extends ts.SourceFile {
@@ -7,7 +7,7 @@ import { shouldIgnore } from '../util/tag.js';
7
7
  import { isAccessExpression, getJSDocTags, getLineAndCharacterOfPosition, getMemberStringLiterals, } from './ast-helpers.js';
8
8
  import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
9
9
  import getExportVisitors from './visitors/exports/index.js';
10
- import { getJSXImplicitImportBase } from './visitors/helpers.js';
10
+ import { getImportsFromPragmas } from './visitors/helpers.js';
11
11
  import getImportVisitors from './visitors/imports/index.js';
12
12
  import getScriptVisitors from './visitors/scripts/index.js';
13
13
  const getVisitors = (sourceFile) => ({
@@ -39,9 +39,6 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
39
39
  const aliasedExports = new Map();
40
40
  const scripts = new Set();
41
41
  const importedInternalSymbols = new Map();
42
- const jsxImport = getJSXImplicitImportBase(sourceFile);
43
- if (jsxImport)
44
- externalImports.add(jsxImport);
45
42
  const visitors = getVisitors(sourceFile);
46
43
  const addInternalImport = (options) => {
47
44
  const { identifier, specifier, symbol, filePath, namespace, isReExport } = options;
@@ -288,6 +285,9 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
288
285
  ts.forEachChild(node, visit);
289
286
  };
290
287
  visit(sourceFile);
288
+ const pragmaImports = getImportsFromPragmas(sourceFile);
289
+ if (pragmaImports)
290
+ pragmaImports.forEach(node => addImport(node, sourceFile));
291
291
  const setRefs = (item) => {
292
292
  if (!item.symbol)
293
293
  return;
@@ -42,7 +42,7 @@ export function createCustomModuleResolver(customSys, compilerOptions, virtualFi
42
42
  const resolvedFileName = tsResolvedModule.resolvedFileName.replace(/\.d\.mts$/, '.mjs');
43
43
  return { resolvedFileName, extension: '.mjs', isExternalLibraryImport: false, resolvedUsingTsExtension: false };
44
44
  }
45
- if (tsResolvedModule.extension === '.d.cts') {
45
+ else if (tsResolvedModule.extension === '.d.cts') {
46
46
  const resolvedFileName = tsResolvedModule.resolvedFileName.replace(/\.d\.cts$/, '.cjs');
47
47
  return { resolvedFileName, extension: '.cjs', isExternalLibraryImport: false, resolvedUsingTsExtension: false };
48
48
  }
@@ -1,9 +1,9 @@
1
1
  import ts from 'typescript';
2
2
  import { importVisitor as visit } from '../index.js';
3
3
  export default visit(() => true, node => {
4
- if (ts.isImportTypeNode(node) && node.isTypeOf) {
4
+ if (ts.isImportTypeNode(node)) {
5
5
  if (ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) {
6
- return { specifier: node.argument.literal.text, identifier: undefined, pos: 0 };
6
+ return { specifier: node.argument.literal.text, identifier: undefined, pos: 0, isTypeOnly: true };
7
7
  }
8
8
  }
9
9
  });
@@ -1,6 +1,7 @@
1
1
  import ts from 'typescript';
2
+ import type { ImportNode } from '../../types/imports.js';
2
3
  import type { BoundSourceFile } from '../SourceFile.js';
3
4
  export declare const isNotJS: (sourceFile: BoundSourceFile) => boolean;
4
5
  export declare const isJS: (sourceFile: BoundSourceFile) => boolean;
5
- export declare function getJSXImplicitImportBase(sourceFile: BoundSourceFile): string | undefined;
6
+ export declare function getImportsFromPragmas(sourceFile: BoundSourceFile): ImportNode[];
6
7
  export declare function hasImportSpecifier(node: ts.Statement, name: string): boolean;
@@ -1,12 +1,31 @@
1
1
  import ts from 'typescript';
2
2
  export const isNotJS = (sourceFile) => sourceFile.scriptKind !== ts.ScriptKind.JS && sourceFile.scriptKind !== ts.ScriptKind.JSX;
3
3
  export const isJS = (sourceFile) => sourceFile.scriptKind === ts.ScriptKind.JS || sourceFile.scriptKind === ts.ScriptKind.JSX;
4
- export function getJSXImplicitImportBase(sourceFile) {
5
- const jsxImportSourcePragmas = sourceFile.pragmas?.get('jsximportsource');
6
- const jsxImportSourcePragma = Array.isArray(jsxImportSourcePragmas)
7
- ? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1]
8
- : jsxImportSourcePragmas;
9
- return jsxImportSourcePragma?.arguments.factory;
4
+ export function getImportsFromPragmas(sourceFile) {
5
+ const importNodes = [];
6
+ if (sourceFile.pragmas) {
7
+ const jsxImportSourcePragmas = sourceFile.pragmas.get('jsximportsource');
8
+ if (jsxImportSourcePragmas) {
9
+ const jsxImportSourcePragma = Array.isArray(jsxImportSourcePragmas)
10
+ ? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1]
11
+ : jsxImportSourcePragmas;
12
+ const { factory: specifier } = jsxImportSourcePragma?.arguments ?? {};
13
+ if (specifier)
14
+ importNodes.push({ specifier, isTypeOnly: true, identifier: '__jsx', pos: 0 });
15
+ }
16
+ const referencePragma = sourceFile.pragmas.get('reference');
17
+ if (referencePragma) {
18
+ const refs = [referencePragma].flat();
19
+ for (const ref of refs) {
20
+ if (ref.arguments?.types) {
21
+ const { value: specifier, pos } = ref.arguments.types;
22
+ if (specifier)
23
+ importNodes.push({ specifier, isTypeOnly: true, identifier: undefined, pos });
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return importNodes;
10
29
  }
11
30
  export function hasImportSpecifier(node, name) {
12
31
  return (ts.isImportDeclaration(node) &&
@@ -0,0 +1,3 @@
1
+ import type { SerializableExportMap } from '../types/exports.js';
2
+ import type { SerializableImportMap, SerializableImports } from '../types/imports.js';
3
+ export declare const getReExportingEntryFileHandler: (entryPaths: Set<string>, exportedSymbols: SerializableExportMap, importedSymbols: SerializableImportMap) => (importedModule: SerializableImports | undefined, id: string, depth?: number, filePath?: string) => string | undefined;
@@ -0,0 +1,55 @@
1
+ import { exportLookupLog } from './debug.js';
2
+ export const getReExportingEntryFileHandler = (entryPaths, exportedSymbols, importedSymbols) => {
3
+ const getReExportingEntryFile = (importedModule, id, depth = 0, filePath) => {
4
+ if (depth === 0 && filePath)
5
+ exportLookupLog(-1, `Looking up re-exporting file for ${id} from`, filePath);
6
+ if (!importedModule)
7
+ return undefined;
8
+ if (importedModule.isReExport) {
9
+ for (const filePath of importedModule.isReExportedBy) {
10
+ if (entryPaths.has(filePath)) {
11
+ if (filePath in exportedSymbols && id in exportedSymbols[filePath]) {
12
+ exportLookupLog(depth, `re-exported by entry`, filePath);
13
+ return filePath;
14
+ }
15
+ else if (importedModule.hasStar) {
16
+ exportLookupLog(depth, `re-exported (*) by entry`, filePath);
17
+ return filePath;
18
+ }
19
+ }
20
+ else {
21
+ exportLookupLog(depth, `re-exported by`, filePath);
22
+ const file = getReExportingEntryFile(importedSymbols[filePath], id, depth + 1);
23
+ if (file)
24
+ return file;
25
+ }
26
+ }
27
+ for (const [filePath, namespace] of importedModule.isReExportedNs) {
28
+ if (entryPaths.has(filePath)) {
29
+ exportLookupLog(depth, `re-exported on ${namespace} by entry`, filePath);
30
+ return filePath;
31
+ }
32
+ else {
33
+ exportLookupLog(depth, `re-exported on ${namespace} by`, filePath);
34
+ const file = getReExportingEntryFile(importedSymbols[filePath], namespace, depth + 1);
35
+ if (file)
36
+ return file;
37
+ }
38
+ }
39
+ for (const [filePath, alias] of importedModule.isReExportedAs) {
40
+ if (entryPaths.has(filePath)) {
41
+ exportLookupLog(depth, `re-exported as ${alias} by entry`, filePath);
42
+ return filePath;
43
+ }
44
+ else {
45
+ exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
46
+ const file = getReExportingEntryFile(importedSymbols[filePath], alias, depth + 1);
47
+ if (file)
48
+ return file;
49
+ }
50
+ }
51
+ }
52
+ exportLookupLog(depth, `${id} is not re-exported by entry file`, '');
53
+ };
54
+ return getReExportingEntryFile;
55
+ };
@@ -21,7 +21,7 @@ function convertGitignoreToMicromatch(pattern) {
21
21
  pattern = pattern.slice(5);
22
22
  if (pattern.startsWith('/'))
23
23
  pattern = pattern.slice(1);
24
- else
24
+ else if (!pattern.startsWith('**/'))
25
25
  pattern = '**/' + pattern;
26
26
  if (pattern.endsWith('/*'))
27
27
  extPattern = pattern;
@@ -36,7 +36,7 @@ function parseGitignoreFile(filePath) {
36
36
  return file
37
37
  .split(/\r?\n/)
38
38
  .filter(line => line && !line.startsWith('#'))
39
- .map(pattern => convertGitignoreToMicromatch(pattern));
39
+ .map(pattern => convertGitignoreToMicromatch(pattern.replace(/#.*/, '').trim()));
40
40
  }
41
41
  async function parseFindGitignores(options) {
42
42
  const ignores = ['.git', ...GLOBAL_IGNORE_PATTERNS];
@@ -0,0 +1,2 @@
1
+ import type { SerializableImportMap, SerializableImports } from '../types/imports.js';
2
+ export declare const getIsIdentifierReferencedHandler: (importedSymbols: SerializableImportMap) => (filePath: string, id: string, importsForExport?: SerializableImports, depth?: number) => boolean;
@@ -0,0 +1,44 @@
1
+ import { exportLookupLog } from './debug.js';
2
+ export const getIsIdentifierReferencedHandler = (importedSymbols) => {
3
+ const isIdentifierReferenced = (filePath, id, importsForExport, depth = 0) => {
4
+ if (depth === 0)
5
+ exportLookupLog(-1, `Looking up export "${id}" from`, filePath);
6
+ if (!importsForExport) {
7
+ exportLookupLog(depth, `no imports found from`, filePath);
8
+ return false;
9
+ }
10
+ if (importsForExport.identifiers.has(id)) {
11
+ exportLookupLog(depth, `imported from`, filePath);
12
+ return true;
13
+ }
14
+ for (const ns of importsForExport.importedNs) {
15
+ if (importsForExport.identifiers.has(`${ns}.${id}`)) {
16
+ exportLookupLog(depth, `imported on ${ns} from`, filePath);
17
+ return true;
18
+ }
19
+ }
20
+ if (importsForExport.isReExport) {
21
+ for (const filePath of importsForExport.isReExportedBy) {
22
+ if (isIdentifierReferenced(filePath, id, importedSymbols[filePath], depth + 1)) {
23
+ exportLookupLog(depth, `re-exported by`, filePath);
24
+ return true;
25
+ }
26
+ }
27
+ for (const [filePath, alias] of importsForExport.isReExportedAs) {
28
+ if (isIdentifierReferenced(filePath, alias, importedSymbols[filePath], depth + 1)) {
29
+ exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
30
+ return true;
31
+ }
32
+ }
33
+ for (const [filePath, ns] of importsForExport.isReExportedNs) {
34
+ if (isIdentifierReferenced(filePath, `${ns}.${id}`, importedSymbols[filePath], depth + 1)) {
35
+ exportLookupLog(depth, `re-exported on ${ns} by`, filePath);
36
+ return true;
37
+ }
38
+ }
39
+ }
40
+ exportLookupLog(depth, `not imported from`, filePath);
41
+ return false;
42
+ };
43
+ return isIdentifierReferenced;
44
+ };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.4.0";
1
+ export declare const version = "5.6.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.4.0';
1
+ export const version = '5.6.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.4.0",
3
+ "version": "5.6.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
package/schema.json CHANGED
@@ -32,7 +32,7 @@
32
32
  "$ref": "#/definitions/list"
33
33
  },
34
34
  "ignoreMembers": {
35
- "title": "Class members to ignore (regex allowed)",
35
+ "title": "Class and enum members to ignore (regex allowed)",
36
36
  "examples": ["render", "on.*"],
37
37
  "$ref": "#/definitions/list"
38
38
  },
@@ -491,6 +491,10 @@
491
491
  "title": "Wireit plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/wireit/README.md)",
492
492
  "$ref": "#/definitions/plugin"
493
493
  },
494
+ "wrangler": {
495
+ "title": "wrangler plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/wrangler/README.md)",
496
+ "$ref": "#/definitions/plugin"
497
+ },
494
498
  "yorkie": {
495
499
  "title": "yorkie plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/yorkie/README.md)",
496
500
  "$ref": "#/definitions/plugin"