Skip to content

Commit

Permalink
Fix npm aliases (resolves #474)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jan 29, 2024
1 parent ad1ff7f commit 470437d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions packages/knip/src/typescript/getImportsAndExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
import { isInNodeModules } from '../util/path.js';
import { timerify } from '../util/Performance.js';
import {
isDeclarationFileExtension,
isAccessExpression,
getJSDocTags,
getLineAndCharacterOfPosition,
Expand Down Expand Up @@ -141,13 +140,9 @@ const getImportsAndExports = (
return;
}

if (isDeclarationFileExtension(module.resolvedModule.extension)) {
// We use TypeScript's module resolution, but it returns DTS references. In the rest of the program we want
// the package name based on the original specifier.
externalImports.add(sanitizedSpecifier);
} else {
externalImports.add(module.resolvedModule.packageId?.name ?? sanitizedSpecifier);
}
// TypeScript module resolution may return DTS references or unaliased npm package names,
// but in the rest of the program we want the package name based on the original specifier.
externalImports.add(sanitizedSpecifier);
} else {
addInternalImport({ ...options, identifier, filePath, isReExport });
}
Expand Down

0 comments on commit 470437d

Please sign in to comment.