Merge pull request #224 from electron-userland/check-if-path-file-exists
Check that the path file exists before spawning
This commit is contained in:
commit
7e72581469
2 changed files with 47 additions and 17 deletions
|
@ -1,4 +1,10 @@
|
|||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
|
||||
module.exports = path.join(__dirname, fs.readFileSync(path.join(__dirname, 'path.txt'), 'utf-8'))
|
||||
var pathFile = path.join(__dirname, 'path.txt')
|
||||
|
||||
if (fs.existsSync(pathFile)) {
|
||||
module.exports = path.join(__dirname, fs.readFileSync(pathFile, 'utf-8'))
|
||||
} else {
|
||||
throw new Error('Electron failed to install correctly, please delete node_modules/' + path.basename(__dirname) + ' and try installing again')
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ var tape = require('tape')
|
|||
var path = require('path')
|
||||
var childProcess = require('child_process')
|
||||
|
||||
tape('fails for unsupported platforms', function (t) {
|
||||
tape('install fails for unsupported platforms', function (t) {
|
||||
install({npm_config_platform: 'android'}, function (code, stderr) {
|
||||
t.notEqual(stderr.indexOf('Electron builds are not available on platform: android'), -1, 'has error message')
|
||||
t.notEqual(code, 0, 'exited with error')
|
||||
|
@ -11,7 +11,7 @@ tape('fails for unsupported platforms', function (t) {
|
|||
})
|
||||
})
|
||||
|
||||
tape('fails for unknown architectures', function (t) {
|
||||
tape('install fails for unsupported architectures', function (t) {
|
||||
install({
|
||||
npm_config_arch: 'midcentury',
|
||||
npm_config_platform: 'win32',
|
||||
|
@ -25,8 +25,16 @@ tape('fails for unknown architectures', function (t) {
|
|||
})
|
||||
})
|
||||
|
||||
var install = function (env, callback) {
|
||||
removeVersionFile()
|
||||
tape('require fails for corrupted installs', function (t) {
|
||||
cli(function (code, stderr) {
|
||||
t.notEqual(stderr.indexOf('Electron failed to install correctly'), -1, 'has error message')
|
||||
t.notEqual(code, 0, 'exited with error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
function install (env, callback) {
|
||||
var restoreFile = removeFile(path.join(__dirname, '..', 'dist', 'version'))
|
||||
|
||||
var installPath = path.join(__dirname, '..', 'install.js')
|
||||
var installProcess = childProcess.fork(installPath, {
|
||||
|
@ -40,23 +48,39 @@ var install = function (env, callback) {
|
|||
})
|
||||
|
||||
installProcess.on('close', function (code) {
|
||||
restoreVersionFile()
|
||||
restoreFile()
|
||||
callback(code, stderr)
|
||||
})
|
||||
}
|
||||
|
||||
var versionPath = path.join(__dirname, '..', 'dist', 'version')
|
||||
var versionContents = null
|
||||
function removeVersionFile () {
|
||||
if (fs.existsSync(versionPath)) {
|
||||
versionContents = fs.readFileSync(versionPath)
|
||||
fs.unlinkSync(versionPath)
|
||||
}
|
||||
function cli (callback) {
|
||||
var restoreFile = removeFile(path.join(__dirname, '..', 'path.txt'))
|
||||
|
||||
var cliPath = path.join(__dirname, '..', 'cli.js')
|
||||
var cliProcess = childProcess.fork(cliPath, {
|
||||
silent: true
|
||||
})
|
||||
|
||||
var stderr = ''
|
||||
cliProcess.stderr.on('data', function (data) {
|
||||
stderr += data
|
||||
})
|
||||
|
||||
cliProcess.on('close', function (code) {
|
||||
restoreFile()
|
||||
callback(code, stderr)
|
||||
})
|
||||
}
|
||||
|
||||
function restoreVersionFile () {
|
||||
if (versionContents != null) {
|
||||
fs.writeFileSync(versionPath, versionContents)
|
||||
versionContents = null
|
||||
function removeFile (filePath) {
|
||||
var contents = null
|
||||
if (fs.existsSync(filePath)) {
|
||||
contents = fs.readFileSync(filePath)
|
||||
fs.unlinkSync(filePath)
|
||||
}
|
||||
return function restoreFile () {
|
||||
if (contents != null) {
|
||||
fs.writeFileSync(filePath, contents)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue