Add support for Whalebrew installed executables

Whalebrew mounts a Docker volume to the host's current working directory (cwd)
therefore the cwd needs to be the temp directory and all file paths which
are to be beautified need to be given to Whalebrew as relative to cwd.
Often this means the temporary directory is simply removed from the prefix
of the file paths, and the cwd = the temporary directory.
See https://github.com/bfirsh/whalebrew#how-it-works for details.
This commit is contained in:
Glavin Wiechert 2017-06-04 00:53:16 -03:00
parent 3e78dc8701
commit f945c38338
1 changed files with 16 additions and 0 deletions

View File

@ -5,6 +5,7 @@ spawn = require('child_process').spawn
path = require('path')
semver = require('semver')
shellEnv = require('shell-env')
os = require('os')
parentConfigKey = "atom-beautify.executables"
@ -127,6 +128,7 @@ module.exports = class Executable
args = _.flatten(args)
exeName = @cmd
config = @getConfig()
cwd ?= os.tmpDir()
# Resolve executable and all args
Promise.all([@shellEnv(), Promise.all(args)])
@ -143,13 +145,17 @@ module.exports = class Executable
.then(([exeName, args, env, exePath]) =>
@debug('exePath:', exePath)
@debug('env:', env)
@debug('PATH:', env.PATH)
@debug('args', args)
args = this.relativizePaths(args)
@debug('relativized args', args)
exe = exePath ? exeName
spawnOptions = {
cwd: cwd
env: env
}
@debug('spawnOptions', spawnOptions)
@spawn(exe, args, spawnOptions, onStdin)
.then(({returnCode, stdout, stderr}) =>
@ -186,6 +192,16 @@ module.exports = class Executable
)
)
relativizePaths: (args) ->
tmpDir = os.tmpDir()
newArgs = args.map((arg) ->
isTmpFile = typeof arg is 'string' and path.isAbsolute(arg) and path.dirname(arg).startsWith(tmpDir)
if isTmpFile
return path.relative(tmpDir, arg)
return arg
)
newArgs
###
Spawn
###