From f945c3833892c8c281eac83afd75ff471e029a73 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 4 Jun 2017 00:53:16 -0300 Subject: [PATCH] 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. --- src/beautifiers/executable.coffee | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index d3bbdf4..e16772c 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -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 ###