@@ -9,19 +9,18 @@ import { TerminalShellType } from '../types';
9
9
import { ActivationScripts , VenvBaseActivationCommandProvider } from './baseActivationProvider' ;
10
10
11
11
// For a given shell the scripts are in order of precedence.
12
- const SCRIPTS : ActivationScripts = ( {
12
+ const SCRIPTS : ActivationScripts = {
13
13
// Group 1
14
14
[ TerminalShellType . commandPrompt ] : [ 'activate.bat' , 'Activate.ps1' ] ,
15
15
// Group 2
16
16
[ TerminalShellType . powershell ] : [ 'Activate.ps1' , 'activate.bat' ] ,
17
17
[ TerminalShellType . powershellCore ] : [ 'Activate.ps1' , 'activate.bat' ] ,
18
- } as unknown ) as ActivationScripts ;
18
+ } ;
19
19
20
20
export function getAllScripts ( pathJoin : ( ...p : string [ ] ) => string ) : string [ ] {
21
21
const scripts : string [ ] = [ ] ;
22
- for ( const key of Object . keys ( SCRIPTS ) ) {
23
- const shell = key as TerminalShellType ;
24
- for ( const name of SCRIPTS [ shell ] ) {
22
+ for ( const names of Object . values ( SCRIPTS ) ) {
23
+ for ( const name of names ) {
25
24
if ( ! scripts . includes ( name ) ) {
26
25
scripts . push (
27
26
name ,
@@ -38,13 +37,14 @@ export function getAllScripts(pathJoin: (...p: string[]) => string): string[] {
38
37
@injectable ( )
39
38
export class CommandPromptAndPowerShell extends VenvBaseActivationCommandProvider {
40
39
protected readonly scripts : ActivationScripts ;
40
+
41
41
constructor ( @inject ( IServiceContainer ) serviceContainer : IServiceContainer ) {
42
42
super ( serviceContainer ) ;
43
- this . scripts = ( { } as unknown ) as ActivationScripts ;
44
- for ( const key of Object . keys ( SCRIPTS ) ) {
43
+ this . scripts = { } ;
44
+ for ( const [ key , names ] of Object . entries ( SCRIPTS ) ) {
45
45
const shell = key as TerminalShellType ;
46
46
const scripts : string [ ] = [ ] ;
47
- for ( const name of SCRIPTS [ shell ] ) {
47
+ for ( const name of names ) {
48
48
scripts . push (
49
49
name ,
50
50
// We also add scripts in subdirs.
@@ -62,21 +62,23 @@ export class CommandPromptAndPowerShell extends VenvBaseActivationCommandProvide
62
62
) : Promise < string [ ] | undefined > {
63
63
const scriptFile = await this . findScriptFile ( pythonPath , targetShell ) ;
64
64
if ( ! scriptFile ) {
65
- return ;
65
+ return undefined ;
66
66
}
67
67
68
68
if ( targetShell === TerminalShellType . commandPrompt && scriptFile . endsWith ( 'activate.bat' ) ) {
69
69
return [ scriptFile . fileToCommandArgumentForPythonExt ( ) ] ;
70
- } else if (
70
+ }
71
+ if (
71
72
( targetShell === TerminalShellType . powershell || targetShell === TerminalShellType . powershellCore ) &&
72
73
scriptFile . endsWith ( 'Activate.ps1' )
73
74
) {
74
75
return [ `& ${ scriptFile . fileToCommandArgumentForPythonExt ( ) } ` ] ;
75
- } else if ( targetShell === TerminalShellType . commandPrompt && scriptFile . endsWith ( 'Activate.ps1' ) ) {
76
+ }
77
+ if ( targetShell === TerminalShellType . commandPrompt && scriptFile . endsWith ( 'Activate.ps1' ) ) {
76
78
// lets not try to run the powershell file from command prompt (user may not have powershell)
77
79
return [ ] ;
78
- } else {
79
- return ;
80
80
}
81
+
82
+ return undefined ;
81
83
}
82
84
}
0 commit comments