Skip to content

Commit bcb6dbf

Browse files
committed
Move the check inside an external function
1 parent faabbf8 commit bcb6dbf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/compiler/moduleSpecifiers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ namespace ts.moduleSpecifiers {
281281
: removeFileExtension(relativePath);
282282
}
283283

284+
function isPnpAvailable() {
285+
// @ts-ignore
286+
return process.versions.pnp;
287+
}
288+
284289
function tryGetModuleNameAsNodeModule(moduleFileName: string, { getCanonicalFileName, sourceDirectory }: Info, host: ModuleSpecifierResolutionHost, options: CompilerOptions, packageNameOnly?: boolean): string | undefined {
285290
if (!host.fileExists || !host.readFile) {
286291
return undefined;
@@ -323,7 +328,7 @@ namespace ts.moduleSpecifiers {
323328
const pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));
324329
// If PnP is enabled the node_modules entries we'll get will always be relevant even if they
325330
// are located in a weird path apparently outside of the source directory
326-
if (!process.versions.pnp && !(startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {
331+
if (!isPnpAvailable() && !(startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {
327332
return undefined;
328333
}
329334

0 commit comments

Comments
 (0)