Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(intellij): get correct executable path under yarn pnp #2070

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,23 @@ class NxCommandLineState(

val targetRun =
NodeTargetRun(
project.nodeInterpreter,
project,
configurator,
NodeTargetRunOptions.of(true, runConfiguration)
)
targetRun.envData = nxRunSettings.environmentVariables
project.nodeInterpreter,
project,
configurator,
NodeTargetRunOptions.of(true, runConfiguration)
)
.apply {
envData = nxRunSettings.environmentVariables
enableWrappingWithYarnNode = false
}

NodeCommandLineUtil.prependNodeDirToPATH(
nxRunSettings.environmentVariables.envs,
project.nodeInterpreter
)

targetRun.commandLineBuilder.apply {
exePath = TargetValue.fixed(NxExecutable.getExecutablePath(project.nxBasePath))
exePath = TargetValue.fixed(NxExecutable.getExecutablePath(project.nxBasePath, project))

addParameters(
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package dev.nx.console.utils

import com.intellij.execution.ExecutionException
import com.intellij.execution.wsl.WslPath
import com.intellij.javascript.nodejs.library.yarn.pnp.YarnPnpManager
import com.intellij.javascript.nodejs.npm.NpmPackageDescriptor
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.vfs.VirtualFileManager
import dev.nx.console.NxConsoleBundle
import java.io.File
import java.nio.file.Paths
Expand All @@ -13,7 +16,7 @@ private val logger = logger<NxExecutable>()

class NxExecutable {
companion object {
fun getExecutablePath(basePath: String): String {
fun getExecutablePath(basePath: String, project: Project): String {

logger.info("Checking if there is standalone nx")
val nxExecutableName =
Expand All @@ -24,6 +27,19 @@ class NxExecutable {
return nxExecutable.absolutePath
}

val yarnPnpManager = YarnPnpManager.getInstance(project)
val virtualBaseFile =
VirtualFileManager.getInstance().findFileByNioPath(Paths.get(basePath))
if (virtualBaseFile != null && yarnPnpManager.isUnderPnp(virtualBaseFile)) {
val packagJsonFile =
virtualBaseFile.findChild("package.json")
?: throw ExecutionException(NxConsoleBundle.message("nx.not.found"))
val nxPackage =
yarnPnpManager.findInstalledPackageDir(packagJsonFile, "nx")
?: throw ExecutionException(NxConsoleBundle.message("nx.not.found"))
return Paths.get(nxPackage.path, "bin", "nx.js").toString()
}

val binPath = Paths.get(basePath, "node_modules", ".bin").toString()

if (WslPath.isWslUncPath(binPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fun NxGeneralCommandLine(
cwd: String? = null
) =
GeneralCommandLine().apply {
exePath = NxExecutable.getExecutablePath(project.nxBasePath)
exePath = NxExecutable.getExecutablePath(project.nxBasePath, project)
addParameters(args)
val workDirectory =
if (cwd !== null) Path.of(project.nxBasePath, cwd).toString() else project.nxBasePath
Expand Down
Loading