@@ -69,9 +69,9 @@ type execResult =
6969 kind : "error" ;
7070 error : string ;
7171 } ;
72- export let formatUsingValidBscPath = (
72+ export let formatUsingValidBscExePath = (
7373 code : string ,
74- bscPath : p . DocumentUri ,
74+ bscExePath : p . DocumentUri ,
7575 isInterface : boolean
7676) : execResult => {
7777 let extension = isInterface ? c . resiExt : c . resExt ;
@@ -81,7 +81,7 @@ export let formatUsingValidBscPath = (
8181 } ) ;
8282 try {
8383 let result = childProcess . execFileSync (
84- bscPath ,
84+ bscExePath ,
8585 [ "-color" , "never" , "-format" , formatTempFileFullPath ] ,
8686 ) ;
8787 return {
@@ -99,16 +99,28 @@ export let formatUsingValidBscPath = (
9999 }
100100} ;
101101
102- export let runBsbWatcherUsingValidBsbPath = (
103- bsbPath : p . DocumentUri ,
102+ export let runBsbWatcherUsingValidBsbNodePath = (
103+ bsbNodePath : p . DocumentUri ,
104104 projectRootPath : p . DocumentUri
105105) => {
106106 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` , {
108120 cwd : projectRootPath ,
109121 } ) ;
110122 } else {
111- return childProcess . execFile ( bsbPath , [ "-w" ] , {
123+ return childProcess . execFile ( bsbNodePath , [ "-w" ] , {
112124 cwd : projectRootPath ,
113125 } ) ;
114126 }
0 commit comments