knip 6.26.0 → 6.27.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 (57) hide show
  1. package/dist/ConfigurationChief.d.ts +6 -0
  2. package/dist/DependencyDeputy.d.ts +1 -1
  3. package/dist/DependencyDeputy.js +2 -2
  4. package/dist/ProjectPrincipal.d.ts +3 -3
  5. package/dist/ProjectPrincipal.js +4 -4
  6. package/dist/binaries/fallback.js +5 -1
  7. package/dist/binaries/resolvers/bun.js +13 -5
  8. package/dist/binaries/resolvers/npm.js +4 -2
  9. package/dist/binaries/resolvers/pnpm.js +11 -1
  10. package/dist/binaries/resolvers/yarn.js +10 -4
  11. package/dist/binaries/util.d.ts +4 -0
  12. package/dist/binaries/util.js +14 -0
  13. package/dist/compilers/index.d.ts +10 -0
  14. package/dist/compilers/less.js +1 -1
  15. package/dist/compilers/scss.js +1 -1
  16. package/dist/compilers/stylus.js +1 -1
  17. package/dist/constants.js +6 -0
  18. package/dist/graph/analyze.js +1 -1
  19. package/dist/graph/build.js +16 -4
  20. package/dist/plugins/_vue/auto-import.js +64 -4
  21. package/dist/plugins/_vue/types.d.ts +18 -11
  22. package/dist/plugins/index.d.ts +1 -0
  23. package/dist/plugins/index.js +2 -0
  24. package/dist/plugins/react-email/index.js +1 -0
  25. package/dist/plugins/tailwind/compiler.js +9 -4
  26. package/dist/plugins/tanstack-router/index.js +3 -1
  27. package/dist/plugins/temporal/index.d.ts +3 -0
  28. package/dist/plugins/temporal/index.js +12 -0
  29. package/dist/plugins/tsdown/index.js +15 -3
  30. package/dist/plugins/tsdown/types.d.ts +4 -1
  31. package/dist/plugins/vitest/index.js +15 -0
  32. package/dist/plugins/vitest/types.d.ts +5 -0
  33. package/dist/run.js +3 -3
  34. package/dist/schema/configuration.d.ts +15 -0
  35. package/dist/schema/plugins.d.ts +5 -0
  36. package/dist/schema/plugins.js +1 -0
  37. package/dist/types/PluginNames.d.ts +2 -2
  38. package/dist/types/PluginNames.js +1 -0
  39. package/dist/types/config.d.ts +1 -0
  40. package/dist/typescript/ast-nodes.d.ts +1 -0
  41. package/dist/typescript/get-imports-and-exports.js +8 -5
  42. package/dist/typescript/resolve-module-names.d.ts +2 -2
  43. package/dist/typescript/resolve-module-names.js +97 -18
  44. package/dist/typescript/visitors/walk.d.ts +2 -1
  45. package/dist/typescript/visitors/walk.js +13 -2
  46. package/dist/util/create-input-handler.js +8 -1
  47. package/dist/util/create-options.d.ts +10 -0
  48. package/dist/util/package-json.d.ts +7 -0
  49. package/dist/util/package-json.js +37 -0
  50. package/dist/util/resolve.d.ts +1 -0
  51. package/dist/util/resolve.js +1 -1
  52. package/dist/util/to-source-path.d.ts +4 -3
  53. package/dist/util/to-source-path.js +22 -5
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +1 -1
  56. package/package.json +1 -1
  57. package/schema.json +4 -0
@@ -35,6 +35,43 @@ const getEntriesFromExports = (obj) => {
35
35
  }
36
36
  return values;
37
37
  };
38
+ export const getPackageMapTarget = (map, key) => {
39
+ if (!map || typeof map !== 'object' || Array.isArray(map))
40
+ return key === '.' ? { target: map } : undefined;
41
+ const entries = Object.entries(map);
42
+ let hasSubpaths = false;
43
+ for (const [subpath, target] of entries) {
44
+ if (!subpath.startsWith('.') && !subpath.startsWith('#'))
45
+ continue;
46
+ hasSubpaths = true;
47
+ if (subpath === key)
48
+ return { target };
49
+ }
50
+ if (!hasSubpaths)
51
+ return key === '.' ? { target: map } : undefined;
52
+ let best;
53
+ for (const [subpath, target] of entries) {
54
+ const starIndex = subpath.indexOf('*');
55
+ if (starIndex < 0)
56
+ continue;
57
+ const prefix = subpath.slice(0, starIndex);
58
+ const suffix = subpath.slice(starIndex + 1);
59
+ if (!key.startsWith(prefix) || !key.endsWith(suffix) || key.length < prefix.length + suffix.length)
60
+ continue;
61
+ if (!best ||
62
+ prefix.length > best.prefixLength ||
63
+ (prefix.length === best.prefixLength && subpath.length > best.subpathLength)) {
64
+ best = {
65
+ target,
66
+ patternMatch: key.slice(prefix.length, key.length - suffix.length),
67
+ prefixLength: prefix.length,
68
+ subpathLength: subpath.length,
69
+ };
70
+ }
71
+ }
72
+ if (best)
73
+ return { target: best.target, patternMatch: best.patternMatch };
74
+ };
38
75
  export const load = async (filePath) => {
39
76
  const file = await readFile(filePath, 'utf8');
40
77
  return parseJson(file);
@@ -1,3 +1,4 @@
1
+ export declare const extensionAlias: Record<string, string[]>;
1
2
  export declare const _resolveModuleSync: (specifier: string, basePath: string) => string | undefined;
2
3
  export declare const _createSyncModuleResolver: (extensions: string[], tsConfigFile?: string) => (specifier: string, basePath: string) => string | undefined;
3
4
  export declare function clearResolverCache(): void;
@@ -2,7 +2,7 @@ import { ResolverFactory } from 'oxc-resolver';
2
2
  import { DEFAULT_EXTENSIONS, DTS_EXTENSIONS } from '../constants.js';
3
3
  import { timerify } from './Performance.js';
4
4
  import { toPosix } from './path.js';
5
- const extensionAlias = {
5
+ export const extensionAlias = {
6
6
  '.js': ['.js', '.ts', '.tsx', '.d.ts'],
7
7
  '.jsx': ['.jsx', '.tsx'],
8
8
  '.mjs': ['.mjs', '.mts', '.d.mts'],
@@ -2,11 +2,12 @@ import type { SourceMap } from '../types/config.ts';
2
2
  import type { CompilerOptions } from '../types/project.ts';
3
3
  import type { ConfigurationChief, Workspace } from '../ConfigurationChief.ts';
4
4
  export declare const augmentWorkspace: (workspace: Workspace, dir: string, compilerOptions: CompilerOptions | undefined, pluginSourceMaps?: SourceMap[]) => void;
5
- export type WorkspaceManifestHandler = (filePath: string) => {
5
+ export type WorkspacePackageTargetHandler = (specifier: string, filePath: string) => {
6
6
  dir: string;
7
- imports: unknown;
7
+ target: unknown;
8
+ patternMatch?: string;
8
9
  } | undefined;
9
- export declare const getWorkspaceManifestHandler: (chief: ConfigurationChief) => WorkspaceManifestHandler;
10
+ export declare const getWorkspacePackageTargetHandler: (chief: ConfigurationChief) => WorkspacePackageTargetHandler;
10
11
  export declare const getModuleSourcePathHandler: (chief: ConfigurationChief) => (filePath: string) => string | undefined;
11
12
  export declare const getToSourcePathsHandler: (chief: ConfigurationChief) => (specifiers: Set<string>, dir: string, extensions: string | undefined, label: string) => Promise<string[]>;
12
13
  export declare const toSourceMappedSpecifiers: (ws: Workspace | undefined, absSpecifier: string, extensions?: string) => string[];
@@ -2,6 +2,8 @@ import { DEFAULT_EXTENSIONS } from '../constants.js';
2
2
  import { debugLog, debugLogArray } from './debug.js';
3
3
  import { findFileWithExtensions, isDirectory } from './fs.js';
4
4
  import { _glob, prependDirToPattern } from './glob.js';
5
+ import { getPackageNameFromModuleSpecifier } from './modules.js';
6
+ import { getPackageMapTarget } from './package-json.js';
5
7
  import { isAbsolute, isInternal, join, toRelative } from './path.js';
6
8
  const defaultExtensions = `.{${[...DEFAULT_EXTENSIONS].map(ext => ext.slice(1)).join(',')}}`;
7
9
  const hasTSExt = /(?<!\.d)\.(m|c)?tsx?$/;
@@ -41,15 +43,30 @@ const rewritePattern = (sourceMaps, absSpecifier, extensions) => {
41
43
  return r;
42
44
  }
43
45
  };
44
- export const getWorkspaceManifestHandler = (chief) => {
45
- return (filePath) => {
46
- const workspace = chief.findWorkspaceByFilePath(filePath);
46
+ export const getWorkspacePackageTargetHandler = (chief) => {
47
+ return (specifier, filePath) => {
48
+ const isImports = specifier.startsWith('#');
49
+ let workspace;
50
+ let key = specifier;
51
+ if (isImports) {
52
+ workspace = chief.findWorkspaceByFilePath(filePath);
53
+ }
54
+ else {
55
+ const packageName = getPackageNameFromModuleSpecifier(specifier);
56
+ if (!packageName)
57
+ return;
58
+ workspace = chief.workspacesByPkgName.get(packageName);
59
+ key = packageName === specifier ? '.' : `.${specifier.slice(packageName.length)}`;
60
+ }
47
61
  if (!workspace)
48
62
  return;
49
63
  const manifest = chief.workspacePackages.get(workspace.name)?.manifest;
50
- if (!manifest?.imports)
64
+ const map = isImports ? manifest?.imports : manifest?.exports;
65
+ if (!manifest || !map)
51
66
  return;
52
- return { dir: workspace.dir, imports: manifest.imports };
67
+ const result = getPackageMapTarget(map, key);
68
+ if (result)
69
+ return { dir: workspace.dir, ...result };
53
70
  };
54
71
  };
55
72
  export const getModuleSourcePathHandler = (chief) => {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.26.0";
1
+ export declare const version = "6.27.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.26.0';
1
+ export const version = '6.27.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.26.0",
3
+ "version": "6.27.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
package/schema.json CHANGED
@@ -942,6 +942,10 @@
942
942
  "title": "tauri plugin configuration (https://knip.dev/reference/plugins/tauri)",
943
943
  "$ref": "#/definitions/plugin"
944
944
  },
945
+ "temporal": {
946
+ "title": "temporal plugin configuration (https://knip.dev/reference/plugins/temporal)",
947
+ "$ref": "#/definitions/plugin"
948
+ },
945
949
  "travis": {
946
950
  "title": "travis plugin configuration (https://knip.dev/reference/plugins/travis)",
947
951
  "$ref": "#/definitions/plugin"