diff --git a/apps/intellij/src/main/kotlin/dev/nx/console/run/NxCommandLineState.kt b/apps/intellij/src/main/kotlin/dev/nx/console/run/NxCommandLineState.kt index 70c517c9ad..832b8d290c 100644 --- a/apps/intellij/src/main/kotlin/dev/nx/console/run/NxCommandLineState.kt +++ b/apps/intellij/src/main/kotlin/dev/nx/console/run/NxCommandLineState.kt @@ -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( diff --git a/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxExecutable.kt b/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxExecutable.kt index 4629ed5e59..f1c780f79c 100644 --- a/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxExecutable.kt +++ b/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxExecutable.kt @@ -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 @@ -13,7 +16,7 @@ private val logger = logger() 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 = @@ -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)) { diff --git a/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxGeneralCommandLine.kt b/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxGeneralCommandLine.kt index 38e99e734c..c511830835 100644 --- a/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxGeneralCommandLine.kt +++ b/apps/intellij/src/main/kotlin/dev/nx/console/utils/NxGeneralCommandLine.kt @@ -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