knip 5.25.2 → 5.26.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.
@@ -29,11 +29,13 @@ const resolveConfig = config => {
29
29
  const presets = configurationOutput
30
30
  .map(configOutput => (configOutput.preset ? configOutput.preset : undefined))
31
31
  .filter((preset) => typeof preset === 'string')
32
- .map(presetName => `@graphql-codegen/${presetName}${presetName.endsWith('-preset') ? '' : '-preset'}`);
32
+ .map(presetName => presetName.startsWith('@graphql-codegen/')
33
+ ? presetName
34
+ : `@graphql-codegen/${presetName}${presetName.endsWith('-preset') ? '' : '-preset'}`);
33
35
  const flatPlugins = generateSet
34
36
  .filter((config) => !isConfigurationOutput(config))
35
37
  .flatMap(item => Object.keys(item))
36
- .map(plugin => `@graphql-codegen/${plugin}`);
38
+ .map(plugin => plugin.includes('codegen-') ? plugin : `@graphql-codegen/${plugin}`);
37
39
  const nestedPlugins = configurationOutput
38
40
  .flatMap(configOutput => (configOutput.plugins ? configOutput.plugins : []))
39
41
  .flatMap(plugin => {
@@ -46,7 +48,7 @@ const resolveConfig = config => {
46
48
  return [];
47
49
  if (isInternal(plugin))
48
50
  return [toEntryPattern(plugin)];
49
- return [`@graphql-codegen/${plugin}`];
51
+ return [plugin.includes('codegen-') ? plugin : `@graphql-codegen/${plugin}`];
50
52
  });
51
53
  return [...presets, ...flatPlugins, ...nestedPlugins];
52
54
  };
@@ -1,11 +1,10 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { isBuiltin } from 'node:module';
3
- import { createMatchPath } from 'tsconfig-paths';
4
3
  import ts from 'typescript';
5
4
  import { DEFAULT_EXTENSIONS } from '../constants.js';
6
5
  import { timerify } from '../util/Performance.js';
7
6
  import { sanitizeSpecifier } from '../util/modules.js';
8
- import { dirname, extname, isAbsolute, isInNodeModules, join, toPosix } from '../util/path.js';
7
+ import { dirname, extname, isAbsolute, isInNodeModules, join } from '../util/path.js';
9
8
  import { resolveSync } from '../util/resolve.js';
10
9
  import { isDeclarationFileExtension } from './ast-helpers.js';
11
10
  const resolutionCache = new Map();
@@ -23,6 +22,21 @@ const fileExists = (name, containingFile) => {
23
22
  export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, useCache = true) {
24
23
  const customCompilerExtensionsSet = new Set(customCompilerExtensions);
25
24
  const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions];
25
+ const virtualDeclarationFiles = new Map();
26
+ const tsSys = {
27
+ ...ts.sys,
28
+ fileExists(path) {
29
+ if (ts.sys.fileExists(path)) {
30
+ return true;
31
+ }
32
+ const original = originalFromDeclarationPath(path);
33
+ if (original && ts.sys.fileExists(original.path)) {
34
+ virtualDeclarationFiles.set(path, original);
35
+ return true;
36
+ }
37
+ return false;
38
+ },
39
+ };
26
40
  function resolveModuleNames(moduleNames, containingFile) {
27
41
  return moduleNames.map(moduleName => {
28
42
  if (!useCache)
@@ -38,7 +52,6 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
38
52
  return resolvedModule;
39
53
  });
40
54
  }
41
- const tsMatchPath = createMatchPath(compilerOptions.baseUrl ?? '/', compilerOptions.paths || {});
42
55
  function resolveModuleName(name, containingFile) {
43
56
  const sanitizedSpecifier = sanitizeSpecifier(name);
44
57
  if (isBuiltin(sanitizedSpecifier) || isInNodeModules(name))
@@ -64,16 +77,7 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
64
77
  resolvedUsingTsExtension: false,
65
78
  };
66
79
  }
67
- const pathMappedFileName = tsMatchPath(sanitizedSpecifier, undefined, undefined, []);
68
- if (pathMappedFileName) {
69
- const ext = extname(pathMappedFileName);
70
- return {
71
- resolvedFileName: toPosix(pathMappedFileName),
72
- extension: customCompilerExtensionsSet.has(ext) ? ts.Extension.Js : ext,
73
- isExternalLibraryImport: false,
74
- };
75
- }
76
- const tsResolvedModule = ts.resolveModuleName(sanitizedSpecifier, containingFile, compilerOptions, ts.sys).resolvedModule;
80
+ const tsResolvedModule = ts.resolveModuleName(sanitizedSpecifier, containingFile, compilerOptions, tsSys).resolvedModule;
77
81
  if (tsResolvedModule) {
78
82
  if (isDeclarationFileExtension(tsResolvedModule.extension)) {
79
83
  const srcFilePath = toSourceFilePath(tsResolvedModule.resolvedFileName);
@@ -86,6 +90,14 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
86
90
  };
87
91
  }
88
92
  }
93
+ const original = virtualDeclarationFiles.get(tsResolvedModule.resolvedFileName);
94
+ if (original) {
95
+ return {
96
+ ...tsResolvedModule,
97
+ resolvedFileName: original.path,
98
+ extension: customCompilerExtensionsSet.has(original.ext) ? ts.Extension.Js : original.ext,
99
+ };
100
+ }
89
101
  return tsResolvedModule;
90
102
  }
91
103
  const module = fileExists(sanitizedSpecifier, containingFile);
@@ -95,3 +107,13 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
95
107
  }
96
108
  return timerify(resolveModuleNames);
97
109
  }
110
+ const declarationPathRe = /^(.*)\.d(\.[^.]+)\.ts$/;
111
+ function originalFromDeclarationPath(path) {
112
+ const match = declarationPathRe.exec(path);
113
+ if (match) {
114
+ return {
115
+ path: match[1] + match[2],
116
+ ext: match[2],
117
+ };
118
+ }
119
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.25.2";
1
+ export declare const version = "5.26.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.25.2';
1
+ export const version = '5.26.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.25.2",
3
+ "version": "5.26.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -75,7 +75,6 @@
75
75
  "smol-toml": "^1.1.4",
76
76
  "strip-json-comments": "5.0.1",
77
77
  "summary": "2.1.0",
78
- "tsconfig-paths": "^4.2.0",
79
78
  "zod": "^3.22.4",
80
79
  "zod-validation-error": "^3.0.3"
81
80
  },