knip 2.41.3 → 2.41.5

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.
@@ -4,7 +4,7 @@ import { tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
4
4
  export const resolve = (binary, args, { cwd }) => {
5
5
  const parsed = parseArgs(args, {
6
6
  string: ['r'],
7
- alias: { require: ['r', 'loader', 'experimental-loader', 'test-reporter', 'watch'] },
7
+ alias: { require: ['r', 'loader', 'experimental-loader', 'test-reporter', 'watch', 'import'] },
8
8
  });
9
9
  return compact([tryResolveFilePath(cwd, parsed._[0]), ...tryResolveSpecifiers(cwd, [parsed.require].flat())]);
10
10
  };
@@ -5,7 +5,6 @@ export declare const DEFAULT_EXTENSIONS: string[];
5
5
  export declare const GLOBAL_IGNORE_PATTERNS: string[];
6
6
  export declare const IGNORED_GLOBAL_BINARIES: string[];
7
7
  export declare const IGNORED_DEPENDENCIES: string[];
8
- export declare const VIRTUAL_FILE_EXTENSIONS: string[];
9
8
  export declare const IGNORED_FILE_EXTENSIONS: string[];
10
9
  export declare const IGNORE_DEFINITELY_TYPED: string[];
11
10
  export declare const ISSUE_TYPES: IssueType[];
package/dist/constants.js CHANGED
@@ -35,12 +35,12 @@ export const IGNORED_GLOBAL_BINARIES = [
35
35
  'yarn',
36
36
  ];
37
37
  export const IGNORED_DEPENDENCIES = ['knip', 'typescript'];
38
- export const VIRTUAL_FILE_EXTENSIONS = ['.css', '.html', '.svg'];
39
38
  export const IGNORED_FILE_EXTENSIONS = [
40
- ...VIRTUAL_FILE_EXTENSIONS,
41
39
  '.avif',
40
+ '.css',
42
41
  '.eot',
43
42
  '.gif',
43
+ '.html',
44
44
  '.ico',
45
45
  '.jpeg',
46
46
  '.jpg',
@@ -49,6 +49,7 @@ export const IGNORED_FILE_EXTENSIONS = [
49
49
  '.sass',
50
50
  '.scss',
51
51
  '.sh',
52
+ '.svg',
52
53
  '.ttf',
53
54
  '.webp',
54
55
  '.woff',
@@ -7,7 +7,10 @@ import { getEnvPackageName, getExternalReporters } from './helpers.js';
7
7
  export const NAME = 'Vitest';
8
8
  export const ENABLERS = ['vitest'];
9
9
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
10
- export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vitest.{workspace,projects}.{ts,js,json}'];
10
+ export const CONFIG_FILE_PATTERNS = [
11
+ 'vitest.config.{js,mjs,ts,cjs,mts,cts}',
12
+ 'vitest.{workspace,projects}.{ts,js,json}',
13
+ ];
11
14
  export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'];
12
15
  const resolveEntry = (containingFilePath, specifier) => {
13
16
  const dir = dirname(containingFilePath);
@@ -1,7 +1,6 @@
1
1
  import { EOL } from 'node:os';
2
2
  import path from 'node:path';
3
3
  import ts from 'typescript';
4
- import { VIRTUAL_FILE_EXTENSIONS } from '../constants.js';
5
4
  import { createCustomModuleResolver } from './resolveModuleNames.js';
6
5
  import { SourceFileManager } from './SourceFileManager.js';
7
6
  import { createCustomSys } from './sys.js';
@@ -9,7 +8,7 @@ const libLocation = path.dirname(ts.getDefaultLibFilePath({}));
9
8
  const fileManager = new SourceFileManager();
10
9
  export const createHosts = ({ cwd, compilerOptions, entryPaths, compilers }) => {
11
10
  fileManager.installCompilers(compilers);
12
- const virtualFileExtensions = [...VIRTUAL_FILE_EXTENSIONS, ...compilers[0].keys(), ...compilers[1].keys()];
11
+ const virtualFileExtensions = [...compilers[0].keys(), ...compilers[1].keys()];
13
12
  const sys = createCustomSys(cwd, virtualFileExtensions);
14
13
  const resolveModuleNames = createCustomModuleResolver(sys, compilerOptions, virtualFileExtensions);
15
14
  const languageServiceHost = {
@@ -1,15 +1,16 @@
1
1
  import { existsSync } from 'node:fs';
2
+ import { isBuiltin } from 'node:module';
2
3
  import ts from 'typescript';
3
4
  import { sanitizeSpecifier } from '../util/modules.js';
4
5
  import { dirname, extname, isAbsolute, isInternal, join } from '../util/path.js';
5
6
  import { isDeclarationFileExtension } from './ast-helpers.js';
6
7
  import { ensureRealFilePath, isVirtualFilePath } from './utils.js';
7
- const simpleResolver = (name, containingFile) => {
8
+ const fileExists = (name, containingFile) => {
8
9
  const resolvedFileName = isAbsolute(name) ? name : join(dirname(containingFile), name);
9
10
  if (existsSync(resolvedFileName)) {
10
11
  return {
11
12
  resolvedFileName,
12
- extension: extname(resolvedFileName),
13
+ extension: extname(name),
13
14
  isExternalLibraryImport: false,
14
15
  resolvedUsingTsExtension: false,
15
16
  };
@@ -21,11 +22,13 @@ export function createCustomModuleResolver(customSys, compilerOptions, virtualFi
21
22
  }
22
23
  function resolveModuleName(name, containingFile) {
23
24
  const sanitizedSpecifier = sanitizeSpecifier(name);
25
+ if (isBuiltin(sanitizedSpecifier))
26
+ return undefined;
24
27
  const tsResolvedModule = ts.resolveModuleName(sanitizedSpecifier, containingFile, compilerOptions, ts.sys).resolvedModule;
25
28
  if (!tsResolvedModule) {
26
29
  const extension = extname(sanitizedSpecifier);
27
- if (extension && isInternal(sanitizedSpecifier) && !virtualFileExtensions.includes(extension)) {
28
- const module = simpleResolver(sanitizedSpecifier, containingFile);
30
+ if (extension && !virtualFileExtensions.includes(extension)) {
31
+ const module = fileExists(sanitizedSpecifier, containingFile);
29
32
  if (module)
30
33
  return module;
31
34
  }
@@ -33,7 +36,7 @@ export function createCustomModuleResolver(customSys, compilerOptions, virtualFi
33
36
  if (tsResolvedModule &&
34
37
  isDeclarationFileExtension(tsResolvedModule?.extension) &&
35
38
  isInternal(tsResolvedModule.resolvedFileName)) {
36
- const module = simpleResolver(sanitizedSpecifier, containingFile);
39
+ const module = fileExists(sanitizedSpecifier, containingFile);
37
40
  if (module)
38
41
  return module;
39
42
  }
@@ -26,7 +26,7 @@ const load = async (filePath) => {
26
26
  const imported = await import(fileUrl.href);
27
27
  return imported.default ?? imported;
28
28
  }
29
- if (isTypeModule(filePath)) {
29
+ if (ext === '.mts' || (ext === '.ts' && isTypeModule(filePath))) {
30
30
  return await jitiESM(filePath);
31
31
  }
32
32
  else {
@@ -1,6 +1,7 @@
1
+ import { isBuiltin } from 'module';
1
2
  import { _glob } from './glob.js';
2
3
  import { getStringValues } from './object.js';
3
- import { toPosix } from './path.js';
4
+ import { isAbsolute, toPosix } from './path.js';
4
5
  export const getPackageNameFromModuleSpecifier = (moduleSpecifier) => {
5
6
  if (!isMaybePackageName(moduleSpecifier))
6
7
  return;
@@ -52,7 +53,9 @@ export const getEntryPathFromManifest = (manifest, sharedGlobOptions) => {
52
53
  return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths) });
53
54
  };
54
55
  export const sanitizeSpecifier = (specifier) => {
55
- if (specifier.startsWith('node:'))
56
+ if (isBuiltin(specifier))
57
+ return specifier;
58
+ if (isAbsolute(specifier))
56
59
  return specifier;
57
60
  return specifier.replace(/^([?!|-]+)?([^!?:]+).*/, '$2');
58
61
  };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.41.3";
1
+ export declare const version = "2.41.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.41.3';
1
+ export const version = '2.41.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.41.3",
3
+ "version": "2.41.5",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",