Skip to content

Commit

Permalink
Exception on Missing Node Env
Browse files Browse the repository at this point in the history
If node isn't accessible, throw an exception.
  • Loading branch information
cyrusboadway committed Jan 30, 2015
1 parent cd7344d commit 469e59f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/Autoprefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function setBrowsers($browsers)
/**
* @param mixed $css
* @param mixed $browsers
* @throw AutoprefixerException
* @throws RuntimeException If node runtime unavailable
* @throws AutoprefixerException
* @return array
*/
public function compile($css, $browsers = null)
Expand All @@ -51,19 +52,20 @@ public function compile($css, $browsers = null)
array(array('pipe', 'r'), array('pipe', 'w')),
$pipes
);

if ($nodejs) {
$this->fwrite_stream($pipes[0],
json_encode(array(
'css' => $css,
'browsers' => !is_null($browsers) ? $browsers : $this->browsers)
));
fclose($pipes[0]);

$output = stream_get_contents($pipes[1]);
$output = json_decode($output, true);
fclose($pipes[1]);
if ($nodejs === false) {
throw new RuntimeException('Could not reach node runtime');
}

$this->fwrite_stream($pipes[0],
json_encode(array(
'css' => $css,
'browsers' => !is_null($browsers) ? $browsers : $this->browsers)
));
fclose($pipes[0]);

$output = stream_get_contents($pipes[1]);
$output = json_decode($output, true);
fclose($pipes[1]);

proc_close($nodejs);

Expand Down

0 comments on commit 469e59f

Please sign in to comment.