alallier / reload

node module to reload your browser when your code changes
MIT License
297 stars 47 forks source link

Not passing `--browser` to `reload` binary parsing is interpreted as it was there #384

Open jest opened 1 month ago

jest commented 1 month ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch reload@3.3.0 for the project I'm working on.

The problem is that when calling the reload binary withour passing --browser, the browser is launched anyway.

The cause is the wrong parsing of options.browser field. When --browser is not passed, the field value is undefined. However, before passing this to reload() function, the value is casted to string, resulting in "undefined", and then double-negated (with !!) turning it into true.

The solution is to double-negate options.browser before converting it into a string.

Here is the diff that solved my problem:

diff --git a/node_modules/reload/bin/reload b/node_modules/reload/bin/reload
index 4e005dc..afcf620 100755
--- a/node_modules/reload/bin/reload
+++ b/node_modules/reload/bin/reload
@@ -40,7 +40,7 @@ nodemon({
   watch: path.join(options.watchDir, '/**/*'), // Watch all subdirectories
   ignore: options.ignore.split(','),
   script: `${serverFile}`,
-  args: [`${options.port}`, `${options.dir}`, !!`${options.browser}`, `${options.hostname}`, `${runFile}`, `${options.startPage}`, `${options.fallback}`, `${options.verbose}`]
+  args: [`${options.port}`, `${options.dir}`, `${!!options.browser}`, `${options.hostname}`, `${runFile}`, `${options.startPage}`, `${options.fallback}`, `${options.verbose}`]
 })

 nodemon.on('start', function () {

This issue body was partially generated by patch-package.