Skip to content

Commit 15cf202

Browse files
authored
Merge pull request #4104 from BuckleScript/websocket_fix
fix #4067, #4101: websocket error better error message and docs
2 parents 28589d8 + a7e3057 commit 15cf202

File tree

5 files changed

+103
-7
lines changed

5 files changed

+103
-7
lines changed

jscomp/bsb/bsb_real_path.mli

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1-
val real_path : string -> string
1+
2+
(* Copyright (C) 2020- Authors of BuckleScript
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* In addition to the permissions granted to you by the LGPL, you may combine
10+
* or link a "work that uses the Library" with a publicly distributed version
11+
* of this file to produce a combined library or application, then distribute
12+
* that combined work under the terms of your choosing, with no requirement
13+
* to comply with the obligations normally placed on you by section 4 of the
14+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
15+
* should you choose to use a later version).
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Lesser General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Lesser General Public License
23+
* along with this program; if not, write to the Free Software
24+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
25+
226

327
val is_same_paths_via_io : string -> string -> bool

jscomp/main/bsb_main.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ let bsb_main_flags : (string * Arg.spec * string) list=
7777
"-where",
7878
Arg.Unit (fun _ ->
7979
print_endline (Filename.dirname Sys.executable_name)),
80-
" Show where bsb.exe is located"
80+
" Show where bsb.exe is located";
81+
(** Below flags are only for bsb script, it is not available for bsb.exe
82+
we make it at this time to make `bsb -help` easier
83+
*)
84+
"-ws", Arg.Bool ignore,
85+
" [host:]port specify the websocket number so that when a build is finished, we send such websocket port number a signal"
8186
]
8287

8388

lib/4.06.1/bsb.ml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7887,7 +7887,31 @@ let info_args (args : string array) =
78877887
end
78887888
module Bsb_real_path : sig
78897889
#1 "bsb_real_path.mli"
7890-
val real_path : string -> string
7890+
7891+
(* Copyright (C) 2020- Authors of BuckleScript
7892+
*
7893+
* This program is free software: you can redistribute it and/or modify
7894+
* it under the terms of the GNU Lesser General Public License as published by
7895+
* the Free Software Foundation, either version 3 of the License, or
7896+
* (at your option) any later version.
7897+
*
7898+
* In addition to the permissions granted to you by the LGPL, you may combine
7899+
* or link a "work that uses the Library" with a publicly distributed version
7900+
* of this file to produce a combined library or application, then distribute
7901+
* that combined work under the terms of your choosing, with no requirement
7902+
* to comply with the obligations normally placed on you by section 4 of the
7903+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
7904+
* should you choose to use a later version).
7905+
*
7906+
* This program is distributed in the hope that it will be useful,
7907+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
7908+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7909+
* GNU Lesser General Public License for more details.
7910+
*
7911+
* You should have received a copy of the GNU Lesser General Public License
7912+
* along with this program; if not, write to the Free Software
7913+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
7914+
78917915

78927916
val is_same_paths_via_io : string -> string -> bool
78937917

@@ -16534,7 +16558,12 @@ let bsb_main_flags : (string * Arg.spec * string) list=
1653416558
"-where",
1653516559
Arg.Unit (fun _ ->
1653616560
print_endline (Filename.dirname Sys.executable_name)),
16537-
" Show where bsb.exe is located"
16561+
" Show where bsb.exe is located";
16562+
(** Below flags are only for bsb script, it is not available for bsb.exe
16563+
we make it at this time to make `bsb -help` easier
16564+
*)
16565+
"-ws", Arg.Bool ignore,
16566+
" [host:]port specify the websocket number so that when a build is finished, we send such websocket port number a signal"
1653816567
]
1653916568

1654016569

lib/4.06.1/unstable/bsb_native.ml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7887,7 +7887,31 @@ let info_args (args : string array) =
78877887
end
78887888
module Bsb_real_path : sig
78897889
#1 "bsb_real_path.mli"
7890-
val real_path : string -> string
7890+
7891+
(* Copyright (C) 2020- Authors of BuckleScript
7892+
*
7893+
* This program is free software: you can redistribute it and/or modify
7894+
* it under the terms of the GNU Lesser General Public License as published by
7895+
* the Free Software Foundation, either version 3 of the License, or
7896+
* (at your option) any later version.
7897+
*
7898+
* In addition to the permissions granted to you by the LGPL, you may combine
7899+
* or link a "work that uses the Library" with a publicly distributed version
7900+
* of this file to produce a combined library or application, then distribute
7901+
* that combined work under the terms of your choosing, with no requirement
7902+
* to comply with the obligations normally placed on you by section 4 of the
7903+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
7904+
* should you choose to use a later version).
7905+
*
7906+
* This program is distributed in the hope that it will be useful,
7907+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
7908+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7909+
* GNU Lesser General Public License for more details.
7910+
*
7911+
* You should have received a copy of the GNU Lesser General Public License
7912+
* along with this program; if not, write to the Free Software
7913+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
7914+
78917915

78927916
val is_same_paths_via_io : string -> string -> bool
78937917

@@ -16641,7 +16665,12 @@ let bsb_main_flags : (string * Arg.spec * string) list=
1664116665
"-where",
1664216666
Arg.Unit (fun _ ->
1664316667
print_endline (Filename.dirname Sys.executable_name)),
16644-
" Show where bsb.exe is located"
16668+
" Show where bsb.exe is located";
16669+
(** Below flags are only for bsb script, it is not available for bsb.exe
16670+
we make it at this time to make `bsb -help` easier
16671+
*)
16672+
"-ws", Arg.Bool ignore,
16673+
" [host:]port specify the websocket number so that when a build is finished, we send such websocket port number a signal"
1664516674
]
1664616675

1664716676

lib/bsb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ function setUpWebSocket() {
9191
wsClients.push(ws)
9292
})
9393
.on('error', function (err) {
94-
console.error(err)
94+
if(err !== undefined && err.code === "EADDRINUSE" ){
95+
var error = std_is_tty?`\x1b[1;31mERROR:\x1b[0m` : `ERROR:`
96+
console.error(`${error} The websocket port number ${webSocketPort} is already used,
97+
please pick a different one using "-ws [host:]port" syntax`)
98+
} else {
99+
console.error(err)
100+
}
95101
process.exit(2)
96102
})
97103
.listen(webSocketPort, webSocketHost);
@@ -112,6 +118,9 @@ for (var i = 2; i < process_argv.length; ++i) {
112118
postBuild = process_argv[++i]
113119
} else if (current === "-ws") {
114120
var hostAndPortNumber = (process_argv[++i] || '').split(':');
121+
/**
122+
* @type {number}
123+
*/
115124
var portNumber;
116125
if (hostAndPortNumber.length === 1) {
117126
portNumber = parseInt(hostAndPortNumber[0])

0 commit comments

Comments
 (0)