refactor(@embark/storage): wrap require.resolve in try/catch

Wrap `require.resolve` in try/catch instead of testing the path with
`embark.fs.access`.
This commit is contained in:
Michael Bradley, Jr 2019-07-05 16:11:51 -05:00 committed by Michael Bradley
parent 13e926659f
commit bd602b45ee
1 changed files with 63 additions and 62 deletions

View File

@ -99,9 +99,11 @@ class StorageProcessesLauncher {
if (self.processes[storageName]) { if (self.processes[storageName]) {
return callback(__('Storage process already started')); return callback(__('Storage process already started'));
} }
const filePath = require.resolve(`embark-${storageName}/process`, {paths: [embarkPath('node_modules')]});
this.embark.fs.access(filePath, (err) => { let filePath;
if (err) { try {
filePath = require.resolve(`embark-${storageName}/process`, {paths: [embarkPath('node_modules')]});
} catch (e) {
return callback(__('No process file for this storage type (%s) exists. Please start the process locally.', storageName)); return callback(__('No process file for this storage type (%s) exists. Please start the process locally.', storageName));
} }
@ -173,9 +175,8 @@ class StorageProcessesLauncher {
self.events.on('logs:swarm:disable', () => { self.events.on('logs:swarm:disable', () => {
self.processes[storageName].silent = true; self.processes[storageName].silent = true;
}); });
});
} }
stopProcess(storageName, cb) { stopProcess(storageName, cb) {
if(this.processes[storageName]) { if(this.processes[storageName]) {
this.manualExit = true; this.manualExit = true;