knip 6.25.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 (171) hide show
  1. package/dist/ConfigurationChief.d.ts +108 -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 +180 -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 +19 -0
  18. package/dist/graph/analyze.js +1 -1
  19. package/dist/graph/build.js +24 -7
  20. package/dist/plugins/_vue/auto-import.d.ts +12 -0
  21. package/dist/plugins/_vue/auto-import.js +332 -0
  22. package/dist/plugins/_vue/types.d.ts +45 -0
  23. package/dist/plugins/_vue/types.js +1 -0
  24. package/dist/plugins/astro/index.js +2 -37
  25. package/dist/plugins/astro/resolveFromAST.d.ts +4 -4
  26. package/dist/plugins/astro/resolveFromAST.js +34 -7
  27. package/dist/plugins/electron-vite/index.d.ts +3 -0
  28. package/dist/plugins/electron-vite/index.js +51 -0
  29. package/dist/plugins/electron-vite/types.d.ts +23 -0
  30. package/dist/plugins/electron-vite/types.js +1 -0
  31. package/dist/plugins/esbuild/index.d.ts +3 -0
  32. package/dist/plugins/esbuild/index.js +17 -0
  33. package/dist/plugins/eslint/resolveFromAST.js +18 -21
  34. package/dist/plugins/index.d.ts +18 -0
  35. package/dist/plugins/index.js +36 -0
  36. package/dist/plugins/laravel-vite-plugin/index.d.ts +3 -0
  37. package/dist/plugins/laravel-vite-plugin/index.js +14 -0
  38. package/dist/plugins/laravel-vite-plugin/resolveFromAST.d.ts +2 -0
  39. package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +27 -0
  40. package/dist/plugins/next/index.js +2 -2
  41. package/dist/plugins/next-mdx/index.js +2 -8
  42. package/dist/plugins/next-mdx/resolveFromAST.d.ts +3 -2
  43. package/dist/plugins/next-mdx/resolveFromAST.js +17 -21
  44. package/dist/plugins/nuxt/index.js +5 -68
  45. package/dist/plugins/nuxt/types.d.ts +0 -34
  46. package/dist/plugins/nuxtjs-i18n/index.d.ts +3 -0
  47. package/dist/plugins/nuxtjs-i18n/index.js +12 -0
  48. package/dist/plugins/oclif/index.js +10 -5
  49. package/dist/plugins/orval/index.js +1 -3
  50. package/dist/plugins/orval/resolveFromAST.d.ts +2 -2
  51. package/dist/plugins/orval/resolveFromAST.js +4 -7
  52. package/dist/plugins/oxlint/index.js +23 -2
  53. package/dist/plugins/pnpm/index.js +2 -1
  54. package/dist/plugins/pnpm/types.d.ts +2 -4
  55. package/dist/plugins/quasar/index.d.ts +3 -0
  56. package/dist/plugins/quasar/index.js +15 -0
  57. package/dist/plugins/quasar/resolveFromAST.d.ts +3 -0
  58. package/dist/plugins/quasar/resolveFromAST.js +63 -0
  59. package/dist/plugins/qwik/index.js +1 -25
  60. package/dist/plugins/qwik/resolveFromAST.d.ts +5 -3
  61. package/dist/plugins/qwik/resolveFromAST.js +28 -9
  62. package/dist/plugins/react-email/index.js +1 -0
  63. package/dist/plugins/rolldown/index.js +2 -5
  64. package/dist/plugins/rollup/index.js +2 -5
  65. package/dist/plugins/rslib/index.js +2 -5
  66. package/dist/plugins/sst/index.js +1 -5
  67. package/dist/plugins/sst/resolveFromAST.d.ts +1 -1
  68. package/dist/plugins/sst/resolveFromAST.js +1 -1
  69. package/dist/plugins/starlight/index.js +1 -19
  70. package/dist/plugins/starlight/resolveFromAST.d.ts +2 -2
  71. package/dist/plugins/starlight/resolveFromAST.js +12 -8
  72. package/dist/plugins/stencil/index.js +2 -37
  73. package/dist/plugins/stencil/resolveFromAST.d.ts +3 -0
  74. package/dist/plugins/stencil/resolveFromAST.js +36 -0
  75. package/dist/plugins/storybook/index.js +3 -0
  76. package/dist/plugins/sveltekit/index.js +1 -48
  77. package/dist/plugins/sveltekit/resolveFromAST.d.ts +2 -0
  78. package/dist/plugins/sveltekit/resolveFromAST.js +45 -0
  79. package/dist/plugins/tailwind/compiler.js +9 -4
  80. package/dist/plugins/tanstack-router/index.js +3 -1
  81. package/dist/plugins/tauri/index.d.ts +3 -0
  82. package/dist/plugins/tauri/index.js +42 -0
  83. package/dist/plugins/tauri/types.d.ts +16 -0
  84. package/dist/plugins/tauri/types.js +1 -0
  85. package/dist/plugins/temporal/index.d.ts +3 -0
  86. package/dist/plugins/temporal/index.js +12 -0
  87. package/dist/plugins/tsdown/index.js +16 -7
  88. package/dist/plugins/tsdown/types.d.ts +4 -1
  89. package/dist/plugins/tsup/index.js +2 -5
  90. package/dist/plugins/unplugin-auto-import/index.d.ts +3 -0
  91. package/dist/plugins/unplugin-auto-import/index.js +18 -0
  92. package/dist/plugins/unplugin-icons/index.d.ts +3 -0
  93. package/dist/plugins/unplugin-icons/index.js +17 -0
  94. package/dist/plugins/unplugin-vue-components/index.d.ts +3 -0
  95. package/dist/plugins/unplugin-vue-components/index.js +16 -0
  96. package/dist/plugins/unplugin-vue-i18n/index.d.ts +3 -0
  97. package/dist/plugins/unplugin-vue-i18n/index.js +10 -0
  98. package/dist/plugins/unplugin-vue-markdown/index.d.ts +3 -0
  99. package/dist/plugins/unplugin-vue-markdown/index.js +16 -0
  100. package/dist/plugins/unplugin-vue-router/index.d.ts +3 -0
  101. package/dist/plugins/unplugin-vue-router/index.js +14 -0
  102. package/dist/plugins/vite/helpers.d.ts +2 -0
  103. package/dist/plugins/vite/helpers.js +46 -31
  104. package/dist/plugins/vite/index.js +1 -1
  105. package/dist/plugins/vite-plugin-pages/index.d.ts +3 -0
  106. package/dist/plugins/vite-plugin-pages/index.js +26 -0
  107. package/dist/plugins/vite-plugin-pwa/index.d.ts +3 -0
  108. package/dist/plugins/vite-plugin-pwa/index.js +17 -0
  109. package/dist/plugins/vite-plugin-pwa/resolveFromAST.d.ts +4 -0
  110. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +37 -0
  111. package/dist/plugins/vite-plugin-vue-layouts-next/index.d.ts +3 -0
  112. package/dist/plugins/vite-plugin-vue-layouts-next/index.js +23 -0
  113. package/dist/plugins/vite-plus/index.d.ts +3 -0
  114. package/dist/plugins/vite-plus/index.js +14 -0
  115. package/dist/plugins/vite-plus/resolveFromAST.d.ts +2 -0
  116. package/dist/plugins/vite-plus/resolveFromAST.js +37 -0
  117. package/dist/plugins/vite-pwa-assets-generator/index.d.ts +3 -0
  118. package/dist/plugins/vite-pwa-assets-generator/index.js +12 -0
  119. package/dist/plugins/vitepress/index.js +5 -1
  120. package/dist/plugins/vitest/index.js +19 -0
  121. package/dist/plugins/vitest/types.d.ts +8 -0
  122. package/dist/plugins/vue/index.js +5 -3
  123. package/dist/plugins/yarn/index.js +2 -1
  124. package/dist/plugins/yarn/types.d.ts +2 -4
  125. package/dist/run.js +3 -3
  126. package/dist/schema/configuration.d.ts +270 -0
  127. package/dist/schema/plugins.d.ts +90 -0
  128. package/dist/schema/plugins.js +18 -0
  129. package/dist/types/PluginNames.d.ts +2 -2
  130. package/dist/types/PluginNames.js +18 -0
  131. package/dist/types/config.d.ts +1 -0
  132. package/dist/types/package-json.d.ts +8 -4
  133. package/dist/typescript/ast-helpers.d.ts +7 -2
  134. package/dist/typescript/ast-helpers.js +36 -8
  135. package/dist/typescript/ast-nodes.d.ts +2 -0
  136. package/dist/typescript/ast-nodes.js +8 -0
  137. package/dist/typescript/get-imports-and-exports.js +8 -5
  138. package/dist/typescript/resolve-module-names.d.ts +2 -2
  139. package/dist/typescript/resolve-module-names.js +97 -18
  140. package/dist/typescript/visitors/walk.d.ts +2 -1
  141. package/dist/typescript/visitors/walk.js +13 -2
  142. package/dist/util/cli-arguments.d.ts +1 -1
  143. package/dist/util/cli-arguments.js +1 -1
  144. package/dist/util/create-input-handler.js +8 -1
  145. package/dist/util/create-options.d.ts +180 -0
  146. package/dist/util/package-json.d.ts +7 -0
  147. package/dist/util/package-json.js +37 -0
  148. package/dist/util/resolve.d.ts +1 -0
  149. package/dist/util/resolve.js +5 -2
  150. package/dist/util/to-source-path.d.ts +4 -3
  151. package/dist/util/to-source-path.js +23 -6
  152. package/dist/version.d.ts +1 -1
  153. package/dist/version.js +1 -1
  154. package/package.json +1 -1
  155. package/schema.json +72 -0
  156. package/dist/plugins/next/resolveFromAST.d.ts +0 -2
  157. package/dist/plugins/next/resolveFromAST.js +0 -2
  158. package/dist/plugins/nuxt/helpers.d.ts +0 -15
  159. package/dist/plugins/nuxt/helpers.js +0 -133
  160. package/dist/plugins/rolldown/resolveFromAST.d.ts +0 -2
  161. package/dist/plugins/rolldown/resolveFromAST.js +0 -4
  162. package/dist/plugins/rollup/resolveFromAST.d.ts +0 -2
  163. package/dist/plugins/rollup/resolveFromAST.js +0 -4
  164. package/dist/plugins/rslib/resolveFromAST.d.ts +0 -2
  165. package/dist/plugins/rslib/resolveFromAST.js +0 -4
  166. package/dist/plugins/tsdown/resolveFromAST.d.ts +0 -2
  167. package/dist/plugins/tsdown/resolveFromAST.js +0 -4
  168. package/dist/plugins/tsup/resolveFromAST.d.ts +0 -2
  169. package/dist/plugins/tsup/resolveFromAST.js +0 -4
  170. package/dist/plugins/vue/compiler.d.ts +0 -3
  171. package/dist/plugins/vue/compiler.js +0 -10
@@ -1,7 +1,8 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, realpathSync } from 'node:fs';
2
2
  import { isBuiltin } from 'node:module';
3
- import { DEFAULT_EXTENSIONS, DTS_EXTENSIONS } from '../constants.js';
4
- import { sanitizeSpecifier } from '../util/modules.js';
3
+ import { DEFAULT_EXTENSIONS, DTS_EXTENSIONS, IS_DTS } from '../constants.js';
4
+ import { isFile } from '../util/fs.js';
5
+ import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, sanitizeSpecifier } from '../util/modules.js';
5
6
  import { timerify } from '../util/Performance.js';
6
7
  import { dirname, extname, isAbsolute, isInNodeModules, join, toPosix } from '../util/path.js';
7
8
  import { _createSyncModuleResolver, _resolveModuleSync } from '../util/resolve.js';
@@ -22,10 +23,81 @@ function pickStringTarget(value) {
22
23
  return s;
23
24
  }
24
25
  }
26
+ const invalidSegments = /(^|\\|\/)((\.|%2e)(\.|%2e)?|node_modules)(\\|\/|$)/i;
27
+ const expandPackageTarget = (target, patternMatch) => {
28
+ if (!target?.startsWith('./') || invalidSegments.test(target.slice(2)))
29
+ return;
30
+ if (!target.includes('*'))
31
+ return target;
32
+ if (patternMatch === undefined || invalidSegments.test(patternMatch))
33
+ return;
34
+ return target.replaceAll('*', patternMatch);
35
+ };
36
+ const toPackagePath = (dir, target) => {
37
+ const candidate = join(dir, target);
38
+ return candidate.startsWith(`${dir}/`) ? candidate : undefined;
39
+ };
40
+ function pickExistingPackageTarget(value, dir, patternMatch, moduleExtensions) {
41
+ if (typeof value === 'string') {
42
+ const target = expandPackageTarget(value, patternMatch);
43
+ if (!target || IS_DTS.test(target) || !moduleExtensions.has(extname(target)))
44
+ return;
45
+ const candidate = toPackagePath(dir, target);
46
+ return candidate && isFile(candidate) ? candidate : undefined;
47
+ }
48
+ if (!value || typeof value !== 'object')
49
+ return;
50
+ if (Array.isArray(value)) {
51
+ for (const item of value) {
52
+ const target = pickExistingPackageTarget(item, dir, patternMatch, moduleExtensions);
53
+ if (target)
54
+ return target;
55
+ }
56
+ return;
57
+ }
58
+ for (const [condition, child] of Object.entries(value)) {
59
+ if (condition === 'types')
60
+ continue;
61
+ const target = pickExistingPackageTarget(child, dir, patternMatch, moduleExtensions);
62
+ if (target)
63
+ return target;
64
+ }
65
+ }
25
66
  const moduleResolutionCaches = [];
67
+ const installedPackageRootCache = new Map();
26
68
  export function clearModuleResolutionCaches() {
27
69
  for (const cache of moduleResolutionCaches)
28
70
  cache.clear();
71
+ installedPackageRootCache.clear();
72
+ }
73
+ function getInstalledPackageRoot(candidate) {
74
+ if (installedPackageRootCache.has(candidate))
75
+ return installedPackageRootCache.get(candidate);
76
+ let packageRoot;
77
+ try {
78
+ packageRoot = toPosix(realpathSync(candidate));
79
+ }
80
+ catch { }
81
+ installedPackageRootCache.set(candidate, packageRoot);
82
+ return packageRoot;
83
+ }
84
+ function getAttributedPackageName(specifier, containingFile, resolvedFileName) {
85
+ const packageName = getPackageNameFromFilePath(resolvedFileName);
86
+ const specifierPackageName = getPackageNameFromModuleSpecifier(specifier);
87
+ if (!specifierPackageName || specifierPackageName === packageName)
88
+ return packageName;
89
+ let dir = dirname(containingFile);
90
+ while (true) {
91
+ const packageRoot = getInstalledPackageRoot(join(dir, 'node_modules', specifierPackageName));
92
+ if (packageRoot) {
93
+ const isResolvedInstall = resolvedFileName === packageRoot || resolvedFileName.startsWith(`${packageRoot}/`);
94
+ return isResolvedInstall ? specifierPackageName : packageName;
95
+ }
96
+ const parent = dirname(dir);
97
+ if (parent === dir)
98
+ return packageName;
99
+ dir = parent;
100
+ }
29
101
  }
30
102
  function compilePathMappings(scopedPaths) {
31
103
  if (!scopedPaths)
@@ -90,8 +162,9 @@ export function createGlobAliasResolver(scopedPaths) {
90
162
  return resolved;
91
163
  };
92
164
  }
93
- export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, findWorkspaceManifestImports, tsConfigFile) {
165
+ export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, findWorkspacePackageTarget, tsConfigFile) {
94
166
  const customCompilerExtensionsSet = new Set(customCompilerExtensions);
167
+ const moduleExtensions = new Set([...DEFAULT_EXTENSIONS, ...customCompilerExtensions, '.json', '.jsonc']);
95
168
  const hasCustomExts = customCompilerExtensionsSet.size > 0;
96
169
  const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions, ...DTS_EXTENSIONS, '.json', '.jsonc'];
97
170
  const resolveSync = hasCustomExts || tsConfigFile ? _createSyncModuleResolver(extensions, tsConfigFile) : _resolveModuleSync;
@@ -103,11 +176,15 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
103
176
  }
104
177
  return resolvedFileName;
105
178
  }
106
- function toResult(resolvedFileName) {
179
+ function toResult(specifier, containingFile, resolvedFileName) {
107
180
  const mapped = toSourcePath(resolvedFileName);
181
+ const isExternalLibraryImport = mapped === resolvedFileName && isInNodeModules(resolvedFileName);
108
182
  return {
109
183
  resolvedFileName: mapped,
110
- isExternalLibraryImport: mapped === resolvedFileName && isInNodeModules(resolvedFileName),
184
+ isExternalLibraryImport,
185
+ packageName: isExternalLibraryImport
186
+ ? getAttributedPackageName(specifier, containingFile, resolvedFileName)
187
+ : undefined,
111
188
  };
112
189
  }
113
190
  const cache = new Map();
@@ -133,7 +210,7 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
133
210
  return undefined;
134
211
  const resolvedFileName = resolveSync(specifier, containingFile);
135
212
  if (resolvedFileName)
136
- return toResult(resolvedFileName);
213
+ return toResult(specifier, containingFile, resolvedFileName);
137
214
  if (pathMappings) {
138
215
  const dir = dirname(containingFile);
139
216
  for (const { prefix, wildcard, values, scope } of pathMappings) {
@@ -146,7 +223,7 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
146
223
  const mapped = starIdx >= 0 ? value.slice(0, starIdx) + captured + value.slice(starIdx + 1) : value;
147
224
  const resolved = resolveSync(mapped, containingFile);
148
225
  if (resolved)
149
- return toResult(resolved);
226
+ return toResult(specifier, containingFile, resolved);
150
227
  }
151
228
  }
152
229
  }
@@ -165,21 +242,23 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
165
242
  continue;
166
243
  const resolved = resolveSync(join(targetRoot, relPath, specifier), containingFile);
167
244
  if (resolved)
168
- return toResult(resolved);
245
+ return toResult(specifier, containingFile, resolved);
169
246
  }
170
247
  }
171
248
  }
172
249
  }
173
- if (specifier.startsWith('#') && findWorkspaceManifestImports) {
174
- const ws = findWorkspaceManifestImports(containingFile);
175
- if (ws) {
176
- const target = pickStringTarget(ws.imports[specifier]);
177
- if (target?.startsWith('.')) {
178
- const sourcePath = toSourceFilePath(join(ws.dir, target));
179
- if (sourcePath)
180
- return toResult(sourcePath);
181
- }
250
+ const workspaceTarget = findWorkspacePackageTarget?.(specifier, containingFile);
251
+ if (workspaceTarget) {
252
+ const target = expandPackageTarget(pickStringTarget(workspaceTarget.target), workspaceTarget.patternMatch);
253
+ if (target) {
254
+ const targetPath = toPackagePath(workspaceTarget.dir, target);
255
+ const sourcePath = targetPath && toSourceFilePath(targetPath);
256
+ if (sourcePath)
257
+ return toResult(specifier, containingFile, sourcePath);
182
258
  }
259
+ const existingTarget = pickExistingPackageTarget(workspaceTarget.target, workspaceTarget.dir, workspaceTarget.patternMatch, moduleExtensions);
260
+ if (existingTarget)
261
+ return toResult(specifier, containingFile, existingTarget);
183
262
  }
184
263
  const candidate = isAbsolute(specifier) ? specifier : join(dirname(containingFile), specifier);
185
264
  if (existsSync(candidate)) {
@@ -50,6 +50,7 @@ export interface WalkState extends WalkContext {
50
50
  filePath: string;
51
51
  sourceText: string;
52
52
  isJS: boolean;
53
+ isModuleFile: boolean;
53
54
  handledImportExpressions: Set<number>;
54
55
  bareExprRefs: Set<string>;
55
56
  accessedAliases: Set<string>;
@@ -88,6 +89,6 @@ export interface WalkState extends WalkContext {
88
89
  }
89
90
  export declare const isShadowed: (name: string, pos: number) => boolean;
90
91
  export declare function buildVisitor(pluginVisitorObjects: PluginVisitorObject[], includeLocalRefs?: boolean): Visitor;
91
- declare function walkAST(program: Program, sourceText: string, filePath: string, ctx: WalkContext): Set<string> | undefined;
92
+ declare function walkAST(program: Program, sourceText: string, filePath: string, hasModuleSyntax: boolean, ctx: WalkContext): Set<string> | undefined;
92
93
  export declare const _walkAST: typeof walkAST;
93
94
  export {};
@@ -211,7 +211,7 @@ const coreVisitorObject = {
211
211
  },
212
212
  TSModuleDeclaration(node) {
213
213
  state.nsRanges.push([node.start, node.end]);
214
- if (node.kind !== 'global' && isStringLiteral(node.id)) {
214
+ if (node.kind !== 'global' && state.isModuleFile && isStringLiteral(node.id)) {
215
215
  const specifier = getStringValue(node.id);
216
216
  for (const name of collectAugmentationRefs(node))
217
217
  state.addImport(specifier, name, undefined, undefined, node.id.start, IMPORT_FLAGS.TYPE_ONLY | IMPORT_FLAGS.AUGMENT);
@@ -704,13 +704,24 @@ export function buildVisitor(pluginVisitorObjects, includeLocalRefs) {
704
704
  }
705
705
  return new Visitor(merged);
706
706
  }
707
- function walkAST(program, sourceText, filePath, ctx) {
707
+ const isExternalModule = (program, hasModuleSyntax) => {
708
+ if (hasModuleSyntax)
709
+ return true;
710
+ for (const node of program.body) {
711
+ if (node.type === 'TSImportEqualsDeclaration' && node.moduleReference.type === 'TSExternalModuleReference') {
712
+ return true;
713
+ }
714
+ }
715
+ return false;
716
+ };
717
+ function walkAST(program, sourceText, filePath, hasModuleSyntax, ctx) {
708
718
  const isJS = filePath.endsWith('.js') || filePath.endsWith('.mjs') || filePath.endsWith('.cjs') || filePath.endsWith('.jsx');
709
719
  state = {
710
720
  ...ctx,
711
721
  filePath,
712
722
  sourceText,
713
723
  isJS,
724
+ isModuleFile: isExternalModule(program, hasModuleSyntax),
714
725
  handledImportExpressions: new Set(),
715
726
  bareExprRefs: new Set(),
716
727
  accessedAliases: new Set(),
@@ -1,4 +1,4 @@
1
- export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -h, --help Print this help text\n -V, --version Print version\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n -c, --config [file] Configuration file path\n (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n --use-tsconfig-files Use tsconfig.json to define project files (override `project` patterns)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n\nMode\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --include-entry-exports Include entry files when reporting unused exports\n --no-gitignore Don't respect .gitignore\n -p, --production Analyze only production source files (e.g. no test files, devDependencies)\n -s, --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -w, --watch Watch mode\n\nScope\n -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)\n -D, --directory [dir] Run process from a different directory (default: cwd)\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved,catalog\n --exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates\n --files Shortcut for --include files\n --cycles Shortcut for --include cycles (circular dependencies)\n --tags Include or exclude tagged exports\n\nFix\n -f, --fix Fix issues (modifies files in your repo)\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n -F, --format Format modified files after --fix using the local formatter\n\nOutput\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter (default: symbols), can be repeated (3)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-tag-hints Suppress tag hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --treat-tag-hints-as-errors Exit with non-zero code (1) if there are any tag hints\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n --no-exit-code Always exit with code zero (0)\n\nTroubleshooting\n -d, --debug Show debug output\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n -u, --duration Print total running time (zero overhead, no instrumentation)\n --trace Show trace output\n --trace-dependency [name] Show files that import the named dependency\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog, cycles\n(2) Fixable issue types: dependencies, exports, types, files, catalog\n(3) Built-in reporters: symbols (default), compact, codeowners, cycles, json, codeclimate, markdown, disclosure, github-actions\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip --workspace @myorg/* --workspace '!@myorg/legacy'\n$ knip --workspace './apps/*' --workspace '@shared/utils'\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
1
+ export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -h, --help Print this help text\n -V, --version Print version\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n -c, --config [file] Configuration file path\n (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n --use-tsconfig-files Use tsconfig.json to define project files (override `project` patterns)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n\nMode\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --include-entry-exports Include entry files when reporting unused exports\n --no-gitignore Don't respect .gitignore\n -p, --production Analyze only production source files (e.g. no test files, devDependencies)\n -s, --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -w, --watch Watch mode\n\nScope\n -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)\n -D, --directory [dir] Run process from a different directory (default: cwd)\n --include Include provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved,catalog\n --exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates\n --files Shortcut for --include files\n --cycles Shortcut for --include cycles (circular dependencies)\n --tags Include or exclude tagged exports\n\nFix\n -f, --fix Fix issues (modifies files in your repo)\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n -F, --format Format modified files after --fix using the local formatter\n\nOutput\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter (default: symbols), can be repeated (3)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-tag-hints Suppress tag hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --treat-tag-hints-as-errors Exit with non-zero code (1) if there are any tag hints\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n --no-exit-code Always exit with code zero (0)\n\nTroubleshooting\n -d, --debug Show debug output\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n -u, --duration Print total running time (zero overhead, no instrumentation)\n --trace Show trace output\n --trace-dependency [name] Show files that import the named dependency\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog, cycles\n(2) Fixable issue types: dependencies, exports, types, files, catalog\n(3) Built-in reporters: symbols (default), compact, codeowners, cycles, json, codeclimate, markdown, disclosure, github-actions\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip --workspace @myorg/* --workspace '!@myorg/legacy'\n$ knip --workspace './apps/*' --workspace '@shared/utils'\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
2
2
  export type ParsedCLIArgs = ReturnType<typeof parseCLIArgs>;
3
3
  export default function parseCLIArgs(): {
4
4
  cache?: boolean | undefined;
@@ -24,7 +24,7 @@ Mode
24
24
  Scope
25
25
  -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)
26
26
  -D, --directory [dir] Run process from a different directory (default: cwd)
27
- --include Report only provided issue type(s), can be comma-separated or repeated (1)
27
+ --include Include provided issue type(s), can be comma-separated or repeated (1)
28
28
  --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
29
29
  --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved,catalog
30
30
  --exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates
@@ -55,7 +55,14 @@ export const createInputHandler = (deputy, chief, isGitIgnored, addIssue, extern
55
55
  const isWorkspace = chief.workspacesByPkgName.has(packageName);
56
56
  const inputWorkspace = getWorkspaceFor(input, chief, workspace);
57
57
  if (inputWorkspace) {
58
- const isHandled = deputy.maybeAddReferencedExternalDependency(inputWorkspace, packageName, isConfig(input), input.isTypeOnly);
58
+ let isHandled = deputy.maybeAddReferencedExternalDependency(inputWorkspace, packageName, isConfig(input), input.isTypeOnly);
59
+ if (input.isTypeOnly && input.containingFilePath) {
60
+ const owningWorkspace = chief.findWorkspaceByFilePath(input.containingFilePath);
61
+ if (owningWorkspace && owningWorkspace !== inputWorkspace) {
62
+ const isOwnerHandled = deputy.maybeAddReferencedExternalDependency(owningWorkspace, packageName, isConfig(input), input.isTypeOnly);
63
+ isHandled = isHandled || isOwnerHandled;
64
+ }
65
+ }
59
66
  if (externalRefs && !isWorkspace) {
60
67
  addExternalRef(externalRefs, containingFilePath, { specifier: packageName, identifier: undefined });
61
68
  }
@@ -185,11 +185,21 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
185
185
  entry?: string | string[] | undefined;
186
186
  project?: string | string[] | undefined;
187
187
  } | undefined;
188
+ 'electron-vite'?: string | boolean | string[] | {
189
+ config?: string | string[] | undefined;
190
+ entry?: string | string[] | undefined;
191
+ project?: string | string[] | undefined;
192
+ } | undefined;
188
193
  eleventy?: string | boolean | string[] | {
189
194
  config?: string | string[] | undefined;
190
195
  entry?: string | string[] | undefined;
191
196
  project?: string | string[] | undefined;
192
197
  } | undefined;
198
+ esbuild?: string | boolean | string[] | {
199
+ config?: string | string[] | undefined;
200
+ entry?: string | string[] | undefined;
201
+ project?: string | string[] | undefined;
202
+ } | undefined;
193
203
  eslint?: string | boolean | string[] | {
194
204
  config?: string | string[] | undefined;
195
205
  entry?: string | string[] | undefined;
@@ -285,6 +295,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
285
295
  entry?: string | string[] | undefined;
286
296
  project?: string | string[] | undefined;
287
297
  } | undefined;
298
+ 'laravel-vite-plugin'?: string | boolean | string[] | {
299
+ config?: string | string[] | undefined;
300
+ entry?: string | string[] | undefined;
301
+ project?: string | string[] | undefined;
302
+ } | undefined;
288
303
  lefthook?: string | boolean | string[] | {
289
304
  config?: string | string[] | undefined;
290
305
  entry?: string | string[] | undefined;
@@ -420,6 +435,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
420
435
  entry?: string | string[] | undefined;
421
436
  project?: string | string[] | undefined;
422
437
  } | undefined;
438
+ 'nuxtjs-i18n'?: string | boolean | string[] | {
439
+ config?: string | string[] | undefined;
440
+ entry?: string | string[] | undefined;
441
+ project?: string | string[] | undefined;
442
+ } | undefined;
423
443
  nx?: string | boolean | string[] | {
424
444
  config?: string | string[] | undefined;
425
445
  entry?: string | string[] | undefined;
@@ -525,6 +545,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
525
545
  entry?: string | string[] | undefined;
526
546
  project?: string | string[] | undefined;
527
547
  } | undefined;
548
+ quasar?: string | boolean | string[] | {
549
+ config?: string | string[] | undefined;
550
+ entry?: string | string[] | undefined;
551
+ project?: string | string[] | undefined;
552
+ } | undefined;
528
553
  qwik?: string | boolean | string[] | {
529
554
  config?: string | string[] | undefined;
530
555
  entry?: string | string[] | undefined;
@@ -715,6 +740,16 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
715
740
  entry?: string | string[] | undefined;
716
741
  project?: string | string[] | undefined;
717
742
  } | undefined;
743
+ tauri?: string | boolean | string[] | {
744
+ config?: string | string[] | undefined;
745
+ entry?: string | string[] | undefined;
746
+ project?: string | string[] | undefined;
747
+ } | undefined;
748
+ temporal?: string | boolean | string[] | {
749
+ config?: string | string[] | undefined;
750
+ entry?: string | string[] | undefined;
751
+ project?: string | string[] | undefined;
752
+ } | undefined;
718
753
  travis?: string | boolean | string[] | {
719
754
  config?: string | string[] | undefined;
720
755
  entry?: string | string[] | undefined;
@@ -760,6 +795,36 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
760
795
  entry?: string | string[] | undefined;
761
796
  project?: string | string[] | undefined;
762
797
  } | undefined;
798
+ 'unplugin-auto-import'?: string | boolean | string[] | {
799
+ config?: string | string[] | undefined;
800
+ entry?: string | string[] | undefined;
801
+ project?: string | string[] | undefined;
802
+ } | undefined;
803
+ 'unplugin-icons'?: string | boolean | string[] | {
804
+ config?: string | string[] | undefined;
805
+ entry?: string | string[] | undefined;
806
+ project?: string | string[] | undefined;
807
+ } | undefined;
808
+ 'unplugin-vue-components'?: string | boolean | string[] | {
809
+ config?: string | string[] | undefined;
810
+ entry?: string | string[] | undefined;
811
+ project?: string | string[] | undefined;
812
+ } | undefined;
813
+ 'unplugin-vue-i18n'?: string | boolean | string[] | {
814
+ config?: string | string[] | undefined;
815
+ entry?: string | string[] | undefined;
816
+ project?: string | string[] | undefined;
817
+ } | undefined;
818
+ 'unplugin-vue-markdown'?: string | boolean | string[] | {
819
+ config?: string | string[] | undefined;
820
+ entry?: string | string[] | undefined;
821
+ project?: string | string[] | undefined;
822
+ } | undefined;
823
+ 'unplugin-vue-router'?: string | boolean | string[] | {
824
+ config?: string | string[] | undefined;
825
+ entry?: string | string[] | undefined;
826
+ project?: string | string[] | undefined;
827
+ } | undefined;
763
828
  vercel?: string | boolean | string[] | {
764
829
  config?: string | string[] | undefined;
765
830
  entry?: string | string[] | undefined;
@@ -780,6 +845,31 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
780
845
  entry?: string | string[] | undefined;
781
846
  project?: string | string[] | undefined;
782
847
  } | undefined;
848
+ 'vite-plugin-pages'?: string | boolean | string[] | {
849
+ config?: string | string[] | undefined;
850
+ entry?: string | string[] | undefined;
851
+ project?: string | string[] | undefined;
852
+ } | undefined;
853
+ 'vite-plugin-pwa'?: string | boolean | string[] | {
854
+ config?: string | string[] | undefined;
855
+ entry?: string | string[] | undefined;
856
+ project?: string | string[] | undefined;
857
+ } | undefined;
858
+ 'vite-plugin-vue-layouts-next'?: string | boolean | string[] | {
859
+ config?: string | string[] | undefined;
860
+ entry?: string | string[] | undefined;
861
+ project?: string | string[] | undefined;
862
+ } | undefined;
863
+ 'vite-plus'?: string | boolean | string[] | {
864
+ config?: string | string[] | undefined;
865
+ entry?: string | string[] | undefined;
866
+ project?: string | string[] | undefined;
867
+ } | undefined;
868
+ 'vite-pwa-assets-generator'?: string | boolean | string[] | {
869
+ config?: string | string[] | undefined;
870
+ entry?: string | string[] | undefined;
871
+ project?: string | string[] | undefined;
872
+ } | undefined;
783
873
  vitepress?: string | boolean | string[] | {
784
874
  config?: string | string[] | undefined;
785
875
  entry?: string | string[] | undefined;
@@ -1008,11 +1098,21 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1008
1098
  entry?: string | string[] | undefined;
1009
1099
  project?: string | string[] | undefined;
1010
1100
  } | undefined;
1101
+ 'electron-vite'?: string | boolean | string[] | {
1102
+ config?: string | string[] | undefined;
1103
+ entry?: string | string[] | undefined;
1104
+ project?: string | string[] | undefined;
1105
+ } | undefined;
1011
1106
  eleventy?: string | boolean | string[] | {
1012
1107
  config?: string | string[] | undefined;
1013
1108
  entry?: string | string[] | undefined;
1014
1109
  project?: string | string[] | undefined;
1015
1110
  } | undefined;
1111
+ esbuild?: string | boolean | string[] | {
1112
+ config?: string | string[] | undefined;
1113
+ entry?: string | string[] | undefined;
1114
+ project?: string | string[] | undefined;
1115
+ } | undefined;
1016
1116
  eslint?: string | boolean | string[] | {
1017
1117
  config?: string | string[] | undefined;
1018
1118
  entry?: string | string[] | undefined;
@@ -1108,6 +1208,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1108
1208
  entry?: string | string[] | undefined;
1109
1209
  project?: string | string[] | undefined;
1110
1210
  } | undefined;
1211
+ 'laravel-vite-plugin'?: string | boolean | string[] | {
1212
+ config?: string | string[] | undefined;
1213
+ entry?: string | string[] | undefined;
1214
+ project?: string | string[] | undefined;
1215
+ } | undefined;
1111
1216
  lefthook?: string | boolean | string[] | {
1112
1217
  config?: string | string[] | undefined;
1113
1218
  entry?: string | string[] | undefined;
@@ -1243,6 +1348,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1243
1348
  entry?: string | string[] | undefined;
1244
1349
  project?: string | string[] | undefined;
1245
1350
  } | undefined;
1351
+ 'nuxtjs-i18n'?: string | boolean | string[] | {
1352
+ config?: string | string[] | undefined;
1353
+ entry?: string | string[] | undefined;
1354
+ project?: string | string[] | undefined;
1355
+ } | undefined;
1246
1356
  nx?: string | boolean | string[] | {
1247
1357
  config?: string | string[] | undefined;
1248
1358
  entry?: string | string[] | undefined;
@@ -1348,6 +1458,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1348
1458
  entry?: string | string[] | undefined;
1349
1459
  project?: string | string[] | undefined;
1350
1460
  } | undefined;
1461
+ quasar?: string | boolean | string[] | {
1462
+ config?: string | string[] | undefined;
1463
+ entry?: string | string[] | undefined;
1464
+ project?: string | string[] | undefined;
1465
+ } | undefined;
1351
1466
  qwik?: string | boolean | string[] | {
1352
1467
  config?: string | string[] | undefined;
1353
1468
  entry?: string | string[] | undefined;
@@ -1538,6 +1653,16 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1538
1653
  entry?: string | string[] | undefined;
1539
1654
  project?: string | string[] | undefined;
1540
1655
  } | undefined;
1656
+ tauri?: string | boolean | string[] | {
1657
+ config?: string | string[] | undefined;
1658
+ entry?: string | string[] | undefined;
1659
+ project?: string | string[] | undefined;
1660
+ } | undefined;
1661
+ temporal?: string | boolean | string[] | {
1662
+ config?: string | string[] | undefined;
1663
+ entry?: string | string[] | undefined;
1664
+ project?: string | string[] | undefined;
1665
+ } | undefined;
1541
1666
  travis?: string | boolean | string[] | {
1542
1667
  config?: string | string[] | undefined;
1543
1668
  entry?: string | string[] | undefined;
@@ -1583,6 +1708,36 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1583
1708
  entry?: string | string[] | undefined;
1584
1709
  project?: string | string[] | undefined;
1585
1710
  } | undefined;
1711
+ 'unplugin-auto-import'?: string | boolean | string[] | {
1712
+ config?: string | string[] | undefined;
1713
+ entry?: string | string[] | undefined;
1714
+ project?: string | string[] | undefined;
1715
+ } | undefined;
1716
+ 'unplugin-icons'?: string | boolean | string[] | {
1717
+ config?: string | string[] | undefined;
1718
+ entry?: string | string[] | undefined;
1719
+ project?: string | string[] | undefined;
1720
+ } | undefined;
1721
+ 'unplugin-vue-components'?: string | boolean | string[] | {
1722
+ config?: string | string[] | undefined;
1723
+ entry?: string | string[] | undefined;
1724
+ project?: string | string[] | undefined;
1725
+ } | undefined;
1726
+ 'unplugin-vue-i18n'?: string | boolean | string[] | {
1727
+ config?: string | string[] | undefined;
1728
+ entry?: string | string[] | undefined;
1729
+ project?: string | string[] | undefined;
1730
+ } | undefined;
1731
+ 'unplugin-vue-markdown'?: string | boolean | string[] | {
1732
+ config?: string | string[] | undefined;
1733
+ entry?: string | string[] | undefined;
1734
+ project?: string | string[] | undefined;
1735
+ } | undefined;
1736
+ 'unplugin-vue-router'?: string | boolean | string[] | {
1737
+ config?: string | string[] | undefined;
1738
+ entry?: string | string[] | undefined;
1739
+ project?: string | string[] | undefined;
1740
+ } | undefined;
1586
1741
  vercel?: string | boolean | string[] | {
1587
1742
  config?: string | string[] | undefined;
1588
1743
  entry?: string | string[] | undefined;
@@ -1603,6 +1758,31 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1603
1758
  entry?: string | string[] | undefined;
1604
1759
  project?: string | string[] | undefined;
1605
1760
  } | undefined;
1761
+ 'vite-plugin-pages'?: string | boolean | string[] | {
1762
+ config?: string | string[] | undefined;
1763
+ entry?: string | string[] | undefined;
1764
+ project?: string | string[] | undefined;
1765
+ } | undefined;
1766
+ 'vite-plugin-pwa'?: string | boolean | string[] | {
1767
+ config?: string | string[] | undefined;
1768
+ entry?: string | string[] | undefined;
1769
+ project?: string | string[] | undefined;
1770
+ } | undefined;
1771
+ 'vite-plugin-vue-layouts-next'?: string | boolean | string[] | {
1772
+ config?: string | string[] | undefined;
1773
+ entry?: string | string[] | undefined;
1774
+ project?: string | string[] | undefined;
1775
+ } | undefined;
1776
+ 'vite-plus'?: string | boolean | string[] | {
1777
+ config?: string | string[] | undefined;
1778
+ entry?: string | string[] | undefined;
1779
+ project?: string | string[] | undefined;
1780
+ } | undefined;
1781
+ 'vite-pwa-assets-generator'?: string | boolean | string[] | {
1782
+ config?: string | string[] | undefined;
1783
+ entry?: string | string[] | undefined;
1784
+ project?: string | string[] | undefined;
1785
+ } | undefined;
1606
1786
  vitepress?: string | boolean | string[] | {
1607
1787
  config?: string | string[] | undefined;
1608
1788
  entry?: string | string[] | undefined;
@@ -5,6 +5,13 @@ interface ExtendedPackageJson extends PackageJson {
5
5
  [INDENT]?: string;
6
6
  [NEWLINE]?: string;
7
7
  }
8
+ export declare const getPackageMapTarget: (map: unknown, key: string) => {
9
+ target: any;
10
+ patternMatch?: undefined;
11
+ } | {
12
+ target: unknown;
13
+ patternMatch: string;
14
+ } | undefined;
8
15
  export declare const load: (filePath: string) => Promise<ExtendedPackageJson>;
9
16
  export declare const save: (filePath: string, content: ExtendedPackageJson) => Promise<void>;
10
17
  export declare const getEntrySpecifiersFromManifest: (manifest: PackageJson) => Set<string>;
@@ -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'],
@@ -20,7 +20,10 @@ const createSyncModuleResolver = (extensions, tsConfigFile) => {
20
20
  tsconfig: tsConfigFile ? { configFile: tsConfigFile, references: 'auto' } : 'auto',
21
21
  ...baseOptions,
22
22
  });
23
- const fallbackResolver = new ResolverFactory(baseOptions);
23
+ const fallbackResolver = new ResolverFactory({
24
+ ...baseOptions,
25
+ conditionNames: ['require', 'import', 'browser', 'default'],
26
+ });
24
27
  resolverInstances.push(resolver, fallbackResolver);
25
28
  return function resolveSync(specifier, basePath) {
26
29
  const resolved = resolver.resolveFileSync(basePath, specifier);