Skip to content

Commit 033c8e8

Browse files
committed
address comments
1 parent add2e45 commit 033c8e8

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

packages/core/src/shared/env/resolveEnv.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export async function getSpawnEnv(
114114
export async function mergeResolvedShellPath(env: IProcessEnvironment): Promise<typeof process.env> {
115115
const shellEnv = await getResolvedShellEnv(env)
116116
// resolve failed or doesn't need to resolve
117-
if (!shellEnv || Object.keys(shellEnv).length === 0) {
117+
if (!shellEnv) {
118118
return env
119119
}
120120
try {
@@ -139,29 +139,29 @@ export async function mergeResolvedShellPath(env: IProcessEnvironment): Promise<
139139
* - we hit a timeout of `MAX_SHELL_RESOLVE_TIME`
140140
* - any other error from spawning a shell to figure out the environment
141141
*/
142-
export async function getResolvedShellEnv(env?: IProcessEnvironment): Promise<typeof process.env> {
142+
export async function getResolvedShellEnv(env?: IProcessEnvironment): Promise<typeof process.env | undefined> {
143143
if (!env) {
144144
env = process.env
145145
}
146146
// Skip if forceResolveEnv is set to false
147147
if (DevSettings.instance._isSet('forceResolveEnv') && !DevSettings.instance.get('forceResolveEnv', false)) {
148148
getLogger().debug('resolveShellEnv(): skipped (forceResolveEnv)')
149149

150-
return {}
150+
return undefined
151151
}
152152

153153
// Skip on windows
154154
else if (process.platform === 'win32') {
155155
getLogger().debug('resolveShellEnv(): skipped (Windows)')
156156

157-
return {}
157+
return undefined
158158
}
159159

160160
// Skip if running from CLI already and forceResolveEnv is not true
161161
else if (isLaunchedFromCli(env) && !DevSettings.instance.get('forceResolveEnv', false)) {
162162
getLogger().info('resolveShellEnv(): skipped (VSCODE_CLI is set)')
163163

164-
return {}
164+
return undefined
165165
}
166166
// Otherwise resolve (macOS, Linux)
167167
else {
@@ -181,10 +181,15 @@ export async function getResolvedShellEnv(env?: IProcessEnvironment): Promise<ty
181181

182182
// Resolve shell env and handle errors
183183
try {
184-
resolve(await doResolveUnixShellEnv(timeout))
184+
const shellEnv = await doResolveUnixShellEnv(timeout)
185+
if (shellEnv && Object.keys(shellEnv).length > 0) {
186+
resolve(shellEnv)
187+
} else {
188+
return undefined
189+
}
185190
} catch {
186191
// failed resolve should not affect other feature.
187-
resolve({})
192+
return undefined
188193
}
189194
})
190195
}

packages/core/src/test/shared/env/resolveEnv.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ describe('resolveEnv', async function () {
1818
sandbox.restore()
1919
})
2020

21-
// a copy of resolveEnv.mergeResolvedShellPath for stubbing
21+
// a copy of resolveEnv.mergeResolvedShellPath for stubbing getResolvedShellEnv
22+
// mergeResolvedShellPath is calling getResolvedShellEnv within the same file
23+
// thus we need a copy to stub getResolvedShellEnv correctly
2224
const testMergeResolveShellPath = async function mergeResolvedShellPath(
2325
env: resolveEnv.IProcessEnvironment
2426
): Promise<typeof process.env> {
2527
const shellEnv = await resolveEnv.getResolvedShellEnv(env)
2628
// resolve failed or doesn't need to resolve
27-
if (!shellEnv || Object.keys(shellEnv).length === 0) {
29+
if (!shellEnv) {
2830
return env
2931
}
3032
try {
@@ -40,7 +42,7 @@ describe('resolveEnv', async function () {
4042
}
4143
}
4244

43-
describe('resolveWindows', async function () {
45+
describe('windows', async function () {
4446
beforeEach(function () {
4547
sandbox.stub(process, 'platform').value('win32')
4648
})
@@ -52,11 +54,11 @@ describe('resolveEnv', async function () {
5254
})
5355
})
5456

55-
describe('resolveUnix', async function () {
57+
describe('unix', async function () {
5658
const originalEnv = { ...process.env }
5759
// skip mac test on windows
5860
if (process.platform !== 'win32') {
59-
it('mergeResolvedShellPath should get path on mac/unix', async function () {
61+
it('mergeResolvedShellPath should get path on mac/linux', async function () {
6062
sandbox.stub(process.env, 'PATH').value('')
6163
// stub the resolve Env logic cause this is platform sensitive.
6264
sandbox.stub(resolveEnv, 'getResolvedShellEnv').resolves(originalEnv)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"type": "Bug Fix",
3-
"description": "getSpawnEnv always return correct env on windows"
3+
"description": "System Path parsing should ignore Windows and only parse Mac/Linux system, Sam Local Invoke should get correct system Path on windows"
44
}

0 commit comments

Comments
 (0)