This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Start refactoring process spawning to common code path * Refactor process management to separate namespace * Add information to README.md * Factor out mergeSpawnOptions, and use current working directory for language server process * Pass full set of path variables * Fix path variable setting in Windows * Add additional paths default to Linux as well * Fix lint issue
- Loading branch information
extr0py
authored
Jul 25, 2017
1 parent
9027507
commit eed7659
Showing
8 changed files
with
121 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as ChildProcess from "child_process" | ||
|
||
import * as Config from "./../../Config" | ||
import * as Platform from "./../../Platform" | ||
|
||
const getPathSeparator = () => { | ||
return Platform.isWindows() ? ";" : ":" | ||
} | ||
|
||
const mergePathEnvironmentVariable = (currentPath: string, pathsToAdd: string[]): string => { | ||
if (!pathsToAdd || !pathsToAdd.length) { | ||
return currentPath | ||
} | ||
|
||
const separator = getPathSeparator() | ||
|
||
const joinedPathsToAdd = pathsToAdd.join(separator) | ||
|
||
return currentPath + separator + joinedPathsToAdd + separator | ||
} | ||
|
||
const mergeSpawnOptions = (originalSpawnOptions: ChildProcess.ExecOptions | ChildProcess.SpawnOptions): any => { | ||
const requiredOptions = { | ||
env: { | ||
...process.env, | ||
...originalSpawnOptions.env, | ||
}, | ||
} | ||
|
||
const existingPath = process.env.Path || process.env.PATH | ||
|
||
requiredOptions.env.PATH = mergePathEnvironmentVariable(existingPath, Config.instance().getValue("environment.additionalPaths")) | ||
|
||
return { | ||
...originalSpawnOptions, | ||
...requiredOptions, | ||
} | ||
} | ||
|
||
/** | ||
* API surface area responsible for handling process-related tasks | ||
* (spawning processes, managing running process, etc) | ||
*/ | ||
export class Process { | ||
|
||
public execNodeScript(scriptPath: string, args: string[] = [], options: ChildProcess.ExecOptions = {}, callback: (err: any, stdout: string, stderr: string) => void): ChildProcess.ChildProcess { | ||
const spawnOptions = mergeSpawnOptions(options) | ||
spawnOptions.env.ELECTRON_RUN_AS_NODE = 1 | ||
|
||
const execOptions = [process.execPath, scriptPath].concat(args) | ||
const execString = execOptions.map((s) => `"${s}"`).join(" ") | ||
|
||
return ChildProcess.exec(execString, spawnOptions, callback) | ||
} | ||
|
||
/** | ||
* Wrapper around `child_process.exec` to run using electron as opposed to node | ||
*/ | ||
public spawnNodeScript(scriptPath: string, args: string[] = [], options: ChildProcess.SpawnOptions = {}): ChildProcess.ChildProcess { | ||
const spawnOptions = mergeSpawnOptions(options) | ||
spawnOptions.env.ELECTRON_RUN_AS_NODE = 1 | ||
|
||
const allArgs = [scriptPath].concat(args) | ||
|
||
return ChildProcess.spawn(process.execPath, allArgs, spawnOptions) | ||
} | ||
|
||
/** | ||
* Spawn process - wrapper around `child_process.spawn` | ||
*/ | ||
public spawnProcess(startCommand: string, args: string[] = [], options: ChildProcess.SpawnOptions = {}): ChildProcess.ChildProcess { | ||
const spawnOptions = mergeSpawnOptions(options) | ||
|
||
return ChildProcess.spawn(startCommand, args, spawnOptions) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters