Skip to content

Commit 0f99b40

Browse files
committed
When Babel fails to compile, report this to the calling CLI
Do not let the CLI to crash See NativeScript/nativescript-cli#1337
1 parent 5b77ac1 commit 0f99b40

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

lib/after-prepare.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,28 @@ module.exports = function (logger, platformsData, projectData, hookArgs) {
2828
glob(path.join(outDir, 'app/**/*.js'), {}, function (err, files) {
2929
if (err) {
3030
reject(err);
31-
} else {
32-
files.forEach(function (jsFile) {
33-
if (minimatch(jsFile, excludedPath)) {
34-
return;
35-
}
31+
return;
32+
}
33+
34+
var error = null;
35+
files.forEach(function (jsFile) {
36+
if (error || minimatch(jsFile, excludedPath)) {
37+
return;
38+
}
3639

37-
logger.trace('Processing ' + jsFile);
40+
logger.trace('Processing ' + jsFile);
41+
try {
3842
var result = babel.transformFileSync(jsFile, babelOptions);
3943
fs.writeFileSync(jsFile, result.code);
40-
});
41-
console.log('Processing complete');
42-
resolve();
44+
} catch(err) {
45+
error = err;
46+
}
47+
});
48+
console.log('Processing complete');
49+
if (error) {
50+
error.errorAsWarning = true;
4351
}
52+
error ? reject(error) : resolve();
4453
});
4554
});
4655
}

0 commit comments

Comments
 (0)