@@ -7,127 +7,124 @@ interface Message {
7
7
}
8
8
9
9
export async function devboxReopen ( ) {
10
-
11
- if ( process . platform === 'win32' ) {
12
- const seeDocs = 'See Devbox docs' ;
13
- const result = await window . showErrorMessage (
14
- 'This feature is not supported on your platform. \
15
- Please open VSCode from inside devbox shell in WSL using the CLI.' , seeDocs
16
- ) ;
17
- if ( result === seeDocs ) {
18
- env . openExternal ( Uri . parse ( 'https://www.jetpack.io/devbox/docs/ide_configuration/vscode/#windows-setup' ) ) ;
19
- return ;
20
- }
10
+ if ( process . platform === 'win32' ) {
11
+ const seeDocs = 'See Devbox docs' ;
12
+ const result = await window . showErrorMessage (
13
+ 'This feature is not supported on your platform. \
14
+ Please open VSCode from inside devbox shell in WSL using the CLI.' , seeDocs
15
+ ) ;
16
+ if ( result === seeDocs ) {
17
+ env . openExternal ( Uri . parse ( 'https://www.jetpack.io/devbox/docs/ide_configuration/vscode/#windows-setup' ) ) ;
18
+ return ;
21
19
}
22
- await window . withProgress ( {
23
- location : ProgressLocation . Notification ,
24
- title : "Setting up your Devbox environment. Please don't close vscode." ,
25
- cancellable : true
26
- } ,
27
- async ( progress , token ) => {
28
- token . onCancellationRequested ( ( ) => {
29
- console . log ( "User canceled the long running operation" ) ;
30
- } ) ;
31
-
32
- const p = new Promise < void > ( async ( resolve , reject ) => {
20
+ }
21
+ await window . withProgress ( {
22
+ location : ProgressLocation . Notification ,
23
+ title : "Setting up your Devbox environment. Please don't close vscode." ,
24
+ cancellable : true
25
+ } ,
26
+ async ( progress , token ) => {
27
+ token . onCancellationRequested ( ( ) => {
28
+ console . log ( "User canceled the long running operation" ) ;
29
+ } ) ;
33
30
34
- if ( workspace . workspaceFolders ) {
35
- const workingDir = workspace . workspaceFolders [ 0 ] . uri ;
36
- const dotdevbox = Uri . joinPath ( workingDir , '/.devbox' ) ;
37
- progress . report ( { message : 'Installing devbox packages...' , increment : 25 } ) ;
38
- await setupDotDevbox ( workingDir , dotdevbox ) ;
31
+ const p = new Promise < void > ( async ( resolve , reject ) => {
32
+ if ( workspace . workspaceFolders ) {
33
+ const workingDir = workspace . workspaceFolders [ 0 ] . uri ;
34
+ const dotdevbox = Uri . joinPath ( workingDir , '/.devbox' ) ;
35
+ progress . report ( { message : 'Installing devbox packages...' , increment : 25 } ) ;
36
+ await setupDotDevbox ( workingDir , dotdevbox ) ;
39
37
40
- // setup required vscode settings
41
- progress . report ( { message : 'Updating configurations...' , increment : 50 } ) ;
42
- updateVSCodeConf ( ) ;
38
+ // setup required vscode settings
39
+ progress . report ( { message : 'Updating configurations...' , increment : 50 } ) ;
40
+ updateVSCodeConf ( ) ;
43
41
44
- // Calling CLI to compute devbox env
45
- progress . report ( { message : 'Calling Devbox to setup environment...' , increment : 80 } ) ;
46
- // To use a custom compiled devbox when testing, change this to an absolute path.
47
- const devbox = 'devbox' ;
48
- // run devbox integrate and then close this window
49
- let child = spawn ( devbox , [ 'integrate' , 'vscode' ] , {
50
- cwd : workingDir . path ,
51
- stdio : [ 0 , 1 , 2 , 'ipc' ]
52
- } ) ;
53
- // if CLI closes before sending "finished" message
54
- child . on ( 'close' , ( code : number ) => {
55
- console . log ( "child process closed with exit code:" , code ) ;
56
- window . showErrorMessage ( "Failed to setup devbox environment." ) ;
57
- reject ( ) ;
58
- } ) ;
59
- // send config path to CLI
60
- child . send ( { configDir : workingDir . path } ) ;
61
- // handle CLI finishing the env and sending "finished"
62
- child . on ( 'message' , function ( msg : Message , handle ) {
63
- if ( msg . status === "finished" ) {
64
- progress . report ( { message : 'Finished setting up! Reloading the window...' , increment : 100 } ) ;
65
- resolve ( ) ;
66
- commands . executeCommand ( "workbench.action.closeWindow" ) ;
67
- }
68
- else {
69
- console . log ( msg ) ;
70
- window . showErrorMessage ( "Failed to setup devbox environment." ) ;
71
- reject ( ) ;
72
- }
73
- } ) ;
74
- }
75
- } ) ;
76
- return p ;
42
+ // Calling CLI to compute devbox env
43
+ progress . report ( { message : 'Calling Devbox to setup environment...' , increment : 80 } ) ;
44
+ // To use a custom compiled devbox when testing, change this to an absolute path.
45
+ const devbox = 'devbox' ;
46
+ // run devbox integrate and then close this window
47
+ let child = spawn ( devbox , [ 'integrate' , 'vscode' ] , {
48
+ cwd : workingDir . path ,
49
+ stdio : [ 0 , 1 , 2 , 'ipc' ]
50
+ } ) ;
51
+ // if CLI closes before sending "finished" message
52
+ child . on ( 'close' , ( code : number ) => {
53
+ console . log ( "child process closed with exit code:" , code ) ;
54
+ window . showErrorMessage ( "Failed to setup devbox environment." ) ;
55
+ reject ( ) ;
56
+ } ) ;
57
+ // send config path to CLI
58
+ child . send ( { configDir : workingDir . path } ) ;
59
+ // handle CLI finishing the env and sending "finished"
60
+ child . on ( 'message' , function ( msg : Message , handle ) {
61
+ if ( msg . status === "finished" ) {
62
+ progress . report ( { message : 'Finished setting up! Reloading the window...' , increment : 100 } ) ;
63
+ resolve ( ) ;
64
+ commands . executeCommand ( "workbench.action.closeWindow" ) ;
65
+ }
66
+ else {
67
+ console . log ( msg ) ;
68
+ window . showErrorMessage ( "Failed to setup devbox environment." ) ;
69
+ reject ( ) ;
70
+ }
71
+ } ) ;
77
72
}
78
- ) ;
79
-
80
-
73
+ } ) ;
74
+ return p ;
75
+ }
76
+ ) ;
81
77
}
82
78
83
79
async function setupDotDevbox ( workingDir : Uri , dotdevbox : Uri ) {
84
- try {
85
- // check if .devbox exists
86
- await workspace . fs . stat ( dotdevbox ) ;
87
- } catch ( error ) {
88
- //.devbox doesn't exist
89
- // running devbox shellenv to create it
90
- spawnSync ( 'devbox' , [ 'shellenv' ] , {
91
- cwd : workingDir . path
92
- } ) ;
93
- }
80
+ try {
81
+ // check if .devbox exists
82
+ await workspace . fs . stat ( dotdevbox ) ;
83
+ } catch ( error ) {
84
+ //.devbox doesn't exist
85
+ // running devbox shellenv to create it
86
+ spawnSync ( 'devbox' , [ 'shellenv' ] , {
87
+ cwd : workingDir . path
88
+ } ) ;
89
+ }
94
90
}
95
91
96
92
function updateVSCodeConf ( ) {
97
- if ( process . platform === 'darwin' ) {
98
- const shell = process . env [ "SHELL" ] ?? "/bin/zsh" ;
99
- const shellArgsMap = ( shellType : string ) => {
100
- switch ( shellType ) {
101
- case "fish" :
102
- // We special case fish here because fish's `fish_add_path` function
103
- // tends to prepend to PATH by default, hence sourcing the fish config after
104
- // vscode reopens in devbox environment, overwrites devbox packages and
105
- // might cause confusion for users as to why their system installed packages
106
- // show up when they type for example `which go` as opposed to the packages
107
- // installed by devbox.
108
- return [ "--no-config" ] ;
109
- default :
110
- return [ ] ;
111
- }
112
- } ;
113
- const shellTypeSlices = shell . split ( "/" ) ;
114
- const shellType = shellTypeSlices [ shellTypeSlices . length - 1 ] ;
115
- shellArgsMap ( shellType ) ;
116
- const devboxCompatibleShell = {
117
- "devboxCompatibleShell" : {
118
- "path" : shell ,
119
- "args" : shellArgsMap ( shellType )
120
- }
121
- } ;
93
+ if ( process . platform === 'darwin' ) {
94
+ const shell = process . env [ "SHELL" ] ?? "/bin/zsh" ;
95
+ const shellArgsMap = ( shellType : string ) => {
96
+ switch ( shellType ) {
97
+ case "fish" :
98
+ // We special case fish here because fish's `fish_add_path` function
99
+ // tends to prepend to PATH by default, hence sourcing the fish config after
100
+ // vscode reopens in devbox environment, overwrites devbox packages and
101
+ // might cause confusion for users as to why their system installed packages
102
+ // show up when they type for example `which go` as opposed to the packages
103
+ // installed by devbox.
104
+ return [ "--no-config" ] ;
105
+ default :
106
+ return [ ] ;
107
+ }
108
+ } ;
109
+ const shellTypeSlices = shell . split ( "/" ) ;
110
+ const shellType = shellTypeSlices [ shellTypeSlices . length - 1 ] ;
111
+ shellArgsMap ( shellType ) ;
112
+ const devboxCompatibleShell = {
113
+ "devboxCompatibleShell" : {
114
+ "path" : shell ,
115
+ "args" : shellArgsMap ( shellType )
116
+ }
117
+ } ;
122
118
123
- workspace . getConfiguration ( ) . update (
124
- 'terminal.integrated.profiles.osx' ,
125
- devboxCompatibleShell ,
126
- ConfigurationTarget . Workspace
127
- ) ;
128
- workspace . getConfiguration ( ) . update (
129
- 'terminal.integrated.defaultProfile.osx' ,
130
- 'devboxCompatibleShell' ,
131
- ConfigurationTarget . Workspace ) ;
132
- }
119
+ workspace . getConfiguration ( ) . update (
120
+ 'terminal.integrated.profiles.osx' ,
121
+ devboxCompatibleShell ,
122
+ ConfigurationTarget . Workspace
123
+ ) ;
124
+ workspace . getConfiguration ( ) . update (
125
+ 'terminal.integrated.defaultProfile.osx' ,
126
+ 'devboxCompatibleShell' ,
127
+ ConfigurationTarget . Workspace
128
+ ) ;
129
+ }
133
130
}
0 commit comments