@@ -3,7 +3,7 @@ import * as cp from "child_process"
3
3
import { promises as fs } from "fs"
4
4
import * as path from "path"
5
5
import { Page } from "playwright"
6
- import util from "util"
6
+ import * as util from "util"
7
7
import { logError , plural } from "../../../src/common/util"
8
8
import { onLine } from "../../../src/node/util"
9
9
import { PASSWORD , workspaceDir } from "../../utils/constants"
@@ -38,12 +38,13 @@ export class CodeServer {
38
38
private process : Promise < CodeServerProcess > | undefined
39
39
public readonly logger : Logger
40
40
private closed = false
41
- private _workspaceDir : Promise < string > | undefined
42
41
43
42
constructor (
44
43
name : string ,
45
- private readonly codeServerArgs : string [ ] ,
46
- private readonly codeServerEnv : NodeJS . ProcessEnv ,
44
+ private readonly args : string [ ] ,
45
+ private readonly env : NodeJS . ProcessEnv ,
46
+ private readonly _workspaceDir : Promise < string > | string | undefined ,
47
+ private readonly entry = process . env . CODE_SERVER_TEST_ENTRY || "." ,
47
48
) {
48
49
this . logger = logger . named ( name )
49
50
}
@@ -75,7 +76,7 @@ export class CodeServer {
75
76
*/
76
77
private async createWorkspace ( ) : Promise < string > {
77
78
const dir = await this . workspaceDir
78
- await fs . mkdir ( path . join ( dir , "User" ) )
79
+ await fs . mkdir ( path . join ( dir , "User" ) , { recursive : true } )
79
80
await fs . writeFile (
80
81
path . join ( dir , "User/settings.json" ) ,
81
82
JSON . stringify ( {
@@ -96,36 +97,33 @@ export class CodeServer {
96
97
const dir = await this . createWorkspace ( )
97
98
98
99
return new Promise ( ( resolve , reject ) => {
99
- this . logger . debug ( "spawning" )
100
- const proc = cp . spawn (
101
- "node" ,
102
- [
103
- process . env . CODE_SERVER_TEST_ENTRY || "." ,
104
- "--extensions-dir" ,
105
- path . join ( dir , "extensions" ) ,
106
- ...this . codeServerArgs ,
107
- // Using port zero will spawn on a random port.
108
- "--bind-addr" ,
109
- "127.0.0.1:0" ,
110
- // Setting the XDG variables would be easier and more thorough but the
111
- // modules we import ignores those variables for non-Linux operating
112
- // systems so use these flags instead.
113
- "--config" ,
114
- path . join ( dir , "config.yaml" ) ,
115
- "--user-data-dir" ,
116
- dir ,
117
- // The last argument is the workspace to open.
118
- dir ,
119
- ] ,
120
- {
121
- cwd : path . join ( __dirname , "../../.." ) ,
122
- env : {
123
- ...process . env ,
124
- ...this . codeServerEnv ,
125
- PASSWORD ,
126
- } ,
100
+ const args = [
101
+ this . entry ,
102
+ "--extensions-dir" ,
103
+ path . join ( dir , "extensions" ) ,
104
+ ...this . args ,
105
+ // Using port zero will spawn on a random port.
106
+ "--bind-addr" ,
107
+ "127.0.0.1:0" ,
108
+ // Setting the XDG variables would be easier and more thorough but the
109
+ // modules we import ignores those variables for non-Linux operating
110
+ // systems so use these flags instead.
111
+ "--config" ,
112
+ path . join ( dir , "config.yaml" ) ,
113
+ "--user-data-dir" ,
114
+ dir ,
115
+ // The last argument is the workspace to open.
116
+ dir ,
117
+ ]
118
+ this . logger . debug ( "spawning `node " + args . join ( " " ) + "`" )
119
+ const proc = cp . spawn ( "node" , args , {
120
+ cwd : path . join ( __dirname , "../../.." ) ,
121
+ env : {
122
+ ...process . env ,
123
+ ...this . env ,
124
+ PASSWORD ,
127
125
} ,
128
- )
126
+ } )
129
127
130
128
const timer = idleTimer ( "Failed to extract address; did the format change?" , reject )
131
129
@@ -136,7 +134,7 @@ export class CodeServer {
136
134
} )
137
135
138
136
proc . on ( "close" , ( code ) => {
139
- const error = new Error ( "closed unexpectedly" )
137
+ const error = new Error ( "code-server closed unexpectedly" )
140
138
if ( ! this . closed ) {
141
139
this . logger . error ( error . message , field ( "code" , code ) )
142
140
}
@@ -153,7 +151,7 @@ export class CodeServer {
153
151
timer . reset ( )
154
152
155
153
// Log the line without the timestamp.
156
- this . logger . trace ( line . replace ( / \[ .+ \] / , "" ) )
154
+ this . logger . debug ( line . replace ( / \[ .+ \] / , "" ) )
157
155
if ( resolved ) {
158
156
return
159
157
}
0 commit comments