knip 4.1.0 → 4.2.1

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 (65) hide show
  1. package/dist/ConfigurationChief.d.ts +14 -12
  2. package/dist/ConfigurationChief.js +37 -25
  3. package/dist/ConfigurationValidator.d.ts +56 -0
  4. package/dist/ConfigurationValidator.js +1 -0
  5. package/dist/DependencyDeputy.d.ts +16 -17
  6. package/dist/DependencyDeputy.js +40 -27
  7. package/dist/IssueFixer.js +1 -1
  8. package/dist/ProjectPrincipal.d.ts +1 -1
  9. package/dist/ProjectPrincipal.js +4 -4
  10. package/dist/WorkspaceWorker.d.ts +15 -23
  11. package/dist/WorkspaceWorker.js +31 -53
  12. package/dist/binaries/bash-parser.d.ts +2 -6
  13. package/dist/binaries/bash-parser.js +7 -6
  14. package/dist/binaries/index.js +2 -4
  15. package/dist/binaries/resolvers/bun.js +2 -3
  16. package/dist/binaries/resolvers/fallback.js +0 -1
  17. package/dist/binaries/resolvers/index.d.ts +15 -11
  18. package/dist/binaries/resolvers/index.js +26 -11
  19. package/dist/binaries/resolvers/npx.js +4 -5
  20. package/dist/binaries/resolvers/pnpm.js +2 -3
  21. package/dist/binaries/resolvers/ts-node.d.ts +2 -0
  22. package/dist/binaries/resolvers/ts-node.js +16 -0
  23. package/dist/binaries/resolvers/yarn.js +3 -4
  24. package/dist/binaries/types.d.ts +7 -11
  25. package/dist/compilers/index.d.ts +13 -3
  26. package/dist/compilers/index.js +3 -8
  27. package/dist/index.js +36 -20
  28. package/dist/manifest/helpers.d.ts +8 -2
  29. package/dist/manifest/helpers.js +14 -1
  30. package/dist/manifest/index.d.ts +3 -8
  31. package/dist/manifest/index.js +6 -21
  32. package/dist/plugins/ava/index.js +2 -6
  33. package/dist/plugins/eleventy/index.js +4 -4
  34. package/dist/plugins/eslint/helpers.d.ts +2 -2
  35. package/dist/plugins/github-actions/index.js +5 -13
  36. package/dist/plugins/husky/index.js +2 -6
  37. package/dist/plugins/index.d.ts +1 -0
  38. package/dist/plugins/index.js +1 -0
  39. package/dist/plugins/lefthook/index.js +3 -3
  40. package/dist/plugins/lint-staged/index.js +1 -2
  41. package/dist/plugins/netlify/helpers.d.ts +2 -0
  42. package/dist/plugins/netlify/helpers.js +4 -0
  43. package/dist/plugins/netlify/index.d.ts +10 -0
  44. package/dist/plugins/netlify/index.js +38 -0
  45. package/dist/plugins/netlify/types.d.ts +11 -0
  46. package/dist/plugins/netlify/types.js +1 -0
  47. package/dist/plugins/nx/index.js +2 -2
  48. package/dist/plugins/release-it/index.js +2 -2
  49. package/dist/plugins/vitest/index.js +7 -8
  50. package/dist/plugins/wireit/index.js +2 -2
  51. package/dist/types/config.d.ts +0 -2
  52. package/dist/types/package-json.d.ts +3 -2
  53. package/dist/types/plugins.d.ts +11 -6
  54. package/dist/types/workspace.d.ts +11 -9
  55. package/dist/typescript/createHosts.js +2 -2
  56. package/dist/util/fs.d.ts +1 -0
  57. package/dist/util/fs.js +5 -0
  58. package/dist/util/loader.js +4 -1
  59. package/dist/util/modules.d.ts +1 -1
  60. package/dist/util/regex.d.ts +0 -1
  61. package/dist/util/regex.js +0 -1
  62. package/dist/version.d.ts +1 -1
  63. package/dist/version.js +1 -1
  64. package/package.json +2 -1
  65. package/schema.json +4 -0
@@ -1,20 +1,22 @@
1
+ export type DependencySet = Set<string>;
2
+ export type DependencyArray = Array<string>;
1
3
  type WorkspaceManifest = {
2
4
  workspaceDir: string;
3
5
  manifestPath: string;
4
- scripts: string[];
5
- dependencies: string[];
6
- peerDependencies: string[];
7
- optionalPeerDependencies: string[];
8
- optionalDependencies: string[];
9
- devDependencies: string[];
10
- allDependencies: string[];
6
+ dependencies: DependencyArray;
7
+ devDependencies: DependencyArray;
8
+ peerDependencies: DependencySet;
9
+ optionalPeerDependencies: DependencyArray;
10
+ allDependencies: DependencySet;
11
11
  ignoreDependencies: (string | RegExp)[];
12
12
  ignoreBinaries: (string | RegExp)[];
13
13
  };
14
14
  export type WorkspaceManifests = Map<string, WorkspaceManifest>;
15
- export type HostDependencies = Map<string, Set<{
15
+ export type HostDependencies = Map<string, Array<{
16
16
  name: string;
17
17
  isPeerOptional: boolean;
18
18
  }>>;
19
- export type InstalledBinaries = Map<string, Set<string>>;
19
+ type PackageName = string;
20
+ type BinaryName = string;
21
+ export type InstalledBinaries = Map<PackageName, Set<BinaryName>>;
20
22
  export {};
@@ -1,7 +1,7 @@
1
1
  import { EOL } from 'node:os';
2
2
  import path from 'node:path';
3
3
  import ts from 'typescript';
4
- import { getExtensions } from '../compilers/index.js';
4
+ import { getCompilerExtensions } from '../compilers/index.js';
5
5
  import { createCustomModuleResolver } from './resolveModuleNames.js';
6
6
  import { SourceFileManager } from './SourceFileManager.js';
7
7
  import { createCustomSys } from './sys.js';
@@ -9,7 +9,7 @@ const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
9
9
  const fileManager = new SourceFileManager();
10
10
  export const createHosts = ({ cwd, compilerOptions, entryPaths, compilers }) => {
11
11
  fileManager.installCompilers(compilers);
12
- const virtualFileExtensions = getExtensions(compilers);
12
+ const virtualFileExtensions = getCompilerExtensions(compilers);
13
13
  const sys = createCustomSys(cwd, virtualFileExtensions);
14
14
  const resolveModuleNames = createCustomModuleResolver(sys, compilerOptions, virtualFileExtensions);
15
15
  const languageServiceHost = {
package/dist/util/fs.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const findFile: (workingDir: string, fileName: string) => string
4
4
  export declare const loadFile: (filePath: string) => Promise<string>;
5
5
  export declare const loadJSON: (filePath: string) => Promise<any>;
6
6
  export declare const loadYAML: (filePath: string) => Promise<unknown>;
7
+ export declare const loadTOML: (filePath: string) => Promise<Record<string, import("smol-toml").TomlPrimitive>>;
7
8
  export declare const parseJSON: (filePath: string, contents: string) => Promise<any>;
8
9
  export declare const parseYAML: (contents: string) => Promise<unknown>;
9
10
  export declare function isTypeModule(path: string): boolean;
package/dist/util/fs.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { readFileSync, statSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import yaml from 'js-yaml';
4
+ import { parse as parseTOML } from 'smol-toml';
4
5
  import stripJsonComments from 'strip-json-comments';
5
6
  import { LoaderError } from './errors.js';
6
7
  import { FAKE_PATH } from './loader.js';
@@ -37,6 +38,10 @@ export const loadYAML = async (filePath) => {
37
38
  const contents = await loadFile(filePath);
38
39
  return parseYAML(contents);
39
40
  };
41
+ export const loadTOML = async (filePath) => {
42
+ const contents = await loadFile(filePath);
43
+ return parseTOML(contents);
44
+ };
40
45
  export const parseJSON = async (filePath, contents) => {
41
46
  try {
42
47
  return JSON.parse(stripJsonComments(contents, { trailingCommas: true }));
@@ -1,6 +1,6 @@
1
1
  import { pathToFileURL } from 'node:url';
2
2
  import { LoaderError } from './errors.js';
3
- import { loadJSON, loadYAML, loadFile, parseJSON, parseYAML } from './fs.js';
3
+ import { loadJSON, loadYAML, loadTOML, loadFile, parseJSON, parseYAML } from './fs.js';
4
4
  import { isTypeModule } from './fs.js';
5
5
  import { extname } from './path.js';
6
6
  import { timerify } from './Performance.js';
@@ -21,6 +21,9 @@ const load = async (filePath) => {
21
21
  if (ext === '.yaml' || ext === '.yml') {
22
22
  return loadYAML(filePath);
23
23
  }
24
+ if (ext === '.toml') {
25
+ return loadTOML(filePath);
26
+ }
24
27
  if (ext === '.mjs' || (ext === '.js' && isTypeModule(filePath))) {
25
28
  const fileUrl = pathToFileURL(filePath);
26
29
  const imported = await import(fileUrl.href);
@@ -1,4 +1,4 @@
1
- import type { PackageJson } from '@npmcli/package-json';
1
+ import type { PackageJson } from '../types/package-json.js';
2
2
  export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string | undefined;
3
3
  export declare const getPackageNameFromFilePath: (value: string) => string;
4
4
  export declare const normalizeSpecifierFromFilePath: (value: string) => string;
@@ -1,5 +1,4 @@
1
1
  export declare const toRegexOrString: (value: string | RegExp) => string | RegExp;
2
2
  export declare const hasMatch: (haystack: undefined | (string | RegExp)[], needle: string) => boolean | undefined;
3
3
  export declare const hasMatchInSet: (haystack: undefined | Set<string>, needle: string | RegExp) => boolean | undefined;
4
- export declare const hasMatchInArray: (haystack: string[], needle: string | RegExp) => boolean;
5
4
  export declare const findKey: (map: Map<string | RegExp, unknown>, key: RegExp) => string | RegExp | undefined;
@@ -1,5 +1,4 @@
1
1
  export const toRegexOrString = (value) => typeof value === 'string' && /[*+\\(|{^$]/.test(value) ? new RegExp(value) : value;
2
2
  export const hasMatch = (haystack, needle) => haystack && haystack.some(n => (typeof n === 'string' ? n === needle : n.test(needle)));
3
3
  export const hasMatchInSet = (haystack, needle) => haystack && (typeof needle === 'string' ? haystack.has(needle) : [...haystack].some(n => needle.test(n)));
4
- export const hasMatchInArray = (haystack, needle) => typeof needle === 'string' ? haystack.includes(needle) : haystack.some(n => needle.test(n));
5
4
  export const findKey = (map, key) => [...map.keys()].find(k => k instanceof RegExp && k.source === key.source);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "4.1.0";
1
+ export declare const version = "4.2.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '4.1.0';
1
+ export const version = '4.2.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -71,6 +71,7 @@
71
71
  "picocolors": "1.0.0",
72
72
  "picomatch": "3.0.1",
73
73
  "pretty-ms": "8.0.0",
74
+ "smol-toml": "1.1.3",
74
75
  "strip-json-comments": "5.0.1",
75
76
  "summary": "2.1.0",
76
77
  "zod": "3.22.4",
package/schema.json CHANGED
@@ -358,6 +358,10 @@
358
358
  "title": "Mocha plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/mocha/README.md)",
359
359
  "$ref": "#/definitions/plugin"
360
360
  },
361
+ "netlify": {
362
+ "title": "Netlify plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/netlify/README.md)",
363
+ "$ref": "#/definitions/plugin"
364
+ },
361
365
  "next": {
362
366
  "title": "Next.js plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/main/README.md)",
363
367
  "$ref": "#/definitions/plugin"