knip 5.27.0 → 5.27.2

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 (47) hide show
  1. package/dist/PrincipalFactory.js +3 -2
  2. package/dist/binaries/util.js +2 -2
  3. package/dist/index.js +2 -2
  4. package/dist/plugins/eslint/helpers.js +8 -7
  5. package/dist/plugins/playwright/index.d.ts +1 -1
  6. package/dist/plugins/playwright/types.d.ts +36 -0
  7. package/dist/plugins/playwright/types.js +1 -0
  8. package/dist/plugins/playwright-ct/index.d.ts +2 -2
  9. package/dist/typescript/resolve-module-names.js +3 -2
  10. package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
  11. package/dist/typescript/visitors/dynamic-imports/importCall.js +17 -21
  12. package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
  13. package/dist/typescript/visitors/dynamic-imports/index.d.ts +1 -1
  14. package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +1 -1
  15. package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +1 -1
  16. package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +1 -1
  17. package/dist/typescript/visitors/dynamic-imports/requireCall.js +8 -4
  18. package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
  19. package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
  20. package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
  21. package/dist/typescript/visitors/exports/exportsAccessExpression.d.ts +1 -1
  22. package/dist/typescript/visitors/exports/index.d.ts +1 -1
  23. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
  24. package/dist/typescript/visitors/helpers.js +1 -1
  25. package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
  26. package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
  27. package/dist/typescript/visitors/imports/index.d.ts +1 -1
  28. package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
  29. package/dist/typescript/visitors/scripts/bun.d.ts +1 -1
  30. package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
  31. package/dist/typescript/visitors/scripts/index.d.ts +1 -1
  32. package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
  33. package/dist/util/handle-dependency.js +6 -8
  34. package/dist/util/loader.js +1 -1
  35. package/dist/util/modules.d.ts +0 -1
  36. package/dist/util/modules.js +0 -7
  37. package/dist/util/plugin.d.ts +1 -0
  38. package/dist/util/plugin.js +7 -6
  39. package/dist/util/require.d.ts +0 -3
  40. package/dist/util/require.js +3 -34
  41. package/dist/util/resolve.d.ts +2 -1
  42. package/dist/util/resolve.js +21 -12
  43. package/dist/version.d.ts +1 -1
  44. package/dist/version.js +1 -1
  45. package/package.json +3 -5
  46. /package/dist/util/{register.d.ts → jiti.d.ts} +0 -0
  47. /package/dist/util/{register.js → jiti.js} +0 -0
@@ -7,8 +7,9 @@ const mapToAbsolutePaths = (paths, cwd) => Object.keys(paths).reduce((result, ke
7
7
  return result;
8
8
  }, {});
9
9
  const mergePaths = (cwd, compilerOptions, paths = {}) => {
10
+ const basePath = typeof compilerOptions.pathsBasePath === 'string' ? compilerOptions.pathsBasePath : cwd;
10
11
  const compilerPaths = !compilerOptions.baseUrl && compilerOptions.paths
11
- ? mapToAbsolutePaths(compilerOptions.paths, cwd)
12
+ ? mapToAbsolutePaths(compilerOptions.paths, basePath)
12
13
  : compilerOptions.paths;
13
14
  const extraPaths = mapToAbsolutePaths(paths, cwd);
14
15
  compilerOptions.paths = { ...compilerPaths, ...extraPaths };
@@ -19,7 +20,7 @@ export class PrincipalFactory {
19
20
  getPrincipal(options) {
20
21
  const { cwd, compilerOptions, isFile, paths, pkgName, isIsolateWorkspaces, compilers } = options;
21
22
  options.compilerOptions = mergePaths(cwd, compilerOptions, paths);
22
- if (isFile)
23
+ if (isFile && compilerOptions.module !== ts.ModuleKind.CommonJS)
23
24
  compilerOptions.moduleResolution ??= ts.ModuleResolutionKind.Bundler;
24
25
  const principal = this.findReusablePrincipal(compilerOptions);
25
26
  if (!isIsolateWorkspaces && principal) {
@@ -1,12 +1,12 @@
1
1
  import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier } from '../util/modules.js';
2
2
  import { isAbsolute, isInNodeModules, join } from '../util/path.js';
3
3
  import { toBinary } from '../util/protocols.js';
4
- import { _tryResolve } from '../util/require.js';
4
+ import { _resolveSync } from '../util/resolve.js';
5
5
  export const tryResolveFilePath = (cwd, specifier, acceptModuleSpecifier) => {
6
6
  if (specifier) {
7
7
  const filePath = isAbsolute(specifier) ? specifier : join(cwd, specifier);
8
8
  if (!isInNodeModules(filePath)) {
9
- const resolvedFilePath = _tryResolve(filePath, cwd);
9
+ const resolvedFilePath = _resolveSync(filePath, cwd);
10
10
  if (resolvedFilePath) {
11
11
  return resolvedFilePath;
12
12
  }
package/dist/index.js CHANGED
@@ -126,7 +126,7 @@ export const main = async (unresolvedConfiguration) => {
126
126
  const negatedEntryPatterns = Array.from(entryFilePatterns).map(negate);
127
127
  {
128
128
  const patterns = worker.getProductionEntryFilePatterns(negatedEntryPatterns);
129
- const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
129
+ const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, gitignore: false });
130
130
  debugLogArray(name, 'Entry paths', workspaceEntryPaths);
131
131
  principal.addEntryPaths(workspaceEntryPaths);
132
132
  }
@@ -147,7 +147,7 @@ export const main = async (unresolvedConfiguration) => {
147
147
  else {
148
148
  {
149
149
  const patterns = worker.getEntryFilePatterns();
150
- const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
150
+ const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, gitignore: false });
151
151
  debugLogArray(name, 'Entry paths', workspaceEntryPaths);
152
152
  principal.addEntryPaths(workspaceEntryPaths);
153
153
  }
@@ -1,8 +1,7 @@
1
1
  import { compact } from '#p/util/array.js';
2
2
  import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier } from '#p/util/modules.js';
3
3
  import { basename, dirname, isAbsolute, isInternal, toAbsolute } from '#p/util/path.js';
4
- import { load } from '#p/util/plugin.js';
5
- import { _resolve } from '#p/util/require.js';
4
+ import { load, resolve } from '#p/util/plugin.js';
6
5
  import { getDependenciesFromConfig } from '../babel/index.js';
7
6
  const getDependencies = (config) => {
8
7
  const extendsSpecifiers = config.extends ? [config.extends].flat().map(resolveExtendSpecifier) : [];
@@ -27,11 +26,13 @@ export const getDependenciesDeep = async (localConfig, options, dependencies = n
27
26
  if (localConfig.extends) {
28
27
  for (const extend of [localConfig.extends].flat()) {
29
28
  if (isInternal(extend)) {
30
- const filePath = _resolve(toAbsolute(extend, configFileDir));
31
- dependencies.add(filePath);
32
- const localConfig = await load(filePath);
33
- const opts = { ...options, configFileDir: dirname(filePath), configFileName: basename(filePath) };
34
- addAll(await getDependenciesDeep(localConfig, opts, dependencies));
29
+ const filePath = resolve(toAbsolute(extend, configFileDir), configFileDir);
30
+ if (filePath) {
31
+ dependencies.add(filePath);
32
+ const localConfig = await load(filePath);
33
+ const opts = { ...options, configFileDir: dirname(filePath), configFileName: basename(filePath) };
34
+ addAll(await getDependenciesDeep(localConfig, opts, dependencies));
35
+ }
35
36
  }
36
37
  }
37
38
  }
@@ -1,5 +1,5 @@
1
- import type { PlaywrightTestConfig } from 'playwright/test';
2
1
  import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { PlaywrightTestConfig } from './types.js';
3
3
  export declare const entry: string[];
4
4
  export declare const resolveEntryPaths: ResolveEntryPaths<PlaywrightTestConfig>;
5
5
  export declare const resolveConfig: ResolveConfig<PlaywrightTestConfig>;
@@ -0,0 +1,36 @@
1
+ type LiteralUnion<T extends U, U = string> = T | (U & {
2
+ zz_IGNORE_ME?: never;
3
+ });
4
+ type ReporterDescription = Readonly<['blob'] | ['blob', {
5
+ outputDir?: string;
6
+ fileName?: string;
7
+ }] | ['dot'] | ['line'] | ['list'] | ['list', {
8
+ printSteps?: boolean;
9
+ }] | ['github'] | ['junit'] | ['junit', {
10
+ outputFile?: string;
11
+ stripANSIControlSequences?: boolean;
12
+ includeProjectInTestName?: boolean;
13
+ }] | ['json'] | ['json', {
14
+ outputFile?: string;
15
+ }] | ['html'] | [
16
+ 'html',
17
+ {
18
+ outputFolder?: string;
19
+ open?: 'always' | 'never' | 'on-failure';
20
+ host?: string;
21
+ port?: number;
22
+ attachmentsBaseURL?: string;
23
+ }
24
+ ] | ['null'] | [string] | [string, any]>;
25
+ type Project = {
26
+ name: string;
27
+ use: string;
28
+ testMatch?: string | RegExp | (string | RegExp)[];
29
+ };
30
+ export type PlaywrightTestConfig = {
31
+ projects?: Project[];
32
+ testMatch?: string | RegExp | (string | RegExp)[];
33
+ testDir?: string;
34
+ reporter?: LiteralUnion<'dot' | 'line' | 'list' | 'junit' | 'html' | 'json' | 'github' | 'null', string> | ReporterDescription[];
35
+ };
36
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -5,7 +5,7 @@ declare const _default: {
5
5
  isEnabled: IsPluginEnabled;
6
6
  config: string[];
7
7
  entry: string[];
8
- resolveEntryPaths: import("#p/types/plugins.js").ResolveEntryPaths<import("playwright/test").PlaywrightTestConfig>;
9
- resolveConfig: import("#p/types/plugins.js").ResolveConfig<import("playwright/test").PlaywrightTestConfig>;
8
+ resolveEntryPaths: import("#p/types/plugins.js").ResolveEntryPaths<import("../playwright/types.js").PlaywrightTestConfig>;
9
+ resolveConfig: import("#p/types/plugins.js").ResolveConfig<import("../playwright/types.js").PlaywrightTestConfig>;
10
10
  };
11
11
  export default _default;
@@ -5,7 +5,7 @@ import { DEFAULT_EXTENSIONS } from '../constants.js';
5
5
  import { timerify } from '../util/Performance.js';
6
6
  import { sanitizeSpecifier } from '../util/modules.js';
7
7
  import { dirname, extname, isAbsolute, isInNodeModules, join } from '../util/path.js';
8
- import { resolveSync } from '../util/resolve.js';
8
+ import { _resolveSync, createSyncResolver } from '../util/resolve.js';
9
9
  import { isDeclarationFileExtension } from './ast-helpers.js';
10
10
  const resolutionCache = new Map();
11
11
  const fileExists = (name, containingFile) => {
@@ -22,6 +22,7 @@ const fileExists = (name, containingFile) => {
22
22
  export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, useCache = true) {
23
23
  const customCompilerExtensionsSet = new Set(customCompilerExtensions);
24
24
  const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions];
25
+ const resolveSync = customCompilerExtensionsSet.size === 0 ? _resolveSync : createSyncResolver(extensions);
25
26
  const virtualDeclarationFiles = new Map();
26
27
  const tsSys = {
27
28
  ...ts.sys,
@@ -56,7 +57,7 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
56
57
  const sanitizedSpecifier = sanitizeSpecifier(name);
57
58
  if (isBuiltin(sanitizedSpecifier) || isInNodeModules(name))
58
59
  return undefined;
59
- const resolvedFileName = resolveSync(sanitizedSpecifier, containingFile, extensions);
60
+ const resolvedFileName = resolveSync(sanitizedSpecifier, dirname(containingFile));
60
61
  if (resolvedFileName) {
61
62
  const ext = extname(resolvedFileName);
62
63
  if (!customCompilerExtensionsSet.has(ext)) {
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
3
3
  export default _default;
@@ -2,6 +2,7 @@ import ts from 'typescript';
2
2
  import { ANONYMOUS } from '../../../constants.js';
3
3
  import { findAncestor, findDescendants, isAccessExpression, isImportCall, isTopLevel, stripQuotes, } from '../../ast-helpers.js';
4
4
  import { importVisitor as visit } from '../index.js';
5
+ const getSymbol = (node, isTopLevel) => (isTopLevel ? node.symbol : undefined);
5
6
  export default visit(() => true, node => {
6
7
  if (isImportCall(node)) {
7
8
  if (node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) {
@@ -34,12 +35,7 @@ export default visit(() => true, node => {
34
35
  return arg.name.elements.map(element => {
35
36
  const identifier = (element.propertyName ?? element.name).getText();
36
37
  const alias = element.propertyName ? element.name.getText() : undefined;
37
- return {
38
- identifier,
39
- alias,
40
- specifier,
41
- pos: element.pos,
42
- };
38
+ return { identifier, alias, specifier, pos: element.pos };
43
39
  });
44
40
  }
45
41
  }
@@ -51,9 +47,9 @@ export default visit(() => true, node => {
51
47
  return ts.isVariableDeclaration(_node);
52
48
  });
53
49
  if (variableDeclaration) {
54
- const isTLA = isTopLevel(variableDeclaration.parent);
55
50
  const alias = String(variableDeclaration.name.escapedText);
56
- return { identifier, alias, symbol: isTLA ? variableDeclaration.symbol : undefined, specifier, pos };
51
+ const symbol = getSymbol(variableDeclaration, isTopLevel(variableDeclaration.parent));
52
+ return { identifier, alias, symbol, specifier, pos };
57
53
  }
58
54
  return { identifier, specifier, pos };
59
55
  }
@@ -71,20 +67,17 @@ export default visit(() => true, node => {
71
67
  ts.isVariableDeclarationList(variableDeclaration.parent)) {
72
68
  const isTLA = isTopLevel(variableDeclaration.parent);
73
69
  if (ts.isIdentifier(variableDeclaration.name)) {
74
- return {
75
- identifier: 'default',
76
- alias: String(variableDeclaration.name.escapedText),
77
- symbol: isTLA ? variableDeclaration.symbol : undefined,
78
- specifier,
79
- pos: node.arguments[0].pos,
80
- };
70
+ const alias = String(variableDeclaration.name.escapedText);
71
+ const symbol = getSymbol(variableDeclaration, isTLA);
72
+ return { identifier: 'default', alias, symbol, specifier, pos: node.arguments[0].pos };
81
73
  }
82
74
  const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
83
75
  if (bindings.length > 0) {
84
76
  return bindings.map(element => {
85
77
  const identifier = (element.propertyName ?? element.name).getText();
86
78
  const alias = element.propertyName ? element.name.getText() : undefined;
87
- return { identifier, alias, symbol: isTLA ? element.symbol : undefined, specifier, pos: element.pos };
79
+ const symbol = getSymbol(element, isTLA);
80
+ return { identifier, alias, symbol, specifier, pos: element.pos };
88
81
  });
89
82
  }
90
83
  return { identifier: ANONYMOUS, specifier, pos: node.arguments[0].pos };
@@ -99,18 +92,21 @@ export default visit(() => true, node => {
99
92
  const index = arrayLiteralExpression.elements.indexOf(node);
100
93
  const element = variableDeclarationParent.name.elements[index];
101
94
  if (element) {
102
- const isTLA = isTopLevel(variableDeclarationParent.parent);
95
+ const isTL = isTopLevel(variableDeclarationParent.parent);
103
96
  if (ts.isBindingElement(element) && ts.isObjectBindingPattern(element.name) && element.name.elements) {
104
97
  return element.name.elements.map(element => {
105
98
  const identifier = (element.propertyName ?? element.name).getText();
106
99
  const alias = element.propertyName ? element.name.getText() : undefined;
107
- const symbol = isTLA ? element.symbol : undefined;
100
+ const symbol = getSymbol(element, isTL);
108
101
  return { identifier, alias, symbol, specifier, pos: element.pos };
109
102
  });
110
103
  }
111
- const alias = element.name.escapedText;
112
- const symbol = isTLA ? element.symbol : undefined;
113
- return { identifier: 'default', symbol, alias, specifier, pos: element.pos };
104
+ if (!ts.isOmittedExpression(element) && ts.isIdentifier(element.name)) {
105
+ const alias = String(element.name.escapedText);
106
+ const symbol = getSymbol(element, isTL);
107
+ return { identifier: 'default', symbol, alias, specifier, pos: element.pos };
108
+ }
109
+ return { identifier: 'default', specifier, pos: element.pos };
114
110
  }
115
111
  }
116
112
  return { identifier: 'default', specifier, pos: node.arguments[0].pos };
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[])[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined)[];
3
3
  export default _default;
@@ -1,4 +1,4 @@
1
1
  import ts from 'typescript';
2
2
  import type { ImportNode } from '../../../types/imports.js';
3
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | ImportNode | ImportNode[];
3
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => ImportNode | ImportNode[] | undefined;
4
4
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
3
3
  export default _default;
@@ -1,5 +1,6 @@
1
1
  import ts from 'typescript';
2
2
  import { findAncestor, findDescendants, isRequireCall, isTopLevel } from '../../ast-helpers.js';
3
+ import { isNotJS } from '../helpers.js';
3
4
  import { importVisitor as visit } from '../index.js';
4
5
  export default visit(() => true, node => {
5
6
  if (isRequireCall(node)) {
@@ -11,9 +12,10 @@ export default visit(() => true, node => {
11
12
  return 'STOP';
12
13
  return ts.isPropertyAccessExpression(_node);
13
14
  });
15
+ const resolve = isNotJS(node.getSourceFile());
14
16
  if (propertyAccessExpression) {
15
17
  const identifier = String(propertyAccessExpression.name.escapedText);
16
- return { identifier, specifier, pos: propertyAccessExpression.name.pos };
18
+ return { identifier, specifier, pos: propertyAccessExpression.name.pos, resolve };
17
19
  }
18
20
  const variableDeclaration = node.parent;
19
21
  if (ts.isVariableDeclaration(variableDeclaration) &&
@@ -27,6 +29,7 @@ export default visit(() => true, node => {
27
29
  symbol: isTLA ? variableDeclaration.symbol : undefined,
28
30
  specifier,
29
31
  pos: node.arguments[0].pos,
32
+ resolve,
30
33
  };
31
34
  }
32
35
  const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
@@ -34,12 +37,13 @@ export default visit(() => true, node => {
34
37
  return bindings.map(element => {
35
38
  const identifier = (element.propertyName ?? element.name).getText();
36
39
  const alias = element.propertyName ? element.name.getText() : undefined;
37
- return { identifier, specifier, alias, symbol: isTLA ? element.symbol : undefined, pos: element.pos };
40
+ const symbol = isTLA ? element.symbol : undefined;
41
+ return { identifier, specifier, alias, symbol, pos: element.pos, resolve };
38
42
  });
39
43
  }
40
- return { identifier: 'default', specifier, pos: node.arguments[0].pos };
44
+ return { identifier: 'default', specifier, pos: node.arguments[0].pos, resolve };
41
45
  }
42
- return { identifier: 'default', specifier, pos: node.arguments[0].pos };
46
+ return { identifier: 'default', specifier, pos: node.arguments[0].pos, resolve };
43
47
  }
44
48
  }
45
49
  }
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[])[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined)[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/exports.js").ExportNode | import("../../../types/exports.js").ExportNode[] | undefined;
3
3
  export default _default;
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- export const isNotJS = (sourceFile) => sourceFile.scriptKind !== ts.ScriptKind.JS && sourceFile.scriptKind !== ts.ScriptKind.JSX;
2
+ export const isNotJS = (sourceFile) => !isJS(sourceFile);
3
3
  export const isJS = (sourceFile) => sourceFile.scriptKind === ts.ScriptKind.JS || sourceFile.scriptKind === ts.ScriptKind.JSX;
4
4
  export function getImportsFromPragmas(sourceFile) {
5
5
  const importNodes = [];
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[])[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined)[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => import("../../../types/imports.js").ImportNode | import("../../../types/imports.js").ImportNode[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import type ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[])[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => ((node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined)[];
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import ts from 'typescript';
2
- declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => undefined | string | string[];
2
+ declare const _default: (sourceFile: ts.SourceFile) => (node: ts.Node, options: import("../../get-imports-and-exports.js").GetImportsAndExportsOptions) => string | string[] | undefined;
3
3
  export default _default;
@@ -1,8 +1,7 @@
1
- import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, normalizeSpecifierFromFilePath, } from './modules.js';
2
- import { isInNodeModules, isInternal } from './path.js';
1
+ import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier } from './modules.js';
2
+ import { dirname, isInNodeModules, isInternal } from './path.js';
3
3
  import { fromBinary, isBinary } from './protocols.js';
4
- import { _resolveSpecifier } from './require.js';
5
- import { resolveSync } from './resolve.js';
4
+ import { _resolveSync } from './resolve.js';
6
5
  export const getReferencedDependencyHandler = (collector, deputy, chief) => (specifier, containingFilePath, workspace) => {
7
6
  if (isBinary(specifier)) {
8
7
  const binaryName = fromBinary(specifier);
@@ -17,7 +16,7 @@ export const getReferencedDependencyHandler = (collector, deputy, chief) => (spe
17
16
  }
18
17
  else {
19
18
  if (isInternal(specifier)) {
20
- const resolvedFilePath = resolveSync(specifier, containingFilePath);
19
+ const resolvedFilePath = _resolveSync(specifier, dirname(containingFilePath));
21
20
  if (resolvedFilePath)
22
21
  return resolvedFilePath;
23
22
  collector.addIssue({
@@ -40,9 +39,8 @@ export const getReferencedDependencyHandler = (collector, deputy, chief) => (spe
40
39
  symbol: specifier,
41
40
  });
42
41
  if (packageName && specifier !== packageName) {
43
- const otherWorkspace = chief.workspacePackagesByName.get(packageName);
44
- if (otherWorkspace) {
45
- const filePath = _resolveSpecifier(otherWorkspace.dir, normalizeSpecifierFromFilePath(specifier));
42
+ if (chief.workspacePackagesByName.get(packageName)) {
43
+ const filePath = _resolveSync(specifier, dirname(containingFilePath));
46
44
  if (filePath)
47
45
  return filePath;
48
46
  collector.addIssue({
@@ -3,8 +3,8 @@ import { timerify } from './Performance.js';
3
3
  import { LoaderError } from './errors.js';
4
4
  import { loadFile, loadJSON, loadTOML, loadYAML, parseJSON, parseYAML } from './fs.js';
5
5
  import { isTypeModule } from './fs.js';
6
+ import { jitiCJS, jitiESM } from './jiti.js';
6
7
  import { extname, isInternal } from './path.js';
7
- import { jitiCJS, jitiESM } from './register.js';
8
8
  const load = async (filePath) => {
9
9
  try {
10
10
  const ext = extname(filePath);
@@ -1,7 +1,6 @@
1
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
- export declare const normalizeSpecifierFromFilePath: (value: string) => string;
5
4
  export declare const isStartsLikePackageName: (specifier: string) => boolean;
6
5
  export declare const isDefinitelyTyped: (packageName: string) => boolean;
7
6
  export declare const getDefinitelyTypedFor: (packageName: string) => string;
@@ -16,13 +16,6 @@ export const getPackageNameFromFilePath = (value) => {
16
16
  return match[match.length - 1];
17
17
  return value;
18
18
  };
19
- const packageNameMatch = /.*\/node_modules\/(.+)/;
20
- export const normalizeSpecifierFromFilePath = (value) => {
21
- const match = toPosix(value).match(packageNameMatch);
22
- if (match)
23
- return match[match.length - 1];
24
- return value;
25
- };
26
19
  export const isStartsLikePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
27
20
  export const isDefinitelyTyped = (packageName) => packageName.startsWith(`${DT_SCOPE}/`);
28
21
  export const getDefinitelyTypedFor = (packageName) => {
@@ -1,6 +1,7 @@
1
1
  export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
2
2
  export { _loadJSON as loadJSON } from './fs.js';
3
3
  export { _load as load } from './loader.js';
4
+ export { _resolveSync as resolve } from './resolve.js';
4
5
  import type { RawPluginConfiguration } from '../types/config.js';
5
6
  import type { Plugin, PluginOptions } from '../types/plugins.js';
6
7
  export declare const toCamelCase: (name: string) => string;
@@ -1,12 +1,13 @@
1
1
  export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
2
2
  export { _loadJSON as loadJSON } from './fs.js';
3
3
  export { _load as load } from './loader.js';
4
+ export { _resolveSync as resolve } from './resolve.js';
4
5
  import { arrayify } from './array.js';
5
6
  import { _load as load } from './loader.js';
6
7
  import { get } from './object.js';
7
8
  import { basename, isAbsolute, join, relative } from './path.js';
8
9
  import { toEntryPattern, toProductionEntryPattern } from './protocols.js';
9
- import { _tryResolve as tryResolve } from './require.js';
10
+ import { _resolveSync } from './resolve.js';
10
11
  export const toCamelCase = (name) => name.toLowerCase().replace(/(-[a-z])/g, group => group.toUpperCase().replace('-', ''));
11
12
  export const hasDependency = (dependencies, values) => values.some(value => {
12
13
  if (typeof value === 'string') {
@@ -77,9 +78,9 @@ const toConfigMap = (defaultExtensions, builderConfig) => (moduleName, options)
77
78
  ];
78
79
  const rcFiles = `${rcPrefix}${moduleName}${rcSuffix}.{${extensions.join(',')}}`;
79
80
  const configExtensions = extensions.filter(ext => config.configFilesAllExtensions || jsTypeExtensions.includes(ext));
80
- const configFiles = !!config.configFiles && `${moduleName}.config.{${configExtensions.join(',')}}`;
81
- const configDirFiles = !!config.configDir && `.config/${moduleName}${rcSuffix}.{${extensions.join(',')}}`;
82
- return [...baseFiles, rcFiles, configFiles, configDirFiles].filter(item => item !== false);
81
+ const configFiles = config.configFiles ? [`${moduleName}.config.{${configExtensions.join(',')}}`] : [];
82
+ const configDirFiles = config.configDir ? [`.config/${moduleName}${rcSuffix}.{${extensions.join(',')}}`] : [];
83
+ return [...baseFiles, rcFiles, ...configFiles, ...configDirFiles];
83
84
  };
84
85
  export const toCosmiconfig = toConfigMap(['json', 'yaml', 'yml', 'js', 'ts', 'cjs', 'mjs'], { configDir: true });
85
86
  export const toLilconfig = toConfigMap(['json', 'js', 'cjs', 'mjs'], { configDir: true });
@@ -90,10 +91,10 @@ export const toUnconfig = toConfigMap(['json', 'ts', 'mts', 'cts', 'js', 'mjs',
90
91
  configFiles: false,
91
92
  });
92
93
  export const resolveEntry = (options, specifier, rootDir = '.') => {
93
- const { configFileDir, configFileName } = options;
94
+ const { configFileDir } = options;
94
95
  const resolvedPath = isAbsolute(specifier)
95
96
  ? specifier
96
- : tryResolve(join(configFileDir, rootDir, specifier), join(configFileDir, rootDir, configFileName));
97
+ : _resolveSync(join(configFileDir, rootDir, specifier), join(configFileDir, rootDir));
97
98
  if (resolvedPath)
98
99
  return toEntryPattern(relative(configFileDir, resolvedPath));
99
100
  return specifier;
@@ -1,4 +1 @@
1
1
  export declare const _require: NodeRequire;
2
- export declare const _resolve: (specifier: string) => string;
3
- export declare const _tryResolve: (specifier: string, from: string) => string | undefined;
4
- export declare const _resolveSpecifier: (dir: string, specifier: string) => string | undefined;
@@ -1,36 +1,5 @@
1
- import { createRequire as nodeCreateRequire } from 'node:module';
2
- import { pathToFileURL } from 'node:url';
3
- import createJITI from 'jiti';
1
+ import { createRequire } from 'node:module';
4
2
  import { timerify } from './Performance.js';
5
- import { debugLog } from './debug.js';
6
- import { getPackageNameFromModuleSpecifier } from './modules.js';
7
- import { cwd, join, toPosix } from './path.js';
8
- import { jitiCJS } from './register.js';
9
- const createRequire = (path) => nodeCreateRequire(pathToFileURL(path ?? cwd));
10
- const require = createRequire();
3
+ import { cwd } from './path.js';
4
+ const require = createRequire(cwd);
11
5
  export const _require = timerify(require);
12
- const resolve = (specifier) => toPosix(jitiCJS.resolve(specifier));
13
- const tryResolve = (specifier, from) => {
14
- try {
15
- return resolve(specifier);
16
- }
17
- catch {
18
- debugLog('*', `Unable to resolve ${specifier} (from ${from})`);
19
- }
20
- };
21
- const resolveSpecifier = (dir, specifier) => {
22
- try {
23
- const jiti = createJITI(dir);
24
- return toPosix(jiti.resolve(specifier));
25
- }
26
- catch {
27
- const packageName = getPackageNameFromModuleSpecifier(specifier);
28
- if (packageName) {
29
- const relativeSpecifier = specifier.replace(packageName, '.');
30
- return tryResolve(join(dir, relativeSpecifier), dir);
31
- }
32
- }
33
- };
34
- export const _resolve = timerify(resolve);
35
- export const _tryResolve = timerify(tryResolve);
36
- export const _resolveSpecifier = timerify(resolveSpecifier);
@@ -1 +1,2 @@
1
- export declare const resolveSync: (specifier: string, containingFile: string, extensions?: string[]) => string | undefined;
1
+ export declare const createSyncResolver: (extensions: string[]) => (specifier: string, baseDir: string) => string | undefined;
2
+ export declare const _resolveSync: (specifier: string, baseDir: string) => string | undefined;
@@ -1,14 +1,23 @@
1
- import resolve from 'resolve';
1
+ import fs from 'node:fs';
2
+ import ER from 'enhanced-resolve';
2
3
  import { DEFAULT_EXTENSIONS } from '../constants.js';
3
- import { dirname, toPosix } from './path.js';
4
- export const resolveSync = (specifier, containingFile, extensions = DEFAULT_EXTENSIONS) => {
5
- try {
6
- const resolved = resolve.sync(specifier, {
7
- basedir: dirname(containingFile),
8
- extensions,
9
- preserveSymlinks: false,
10
- });
11
- return toPosix(resolved);
12
- }
13
- catch (_error) { }
4
+ import { timerify } from './Performance.js';
5
+ import { toPosix } from './path.js';
6
+ const fileSystem = new ER.CachedInputFileSystem(fs, 9999999);
7
+ export const createSyncResolver = (extensions) => {
8
+ const resolver = ER.create.sync({
9
+ fileSystem,
10
+ extensions,
11
+ conditionNames: ['require', 'import', 'node', 'default'],
12
+ });
13
+ return function resolveSync(specifier, baseDir) {
14
+ try {
15
+ const resolved = resolver({}, baseDir, specifier);
16
+ if (resolved)
17
+ return toPosix(resolved);
18
+ }
19
+ catch (_error) { }
20
+ };
14
21
  };
22
+ const resolveSync = createSyncResolver([...DEFAULT_EXTENSIONS, '.json']);
23
+ export const _resolveSync = timerify(resolveSync);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.27.0";
1
+ export declare const version = "5.27.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.27.0';
1
+ export const version = '5.27.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.27.0",
3
+ "version": "5.27.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "lint": "biome lint ../..",
46
46
  "format": "biome format --write .",
47
47
  "test": "bun test test/*.test.ts test/**/*.test.ts",
48
- "test:node": "glob -c \"npx -y tsx@4.7.1 --test --import ./transform-test.js\" \"test/**/*.test.ts\"",
48
+ "test:node": "glob -c \"npx -y tsx --test --import ./transform-test.js\" \"test/**/*.test.ts\"",
49
49
  "watch": "npm link && tsc --watch",
50
50
  "prebuild": "node rmdir.js dist",
51
51
  "build": "tsc",
@@ -64,6 +64,7 @@
64
64
  "@nodelib/fs.walk": "1.2.8",
65
65
  "@snyk/github-codeowners": "1.1.0",
66
66
  "easy-table": "1.2.0",
67
+ "enhanced-resolve": "^5.17.1",
67
68
  "fast-glob": "^3.3.2",
68
69
  "jiti": "^1.21.6",
69
70
  "js-yaml": "^4.1.0",
@@ -71,7 +72,6 @@
71
72
  "picocolors": "^1.0.0",
72
73
  "picomatch": "^4.0.1",
73
74
  "pretty-ms": "^9.0.0",
74
- "resolve": "^1.22.8",
75
75
  "smol-toml": "^1.1.4",
76
76
  "strip-json-comments": "5.0.1",
77
77
  "summary": "2.1.0",
@@ -89,11 +89,9 @@
89
89
  "@types/js-yaml": "^4.0.9",
90
90
  "@types/minimist": "^1.2.5",
91
91
  "@types/picomatch": "2.3.4",
92
- "@types/resolve": "^1.20.6",
93
92
  "@types/webpack": "^5.28.5",
94
93
  "@wdio/types": "^8.39.0",
95
94
  "glob": "^10.4.2",
96
- "playwright": "^1.44.1",
97
95
  "release-it": "^17.4.1",
98
96
  "type-fest": "^4.20.0",
99
97
  "typescript": "^5.5.2"
File without changes
File without changes