Skip to content

Commit 56df370

Browse files
committed
Additionally resolve --elm-format-path from PATH
1 parent 3bac586 commit 56df370

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Publicly document the `--fix-all-without-prompt` CLI flag. Please use it well!
66
- The `--compiler` flag now additionally resolves the compiler path using the `PATH` environment variable (more easily enabling `elm-review --compiler lamdera` for instance).
7+
- The `--elm-format-path` flag now additionally resolves the path to `elm-format` using the `PATH` environment variable.
78
- Fixed an issue where the initial rule created with `elm-review new-package` was always a module rule, even when it was requested to be a project rule. Thanks to [@mateusfpleite](https://github.com/mateusfpleite)!
89
- Plenty of behind the scenes improvement to the maintenance of the repository. Thanks to [@lishaduck](https://github.com/lishaduck) for all of those.
910

lib/autofix.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ function formatFileContent(options, file, filePath) {
188188
['--elm-version=0.19', '--stdin', '--output', filePath],
189189
{
190190
input: file.source,
191-
env: hasElmFormatPathFlag
192-
? process.env
193-
: {...process.env, [pathKey]: backwardsCompatiblePath()}
191+
env: {
192+
...process.env,
193+
[pathKey]: backwardsCompatiblePath(options.elmFormatPath)
194+
}
194195
}
195196
);
196197

lib/elm-binary.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ const {backwardsCompatiblePath} = require('./npx');
1717
* @returns {Promise<Path>}
1818
*/
1919
async function getElmBinary(options) {
20-
let pathFolders = backwardsCompatiblePath();
21-
if (options.compiler) {
22-
pathFolders = pathFolders + path.delimiter + options.userSrc();
23-
}
2420
try {
2521
const elmBinaryPath = await which(options.compiler ?? 'elm', {
26-
path: pathFolders
22+
path: backwardsCompatiblePath(options.compiler)
2723
});
2824
return path.resolve(elmBinaryPath);
2925
} catch {

lib/npx.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ const pathKey = getPathKey();
6161
*
6262
* This can be removed in a major version.
6363
*
64+
* @param {Path | undefined} providedBinaryPath
6465
* @returns {Path}
6566
*/
66-
function backwardsCompatiblePath() {
67+
function backwardsCompatiblePath(providedBinaryPath) {
6768
return [
6869
...process
6970
.cwd()
@@ -72,6 +73,11 @@ function backwardsCompatiblePath() {
7273
[...parts.slice(0, index + 1), 'node_modules', '.bin'].join(path.sep)
7374
)
7475
.reverse(),
76+
[
77+
...(providedBinaryPath
78+
? [path.resolve(path.dirname(providedBinaryPath))]
79+
: [])
80+
],
7581
process.env[pathKey]
7682
].join(path.delimiter);
7783
}

0 commit comments

Comments
 (0)