Skip to content

Commit bfc0d21

Browse files
committed
Download dependencies of the target project
1 parent e8e744f commit bfc0d21

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/elm-binary.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@ async function getElmVersion(elmBinary) {
6363
return trimVersion(result.stdout.toString());
6464
}
6565

66+
/** Download the dependencies of the project to analyze.
67+
*
68+
* @param {Path} elmBinary
69+
* @param {Path} elmJsonPath
70+
* @return {Promise<void>}
71+
*/
72+
async function downloadDependenciesOfElmJson(elmBinary, elmJsonPath) {
73+
const result = spawn.sync(elmBinary, ['make', '--report=json'], {
74+
cwd: path.dirname(elmJsonPath),
75+
silent: false,
76+
env: process.env
77+
});
78+
79+
if (result.status !== 0) {
80+
const error = JSON.parse(result.stderr.toString());
81+
// TODO Check for other kinds of errors
82+
if (error.title !== 'NO INPUT') {
83+
// TODO Print error nicely
84+
throw new Error(error);
85+
}
86+
}
87+
}
88+
6689
/**
6790
* @param {string} version
6891
* @return {string}
@@ -78,5 +101,6 @@ function trimVersion(version) {
78101

79102
module.exports = {
80103
getElmBinary,
81-
getElmVersion
104+
getElmVersion,
105+
downloadDependenciesOfElmJson
82106
};

lib/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const NewRule = require('./new-rule');
1717
const Anonymize = require('./anonymize');
1818
const newPackage = require('./new-package');
1919
const AppWrapper = require('./app-wrapper');
20+
const ElmFiles = require('./elm-files');
21+
const ElmBinary = require('./elm-binary');
2022
const ResultCache = require('./result-cache');
2123
const ErrorMessage = require('./error-message');
2224
const SuppressedErrors = require('./suppressed-errors');
@@ -107,7 +109,10 @@ async function runElmReviewInWatchMode() {
107109
}
108110

109111
async function prepareOffline() {
110-
const {elmModulePath, reviewElmJson, appHash} = await Builder.build(options);
112+
const elmBinary = await ElmBinary.getElmBinary(options);
113+
await ElmBinary.downloadDependenciesOfElmJson(elmBinary, options.elmJsonPath);
114+
115+
const {elmModulePath, reviewElmJson} = await Builder.build(options);
111116

112117
if (!elmModulePath) {
113118
AppState.exitRequested(1);

0 commit comments

Comments
 (0)