Skip to content

Commit

Permalink
Merge pull request #16 from vladyslav-mikhieiev/feature/pass-node-pat…
Browse files Browse the repository at this point in the history
…h-via-env

Add support for specifying the path to nodejs executable
  • Loading branch information
freekmurze authored Jan 22, 2024
2 parents 3ff7d53 + 686a2e2 commit edc2cd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ use Spatie\Mjml\Mjml;
Mjml::new()->canConvertWithoutErrors($mjml); // returns a boolean
```

### Specifying the path to nodejs executable

By default, the package itself will try to determine the path to the `node` executable. If the package can't find a path, you can specify a path in the environment variable `MJML_NODE_PATH`

```shell
MJML_NODE_PATH=/home/user/.nvm/versions/node/v20.11.0/bin
```

## Sidecar

This package also supports running through [Sidecar](https://github.com/hammerstonedev/sidecar) in Laravel projects.
Expand Down
16 changes: 12 additions & 4 deletions src/Mjml.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,19 @@ protected function checkForDeprecationWarning(string $result): string

protected function getCommand(array $arguments): array
{
$extraDirectories = [
'/usr/local/bin',
'/opt/homebrew/bin'
];

$nodePathFromEnv = getenv('MJML_NODE_PATH');

if ($nodePathFromEnv) {
array_unshift($extraDirectories, $nodePathFromEnv);
}

return [
(new ExecutableFinder())->find('node', 'node', [
'/usr/local/bin',
'/opt/homebrew/bin',
]),
(new ExecutableFinder())->find('node', 'node', $extraDirectories),
'mjml.mjs',
json_encode(array_values($arguments)),
];
Expand Down

0 comments on commit edc2cd2

Please sign in to comment.