Skip to content

Commit

Permalink
Merge pull request #23 from dbu/fix-paths
Browse files Browse the repository at this point in the history
fix when composer bin dir is in path
  • Loading branch information
moufmouf committed Nov 18, 2015
2 parents dbc3b29 + 7ab526e commit 56cd5a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/NodeJsInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function getGlobalInstallPath($command)
*
* @return null|string
*/
public function getNodeJsLocalInstallVersion()
public function getNodeJsLocalInstallVersion($binDir)
{
$returnCode = 0;
$output = "";
Expand All @@ -121,11 +121,7 @@ public function getNodeJsLocalInstallVersion()

ob_start();

if (!Environment::isWindows()) {
$version = exec("vendor/bin/node -v 2>&1", $output, $returnCode);
} else {
$version = exec("vendor\\bin\\node -v 2>&1", $output, $returnCode);
}
$version = exec($binDir.DIRECTORY_SEPARATOR.'node -v 2>&1', $output, $returnCode);

ob_end_clean();

Expand Down Expand Up @@ -332,8 +328,15 @@ private function createBinScript($binDir, $fullTargetDir, $scriptName, $target,
} else {
$path = $this->getGlobalInstallPath($target);
}

if (strpos($path, $binDir) === 0) {
// we found the local installation that already exists.

return;
}
}


file_put_contents($binDir.'/'.$scriptName, sprintf($content, $path));
chmod($binDir.'/'.$scriptName, 0755);
}
Expand Down
13 changes: 7 additions & 6 deletions src/NodeJsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function onPostUpdateInstall(Event $event)

if ($settings['forceLocal']) {
$this->verboseLog(" - Forcing local NodeJS install.");
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$this->installLocalVersion($binDir, $nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
} else {
$globalVersion = $nodeJsInstaller->getNodeJsGlobalInstallVersion();
Expand All @@ -101,17 +101,17 @@ public function onPostUpdateInstall(Event $event)

if (!$npmPath) {
$this->verboseLog(" - No NPM install found");
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$this->installLocalVersion($binDir, $nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
} elseif (!$nodeJsVersionMatcher->isVersionMatching($globalVersion, $versionConstraint)) {
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$this->installLocalVersion($binDir, $nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
} else {
$this->verboseLog(" - Global NodeJS install matches constraint ".$versionConstraint);
}
} else {
$this->verboseLog(" - No global NodeJS install found");
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$this->installLocalVersion($binDir, $nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
}
}
Expand Down Expand Up @@ -139,16 +139,17 @@ private function verboseLog($message)
/**
* Checks local NodeJS version, performs install if needed.
*
* @param string $binDir
* @param NodeJsInstaller $nodeJsInstaller
* @param string $versionConstraint
* @param string $targetDir
* @throws NodeJsInstallerException
*/
private function installLocalVersion(NodeJsInstaller $nodeJsInstaller, $versionConstraint, $targetDir)
private function installLocalVersion($binDir, NodeJsInstaller $nodeJsInstaller, $versionConstraint, $targetDir)
{
$nodeJsVersionMatcher = new NodeJsVersionMatcher();

$localVersion = $nodeJsInstaller->getNodeJsLocalInstallVersion();
$localVersion = $nodeJsInstaller->getNodeJsLocalInstallVersion($binDir);
if ($localVersion !== null) {
$this->verboseLog(" - Local NodeJS install found: v".$localVersion);

Expand Down

0 comments on commit 56cd5a9

Please sign in to comment.