Created by: GAumala
Modify OpenBrowser.js to run node scripts specified with the BROWSER
environment
variable as discussed in #1533 (closed) . If the value of the BROWSER
environment variable ends with '.js' a
child process is spawned to execute the script with node.js. The command
executed in the child process is 'node PATH_SCRIPT'.
Some observations I'd like to discuss:
- Since
BROWSER
now does more than just opening your browser, maybe we should consider renaming a few things. - The string argument of the script to run with node is not sanitized in any way. Nothing is checked, the string is passed to the child process as is. I don't know what is the worst thing that could happen. Scripts ending in '.JS' are not executed.
- The openBrowser() function returns a boolean. I decided to stick with this behavior,
but I noticed that the result is not used in
react-scripts/scripts/start.js
.
How to test this:
create any 'script.js' file. You can use this one that writes a file to the current working directory:
const fs = require('fs')
fs.writeFileSync('message.txt', 'script says hello!');
Now in the same directory execute:
BROWSER=script.js npm start
The file should be created in that directory and no browser should be opened.
And of course, the other use cases of BROWSER
still work
BROWSER=none npm start
BROWSER=firefox npm start
Any feedback is appreciated.