@@ -69,9 +69,9 @@ type execResult =
69
69
kind : "error" ;
70
70
error : string ;
71
71
} ;
72
- export let formatUsingValidBscPath = (
72
+ export let formatUsingValidBscExePath = (
73
73
code : string ,
74
- bscPath : p . DocumentUri ,
74
+ bscExePath : p . DocumentUri ,
75
75
isInterface : boolean
76
76
) : execResult => {
77
77
let extension = isInterface ? c . resiExt : c . resExt ;
@@ -81,7 +81,7 @@ export let formatUsingValidBscPath = (
81
81
} ) ;
82
82
try {
83
83
let result = childProcess . execFileSync (
84
- bscPath ,
84
+ bscExePath ,
85
85
[ "-color" , "never" , "-format" , formatTempFileFullPath ] ,
86
86
) ;
87
87
return {
@@ -99,16 +99,28 @@ export let formatUsingValidBscPath = (
99
99
}
100
100
} ;
101
101
102
- export let runBsbWatcherUsingValidBsbPath = (
103
- bsbPath : p . DocumentUri ,
102
+ export let runBsbWatcherUsingValidBsbNodePath = (
103
+ bsbNodePath : p . DocumentUri ,
104
104
projectRootPath : p . DocumentUri
105
105
) => {
106
106
if ( process . platform === "win32" ) {
107
- return childProcess . exec ( `${ bsbPath } .cmd -w` , {
107
+ /*
108
+ - a node.js script in node_modules/.bin on windows is wrapped in a
109
+ batch script wrapper (there's also a regular binary of the same name on
110
+ windows, but that one's a shell script wrapper for cygwin). More info:
111
+ https://github.com/npm/cmd-shim/blob/c5118da34126e6639361fe9706a5ff07e726ed45/index.js#L1
112
+ - a batch script adds the suffix .cmd to the script
113
+ - you can't call batch scripts through the regular `execFile`:
114
+ https://nodejs.org/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows
115
+ - So you have to use `exec` instead, and make sure you quote the path
116
+ (since the path might have spaces), which `execFile` would have done
117
+ for you under the hood
118
+ */
119
+ return childProcess . exec ( `"${ bsbNodePath } ".cmd -w` , {
108
120
cwd : projectRootPath ,
109
121
} ) ;
110
122
} else {
111
- return childProcess . execFile ( bsbPath , [ "-w" ] , {
123
+ return childProcess . execFile ( bsbNodePath , [ "-w" ] , {
112
124
cwd : projectRootPath ,
113
125
} ) ;
114
126
}
0 commit comments