Skip to content

Commit

Permalink
Update formatting, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderRonde committed Nov 24, 2024
1 parent d84b0db commit 19616a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
13 changes: 9 additions & 4 deletions packages/knip/src/ProjectPrincipal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,15 @@ export class ProjectPrincipal {

const resolve = (specifier: string) => this.backend.resolveModuleNames([specifier], sourceFile.fileName)[0];

const { imports, exports, scripts, traceRefs, jsxComponents } = _getImportsAndExports(sourceFile, resolve, typeChecker, {
...options,
skipExports,
});
const { imports, exports, scripts, traceRefs, jsxComponents } = _getImportsAndExports(
sourceFile,
resolve,
typeChecker,
{
...options,
skipExports,
}
);

const { internal, resolved, specifiers, unresolved, external } = imports;

Expand Down
27 changes: 11 additions & 16 deletions packages/knip/src/typescript/create-hosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,18 @@ export const createHosts = ({
// Try to resolve @types for any non-relative, non-absolute import
if (!moduleName.startsWith('.') && !moduleName.startsWith('/') && !moduleName.startsWith('node:')) {
// Get the base package name (handle scoped packages and subpaths)
const basePackage = moduleName.startsWith('@')
const basePackage = moduleName.startsWith('@')
? moduleName.split('/').slice(0, 2).join('/')
: moduleName.split('/')[0];

const typeResult = ts.resolveTypeReferenceDirective(
basePackage,
containingFile,
options,
{
fileExists: ts.sys.fileExists,
readFile: ts.sys.readFile,
directoryExists: ts.sys.directoryExists,
getCurrentDirectory: () => cwd,
getDirectories: ts.sys.getDirectories,
}
);


const typeResult = ts.resolveTypeReferenceDirective(basePackage, containingFile, options, {
fileExists: ts.sys.fileExists,
readFile: ts.sys.readFile,
directoryExists: ts.sys.directoryExists,
getCurrentDirectory: () => cwd,
getDirectories: ts.sys.getDirectories,
});

if (typeResult.resolvedTypeReferenceDirective?.resolvedFileName) {
return {
resolvedFileName: typeResult.resolvedTypeReferenceDirective.resolvedFileName,
Expand All @@ -77,7 +72,7 @@ export const createHosts = ({
};
}
}

// Fall back to normal module resolution
return resolveModuleNames([moduleName], containingFile)[0];
});
Expand Down
2 changes: 1 addition & 1 deletion packages/knip/test/react-props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ test('Find unused component props', async () => {
processed: 3,
total: 3,
types: 1,
reactComponentProps: totalErrors,
componentProps: totalErrors,
});
});

0 comments on commit 19616a9

Please sign in to comment.