Closed kqvanity closed 2 years ago
This is a feature of your shell, not nodemon. In that a new (sub) shell session doesn't inherit your functions.
This can be tested by writing a vanilla shell script - you'll find you can't call your javab
function.
I can't remember how you get around it, but I'd start looking there.
This is a feature of your shell, not nodemon. In that a new (sub) shell session doesn't inherit your functions.
I did export the function using export -f javab
after defining it, so that other child process including subshells can read it. I've also tried spawning one from within the shell session, and it did work with them.
Can you share the node script you used to spawn to then call your function? I can use it for my own test and if it's something that's fixable, I'll reopen this ticket and see what we can do.
Can you share the node script you used to spawn to then call your function?
I haven't used one at all. I've just defined the function & exported it at my bashrc. Invoked another shell session, then attempted to issue the function from within the initial shell, then a child one, and it worked in both cases.
~/.bashrc
entails
function javab(){
local javafile="$1";
javac ${javafile} && java $javafile%.*}
} && export -f javab
~/nodemon.json
{
"execMap": {
"java": "bash -c javab",
}
}
node script
const { spawn } = require('node:child_process')
spawn('bash', ['-c', 'javab VariableTypes.java']).stdout
.on('data', (data) => {
console.log(data.toString())
})
nodemon -v
: 2.0.20node -v
: v18.9.1nodemon javaFile.java
Expected behaviour
Nodemon to execute a shell function that compile a java file named passed to it, then the functions also runs the resulting class file with its filename truncated (i.e. excluding the .class file extension]. It would be really useful if such a feature of having the file name passed have a respective placeholder at the json file, for other manipulations. I usually use temporary source files without build systems or single makes files to carry the heavy lifting.
Actual behaviour
An error stating that
Also specifying
bash -c java
in~/nodemon.json
results in a similar error.Steps to reproduce
Have a shell function, then try to assign it to a file extension in the
~/nodemon.json
file. Try to run a java file afterwards, and it won't work.