Bugfix/Fix dynamic import for shell env (#2640)

The `shell env` package has been silently failing meaning that fixes that allow oni to read in a user's env var have regressed. This happened when we upgraded `webpack` because with the new version of webpack, dynamic imports now return objects with the shape `{ default: DefaultFnExport, aVar: var }`

Also upgraded the `shellenv` package as is since been upgraded.
This commit is contained in:
Akin 2018-10-27 10:19:15 +01:00 committed by GitHub
parent c4dd8ad726
commit 8bb8a9fe2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 1814 deletions

View File

@ -10,19 +10,38 @@ export interface IShellEnvironmentFetcher {
getEnvironmentVariables(): Promise<any>
}
interface IShellEnv {
default: {
sync: (shell?: string) => NodeJS.ProcessEnv
}
}
export class ShellEnvironmentFetcher implements IShellEnvironmentFetcher {
private _shellEnvPromise: Promise<any>
private _shellEnv: any
private _shellEnv: IShellEnv
constructor() {
// Dynamic imports return { default: Module }
this._shellEnvPromise = import("shell-env")
}
public async getEnvironmentVariables(): Promise<any> {
public async getEnvironmentVariables(): Promise<NodeJS.ProcessEnv> {
if (!this._shellEnv) {
this._shellEnv = await this._shellEnvPromise
return this._shellEnv.sync()
}
try {
const userShell = configuration.getValue<string>("oni.userShell")
const shell = typeof userShell === "string" ? userShell : undefined
const env = this._shellEnv.default.sync(shell)
return env
} catch (error) {
Log.warn(
`[Oni environment fetcher]: unable to get enviroment variables because: ${
error.message
}`,
)
}
return {}
}
}
@ -129,7 +148,7 @@ export class Process implements Oni.Process {
try {
if (!this._env) {
this._env = (await this._shellEnvironmentFetcher.getEnvironmentVariables()) || {}
this._env = await this._shellEnvironmentFetcher.getEnvironmentVariables()
}
existingPath = process.env.Path || process.env.PATH
} catch (e) {

View File

@ -109,6 +109,8 @@ const BaseConfiguration: IConfigurationValues = {
"oni.enhancedSyntaxHighlighting": true,
"oni.userShell": undefined,
"oni.loadInitVim": false,
"oni.hideMenu": false,

View File

@ -111,6 +111,10 @@ export interface IConfigurationValues {
// Set this to 'false' to avoid loading the default config, and load settings from init.vim instead.
"oni.useDefaultConfig": boolean
// This string represents the path to the shell that the user would like oni to use to extract
// environment variables that it uses derives the $PATH variable from.
"oni.userShell": string
// By default, user's init.vim is not loaded, to avoid conflicts.
// Set this to `true` to enable loading of init.vim.
// Set this to a string to override the init.vim path.

View File

@ -882,7 +882,7 @@
"react-dnd-html5-backend": "^2.5.4",
"react-dom": "^16.3.2",
"redux-batched-subscribe": "^0.1.6",
"shell-env": "^0.3.0",
"shell-env": "^2.1.0",
"shelljs": "0.7.7",
"simple-git": "^1.92.0",
"styled-components": "^3.4.4",

1841
yarn.lock

File diff suppressed because it is too large Load Diff