diff --git a/README.md b/README.md index 14a0371..6d0cd6b 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ npm install minidump ``` ## Building - * Clone the repository recursively - * Run `npm install` + +* `git clone --recurse-submodules https://github.com/electron/node-minidump` +* `npm install` ## Docs diff --git a/lib/minidump.js b/lib/minidump.js index 0d5484b..361b556 100644 --- a/lib/minidump.js +++ b/lib/minidump.js @@ -1,75 +1,81 @@ -var fs = require('fs'); -var path = require('path'); -var spawn = require('child_process').spawn; +var fs = require('fs') +var path = require('path') +var spawn = require('child_process').spawn var searchPaths = [ path.resolve(__dirname, '..', 'build', 'Release'), path.resolve(__dirname, '..', 'build', 'Debug'), - path.resolve(__dirname, '..', 'bin'), -]; -function searchCommand(command) { - if (process.platform == 'win32') { + path.resolve(__dirname, '..', 'bin') +] + +function searchCommand (command) { + var binaryPath = null + if (process.platform === 'win32') { command += '.exe' - var binaryPath = path.join(__dirname, '..', 'deps', 'breakpad', command) - if (fs.existsSync(binaryPath)) - return binaryPath; + binaryPath = path.join(__dirname, '..', 'deps', 'breakpad', command) + if (fs.existsSync(binaryPath)) { + return binaryPath + } } else { for (var i in searchPaths) { - var binaryPath = path.join(searchPaths[i], command); - if (fs.existsSync(binaryPath)) - return binaryPath; + binaryPath = path.join(searchPaths[i], command) + if (fs.existsSync(binaryPath)) { + return binaryPath + } } } } -function execute(command, args, callback) { - var stdout = new Buffer(0); - var stderr = new Buffer(0); - var child = spawn(command, args); - child.stdout.on('data', function(chunk) { - stdout = Buffer.concat([stdout, chunk]); - }); - child.stderr.on('data', function(chunk) { - stderr = Buffer.concat([stderr, chunk]); - }); - child.on('close', function(code) { - if (code != 0) - callback(stderr ? new Error(stderr.toString()) : new Error("Command `" + command + "` failed: " + code)); - else - callback(null, stdout); - }); +function execute (command, args, callback) { + var stdout = new Buffer(0) + var stderr = new Buffer(0) + var child = spawn(command, args) + child.stdout.on('data', function (chunk) { + stdout = Buffer.concat([stdout, chunk]) + }) + child.stderr.on('data', function (chunk) { + stderr = Buffer.concat([stderr, chunk]) + }) + child.on('close', function (code) { + if (code !== 0) { + callback(stderr ? new Error(stderr.toString()) : new Error('Command `' + command + '` failed: ' + code)) + } else { + callback(null, stdout) + } + }) } -var globalSymbolPaths = []; -module.exports.addSymbolPath = Array.prototype.push.bind(globalSymbolPaths); +var globalSymbolPaths = [] +module.exports.addSymbolPath = Array.prototype.push.bind(globalSymbolPaths) -module.exports.walkStack = function(minidump, symbolPaths, callback) { +module.exports.walkStack = function (minidump, symbolPaths, callback) { if (!callback) { - callback = symbolPaths; - symbolPaths = []; + callback = symbolPaths + symbolPaths = [] } - var stackwalk = searchCommand('minidump_stackwalk'); + var stackwalk = searchCommand('minidump_stackwalk') if (!stackwalk) { - callback(new Error('Unable to find "minidump_stackwalk"')); - return; + callback(new Error('Unable to find "minidump_stackwalk"')) + return } - args = [minidump].concat(symbolPaths, globalSymbolPaths) - execute(stackwalk, args, callback); + var args = [minidump].concat(symbolPaths, globalSymbolPaths) + execute(stackwalk, args, callback) } -module.exports.dumpSymbol = function(binary, callback) { - var dumpsyms = searchCommand('dump_syms'); +module.exports.dumpSymbol = function (binary, callback) { + var dumpsyms = searchCommand('dump_syms') if (!dumpsyms) { - callback(new Error('Unable to find "dump_syms"')); - return; + callback(new Error('Unable to find "dump_syms"')) + return } // Search for binary.dSYM on OS X. - dsymPath = binary + '.dSYM'; - if (process.platform == 'darwin' && fs.existsSync(dsymPath)) - binary = dsymPath; + var dsymPath = binary + '.dSYM' + if (process.platform === 'darwin' && fs.existsSync(dsymPath)) { + binary = dsymPath + } execute(dumpsyms, ['-r', '-c', binary], callback) } diff --git a/package.json b/package.json index bb0a3a9..4ee4299 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,13 @@ "url": "https://github.com/electron/node-minidump/issues" }, "scripts": { - "test": "mocha test" + "test": "mocha test && standard" }, "devDependencies": { "electron-download": "^3.0.1", "extract-zip": "^1.5.0", "mocha": "^3.1.2", + "standard": "^8.4.0", "temp": "^0.8.3" } } diff --git a/test/minidump-test.js b/test/minidump-test.js index 3e7ed74..bb8a1ef 100644 --- a/test/minidump-test.js +++ b/test/minidump-test.js @@ -6,6 +6,9 @@ var electronDownload = require('electron-download') var extractZip = require('extract-zip') var temp = require('temp').track() +var describe = global.describe +var it = global.it + describe('minidump', function () { this.timeout(3 * 60 * 1000) @@ -105,7 +108,7 @@ var downloadElectron = function (callback) { } else { callback(null, path.join(electronPath, 'electron')) } - }) + }) }) } @@ -123,6 +126,6 @@ var downloadElectronSymbols = function (platform, callback) { extractZip(zipPath, {dir: symbolsPath}, function (error) { if (error) return callback(error) callback(null, path.join(symbolsPath, 'electron.breakpad.syms')) - }) + }) }) }